All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CollisionPair.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, 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_COLLISIONPAIR_H
17 #define SURGSIM_COLLISION_COLLISIONPAIR_H
18 
19 #include <memory>
20 #include <list>
22 #include "SurgSim/Math/Vector.h"
23 
24 namespace SurgSim
25 {
26 namespace Collision
27 {
28 
29 class Representation;
30 
36 struct Contact {
37  Contact(const double& newDepth,
38  const SurgSim::Math::Vector3d& newContact,
39  const SurgSim::Math::Vector3d& newNormal,
40  const std::pair<SurgSim::DataStructures::Location,
41  SurgSim::DataStructures::Location>& newPenetrationPoints) :
42  depth(newDepth), contact(newContact), normal(newNormal), penetrationPoints(newPenetrationPoints)
43  {
44  };
45  double depth;
50 };
51 
56 {
57 public:
59  CollisionPair();
60 
62  CollisionPair(const std::shared_ptr<Representation>& first,
63  const std::shared_ptr<Representation>& second);
64 
67 
71  void setRepresentations(const std::shared_ptr<Representation>& first,
72  const std::shared_ptr<Representation>& second);
73 
76  const std::pair<std::shared_ptr<Representation>, std::shared_ptr<Representation>>&
77  getRepresentations() const;
78 
80  std::shared_ptr<Representation> getFirst() const;
81 
83  std::shared_ptr<Representation> getSecond() const;
84 
86  bool hasContacts() const;
87 
93  void addContact(const double& depth,
94  const SurgSim::Math::Vector3d& contactPoint,
95  const SurgSim::Math::Vector3d& normal,
96  const std::pair<SurgSim::DataStructures::Location,
97  SurgSim::DataStructures::Location>& penetrationPoints);
98 
103  void addContact(const double& depth,
104  const SurgSim::Math::Vector3d& normal,
105  const std::pair<SurgSim::DataStructures::Location,
106  SurgSim::DataStructures::Location>& penetrationPoints);
107 
110  void addContact(const std::shared_ptr<Contact>& contact);
111 
113  const std::list<std::shared_ptr<Contact>>& getContacts() const;
114 
116  void clearContacts();
117 
119  void swapRepresentations();
120 
123  bool isSwapped() const;
124 
125 private:
126 
128  std::pair<std::shared_ptr<Representation>,
129  std::shared_ptr<Representation>> m_representations;
130 
132  std::list<std::shared_ptr<Contact>> m_contacts;
133 
135 };
136 
137 
138 }; // namespace Collision
139 }; // namespace SurgSim
140 
141 #endif
std::shared_ptr< Representation > getSecond() const
Definition: CollisionPair.cpp:71
const std::list< std::shared_ptr< Contact > > & getContacts() const
Definition: CollisionPair.cpp:108
std::pair< std::shared_ptr< Representation >, std::shared_ptr< Representation > > m_representations
Pair of objects that are colliding.
Definition: CollisionPair.h:129
~CollisionPair()
Destructor.
Definition: CollisionPair.cpp:42
Definition: Location.h:31
bool isSwapped() const
Query if this the pair has been swapped from when it was constructed.
Definition: CollisionPair.cpp:125
SurgSim::Math::Vector3d normal
The normal on the contact point (normalized)
Definition: CollisionPair.h:47
Collision Pair class, it signifies a pair of items that should be checked with the collision algorith...
Definition: CollisionPair.h:55
bool m_isSwapped
Definition: CollisionPair.h:134
void clearContacts()
Reset clear the list of contacts, invalidating all the contacts.
Definition: CollisionPair.cpp:113
double depth
What is the penetration depth for the representation.
Definition: CollisionPair.h:44
void addContact(const double &depth, const SurgSim::Math::Vector3d &contactPoint, const SurgSim::Math::Vector3d &normal, const std::pair< SurgSim::DataStructures::Location, SurgSim::DataStructures::Location > &penetrationPoints)
Adds a contact to the collision pair.
Definition: CollisionPair.cpp:81
const std::pair< std::shared_ptr< Representation >, std::shared_ptr< Representation > > & getRepresentations() const
Function that returns the pair of representations of the objects that are colliding.
Definition: CollisionPair.cpp:61
bool hasContacts() const
Definition: CollisionPair.cpp:76
Contact(const double &newDepth, const SurgSim::Math::Vector3d &newContact, const SurgSim::Math::Vector3d &newNormal, const std::pair< SurgSim::DataStructures::Location, SurgSim::DataStructures::Location > &newPenetrationPoints)
Definition: CollisionPair.h:37
std::pair< SurgSim::DataStructures::Location, SurgSim::DataStructures::Location > penetrationPoints
The deepest point inside the opposing object.
Definition: CollisionPair.h:49
Definitions of small fixed-size vector types.
void swapRepresentations()
Swap the representation pair so that first becomes second and second becomes first.
Definition: CollisionPair.cpp:118
void setRepresentations(const std::shared_ptr< Representation > &first, const std::shared_ptr< Representation > &second)
Sets the representations in this pair, representations cannot be the same instance and neither can be...
Definition: CollisionPair.cpp:47
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:56
std::shared_ptr< Representation > getFirst() const
Definition: CollisionPair.cpp:66
std::list< std::shared_ptr< Contact > > m_contacts
List of current contacts.
Definition: CollisionPair.h:132
SurgSim::Math::Vector3d contact
The actual contact point, only used for CCD.
Definition: CollisionPair.h:46
Contact data structure used when two representations touch each other The convention is that if body ...
Definition: CollisionPair.h:36
CollisionPair()
Default Constructor.
Definition: CollisionPair.cpp:30