Broad Phase

enum class ipc::BroadPhaseMethod;

Enumeration of implemented broad phase methods.

Values:

enumerator BRUTE_FORCE;
enumerator HASH_GRID;
enumerator SPATIAL_HASH;
enumerator SWEEP_AND_TINIEST_QUEUE;
enumerator SWEEP_AND_TINIEST_QUEUE_GPU;
enumerator NUM_METHODS;
static constexpr BroadPhaseMethod ipc::DEFAULT_BROAD_PHASE_METHOD
   
 = BroadPhaseMethod::HASH_GRID;

Broad Phase

class BroadPhase;

Subclassed by ipc::BruteForce, ipc::CopyMeshBroadPhase, ipc::HashGrid, ipc::SpatialHash

Public Functions

inline virtual ~BroadPhase();
virtual void build(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0);

Build the broad phase for static collision detection.

Parameters:
const Eigen::MatrixXd &vertices

Vertex positions

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

virtual void build(const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0);

Build the broad phase for continuous collision detection.

Parameters:
const Eigen::MatrixXd &vertices_t0

Starting vertices of the vertices.

const Eigen::MatrixXd &vertices_t1

Ending vertices of the vertices.

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

virtual void clear();

Clear any built data.

virtual void detect_edge_vertex_candidates(
    
std::vector<EdgeVertexCandidate>& candidates) const
   
 = 0;

Find the candidate edge-vertex collisisons.

Parameters:
std::vector<EdgeVertexCandidate> &candidates

[out] The candidate edge-vertex collisisons.

virtual void detect_edge_edge_candidates(
    
std::vector<EdgeEdgeCandidate>& candidates) const
   
 = 0;

Find the candidate edge-edge collisions.

Parameters:
std::vector<EdgeEdgeCandidate> &candidates

[out] The candidate edge-edge collisisons.

virtual void detect_face_vertex_candidates(
    
std::vector<FaceVertexCandidate>& candidates) const
   
 = 0;

Find the candidate face-vertex collisions.

Parameters:
std::vector<FaceVertexCandidate> &candidates

[out] The candidate face-vertex collisisons.

virtual void detect_edge_face_candidates(
    
std::vector<EdgeFaceCandidate>& candidates) const
   
 = 0;

Find the candidate edge-face intersections.

Parameters:
std::vector<EdgeFaceCandidate> &candidates

[out] The candidate edge-face intersections.

virtual void detect_collision_candidates(
    
int dimCandidatescandidates) const;

Detect all collision candidates needed for a given dimensional simulation.

Parameters:
int dim

The dimension of the simulation (i.e., 2 or 3).

Candidates &candidates

The detected collision candidates.

Public Members

std::function<bool(size_t, size_t)> can_vertices_collide
   
 = default_can_vertices_collide;

Function for determining if two vertices can collide.

Public Static Functions

static std::unique_ptr<BroadPhase> make_broad_phase(
    
const BroadPhaseMethod broad_phase_method);

Construct a registered broad phase object.

Parameters:
const BroadPhaseMethod broad_phase_method

The broad phase method to use.

Returns:

The constructed broad phase object.

static inline bool default_can_vertices_collide(size_tsize_t);

Protected Functions

virtual bool can_edge_vertex_collide(size_t eisize_t vi) const;
virtual bool can_edges_collide(size_t eaisize_t ebi) const;
virtual bool can_face_vertex_collide(size_t fisize_t vi) const;
virtual bool can_edge_face_collide(size_t eisize_t fi) const;

Protected Attributes

std::vector<AABB> vertex_boxes;
std::vector<AABB> edge_boxes;
std::vector<AABB> face_boxes;

Brute Force

class BruteForce : public ipc::BroadPhase;

Public Functions

virtual void detect_edge_vertex_candidates(
    
std::vector<EdgeVertexCandidate>& candidates) const override;

Find the candidate edge-vertex collisisons.

virtual void detect_edge_edge_candidates(
    
std::vector<EdgeEdgeCandidate>& candidates) const override;

Find the candidate edge-edge collisions.

virtual void detect_face_vertex_candidates(
    
std::vector<FaceVertexCandidate>& candidates) const override;

