Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkIndexROI.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkIndexROI.h"
18 #include <mitkLogMacros.h>
19 #include <sofa/core/loader/MeshLoader.h>
20 #include <sofa/core/visual/VisualParams.h>
21 
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", ""))
29 {
30 }
31 
32 mitk::IndexROI::~IndexROI()
33 {
34 }
35 
37 {
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;
43 
44  if (!m_Position.isSet())
45  {
46  MeshLoader* loader = nullptr;
47  this->getContext()->get(loader, BaseContext::Local);
48 
49  if (loader != nullptr)
50  {
51  BaseData* parent = loader->findField("position");
52 
53  if (parent != nullptr)
54  {
55  m_Position.setParent(parent);
56  m_Position.setReadOnly(true);
57  }
58  }
59  }
60 
61  if (!m_Indices.isSet())
62  {
63  sofa::helper::WriteAccessor<sofa::core::objectmodel::Data<SetIndex> > indices = m_Indices;
64 
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);
68 
69  for (size_t i = 0; i < first; ++i)
70  indices.push_back(i);
71 
72  unsigned int last = numPositions - std::min(m_Last.getValue(), numPositions - first);
73 
74  for (size_t i = last; i < numPositions; ++i)
75  indices.push_back(i);
76 
77  SetIndex individual = m_Individual.getValue();
78  size_t numIndividuals = individual.size();
79 
80  for (size_t i = 0; i < numIndividuals; ++i)
81  {
82  unsigned int index = individual[i];
83 
84  if (index >= first && index < last)
85  indices.push_back(index);
86  }
87  }
88 
89  this->addInput(&m_Indices);
90  this->addInput(&m_Position);
91 
92  this->addOutput(&m_PointsInROI);
93 
94  this->setDirtyValue();
95 }
96 
98 {
99  typedef sofa::core::topology::BaseMeshTopology::SetIndex SetIndex;
100  typedef sofa::defaulttype::ExtVec3fTypes::VecCoord VecCoord;
101 
102  this->cleanDirty();
103 
104  sofa::helper::WriteAccessor<sofa::core::objectmodel::Data<VecCoord> > pointsInROI = m_PointsInROI;
105  pointsInROI.clear();
106 
107  const VecCoord& position = m_Position.getValue();
108  SetIndex indices = m_Indices.getValue();
109  size_t numIndices = indices.size();
110 
111  for (size_t i = 0; i < numIndices; ++i)
112  pointsInROI.push_back(position[indices[i]]);
113 }
Base of all data objects.
Definition: mitkBaseData.h:39
void update() override
static T min(T x, T y)
Definition: svm.cpp:67
void init() override