SegmentSegmentCcdMovingContact.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_SEGMENTSEGMENTCCDMOVINGCONTACT_H
17 #define SURGSIM_COLLISION_SEGMENTSEGMENTCCDMOVINGCONTACT_H
18 
19 #include <array>
20 
24 
25 namespace SurgSim
26 {
27 namespace Math
28 {
29 class SegmentMeshShape;
30 };
31 
32 namespace Collision
33 {
34 
35 class CollisionPair;
36 
53 {
54 public:
55  static const int SUB_POINTS_PARALLEL_CASE = 5;
56  static const int SUB_POINTS_COPLANAR_CASE = 10;
57 
60 
74  bool collideMovingSegmentSegment(
75  const std::array<Math::Vector3d, 2>& pt0Positions,
76  const std::array<Math::Vector3d, 2>& pt1Positions,
77  const std::array<Math::Vector3d, 2>& qt0Positions,
78  const std::array<Math::Vector3d, 2>& qt1Positions,
79  double thicknessEpsilon,
80  double timePrecisionEpsilon,
81  double* t, double* r, double* s, Math::Vector3d* pToQDir);
82 
97  bool collideMovingSegmentSegment(
98  const std::array<Math::Vector3d, 2>& pt0Positions,
99  const std::array<Math::Vector3d, 2>& pt1Positions,
100  const std::array<Math::Vector3d, 2>& qt0Positions,
101  const std::array<Math::Vector3d, 2>& qt1Positions,
102  double thicknessP,
103  double thicknessQ,
104  double timePrecisionEpsilon,
105  double* t, double* r, double* s, Math::Vector3d* pToQDir);
106 
107 protected:
121  bool collideSegmentSegmentBaseCase(
122  const std::array<Math::Vector3d, 2>& pT0,
123  const std::array<Math::Vector3d, 2>& pT1,
124  const std::array<Math::Vector3d, 2>& qT0,
125  const std::array<Math::Vector3d, 2>& qT1,
126  double thicknessP,
127  double thicknessQ,
128  double timePrecisionEpsilon,
129  double* t, double* r, double* s);
130 
147  bool collideSegmentSegmentParallelCase(
148  const std::array<Math::Vector3d, 2>& pT0,
149  const std::array<Math::Vector3d, 2>& pT1,
150  const std::array<Math::Vector3d, 2>& qT0,
151  const std::array<Math::Vector3d, 2>& qT1,
152  double a, double b,
153  double thicknessP, double thicknessQ,
154  double timePrecisionEpsilon,
155  double* t, double* r, double* s, int depth = 0);
156 
173  bool collideSegmentSegmentCoplanarCase(
174  const std::array<Math::Vector3d, 2>& pT0, /* Segment 1 at t=0 */
175  const std::array<Math::Vector3d, 2>& pT1, /* Segment 1 at t=1 */
176  const std::array<Math::Vector3d, 2>& qT0, /* Segment 2 at t=0 */
177  const std::array<Math::Vector3d, 2>& qT1, /* Segment 2 at t=1 */
178  double a, double b, /* Interval boundaries */
179  double timePrecisionEpsilon,
180  double thicknessP, double thicknessQ,
181  double* t, double* r, double* s,
182  int depth = 0);
183 
194  bool collideSegmentSegmentGeneralCase(
195  const SegmentSegmentCcdIntervalCheck& state,
196  double a, double b, // Interval boundaries
197  double* t, double* r, double* s,
198  int depth = 0);
199 
207  void normalizeSegmentsConsistently(Math::Vector3d* t0, Math::Vector3d* t1, double epsilon) const;
208 
209 private:
223  bool checkForCoplanarContactWithinInterval(double rCurrent, double rNext, double sCurrent, double sNext,
224  const Math::Vector3d& nCurrent, const Math::Vector3d& nNext) const;
225 
227  const double m_distanceEpsilon;
228 
231 
233  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
234 };
235 
236 }; // namespace Collision
237 }; // namespace SurgSim
238 
239 #endif // SURGSIM_COLLISION_SEGMENTSEGMENTCCDMOVINGCONTACT_H
Definition: CompoundShapeToGraphics.cpp:29
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger.
Definition: SegmentSegmentCcdMovingContact.h:233
SegmentSegmentCcdMovingContact computes the self collisions among a SegmentMesh under motion at two t...
Definition: SegmentSegmentCcdMovingContact.h:52
const double m_distanceEpsilon
Minimum distance precision epsilon used in continuous collision detection.
Definition: SegmentSegmentCcdMovingContact.h:227
Collision::SegmentSegmentCcdStaticContact m_staticTest
Utility class for testing interval boundary collisions.
Definition: SegmentSegmentCcdMovingContact.h:230
SegmentSegmentCcdStaticContact computes if there is contact between two segments at a specific point ...
Definition: SegmentSegmentCcdStaticContact.h:35
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SegmentSegmentCcdIntervalCheck uses the Interval classes including the LinearMotion and Polynomial fa...
Definition: SegmentSegmentCcdIntervalCheck.h:37