iMSTK
Interactive Medical Simulation Toolkit
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
imstkPuncturable.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 "imstkPuncturable.h"
8 #include "imstkEntity.h"
9 #include "imstkNeedle.h"
10 
11 namespace imstk
12 {
13 void
14 Puncturable::setPuncture(const PunctureId& id, std::shared_ptr<Puncture> data)
15 {
16  m_punctures[id] = data;
17 }
18 
19 std::shared_ptr<Puncture>
20 Puncturable::getPuncture(const PunctureId& id)
21 {
22  auto iter = m_punctures.find(id);
23  if (iter == m_punctures.end())
24  {
25  m_punctures[id] = std::make_shared<Puncture>();
26  }
27  return m_punctures[id];
28 }
29 
30 bool
31 Puncturable::getPunctured() const
32 {
33  for (auto puncture : m_punctures)
34  {
35  if (puncture.second->state == Puncture::State::INSERTED)
36  {
37  return true;
38  }
39  }
40  return false;
41 }
42 
44 getPunctureId(std::shared_ptr<Needle> needle,
45  std::shared_ptr<Puncturable> puncturable,
46  const int supportId)
47 {
48  std::shared_ptr<Entity> needleEntity = needle->getEntity().lock();
49  std::shared_ptr<Entity> puncturableEntity = puncturable->getEntity().lock();
50  CHECK(needleEntity != nullptr) << "Cannot generate puncture id without needle entity";
51  CHECK(puncturableEntity != nullptr) << "Cannot generate puncture id without puncturable entity";
52  return { needleEntity->getID(), puncturableEntity->getID(), supportId };
53 }
54 } // namespace imstk
PunctureId getPunctureId(std::shared_ptr< Needle > needle, std::shared_ptr< Puncturable > puncturable, const int supportId)
Get puncture id between needle and puncturable.
Compound Geometry.
void setPuncture(const PunctureId &id, std::shared_ptr< Puncture > data)
Get/Set puncture data.
std::tuple< int, int, int > PunctureId
Punctures are identified via three ints. The needle id, the puncturable id, and a local id that allow...
Definition: imstkPuncture.h:21