opensurgsim
Representation.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2015, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_COLLISION_REPRESENTATION_H
17 #define SURGSIM_COLLISION_REPRESENTATION_H
18 
19 #include <boost/thread/mutex.hpp>
20 #include <list>
21 #include <memory>
22 #include <unordered_map>
23 #include <unordered_set>
24 
25 #include "SurgSim/DataStructures/BufferedValue.h"
26 #include "SurgSim/Framework/Log.h"
27 #include "SurgSim/Framework/Representation.h"
28 #include "SurgSim/Math/Aabb.h"
29 #include "SurgSim/Math/Shape.h"
30 
31 namespace SurgSim
32 {
33 
34 namespace Math
35 {
36 class Shape;
37 };
38 
39 namespace Physics
40 {
41 class Representation;
42 };
43 
44 namespace Collision
45 {
46 struct Contact;
47 class Representation;
48 
49 typedef std::unordered_map<std::shared_ptr<SurgSim::Collision::Representation>,
50  std::list<std::shared_ptr<SurgSim::Collision::Contact>>> ContactMapType;
51 
53 enum CollisionDetectionType : SURGSIM_ENUM_TYPE;
54 
61 {
62 public:
65  explicit Representation(const std::string& name);
66 
68  virtual ~Representation();
69 
72  virtual int getShapeType() const = 0;
73 
76  virtual void setCollisionDetectionType(CollisionDetectionType type);
77 
80  CollisionDetectionType getCollisionDetectionType() const;
81 
84  virtual void setSelfCollisionDetectionType(CollisionDetectionType type);
85 
88  CollisionDetectionType getSelfCollisionDetectionType() const;
89 
92  virtual std::shared_ptr<SurgSim::Math::Shape> getShape() const = 0;
93 
96  virtual const Math::PosedShape<std::shared_ptr<Math::Shape>>& getPosedShape();
97 
99  const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& getPosedShapeMotion() const;
100 
105 
110  void addContact(const std::shared_ptr<Representation>& other,
111  const std::shared_ptr<SurgSim::Collision::Contact>& contact);
112 
116  bool collidedWith(const std::shared_ptr<Representation>& other);
117 
120  virtual void update(const double& dt);
121 
123  virtual void updateShapeData();
124 
126  virtual void updateDcdData();
127 
131  virtual void updateCcdData(double timeOfImpact);
132 
137  bool ignore(const std::string& fullName);
138 
143  bool ignore(const std::shared_ptr<Representation>& representation);
144 
150  void setIgnoring(const std::vector<std::string>& fullNames);
151 
155  bool isIgnoring(const std::string& fullName) const;
156 
160  bool isIgnoring(const std::shared_ptr<Representation>& representation) const;
161 
170  bool allow(const std::string& fullName);
171 
180  bool allow(const std::shared_ptr<Representation>& representation);
181 
187  void setAllowing(const std::vector<std::string>& fullNames);
188 
192  bool isAllowing(const std::string& fullName) const;
193 
197  bool isAllowing(const std::shared_ptr<Representation>& representation) const;
198 
200  virtual Math::Aabbd getBoundingBox() const;
201 
202 protected:
204  void invalidatePosedShapeMotion();
205 
208  std::vector<std::string> getIgnoring() const;
209 
212  std::vector<std::string> getAllowing() const;
213 
214  void doRetire() override;
215 
217  void setPosedShapeMotion(const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& posedShape);
218 
219  std::shared_ptr<Framework::Logger> m_logger;
220 
223  double m_oldVolume;
224  double m_aabbThreshold;
225  Math::RigidTransform3d m_previousDcdPose;
226  Math::RigidTransform3d m_previousCcdCurrentPose;
228 
229 private:
231  CollisionDetectionType m_collisionDetectionType;
232 
234  CollisionDetectionType m_selfCollisionDetectionType;
235 
240 
242  boost::mutex m_collisionsMutex;
243 
246 
248  mutable boost::shared_mutex m_posedShapeMotionMutex;
249 
251  std::unordered_set<std::string> m_ignoring;
252 
254  std::unordered_set<std::string> m_allowing;
255 };
256 
257 }; // namespace Collision
258 }; // namespace SurgSim
259 
260 SURGSIM_SERIALIZABLE_ENUM(SurgSim::Collision::CollisionDetectionType,
261  (COLLISION_DETECTION_TYPE_NONE)
262  (COLLISION_DETECTION_TYPE_DISCRETE)
263  (COLLISION_DETECTION_TYPE_CONTINUOUS)
264  (MAX_COLLISION_DETECTION_TYPES))
265 
266 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
The convenience header that provides the entirety of the logging API.
double m_oldVolume
Definition: Representation.h:223
PosedShape is a transformed shape with a record of the pose used to transform it. ...
Definition: Shape.h:128
The type of collision detection.
Definition: Representation.h:60
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:156
Representations are manifestations of a SceneElement.
Definition: Representation.h:33