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: 2005/07/26 15:55:04 $
00007 Version:   $Revision: 1.13 $
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::MeasurementVectorSizeType MeasurementVectorSizeType;
00079 
00081   void SetPointSet(TPointSet* pointSet) ;
00082 
00084   TPointSet* GetPointSet() ;
00085 
00087   unsigned int Size() const ;
00088 
00091   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00092 
00095   void SetMeasurement(const InstanceIdentifier &id, 
00096                       const unsigned int &dim,
00097                       const MeasurementType &value) ;
00098 
00100   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00101 
00103   FrequencyType GetTotalFrequency() const ;
00104 
00105   void SetMeasurementVectorSize( const MeasurementVectorSizeType s )
00106     {
00107     // MV size of the point set is fixed as that of the point's dimension
00108     // Throw exception if user tries to set it to a different value
00109     if( s != MeasurementVectorSize )
00110       {
00111       itkExceptionMacro( << "PointSetToListAdaptor's measurement vector lengths"
00112           << " cannot be set to " << s );
00113       }
00114     }
00115 
00116   MeasurementVectorSizeType GetMeasurementVectorSize() const
00117     {
00118     return MeasurementVectorSize;
00119     }
00120     
00121 
00122  
00123   class Iterator
00124   {
00125   public:
00126     
00127     Iterator(){}
00128     
00129     Iterator(PointsContainerIterator iter)
00130       :m_Iter(iter)
00131     {}
00132     
00133     FrequencyType GetFrequency() const
00134     { return 1 ;}
00135 
00136     const MeasurementVectorType & GetMeasurementVector() const
00137     { return (MeasurementVectorType&) m_Iter.Value() ;} 
00138 
00139     InstanceIdentifier GetInstanceIdentifier() const
00140     { return m_Iter.Index() ;}
00141 
00142     Iterator& operator++()
00143     { ++m_Iter ; return *this ;}
00144     
00145     Iterator& operator--()
00146     { --m_Iter ; return *this ;}
00147 
00148     bool operator!=(const Iterator &it)
00149     { return (m_Iter != it.m_Iter) ;}
00150     
00151     bool operator==(const Iterator &it)
00152     { return (m_Iter == it.m_Iter) ;}
00153     
00154     Iterator& operator = (const Iterator &iter)
00155     { 
00156       m_Iter = iter.m_Iter; 
00157       return iter ;
00158     }
00159 
00160     Iterator(const Iterator &iter)
00161     { m_Iter = iter.m_Iter; }
00162     
00163   private:
00164     PointsContainerIterator m_Iter ;
00165   } ;
00166    
00167  
00168   class ConstIterator
00169   {
00170   public:
00171     
00172     ConstIterator(){}
00173     
00174     ConstIterator(PointsContainerIterator iter)
00175       :m_Iter(iter)
00176     {}
00177     
00178     FrequencyType GetFrequency() const
00179     { return 1 ;}
00180 
00181     const MeasurementVectorType & GetMeasurementVector() const
00182     { return (MeasurementVectorType&) m_Iter.Value() ;} 
00183 
00184     InstanceIdentifier GetInstanceIdentifier() const
00185     { return m_Iter.Index() ;}
00186 
00187     ConstIterator& operator++()
00188     { ++m_Iter ; return *this ;}
00189     
00190     ConstIterator& operator--()
00191     { --m_Iter ; return *this ;}
00192 
00193     bool operator!=(const ConstIterator &it)
00194     { return (m_Iter != it.m_Iter) ;}
00195     
00196     bool operator==(const ConstIterator &it)
00197     { return (m_Iter == it.m_Iter) ;}
00198     
00199     ConstIterator& operator = (const ConstIterator &iter)
00200     { 
00201       m_Iter = iter.m_Iter; 
00202       return iter ;
00203     }
00204 
00205     ConstIterator(const ConstIterator &iter)
00206     { m_Iter = iter.m_Iter; }
00207     
00208   private:
00209     PointsContainerIterator m_Iter ;
00210   } ;
00211    
00213   Iterator Begin()
00214   { 
00215     Iterator iter(m_PointsContainer->Begin());
00216     return iter; 
00217   }
00218   
00220   Iterator End()        
00221   {
00222     Iterator iter(m_PointsContainer->End()); 
00223     return iter; 
00224   }
00225    
00227   ConstIterator Begin() const
00228   { 
00229     ConstIterator iter(m_PointsContainer->Begin());
00230     return iter; 
00231   }
00232   
00234   ConstIterator End() const
00235   {
00236     ConstIterator iter(m_PointsContainer->End()); 
00237     return iter; 
00238   }
00239   
00240 protected:
00241   PointSetToListAdaptor(); 
00242   
00243   virtual ~PointSetToListAdaptor() {}
00244   void PrintSelf(std::ostream& os, Indent indent) const;  
00245 
00246 private:
00247   PointSetToListAdaptor(const Self&) ; //purposely not implemented
00248   void operator=(const Self&) ; //purposely not implemented
00249 
00251   mutable PointSetPointer m_PointSet ;
00254   PointsContainerPointer m_PointsContainer ;
00256   mutable PointType m_TempPoint ;
00257 } ; // end of class PointSetToListAdaptor
00258 
00259 } // end of namespace Statistics
00260 } // end of namespace itk
00261 
00262 
00263 #ifndef ITK_MANUAL_INSTANTIATION
00264 #include "itkPointSetToListAdaptor.txx"
00265 #endif
00266 
00267 #endif

Generated at Tue Aug 30 16:45:53 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000