iMSTK
Interactive Medical Simulation Toolkit
imstkRigidObject2.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkRigidObject2.h"
8 #include "imstkLogger.h"
9 #include "imstkRbdConstraint.h"
10 #include "imstkRigidBodyModel2.h"
11 
12 namespace imstk
13 {
14 bool
16 {
19  return true;
20 }
21 
22 std::shared_ptr<RigidBodyModel2>
24 {
25  m_rigidBodyModel2 = std::dynamic_pointer_cast<RigidBodyModel2>(m_dynamicalModel);
26  return m_rigidBodyModel2;
27 }
28 
29 void
30 RigidObject2::setDynamicalModel(std::shared_ptr<AbstractDynamicalModel> dynaModel)
31 {
32  // todo: If already has another model, should remove the corresponding body?
33  m_rigidBodyModel2 = std::dynamic_pointer_cast<RigidBodyModel2>(dynaModel);
34  m_dynamicalModel = dynaModel;
35  m_rigidBody = m_rigidBodyModel2->addRigidBody();
36 }
37 
38 void
40 {
41  // Apply the transform back to the geometry
42  // If called before body is init'd use initial pose
43  if (m_rigidBody->m_pos != nullptr)
44  {
45  m_physicsGeometry->setTranslation(m_rigidBody->getPosition());
46  }
47  else
48  {
49  m_physicsGeometry->setTranslation(m_rigidBody->m_initPos);
50  }
51  // If called before body is init'd use initial pose
52  if (m_rigidBody->m_orientation != nullptr)
53  {
54  m_physicsGeometry->setRotation(m_rigidBody->getOrientation());
55  }
56  else
57  {
58  m_physicsGeometry->setRotation(m_rigidBody->m_initOrientation);
59  }
60  m_physicsGeometry->updatePostTransformData();
61 
63 }
64 } // namespace imstk
void setDynamicalModel(std::shared_ptr< AbstractDynamicalModel > dynaModel) override
Sets the model, and creates the body within the model.
std::shared_ptr< RigidBody > m_rigidBody
Gives the actual body within the model.
Compound Geometry.
virtual void updatePhysicsGeometry()
Update only the physics geometry and apply collision map.
This class implements a constraint based rigid body linear system with pgs solver.
bool initialize() override
Initialize the scene object.
std::shared_ptr< AbstractDynamicalModel > m_dynamicalModel
Dynamical model.
void updateGeometries() final
Update the physics geometry and the apply the maps (if defined)
void updatePhysicsGeometry() override
Updates the physics geometry of the object.
std::shared_ptr< RigidBodyModel2 > getRigidBodyModel2()
Add local force at a position relative to object.
bool initialize() override
Initialize the rigid scene object.
std::shared_ptr< Geometry > m_physicsGeometry
Geometry used for Physics.