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: 2004/03/03 19:15:19 $
00007   Version:   $Revision: 1.9 $
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(SegmentTable, DataObject);
00061 
00064   struct edge_pair_t
00065   {
00066     edge_pair_t() {}
00067     edge_pair_t(unsigned long l, ScalarType s)
00068       : label(l), height(s) {}
00069     unsigned long label;
00070     ScalarType height;
00071 
00073     bool operator<(edge_pair_t &o)
00074     {
00075       if ( this->height < o.height ) return true;
00076       else return false;
00077     }
00078     
00079   };
00080   
00083   typedef std::list<edge_pair_t>  edge_list_t;
00084 
00086   struct segment_t
00087   {
00088     ScalarType    min;
00089     edge_list_t   edge_list;
00090   };
00091 
00093   typedef itk::hash_map<unsigned long, segment_t, itk::hash<unsigned long> >
00094   HashMapType;
00095   typedef typename HashMapType::iterator Iterator;
00096   typedef typename HashMapType::const_iterator ConstIterator;
00097   typedef typename HashMapType::value_type ValueType;
00098   typedef typename HashMapType::data_type  DataType;
00099 
00101   bool Add(unsigned long a, const segment_t &t);
00102 
00107   void PruneEdgeLists(ScalarType maximum_saliency);
00108 
00111   segment_t *Lookup(const unsigned long a)
00112   {
00113     Iterator result = m_HashMap.find(a);
00114     if ( result == m_HashMap.end() ) return 0;
00115     else return &((*result).second);
00116   }
00117 
00120   const segment_t *Lookup(const unsigned long a) const
00121   {
00122     ConstIterator result = m_HashMap.find(a);
00123     if ( result == m_HashMap.end() ) return 0;
00124     else return &((*result).second);
00125   }
00126 
00129   bool IsEntry(const unsigned long a) const
00130   {
00131     if ( m_HashMap.find(a) == m_HashMap.end() ) return false;
00132     else return true;
00133   }
00134 
00136   void Erase(const unsigned long a)
00137   {  m_HashMap.erase(a); }
00138 
00140   void Clear()
00141   {      m_HashMap.clear();    }
00142 
00145   bool Empty() const
00146   {      return m_HashMap.empty();    }
00147 
00150   void SortEdgeLists();
00151 
00153   typename HashMapType::size_type  Size() const 
00154   {      return m_HashMap.size();     }
00155 
00157   //  void Merge(const unsigned long from, const unsigned long to);
00158 
00161   Iterator Begin() { return m_HashMap.begin(); }
00162 
00165   Iterator End()   { return m_HashMap.end();   }
00166 
00169   ConstIterator Begin() const { return m_HashMap.begin(); }
00170 
00173   ConstIterator End()   const { return m_HashMap.end();   }
00174 
00176   unsigned int GetSegmentMemorySize() const
00177   {
00178     return sizeof(segment_t);
00179   }
00180   //  void PrintHashTable() const;
00181   
00184   void SetMaximumDepth(ScalarType s)
00185   {
00186     m_MaximumDepth = s;
00187     this->Modified();
00188   }
00189   ScalarType GetMaximumDepth() const
00190   { return m_MaximumDepth; }
00191 
00195   void Copy(const Self& o)
00196   {
00197     m_HashMap = o.m_HashMap;
00198     m_MaximumDepth = o.m_MaximumDepth;
00199   }
00200 
00201 protected:
00202   SegmentTable() {}
00203   virtual ~SegmentTable() {}
00204   void PrintSelf(std::ostream& os, Indent indent) const;
00205 
00206   HashMapType m_HashMap;
00207   ScalarType m_MaximumDepth;
00208   
00209 private:
00210   void operator=(const Self&) {}
00211   
00212 };
00213 
00214 }// end namespace watershed
00215 }// end namespace itk
00216 
00217 #ifndef ITK_MANUAL_INSTANTIATION
00218 #include "itkWatershedSegmentTable.txx"
00219 #endif
00220 
00221 #endif
00222 

Generated at Thu May 25 00:18:16 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000