7 #include "imstkSurfaceMeshToSurfaceMeshCD.h"     8 #include "imstkCollisionUtils.h"     9 #include "imstkSurfaceMesh.h"    10 #include "imstkGeometryUtilities.h"    14     EdgePair(uint32_t a1, uint32_t a2, uint32_t b1, uint32_t b2)
    31         return (edgeAId == other.edgeAId && edgeBId == other.edgeBId)
    32                || (edgeAId == other.edgeBId && edgeBId == other.edgeAId);
    37     const uint32_t getIdA()
 const    39         const uint32_t max = std::max(edgeA[0], edgeA[1]);
    40         const uint32_t min = std::min(edgeA[0], edgeA[1]);
    41         return max * (max + 1) / 2 + min;
    44     const uint32_t getIdB()
 const    46         const uint32_t max = std::max(edgeB[0], edgeB[1]);
    47         const uint32_t min = std::min(edgeB[0], edgeB[1]);
    48         return max * (max + 1) / 2 + min;
    66     std::size_t operator()(
const EdgePair& k)
 const    73         return (k.edgeAId ^ (k.edgeBId << 16));
    80 SurfaceMeshToSurfaceMeshCD::SurfaceMeshToSurfaceMeshCD()
    82     setRequiredInputType<SurfaceMesh>(0);
    83     setRequiredInputType<SurfaceMesh>(1);
    86     setGenerateCD(
true, 
true);
    90 SurfaceMeshToSurfaceMeshCD::computeCollisionDataAB(
    91     std::shared_ptr<Geometry>      geomA,
    92     std::shared_ptr<Geometry>      geomB,
    93     std::vector<CollisionElement>& elementsA,
    94     std::vector<CollisionElement>& elementsB)
    96     std::shared_ptr<SurfaceMesh>             surfMeshA    = std::dynamic_pointer_cast<
SurfaceMesh>(geomA);
    97     std::shared_ptr<VecDataArray<double, 3>> verticesAPtr = surfMeshA->
getVertexPositions();
    99     std::shared_ptr<VecDataArray<int, 3>>    indicesAPtr  = surfMeshA->getCells();
   102     std::shared_ptr<SurfaceMesh>             surfMeshB    = std::dynamic_pointer_cast<
SurfaceMesh>(geomB);
   103     std::shared_ptr<VecDataArray<double, 3>> verticesBPtr = surfMeshB->
getVertexPositions();
   105     std::shared_ptr<VecDataArray<int, 3>>    indicesBPtr  = surfMeshB->getCells();
   108     std::unordered_set<EdgePair> edges;
   109     for (
int i = 0; i < indicesA.size(); i++)
   111         const Vec3i& cellA = indicesA[i];
   112         for (
int j = 0; j < indicesB.size(); j++)
   114             const Vec3i& cellB = indicesB[j];
   117             std::pair<Vec2i, Vec2i> eeContact;
   118             std::pair<int, Vec3i>   vtContact;
   119             std::pair<Vec3i, int>   tvContact;
   120             const int               contactType = CollisionUtils::triangleToTriangle(cellA, cellB,
   121                 verticesA[cellA[0]], verticesA[cellA[1]], verticesA[cellA[2]],
   122                 verticesB[cellB[0]], verticesB[cellB[1]], verticesB[cellB[2]],
   123                 eeContact, vtContact, tvContact);
   143             if (contactType == 1)
   147                 elemA.cellType = IMSTK_VERTEX;
   148                 elemA.ids[0]   = vtContact.first;
   152                 elemB.cellType = IMSTK_TRIANGLE;
   153                 elemB.ids[0]   = vtContact.second[0];
   154                 elemB.ids[1]   = vtContact.second[1];
   155                 elemB.ids[2]   = vtContact.second[2];
   158                 elementsA.push_back(elemA);
   159                 elementsB.push_back(elemB);
   162             else if (contactType == 0)
   167                     static_cast<uint32_t
>(eeContact.first[0]),
   168                     static_cast<uint32_t>(eeContact.first[1]),
   169                     static_cast<uint32_t
>(eeContact.second[0]),
   170                     static_cast<uint32_t>(eeContact.second[1]) };
   171                 if (edges.count(edgePair) == 0)
   175                     elemA.cellType = IMSTK_EDGE;
   176                     elemA.ids[0]   = eeContact.first[0];
   177                     elemA.ids[1]   = eeContact.first[1];
   182                     elemB.cellType = IMSTK_EDGE;
   183                     elemB.ids[0]   = eeContact.second[0];
   184                     elemB.ids[1]   = eeContact.second[1];
   187                     elementsA.push_back(elemA);
   188                     elementsB.push_back(elemB);
   189                     edges.insert(edgePair);
   193             else if (contactType == 2)
   197                 elemA.cellType = IMSTK_TRIANGLE;
   198                 elemA.ids[0]   = tvContact.first[0];
   199                 elemA.ids[1]   = tvContact.first[1];
   200                 elemA.ids[2]   = tvContact.first[2];
   205                 elemB.cellType = IMSTK_VERTEX;
   206                 elemB.ids[0]   = tvContact.second;
   208                 elementsA.push_back(elemA);
   209                 elementsB.push_back(elemB);
 
Hash together a pair of edges. 
Returns a hash value for a PointEntry. 
std::shared_ptr< VecDataArray< double, 3 > > getVertexPositions(DataType type=DataType::PostTransform) const
Returns the vector of current positions of the mesh vertices. 
Represents a set of triangles & vertices via an array of Vec3d double vertices & Vec3i integer indice...
Represents a cell by a single cell id OR by N vertex ids. Which case can be determined by the idCount...
bool operator==(const EdgePair &other) const
Reversible edges are equivalent, reversible vertices in the edges are equivalent as well EdgePair(0...