Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkIsoDoseLevelCollections.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 <algorithm>
18 
20 #include "mitkExceptionMacro.h"
21 
22 namespace mitk
23 {
25 class EqualDoseFunctor
26 {
27 public:
28  typedef IsoDoseLevel::DoseValueType DoseValueType;
29 
30  EqualDoseFunctor(const DoseValueType& refValue) : m_refValue(refValue)
31  {}
32 
33  bool operator () (const IsoDoseLevel* level)
34  {
35  return level->GetDoseValue() == m_refValue;
36  }
37 
38 protected:
39  DoseValueType m_refValue;
40 };
41 
43 bool lesserIsoDoseLevel(const IsoDoseLevel* first, const IsoDoseLevel* second)
44 {
45  return first->GetDoseValue() < second->GetDoseValue();
46 }
47 }
48 
50 {
51  if (&other != this)
52  {
53  this->m_IsoLevels = other.m_IsoLevels;
54  }
55 }
56 
58 {
59  if (index < this->m_IsoLevels.size())
60  {
61  return *(this->m_IsoLevels[index].GetPointer());
62  }
63  else
64  {
65  mitkThrow() << "Try to access non existing dose iso level.";
66  }
67 }
68 
70 {
71  auto pos = std::find_if(this->m_IsoLevels.begin(), this->m_IsoLevels.end(), EqualDoseFunctor(value));
72 
73  if (pos != this->m_IsoLevels.end())
74  {
75  return *(pos->GetPointer());
76  }
77  else
78  {
79  mitkThrow() << "Try to access non existing dose iso level.";
80  }
81 }
82 
84 {
85  if (!level)
86  {
87  mitkThrow() << "Cannot set iso level. Passed null pointer.";
88  }
89 
90  this->DeleteIsoDoseLevel(level->GetDoseValue());
91 
92  this->m_IsoLevels.push_back(level->Clone());
93 
94  std::sort(this->m_IsoLevels.begin(), this->m_IsoLevels.end(),lesserIsoDoseLevel);
95 }
96 
98 {
99  return index < this->m_IsoLevels.size();
100 }
101 
102 
104 {
105  auto pos = std::find_if(this->m_IsoLevels.begin(), this->m_IsoLevels.end(), EqualDoseFunctor(value));
106  return pos != this->m_IsoLevels.end();
107 }
108 
110 {
111  auto pos = std::find_if(this->m_IsoLevels.begin(), this->m_IsoLevels.end(), EqualDoseFunctor(value));
112 
113  if (pos != this->m_IsoLevels.end())
114  {
115  this->m_IsoLevels.erase(pos);
116  }
117 }
118 
120 {
121  if (DoseLevelExists(index))
122  {
123  this->m_IsoLevels.erase(this->m_IsoLevels.begin()+index);
124  }
125 }
126 
128 {
129  return ConstIterator(this->m_IsoLevels.begin());
130 }
131 
133 {
134  return ConstIterator(this->m_IsoLevels.end());
135 }
136 
138 {
139  return this->m_IsoLevels.size();
140 }
141 
143 {
144  this->m_IsoLevels.clear();
145 }
Stores values needed for the representation/visualization of dose iso levels.
ConstIterator Begin(void) const
virtual DoseValueType GetDoseValue() const
void SetIsoDoseLevel(const IsoDoseLevel *)
bool lesserIsoDoseLevel(const IsoDoseLevel *first, const IsoDoseLevel *second)
ConstIterator End(void) const
DataCollection - Class to facilitate loading/accessing structured data.
bool DoseLevelExists(IsoLevelIndexType) const
Stores values needed for the representation/visualization of dose iso levels.
IsoLevelIndexType Size(void) const
#define mitkThrow()
IsoDoseLevel::DoseValueType DoseValueType
DoseValueRel DoseValueType
const IsoDoseLevel & GetIsoDoseLevel(IsoLevelIndexType) const