19 #include <sofa/core/loader/MeshLoader.h>
20 #include <sofa/core/visual/VisualParams.h>
22 mitk::IndexROI::IndexROI()
23 : m_First(initData(&m_First,
"first",
"")),
24 m_Last(initData(&m_Last,
"last",
"")),
25 m_Individual(initData(&m_Individual,
"individual",
"")),
26 m_Indices(initData(&m_Indices,
"indices",
"")),
27 m_PointsInROI(initData(&m_PointsInROI,
"pointsInROI",
"")),
28 m_Position(initData(&m_Position,
"position",
""))
32 mitk::IndexROI::~IndexROI()
38 using sofa::core::loader::MeshLoader;
39 using sofa::core::objectmodel::BaseContext;
40 using sofa::core::objectmodel::BaseData;
41 typedef sofa::core::topology::BaseMeshTopology::SetIndex SetIndex;
42 typedef sofa::defaulttype::ExtVec3fTypes::VecCoord VecCoord;
44 if (!m_Position.isSet())
46 MeshLoader* loader =
nullptr;
47 this->getContext()->get(loader, BaseContext::Local);
49 if (loader !=
nullptr)
51 BaseData* parent = loader->findField(
"position");
53 if (parent !=
nullptr)
55 m_Position.setParent(parent);
56 m_Position.setReadOnly(
true);
61 if (!m_Indices.isSet())
63 sofa::helper::WriteAccessor<sofa::core::objectmodel::Data<SetIndex> > indices = m_Indices;
65 const VecCoord& position = m_Position.getValue();
66 unsigned int numPositions =
static_cast<unsigned int>(position.size());
67 unsigned int first =
std::min(m_First.getValue(), numPositions);
69 for (
size_t i = 0; i < first; ++i)
72 unsigned int last = numPositions -
std::min(m_Last.getValue(), numPositions - first);
74 for (
size_t i = last; i < numPositions; ++i)
77 SetIndex individual = m_Individual.getValue();
78 size_t numIndividuals = individual.size();
80 for (
size_t i = 0; i < numIndividuals; ++i)
82 unsigned int index = individual[i];
84 if (index >= first && index < last)
85 indices.push_back(index);
89 this->addInput(&m_Indices);
90 this->addInput(&m_Position);
92 this->addOutput(&m_PointsInROI);
94 this->setDirtyValue();
99 typedef sofa::core::topology::BaseMeshTopology::SetIndex SetIndex;
100 typedef sofa::defaulttype::ExtVec3fTypes::VecCoord VecCoord;
104 sofa::helper::WriteAccessor<sofa::core::objectmodel::Data<VecCoord> > pointsInROI = m_PointsInROI;
107 const VecCoord& position = m_Position.getValue();
108 SetIndex indices = m_Indices.getValue();
109 size_t numIndices = indices.size();
111 for (
size_t i = 0; i < numIndices; ++i)
112 pointsInROI.push_back(position[indices[i]]);
Base of all data objects.