iMSTK
Interactive Medical Simulation Toolkit
imstkLaparoscopicToolController.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 "imstkTrackingDeviceControl.h"
10 
11 namespace imstk
12 {
13 class CollidingObject;
14 class Geometry;
15 
25 {
26 public:
27  enum class JawState
28  {
29  Closed,
30  Opened
31  };
32 
33 public:
34  LaparoscopicToolController(const std::string& name = "LaparoscopicToolController") : TrackingDeviceControl(name) { }
35  ~LaparoscopicToolController() override = default;
36 
37  void setParts(
38  std::shared_ptr<CollidingObject> shaft,
39  std::shared_ptr<CollidingObject> upperJaw,
40  std::shared_ptr<CollidingObject> lowerJaw,
41  std::shared_ptr<Geometry> pickGeom);
42 
43  void setDevice(std::shared_ptr<DeviceClient> device) override;
44 
45  // *INDENT-OFF*
50 
55  // *INDENT-ON*
56 
57 public:
61  void update(const double& dt) override;
62 
66  void setMaxJawAngle(const double maxAngle) { m_maxJawAngle = maxAngle; }
67 
71  void setJawAngleChange(const double dAngle) { m_change = dAngle; }
72 
76  void setJawRotationAxis(const Vec3d& axis) { m_jawRotationAxis = axis; }
77 
81  double getJawAngle() const { return m_jawAngle; }
82 
86  double getMaxJawAngle() const { return m_maxJawAngle; }
87 
92  JawState getJawState() const { return m_jawState; }
93 
94 protected:
95  std::shared_ptr<CollidingObject> m_shaft;
96  std::shared_ptr<CollidingObject> m_upperJaw;
97  std::shared_ptr<CollidingObject> m_lowerJaw;
98  std::shared_ptr<Geometry> m_pickGeom;
99 
100  double m_jawAngle = PI / 6.0;
101  double m_change = 6.0e-5;
102  double m_maxJawAngle = PI / 6.0;
103  JawState m_jawState = JawState::Opened;
104 
105  Vec3d m_jawRotationAxis = Vec3d(1.0, 0.0, 0.0);
106 
107  Mat4d m_controllerWorldTransform = Mat4d::Identity(); // Final world transform of the controller
108  Mat4d m_pickGeomTransform = Mat4d::Identity();
109 
110  Mat4d m_shaftVisualTransform = Mat4d::Identity(); // Initial local transform of the visual shaft
111  Mat4d m_upperJawVisualTransform = Mat4d::Identity(); // Initial local transform of the visual upper jaw
112  Mat4d m_lowerJawVisualTransform = Mat4d::Identity(); // Initial local transform of the visual lower jaw
113 
114  Mat4d m_shaftCollidingTransform = Mat4d::Identity(); // Initial local transform of the colliding shaft
115  Mat4d m_upperJawCollidingTransform = Mat4d::Identity(); // Initial local transform of the colliding upper jaw
116  Mat4d m_lowerJawCollidingTransform = Mat4d::Identity(); // Initial local transform of the colliding lower jaw
117 
118  Mat4d m_upperJawLocalTransform = Mat4d::Identity(); // upperJawWorldTransform = m_controllerWorldTransform * m_upperJawLocalTransform * m_upperJawVisual/CollidingTransform
119  Mat4d m_lowerJawLocalTransform = Mat4d::Identity(); // lowerJawWorldTransform = m_controllerWorldTransform * m_lowerJawLocalTransform * m_lowerJawVisual/CollidingTransform
120 };
121 } // namespace imstk
JawState getJawState() const
Get the state of the jaw whether it is open or closed.
std::shared_ptr< CollidingObject > m_upperJaw
Tool upper jaw.
void setJawAngleChange(const double dAngle)
Set the increment.
Two-jawed laparoscopic tool controlled by external device The tool is composed of three scene objects...
double getJawAngle() const
Get the current jaw angle.
Compound Geometry.
void setJawRotationAxis(const Vec3d &axis)
Set the jaw rotation axis.
SIGNAL(LaparoscopicToolController, JawClosed)
Fired once when the jaw transitions to closed state.
double m_change
Amount of change in jaw angle per frame.
std::shared_ptr< CollidingObject > m_shaft
Tool shaft.
double m_maxJawAngle
Maximum angle of the jaws.
std::shared_ptr< CollidingObject > m_lowerJaw
Tool lower jaw.
void setMaxJawAngle(const double maxAngle)
Set the maximum jaw angle.
Base class for all DeviceControls that track something in space (position and orientation) ...
void update(const double &dt) override
Update controlled laparoscopic tool using latest tracking information.
double getMaxJawAngle() const
Get the max jaw angle.