7 #include "imstkPointwiseMap.h" 8 #include "imstkParallelUtils.h" 9 #include "imstkLogger.h" 10 #include "imstkPointSet.h" 14 PointwiseMap::PointwiseMap()
16 setRequiredInputType<PointSet>(0);
17 setRequiredInputType<PointSet>(1);
20 PointwiseMap::PointwiseMap(
21 std::shared_ptr<Geometry> parent,
22 std::shared_ptr<Geometry> child)
27 setRequiredInputType<PointSet>(0);
28 setRequiredInputType<PointSet>(1);
36 LOG(WARNING) <<
"PointwiseMap failed to run, inputs not satisfied";
54 tetVertToSurfVertMap.clear();
58 LOG(WARNING) <<
"PointwiseMap failed to run, inputs not satisfied";
62 auto meshParent = std::dynamic_pointer_cast<
PointSet>(getParentGeometry());
63 auto meshChild = std::dynamic_pointer_cast<
PointSet>(getChildGeometry());
65 std::shared_ptr<VecDataArray<double, 3>> parentVerticesPtr = meshParent->
getVertexPositions();
67 std::shared_ptr<VecDataArray<double, 3>> childVerticesPtr = meshChild->getVertexPositions();
72 ParallelUtils::parallelFor(meshChild->getNumVertices(),
77 if (matchingNodeId == -1)
85 tetVertToSurfVertMap[nodeId] = matchingNodeId;
93 for (
int idx = 0; idx < parentVertices.size(); idx++)
95 if (p.isApprox(parentVertices[idx],
m_epsilon))
119 auto meshParent = std::dynamic_pointer_cast<
PointSet>(getParentGeometry());
120 auto meshChild = std::dynamic_pointer_cast<
PointSet>(getChildGeometry());
129 std::shared_ptr<VecDataArray<double, 3>> childVerticesPtr = meshChild->getVertexPositions();
131 std::shared_ptr<VecDataArray<double, 3>> parentVerticesPtr = meshParent->getVertexPositions();
137 [&](
const size_t idx)
140 childVertices[mapValue.first] = parentVertices[mapValue.second];
void setMap(const std::unordered_map< int, int > &sourceMap)
Sets the one-to-one correspondence directly.
void unlock()
End a thread-safe region.
Base class for all geometries represented by discrete points and elements The pointsets follow a pipe...
void computeMap(std::unordered_map< int, int > &tetVertToSurfVertMap)
Compute tet vertex id to surf vertex id map.
int findMatchingVertex(const VecDataArray< double, 3 > &parentMesh, const Vec3d &p)
Returns the first matching vertex, -1 if not found.
void setParentGeometry(std::shared_ptr< Geometry > parent)
Get/Set parent geometry.
void requestUpdate() override
Apply (if active) the tetra-triangle mesh map.
int getParentVertexId(const int childVertexId) const
Get the mapped/corresponding parent index, given a child index. returns -1 if no correspondence found...
void setChildGeometry(std::shared_ptr< Geometry > child)
Get/Set child geometry.
std::unordered_map< int, int > m_oneToOneMap
One to one mapping data.
void lock()
Start a thread-safe region, where only one thread can execute at a time until a call to the unlock fu...
std::shared_ptr< VecDataArray< double, 3 > > getVertexPositions(DataType type=DataType::PostTransform) const
Returns the vector of current positions of the mesh vertices.
void postModified()
emits signal to all observers, informing them on the current address in memory and size of array ...
virtual bool areInputsValid()
Check inputs are correct.
void setOutput(std::shared_ptr< Geometry > inputGeometry, const size_t port=0)
Set the output at the port.
void compute() override
Compute the tetra-triangle mesh map.
double m_epsilon
Tolernace for considering two points equivalent/mapped. The tolerance is set a bit higher here since ...
std::vector< std::pair< int, int > > m_oneToOneMapVector
One to one mapping data.