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

itkPointSetToListSampleAdaptor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Insight Segmentation & Registration Toolkit
00004 Module:    $RCSfile: itkPointSetToListSampleAdaptor.h,v $
00005 Language:  C++
00006 Date:      $Date: 2009-05-22 12:55:07 $
00007 Version:   $Revision: 1.3 $
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 __itkPointSetToListSampleAdaptor_h
00018 #define __itkPointSetToListSampleAdaptor_h
00019 
00020 #include <typeinfo>
00021 
00022 #include "itkPointSet.h"
00023 #include "itkListSample.h"
00024 #include "itkSmartPointer.h"
00025 
00026 namespace itk { 
00027 namespace Statistics {
00028 
00042 template < class TPointSet >
00043 class ITK_EXPORT PointSetToListSampleAdaptor :
00044     public ListSample< typename TPointSet::PointType >
00045 {
00046 public:
00048   typedef PointSetToListSampleAdaptor                           Self;
00049   typedef ListSample< typename TPointSet::PointType >           Superclass;
00050   typedef SmartPointer< Self >                                  Pointer;
00051   typedef SmartPointer<const Self>                              ConstPointer;
00052 
00054   itkTypeMacro(PointSetToListSampleAdaptor, ListSample);
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::ConstPointer                 PointSetConstPointer;
00067   typedef typename TPointSet::PointsContainer              PointsContainer;
00068   typedef typename TPointSet::PointsContainerPointer       PointsContainerPointer;
00069   typedef typename TPointSet::PointsContainerConstPointer  PointsContainerConstPointer;
00070   typedef typename TPointSet::PointsContainerIterator      PointsContainerIteratorType;
00071   typedef typename TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType;
00072   typedef typename TPointSet::PointType                    PointType;
00073 
00074 
00077   itkSuperclassTraitMacro( MeasurementType )
00078   itkSuperclassTraitMacro( MeasurementVectorType )
00079   itkSuperclassTraitMacro( AbsoluteFrequencyType )
00080   itkSuperclassTraitMacro( TotalAbsoluteFrequencyType )
00081   itkSuperclassTraitMacro( MeasurementVectorSizeType )
00082   itkSuperclassTraitMacro( InstanceIdentifier )
00083 
00084   typedef MeasurementVectorType                           ValueType;
00085 
00087   void SetPointSet(const TPointSet* pointSet);
00088 
00090   const TPointSet* GetPointSet();
00091 
00093   InstanceIdentifier Size() const;
00094 
00097   const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier id ) const;
00098 
00100   AbsoluteFrequencyType GetFrequency( InstanceIdentifier id ) const;
00101 
00103   TotalAbsoluteFrequencyType GetTotalFrequency() const;
00104 
00106   class ConstIterator
00107     {
00108     friend class PointSetToListSampleAdaptor;
00109     public:
00110 
00111     ConstIterator( const PointSetToListSampleAdaptor * adaptor )
00112       {
00113       *this = adaptor->Begin();
00114       }
00115 
00116     ConstIterator(const ConstIterator &iter)
00117       {
00118       m_Iter = iter.m_Iter;
00119       m_InstanceIdentifier = iter.m_InstanceIdentifier;
00120       }
00121 
00122     ConstIterator& operator=( const ConstIterator & iter )
00123       {
00124       m_Iter = iter.m_Iter;
00125       m_InstanceIdentifier = iter.m_InstanceIdentifier;
00126       return *this;
00127       }
00128 
00129     AbsoluteFrequencyType GetFrequency() const
00130       {
00131       return 1;
00132       }
00133 
00134     const MeasurementVectorType & GetMeasurementVector() const
00135       {
00136       return (const MeasurementVectorType&) m_Iter.Value();
00137       }
00138 
00139     InstanceIdentifier GetInstanceIdentifier() const
00140       {
00141       return m_InstanceIdentifier;
00142       }
00143 
00144     ConstIterator& operator++()
00145       {
00146       ++m_Iter;
00147       ++m_InstanceIdentifier;
00148       return *this;
00149       }
00150 
00151     bool operator!=(const ConstIterator &it)
00152       {
00153       return (m_Iter != it.m_Iter);
00154       }
00155 
00156     bool operator==(const ConstIterator &it)
00157       {
00158       return (m_Iter == it.m_Iter);
00159       }
00160 
00161 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00162   protected:
00163 #endif
00164     // This method should only be available to the ListSample class
00165     ConstIterator(
00166       PointsContainerConstIteratorType iter,
00167       InstanceIdentifier iid)
00168       {
00169       m_Iter = iter;
00170       m_InstanceIdentifier = iid;
00171       }
00172 
00173     // This method is purposely not implemented
00174     ConstIterator();
00175 
00176   private:
00177     PointsContainerConstIteratorType      m_Iter;
00178     InstanceIdentifier                    m_InstanceIdentifier;
00179     };
00180 
00182   class Iterator : public ConstIterator
00183   {
00184 
00185   friend class PointSetToListSampleAdaptor;
00186 
00187   public:
00188 
00189     Iterator(Self * adaptor):ConstIterator(adaptor)
00190       {
00191       }
00192 
00193     Iterator(const Iterator &iter):ConstIterator( iter )
00194       {
00195       }
00196 
00197     Iterator& operator =(const Iterator & iter)
00198       {
00199       this->ConstIterator::operator=( iter );
00200       return *this;
00201       }
00202 
00203 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00204   protected:
00205 #endif
00206     // To ensure const-correctness these method must not be in the public API.
00207     // The are purposly not implemented, since they should never be called.
00208     Iterator();
00209     Iterator(const Self * adaptor);
00210     Iterator(  PointsContainerConstIteratorType iter, InstanceIdentifier iid);
00211     Iterator(const ConstIterator & it);
00212     ConstIterator& operator=(const ConstIterator& it);
00213     Iterator(
00214       PointsContainerIteratorType iter,
00215       InstanceIdentifier iid):ConstIterator( iter, iid )
00216       {
00217       }
00218 
00219   private:
00220   };
00221 
00222 
00224   Iterator Begin()
00225     {
00226     PointsContainerPointer nonConstPointsDataContainer = 
00227                       const_cast< PointsContainer * > (m_PointsContainer.GetPointer());
00228     Iterator iter(nonConstPointsDataContainer->Begin(), 0);
00229     return iter;
00230     }
00232 
00234   Iterator End()
00235     {
00236     PointsContainerPointer nonConstPointsDataContainer = 
00237                       const_cast< PointsContainer * > (m_PointsContainer.GetPointer());
00238 
00239     Iterator iter(nonConstPointsDataContainer->End(), m_PointsContainer->Size());
00240     return iter;
00241     }
00242 
00244   ConstIterator Begin() const
00245     {
00246     ConstIterator iter(m_PointsContainer->Begin(), 0);
00247     return iter;
00248     }
00250 
00252   ConstIterator End() const
00253     {
00254     ConstIterator iter(m_PointsContainer->End(), m_PointsContainer->Size());
00255     return iter;
00256     }
00258 
00259 
00260 protected:
00261   PointSetToListSampleAdaptor(); 
00262   
00263   virtual ~PointSetToListSampleAdaptor() {}
00264   void PrintSelf(std::ostream& os, Indent indent) const;  
00265 
00266 private:
00267   PointSetToListSampleAdaptor(const Self&); //purposely not implemented
00268   void operator=(const Self&); //purposely not implemented
00269 
00271   PointSetConstPointer                     m_PointSet;
00272 
00275   PointsContainerConstPointer              m_PointsContainer;
00276 
00278   mutable PointType                        m_TempPoint;
00279 
00280 }; // end of class PointSetToListSampleAdaptor
00281 
00282 } // end of namespace Statistics
00283 } // end of namespace itk
00284 
00285 
00286 #ifndef ITK_MANUAL_INSTANTIATION
00287 #include "itkPointSetToListSampleAdaptor.txx"
00288 #endif
00289 
00290 #endif
00291 

Generated at Tue Sep 15 04:22:48 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000