ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkWatershedSegmentTree.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 __itkWatershedSegmentTree_h
00019 #define __itkWatershedSegmentTree_h
00020 
00021 #include "itkProcessObject.h"
00022 #include <deque>
00023 #include <functional>
00024 
00025 namespace itk
00026 {
00027 namespace watershed
00028 {
00046 template< class TScalarType >
00047 class ITK_EXPORT SegmentTree:public DataObject
00048 {
00049 public:
00051   typedef SegmentTree                Self;
00052   typedef DataObject                 Superclass;
00053   typedef SmartPointer< Self >       Pointer;
00054   typedef SmartPointer< const Self > ConstPointer;
00055   itkNewMacro(Self);
00056   itkTypeMacro(WatershedSegmentTree, DataObject);
00057   typedef TScalarType ScalarType;
00059 
00063   struct merge_t {
00064     IdentifierType from;
00065     IdentifierType to;
00066     ScalarType saliency;
00067   };
00069 
00071   typedef std::deque< merge_t >              DequeType;
00072   typedef typename DequeType::iterator       Iterator;
00073   typedef typename DequeType::const_iterator ConstIterator;
00074   typedef typename DequeType::value_type     ValueType;
00075 
00077   struct merge_comp:public std:: binary_function< bool, const merge_t &,
00078                                                   const merge_t & > {
00079     merge_comp() {}
00080     bool operator()(const merge_t & a, const merge_t & b)
00081     {
00082       return b.saliency < a.saliency;
00083     }
00084   };
00086 
00088   struct sort_comp:public std:: binary_function< bool, const merge_t &,
00089                                                  const merge_t & > {
00090     bool operator()(const merge_t & a, const merge_t & b)
00091     {
00092       return a.saliency < b.Saliency;
00093     }
00094   };
00095 
00097   typename DequeType::size_type Size() const
00098   { return m_Deque.size(); }
00099 
00102   bool Empty() const
00103   { return m_Deque.empty();    }
00104 
00107   const merge_t & Front() const
00108   { return m_Deque.front(); }
00109 
00112   const merge_t & Back() const
00113   { return m_Deque.back(); }
00114 
00116   merge_t & Front()
00117   { return m_Deque.front(); }
00118 
00120   merge_t & Back()
00121   { return m_Deque.back(); }
00122 
00124   void PushFront(const ValueType & t)
00125   { m_Deque.push_front(t); }
00126 
00128   void PushBack(const ValueType & t)
00129   { m_Deque.push_back(t); }
00130 
00132   void PopFront()
00133   { m_Deque.pop_front(); }
00134 
00136   void PopBack()
00137   { m_Deque.pop_back(); }
00138 
00140   Iterator Begin()
00141   { return m_Deque.begin(); }
00142 
00144   ConstIterator Begin() const
00145   { return m_Deque.begin(); }
00146 
00149   Iterator End()
00150   { return m_Deque.end(); }
00151 
00154   ConstIterator End() const
00155   { return m_Deque.end(); }
00156 
00158   void Clear()
00159   { m_Deque.clear(); }
00160 
00163   void Initialize();
00164 
00165 protected:
00166   SegmentTree() {}
00167   virtual ~SegmentTree() {}
00168   SegmentTree(const Self &) {}
00169   void operator=(const Self &) {}
00170   void PrintSelf(std::ostream & os, Indent indent) const;
00171 
00172   DequeType m_Deque;
00173 };
00174 } // end namespace watershed
00175 } // end namespace itk
00176 
00177 #ifndef ITK_MANUAL_INSTANTIATION
00178 #include "itkWatershedSegmentTree.hxx"
00179 #endif
00180 
00181 #endif
00182