diff --git a/Source/Core/imstkEntity.cpp b/Source/Core/imstkEntity.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa693aecfae107ccb888c667ed46fd822fe1fad2 --- /dev/null +++ b/Source/Core/imstkEntity.cpp @@ -0,0 +1,39 @@ +/*========================================================================= + + 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 Entity::s_count {0}; + +Entity::Entity() +{ + s_count++; + m_ID = s_count; +} + +EntityID +Entity::getID() const +{ + return m_ID; +} +} diff --git a/Source/Core/imstkEntity.h b/Source/Core/imstkEntity.h new file mode 100644 index 0000000000000000000000000000000000000000..c86d2fad654ed19bf0eac9d6fbb6a83c0fc4f6bf --- /dev/null +++ b/Source/Core/imstkEntity.h @@ -0,0 +1,57 @@ +/*========================================================================= + + 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 + +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 s_count; ///< current count of entities + + EntityID m_ID; ///< unique ID of entity +}; +} + +#endif \ No newline at end of file diff --git a/Source/SceneElements/Light/imstkLight.h b/Source/SceneElements/Light/imstkLight.h index 25728f6670b7b922e7064392487d821903602b81..f7127b6c3c58a8d028d7d04038d311b54b51eeda 100644 --- a/Source/SceneElements/Light/imstkLight.h +++ b/Source/SceneElements/Light/imstkLight.h @@ -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.; diff --git a/Source/SceneElements/Objects/imstkSceneObject.cpp b/Source/SceneElements/Objects/imstkSceneObject.cpp index 12efbad15c309798857ae95d6ab86b0b54159a8d..1ab5faa5f6fb4a1b85f5fc750d1bf8f51ab0d141 100644 --- a/Source/SceneElements/Objects/imstkSceneObject.cpp +++ b/Source/SceneElements/Objects/imstkSceneObject.cpp @@ -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 SceneObject::getVisualGeometry() const { diff --git a/Source/SceneElements/Objects/imstkSceneObject.h b/Source/SceneElements/Objects/imstkSceneObject.h index 35532d248b318d03000eb030e94345ef217effc3..eeb05bc294dc1cd6a541fbf9d4715741ca28bcbe 100644 --- a/Source/SceneElements/Objects/imstkSceneObject.h +++ b/Source/SceneElements/Objects/imstkSceneObject.h @@ -26,6 +26,7 @@ #include #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