iMSTK
Interactive Medical Simulation Toolkit
imstkPbdInflatableDistanceConstraint.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 "imstkPbdDistanceConstraint.h"
10 #include "imstkPbdConstraintFunctor.h"
11 
12 namespace imstk
13 {
18 {
19 public:
21 
25  void initConstraint(const Vec3d& p0, const Vec3d& p1,
26  const PbdParticleId& pIdx0,
27  const PbdParticleId& pIdx1,
28  const double k = 1e5)
29  {
30  PbdDistanceConstraint::initConstraint(p0, p1, pIdx0, pIdx1, k);
31  m_initialRestLength = m_restLength;
32  m_initialStiffness = m_stiffness;
33  }
34 
39  const double dt,
40  const SolverType& type) override
41  {
42  if (isInflated())
43  {
44  m_restLength =
45  m_restLength + m_diffusionRate * dt * (m_initialRestLength - m_restLength);
46  m_stiffness = m_stiffness + m_diffusionRate * dt * (m_initialStiffness - m_stiffness);
47  }
48  PbdConstraint::projectConstraint(bodies, dt, type);
49  }
50 
51  void setRestLength(const double restLength) { m_restLength = restLength; }
52  const double getRestLength() const { return m_restLength; }
53 
54  void setInitRestLength(const double initRestLength) { m_initialRestLength = initRestLength; }
55  const double getInitRestLength() const { return m_initialRestLength; }
56 
60  void resetRestLength() { m_restLength = m_initialRestLength; }
61  void resetStiffness() { m_stiffness = m_initialStiffness; }
62 
63  bool isInflated() const { return m_inflated; }
64  void setInflated() { m_inflated = true; }
65 
66 public:
67  double m_initialRestLength = 0.0;
68  double m_initialStiffness = 1.0;
69  double m_diffusionRate = 0.00001;
70 
71  bool m_inflated = false;
72 };
73 
75 {
76  public:
78  ~PbdInflatableDistanceConstraintFunctor() override = default;
79 
83  std::shared_ptr<PbdDistanceConstraint> makeDistConstraint(
84  const VecDataArray<double, 3>& vertices,
85  int i1, int i2) override
86  {
87  auto constraint = std::make_shared<PbdInflatableDistanceConstraint>();
88  constraint->initConstraint(vertices[i1], vertices[i2],
89  { m_bodyIndex, i1 }, { m_bodyIndex, i2 }, m_stiffness);
90  return constraint;
91  }
92 };
93 } // imstk
double m_restLength
Rest length between the nodes.
void projectConstraint(PbdState &bodies, const double dt, const SolverType &type) override
Apply diffusion and update positions.
std::pair< int, int > PbdParticleId
Index pair that refers to a particle in a PbdState. Index 0 is the body id, Index 1 is the particle i...
Compound Geometry.
void initConstraint(const Vec3d &p0, const Vec3d &p1, const PbdParticleId &pIdx0, const PbdParticleId &pIdx1, const double k=1e5)
Initialize the constraint with resting length as the length between the two points.
Distance constraints between two nodal points.
std::shared_ptr< PbdDistanceConstraint > makeDistConstraint(const VecDataArray< double, 3 > &vertices, int i1, int i2) override
Create the distance constraint.
void initConstraint(const Vec3d &p0, const Vec3d &p1, const PbdParticleId &pIdx0, const PbdParticleId &pIdx1, const double k=1e5)
Initializes the inflatable distance constraint.
double m_stiffness
used in PBD, [0, 1]
SolverType
Type of solvers.
void resetRestLength()
Reset constraint rest measurement.
PbdDistanceConstraintFunctor generates constraints between the edges of the input TetrahedralMesh...
virtual void projectConstraint(PbdState &bodies, const double dt, const SolverType &type)
Update positions by projecting constraints.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229