ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkWatershedBoundary.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 __itkWatershedBoundary_h
19 #define __itkWatershedBoundary_h
20 
21 
22 #include <list>
23 #include <vector>
24 #include "itkImage.h"
25 #include "itkProcessObject.h"
26 #include "itksys/hash_map.hxx"
27 
28 namespace itk
29 {
30 namespace watershed
31 {
53 template< class TScalarType, unsigned int TDimension >
54 class ITK_EXPORT Boundary:public DataObject
55 {
56 public:
61  itkStaticConstMacro(Dimension, unsigned int, TDimension);
62 
67  typedef std::pair< unsigned, unsigned > IndexType;
70  typedef TScalarType ScalarType;
71 
73  struct face_pixel_t {
74 
89  short flow;
90 
93  };
94 
96  struct flat_region_t {
97 
101  std::list< IdentifierType > offset_list;
102 
106 
110 
113  };
114 
118 
120  typedef itksys::hash_map< IdentifierType, flat_region_t,
121  itksys::hash< IdentifierType > > flat_hash_t;
122  typedef typename flat_hash_t::value_type FlatHashValueType;
123 
126  typedef Boundary Self;
130  itkNewMacro(Self);
131  itkTypeMacro(WatershedBoundary, DataObject);
133 
135  typedef typename face_t::Pointer FacePointer;
136 
138  FacePointer GetFace(const IndexType & idx)
139  { return this->GetFace(idx.first, idx.second); }
140 
144  FacePointer GetFace(unsigned dimension, unsigned highlow)
145  {
146  if ( highlow == 0 ) { return m_Faces[dimension].first; }
147  else { return m_Faces[dimension].second; }
148  }
150 
151  void SetFace(FacePointer f, const IndexType & idx)
152  { this->SetFace(f, idx.first, idx.second); }
153 
154  void SetFace(FacePointer f, unsigned dimension, unsigned highlow)
155  {
156  if ( highlow == 0 ) { m_Faces[dimension].first = f; }
157  else { m_Faces[dimension].second = f; }
158  this->Modified();
159  }
160 
162  flat_hash_t * GetFlatHash(const IndexType & idx)
163  { return this->GetFlatHash(idx.first, idx.second); }
164  flat_hash_t * GetFlatHash(unsigned dimension, unsigned highlow)
165  {
166  if ( highlow == 0 ) { return &( m_FlatHashes[dimension].first ); }
167  else { return &( m_FlatHashes[dimension].second ); }
168  }
170 
171  void SetFlatHash(flat_hash_t & l, const IndexType & idx)
172  { this->SetFlatHash(l, idx.first, idx.second); }
173  void SetFlatHash(flat_hash_t & l, unsigned dimension,
174  unsigned highlow)
175  {
176  if ( highlow == 0 ) { m_FlatHashes[dimension].first = l; }
177  else { m_FlatHashes[dimension].second = l; }
178  this->Modified();
179  }
180 
185  void SetValid(bool & l, const IndexType & idx)
186  { this->SetValid(l, idx.first, idx.second); }
187  void SetValid(bool b, unsigned dimension,
188  unsigned highlow)
189  {
190  if ( highlow == 0 ) { m_Valid[dimension].first = b; }
191  else { m_Valid[dimension].second = b; }
192  this->Modified();
193  }
195 
196  bool GetValid(const IndexType & idx) const
197  { return this->GetValid(idx.first, idx.second); }
198  bool GetValid(unsigned dimension, unsigned highlow) const
199  {
200  if ( highlow == 0 ) { return m_Valid[dimension].first; }
201  else { return m_Valid[dimension].second; }
202  }
203 
204 protected:
205  Boundary();
206  virtual ~Boundary() {}
207  Boundary(const Self &) {}
208  void operator=(const Self &) {}
209  void PrintSelf(std::ostream & os, Indent indent) const;
210 
212  std::vector< std::pair< FacePointer, FacePointer > > m_Faces;
213 
216  std::vector< std::pair< flat_hash_t, flat_hash_t > > m_FlatHashes;
217 
220  std::vector< std::pair< bool, bool > > m_Valid;
221 };
222 } // end namespace watershed
223 } // end namespace itk
224 
225 #ifndef ITK_MANUAL_INSTANTIATION
226 #include "itkWatershedBoundary.hxx"
227 #endif
228 
229 #endif
230