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  * https://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  ITK_DISALLOW_COPY_AND_MOVE(SegmentTree);
52 
54  using Self = SegmentTree;
58  itkNewMacro(Self);
59  itkTypeMacro(SegmentTree, DataObject);
60  using ScalarType = TScalar;
66  struct merge_t
67  {
71  };
75  using DequeType = std::deque<merge_t>;
76  using Iterator = typename DequeType::iterator;
77  using ConstIterator = typename DequeType::const_iterator;
78  using ValueType = typename DequeType::value_type;
79 
81  struct merge_comp
82  {
83  merge_comp() = default;
84  bool
85  operator()(const merge_t & a, const merge_t & b)
86  {
87  return b.saliency < a.saliency;
88  }
89  };
93  struct sort_comp
94  {
95  bool
96  operator()(const merge_t & a, const merge_t & b)
97  {
98  return a.saliency < b.Saliency;
99  }
100  };
101 
103  typename DequeType::size_type
104  Size() const
105  {
106  return m_Deque.size();
107  }
108 
111  bool
112  Empty() const
113  {
114  return m_Deque.empty();
115  }
116 
119  const merge_t &
120  Front() const
121  {
122  return m_Deque.front();
123  }
124 
127  const merge_t &
128  Back() const
129  {
130  return m_Deque.back();
131  }
132 
134  merge_t &
136  {
137  return m_Deque.front();
138  }
139 
141  merge_t &
143  {
144  return m_Deque.back();
145  }
146 
148  void
149  PushFront(const ValueType & t)
150  {
151  m_Deque.push_front(t);
152  }
153 
155  void
156  PushBack(const ValueType & t)
157  {
158  m_Deque.push_back(t);
159  }
160 
162  void
164  {
165  m_Deque.pop_front();
166  }
167 
169  void
171  {
172  m_Deque.pop_back();
173  }
174 
176  Iterator
178  {
179  return m_Deque.begin();
180  }
181 
183  ConstIterator
184  Begin() const
185  {
186  return m_Deque.begin();
187  }
188 
191  Iterator
192  End()
193  {
194  return m_Deque.end();
195  }
196 
199  ConstIterator
200  End() const
201  {
202  return m_Deque.end();
203  }
204 
206  void
208  {
209  m_Deque.clear();
210  }
211 
214  void
215  Initialize() override;
216 
217 protected:
218  SegmentTree() = default;
219  ~SegmentTree() override = default;
220 
221  void
222  PrintSelf(std::ostream & os, Indent indent) const override;
223 
225 };
226 } // end namespace watershed
227 } // end namespace itk
228 
229 #ifndef ITK_MANUAL_INSTANTIATION
230 # include "itkWatershedSegmentTree.hxx"
231 #endif
232 
233 #endif
itk::watershed::SegmentTree::merge_t::saliency
ScalarType saliency
Definition: itkWatershedSegmentTree.h:70
itk::watershed::SegmentTree::ScalarType
TScalar ScalarType
Definition: itkWatershedSegmentTree.h:60
itk::watershed::SegmentTree::Begin
ConstIterator Begin() const
Definition: itkWatershedSegmentTree.h:184
itk::watershed::SegmentTree::Size
DequeType::size_type Size() const
Definition: itkWatershedSegmentTree.h:104
itk::watershed::SegmentTree::merge_t::from
IdentifierType from
Definition: itkWatershedSegmentTree.h:68
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:120
itk::watershed::SegmentTree::Back
const merge_t & Back() const
Definition: itkWatershedSegmentTree.h:128
itk::watershed::SegmentTree::PushFront
void PushFront(const ValueType &t)
Definition: itkWatershedSegmentTree.h:149
itk::watershed::SegmentTree::merge_comp::operator()
bool operator()(const merge_t &a, const merge_t &b)
Definition: itkWatershedSegmentTree.h:85
itk::watershed::SegmentTree::Empty
bool Empty() const
Definition: itkWatershedSegmentTree.h:112
itk::watershed::SegmentTree::Front
merge_t & Front()
Definition: itkWatershedSegmentTree.h:135
itk::watershed::SegmentTree::merge_t
Definition: itkWatershedSegmentTree.h:66
itk::watershed::SegmentTree::sort_comp::operator()
bool operator()(const merge_t &a, const merge_t &b)
Definition: itkWatershedSegmentTree.h:96
itkProcessObject.h
itk::watershed::SegmentTree::Back
merge_t & Back()
Definition: itkWatershedSegmentTree.h:142
itk::watershed::SegmentTree::Clear
void Clear()
Definition: itkWatershedSegmentTree.h:207
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::watershed::SegmentTree::ValueType
typename DequeType::value_type ValueType
Definition: itkWatershedSegmentTree.h:78
itk::watershed::SegmentTree::merge_t::to
IdentifierType to
Definition: itkWatershedSegmentTree.h:69
itk::watershed::SegmentTree::merge_comp
Definition: itkWatershedSegmentTree.h:81
itk::watershed::SegmentTree::End
Iterator End()
Definition: itkWatershedSegmentTree.h:192
itk::watershed::SegmentTree::DequeType
std::deque< merge_t > DequeType
Definition: itkWatershedSegmentTree.h:75
itk::watershed::SegmentTree
Definition: itkWatershedSegmentTree.h:48
itk::watershed::SegmentTree::m_Deque
DequeType m_Deque
Definition: itkWatershedSegmentTree.h:224
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:93
itk::watershed::SegmentTree::Iterator
typename DequeType::iterator Iterator
Definition: itkWatershedSegmentTree.h:76
itk::watershed::SegmentTree::PopBack
void PopBack()
Definition: itkWatershedSegmentTree.h:170
itk::watershed::SegmentTree::End
ConstIterator End() const
Definition: itkWatershedSegmentTree.h:200
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::watershed::SegmentTree::PopFront
void PopFront()
Definition: itkWatershedSegmentTree.h:163
itk::watershed::SegmentTree::Begin
Iterator Begin()
Definition: itkWatershedSegmentTree.h:177
itk::watershed::SegmentTree::ConstIterator
typename DequeType::const_iterator ConstIterator
Definition: itkWatershedSegmentTree.h:77
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itk::watershed::SegmentTree::PushBack
void PushBack(const ValueType &t)
Definition: itkWatershedSegmentTree.h:156
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293