iMSTK
Interactive Medical Simulation Toolkit
imstkPbdObjectCutting.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 "imstkSceneObject.h"
10 #include "imstkCellMesh.h"
11 #include "imstkMacros.h"
12 
13 #include <unordered_set>
14 #include <vector>
15 
16 namespace imstk
17 {
18 template<typename T, int N> class VecDataArray;
19 class CollidingObject;
20 class PbdObject;
21 class SurfaceMesh;
22 
31 {
32 public:
33  PbdObjectCutting(std::shared_ptr<PbdObject> pbdObj, std::shared_ptr<CollidingObject> cutObj);
34  ~PbdObjectCutting() override = default;
35 
36  IMSTK_TYPE_NAME(PbdObjectCutting)
37 
38 
39  double getEpsilon() const { return m_epsilon; }
43  void setEpsilon(const double eps) { m_epsilon = eps; }
45 
49  void apply();
50 
51 protected:
55  void addVertices(std::shared_ptr<SurfaceMesh> pbdMesh,
56  std::shared_ptr<VecDataArray<double, 3>> vertices,
57  std::shared_ptr<VecDataArray<double, 3>> initialVertices);
58 
62  void modifyVertices(std::shared_ptr<SurfaceMesh> pbdMesh,
63  std::shared_ptr<std::vector<size_t>> vertexIndices,
64  std::shared_ptr<VecDataArray<double, 3>> vertices,
65  std::shared_ptr<VecDataArray<double, 3>> initialVertices);
66 
70  template<int N>
71  void addCells(std::shared_ptr<CellMesh<N>> pbdMesh,
72  std::shared_ptr<VecDataArray<int, N>> newCells)
73  {
74  std::shared_ptr<VecDataArray<int, N>> cells = pbdMesh->getCells();
75  const int nCells = cells->size();
76  const int nNewCells = newCells->size();
77 
78  cells->reserve(nCells + nNewCells);
79  for (int i = 0; i < nNewCells; i++)
80  {
81  const Vec3i& cell = (*newCells)[i];
82  cells->push_back(cell);
83  for (int j = 0; j < N; j++)
84  {
85  m_addConstraintVertices->insert(cell[j]);
86  }
87  }
88  }
89 
93  void modifyTriangles(std::shared_ptr<SurfaceMesh> pbdMesh,
94  std::shared_ptr<std::vector<size_t>> elementIndices,
95  std::shared_ptr<VecDataArray<int, 3>> elements);
96 
97  double m_epsilon = 0.1;
98 
99  std::shared_ptr<PbdObject> m_objA = nullptr;
100  std::shared_ptr<CollidingObject> m_objB = nullptr;
101 
102  std::shared_ptr<std::unordered_set<size_t>> m_removeConstraintVertices = std::make_shared<std::unordered_set<size_t>>();
103  std::shared_ptr<std::unordered_set<size_t>> m_addConstraintVertices = std::make_shared<std::unordered_set<size_t>>();
104 };
105 } // namespace imstk
void modifyTriangles(std::shared_ptr< SurfaceMesh > pbdMesh, std::shared_ptr< std::vector< size_t >> elementIndices, std::shared_ptr< VecDataArray< int, 3 >> elements)
Modify existing elements of pbdObj.
void addCells(std::shared_ptr< CellMesh< N >> pbdMesh, std::shared_ptr< VecDataArray< int, N >> newCells)
Add new elements to pbdObj.
void apply()
Applies the cut when called.
Compound Geometry.
This class defines a cutting interaction between a PbdObject and a CollidingObject. PbdObjectCutting::apply can be used to perform a discrete cut given the current states of both objects.
void modifyVertices(std::shared_ptr< SurfaceMesh > pbdMesh, std::shared_ptr< std::vector< size_t >> vertexIndices, std::shared_ptr< VecDataArray< double, 3 >> vertices, std::shared_ptr< VecDataArray< double, 3 >> initialVertices)
Modify current vertices of pbdObj.
Base class for all scene objects. A scene object can optionally be visible and collide with other sce...
void addVertices(std::shared_ptr< SurfaceMesh > pbdMesh, std::shared_ptr< VecDataArray< double, 3 >> vertices, std::shared_ptr< VecDataArray< double, 3 >> initialVertices)
Add new vertices to pbdObj.
Abstract template base class for all meshes that have homogenous cell types. This class allows templa...
Definition: imstkCellMesh.h:23
double getEpsilon() const
Epsilon controls the distance a point needs to be to be considered "inside" the cutting zone...