ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkWatershedBoundary.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkWatershedBoundary_h
00019 #define __itkWatershedBoundary_h
00020 
00021 
00022 #include <list>
00023 #include <vector>
00024 #include "itkImage.h"
00025 #include "itkProcessObject.h"
00026 #include "itksys/hash_map.hxx"
00027 
00028 namespace itk
00029 {
00030 namespace watershed
00031 {
00053 template< class TScalarType, unsigned int TDimension >
00054 class ITK_EXPORT Boundary:public DataObject
00055 {
00056 public:
00061   itkStaticConstMacro(Dimension, unsigned int, TDimension);
00062 
00067   typedef std::pair< unsigned, unsigned >                        IndexType;
00068   typedef Image< IdentifierType, TDimension >                    ImageType;
00069   typedef typename ImageType::IndexType                          ImageIndexType;
00070   typedef TScalarType                                            ScalarType;
00071 
00073   struct face_pixel_t {
00074 
00089     short flow;
00090 
00092     IdentifierType label;
00093   };
00094 
00096   struct flat_region_t {
00097 
00101     std::list< IdentifierType > offset_list;
00102 
00105     ScalarType bounds_min;
00106 
00109     IdentifierType min_label;
00110 
00112     ScalarType value;
00113   };
00114 
00117   typedef Image< face_pixel_t, TDimension > face_t;
00118 
00120   typedef itksys::hash_map< IdentifierType,             flat_region_t,
00121                         itksys::hash< IdentifierType > > flat_hash_t;
00122   typedef typename flat_hash_t::value_type FlatHashValueType;
00123 
00126   typedef Boundary                   Self;
00127   typedef DataObject                 Superclass;
00128   typedef SmartPointer< Self >       Pointer;
00129   typedef SmartPointer< const Self > ConstPointer;
00130   itkNewMacro(Self);
00131   itkTypeMacro(WatershedBoundary, DataObject);
00133 
00135   typedef typename face_t::Pointer FacePointer;
00136 
00138   FacePointer GetFace(const IndexType & idx)
00139   {      return this->GetFace(idx.first, idx.second);    }
00140 
00144   FacePointer GetFace(unsigned dimension, unsigned highlow)
00145   {
00146     if ( highlow == 0 ) { return m_Faces[dimension].first; }
00147     else { return m_Faces[dimension].second; }
00148   }
00150 
00151   void SetFace(FacePointer f, const IndexType & idx)
00152   { this->SetFace(f, idx.first, idx.second); }
00153 
00154   void SetFace(FacePointer f, unsigned dimension, unsigned highlow)
00155   {
00156     if ( highlow == 0 ) { m_Faces[dimension].first = f; }
00157     else { m_Faces[dimension].second = f; }
00158     this->Modified();
00159   }
00160 
00162   flat_hash_t * GetFlatHash(const IndexType & idx)
00163   { return this->GetFlatHash(idx.first, idx.second); }
00164   flat_hash_t * GetFlatHash(unsigned dimension, unsigned highlow)
00165   {
00166     if ( highlow == 0 ) { return &( m_FlatHashes[dimension].first ); }
00167     else { return &( m_FlatHashes[dimension].second ); }
00168   }
00170 
00171   void SetFlatHash(flat_hash_t & l, const IndexType & idx)
00172   { this->SetFlatHash(l, idx.first, idx.second); }
00173   void SetFlatHash(flat_hash_t & l, unsigned dimension,
00174                    unsigned highlow)
00175   {
00176     if ( highlow == 0 ) { m_FlatHashes[dimension].first = l; }
00177     else { m_FlatHashes[dimension].second = l; }
00178     this->Modified();
00179   }
00180 
00185   void SetValid(bool & l, const IndexType & idx)
00186   { this->SetValid(l, idx.first, idx.second); }
00187   void SetValid(bool b, unsigned dimension,
00188                 unsigned highlow)
00189   {
00190     if ( highlow == 0 ) { m_Valid[dimension].first = b; }
00191     else { m_Valid[dimension].second = b; }
00192     this->Modified();
00193   }
00195 
00196   bool GetValid(const IndexType & idx) const
00197   { return this->GetValid(idx.first, idx.second); }
00198   bool GetValid(unsigned dimension, unsigned highlow) const
00199   {
00200     if ( highlow == 0 ) { return m_Valid[dimension].first; }
00201     else { return m_Valid[dimension].second; }
00202   }
00203 
00204 protected:
00205   Boundary();
00206   virtual ~Boundary() {}
00207   Boundary(const Self &) {}
00208   void operator=(const Self &) {}
00209   void PrintSelf(std::ostream & os, Indent indent) const;
00210 
00212   std::vector< std::pair< FacePointer, FacePointer > > m_Faces;
00213 
00216   std::vector< std::pair< flat_hash_t, flat_hash_t > > m_FlatHashes;
00217 
00220   std::vector< std::pair< bool, bool > > m_Valid;
00221 };
00222 } // end namespace watershed
00223 } // end namespace itk
00224 
00225 #ifndef ITK_MANUAL_INSTANTIATION
00226 #include "itkWatershedBoundary.hxx"
00227 #endif
00228 
00229 #endif
00230