iMSTK
Interactive Medical Simulation Toolkit
imstkPointwiseMap.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkGeometryMap.h"
10 #include "imstkMacros.h"
11 #include "imstkMath.h"
12 #include "imstkTypes.h"
13 
14 namespace imstk
15 {
16 template<typename T, int N> class VecDataArray;
17 
24 class PointwiseMap : public GeometryMap
25 {
26 public:
27  PointwiseMap();
29  std::shared_ptr<Geometry> parent,
30  std::shared_ptr<Geometry> child);
31  ~PointwiseMap() override = default;
32 
33  IMSTK_TYPE_NAME(PointwiseMap)
34 
35 
36  void compute() override;
39 
43  void computeMap(std::unordered_map<int, int>& tetVertToSurfVertMap);
44 
48  void setMap(const std::unordered_map<int, int>& sourceMap);
49  const std::unordered_map<int, int>& getMap() const { return m_oneToOneMap; }
50 
54  void addNewUniquePoint(int sourceId, int targetId)
55  {
56  m_oneToOneMap[sourceId] = targetId;
57  m_oneToOneMapVector.push_back({ sourceId, targetId });
58  }
59 
65  int getParentVertexId(const int childVertexId) const;
66 
71  void setTolerance(const double tolerance) { m_epsilon = tolerance; }
72  double getTolerance() const { return m_epsilon; }
74 
75 protected:
79  int findMatchingVertex(const VecDataArray<double, 3>& parentMesh, const Vec3d& p);
80 
84  void requestUpdate() override;
85 
86 public:
87  // A map and vector are maintained. The vector for parallel processing, the map for fast lookup
88  std::unordered_map<int, int> m_oneToOneMap;
89  std::vector<std::pair<int, int>> m_oneToOneMapVector;
90 
96  double m_epsilon = 0.00000001;
97 };
98 } // namespace imstk
void setMap(const std::unordered_map< int, int > &sourceMap)
Sets the one-to-one correspondence directly.
void computeMap(std::unordered_map< int, int > &tetVertToSurfVertMap)
Compute tet vertex id to surf vertex id map.
void addNewUniquePoint(int sourceId, int targetId)
Unsafe function for adding new points Can be used in methods that modify the parent mesh when new ver...
int findMatchingVertex(const VecDataArray< double, 3 > &parentMesh, const Vec3d &p)
Returns the first matching vertex, -1 if not found.
Compound 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...
std::unordered_map< int, int > m_oneToOneMap
One to one mapping data.
PointwiseMap can compute & apply a mapping between parent and child PointSet geometries.
Base class for any geometric map.
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 ...
void setTolerance(const double tolerance)
Set/Get the tolerance. The distance to consider two points equivalent/corresponding.
std::vector< std::pair< int, int > > m_oneToOneMapVector
One to one mapping data.