00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkPointSetToListAdaptor.h,v $ 00005 Language: C++ 00006 Date: $Date: 2005/09/30 17:40:35 $ 00007 Version: $Revision: 1.15 $ 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 __itkPointSetToListAdaptor_h 00018 #define __itkPointSetToListAdaptor_h 00019 00020 #include <typeinfo> 00021 00022 #include "itkPointSet.h" 00023 #include "itkListSampleBase.h" 00024 #include "itkSmartPointer.h" 00025 00026 namespace itk{ 00027 namespace Statistics{ 00028 00042 template < class TPointSet > 00043 class ITK_EXPORT PointSetToListAdaptor : 00044 public ListSampleBase< typename TPointSet::PointType > 00045 { 00046 public: 00048 typedef PointSetToListAdaptor Self; 00049 typedef ListSampleBase< typename TPointSet::PointType > Superclass ; 00050 typedef SmartPointer< Self > Pointer; 00051 typedef SmartPointer<const Self> ConstPointer; 00052 00054 itkTypeMacro(PointSetToListAdaptor, ListSampleBase) ; 00055 00057 itkNewMacro(Self) ; 00058 00060 itkStaticConstMacro(MeasurementVectorSize, unsigned int, 00061 TPointSet::PointDimension); 00062 00064 typedef TPointSet PointSetType; 00065 typedef typename TPointSet::Pointer PointSetPointer ; 00066 typedef typename TPointSet::PointIdentifier InstanceIdentifier; 00067 typedef typename TPointSet::PointsContainerPointer PointsContainerPointer ; 00068 typedef typename TPointSet::PointsContainerIterator PointsContainerIterator ; 00069 typedef typename TPointSet::PointType PointType ; 00070 00071 00074 typedef typename Superclass::MeasurementType MeasurementType ; 00075 typedef typename Superclass::MeasurementVectorType MeasurementVectorType; 00076 typedef MeasurementVectorType ValueType ; 00077 typedef typename Superclass::FrequencyType FrequencyType ; 00078 typedef typename Superclass::TotalFrequencyType TotalFrequencyType ; 00079 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType; 00080 00082 void SetPointSet(TPointSet* pointSet) ; 00083 00085 TPointSet* GetPointSet() ; 00086 00088 unsigned int Size() const ; 00089 00092 const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const; 00093 00096 void SetMeasurement(const InstanceIdentifier &id, 00097 const unsigned int &dim, 00098 const MeasurementType &value) ; 00099 00101 FrequencyType GetFrequency(const InstanceIdentifier &id) const ; 00102 00104 TotalFrequencyType GetTotalFrequency() const ; 00105 00106 void SetMeasurementVectorSize( const MeasurementVectorSizeType s ) 00107 { 00108 // MV size of the point set is fixed as that of the point's dimension 00109 // Throw exception if user tries to set it to a different value 00110 if( s != MeasurementVectorSize ) 00111 { 00112 itkExceptionMacro( << "PointSetToListAdaptor's measurement vector lengths" 00113 << " cannot be set to " << s ); 00114 } 00115 } 00116 00117 MeasurementVectorSizeType GetMeasurementVectorSize() const 00118 { 00119 return MeasurementVectorSize; 00120 } 00121 00122 00123 00124 class Iterator 00125 { 00126 public: 00127 00128 Iterator(){} 00129 00130 Iterator(PointsContainerIterator iter) 00131 :m_Iter(iter) 00132 {} 00133 00134 FrequencyType GetFrequency() const 00135 { return 1 ;} 00136 00137 const MeasurementVectorType & GetMeasurementVector() const 00138 { return (MeasurementVectorType&) m_Iter.Value() ;} 00139 00140 InstanceIdentifier GetInstanceIdentifier() const 00141 { return m_Iter.Index() ;} 00142 00143 Iterator& operator++() 00144 { ++m_Iter ; return *this ;} 00145 00146 Iterator& operator--() 00147 { --m_Iter ; return *this ;} 00148 00149 bool operator!=(const Iterator &it) 00150 { return (m_Iter != it.m_Iter) ;} 00151 00152 bool operator==(const Iterator &it) 00153 { return (m_Iter == it.m_Iter) ;} 00154 00155 Iterator& operator = (const Iterator &iter) 00156 { 00157 m_Iter = iter.m_Iter; 00158 return iter ; 00159 } 00160 00161 Iterator(const Iterator &iter) 00162 { m_Iter = iter.m_Iter; } 00163 00164 private: 00165 PointsContainerIterator m_Iter ; 00166 } ; 00167 00168 00169 class ConstIterator 00170 { 00171 public: 00172 00173 ConstIterator(){} 00174 00175 ConstIterator(PointsContainerIterator iter) 00176 :m_Iter(iter) 00177 {} 00178 00179 FrequencyType GetFrequency() const 00180 { return 1 ;} 00181 00182 const MeasurementVectorType & GetMeasurementVector() const 00183 { return (MeasurementVectorType&) m_Iter.Value() ;} 00184 00185 InstanceIdentifier GetInstanceIdentifier() const 00186 { return m_Iter.Index() ;} 00187 00188 ConstIterator& operator++() 00189 { ++m_Iter ; return *this ;} 00190 00191 ConstIterator& operator--() 00192 { --m_Iter ; return *this ;} 00193 00194 bool operator!=(const ConstIterator &it) 00195 { return (m_Iter != it.m_Iter) ;} 00196 00197 bool operator==(const ConstIterator &it) 00198 { return (m_Iter == it.m_Iter) ;} 00199 00200 ConstIterator& operator = (const ConstIterator &iter) 00201 { 00202 m_Iter = iter.m_Iter; 00203 return iter ; 00204 } 00205 00206 ConstIterator(const ConstIterator &iter) 00207 { m_Iter = iter.m_Iter; } 00208 00209 private: 00210 PointsContainerIterator m_Iter ; 00211 } ; 00212 00214 Iterator Begin() 00215 { 00216 Iterator iter(m_PointsContainer->Begin()); 00217 return iter; 00218 } 00219 00221 Iterator End() 00222 { 00223 Iterator iter(m_PointsContainer->End()); 00224 return iter; 00225 } 00226 00228 ConstIterator Begin() const 00229 { 00230 ConstIterator iter(m_PointsContainer->Begin()); 00231 return iter; 00232 } 00233 00235 ConstIterator End() const 00236 { 00237 ConstIterator iter(m_PointsContainer->End()); 00238 return iter; 00239 } 00240 00241 protected: 00242 PointSetToListAdaptor(); 00243 00244 virtual ~PointSetToListAdaptor() {} 00245 void PrintSelf(std::ostream& os, Indent indent) const; 00246 00247 private: 00248 PointSetToListAdaptor(const Self&) ; //purposely not implemented 00249 void operator=(const Self&) ; //purposely not implemented 00250 00252 mutable PointSetPointer m_PointSet ; 00255 PointsContainerPointer m_PointsContainer ; 00257 mutable PointType m_TempPoint ; 00258 } ; // end of class PointSetToListAdaptor 00259 00260 } // end of namespace Statistics 00261 } // end of namespace itk 00262 00263 00264 #ifndef ITK_MANUAL_INSTANTIATION 00265 #include "itkPointSetToListAdaptor.txx" 00266 #endif 00267 00268 #endif