From de74bde7fb510ecf4be509adce1802f13c326a80 Mon Sep 17 00:00:00 2001 From: Sreekanth Arikatla <sreekanth.arikatla@kitware.com> Date: Wed, 18 May 2016 13:30:30 -0400 Subject: [PATCH] ENH: Adds time integrator class Adds time integrator which only sets rules for finite difference in time. Adds comments for DeformableObject class --- Base/Scene/Object/imstkDeformableObject.cpp | 8 +++ Base/Scene/Object/imstkDeformableObject.h | 30 +++++++- Base/Scene/Object/imstkSceneObject.h | 1 + Base/Scene/Object/imstkTimeIntegrator.cpp | 66 +++++++++++++++++ Base/Scene/Object/imstkTimeIntegrator.h | 78 +++++++++++++++++++++ 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 Base/Scene/Object/imstkTimeIntegrator.cpp create mode 100644 Base/Scene/Object/imstkTimeIntegrator.h diff --git a/Base/Scene/Object/imstkDeformableObject.cpp b/Base/Scene/Object/imstkDeformableObject.cpp index a1c33f055..93d8a51b1 100644 --- a/Base/Scene/Object/imstkDeformableObject.cpp +++ b/Base/Scene/Object/imstkDeformableObject.cpp @@ -22,6 +22,7 @@ #include "imstkDeformableObject.h" namespace imstk { + std::shared_ptr<Geometry> DeformableObject::getPhysicsGeometry() const { @@ -33,4 +34,11 @@ DeformableObject::setPhysicsGeometry(std::shared_ptr<Geometry> geometry) { m_physicsGeometry = geometry; } + +int +DeformableObject::getNumOfDOF() const +{ + return numDOF; +} + } diff --git a/Base/Scene/Object/imstkDeformableObject.h b/Base/Scene/Object/imstkDeformableObject.h index 81ae48da1..bd05cc19c 100644 --- a/Base/Scene/Object/imstkDeformableObject.h +++ b/Base/Scene/Object/imstkDeformableObject.h @@ -23,6 +23,7 @@ #define imstkDeformableObject_h #include <memory> +#include <string> #include "imstkCollidingObject.h" @@ -31,25 +32,50 @@ namespace imstk { class Geometry; class GeometryMap; +/// +/// \class DeformableObject +/// +/// \brief Base class for scene objects that deform +/// class DeformableObject : public CollidingObject { public: + /// + /// \brief Constructor + /// DeformableObject(std::string name) : CollidingObject(name) { m_type = Type::Deformable; } + /// + /// \brief Destructor + /// ~DeformableObject() = default; + /// + /// \brief Returns the geometry used for Physics computations + /// std::shared_ptr<Geometry> getPhysicsGeometry() const; + + /// + /// \brief Assigns the geometry used for Physics related computations + /// void setPhysicsGeometry(std::shared_ptr<Geometry> geometry); + /// + /// \brief Returns the number of degree of freedom + /// + int getNumOfDOF() const; + protected: - std::shared_ptr<Geometry> m_physicsGeometry; ///> Geometry for collisions - std::shared_ptr<GeometryMap> m_physicsToCollidingMap; ///> Maps transformations to colliding geometry + std::shared_ptr<Geometry> m_physicsGeometry; ///> Geometry used for Physics + std::shared_ptr<GeometryMap> m_physicsToCollidingGeomMap; ///> Maps transformations to colliding geometry + std::shared_ptr<GeometryMap> m_physicsToVisualGeomMap; ///> Maps transformations to colliding geometry + int numDOF; ///> Number of degree of freedom of the body in the discretized model }; } diff --git a/Base/Scene/Object/imstkSceneObject.h b/Base/Scene/Object/imstkSceneObject.h index d510d762e..e1b4bd2cd 100644 --- a/Base/Scene/Object/imstkSceneObject.h +++ b/Base/Scene/Object/imstkSceneObject.h @@ -23,6 +23,7 @@ #define imstkSceneObject_h #include <memory> +#include <string> namespace imstk { diff --git a/Base/Scene/Object/imstkTimeIntegrator.cpp b/Base/Scene/Object/imstkTimeIntegrator.cpp new file mode 100644 index 000000000..c29d56dad --- /dev/null +++ b/Base/Scene/Object/imstkTimeIntegrator.cpp @@ -0,0 +1,66 @@ +/*========================================================================= + +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 "imstkTimeIntegrator.h" + +namespace imstk { + +TimeIntegrator::TimeIntegrator(const timeIntegratorType type) +{ + this->setType(type); +} + +void +TimeIntegrator::setType(const timeIntegratorType type) +{ + this->m_type = type; + this->setCoefficients(type); +} + +const Type& +TimeIntegrator::getType() const +{ + return m_type; +} + +void +TimeIntegrator::setCoefficients(const timeIntegratorType type) +{ + switch (type) { + case timeIntegratorType::backwardEuler: + m_alpha = {1, 0, 0}; + m_beta = {1, -1, 0}; + m_gamma = {1, -2, -1}; + break; + + case timeIntegratorType::forwardEuler: + case timeIntegratorType::newmarkBeta: + case timeIntegratorType::centralDifference: + LOG(WARNING) << "Type of the time integrator not supported!"; + break; + + default: + LOG(WARNING) << "Type of the time integrator not identified!"; + break; + } +} + +} diff --git a/Base/Scene/Object/imstkTimeIntegrator.h b/Base/Scene/Object/imstkTimeIntegrator.h new file mode 100644 index 000000000..73ba427d3 --- /dev/null +++ b/Base/Scene/Object/imstkTimeIntegrator.h @@ -0,0 +1,78 @@ +/*========================================================================= + + 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 imstkTimeIntegrator_h +#define imstkTimeIntegrator_h + +namespace imstk { + +/// +/// \class TimeIntegrator +/// +/// \brief This class defines the time integrators of various types. +/// It only sets the rules of how the velocity (or equivalent) and +/// acceleration (or equivalent) of the present time in terms of +/// positions (or equivalent) from previous time steps. +/// +class TimeIntegrator +{ + enum class timeIntegratorType + { + forwardEuler, + backwardEuler, + newmarkBeta, + centralDifference + }; + +public: + /// + /// \brief Constructor + /// + TimeIntegrator(const timeIntegratorType type); + + /// + /// \brief Destructor + /// + ~TimeIntegrator() = default; + + /// + /// \brief Set/Get type of the time integrator + /// + void setType(const timeIntegratorType type); + const Type& getType() const; + + /// + /// \brief Set coefficients for a given time integrator type + /// + void setCoefficients(const timeIntegratorType type); + +protected: + timeIntegratorType m_type; ///> Type of the time integrator + + // Coefficients of the time integrator + double m_alpha[3]; + double m_gamma[3]; + double m_beta[3]; +}; + +} + +#endif // ifndef imstkTimeIntegrator_h -- GitLab