Commit fa7d2f16 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla

Merge branch 'imstkObject' into 'master'

ENH: added Entity class

Closes #218

See merge request !297
parents 6e284b3c a4c60f6c
Pipeline #136115 failed with stage
in 0 seconds
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include "imstkEntity.h"
namespace imstk
{
std::atomic<EntityID> Entity::s_count {0};
Entity::Entity()
{
s_count++;
m_ID = s_count;
}
EntityID
Entity::getID() const
{
return m_ID;
}
}
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#ifndef imstkEntity_h
#define imstkEntity_h
#include <atomic>
namespace imstk
{
using EntityID = unsigned long;
///
/// \class Entity
/// \brief Top-level class for iMSTK objects
///
class Entity
{
public:
///
/// \brief Get ID (ALWAYS query the ID in your code, DO NOT hardcode it)
/// \returns ID of entity
///
EntityID getID() const;
protected:
///
/// \brief Constructor
///
Entity();
// Not the best design pattern
static std::atomic<EntityID> s_count; ///< current count of entities
EntityID m_ID; ///< unique ID of entity
};
}
#endif
\ No newline at end of file
......@@ -27,6 +27,7 @@
// imstk
#include "imstkMath.h"
#include "imstkColor.h"
#include "imstkEntity.h"
namespace imstk
{
......@@ -45,7 +46,7 @@ enum class LightType
///
/// \brief Abstract base class for lights
///
class Light
class Light : public Entity
{
public:
///
......@@ -117,8 +118,8 @@ public:
void setName(const std::string&& name) { m_name = std::move(name); };
protected:
Light(const std::string& name) : m_name(name){};
Light(std::string&& name) : m_name(std::move(name)){};
Light(const std::string& name) : m_name(name), Entity() {};
Light(std::string&& name) : m_name(std::move(name)), Entity() {};
// properties with defaults
float m_intensity = 100.;
......
......@@ -26,6 +26,16 @@
namespace imstk
{
SceneObject::SceneObject(const std::string& name) : m_name(name), Entity()
{
m_type = Type::Visual;
}
SceneObject::SceneObject(std::string&& name) : m_name(std::move(name)), Entity()
{
m_type = Type::Visual;
}
std::shared_ptr<Geometry>
SceneObject::getVisualGeometry() const
{
......
......@@ -26,6 +26,7 @@
#include <string>
#include "imstkVisualModel.h"
#include "imstkEntity.h"
namespace imstk
{
......@@ -38,7 +39,7 @@ class DeviceClient;
/// \brief Base class for all scene objects. A scene object can optionally be visible and
/// collide with other scene objects. A object of the class is static.
///
class SceneObject
class SceneObject : public Entity
{
public:
enum class Type
......@@ -54,14 +55,8 @@ public:
///
/// \brief Constructor
///
SceneObject(const std::string& name) : m_name(name)
{
m_type = Type::Visual;
}
SceneObject(std::string&& name) : m_name(std::move(name))
{
m_type = Type::Visual;
}
SceneObject(const std::string& name);
SceneObject(std::string&& name);
///
/// \brief Destructor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment