7 #include "imstkImplicitGeometryToPointSetCD.h" 8 #include "imstkCollisionData.h" 9 #include "imstkImageData.h" 10 #include "imstkImplicitGeometry.h" 11 #include "imstkMath.h" 12 #include "imstkParallelUtils.h" 13 #include "imstkPointSet.h" 14 #include "imstkSignedDistanceField.h" 18 ImplicitGeometryToPointSetCD::ImplicitGeometryToPointSetCD()
20 setRequiredInputType<ImplicitGeometry>(0);
21 setRequiredInputType<PointSet>(1);
22 m_centralGrad.setDx(Vec3d(0.001, 0.001, 0.001));
27 std::shared_ptr<Geometry> geomA,
28 std::shared_ptr<Geometry> geomB,
29 std::vector<CollisionElement>& elementsA,
30 std::vector<CollisionElement>& elementsB)
33 auto pointSet = std::dynamic_pointer_cast<
PointSet>(geomB);
35 m_centralGrad.setFunction(implicitGeom);
36 if (
auto sdf = std::dynamic_pointer_cast<SignedDistanceField>(implicitGeom))
38 m_centralGrad.setDx(sdf->getImage()->getSpacing() * 0.5);
41 std::shared_ptr<VecDataArray<double, 3>> verticesPtr = pointSet->getVertexPositions();
44 ParallelUtils::parallelFor(vertices.size(),
47 const Vec3d& pt = vertices[i];
49 const double signedDistance = implicitGeom->getFunctionValue(pt);
50 if (signedDistance < 0.0)
52 const Vec3d n = m_centralGrad(pt).normalized();
53 const double depth = std::abs(signedDistance);
57 elemA.pt = pt + n * depth;
58 elemA.penetrationDepth = depth;
63 elemB.penetrationDepth = depth;
66 elementsA.push_back(elemA);
67 elementsB.push_back(elemB);
70 }, vertices.size() > 100);
75 std::shared_ptr<Geometry> geomA,
76 std::shared_ptr<Geometry> geomB,
77 std::vector<CollisionElement>& elementsA)
80 auto pointSet = std::dynamic_pointer_cast<
PointSet>(geomB);
82 m_centralGrad.setFunction(implicitGeom);
83 if (
auto sdf = std::dynamic_pointer_cast<SignedDistanceField>(implicitGeom))
85 m_centralGrad.setDx(sdf->getImage()->getSpacing() * 0.5);
88 std::shared_ptr<VecDataArray<double, 3>> verticesPtr = pointSet->getVertexPositions();
91 ParallelUtils::parallelFor(vertices.size(),
94 const Vec3d& pt = vertices[i];
96 const double signedDistance = implicitGeom->getFunctionValue(pt);
97 if (signedDistance < 0.0)
99 const Vec3d n = m_centralGrad(pt).normalized();
100 const double depth = std::abs(signedDistance);
104 elemA.pt = pt + n * depth;
105 elemA.penetrationDepth = depth;
108 elementsA.push_back(elemA);
111 }, vertices.size() > 100);
116 std::shared_ptr<Geometry> geomA,
117 std::shared_ptr<Geometry> geomB,
118 std::vector<CollisionElement>& elementsB)
121 auto pointSet = std::dynamic_pointer_cast<
PointSet>(geomB);
123 m_centralGrad.setFunction(implicitGeom);
124 if (
auto sdf = std::dynamic_pointer_cast<SignedDistanceField>(implicitGeom))
126 m_centralGrad.setDx(sdf->getImage()->getSpacing() * 0.5);
129 std::shared_ptr<VecDataArray<double, 3>> verticesPtr = pointSet->getVertexPositions();
132 ParallelUtils::parallelFor(vertices.size(),
135 const Vec3d& pt = vertices[i];
137 const double signedDistance = implicitGeom->getFunctionValue(pt);
138 if (signedDistance < 0.0)
140 const Vec3d n = m_centralGrad(pt).normalized();
145 elemB.penetrationDepth = std::abs(signedDistance);
148 elementsB.push_back(elemB);
151 }, vertices.size() > 100);
void unlock()
End a thread-safe region.
Base class for all geometries represented by discrete points and elements The pointsets follow a pipe...
void computeCollisionDataAB(std::shared_ptr< Geometry > geomA, std::shared_ptr< Geometry > geomB, std::vector< CollisionElement > &elementsA, std::vector< CollisionElement > &elementsB) override
Compute collision data for AB simultaneously.
void lock()
Start a thread-safe region, where only one thread can execute at a time until a call to the unlock fu...
void computeCollisionDataA(std::shared_ptr< Geometry > geomA, std::shared_ptr< Geometry > geomB, std::vector< CollisionElement > &elementsA) override
Compute collision data for side A.
Direclty gives a point-direction contact as its collision data, point given by index.
Class that can represent the geometry of multiple implicit geometries as boolean functions One may su...
Direclty gives a point-direction contact as its collision data.
void computeCollisionDataB(std::shared_ptr< Geometry > geomA, std::shared_ptr< Geometry > geomB, std::vector< CollisionElement > &elementsB) override
Compute collision data for side B.