00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkListSampleBase_h
00018 #define __itkListSampleBase_h
00019
00020 #include "itkSample.h"
00021
00022 #include <vector>
00023
00024 namespace itk{
00025 namespace Statistics{
00026
00038 template< class TMeasurementVector >
00039 class ITK_EXPORT ListSampleBase : public Sample< TMeasurementVector >
00040 {
00041 public:
00043 typedef ListSampleBase Self;
00044 typedef Sample< TMeasurementVector > Superclass;
00045
00047 itkTypeMacro(ListSampleBase, Sample);
00048
00053 typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00054 typedef typename Superclass::MeasurementType MeasurementType;
00055 typedef typename Superclass::FrequencyType FrequencyType ;
00056 typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00057
00058 typedef std::vector< InstanceIdentifier > SearchResultVectorType ;
00060 itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00061 TMeasurementVector::Length);
00062
00063
00064 inline void Search(MeasurementVectorType center, double radius,
00065 SearchResultVectorType& result) const
00066 {
00067 if (radius == 0.0)
00068 {
00069 itkGenericExceptionMacro("Search radius should be greater than zero.") ;
00070 }
00071
00072 unsigned int j ;
00073 double squaredRadius ;
00074 double distance ;
00075 double coordinateDistance ;
00076
00077 MeasurementVectorType tempVector ;
00078 unsigned int length = MeasurementVectorType::Length ;
00079
00080 squaredRadius = radius * radius ;
00081
00082 result.clear() ;
00083 for ( InstanceIdentifier id = 0 ; id < this->Size() ; ++id )
00084 {
00085 distance = 0.0 ;
00086 tempVector = this->GetMeasurementVector( id ) ;
00087 for (j = 0 ; j < length && distance < squaredRadius ; j++)
00088 {
00089 coordinateDistance = (double)tempVector[j] - center[j] ;
00090 if (vnl_math_abs(coordinateDistance) > radius )
00091 {
00092 distance = squaredRadius ;
00093 }
00094 }
00095
00096 for (j = 0 ; j < length && distance < squaredRadius ; j++)
00097 {
00098 coordinateDistance = (double)tempVector[j] - center[j] ;
00099 distance += coordinateDistance * coordinateDistance ;
00100 }
00101
00102 if (distance < squaredRadius)
00103 {
00104 result.push_back( id ) ;
00105 }
00106 }
00107 }
00108 protected:
00109 ListSampleBase() {}
00110 virtual ~ListSampleBase() {}
00111
00112 private:
00113 ListSampleBase(const Self&) ;
00114 void operator=(const Self&) ;
00115 };
00116
00117 }
00118 }
00119
00120 #endif