iMSTK
Interactive Medical Simulation Toolkit
EmbeddingConstraint.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 "imstkPbdContactConstraint.h"
10 
11 namespace imstk
12 {
18 {
19 public:
21  ~EmbeddingConstraint() override = default;
22 
33  void initConstraint(
34  PbdState& bodies,
35  const PbdParticleId& ptA1, // rigid body id
36  const PbdParticleId& ptB1, const PbdParticleId& ptB2, const PbdParticleId& ptB3, // Triangle
37  Vec3d* p, Vec3d* q,
38  const double compliance = 0.0); // Needle line vertices
39 
44  Vec3d computeInterpolantDifference(const PbdState& bodies) const;
45 
46  bool computeValueAndGradient(PbdState& bodies,
47  double& c, std::vector<Vec3d>& dcdx) override;
48 
49 // Vec3d computeRelativeVelocity(PbdState& bodies) override;
50 
51  const Vec3d& getIntersectionPoint() const { return m_iPt; }
52  Vec3d* getP() const { return m_p; }
53  Vec3d* getQ() const { return m_q; }
54 
55 protected:
56  // Intersection point via interpolants on triangle
57  Vec3d m_uvw = Vec3d::Zero();
58  // Intersection point via interpolants on line
59  Vec2d m_uv = Vec2d::Zero();
60  double t = 0.0;
61 
62  // The actual line
63  Vec3d* m_p = nullptr;
64  Vec3d* m_q = nullptr;
65 
66 protected:
67  Vec3d m_iPt;
68 
69 protected:
70  // If 0.0, completely removes pbd reaction in line axes direction, the pbd triangle will completely let
71  // the tool slide in that direction
72  // If 1.0, completely resist normal movement
73  double m_normalFriction = 0.0;
74 };
75 } // namespace imstk
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.
bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx) override
Compute value and gradient of the constraint.
Vec3d computeInterpolantDifference(const PbdState &bodies) const
Given two interpolants on the two elements, compute the difference between them and use for resolutio...
void initConstraint(PbdState &bodies, const PbdParticleId &ptA1, const PbdParticleId &ptB1, const PbdParticleId &ptB2, const PbdParticleId &ptB3, Vec3d *p, Vec3d *q, const double compliance=0.0)
Initializes both PBD and RBD constraint.
Constrains a rigid body line segment defined via p and q to a "puncture" point defined via barycentri...
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229
A constraint on a rigid body that defines rotationl correction through dx applied at a local position...