iMSTK
Interactive Medical Simulation Toolkit
imstkBurner.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 #include "imstkComponent.h"
8 #include "imstkMath.h"
9 
10 #pragma once
11 
12 namespace imstk
13 {
14 class PbdObject;
15 class TaskNode;
16 class CellPicker;
17 class AnalyticalGeometry;
18 
28 class Burner : public SceneBehaviour
29 {
30 public:
31  Burner(const std::string& name = "BurnerPbdObjectBehavior");
32 
33  void init() override;
34 
38  std::shared_ptr<PbdObject> getBurnerObject() const { return m_burningObj; }
40 
44  std::shared_ptr<AnalyticalGeometry> getBurnerGeometry() const { return m_burnGeometry; }
45  void setBurnerGeometry(std::shared_ptr<AnalyticalGeometry> geom)
46  {
47  CHECK(geom != nullptr);
48  m_burnGeometry = geom;
49  }
50 
52 
58  double getOnTime() const { return m_onTime; }
59  void setOnTime(const double onTime)
60  {
61  CHECK(onTime >= 0.0 && onTime <= 1.0) << "On time in the burning component must be between 0 and 1 \n";
62  m_onTime = onTime;
63  }
64 
66 
72  double getWattage() const { return m_wattage; }
73  void setWattage(const double wattage)
74  {
75  CHECK(wattage >= 10.0 && wattage <= 200.0) << "Wattage is currently forced to be within 10 and 200 for the burning tool, set value within these bounds \n";
76  m_wattage = wattage;
77  m_normWattage = wattage / 100.0;
78  }
79 
81 
85  void start() { m_onState = true; }
86  void stop() { m_onState = false; }
88 
92  void addObject(std::shared_ptr<PbdObject> obj)
93  {
94  m_burnableObjects.push_back({ obj, nullptr });
95  }
96 
98 
100  bool getState() const { return m_onState; }
101 
102  // Check state of mesh and delete cells that are burned away
103  // void update(double dt);
104  void visualUpdate(const double& dt) override;
105 
106  bool getDidBurn() const;
107 
108 protected:
109 
110  // The handle does the picking to choose which cells are burned.
111  void handle();
112 
113  void handleBurnable(int burnableId);
114 
115  // Applies the burn using the burn model
116  void applyBurn(int burnableId, int cellId);
117 
118  // Burner model for the monopolar tool (variables defined below)
119  // Damage evolution: damage^{n+1} = damage^{n} + onTime*q*normWattage*dt
120  // Visual evolution: visual^{n+1} = visual^{n} + (1-onTime)*q*normWattage*dt
121  void monopolarToolModel(double& burnDmg, double& burnVis, double dt);
122 
123  void initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink) override;
124 
125  std::shared_ptr<PbdObject> m_burningObj;
126  std::shared_ptr<AnalyticalGeometry> m_burnGeometry;
127 
128  std::shared_ptr<TaskNode> m_burningHandleNode;
129 
130  struct Burnable
131  {
132  std::shared_ptr<PbdObject> object;
133  std::shared_ptr<CellPicker> picker;
134  };
135 
136  std::vector<Burnable> m_burnableObjects;
137 
138  double m_onTime = 0.5;
139  double m_wattage = 50;
140  double m_normWattage = 0.5;
141  double m_q = 4.0;
142 
143  bool m_onState = false;
144  bool m_burnOnce = false;
145  bool m_didBurnLastPhysics = false;
146 private:
147  bool m_didBurn = false;
148  double m_burnTime = 0;
149 };
150 } // namespace imstk
std::shared_ptr< AnalyticalGeometry > m_burnGeometry
Geometry doing the burning.
Definition: imstkBurner.h:126
double m_q
Fitting parameter that modifies how quickly tissue gets burned.
Definition: imstkBurner.h:141
double m_normWattage
Tool wattage / 100.
Definition: imstkBurner.h:140
double getOnTime() const
Get/Set the ontime from [0,1] where 1 is on fully and any value less than 1 is the percent of on time...
Definition: imstkBurner.h:58
void init() override
Initialize the component, called at a later time after all component construction is complete...
Definition: imstkBurner.cpp:32
bool m_didBurnLastPhysics
Buffer for providing information to the user.
Definition: imstkBurner.h:145
Compound Geometry.
std::vector< Burnable > m_burnableObjects
Set of burnable objects, currently set by user during setup.
Definition: imstkBurner.h:136
bool getState() const
Get state of burner (on/off ~ true/false)
Definition: imstkBurner.h:100
std::shared_ptr< AnalyticalGeometry > getBurnerGeometry() const
Get/Set the geometry doing the burning, if it&#39;s not set the collision geoemtry of the burner object w...
Definition: imstkBurner.h:44
A Behaviour represents a single component system A template is used here for UpdateInfo to keep the C...
void addObject(std::shared_ptr< PbdObject > obj)
Add burnable object to list of things that can be burned.
Definition: imstkBurner.h:92
double m_onTime
On time for energy burning tool from [0,1].
Definition: imstkBurner.h:138
bool m_burnOnce
Rate limit the burning to once per phyics cycle.
Definition: imstkBurner.h:144
double m_wattage
Tool wattage.
Definition: imstkBurner.h:139
std::shared_ptr< PbdObject > getBurnerObject() const
Get the object doing the burning.
Definition: imstkBurner.h:38
std::shared_ptr< PbdObject > m_burningObj
PbdObject doing the burning.
Definition: imstkBurner.h:125
bool m_onState
flag if tool is currently on or not
Definition: imstkBurner.h:143
Defines the behaviour to allow a tool to burn a pbdObject. This is done by storing state on the mesh ...
Definition: imstkBurner.h:28
double getWattage() const
Get/Set the wattage. This value is generally between 50-80 watts for L-hook monopolar devices...
Definition: imstkBurner.h:72
void start()
Start/Stop the burn by changing the onState flag.
Definition: imstkBurner.h:85