SurgSim::Collision::SegmentSelfContact Class Reference

SegmentSelfContact computes the self collisions among a SegmentMesh under motion at two time points parametrized over the time interval [0,1]. More...

`#include <SurgSim/Collision/SegmentSelfContact.h>`

Inheritance diagram for SurgSim::Collision::SegmentSelfContact:

## Public Member Functions

| SegmentSelfContact ()
| Constructor. More...

std::list< std::shared_ptr< Contact > >

calculateCcdContact (const Math::SegmentMeshShape &segmentShape1AtTime0, const Math::RigidTransform3d &segmentPose1AtTime0, const Math::SegmentMeshShape &segmentShape1AtTime1, const Math::RigidTransform3d &segmentPose1AtTime1, const Math::SegmentMeshShape &segmentShape2AtTime0, const Math::RigidTransform3d &segmentPose2AtTime0, const Math::SegmentMeshShape &segmentShape2AtTime1, const Math::RigidTransform3d &segmentPose2AtTime1) const override

void | setTimeMinPrecisionEpsilon (double precision)
| Set the minimum time precision allowed when deciding on the depth of recursion. More...
double | getTimeMinPrecisionEpsilon ()
void | setTimeMaxPrecisionEpsilon (double precision)
| Set the maximum time precision allowed when deciding on the depth of recursion. More...
double | getTimeMaxPrecisionEpsilon ()
void | setDistanceEpsilon (double precision)
| Set the maximum separation for which two points are considered the same. More...
double | distanceEpsilon ()
std::pair< int, int > | getShapeTypes () override
| Function that returns the shapes between which this class performs collision detection. More...
Public Member Functions inherited from SurgSim::Collision::ContactCalculation
| ContactCalculation ()
| Constructor. More...
virtual | ~ContactCalculation ()
| Destructor. More...
void | calculateContact (std::shared_ptr< CollisionPair > pair)
| Calculate the contacts for a given pair. More...
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. More...
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. More...

## Protected Member Functions

bool

detectCollision (const std::array< SurgSim::Math::Vector3d, 2 > &pt0Positions, const std::array< SurgSim::Math::Vector3d, 2 > &pt1Positions, const std::array< SurgSim::Math::Vector3d, 2 > &qt0Positions, const std::array< SurgSim::Math::Vector3d, 2 > &qt1Positions, double segmentRadius1, double segmentRadius2, double timePrecision, double *r, double *s, double *t, SurgSim::Math::Vector3d *pToQDir, SurgSim::Math::Vector3d *contactPtP, SurgSim::Math::Vector3d *contactPtQ) const

| Detect if two segments actually collide either at time t=0 (Fixed case) or within a movement phase. More...
void | getUniqueCandidates (const std::list< SurgSim::DataStructures::AabbTree::TreeNodePairType > &intersectionList, std::set< std::pair< size_t, size_t >> *segmentIds) const
| Given a list of potentially intersecting AABB nodes, cull the list of any duplicates and return the uniques candidates as synchronized pairs. More...
bool | removeInvalidCollisions (const Math::SegmentMeshShape &segmentA, const Math::SegmentMeshShape &segmentB, size_t segment1SegID, size_t segment2SegID) const
| From the initial AABB tree collisions, there are some very simple filtering operations that we can do to eliminate a number of false positives. More...
bool | detectExcessMovement (const SurgSim::Math::Vector3d &pt0, const SurgSim::Math::Vector3d &pt1, double threshold) const
| Verify the a given point at times t0 and t1 have remained within a reasonable neighborhood. More...
bool | findSegSegContact (const Math::SegmentMeshShape &segmentShape, const std::list< std::shared_ptr< Contact >> &contacts, double t, Collision::CollisionDetectionType collisionType, size_t segId1, double s1, size_t segId2, double s2, double timeEpsilon) const
| Search the list of contacts for a match to the current contact. More...
bool | isSameSegContactPoint (const Math::SegmentMeshShape &segmentShape, size_t segId1, double s1, size_t segId2, double s2) const
| Check for the same location among two parametric location specifications. More...
double | maxTimePrecision (const std::array< SurgSim::Math::Vector3d, 2 > &pt0Positions, const std::array< SurgSim::Math::Vector3d, 2 > &pt1Positions, const std::array< SurgSim::Math::Vector3d, 2 > &qt0Positions, const std::array< SurgSim::Math::Vector3d, 2 > &qt1Positions, double effectiveThickness) const
| Calculate the maximum time interval that guarantees that all collisions can be detected given the derived motions of the segment end points. More...

