00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkSparseFieldLayer.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/02/27 20:14:09 $ 00007 Version: $Revision: 1.3 $ 00008 00009 Copyright (c) 2002 Insight 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 *m_Pointer; } 00098 00099 TNodeType* operator->() 00100 { return m_Pointer; } 00101 00102 TNodeType* GetPointer() 00103 { return m_Pointer; } 00104 00105 SparseFieldLayerIterator &operator++() 00106 { 00107 m_Pointer = m_Pointer->Next; 00108 return *this; 00109 } 00110 00111 SparseFieldLayerIterator &operator--() 00112 { 00113 m_Pointer = m_Pointer->Previous; 00114 return *this; 00115 } 00116 00117 SparseFieldLayerIterator &operator=(Superclass &sc) 00118 { 00119 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 00185 NodeType *Front() 00186 { return m_HeadNode->Next; } 00187 00189 const NodeType *Front() const 00190 { return m_HeadNode->Next; } 00191 00193 void PopFront() 00194 { 00195 m_HeadNode->Next = m_HeadNode->Next->Next; 00196 m_HeadNode->Next->Previous = m_HeadNode; 00197 } 00198 00200 void PushFront(NodeType *n) 00201 { 00202 n->Next = m_HeadNode->Next; 00203 n->Previous = m_HeadNode; 00204 m_HeadNode->Next->Previous = n; 00205 m_HeadNode->Next = n; 00206 } 00207 00209 void Unlink(NodeType *n) 00210 { 00211 n->Previous->Next = n->Next; 00212 n->Next->Previous = n->Previous; 00213 } 00214 00216 Iterator Begin() 00217 { return Iterator(m_HeadNode->Next); } 00218 00220 ConstIterator Begin() const 00221 { return ConstIterator(m_HeadNode->Next); } 00222 00224 Iterator End() 00225 { return Iterator(m_HeadNode); } 00226 00228 ConstIterator End() const 00229 { return ConstIterator(m_HeadNode); } 00230 00233 bool Empty() const 00234 { 00235 if (m_HeadNode->Next == m_HeadNode) return true; 00236 else return false; 00237 } 00238 00243 unsigned int Size() const; 00244 00247 RegionListType SplitRegions(int num) const; 00248 00251 // void Splice (SparseFieldLayer &); 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 }; 00266 00267 00268 } // end namespace itk 00269 00270 #ifndef ITK_MANUAL_INSTANTIATION 00271 #include "itkSparseFieldLayer.txx" 00272 #endif 00273 00274 #endif