itkListSampleBase.h
Go to the documentation of this file.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
00047 template< class TMeasurementVector >
00048 class ITK_EXPORT ListSampleBase : public Sample< TMeasurementVector >
00049 {
00050 public:
00052 typedef ListSampleBase Self;
00053 typedef Sample< TMeasurementVector > Superclass;
00054 typedef SmartPointer< Self > Pointer;
00055 typedef SmartPointer<const Self> ConstPointer;
00056
00058 itkTypeMacro(ListSampleBase, Sample);
00059
00061 typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00062 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00063 typedef typename Superclass::MeasurementType MeasurementType;
00064 typedef typename Superclass::FrequencyType FrequencyType;
00065 typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00066
00069 typedef std::vector< InstanceIdentifier > SearchResultVectorType;
00070
00073 inline void Search(MeasurementVectorType center, double radius,
00074 SearchResultVectorType& result) const
00075 {
00076 if (radius == 0.0)
00077 {
00078 itkGenericExceptionMacro("Search radius should be greater than zero.");
00079 }
00080
00081 unsigned int j;
00082 double squaredRadius;
00083 double distance;
00084 double coordinateDistance;
00085
00086 MeasurementVectorType tempVector;
00087
00088 squaredRadius = radius * radius;
00089
00090 result.clear();
00091 for ( InstanceIdentifier identifier = 0; identifier < this->Size(); ++identifier )
00092 {
00093 distance = 0.0;
00094 tempVector = this->GetMeasurementVector( identifier );
00095 for (j = 0; j < this->GetMeasurementVectorSize() && distance < squaredRadius; j++)
00096 {
00097 coordinateDistance = (double)tempVector[j] - center[j];
00098 if (vnl_math_abs(coordinateDistance) > radius )
00099 {
00100 distance = squaredRadius;
00101 }
00102 }
00103
00104 for (j = 0; j < this->GetMeasurementVectorSize() && distance < squaredRadius; j++)
00105 {
00106 coordinateDistance = (double)tempVector[j] - center[j];
00107 distance += coordinateDistance * coordinateDistance;
00108 }
00109
00110 if (distance < squaredRadius)
00111 {
00112 result.push_back( identifier );
00113 }
00114 }
00115 }
00116
00117 protected:
00118 ListSampleBase() {}
00119 virtual ~ListSampleBase() {}
00120 void PrintSelf(std::ostream& os, Indent indent) const
00121 {
00122 Superclass::PrintSelf(os,indent);
00123 }
00124
00125
00126 private:
00127 ListSampleBase(const Self&);
00128 void operator=(const Self&);
00129
00130 };
00131
00132 }
00133 }
00134
00135 #endif
00136