## Private Attributes

double | m_distanceEpsilon
| Minimum distance precision epsilon used in continuous collision detection. More...
double | m_timeMinPrecisionEpsilon
| Minimum time precision epsilon used in continuous collision detection. More...
double | m_timeMaxPrecisionEpsilon
| Maximum time precision epsilon used in continuous collision detection. More...
const double | m_maxMovementThreshold
| Maximum time precision epsilon used in continuous collision detection. More...
const bool | m_useSegmentThickness
| Flag to determine if segment thickness is to be used in contact calculations. More...
std::shared_ptr< SurgSim::Framework::Logger > | m_logger
| Logger. More...

## Additional Inherited Members

Public Types inherited from SurgSim::Collision::ContactCalculation
typedef std::array< std::array< std::shared_ptr< ContactCalculation >, Math::SHAPE_TYPE_COUNT >, Math::SHAPE_TYPE_COUNT > | TableType
Static Public Member Functions inherited from SurgSim::Collision::ContactCalculation
static void | registerDcdContactCalculation (const std::shared_ptr< ContactCalculation > &calculation)
| Register an instance of a contact calculation in the table. More...
static void | registerCcdContactCalculation (const std::shared_ptr< ContactCalculation > &calculation)
| Register an instance of a contact calculation in the table. More...
static const TableType & | getDcdContactTable ()
static const TableType & | getCcdContactTable ()

## Detailed Description

SegmentSelfContact computes the self collisions among a SegmentMesh under motion at two time points parametrized over the time interval [0,1].

An initial phase uses the AABB tree to select a set of potentially colliding segments from the SegmentMesh. For each of these candidate segment pairs, the goal is to determine the point of earliest contact should any exist.

At the highest level the actual collision detection of candidate segment pairs is a two phase algorithm. First determine if there is contact at the start of an interval and report the contact if found. If no contact is found at the start, subdivide the interval, determine which of the resulting candidate subintervals may have collisions, and then recursively check those promising subintervals. Note that a simple algorithm based on interval arithmetic (including the Interval, LinearMotion and Polynomial interval classes) allows for a quick determination of promising subintervals allowing many of the subintervals to be pruned during the subdivision step without forcing the recursion to bottom out.

See also
  Interval, LinearMotion, Polynomial, SegmentSegmentCcdIntervalCheck

## Constructor & Destructor Documentation

## SegmentSelfContact()

SurgSim::Collision::SegmentSelfContact::SegmentSelfContact | ( |  | ) |

Constructor.

## Member Function Documentation

## calculateCcdContact()

std::list< std::shared_ptr< Contact > > SurgSim::Collision::SegmentSelfContact::calculateCcdContact | ( | const Math::SegmentMeshShape & | segmentShape1AtTime0,
|  | const Math::RigidTransform3d & | segmentPose1AtTime0,
|  | const Math::SegmentMeshShape & | segmentShape1AtTime1,
|  | const Math::RigidTransform3d & | segmentPose1AtTime1,
|  | const Math::SegmentMeshShape & | segmentShape2AtTime0,
|  | const Math::RigidTransform3d & | segmentPose2AtTime0,
|  | const Math::SegmentMeshShape & | segmentShape2AtTime1,
|  | const Math::RigidTransform3d & | segmentPose2AtTime1
| ) |  | const

override virtual

Reimplemented from SurgSim::Collision::ShapeShapeContactCalculation< Math::SegmentMeshShape, Math::SegmentMeshShape >.

## detectCollision()

bool SurgSim::Collision::SegmentSelfContact::detectCollision | ( | const std::array< SurgSim::Math::Vector3d, 2 > & | pt0Positions,
|  | const std::array< SurgSim::Math::Vector3d, 2 > & | pt1Positions,
|  | const std::array< SurgSim::Math::Vector3d, 2 > & | qt0Positions,
|  | const std::array< SurgSim::Math::Vector3d, 2 > & | qt1Positions,
|  | double | segmentRadius1,
|  | double | segmentRadius2,
|  | double | timePrecision,
|  | double * | r,
|  | double * | s,
|  | double * | t,
|  | SurgSim::Math::Vector3d * | pToQDir,
|  | SurgSim::Math::Vector3d * | contactPtP,
|  | SurgSim::Math::Vector3d * | contactPtQ
| ) |  | const

protected

Detect if two segments actually collide either at time t=0 (Fixed case) or within a movement phase.

