ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkWatershedSegmentTable.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 __itkWatershedSegmentTable_h
00019 #define __itkWatershedSegmentTable_h
00020 
00021 
00022 #include "itkDataObject.h"
00023 #include <list>
00024 #include "itkOneWayEquivalencyTable.h"
00025 
00026 namespace itk
00027 {
00028 namespace watershed
00029 {
00046 template< class TScalarType >
00047 class ITK_EXPORT SegmentTable:public DataObject
00048 {
00049 public:
00051   typedef SegmentTable               Self;
00052   typedef DataObject                 Superclass;
00053   typedef SmartPointer< Self >       Pointer;
00054   typedef SmartPointer< const Self > ConstPointer;
00055   typedef TScalarType                ScalarType;
00056   itkNewMacro(Self);
00057   itkTypeMacro(WatershedSegmentTable, DataObject);
00059 
00062   struct edge_pair_t {
00063     edge_pair_t() {}
00064     edge_pair_t(IdentifierType l, ScalarType s):label(l), height(s) {}
00065     IdentifierType label;
00066     ScalarType height;
00068 
00070     bool operator<(const edge_pair_t & o) const
00071     {
00072       if ( this->height < o.height )
00073         {
00074         return true;
00075         }
00076       else
00077         {
00078         return false;
00079         }
00080     }
00081   };
00083 
00086   typedef std::list< edge_pair_t > edge_list_t;
00087 
00089   struct segment_t {
00090     ScalarType min;
00091     edge_list_t edge_list;
00092   };
00093 
00095   typedef itksys::hash_map< IdentifierType, segment_t,
00096     itksys::hash< IdentifierType > >           HashMapType;
00097   typedef typename HashMapType::iterator       Iterator;
00098   typedef typename HashMapType::const_iterator ConstIterator;
00099   typedef typename HashMapType::value_type     ValueType;
00100   typedef typename HashMapType::data_type      DataType;
00101 
00103   bool Add(IdentifierType a, const segment_t & t);
00104 
00109   void PruneEdgeLists(ScalarType maximum_saliency);
00110 
00113   segment_t * Lookup(const IdentifierType a)
00114   {
00115     Iterator result = m_HashMap.find(a);
00116 
00117     if ( result == m_HashMap.end() ) { return 0; }
00118     else { return &( ( *result ).second ); }
00119   }
00120 
00123   const segment_t * Lookup(const IdentifierType a) const
00124   {
00125     ConstIterator result = m_HashMap.find(a);
00126 
00127     if ( result == m_HashMap.end() ) { return 0; }
00128     else { return &( ( *result ).second ); }
00129   }
00130 
00133   bool IsEntry(const IdentifierType a) const
00134   {
00135     if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
00136     else { return true; }
00137   }
00139 
00141   void Erase(const IdentifierType a)
00142   {  m_HashMap.erase(a); }
00143 
00145   void Clear()
00146   {      m_HashMap.clear();    }
00147 
00150   bool Empty() const
00151   {      return m_HashMap.empty();    }
00152 
00155   void SortEdgeLists();
00156 
00158   typename HashMapType::size_type  Size() const
00159   {      return m_HashMap.size();     }
00160 
00162   //  void Merge(const IdentifierType from, const IdentifierType to);
00163 
00166   Iterator Begin() { return m_HashMap.begin(); }
00167 
00170   Iterator End()   { return m_HashMap.end();   }
00171 
00174   ConstIterator Begin() const { return m_HashMap.begin(); }
00175 
00178   ConstIterator End()   const { return m_HashMap.end();   }
00179 
00181   unsigned int GetSegmentMemorySize() const
00182   {
00183     return sizeof( segment_t );
00184   }
00185 
00186   //  void PrintHashTable() const;
00187 
00190   void SetMaximumDepth(ScalarType s)
00191   {
00192     m_MaximumDepth = s;
00193     this->Modified();
00194   }
00196 
00197   ScalarType GetMaximumDepth() const
00198   { return m_MaximumDepth; }
00199 
00203   void Copy(const Self & o)
00204   {
00205     m_HashMap = o.m_HashMap;
00206     m_MaximumDepth = o.m_MaximumDepth;
00207   }
00208 
00209 protected:
00210   SegmentTable() {}
00211   virtual ~SegmentTable() {}
00212 
00213   HashMapType m_HashMap;
00214 
00215   ScalarType m_MaximumDepth;
00216 private:
00217   void operator=(const Self &) {}
00218 };
00219 } // end namespace watershed
00220 } // end namespace itk
00221 
00222 #ifndef ITK_MANUAL_INSTANTIATION
00223 #include "itkWatershedSegmentTable.hxx"
00224 #endif
00225 
00226 #endif
00227