iMSTK
Interactive Medical Simulation Toolkit
imstkPbdObjectStitching.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 "imstkMacros.h"
10 #include "imstkMath.h"
11 #include "imstkPbdCollisionConstraint.h"
12 #include "imstkSceneObject.h"
13 
14 #include <unordered_map>
15 
16 namespace imstk
17 {
18 class PbdBaryPointToPointConstraint;
19 class PbdObject;
20 class PickingAlgorithm;
21 class PointwiseMap;
22 
30 {
31 public:
32  PbdObjectStitching(std::shared_ptr<PbdObject> obj1);
33  ~PbdObjectStitching() override = default;
34 
35  IMSTK_TYPE_NAME(PbdObjectStitching)
36 
37 
38  void setStiffness(const double stiffness) { m_stiffness = stiffness; }
42  double getStiffness() const { return m_stiffness; }
44 
48  void setStitchDistance(const double distance) { m_maxStitchDist = distance; }
49  double getStitchDistance() const { return m_maxStitchDist; }
51 
57  void beginStitch(const Vec3d& rayStart, const Vec3d& rayDir, const double maxDist = -1.0);
58 
62  void addStitchConstraints();
63 
68 
74  virtual void addConstraint(
75  const std::vector<PbdParticleId>& ptsA,
76  const std::vector<double>& weightsA,
77  const std::vector<PbdParticleId>& ptsB,
78  const std::vector<double>& weightsB,
79  const double stiffnessA, const double stiffnessB);
80 
84  void setPickingAlgorithm(std::shared_ptr<PickingAlgorithm> pickMethod) { m_pickMethod = pickMethod; }
85  std::shared_ptr<PickingAlgorithm> getPickingAlgorithm() const { return m_pickMethod; }
87 
92  void setGeometryToStitch(std::shared_ptr<Geometry> geomToStitch, std::shared_ptr<PointwiseMap> map)
93  {
94  m_geomToStitch = geomToStitch;
95  m_geometryToStitchMap = map;
96  }
97 
98  std::shared_ptr<TaskNode> getPickingNode() const { return m_stitchingNode; }
99 
100  void initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink) override;
101 
102 protected:
106  virtual void updateStitching();
107 
108 protected:
109  std::shared_ptr<TaskNode> m_stitchingNode = nullptr;
110 
111  std::shared_ptr<Geometry> m_geomToStitch = nullptr;
112  std::shared_ptr<PointwiseMap> m_geometryToStitchMap = nullptr;
113 
114  std::shared_ptr<PbdObject> m_objectToStitch = nullptr;
115 
116  std::shared_ptr<PickingAlgorithm> m_pickMethod = nullptr;
117 
118  bool m_performStitch = false;
119 
122  double m_stiffness = 0.1;
123  double m_maxStitchDist = -1.0; // Set a maximum distance for which a stitch can be placed
124 
125  std::vector<std::shared_ptr<PbdBaryPointToPointConstraint>> m_constraints;
126 
127 private:
128  std::vector<PbdConstraint*> m_collisionConstraints;
129 };
130 } // namespace imstk
void addStitchConstraints()
Compute/generate the constraints for stitching.
virtual void addConstraint(const std::vector< PbdParticleId > &ptsA, const std::vector< double > &weightsA, const std::vector< PbdParticleId > &ptsB, const std::vector< double > &weightsB, const double stiffnessA, const double stiffnessB)
Add constraint between a point on each element given via barycentric coordinates pt position = weight...
std::vector< std::shared_ptr< PbdBaryPointToPointConstraint > > m_constraints
Array of PBD constraints.
void setStitchDistance(const double distance)
Set/Get the maximum distance for which a stitch may be placed.
void beginStitch(const Vec3d &rayStart, const Vec3d &rayDir, const double maxDist=-1.0)
Begin a ray point stitch. Stitches two points for separate elements.
Compound Geometry.
virtual void updateStitching()
Update picking state, this should move grasp points.
void setPickingAlgorithm(std::shared_ptr< PickingAlgorithm > pickMethod)
Get/Set the method use for picking, default is CellPicker.
void setStiffness(const double stiffness)
Set/Get the stiffness, 0-1 value that alters the step size in the solver.
This class defines stitching of a PbdObject via different picking methods. Ray based stitching is def...
Base class for all scene objects. A scene object can optionally be visible and collide with other sce...
void removeStitchConstraints()
Clears all the stitches.
void setGeometryToStitch(std::shared_ptr< Geometry > geomToStitch, std::shared_ptr< PointwiseMap > map)
Set a different geometry to pick with and a mapping back to the physics geometry to select the correc...
void initGraphEdges()
Initializes the edges of the SceneObject&#39;s computational graph.