Parameters

  pt0Positions | are the segment endpoints for the first segment at time t=0.
  pt1Positions | are the segment endpoints for the first segment at time t=1.
  qt0Positions | are the segment endpoints for the second segment at time t=0.
  qt1Positions | are the segment endpoints for the second segment at time t=1.
  segmentRadius1 | is the radius of the first segment.
  segmentRadius2 | is the radius of the second segment.
  timePrecision | is the minimum time delta. Recursion terminates at or below the timePrecision.
  r | [out] parametric location of the collision point (if any) on segment 1.
  s | [out] parametric location of the collision point (if any) on segment 2.
  t | [out] parametric location of the time of any collision in the interval [0, 1].
  pToQDir | [out] direction from p(s) to q(r)
  contactPtP | [out] location of the contact point along segment 1.
  contactPtQ | [out] location of the contact point along segment 2.

Returns
  true if a collision is detected between segment 1 and segment 2; false otherwise.

## detectExcessMovement()

bool SurgSim::Collision::SegmentSelfContact::detectExcessMovement | ( | const SurgSim::Math::Vector3d & | pt0,
|  | const SurgSim::Math::Vector3d & | pt1,
|  | double | threshold
| ) |  | const

protected

Verify the a given point at times t0 and t1 have remained within a reasonable neighborhood.

Large movements make it impossible to accurately determine collisions.

Parameters

  pt0 | vertex coordinates at time t0
  pt1 | vertex coordinates at time t1
  threshold | distance threshold

Returns
  true if any point has exceeded the movement threshold

## distanceEpsilon()

double SurgSim::Collision::SegmentSelfContact::distanceEpsilon | ( |  | ) |

Returns
  the maximum separation for which two points are considered the same.

## findSegSegContact()

bool SurgSim::Collision::SegmentSelfContact::findSegSegContact | ( | const Math::SegmentMeshShape & | segmentShape,
|  | const std::list< std::shared_ptr< Contact >> & | contacts,
|  | double | t,
|  | Collision::CollisionDetectionType | collisionType,
|  | size_t | segId1,
|  | double | s1,
|  | size_t | segId2,
|  | double | s2,
|  | double | timeEpsilon
| ) |  | const

protected

Search the list of contacts for a match to the current contact.

Parameters

  segmentShape | shape to be interrogated to see if the contacts match
  contacts | the current list of detected contacts
  t | time of the contact under consideration.
  collisionType | type of contact under consideration.
  segId1 | segment 1 identifier.
  s1 | parametric location of the contact point along segment 1.
  segId2 | segment 2 identifier.
  s2 | parametric location of the contact point along segment 2.
  timeEpsilon | maximum allowed epsilon for time matches.

Returns
  true if the contacts match, return false otherwise.

## getShapeTypes()

std::pair< int, int > SurgSim::Collision::SegmentSelfContact::getShapeTypes | ( |  | ) |

override virtual

Function that returns the shapes between which this class performs collision detection.

Returns
  int std::pair containing the shape types.

Implements SurgSim::Collision::ContactCalculation.

## getTimeMaxPrecisionEpsilon()

double SurgSim::Collision::SegmentSelfContact::getTimeMaxPrecisionEpsilon | ( |  | ) |

Returns
  the maximum time precision allowed when deciding on the depth of recursion.

## getTimeMinPrecisionEpsilon()

double SurgSim::Collision::SegmentSelfContact::getTimeMinPrecisionEpsilon | ( |  | ) |

Returns
  the minimum time precision allowed when deciding on the depth of recursion.

## getUniqueCandidates()

void SurgSim::Collision::SegmentSelfContact::getUniqueCandidates | ( | const std::list< SurgSim::DataStructures::AabbTree::TreeNodePairType > & | intersectionList,
|  | std::set< std::pair< size_t, size_t >> * | segmentIds
| ) |  | const

protected

Given a list of potentially intersecting AABB nodes, cull the list of any duplicates and return the uniques candidates as synchronized pairs.

Parameters

  intersectionList | list of potentially intersecting AABB node.
  segmentIds | [out] paired unique matches

## isSameSegContactPoint()

bool SurgSim::Collision::SegmentSelfContact::isSameSegContactPoint | ( | const Math::SegmentMeshShape & | segmentShape,
|  | size_t | segId1,
|  | double | s1,
|  | size_t | segId2,
|  | double | s2
| ) |  | const

protected

Check for the same location among two parametric location specifications.

Parameters

  segmentShape | shape to be interrogated to see if the contacts match
  segId1 | segment 1 identifier.
  s1 | parametric location of the contact point along segment 1.
  segId2 | segment 2 identifier.
  s2 | parametric location of the contact point along segment 2.

