ContactCalculation.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_CONTACTCALCULATION_H
17 #define SURGSIM_COLLISION_CONTACTCALCULATION_H
18 
19 #include <memory>
20 #include <mutex>
21 
24 #include "SurgSim/Math/Shape.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace Math
30 {
31 class Shape;
32 }
33 
34 namespace Collision
35 {
36 
42 {
43 public:
46 
48  virtual ~ContactCalculation();
49 
52  void calculateContact(std::shared_ptr<CollisionPair> pair);
53 
57  std::list<std::shared_ptr<Contact>> calculateDcdContact(
58  const Math::PosedShape<std::shared_ptr<Math::Shape>> posedShape1,
59  const Math::PosedShape<std::shared_ptr<Math::Shape>> posedShape2);
60 
66  std::list<std::shared_ptr<Contact>> calculateCcdContact(
67  const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>> posedShapeMotion1,
68  const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>> posedShapeMotion2);
69 
72  virtual std::pair<int, int> getShapeTypes() = 0;
73 
76  static void registerDcdContactCalculation(const std::shared_ptr<ContactCalculation>& calculation);
77 
80  static void registerCcdContactCalculation(const std::shared_ptr<ContactCalculation>& calculation);
81 
82  typedef
83  std::array<std::array<std::shared_ptr<ContactCalculation>, Math::SHAPE_TYPE_COUNT>, Math::SHAPE_TYPE_COUNT>
85 
86  static const TableType& getDcdContactTable();
87  static const TableType& getCcdContactTable();
88 private:
89 
92  virtual void doCalculateContact(std::shared_ptr<CollisionPair> pair);
93 
99  virtual std::list<std::shared_ptr<Contact>> doCalculateDcdContact(
100  const Math::PosedShape<std::shared_ptr<Math::Shape>>& posedShape1,
101  const Math::PosedShape<std::shared_ptr<Math::Shape>>& posedShape2);
102 
108  virtual std::list<std::shared_ptr<Contact>> doCalculateCcdContact(
109  const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& posedShapeMotion1,
110  const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& posedShapeMotion2);
111 
113  static void initializeTables();
114 
118  static void privateDcdRegister(
119  const std::shared_ptr<ContactCalculation>& calculation,
120  const std::pair<int, int>& types);
121  static void privateDcdRegister(const std::shared_ptr<ContactCalculation>& calculation);
123 
127  static void privateCcdRegister(
128  const std::shared_ptr<ContactCalculation>& calculation,
129  const std::pair<int, int>& types);
130  static void privateCcdRegister(const std::shared_ptr<ContactCalculation>& calculation);
132 
135  static std::once_flag m_initializationFlag;
136 };
137 
138 }; // namespace Collision
139 }; // namespace SurgSim
140 
141 #endif
Shape.h
SurgSim::Collision::ContactCalculation::calculateContact
void calculateContact(std::shared_ptr< CollisionPair > pair)
Calculate the contacts for a given pair.
Definition: ContactCalculation.cpp:69
CollisionPair.h
SurgSim::Collision::ContactCalculation::registerDcdContactCalculation
static void registerDcdContactCalculation(const std::shared_ptr< ContactCalculation > &calculation)
Register an instance of a contact calculation in the table.
Definition: ContactCalculation.cpp:41
SurgSim::Collision::ContactCalculation::~ContactCalculation
virtual ~ContactCalculation()
Destructor.
Definition: ContactCalculation.cpp:37
SurgSim::Collision::ContactCalculation::TableType
std::array< std::array< std::shared_ptr< ContactCalculation >, Math::SHAPE_TYPE_COUNT >, Math::SHAPE_TYPE_COUNT > TableType
Definition: ContactCalculation.h:84
SurgSim::Collision::ContactCalculation::calculateCcdContact
std::list< std::shared_ptr< Contact > > calculateCcdContact(const Math::PosedShapeMotion< std::shared_ptr< Math::Shape >> posedShapeMotion1, const Math::PosedShapeMotion< std::shared_ptr< Math::Shape >> posedShapeMotion2)
Calculate the ccd contacts between two posed/transformed shapes.
Definition: ContactCalculation.cpp:107
SurgSim::Collision::ContactCalculation::privateCcdRegister
static void privateCcdRegister(const std::shared_ptr< ContactCalculation > &calculation, const std::pair< int, int > &types)
Definition: ContactCalculation.cpp:290
SurgSim::Collision::ContactCalculation
Base class responsible for calculating contact data between two objects.
Definition: ContactCalculation.h:41
SurgSim::Collision::ContactCalculation::getShapeTypes
virtual std::pair< int, int > getShapeTypes()=0
Virtual function that returns the shapes that this ContactCalculation class handles.
SurgSim::Collision::ContactCalculation::m_contactCcdCalculations
static TableType m_contactCcdCalculations
Static table of Ccd contact calculations.
Definition: ContactCalculation.h:134
SurgSim::Collision::ContactCalculation::m_contactDcdCalculations
static TableType m_contactDcdCalculations
Static table of Dcd contact calculations.
Definition: ContactCalculation.h:133
SurgSim::Math::PosedShapeMotion
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:145
SurgSim::Math::PosedShape
PosedShape is a transformed shape with a record of the pose used to transform it.
Definition: Shape.h:117
SurgSim::Collision::ContactCalculation::doCalculateCcdContact
virtual std::list< std::shared_ptr< Contact > > doCalculateCcdContact(const Math::PosedShapeMotion< std::shared_ptr< Math::Shape >> &posedShapeMotion1, const Math::PosedShapeMotion< std::shared_ptr< Math::Shape >> &posedShapeMotion2)
Virtual function receives the call from the public interface, usually will type the shapes statically...
Definition: ContactCalculation.cpp:202
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Collision::ContactCalculation::privateDcdRegister
static void privateDcdRegister(const std::shared_ptr< ContactCalculation > &calculation, const std::pair< int, int > &types)
Definition: ContactCalculation.cpp:276
SurgSim::Collision::ContactCalculation::initializeTables
static void initializeTables()
Statically initialize the tables, used via call once.
Definition: ContactCalculation.cpp:210
SurgSim::Collision::ContactCalculation::registerCcdContactCalculation
static void registerCcdContactCalculation(const std::shared_ptr< ContactCalculation > &calculation)
Register an instance of a contact calculation in the table.
Definition: ContactCalculation.cpp:48
SurgSim::Collision::ContactCalculation::ContactCalculation
ContactCalculation()
Constructor.
Definition: ContactCalculation.cpp:33
SurgSim::Collision::ContactCalculation::getCcdContactTable
static const TableType & getCcdContactTable()
Definition: ContactCalculation.cpp:62
RigidTransform.h
SurgSim::Collision::ContactCalculation::getDcdContactTable
static const TableType & getDcdContactTable()
Definition: ContactCalculation.cpp:55
SurgSim::Collision::ContactCalculation::m_initializationFlag
static std::once_flag m_initializationFlag
Flag used for initialization.
Definition: ContactCalculation.h:135
SurgSim::Collision::ContactCalculation::doCalculateContact
virtual void doCalculateContact(std::shared_ptr< CollisionPair > pair)
Calculate the actual contact between two shapes of the given CollisionPair.
Definition: ContactCalculation.cpp:141
SurgSim::Math::SHAPE_TYPE_COUNT
Definition: Shape.h:59
SurgSim::Collision::ContactCalculation::calculateDcdContact
std::list< std::shared_ptr< Contact > > calculateDcdContact(const Math::PosedShape< std::shared_ptr< Math::Shape >> posedShape1, const Math::PosedShape< std::shared_ptr< Math::Shape >> posedShape2)
Calculate the dcd contacts between two posed/transformed shapes.
Definition: ContactCalculation.cpp:74
SurgSim::Collision::ContactCalculation::doCalculateDcdContact
virtual std::list< std::shared_ptr< Contact > > doCalculateDcdContact(const Math::PosedShape< std::shared_ptr< Math::Shape >> &posedShape1, const Math::PosedShape< std::shared_ptr< Math::Shape >> &posedShape2)
Virtual function receives the call from the public interface, usually will type the shapes statically...
Definition: ContactCalculation.cpp:194