diff --git a/Base/Core/imstkMath.h b/Base/Core/imstkMath.h index af35da39baeade33d0322d8a7fa1684a9b07ea2a..b64aae9432e82860a63b6620c59f3b1c9a69f923 100644 --- a/Base/Core/imstkMath.h +++ b/Base/Core/imstkMath.h @@ -41,8 +41,8 @@ using Vec4f = Eigen::Vector4f; using Vec4d = Eigen::Vector4d; // Dynamic size vector -using VecNf = Eigen::VectorXf; -using VecNd = Eigen::VectorXd; +using Vectorf = Eigen::VectorXf; +using Vectord = Eigen::VectorXd; // Quaternion using Quatf = Eigen::Quaternion<float,Eigen::DontAlign>; diff --git a/Base/Scene/Object/imstkDeformableBodyModel.h b/Base/Scene/Object/imstkDeformableBodyModel.h index 77e41eaa40e90d8f57ffe350b0ddc35a328cd844..eb9893e40fe64498928230204cdbd1a74409ee17 100644 --- a/Base/Scene/Object/imstkDeformableBodyModel.h +++ b/Base/Scene/Object/imstkDeformableBodyModel.h @@ -54,7 +54,7 @@ public: protected: //std::shared_ptr<ForceModel> forceModel; ///> Mathematical model for intenal forces - std::shared_ptr<TimeIntegrator> timeIntegrator; ///> Time integrator + std::shared_ptr<TimeIntegrator> m_timeIntegrator; ///> Time integrator }; } diff --git a/Base/Scene/Object/imstkDynamicObject.h b/Base/Scene/Object/imstkDynamicObject.h index ba93635fd40fdafb606909034af6933366e2abca..a7610d0701198a5779bac60f39f5e84ea2eebfb3 100644 --- a/Base/Scene/Object/imstkDynamicObject.h +++ b/Base/Scene/Object/imstkDynamicObject.h @@ -74,6 +74,7 @@ protected: std::shared_ptr<Geometry> m_physicsGeometry; ///> Geometry used for Physics + //Maps std::shared_ptr<GeometryMap> m_physicsToCollidingGeomMap; ///> Maps from Physics to collision geometry std::shared_ptr<GeometryMap> m_physicsToVisualGeomMap; ///> Maps from Physics to visual geometry }; diff --git a/Base/Scene/Object/imstkKinematicState.cpp b/Base/Scene/Object/imstkKinematicState.cpp new file mode 100644 index 0000000000000000000000000000000000000000..936d6155cb8c482237a7308f54a64e21a3bb3a12 --- /dev/null +++ b/Base/Scene/Object/imstkKinematicState.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 "imstkKinematicState.h" + +namespace imstk +{ + +KinematicState::KinematicState(const T& u, const T& v) +{ + m_displacement = u; + m_velocity = v; +} + +} diff --git a/Base/Scene/Object/imstkKinematicState.h b/Base/Scene/Object/imstkKinematicState.h new file mode 100644 index 0000000000000000000000000000000000000000..cc2a7d995676a855cf39b01db9060c6bc40bd375 --- /dev/null +++ b/Base/Scene/Object/imstkKinematicState.h @@ -0,0 +1,62 @@ +/*========================================================================= + + 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 imstkKinematicState_h +#define imstkKinematicState_h + + +namespace imstk +{ + +/// +/// \class KinematicState +/// +/// \brief Kinematic state of the body in time +/// +template<class T> +class KinematicState +{ +public: + + /// + /// \brief Constructor + /// + KinematicState() = default; + KinematicState(const T& u, const T& v); + + /// + /// \brief Set the state to a given one + /// + void setState(const T& u, const T& v); + + /// + /// \brief Destructor + /// + ~KinematicState(){} + +protected: + T m_displacement; + T m_velocity; +}; + +} + +#endif // ifndef imstkKinematicState_h diff --git a/Base/SceneElements/Objects/imstkDeformableObject.h b/Base/SceneElements/Objects/imstkDeformableObject.h index 9399883ccf9219ebab59365f6802ed9944da0efd..91859183f763f7d3e294a3fa066fe87466fef012 100644 --- a/Base/SceneElements/Objects/imstkDeformableObject.h +++ b/Base/SceneElements/Objects/imstkDeformableObject.h @@ -27,6 +27,9 @@ #include "imstkDynamicObject.h" #include "imstkDynamicalModel.h" +#include "imstkTimeIntegrator.h" +#include "imstkKinematicState.h" +#include "imstkMath.h" namespace imstk { @@ -37,6 +40,7 @@ namespace imstk { /// class DeformableObject : public DynamicObject { + using objectState = KinematicState <Vectord>; public: /// @@ -52,9 +56,47 @@ public: /// ~DeformableObject() = default; + /// + /// \brief Initialize the kinematic state of the body + /// + void initializeState(); + void initializeState(const Vectord& p, const Vectord& v); + + // Get/Set States of the body + const Vectord& getDisplacements() const; + const Vectord& getPrevDisplacements() const; + const Vectord& getVelocities() const; + const Vectord& getPrevVelocities() const; + + /// + /// \brief Return the current state of the body + /// + std::shared_ptr<objectState> getCurrentState(); + + /// + /// \brief Return the current state of the body + /// + std::shared_ptr<objectState> getPreviousState(); + + /// + /// \brief Reset the current state to the initial state + /// + virtual void resetToInitialState(); + + /// + /// \brief Set the integration scheme used to solve the ODE system. + /// + void setTimeIntegrator(TimeIntegratorType integrator); + protected: - std::shared_ptr<DynamicalModel> dynamicalModel; ///> Dynamical model + std::shared_ptr<DynamicalModel> m_dynamicalModel; ///> Dynamical model + + // States + std::shared_ptr<objectState> m_initialState; ///> Initial state + std::shared_ptr<objectState> m_currentState; ///> Current state + std::shared_ptr<objectState> m_previousState;///> Previous state + //std::shared_ptr<kinematicState> m_newState; ///> Storage for the next state }; }