Returns
  true if the contacts match, return false otherwise.

## maxTimePrecision()

double SurgSim::Collision::SegmentSelfContact::maxTimePrecision | ( | const std::array< SurgSim::Math::Vector3d, 2 > & | pt0Positions,
|  | const std::array< SurgSim::Math::Vector3d, 2 > & | pt1Positions,
|  | const std::array< SurgSim::Math::Vector3d, 2 > & | qt0Positions,
|  | const std::array< SurgSim::Math::Vector3d, 2 > & | qt1Positions,
|  | double | effectiveThickness
| ) |  | const

protected

Calculate the maximum time interval that guarantees that all collisions can be detected given the derived motions of the segment end points.

Parameters

  pt0Positions | are the segment endpoints for the first segment at time t=0.
  pt1Positions | are the segment endpoints for the first segment at time t=1.
  qt0Positions | are the segment endpoints for the second segment at time t=0.
  qt1Positions | are the segment endpoints for the second segment at time t=1.
  effectiveThickness | nearness criteria for declaring a contact.

Returns
  the maximum time interval that will still allow for the detection of all contacts within effectveThickness. This value is bounded from below by the value of the member variable m_timeMinPrecisionEpsilon and from above by m_timeMaxPrecisionEpsilon.

## removeInvalidCollisions()

bool SurgSim::Collision::SegmentSelfContact::removeInvalidCollisions | ( | const Math::SegmentMeshShape & | segmentA,
|  | const Math::SegmentMeshShape & | segmentB,
|  | size_t | segment1SegID,
|  | size_t | segment2SegID
| ) |  | const

protected

From the initial AABB tree collisions, there are some very simple filtering operations that we can do to eliminate a number of false positives.

Most notably, we do not want to collide a single segment against itself, or against one of the segments with which it shares a vertex. These are trivial collisions and will always be present. Less obvious, we want to filter out segments with wild movement vectors. These segments cannot be appropriately processed and are likely to represent errors.

Parameters

  segmentA | the segment mesh at time t=0.
  segmentB | the segment mesh at time t=1.
  segment1SegID | the specific identifier of the candidate segment at time t=0.
  segment2SegID | the specific identifier of the candidate segment at time t=1.

Returns
  true if this collision should be discarded, false if it should be processed further.

## setDistanceEpsilon()

void SurgSim::Collision::SegmentSelfContact::setDistanceEpsilon | ( | double | precision | ) |

Set the maximum separation for which two points are considered the same.

Parameters

  precision | the desired maximum separation for which two points are considered the same.

## setTimeMaxPrecisionEpsilon()

void SurgSim::Collision::SegmentSelfContact::setTimeMaxPrecisionEpsilon | ( | double | precision | ) |

Set the maximum time precision allowed when deciding on the depth of recursion.

Parameters

  precision | the desired maximum time precision

## setTimeMinPrecisionEpsilon()

void SurgSim::Collision::SegmentSelfContact::setTimeMinPrecisionEpsilon | ( | double | precision | ) |

Set the minimum time precision allowed when deciding on the depth of recursion.

Parameters

  precision | the desired minimum time precision

## Member Data Documentation

## m_distanceEpsilon

double SurgSim::Collision::SegmentSelfContact::m_distanceEpsilon

private

Minimum distance precision epsilon used in continuous collision detection.

## m_logger

std::shared_ptr<SurgSim::Framework::Logger> SurgSim::Collision::SegmentSelfContact::m_logger

private

Logger.

## m_maxMovementThreshold

const double SurgSim::Collision::SegmentSelfContact::m_maxMovementThreshold

private

Maximum time precision epsilon used in continuous collision detection.

## m_timeMaxPrecisionEpsilon

double SurgSim::Collision::SegmentSelfContact::m_timeMaxPrecisionEpsilon

private

Maximum time precision epsilon used in continuous collision detection.

## m_timeMinPrecisionEpsilon

double SurgSim::Collision::SegmentSelfContact::m_timeMinPrecisionEpsilon

private

Minimum time precision epsilon used in continuous collision detection.

## m_useSegmentThickness

const bool SurgSim::Collision::SegmentSelfContact::m_useSegmentThickness

private

Flag to determine if segment thickness is to be used in contact calculations.

The documentation for this class was generated from the following files:

- SurgSim/Collision/SegmentSelfContact.h
- SurgSim/Collision/SegmentSelfContact.cpp