7 #include "imstkMeshCut.h" 8 #include "imstkAnalyticalGeometry.h" 9 #include "imstkSurfaceMesh.h" 16 setRequiredInputType<AbstractCellMesh>(0);
18 m_CutGeometry =
nullptr;
19 m_RemoveConstraintVertices = std::make_shared<std::unordered_set<size_t>>();
20 m_AddConstraintVertices = std::make_shared<std::unordered_set<size_t>>();
28 if (inputGeom ==
nullptr)
30 LOG(WARNING) <<
"Missing required AbstractCellMesh input";
38 std::map<int, bool> cutVerts;
42 if (m_CutData->size() == 0)
51 splitVerts(outputGeom, cutVerts, m_CutGeometry);
57 if (
auto implicitGeom = std::dynamic_pointer_cast<ImplicitGeometry>(geometry))
59 const double normalProjection = implicitGeom->getFunctionValue(pt);
60 if (normalProjection > m_Epsilon)
64 else if (normalProjection < -m_Epsilon)
69 else if (std::dynamic_pointer_cast<SurfaceMesh>(geometry) !=
nullptr)
77 MeshCut::pointProjectionInSurface(
const Vec3d& pt,
78 std::shared_ptr<SurfaceMesh> surface)
80 std::shared_ptr<VecDataArray<int, 3>> triangles = surface->getCells();
81 std::shared_ptr<VecDataArray<double, 3>> vertices = surface->getVertexPositions();
82 bool inSurface =
false;
84 for (
const Vec3i& tri : *triangles)
86 const Vec3d p0 = (*vertices)[tri[0]];
87 const Vec3d p1 = (*vertices)[tri[1]];
88 const Vec3d p2 = (*vertices)[tri[2]];
89 const Vec3d normal = (p1 - p0).cross(p2 - p0).normalized();
91 const double leftP0P1 = normal.dot((p1 - p0).cross(pt - p0));
92 const double leftP1P2 = normal.dot((p2 - p1).cross(pt - p1));
93 const double leftP2P0 = normal.dot((p0 - p2).cross(pt - p2));
95 if (leftP0P1 >= 0.0 && leftP1P2 >= 0.0 && leftP2P0 >= 0.0)
virtual void refinement(std::shared_ptr< AbstractCellMesh > outputGeom, std::map< int, bool > &cutVerts)=0
Refine the mesh adding vertices and changing connectivity along the cut.
std::shared_ptr< Geometry > getInput(size_t port=0) const
Returns input geometry given port, returns nullptr if doesn't exist.
int ptBoundarySign(const Vec3d &pt, std::shared_ptr< Geometry > geometry)
Determine the sign of the point -1 if inside, 1 if outside, 0 if on boundary defined by epsilon...
std::shared_ptr< Geometry > getOutput(size_t port=0) const
Returns output geometry given port, returns nullptr if doesn't exist.
virtual void splitVerts(std::shared_ptr< AbstractCellMesh > outputGeom, std::map< int, bool > &cutVerts, std::shared_ptr< Geometry > cuttingGeom)=0
Split the cutting vertices, separating them into two.
void requestUpdate() override
Users can implement this for the logic to be run.
void setOutput(std::shared_ptr< Geometry > inputGeometry, const size_t port=0)
Set the output at the port.
virtual std::shared_ptr< std::vector< CutData > > generateCutData(std::shared_ptr< Geometry > cuttingGeom, std::shared_ptr< AbstractCellMesh > geomToCut)=0
Generate CutData which defines how the cut should be performed.
void setNumInputPorts(const size_t numPorts)
Get/Set the amount of input ports.
Provides non templated base for cell based meshes.