Find the candidate face-vertex collisions.

virtual void detect_edge_face_candidates(
    
std::vector<EdgeFaceCandidate>& candidates) const override;

Find the candidate edge-face intersections.

Private Functions

template <typename Candidate, bool triangular = false>
void detect_candidates(const std::vector<AABB>& boxes0,
    
const std::vector<AABB>& boxes1,
    
const std::function<bool(size_t, size_t)>& can_collide,
    
std::vector<Candidate>& candidates) const;

Hash Grid

class HashGrid : public ipc::BroadPhase;

Public Functions

virtual void build(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0) override;

Build the broad phase for static collision detection.

Parameters:
const Eigen::MatrixXd &vertices

Vertex positions

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

virtual void build(const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0) override;

Build the broad phase for continuous collision detection.

Parameters:
const Eigen::MatrixXd &vertices_t0

Starting vertices of the vertices.

const Eigen::MatrixXd &vertices_t1

Ending vertices of the vertices.

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

inline virtual void clear() override;

Clear the hash grid.

virtual void detect_edge_vertex_candidates(
    
std::vector<EdgeVertexCandidate>& candidates) const override;

Find the candidate edge-vertex collisisons.

Parameters:
std::vector<EdgeVertexCandidate> &candidates

[out] The candidate edge-vertex collisisons.

virtual void detect_edge_edge_candidates(
    
std::vector<EdgeEdgeCandidate>& candidates) const override;

Find the candidate edge-edge collisions.

Parameters:
std::vector<EdgeEdgeCandidate> &candidates

[out] The candidate edge-edge collisisons.

virtual void detect_face_vertex_candidates(
    
std::vector<FaceVertexCandidate>& candidates) const override;

Find the candidate face-vertex collisions.

Parameters:
std::vector<FaceVertexCandidate> &candidates

[out] The candidate face-vertex collisisons.

virtual void detect_edge_face_candidates(
    
std::vector<EdgeFaceCandidate>& candidates) const override;

Find the candidate edge-face intersections.

Parameters:
std::vector<EdgeFaceCandidate> &candidates

[out] The candidate edge-face intersections.

inline double cellSize() const;
inline const ArrayMax3igridSize() const;
inline const ArrayMax3ddomainMin() const;
inline const ArrayMax3ddomainMax() const;

Protected Functions

void resize(
    
const ArrayMax3dminconst ArrayMax3dmaxdouble cellSize);
void insert_boxes();
void insert_boxes(const std::vector<AABB>& boxes,
    
std::vector<HashItem>& items) const;
void insert_box(const AABBaabbconst long id,
    
std::vector<HashItem>& items) const;

Add an AABB of the extents to the hash grid.

inline long hash(int xint yint z) const;

Create the hash of a cell location.

Protected Attributes

double m_cellSize;
ArrayMax3i m_gridSize;
ArrayMax3d m_domainMin;
ArrayMax3d m_domainMax;
std::vector<HashItem> vertex_items;
std::vector<HashItem> edge_items;
std::vector<HashItem> face_items;

Private Functions

template <typename Candidate>
void detect_candidates(const std::vector<HashItem>& items0,
    
const std::vector<HashItem>& items1,
    
const std::vector<AABB>& boxes0,
    
const std::vector<AABB>& boxes1,
    
const std::function<bool(size_t, size_t)>& can_collide,
    
std::vector<Candidate>& candidates) const;
template <typename Candidate>
void detect_candidates(const std::vector<HashItem>& items,
    
const std::vector<AABB>& boxes,
    
const std::function<bool(size_t, size_t)>& can_collide,
    
std::vector<Candidate>& candidates) const;

Spatial Hash

class SpatialHash : public ipc::BroadPhase;

Public Functions

inline SpatialHash();
inline SpatialHash(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0double voxelSize = -1);
inline SpatialHash(const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0double voxelSize = -1);
inline virtual void build(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0) override;

Build the broad phase for static collision detection.

Parameters:
const Eigen::MatrixXd &vertices

Vertex positions

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

inline virtual void build(const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0) override;

