7 #include "imstkAnalyticalGeometry.h" 8 #include "imstkBurner.h" 9 #include "imstkCDObjectFactory.h" 10 #include "imstkCellMesh.h" 11 #include "imstkCellPicker.h" 12 #include "imstkParallelUtils.h" 13 #include "imstkPbdObject.h" 14 #include "imstkPbdModel.h" 15 #include "imstkPbdModelConfig.h" 16 #include "imstkPickingAlgorithm.h" 17 #include "imstkTaskGraph.h" 18 #include "imstkTaskNode.h" 19 #include "imstkParallelFor.h" 23 Burner::Burner(
const std::string& name) :
SceneBehaviour(true, name)
25 m_burningHandleNode = std::make_shared<TaskNode>([
this]()
28 },
"Handle_" + m_name);
36 CHECK(m_burningObj !=
nullptr) <<
"Burner requires an object to do the burning";
38 if (m_burnGeometry ==
nullptr)
40 m_burnGeometry = std::dynamic_pointer_cast<
AnalyticalGeometry>(m_burningObj->getPhysicsGeometry());
41 CHECK(m_burnGeometry !=
nullptr) <<
"Burner requires analytical geometry for physics geometry";
45 if (m_burnableObjects.empty())
47 LOG(INFO) <<
"There are no burnable objects for the burning tool to burn.";
51 m_taskGraph->addNode(m_burningHandleNode);
52 m_taskGraph->addNode(m_burningObj->getPbdModel()->getTaskGraph()->getSink());
53 m_taskGraph->addNode(m_burningObj->getPbdModel()->getIntegratePositionNode());
54 m_taskGraph->addNode(m_burningObj->getPbdModel()->getSolveNode());
58 Burner::visualUpdate(
const double& dt)
61 m_didBurnLastPhysics = m_didBurn;
67 Burner::getDidBurn()
const 69 return m_didBurnLastPhysics;
76 if (m_onState && m_burnOnce)
79 ParallelUtils::parallelFor(m_burnableObjects.size(), [
this](
const int index) {
80 handleBurnable(index);
81 }, m_burnableObjects.size() > 1);
86 Burner::handleBurnable(
int burnableId)
88 if (m_burnableObjects[burnableId].
object ==
nullptr)
93 if (m_burnableObjects[burnableId].picker ==
nullptr)
96 auto cellPicker = std::make_shared<CellPicker>();
97 cellPicker->setPickingGeometry(m_burnGeometry);
99 std::shared_ptr<Geometry> pbdPhysicsGeom = m_burnableObjects[burnableId].object->getPhysicsGeometry();
100 CHECK(pbdPhysicsGeom !=
nullptr) <<
"Physics geometry of burnable object: " << m_burnableObjects[burnableId].object->getName() <<
" is null in Burner";
108 m_burnableObjects[burnableId].picker = cellPicker;
112 std::shared_ptr<Geometry> geometryToPick = m_burnableObjects[burnableId].object->getPhysicsGeometry();
113 const std::vector<PickData>& pickData = m_burnableObjects[burnableId].picker->pick(geometryToPick);
115 for (
size_t i = 0; i < pickData.size(); i++)
126 applyBurn(burnableId, data.
cellId);
131 Burner::applyBurn(
int burnableId,
int cellId)
137 auto cellMesh = std::dynamic_pointer_cast<
AbstractCellMesh>(m_burnableObjects[burnableId].object->getPhysicsGeometry());
138 auto burnDamagePtr = std::dynamic_pointer_cast<
DataArray<double>>(cellMesh->getCellAttribute(
"BurnDamage"));
141 auto burnVisualPtr = std::dynamic_pointer_cast<
DataArray<double>>(cellMesh->getCellAttribute(
"BurnVisual"));
144 monopolarToolModel(burnDamage[cellId], burnVisual[cellId], m_burnTime);
149 Burner::monopolarToolModel(
double& burnDmg,
double& burnVis,
double dt)
151 burnDmg += m_onTime * m_q * m_normWattage * dt;
152 burnVis += (1.0 - m_onTime) * m_q * m_normWattage * dt;
156 Burner::initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink)
158 m_taskGraph->addEdge(source, m_burningObj->getPbdModel()->getIntegratePositionNode());
159 m_taskGraph->addEdge(m_burningObj->getPbdModel()->getIntegratePositionNode(), m_burningHandleNode);
160 m_taskGraph->addEdge(m_burningHandleNode, m_burningObj->getPbdModel()->getSolveNode());
161 m_taskGraph->addEdge(m_burningObj->getPbdModel()->getSolveNode(), m_burningObj->getPbdModel()->getTaskGraph()->getSink());
162 m_taskGraph->addEdge(m_burningObj->getPbdModel()->getTaskGraph()->getSink(), sink);
Base class for any analytical geometrical representation.
void init() override
Initialize the component, called at a later time after all component construction is complete...
std::weak_ptr< Entity > getEntity() const
Get parent entity.
int cellId
Supplemental cell id (when vertices are provided above and cell id is available)
static std::shared_ptr< CollisionDetectionAlgorithm > makeCollisionDetection(const std::string collisionTypeName)
attempts to create a new CD algorithm
PickData provides ids to indicate what was picked These may be optionally used to indicate the select...
Base class for scene objects that move and/or deform under position based dynamics formulation...
static std::string getCDType(const Geometry &obj1, const Geometry &obj2)
Get the CD type from the types of objects colliding.
Provides non templated base for cell based meshes.