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