7 #include "imstkPointSetToPlaneCD.h" 8 #include "imstkCollisionData.h" 9 #include "imstkCollisionUtils.h" 10 #include "imstkParallelUtils.h" 11 #include "imstkPlane.h" 12 #include "imstkPointSet.h" 13 #include "imstkVecDataArray.h" 17 PointSetToPlaneCD::PointSetToPlaneCD()
19 setRequiredInputType<PointSet>(0);
20 setRequiredInputType<Plane>(1);
28 std::shared_ptr<Geometry> geomA,
29 std::shared_ptr<Geometry> geomB,
30 std::vector<CollisionElement>& elementsA,
31 std::vector<CollisionElement>& elementsB)
33 std::shared_ptr<PointSet> pointSet = std::dynamic_pointer_cast<
PointSet>(geomA);
34 std::shared_ptr<Plane> plane = std::dynamic_pointer_cast<
Plane>(geomB);
37 const Vec3d planeNormal = plane->getNormal();
39 std::shared_ptr<VecDataArray<double, 3>> vertexData = pointSet->getVertexPositions();
42 ParallelUtils::parallelFor(static_cast<unsigned int>(vertices.size()),
43 [&](
const unsigned int idx)
45 Vec3d contactPt, contactNormal;
48 if (CollisionUtils::testPlaneToPoint(
49 planePt, planeNormal, vertices[idx],
50 contactPt, contactNormal, depth))
53 elemA.dir = planeNormal;
55 elemA.penetrationDepth = depth;
58 elemB.dir = -planeNormal;
59 elemB.pt = vertices[idx] + planeNormal * depth;
60 elemB.penetrationDepth = depth;
63 elementsA.push_back(elemA);
64 elementsB.push_back(elemB);
67 }, vertices.size() > 100);
72 std::shared_ptr<Geometry> geomA,
73 std::shared_ptr<Geometry> geomB,
74 std::vector<CollisionElement>& elementsA)
76 std::shared_ptr<PointSet> pointSet = std::dynamic_pointer_cast<
PointSet>(geomA);
77 std::shared_ptr<Plane> plane = std::dynamic_pointer_cast<
Plane>(geomB);
80 const Vec3d planeNormal = plane->getNormal();
82 std::shared_ptr<VecDataArray<double, 3>> vertexData = pointSet->getVertexPositions();
85 ParallelUtils::parallelFor(static_cast<unsigned int>(vertices.size()),
86 [&](
const unsigned int idx)
88 Vec3d contactPt, contactNormal;
91 if (CollisionUtils::testPlaneToPoint(
92 planePt, planeNormal, vertices[idx],
93 contactPt, contactNormal, depth))
96 elemA.dir = planeNormal;
98 elemA.penetrationDepth = depth;
101 elementsA.push_back(elemA);
104 }, vertices.size() > 100);
109 std::shared_ptr<Geometry> geomA,
110 std::shared_ptr<Geometry> geomB,
111 std::vector<CollisionElement>& elementsB)
113 std::shared_ptr<PointSet> pointSet = std::dynamic_pointer_cast<
PointSet>(geomA);
114 std::shared_ptr<Plane> plane = std::dynamic_pointer_cast<
Plane>(geomB);
117 const Vec3d planeNormal = plane->getNormal();
119 std::shared_ptr<VecDataArray<double, 3>> vertexData = pointSet->getVertexPositions();
122 ParallelUtils::parallelFor(static_cast<unsigned int>(vertices.size()),
123 [&](
const unsigned int idx)
125 Vec3d contactPt, contactNormal;
128 if (CollisionUtils::testPlaneToPoint(
129 planePt, planeNormal, vertices[idx],
130 contactPt, contactNormal, depth))
133 elemB.dir = -planeNormal;
134 elemB.pt = vertices[idx] + planeNormal * depth;
135 elemB.penetrationDepth = depth;
138 elementsB.push_back(elemB);
141 }, 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 computeCollisionDataB(std::shared_ptr< Geometry > geomA, std::shared_ptr< Geometry > geomB, std::vector< CollisionElement > &elementsB) override
Compute collision data for side B.
void setGenerateCD(const bool generateA, const bool generateB)
If generateA is false, CD data will not be generated for input0,A Similarly, if generateB is false...
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
Represents and infinite plane, width can be used for visual purposes.
void lock()
Start a thread-safe region, where only one thread can execute at a time until a call to the unlock fu...
Direclty gives a point-direction contact as its collision data, point given by index.
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.