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

itkSparseFieldLayer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSparseFieldLayer.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-01-14 18:39:05 $
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 __itkSparseFieldLayer_h
00018 #define __itkSparseFieldLayer_h
00019 
00020 #include "itkObjectFactory.h"
00021 #include "itkObject.h"
00022 #include <vector>
00023 
00024 namespace itk {
00025 
00031 template <class TNodeType>
00032 class ConstSparseFieldLayerIterator
00033 {
00034 public:
00035   const TNodeType& operator*() const
00036     { return *m_Pointer; }
00037 
00038   const TNodeType* operator->() const
00039     { return m_Pointer; }
00040 
00041   const TNodeType* GetPointer() const
00042     { return m_Pointer; }
00043   
00044   bool operator==(const ConstSparseFieldLayerIterator o) const
00045     {
00046     if (m_Pointer == o.m_Pointer) return true;
00047     else return false;
00048     }
00049 
00050   bool operator!=(const ConstSparseFieldLayerIterator o) const
00051     {
00052     if (m_Pointer != o.m_Pointer) return true;
00053     else return false;
00054     }
00055 
00056   ConstSparseFieldLayerIterator &operator++()
00057     {
00058     m_Pointer = m_Pointer->Next;
00059     return *this;
00060     }
00061 
00062   ConstSparseFieldLayerIterator &operator--()
00063     {
00064     m_Pointer = m_Pointer->Previous;
00065     return *this;
00066     }
00067 
00068   ConstSparseFieldLayerIterator()
00069     { m_Pointer=0; }
00070 
00071   ConstSparseFieldLayerIterator(TNodeType *p)
00072     { m_Pointer=p; }
00073 
00074   ~ConstSparseFieldLayerIterator() {}
00075 
00076 protected:
00077   TNodeType *m_Pointer;
00078 };
00079 
00083 template <class TNodeType>
00084 class SparseFieldLayerIterator
00085   : public ConstSparseFieldLayerIterator<TNodeType>
00086 {
00087 public:
00088   typedef ConstSparseFieldLayerIterator<TNodeType> Superclass;
00089 
00090   SparseFieldLayerIterator() : Superclass()
00091     {}
00092 
00093   SparseFieldLayerIterator(TNodeType *p) : Superclass(p)
00094     {}
00095 
00096   TNodeType &operator*()
00097     { return *this->m_Pointer; }
00098 
00099   TNodeType* operator->()
00100     { return this->m_Pointer; }
00101 
00102   TNodeType* GetPointer()
00103     { return this->m_Pointer; }
00104   
00105   SparseFieldLayerIterator &operator++()
00106     {
00107     this->m_Pointer = this->m_Pointer->Next;
00108     return *this;
00109     }
00110 
00111   SparseFieldLayerIterator &operator--()
00112     {
00113     this->m_Pointer = this->m_Pointer->Previous;
00114     return *this;
00115     }
00116 
00117   SparseFieldLayerIterator &operator=(Superclass &sc)
00118     {
00119     this->m_Pointer = const_cast<TNodeType*> (sc.GetPointer());
00120     return *this;
00121     }
00122 };
00123 
00124 
00145 template <class TNodeType>
00146 class ITK_EXPORT SparseFieldLayer
00147     : public Object
00148 {
00149 public:
00151   typedef SparseFieldLayer          Self;
00152   typedef Object                    Superclass;
00153   typedef SmartPointer<Self>        Pointer;
00154   typedef SmartPointer<const Self>  ConstPointer;
00155 
00157   itkNewMacro(Self);
00158 
00160   itkTypeMacro(SparseFieldLayer, Object);
00161 
00163   typedef TNodeType NodeType;
00164 
00167   typedef NodeType ValueType;
00168 
00170   typedef SparseFieldLayerIterator<NodeType> Iterator;
00171 
00173   typedef ConstSparseFieldLayerIterator<NodeType> ConstIterator;
00174 
00176   struct RegionType 
00177     {
00178     ConstIterator first;
00179     ConstIterator last;  // this is one past the actual last element
00180     };   
00181 
00182   typedef std::vector<RegionType> RegionListType;
00183 
00186   NodeType *Front()
00187     { return m_HeadNode->Next; }
00188 
00190   const NodeType *Front() const
00191     { return m_HeadNode->Next; }
00192 
00194   void PopFront()
00195     {
00196     m_HeadNode->Next = m_HeadNode->Next->Next;
00197     m_HeadNode->Next->Previous = m_HeadNode;
00198     m_Size -= 1;
00199     }
00200 
00202   void PushFront(NodeType *n)
00203     {
00204     n->Next = m_HeadNode->Next;
00205     n->Previous = m_HeadNode;
00206     m_HeadNode->Next->Previous = n;
00207     m_HeadNode->Next = n;
00208     m_Size += 1;
00209     }
00210 
00212   void Unlink(NodeType *n)
00213     {
00214     n->Previous->Next = n->Next;
00215     n->Next->Previous = n->Previous;
00216     m_Size -= 1;
00217     }
00218 
00220   Iterator Begin()
00221     { return Iterator(m_HeadNode->Next); }
00222 
00225   ConstIterator Begin() const
00226     { return ConstIterator(m_HeadNode->Next); }
00227 
00229   Iterator End()
00230     { return Iterator(m_HeadNode); }
00231 
00233   ConstIterator End() const
00234     { return ConstIterator(m_HeadNode); }
00235 
00238   bool Empty() const
00239     {
00240     if (m_HeadNode->Next == m_HeadNode) return true;
00241     else return false;
00242     }
00244 
00247   unsigned int Size() const;
00248 
00251   RegionListType SplitRegions(int num) const;
00252 
00253 protected:
00254   SparseFieldLayer();
00255   ~SparseFieldLayer();
00256   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00257   
00258 private:
00259   SparseFieldLayer(const Self&);    //purposely not implemented
00260   void operator=(const Self&);      //purposely not implemented
00261   
00264   NodeType *   m_HeadNode;
00265   unsigned int m_Size;
00266 };
00267 
00268 
00269 } // end namespace itk
00270 
00271 #ifndef ITK_MANUAL_INSTANTIATION
00272 #include "itkSparseFieldLayer.txx"
00273 #endif
00274 
00275 #endif
00276 

Generated at Mon Jul 12 2010 19:55:50 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000