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

itkPointSetToListAdaptor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Insight Segmentation & Registration Toolkit
00004 Module:    $RCSfile: itkPointSetToListAdaptor.h,v $
00005 Language:  C++
00006 Date:      $Date: 2009-03-04 15:24:04 $
00007 Version:   $Revision: 1.16 $
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     }
00220 
00222   Iterator End()
00223     {
00224     Iterator iter(m_PointsContainer->End()); 
00225     return iter; 
00226     }
00228 
00230   ConstIterator Begin() const
00231     { 
00232     ConstIterator iter(m_PointsContainer->Begin());
00233     return iter; 
00234     }
00236 
00238   ConstIterator End() const
00239     {
00240     ConstIterator iter(m_PointsContainer->End()); 
00241     return iter; 
00242     }
00244 
00245 protected:
00246   PointSetToListAdaptor(); 
00247   
00248   virtual ~PointSetToListAdaptor() {}
00249   void PrintSelf(std::ostream& os, Indent indent) const;  
00250 
00251 private:
00252   PointSetToListAdaptor(const Self&); //purposely not implemented
00253   void operator=(const Self&); //purposely not implemented
00254 
00256   mutable PointSetPointer m_PointSet;
00257 
00260   PointsContainerPointer m_PointsContainer;
00261 
00263   mutable PointType m_TempPoint;
00264 }; // end of class PointSetToListAdaptor
00265 
00266 } // end of namespace Statistics
00267 } // end of namespace itk
00268 
00269 
00270 #ifndef ITK_MANUAL_INSTANTIATION
00271 #include "itkPointSetToListAdaptor.txx"
00272 #endif
00273 
00274 #endif
00275 

Generated at Fri Apr 16 19:19:02 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000