ITK  5.3.0
Insight Toolkit
itkWatershedSegmentTree.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkWatershedSegmentTree_h
19 #define itkWatershedSegmentTree_h
20 
21 #include "itkProcessObject.h"
22 #include <deque>
23 #include <functional>
24 
25 namespace itk
26 {
27 namespace watershed
28 {
47 template <typename TScalar>
48 class ITK_TEMPLATE_EXPORT SegmentTree : public DataObject
49 {
50 public:
51 
53  using Self = SegmentTree;
57  itkNewMacro(Self);
58  itkTypeMacro(WatershedSegmentTree, DataObject);
59  using ScalarType = TScalar;
61 
65  struct merge_t
66  {
70  };
72 
74  using DequeType = std::deque<merge_t>;
75  using Iterator = typename DequeType::iterator;
76  using ConstIterator = typename DequeType::const_iterator;
77  using ValueType = typename DequeType::value_type;
78 
80  struct merge_comp
81  {
82  merge_comp() = default;
83  bool
84  operator()(const merge_t & a, const merge_t & b)
85  {
86  return b.saliency < a.saliency;
87  }
88  };
90 
92  struct sort_comp
93  {
94  bool
95  operator()(const merge_t & a, const merge_t & b)
96  {
97  return a.saliency < b.Saliency;
98  }
99  };
100 
102  typename DequeType::size_type
103  Size() const
104  {
105  return m_Deque.size();
106  }
107 
110  bool
111  Empty() const
112  {
113  return m_Deque.empty();
114  }
115 
118  const merge_t &
119  Front() const
120  {
121  return m_Deque.front();
122  }
123 
126  const merge_t &
127  Back() const
128  {
129  return m_Deque.back();
130  }
131 
133  merge_t &
135  {
136  return m_Deque.front();
137  }
138 
140  merge_t &
142  {
143  return m_Deque.back();
144  }
145 
147  void
148  PushFront(const ValueType & t)
149  {
150  m_Deque.push_front(t);
151  }
152 
154  void
155  PushBack(const ValueType & t)
156  {
157  m_Deque.push_back(t);
158  }
159 
161  void
163  {
164  m_Deque.pop_front();
165  }
166 
168  void
170  {
171  m_Deque.pop_back();
172  }
173 
175  Iterator
177  {
178  return m_Deque.begin();
179  }
180 
182  ConstIterator
183  Begin() const
184  {
185  return m_Deque.begin();
186  }
187 
190  Iterator
191  End()
192  {
193  return m_Deque.end();
194  }
195 
198  ConstIterator
199  End() const
200  {
201  return m_Deque.end();
202  }
203 
205  void
207  {
208  m_Deque.clear();
209  }
210 
213  void
214  Initialize() override;
215 
216 protected:
217  SegmentTree() = default;
218  ~SegmentTree() override = default;
219  SegmentTree(const Self &) {}
220  void
221  operator=(const Self &)
222  {}
223  void
224  PrintSelf(std::ostream & os, Indent indent) const override;
225 
227 };
228 } // end namespace watershed
229 } // end namespace itk
230 
231 #ifndef ITK_MANUAL_INSTANTIATION
232 # include "itkWatershedSegmentTree.hxx"
233 #endif
234 
235 #endif
itk::watershed::SegmentTree::merge_t::saliency
ScalarType saliency
Definition: itkWatershedSegmentTree.h:69
itk::watershed::SegmentTree::ScalarType
TScalar ScalarType
Definition: itkWatershedSegmentTree.h:59
itk::watershed::SegmentTree::Begin
ConstIterator Begin() const
Definition: itkWatershedSegmentTree.h:183
itk::watershed::SegmentTree::Size
DequeType::size_type Size() const
Definition: itkWatershedSegmentTree.h:103
itk::watershed::SegmentTree::merge_t::from
IdentifierType from
Definition: itkWatershedSegmentTree.h:67
itk::watershed::SegmentTree::SegmentTree
SegmentTree(const Self &)
Definition: itkWatershedSegmentTree.h:219
itk::watershed::SegmentTree::operator=
void operator=(const Self &)
Definition: itkWatershedSegmentTree.h:221
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::watershed::SegmentTree::Front
const merge_t & Front() const
Definition: itkWatershedSegmentTree.h:119
itk::watershed::SegmentTree::Back
const merge_t & Back() const
Definition: itkWatershedSegmentTree.h:127
itk::watershed::SegmentTree::PushFront
void PushFront(const ValueType &t)
Definition: itkWatershedSegmentTree.h:148
itk::watershed::SegmentTree::merge_comp::operator()
bool operator()(const merge_t &a, const merge_t &b)
Definition: itkWatershedSegmentTree.h:84
itk::watershed::SegmentTree::Empty
bool Empty() const
Definition: itkWatershedSegmentTree.h:111
itk::watershed::SegmentTree::Front
merge_t & Front()
Definition: itkWatershedSegmentTree.h:134
itk::watershed::SegmentTree::merge_t
Definition: itkWatershedSegmentTree.h:65
itk::watershed::SegmentTree::sort_comp::operator()
bool operator()(const merge_t &a, const merge_t &b)
Definition: itkWatershedSegmentTree.h:95
itkProcessObject.h
itk::watershed::SegmentTree::Back
merge_t & Back()
Definition: itkWatershedSegmentTree.h:141
itk::watershed::SegmentTree::Clear
void Clear()
Definition: itkWatershedSegmentTree.h:206
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::watershed::SegmentTree::ValueType
typename DequeType::value_type ValueType
Definition: itkWatershedSegmentTree.h:77
itk::watershed::SegmentTree::merge_t::to
IdentifierType to
Definition: itkWatershedSegmentTree.h:68
itk::watershed::SegmentTree::merge_comp
Definition: itkWatershedSegmentTree.h:80
itk::watershed::SegmentTree::End
Iterator End()
Definition: itkWatershedSegmentTree.h:191
itk::watershed::SegmentTree::DequeType
std::deque< merge_t > DequeType
Definition: itkWatershedSegmentTree.h:74
itk::watershed::SegmentTree
Definition: itkWatershedSegmentTree.h:48
itk::watershed::SegmentTree::m_Deque
DequeType m_Deque
Definition: itkWatershedSegmentTree.h:226
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::watershed::SegmentTree::sort_comp
Definition: itkWatershedSegmentTree.h:92
itk::watershed::SegmentTree::Iterator
typename DequeType::iterator Iterator
Definition: itkWatershedSegmentTree.h:75
itk::watershed::SegmentTree::PopBack
void PopBack()
Definition: itkWatershedSegmentTree.h:169
itk::watershed::SegmentTree::End
ConstIterator End() const
Definition: itkWatershedSegmentTree.h:199
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::watershed::SegmentTree::PopFront
void PopFront()
Definition: itkWatershedSegmentTree.h:162
itk::watershed::SegmentTree::Begin
Iterator Begin()
Definition: itkWatershedSegmentTree.h:176
itk::watershed::SegmentTree::ConstIterator
typename DequeType::const_iterator ConstIterator
Definition: itkWatershedSegmentTree.h:76
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itk::watershed::SegmentTree::PushBack
void PushBack(const ValueType &t)
Definition: itkWatershedSegmentTree.h:155
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293