From 10c349404612f9ce032b9151f0c2a3e3e14c9d32 Mon Sep 17 00:00:00 2001 From: sreekanth-arikatla <sreekanth.arikatla@kitware.com> Date: Tue, 29 Jun 2021 08:42:28 -0400 Subject: [PATCH] REFAC: Move impl to cpp files --- Source/Common/CMakeLists.txt | 1 - Source/Common/TaskGraph/imstkTaskGraph.h | 4 +- Source/Common/imstkEventObject.h | 6 +- Source/Common/imstkModule.cpp | 59 ++++++++++++++++ Source/Common/imstkModule.h | 39 ++--------- .../VTKRenderer/imstkVTKRenderer.cpp | 1 - Source/Scene/imstkInteractionPair.h | 8 +-- Source/Scene/imstkObjectInteractionPair.h | 4 +- Source/Scene/imstkPbdObjectCuttingPair.h | 2 +- Source/SceneEntities/Camera/imstkCamera.cpp | 33 +++++++++ Source/SceneEntities/Camera/imstkCamera.h | 70 +++++++------------ Source/SceneEntities/Lights/imstkLight.h | 7 +- .../Objects/imstkAnimationModel.h | 1 - .../Objects/imstkVisualModel.cpp | 14 ++++ .../SceneEntities/Objects/imstkVisualModel.h | 12 +--- 15 files changed, 154 insertions(+), 107 deletions(-) create mode 100644 Source/Common/imstkModule.cpp create mode 100644 Source/SceneEntities/Camera/imstkCamera.cpp diff --git a/Source/Common/CMakeLists.txt b/Source/Common/CMakeLists.txt index b0481037b..c79c608b4 100644 --- a/Source/Common/CMakeLists.txt +++ b/Source/Common/CMakeLists.txt @@ -7,7 +7,6 @@ imstk_add_library( Common Eigen3::Eigen g3log tbb - # tsimd ) #----------------------------------------------------------------------------- diff --git a/Source/Common/TaskGraph/imstkTaskGraph.h b/Source/Common/TaskGraph/imstkTaskGraph.h index b38b474df..1cdacadee 100644 --- a/Source/Common/TaskGraph/imstkTaskGraph.h +++ b/Source/Common/TaskGraph/imstkTaskGraph.h @@ -142,7 +142,7 @@ public: void addEdge(std::shared_ptr<TaskNode> srcNode, std::shared_ptr<TaskNode> destNode); /// - /// \brief Attachs another TaskGraph as a subgraph (copies nodes and edges, then connects source->subgraph::source, subgraph::sink->sink), + /// \brief Attaches another TaskGraph as a subgraph (copies nodes and edges, then connects source->subgraph::source, subgraph::sink->sink), /// source and sink must exist in this graph. Also serves as a graph sum between this and subgraph /// void nestGraph(std::shared_ptr<TaskGraph> subgraph, std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink); @@ -190,7 +190,7 @@ public: static std::shared_ptr<TaskGraph> resolveCriticalNodes(std::shared_ptr<TaskGraph> graph); /// - /// \brief Remove redudant edges. Removal is such that all vertices are still reachable and graph goes from source->sink + /// \brief Remove redundant edges. Removal is such that all vertices are still reachable and graph goes from source->sink /// returns nullptr if failed. Only fails if graph is cyclic. /// static std::shared_ptr<TaskGraph> transitiveReduce(std::shared_ptr<TaskGraph> graph); diff --git a/Source/Common/imstkEventObject.h b/Source/Common/imstkEventObject.h index 79b5eede7..aa2dd08cb 100644 --- a/Source/Common/imstkEventObject.h +++ b/Source/Common/imstkEventObject.h @@ -102,10 +102,10 @@ static void disconnect(EventObject*, EventObject*, std::string (*)()); /// \class EventObject /// /// \brief EventObject is the base class for all objects in iMSTK that -/// can recieve and emit events. It supports direct and queued observer functions. -/// Direct observers recieve events immediately on the same thread +/// can receive and emit events. It supports direct and queued observer functions. +/// Direct observers receive events immediately on the same thread /// This can either be posted on an object or be a function pointer -/// Queued observers recieve events within their queue which they can process whenever +/// Queued observers receive events within their queue which they can process whenever /// they like. /// These can be connected with the connect/queuedConnect/disconnect functions /// \todo ThreadObject affinity diff --git a/Source/Common/imstkModule.cpp b/Source/Common/imstkModule.cpp new file mode 100644 index 000000000..6ce00bc20 --- /dev/null +++ b/Source/Common/imstkModule.cpp @@ -0,0 +1,59 @@ +/*========================================================================= + + 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 "imstkModule.h" + +namespace imstk +{ +void +Module::update() +{ + if (m_init && !m_paused) + { + if (sleepDelay != 0.0) + { + std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(sleepDelay)); + } + + if (muteUpdateEvents) + { + this->updateModule(); + } + else + { + this->postEvent(Event(Module::preUpdate())); + this->updateModule(); + this->postEvent(Event(Module::postUpdate())); + } + } +} + +void +Module::uninit() +{ + // Can only uninit if, init'd + if (m_init) + { + uninitModule(); + m_init = false; + } +} +}// imstk diff --git a/Source/Common/imstkModule.h b/Source/Common/imstkModule.h index 7d2f88e7c..724083eaa 100644 --- a/Source/Common/imstkModule.h +++ b/Source/Common/imstkModule.h @@ -74,7 +74,7 @@ public: public: /// - /// \brief Get/Set the timestep + /// \brief Get/Set the time step /// double getDt() const { return m_dt; } void setDt(const double dt) { m_dt = dt; } @@ -90,6 +90,9 @@ public: bool getPaused() const { return m_paused; } void setPaused(const bool paused) { m_paused = paused; } + /// + /// \brief Set/Get the execution type (see imstk::ExecutionType) + /// ExecutionType getExecutionType() const { return m_executionType; } void setExecutionType(const ExecutionType type) { m_executionType = type; } @@ -101,37 +104,9 @@ public: public: void init() { m_init = initModule(); } - void update() - { - if (m_init && !m_paused) - { - if (sleepDelay != 0.0) - { - std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(sleepDelay)); - } - - if (muteUpdateEvents) - { - this->updateModule(); - } - else - { - this->postEvent(Event(Module::preUpdate())); - this->updateModule(); - this->postEvent(Event(Module::postUpdate())); - } - } - } - - void uninit() - { - // Can only uninit if, init'd - if (m_init) - { - uninitModule(); - m_init = false; - } - } + void update(); + + void uninit(); public: virtual bool initModule() = 0; diff --git a/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp b/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp index 718501404..19a809dd7 100644 --- a/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp +++ b/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp @@ -418,7 +418,6 @@ VTKRenderer::updateCamera() m_camera->SetViewUp(up[0], up[1], up[2]); m_camera->SetViewAngle(cam->getFieldOfView()); m_camera->SetClippingRange(cam->getNearZ(), cam->getFarZ()); - m_camera->SetClippingRange(cam->getNearZ(), cam->getFarZ()); } void diff --git a/Source/Scene/imstkInteractionPair.h b/Source/Scene/imstkInteractionPair.h index 585bba397..7714d9192 100644 --- a/Source/Scene/imstkInteractionPair.h +++ b/Source/Scene/imstkInteractionPair.h @@ -50,10 +50,10 @@ public: const Outputs& getTaskNodeOutputs() const { return m_taskNodeOutputs; } public: - /// - /// \brief Modifies the computational graph - /// - void compute(); +/// +/// \brief Modifies the computational graph +/// +//void compute(); protected: Inputs m_taskNodeInputs; ///> The interacting nodes diff --git a/Source/Scene/imstkObjectInteractionPair.h b/Source/Scene/imstkObjectInteractionPair.h index 35f92499e..14bed089b 100644 --- a/Source/Scene/imstkObjectInteractionPair.h +++ b/Source/Scene/imstkObjectInteractionPair.h @@ -31,7 +31,7 @@ class SceneObject; /// \class ObjectInteractionPair /// /// \brief This class defines an interaction between two SceneObjects -/// An interaction is a function occuring between two SceneObjects at some point +/// An interaction is a function occurring between two SceneObjects at some point /// class ObjectInteractionPair : public InteractionPair { @@ -46,7 +46,7 @@ protected: virtual ~ObjectInteractionPair() override = default; public: - /// \brief TODO + /// \brief Return the pair of scene objects involved in the interaction const SceneObjectPair& getObjectsPair() const { return m_objects; } public: diff --git a/Source/Scene/imstkPbdObjectCuttingPair.h b/Source/Scene/imstkPbdObjectCuttingPair.h index f045183f2..3f9a2d9f6 100644 --- a/Source/Scene/imstkPbdObjectCuttingPair.h +++ b/Source/Scene/imstkPbdObjectCuttingPair.h @@ -71,7 +71,7 @@ protected: std::shared_ptr<VecDataArray<int, 3>> elements); /// - /// \brief Modify exsiting elements of pbdObj + /// \brief Modify existing elements of pbdObj /// void modifyTriangles(std::shared_ptr<SurfaceMesh> pbdMesh, std::shared_ptr<std::vector<size_t>> elementIndices, diff --git a/Source/SceneEntities/Camera/imstkCamera.cpp b/Source/SceneEntities/Camera/imstkCamera.cpp new file mode 100644 index 000000000..945d1ded6 --- /dev/null +++ b/Source/SceneEntities/Camera/imstkCamera.cpp @@ -0,0 +1,33 @@ +/*========================================================================= + + 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 "imstkCamera.h" + +namespace imstk +{ +void +Camera::print() +{ + std::cout << "CamPos: " << m_position[0] << ", " << m_position[1] << ", " << m_position[2] << std::endl; + std::cout << "FocalPoint: " << m_focalPoint[0] << ", " << m_focalPoint[1] << ", " << m_focalPoint[2] << std::endl; + std::cout << "Up: " << m_viewUp[0] << ", " << m_viewUp[1] << ", " << m_viewUp[2] << std::endl; +} +} \ No newline at end of file diff --git a/Source/SceneEntities/Camera/imstkCamera.h b/Source/SceneEntities/Camera/imstkCamera.h index a4e84dd87..b5f2d368a 100644 --- a/Source/SceneEntities/Camera/imstkCamera.h +++ b/Source/SceneEntities/Camera/imstkCamera.h @@ -81,44 +81,34 @@ public: /// \brief Get camera view matrix /// \returns Camera view matrix reference /// - Mat4d& getView() { return m_view; } + inline Mat4d& getView() { return m_view; } /// /// \brief Get the inverse view matrix /// - const Mat4d& getInvView() { return m_invView; } + inline const Mat4d& getInvView() { return m_invView; } /// /// \brief Set the camera view matrix /// - void setView(const Mat4d& view) + inline void setView(const Mat4d& view) { m_viewModified = false; m_view = view; m_invView = m_view.inverse(); } - /// - /// \brief Get camera projection matrix - /// - //const Mat4d& getProj() { return m_proj; } - - /// - /// \brief Set camera projection matrix - /// - //void setProj(const Mat4d& proj) { m_proj = proj; } - /// /// \brief Gets the field of view /// \returns vertical field of view in degrees /// - const double getFieldOfView() const { return m_fieldOfView; } + inline const double getFieldOfView() const { return m_fieldOfView; } /// /// \brief Sets the field of view /// \param vertical field of view in degrees /// - void setFieldOfView(const double fov) + inline void setFieldOfView(const double fov) { m_fieldOfView = fov; //m_projModified = true; @@ -129,20 +119,19 @@ public: /// note: You lose depth accuracy as the range between near and far increases /// could cause z fighting /// - void setNearZ(const double nearZ) { m_nearZ = nearZ; } - - const double getNearZ() const { return m_nearZ; } + inline void setNearZ(const double nearZ) { m_nearZ = nearZ; } + inline const double getNearZ() const { return m_nearZ; } /// /// \brief Set clipping near /// note: You lose depth accuracy as the range between near and far increases /// could cause z fighting /// - void setFarZ(const double farZ) { m_farZ = farZ; } + inline void setFarZ(const double farZ) { m_farZ = farZ; } - const double getFarZ() const { return m_farZ; } + inline const double getFarZ() const { return m_farZ; } - virtual void update() + inline virtual void update() { if (m_viewModified) { @@ -156,25 +145,24 @@ public: }*/ } -public: /// /// \brief Gets the camera position /// \returns camera position /// - const Vec3d& getPosition() const { return m_position; } + inline const Vec3d& getPosition() const { return m_position; } /// /// \brief Sets the camera position /// - void setPosition(const Vec3d& pos) + inline void setPosition(const Vec3d& pos) { m_position = pos; m_viewModified = true; } - void setPosition(const double x, - const double y, - const double z) + inline void setPosition(const double x, + const double y, + const double z) { setPosition(Vec3d(x, y, z)); } @@ -184,20 +172,20 @@ public: /// The focal point is the point that the camera points to /// \returns Focal point position /// - const Vec3d& getFocalPoint() const { return m_focalPoint; } + inline const Vec3d& getFocalPoint() const { return m_focalPoint; } /// /// \brief Sets the focal point /// - void setFocalPoint(const Vec3d& focalPt) + inline void setFocalPoint(const Vec3d& focalPt) { m_focalPoint = focalPt; m_viewModified = true; } - void setFocalPoint(const double x, - const double y, - const double z) + inline void setFocalPoint(const double x, + const double y, + const double z) { setFocalPoint(Vec3d(x, y, z)); } @@ -206,20 +194,20 @@ public: /// \brief Get the up vector /// \returns up vector of camera /// - const Vec3d& getViewUp() const { return m_viewUp; } + inline const Vec3d& getViewUp() const { return m_viewUp; } /// /// \brief Set the up vector /// - void setViewUp(const Vec3d& up) + inline void setViewUp(const Vec3d& up) { m_viewUp = up.normalized(); m_viewModified = true; } - void setViewUp(const double x, - const double y, - const double z) + inline void setViewUp(const double x, + const double y, + const double z) { setViewUp(Vec3d(x, y, z)); } @@ -227,12 +215,7 @@ public: /// /// \brief Utility function to quickly print cam stats /// - void print() - { - std::cout << "CamPos: " << m_position[0] << ", " << m_position[1] << ", " << m_position[2] << std::endl; - std::cout << "FocalPoint: " << m_focalPoint[0] << ", " << m_focalPoint[1] << ", " << m_focalPoint[2] << std::endl; - std::cout << "Up: " << m_viewUp[0] << ", " << m_viewUp[1] << ", " << m_viewUp[2] << std::endl; - } + void print(); protected: // Base camera values @@ -242,7 +225,6 @@ protected: bool m_viewModified = true; //bool m_projModified = true; -protected: // Base projection parameters double m_fieldOfView = 40.0; ///> field of view in degrees double m_nearZ = 0.01; ///> near plane of the camera diff --git a/Source/SceneEntities/Lights/imstkLight.h b/Source/SceneEntities/Lights/imstkLight.h index 8b2106aaf..e3e5c9699 100644 --- a/Source/SceneEntities/Lights/imstkLight.h +++ b/Source/SceneEntities/Lights/imstkLight.h @@ -77,11 +77,6 @@ public: /// void switchOn() { m_switchState = true; } - /// - /// \brief Get the status (On/off) of the light - /// - bool isOff() const { return m_switchState; } - /// /// \brief Switch the light Off /// @@ -105,7 +100,7 @@ public: /// /// \brief Set the light intensity. This value is unbounded. /// - void setIntensity(double intensity) { m_intensity = (float)intensity; } + void setIntensity(const double intensity) { m_intensity = (float)intensity; } protected: Light(const LightType& type) : SceneEntity(), m_type(type) { } diff --git a/Source/SceneEntities/Objects/imstkAnimationModel.h b/Source/SceneEntities/Objects/imstkAnimationModel.h index 924fe8632..66c2f16d1 100644 --- a/Source/SceneEntities/Objects/imstkAnimationModel.h +++ b/Source/SceneEntities/Objects/imstkAnimationModel.h @@ -37,7 +37,6 @@ public: /// \brief Constructor /// explicit AnimationModel(std::shared_ptr<Geometry> geometry); - AnimationModel() = delete; /// diff --git a/Source/SceneEntities/Objects/imstkVisualModel.cpp b/Source/SceneEntities/Objects/imstkVisualModel.cpp index 1b3f017a3..74f58c226 100644 --- a/Source/SceneEntities/Objects/imstkVisualModel.cpp +++ b/Source/SceneEntities/Objects/imstkVisualModel.cpp @@ -50,6 +50,20 @@ VisualModel::VisualModel() : m_renderMaterial(std::make_shared<RenderMaterial>() { } +void +VisualModel::setRenderMaterial(std::shared_ptr<RenderMaterial> renderMaterial) +{ + m_renderMaterial = renderMaterial; + this->postModified(); +} + +void +VisualModel::setIsVisible(const bool visible) +{ + m_isVisible = visible; + this->postModified(); +} + bool VisualModel::getRenderDelegateCreated(Renderer* ren) { diff --git a/Source/SceneEntities/Objects/imstkVisualModel.h b/Source/SceneEntities/Objects/imstkVisualModel.h index 8fab729f2..21494f9be 100644 --- a/Source/SceneEntities/Objects/imstkVisualModel.h +++ b/Source/SceneEntities/Objects/imstkVisualModel.h @@ -81,11 +81,7 @@ public: /// /// \brief Set/Get render material /// - void setRenderMaterial(std::shared_ptr<RenderMaterial> renderMaterial) - { - m_renderMaterial = renderMaterial; - this->postModified(); - } + void setRenderMaterial(std::shared_ptr<RenderMaterial> renderMaterial); std::shared_ptr<RenderMaterial> getRenderMaterial() const { return m_renderMaterial; } @@ -95,11 +91,7 @@ public: void show() { setIsVisible(true); } void hide() { setIsVisible(false); } bool isVisible() const { return m_isVisible; } - void setIsVisible(const bool visible) - { - m_isVisible = visible; - this->postModified(); - } + void setIsVisible(const bool visible); /// /// \brief Get/Set whether the delegate has been created -- GitLab