Representation.h
Go to the documentation of this file.
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 
26 #include "SurgSim/Framework/Log.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;
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  void setCollisionDetectionType(CollisionDetectionType type);
77 
80  CollisionDetectionType getCollisionDetectionType() const;
81 
84  void setSelfCollisionDetectionType(CollisionDetectionType type);
85 
88  CollisionDetectionType getSelfCollisionDetectionType() const;
89 
92  virtual const std::shared_ptr<SurgSim::Math::Shape> getShape() const = 0;
93 
96  virtual std::shared_ptr<SurgSim::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  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 
221 private:
223  CollisionDetectionType m_collisionDetectionType;
224 
226  CollisionDetectionType m_selfCollisionDetectionType;
227 
232 
234  boost::mutex m_collisionsMutex;
235 
238 
240  mutable boost::shared_mutex m_posedShapeMotionMutex;
241 
243  std::unordered_set<std::string> m_ignoring;
244 
246  std::unordered_set<std::string> m_allowing;
247 };
248 
249 }; // namespace Collision
250 }; // namespace SurgSim
251 
252 SURGSIM_SERIALIZABLE_ENUM(SurgSim::Collision::CollisionDetectionType,
253  (COLLISION_DETECTION_TYPE_NONE)
254  (COLLISION_DETECTION_TYPE_DISCRETE)
255  (COLLISION_DETECTION_TYPE_CONTINUOUS)
256  (MAX_COLLISION_DETECTION_TYPES))
257 
258 #endif
Definition: CompoundShapeToGraphics.cpp:29
boost::shared_mutex m_posedShapeMotionMutex
Mutex to lock write access to m_posedShapeMotion.
Definition: Representation.h:240
std::shared_ptr< Framework::Logger > m_logger
Definition: Representation.h:219
boost::mutex m_collisionsMutex
Mutex to lock write access to m_collisions.
Definition: Representation.h:234
The convenience header that provides the entirety of the logging API.
CollisionDetectionType m_collisionDetectionType
The type of collision detection.
Definition: Representation.h:223
std::unordered_set< std::string > m_ignoring
Ignored collision representations.
Definition: Representation.h:243
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
std::unordered_map< std::shared_ptr< SurgSim::Collision::Representation >, std::list< std::shared_ptr< SurgSim::Collision::Contact > > > ContactMapType
Definition: Representation.h:47
SURGSIM_SERIALIZABLE_ENUM(SurgSim::Devices::HandType,(HANDTYPE_LEFT)(HANDTYPE_RIGHT))
CollisionDetectionType m_selfCollisionDetectionType
The type of self collision detection.
Definition: Representation.h:226
SurgSim::DataStructures::BufferedValue< ContactMapType > m_collisions
A map which associates a list of contacts with each collision representation.
Definition: Representation.h:231
The type of collision detection.
Definition: Representation.h:60
Math::PosedShapeMotion< std::shared_ptr< Math::Shape > > m_posedShapeMotion
The shape transformed in space and defined through time, i.e. with 2 differents configurations.
Definition: Representation.h:237
#define SURGSIM_ENUM_TYPE
Required type of enums used by SURGSIM_SERIALIZABLE_ENUM.
Definition: Accessible.h:261
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:145
Representations are manifestations of a SceneElement.
Definition: Representation.h:33
std::unordered_set< std::string > m_allowing
Allowed collision representations.
Definition: Representation.h:246