Build the broad phase for continuous collision detection.

Parameters:
const Eigen::MatrixXd &vertices_t0

Starting vertices of the vertices.

const Eigen::MatrixXd &vertices_t1

Ending vertices of the vertices.

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

void build(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radiusdouble voxelSize);
void build(const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radiusdouble voxelSize);
inline virtual void clear() override;

Clear any built data.

void queryPointForTriangles(const VectorMax3dp,
    
unordered_set<int>& triIndsdouble radius = 0) const;
void queryPointForTriangles(const VectorMax3dp_t0,
    
const VectorMax3dp_t1unordered_set<int>& triInds,
    
double radius = 0) const;
void queryPointForPrimitives(const VectorMax3dp_t0,
    
const VectorMax3dp_t1unordered_set<int>& vertInds,
    
unordered_set<int>& edgeIndsunordered_set<int>& triInds,
    
double radius = 0) const;
void queryEdgeForPE(const VectorMax3de0const VectorMax3de1,
    
std::vector<int>& vertIndsstd::vector<int>& edgeInds,
    
double radius = 0) const;
void queryEdgeForEdges(const VectorMax3dea0,
    
const VectorMax3dea1std::vector<int>& edgeInds,
    
double radius = 0int eai = -1) const;
void queryEdgeForEdgesWithBBoxCheck(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst VectorMax3dea0,
    
const VectorMax3dea1std::vector<int>& edgeInds,
    
double radius = 0int eai = -1) const;
void queryEdgeForEdges(const VectorMax3dea0_t0,
    
const VectorMax3dea1_t0const VectorMax3dea0_t1,
    
const VectorMax3dea1_t1std::vector<int>& edgeInds,
    
double radius = 0int eai = -1) const;
void queryTriangleForPoints(const VectorMax3dt0,
    
const VectorMax3dt1const VectorMax3dt2,
    
unordered_set<int>& pointIndsdouble radius = 0) const;
void queryTriangleForPoints(const VectorMax3dt0_t0,
    
const VectorMax3dt1_t0const VectorMax3dt2_t0,
    
const VectorMax3dt0_t1const VectorMax3dt1_t1,
    
const VectorMax3dt2_t1unordered_set<int>& pointInds,
    
double radius = 0) const;
void queryTriangleForEdges(const VectorMax3dt0,
    
const VectorMax3dt1const VectorMax3dt2,
    
unordered_set<int>& edgeIndsdouble radius = 0) const;
void queryEdgeForTriangles(const VectorMax3de0,
    
const VectorMax3de1unordered_set<int>& triInds,
    
double radius = 0) const;
void queryPointForPrimitives(int viunordered_set<int>& vertInds,
    
unordered_set<int>& edgeInds,
    
unordered_set<int>& triInds) const;
void queryPointForEdges(int viunordered_set<int>& edgeInds) const;
void queryPointForTriangles(
    
int viunordered_set<int>& triInds) const;
void queryEdgeForEdges(int eaiunordered_set<int>& edgeInds) const;
void queryEdgeForEdgesWithBBoxCheck(
    
const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesint eai,
    
unordered_set<int>& edgeInds) const;
void queryEdgeForTriangles(
    
int eiunordered_set<int>& triInds) const;
virtual void detect_edge_vertex_candidates(
    
std::vector<EdgeVertexCandidate>& candidates) const override;

Find the candidate edge-vertex collisisons.

virtual void detect_edge_edge_candidates(
    
std::vector<EdgeEdgeCandidate>& candidates) const override;

Find the candidate edge-edge collisions.

virtual void detect_face_vertex_candidates(
    
std::vector<FaceVertexCandidate>& candidates) const override;

Find the candidate face-vertex collisions.

virtual void detect_edge_face_candidates(
    
std::vector<EdgeFaceCandidate>& candidates) const override;

Find the candidate edge-face intersections.

Public Members

ArrayMax3d leftBottomCorner;
ArrayMax3d rightTopCorner;
ArrayMax3i voxelCount;
double one_div_voxelSize;
int voxelCount0x1;
int edgeStartInd;
int triStartInd;
unordered_map<int, std::vector<int>> voxel;
std::vector<std::vector<int>> pointAndEdgeOccupancy;

