iMSTK
Interactive Medical Simulation Toolkit
imstkCollidingObject.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 "imstkCollidingObject.h"
8 #include "imstkCDObjectFactory.h"
9 #include "imstkGeometry.h"
10 #include "imstkGeometryMap.h"
11 
12 namespace imstk
13 {
14 bool
16 {
18  {
19  return false;
20  }
21 
23  {
24  m_collidingToVisualMap->compute();
25  }
26 
27  return true;
28 }
29 
30 void
32 {
33  for (auto& item : m_collisions)
34  {
35  item.second.clear();
36  }
37 }
38 
39 void
40 CollidingObject::addCollision(std::shared_ptr<CollidingObject> other, std::shared_ptr<CollisionData> data)
41 {
42  m_collisions[other].push_back(data);
43 }
44 
45 const std::vector<std::shared_ptr<imstk::CollisionData>>&
46 CollidingObject::getCollisions(std::shared_ptr<CollidingObject> other) const
47 {
48  static const std::vector<std::shared_ptr<imstk::CollisionData>> empty;
49 
50  if (m_collisions.find(other) != m_collisions.end())
51  {
52  return m_collisions.at(other);
53  }
54  else
55  {
56  return empty;
57  }
58 }
59 
60 void
62 {
65 }
66 
67 bool
68 CollidingObject::didCollide(std::shared_ptr<CollidingObject> other)
69 {
70  return !m_collisions[other].empty();
71 }
72 
73 std::shared_ptr<Geometry>
74 CollidingObject::getCollidingGeometry() const
75 {
76  return m_collidingGeometry;
77 }
78 
79 void
80 CollidingObject::setCollidingGeometry(std::shared_ptr<Geometry> geometry)
81 {
82  m_collidingGeometry = geometry;
83 }
84 
85 std::shared_ptr<GeometryMap>
86 CollidingObject::getCollidingToVisualMap() const
87 {
89 }
90 
91 void
92 CollidingObject::setCollidingToVisualMap(std::shared_ptr<GeometryMap> map)
93 {
95 }
96 
97 void
99 {
101  {
102  m_collidingToVisualMap->update();
103  m_collidingToVisualMap->getChildGeometry()->postModified();
104  }
106 }
107 
108 std::string
109 getCDType(const CollidingObject& obj1, const CollidingObject& obj2)
110 {
111  std::string cdType = CDObjectFactory::getCDType(*obj1.getCollidingGeometry(), *obj2.getCollidingGeometry());
112  return cdType;
113 }
114 
115 void
117 {
118  if (m_collidingGeometry != nullptr)
119  {
120  m_collidingGeometry->postModified();
121  }
123 }
124 } // namespace imstk
void updateGeometries() override
Updates the geometries from the maps (if defined)
void postModifiedAll() override
Posts modified for all geometries.
virtual void updateGeometries()
Update the geometries.
Compound Geometry.
void clearCollisions()
resets the collision information
void update() override
Update the SceneObject, called during scene update.
bool initialize() override
Initialize the scene object.
void addCollision(std::shared_ptr< CollidingObject > other, std::shared_ptr< imstk::CollisionData > data)
Add data for collision with the object `other.
virtual bool initialize()
Initialize the scene object.
std::shared_ptr< GeometryMap > m_collidingToVisualMap
Maps transformations to visual geometry.
virtual void update()
Update the SceneObject, called during scene update.
static std::string getCDType(const Geometry &obj1, const Geometry &obj2)
Get the CD type from the types of objects colliding.
bool didCollide(std::shared_ptr< CollidingObject > other)
A SceneObject with a geometry for collision.
virtual void postModifiedAll()
Posts modified for all geometries.
std::shared_ptr< Geometry > m_collidingGeometry
Geometry for collisions.