Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkWatershedSegmentTable.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkWatershedSegmentTable.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-01-27 19:30:18 $
00007   Version:   $Revision: 1.13 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkWatershedSegmentTable_h
00018 #define __itkWatershedSegmentTable_h
00019 
00020 #if defined(_MSC_VER)
00021 #pragma warning ( disable : 4786 )
00022 #endif
00023 
00024 #include "itkObjectFactory.h"
00025 #include "itkDataObject.h"
00026 #include "itkProcessObject.h"
00027 #include "itk_hash_map.h"
00028 #include <list>
00029 #include "itkOneWayEquivalencyTable.h"
00030 
00031 namespace itk
00032 {
00033 namespace watershed
00034 {
00049 template <class TScalarType> 
00050 class ITK_EXPORT SegmentTable : public DataObject
00051 {
00052 public:
00054   typedef SegmentTable             Self;
00055   typedef DataObject               Superclass;
00056   typedef SmartPointer<Self>       Pointer;
00057   typedef SmartPointer<const Self> ConstPointer;
00058   typedef TScalarType              ScalarType;
00059   itkNewMacro(Self);
00060   itkTypeMacro(WatershedSegmentTable, DataObject);
00062 
00065   struct edge_pair_t
00066     {
00067     edge_pair_t() {}
00068     edge_pair_t(unsigned long l, ScalarType s) : label(l), height(s) {}
00069     unsigned long label;
00070     ScalarType height;
00072 
00074     bool operator<( const edge_pair_t & o) const
00075       {
00076       if ( this->height < o.height ) 
00077         {
00078         return true;
00079         }
00080       else 
00081         {
00082         return false;
00083         }
00084       }
00086 
00087     };
00088   
00091   typedef std::list<edge_pair_t>  edge_list_t;
00092 
00094   struct segment_t
00095   {
00096     ScalarType    min;
00097     edge_list_t   edge_list;
00098   };
00099 
00101   typedef itk::hash_map<unsigned long, segment_t, itk::hash<unsigned long> >
00102                                                HashMapType;
00103   typedef typename HashMapType::iterator       Iterator;
00104   typedef typename HashMapType::const_iterator ConstIterator;
00105   typedef typename HashMapType::value_type     ValueType;
00106   typedef typename HashMapType::data_type      DataType;
00107 
00109   bool Add(unsigned long a, const segment_t &t);
00110 
00115   void PruneEdgeLists(ScalarType maximum_saliency);
00116 
00119   segment_t *Lookup(const unsigned long a)
00120   {
00121     Iterator result = m_HashMap.find(a);
00122     if ( result == m_HashMap.end() ) return 0;
00123     else return &((*result).second);
00124   }
00126 
00129   const segment_t *Lookup(const unsigned long a) const
00130   {
00131     ConstIterator result = m_HashMap.find(a);
00132     if ( result == m_HashMap.end() ) return 0;
00133     else return &((*result).second);
00134   }
00136 
00139   bool IsEntry(const unsigned long a) const
00140   {
00141     if ( m_HashMap.find(a) == m_HashMap.end() ) return false;
00142     else return true;
00143   }
00145 
00147   void Erase(const unsigned long a)
00148   {  m_HashMap.erase(a); }
00149 
00151   void Clear()
00152   {      m_HashMap.clear();    }
00153 
00156   bool Empty() const
00157   {      return m_HashMap.empty();    }
00158 
00161   void SortEdgeLists();
00162 
00164   typename HashMapType::size_type  Size() const 
00165   {      return m_HashMap.size();     }
00166 
00168   //  void Merge(const unsigned long from, const unsigned long to);
00169 
00172   Iterator Begin() { return m_HashMap.begin(); }
00173 
00176   Iterator End()   { return m_HashMap.end();   }
00177 
00180   ConstIterator Begin() const { return m_HashMap.begin(); }
00181 
00184   ConstIterator End()   const { return m_HashMap.end();   }
00185 
00187   unsigned int GetSegmentMemorySize() const
00188     {
00189     return sizeof(segment_t);
00190     }
00191   //  void PrintHashTable() const;
00193 
00196   void SetMaximumDepth(ScalarType s)
00197     {
00198     m_MaximumDepth = s;
00199     this->Modified();
00200     }
00201   ScalarType GetMaximumDepth() const
00202     { return m_MaximumDepth; }
00204 
00208   void Copy(const Self& o)
00209     {
00210     m_HashMap = o.m_HashMap;
00211     m_MaximumDepth = o.m_MaximumDepth;
00212     }
00213 
00214 protected:
00215   SegmentTable() {}
00216   virtual ~SegmentTable() {}
00217 
00218   HashMapType m_HashMap;
00219   ScalarType  m_MaximumDepth;
00220   
00221 private:
00222   void operator=(const Self&) {}
00223   
00224 };
00225 
00226 }// end namespace watershed
00227 }// end namespace itk
00228 
00229 #ifndef ITK_MANUAL_INSTANTIATION
00230 #include "itkWatershedSegmentTable.txx"
00231 #endif
00232 
00233 #endif
00234 

Generated at Thu May 28 12:06:49 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000