Protected Functions

int locateVoxelIndex(const VectorMax3dp) const;
void locateVoxelAxisIndex(
    
const VectorMax3dpArrayMax3ivoxelAxisIndex) const;
void locateBoxVoxelAxisIndex(ArrayMax3d minCorner,
    
ArrayMax3d maxCornerArrayMax3iminIndex,
    
ArrayMax3imaxIndexconst double inflation_radius = 0) const;
int voxelAxisIndex2VoxelIndex(
    
const ArrayMax3ivoxelAxisIndex) const;
int voxelAxisIndex2VoxelIndex(int ixint iyint iz) const;

Protected Attributes

int dim;
double builtInRadius;

Sweep and Tiniest Queue

class SweepAndTiniestQueue : public ipc::CopyMeshBroadPhase;

Public Functions

virtual void build(const Eigen::MatrixXdvertices,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0) override;

Build the broad phase for static collision detection.

Parameters:
const Eigen::MatrixXd &vertices

Vertex positions

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

virtual void build(const Eigen::MatrixXdvertices_t0,
    
const Eigen::MatrixXdvertices_t1,
    
const Eigen::MatrixXiedgesconst Eigen::MatrixXifaces,
    
double inflation_radius = 0) override;

Build the broad phase for continuous collision detection.

Parameters:
const Eigen::MatrixXd &vertices_t0

Starting vertex positions

const Eigen::MatrixXd &vertices_t1

Ending vertex positions

const Eigen::MatrixXi &edges

Collision mesh edges

const Eigen::MatrixXi &faces

Collision mesh faces

double inflation_radius = 0

Radius of inflation around all elements.

virtual void clear() override;

Clear any built data.

virtual void detect_edge_vertex_candidates(
    
std::vector<EdgeVertexCandidate>& candidates) const override;

Find the candidate edge-vertex collisisons.

Parameters:
std::vector<EdgeVertexCandidate> &candidates

[out] The candidate edge-vertex collisisons.

virtual void detect_edge_edge_candidates(
    
std::vector<EdgeEdgeCandidate>& candidates) const override;

Find the candidate edge-edge collisions.

Parameters:
std::vector<EdgeEdgeCandidate> &candidates

[out] The candidate edge-edge collisisons.

virtual void detect_face_vertex_candidates(
    
std::vector<FaceVertexCandidate>& candidates) const override;

Find the candidate face-vertex collisions.

Parameters:
std::vector<FaceVertexCandidate> &candidates

[out] The candidate face-vertex collisisons.

virtual void detect_edge_face_candidates(
    
std::vector<EdgeFaceCandidate>& candidates) const override;

Find the candidate edge-face intersections.

Parameters:
std::vector<EdgeFaceCandidate> &candidates

[out] The candidate edge-face intersections.

Protected Functions

long to_edge_id(long id) const;
long to_face_id(long id) const;
bool is_vertex(long id) const;
bool is_edge(long id) const;
bool is_face(long id) const;

Protected Attributes

std::vector<stq::cpu::Aabb> boxes;
std::vector<std::pair<int, int>> overlaps;
long num_vertices;

AABB

class AABB;

Axis aligned bounding-box of some type.

Public Functions

inline AABB();
AABB(const ArrayMax3dminconst ArrayMax3dmax);
inline AABB(const AABBaabb1const AABBaabb2);
inline AABB(
    
const AABBaabb1const AABBaabb2const AABBaabb3);
bool intersects(const AABBother) const;

Public Members

ArrayMax3d min;
ArrayMax3d max;
std::array<long, 3> vertex_ids;

Public Static Functions

static AABB from_point(
    
const VectorMax3dpconst double inflation_radius = 0);

Compute a AABB for a static point.

static inline AABB from_point(const VectorMax3dp_t0,
    
const VectorMax3dp_t1const double inflation_radius = 0);

Compute a AABB for a moving point (i.e. temporal edge).

static void conservative_inflation(ArrayMax3dminArrayMax3dmax,
    
const double inflation_radius);

Compute a conservative inflation of the AABB.