iMSTK
Interactive Medical Simulation Toolkit
imstkLinearProjectionConstraint.cpp
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 #include "imstkLinearProjectionConstraint.h"
8 
9 namespace imstk
10 {
11 LinearProjectionConstraint::
12 LinearProjectionConstraint(const size_t& nodeId,
13  const bool isFixed /*= false*/) :
14  m_isFixedConstraint(false),
15  m_projection(Mat3d::Identity()),
16  m_value(Vec3d(0., 0., 0.))
17 {
18  m_nodeId = nodeId;
19  if (isFixed)
20  {
21  m_projection = Mat3d::Zero();
22  m_isFixedConstraint = true;
23  }
24 }
25 
26 void
27 LinearProjectionConstraint::setProjection(const size_t& nodeId, const Vec3d& p, const Vec3d& q /*= Vec3d::Zero()*/)
28 {
29  m_nodeId = nodeId;
30  m_projection = Mat3d::Identity() - p * p.transpose() - q * q.transpose();
31 }
32 
33 void
34 LinearProjectionConstraint::setProjectionToLine(const size_t& nodeId, const Vec3d& p)
35 {
36  m_nodeId = nodeId;
37  auto v = p / p.norm();
38  m_projection = v * v.transpose();
39 }
40 
41 void
42 LinearProjectionConstraint::setProjectorToDirichlet(const unsigned int& nodeId, const Vec3d z)
43 {
44  m_nodeId = nodeId;
45  m_projection = Mat3d::Zero();
46  m_isFixedConstraint = true;
47  m_value = z;
48 }
49 
50 void
52 {
53  m_projection = Mat3d::Identity();
54  m_value = Vec3d(0.0, 0.0, 0.0);
55 }
56 } // namespace imstk
Compound Geometry.
void setProjectionToLine(const size_t &nodeId, const Vec3d &p)
Form the projection.
void setProjectorToDirichlet(const size_t &nodeId)
Set the projector to simulate Dirichlet conditions.
void setProjection(const size_t &nodeId, const Vec3d &p, const Vec3d &q=Vec3d::Zero())
Form the projection.
void reset()
Reset the linear projector.