iMSTK
Interactive Medical Simulation Toolkit
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
imstkCollidingObject.h
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 #pragma once
8 
9 #include "imstkSceneObject.h"
10 #include "imstkMacros.h"
11 #include "imstkMath.h"
12 #include "imstkCollisionData.h"
13 
14 #include <unordered_map>
15 
16 namespace imstk
17 {
18 class GeometryMap;
19 
26 {
27 public:
28  CollidingObject(const std::string& name = "CollidingObject") : SceneObject(name) { }
29  ~CollidingObject() override = default;
30 
31  IMSTK_TYPE_NAME(CollidingObject)
32 
33 
34  std::shared_ptr<Geometry> getCollidingGeometry() const;
37  void setCollidingGeometry(std::shared_ptr<Geometry> geometry);
39 
43  std::shared_ptr<GeometryMap> getCollidingToVisualMap() const;
44  void setCollidingToVisualMap(std::shared_ptr<GeometryMap> map);
46 
50  void updateGeometries() override;
51 
55  bool initialize() override;
56 
57  void update() override;
58 
61  bool didCollide(std::shared_ptr<CollidingObject> other);
62 
64  void addCollision(std::shared_ptr<CollidingObject> other, std::shared_ptr<imstk::CollisionData> data);
65 
66  const std::vector<std::shared_ptr<imstk::CollisionData>>& getCollisions(std::shared_ptr<CollidingObject> other) const;
67 
68 protected:
69  void postModifiedAll() override;
70 
72  void clearCollisions();
73 
74  std::shared_ptr<Geometry> m_collidingGeometry = nullptr;
75  std::shared_ptr<GeometryMap> m_collidingToVisualMap = nullptr;
76  Vec3d m_force = Vec3d::Zero();
77 
78  std::unordered_map<std::shared_ptr<CollidingObject>, std::vector<std::shared_ptr<CollisionData>>> m_collisions;
79 };
80 
81 std::string getCDType(const CollidingObject& obj1, const CollidingObject& obj2);
82 } // namespace imstk
void updateGeometries() override
Updates the geometries from the maps (if defined)
void postModifiedAll() override
Posts modified for all 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.
std::shared_ptr< GeometryMap > m_collidingToVisualMap
Maps transformations to visual geometry.
bool didCollide(std::shared_ptr< CollidingObject > other)
Base class for all scene objects. A scene object can optionally be visible and collide with other sce...
A SceneObject with a geometry for collision.
std::shared_ptr< Geometry > m_collidingGeometry
Geometry for collisions.