iMSTK
Interactive Medical Simulation Toolkit
imstkPbdObjectCellRemoval.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 #pragma once
7 
8 #include "imstkSceneObject.h"
9 #include "imstkMacros.h"
10 #include "imstkMath.h"
11 
12 #include <unordered_set>
13 #include <map>
14 #include <unordered_map>
15 
16 namespace imstk
17 {
18 class PointSet;
19 class AbstractCellMesh;
20 class PbdObject;
21 class SurfaceMesh;
22 class PointwiseMap;
38 {
39 public:
40 
41  enum class OtherMeshUpdateType
42  {
43  None = 0,
44  Collision = 1,
45  VisualReuseVertices = 2, // If possible reuse a vertex from the visual mesh when removing tetrahedron
46  VisualSeparateVertices = 4, // Create a new vertex even if it existed in the visual mesh
47  CollisionAndVisualSeparate = Collision | VisualSeparateVertices,
48  CollisionAndVisualReused = Collision | VisualReuseVertices
49  };
50 
51  PbdObjectCellRemoval(std::shared_ptr<PbdObject> pbdObj, OtherMeshUpdateType alsoUpdate = OtherMeshUpdateType::None);
52  ~PbdObjectCellRemoval() override = default;
53 
54  IMSTK_TYPE_NAME(PbdObjectCellRemoval)
55 
56 
57  void removeCellOnApply(int cellId);
60 
64  void apply();
65 
69  std::vector<int> getRemovedCells() { return m_removedCells; }
70 
71 protected:
72 
73  void removeConstraints();
74 
75  void addDummyVertexPointSet(std::shared_ptr<PointSet> pointSet);
76  void addDummyVertex(std::shared_ptr<AbstractCellMesh> mesh);
77  void fixup();
78 
79  std::shared_ptr<PbdObject> m_obj;
80  std::shared_ptr<AbstractCellMesh> m_mesh;
81  std::vector<int> m_cellsToRemove;
82  std::vector<int> m_removedCells;
83 
84 private:
85  struct LinkedMeshData
86  {
87  bool newVertexOnSplit = false;
88  std::shared_ptr<SurfaceMesh> surfaceMesh;
89  std::shared_ptr<PointwiseMap> map;
90 
92  std::multimap<int, int> tetToTriMap;
93 
96  std::multimap<int, std::pair<int, Vec3i>> tetAdjancencyMap;
97 
98  // The reverse of the PointwiseMap mapping
99  std::unordered_map<int, int> tetVertToTriVertMap;
100  };
101 
102  OtherMeshUpdateType m_updateMode;
103 
104  std::vector<LinkedMeshData> m_linkedMeshData;
105 
106  void updateMesh(LinkedMeshData& data);
107  void setupForExtraMeshUpdates(std::shared_ptr<SurfaceMesh> surfaceMesh, std::shared_ptr<PointwiseMap> map);
108 };
109 } // namespace imstk
std::vector< int > m_cellsToRemove
List of cells to remove, cleared after removal.
std::vector< int > m_removedCells
Cells that have been removed.
std::shared_ptr< PbdObject > m_obj
Object that cells are removed from.
void removeCellOnApply(int cellId)
Adds cell to list of cells to be removed.
Compound Geometry.
This class defines a method of removing cells and their associated constraints from a Pbd object...
std::shared_ptr< AbstractCellMesh > m_mesh
Mesh from object cells are removed from.
Base class for all scene objects. A scene object can optionally be visible and collide with other sce...
void apply()
removed cells and associated constraints
std::vector< int > getRemovedCells()
Get ids of cells that have been removed.