7 #include "imstkCollisionDataDebugModel.h" 8 #include "imstkLineMesh.h" 9 #include "imstkSurfaceMesh.h" 10 #include "imstkVecDataArray.h" 19 if (pointSet !=
nullptr)
21 vertices = *pointSet->getVertexPositions();
23 if (elem.m_type == CollisionElementType::CellIndex)
25 const int idCount = elem.m_element.m_CellIndexElement.idCount;
26 const CellTypeId type = elem.m_element.m_CellIndexElement.cellType;
27 if (type == IMSTK_VERTEX)
29 addPoint(vertices[elem.m_element.m_CellIndexElement.ids[0]]);
31 else if (type == IMSTK_EDGE)
36 auto indices = std::dynamic_pointer_cast<
LineMesh>(pointSet)->getCells();
37 cell = (*indices)[elem.m_element.m_CellIndexElement.ids[0]];
42 elem.m_element.m_CellIndexElement.ids[0],
43 elem.m_element.m_CellIndexElement.ids[1]);
45 addLine(vertices[cell[0]], vertices[cell[1]]);
47 else if (type == IMSTK_TRIANGLE)
52 auto indices = std::dynamic_pointer_cast<
SurfaceMesh>(pointSet)->getCells();
53 cell = (*indices)[elem.m_element.m_CellIndexElement.ids[0]];
58 elem.m_element.m_CellIndexElement.ids[0],
59 elem.m_element.m_CellIndexElement.ids[1],
60 elem.m_element.m_CellIndexElement.ids[2]);
62 addTriangle(vertices[cell[0]], vertices[cell[1]], vertices[cell[2]]);
66 else if (elem.m_type == CollisionElementType::CellVertex)
68 const int vertexCount = elem.m_element.m_CellVertexElement.size;
71 addPoint(elem.m_element.m_CellVertexElement.pts[0]);
73 else if (vertexCount == 2)
76 elem.m_element.m_CellVertexElement.pts[0],
77 elem.m_element.m_CellVertexElement.pts[1]);
79 else if (vertexCount == 3)
82 elem.m_element.m_CellVertexElement.pts[0],
83 elem.m_element.m_CellVertexElement.pts[1],
84 elem.m_element.m_CellVertexElement.pts[2]);
88 else if (elem.m_type == CollisionElementType::PointIndexDirection)
90 addPoint(vertices[elem.m_element.m_PointIndexDirectionElement.ptIndex]);
91 addArrow(vertices[elem.m_element.m_PointIndexDirectionElement.ptIndex],
92 vertices[elem.m_element.m_PointIndexDirectionElement.ptIndex] +
93 elem.m_element.m_PointIndexDirectionElement.dir * elem.m_element.m_PointIndexDirectionElement.penetrationDepth);
95 else if (elem.m_type == CollisionElementType::PointDirection)
97 addPoint(elem.m_element.m_PointDirectionElement.pt);
98 addArrow(elem.m_element.m_PointDirectionElement.pt,
99 elem.m_element.m_PointDirectionElement.pt +
100 elem.m_element.m_PointDirectionElement.dir * elem.m_element.m_PointDirectionElement.penetrationDepth);
107 if (elem.m_type == CollisionElementType::CellVertex)
109 const int vertexCount = elem.m_element.m_CellVertexElement.size;
110 printf(
" CellVertexElement\n");
111 printf(
" # Vertices: %d\n", vertexCount);
112 for (
int i = 0; i < vertexCount; i++)
114 printf(
" ptIndex: (%f, %f, %f)\n",
115 elem.m_element.m_CellVertexElement.pts[i][0],
116 elem.m_element.m_CellVertexElement.pts[i][1],
117 elem.m_element.m_CellVertexElement.pts[i][2]);
120 else if (elem.m_type == CollisionElementType::CellIndex)
122 printf(
" CellIndexElement\n");
123 printf(
" Cell Type: %d\n", elem.m_element.m_CellIndexElement.cellType);
124 printf(
" # ids: %d\n", elem.m_element.m_CellIndexElement.idCount);
125 for (
int i = 0; i < elem.m_element.m_CellIndexElement.idCount; i++)
127 printf(
" Cell Index: %d\n", elem.m_element.m_CellIndexElement.ids[i]);
130 else if (elem.m_type == CollisionElementType::PointDirection)
132 printf(
" PointDirectionElement\n");
133 printf(
" pt: (%f, %f, %f)\n",
134 elem.m_element.m_PointDirectionElement.pt[0],
135 elem.m_element.m_PointDirectionElement.pt[1],
136 elem.m_element.m_PointDirectionElement.pt[2]);
137 printf(
" dir: (%f, %f, %f)\n",
138 elem.m_element.m_PointDirectionElement.dir[0],
139 elem.m_element.m_PointDirectionElement.dir[1],
140 elem.m_element.m_PointDirectionElement.dir[2]);
141 printf(
" penetrationDepth: %f\n", elem.m_element.m_PointDirectionElement.penetrationDepth);
143 else if (elem.m_type == CollisionElementType::PointIndexDirection)
145 printf(
" PointIndexDirectionElement\n");
146 printf(
" ptIndex: %d\n", elem.m_element.m_PointIndexDirectionElement.ptIndex);
147 printf(
" dir: (%f, %f, %f)\n",
148 elem.m_element.m_PointIndexDirectionElement.dir[0],
149 elem.m_element.m_PointIndexDirectionElement.dir[1],
150 elem.m_element.m_PointIndexDirectionElement.dir[2]);
151 printf(
" penetrationDepth: %f\n", elem.m_element.m_PointIndexDirectionElement.penetrationDepth);
158 if (m_cdData ==
nullptr)
165 printf(
"# A Contacts: %d\n", static_cast<int>(m_cdData->elementsA.size()));
166 printf(
"# B Contacts: %d\n", static_cast<int>(m_cdData->elementsB.size()));
170 if (m_frameCounter >= m_clearRate)
176 std::shared_ptr<PointSet> pointSetA = std::dynamic_pointer_cast<
PointSet>(m_cdData->geomA);
177 for (
int i = 0; i < static_cast<int>(m_cdData->elementsA.size()); i++)
183 printf(
"Contact A %d\n", i);
187 std::shared_ptr<PointSet> pointSetB = std::dynamic_pointer_cast<
PointSet>(m_cdData->geomB);
188 for (
int i = 0; i < static_cast<int>(m_cdData->elementsB.size()); i++)
194 printf(
"Contact B %d\n", i);
199 if (m_countEmptyFrames)
205 if ((m_cdData->elementsA.size() > 0 || m_cdData->elementsB.size() > 0))
Base class for all geometries represented by discrete points and elements The pointsets follow a pipe...
void addTriangle(const Vec3d &a, const Vec3d &b, const Vec3d &c)
Adds a triangle to the debug triangles with default color.
void debugUpdate()
Updates visual representation to the current cd (we don't use the built in update as its useful to ca...
void addPoint(const Vec3d &a)
Adds a point to the debug points.
void addLine(const Vec3d &a, const Vec3d &b)
Adds a line to the debug lines with default color.
Union of collision elements. We use a union to avoid polymorphism. There may be many elements and acc...
void addCollisionElement(std::shared_ptr< PointSet > pointSet, const CollisionElement &elem)
Append visual representation to the debug meshes for the given contact and geometry.
Base class for all volume mesh types.
Represents a set of triangles & vertices via an array of Vec3d double vertices & Vec3i integer indice...
void addArrow(const Vec3d &start, const Vec3d &end)
Adds an arrow to the debug arrows.
void printContactInfo(const CollisionElement &elem)
Print the contact information.
void clear()
Clears all primitives.