20 #include "itkImageFileReader.h" 21 #include "itkPSMSurfaceNeighborhood.h" 28 int itkPSMSurfaceNeighborhoodTest(
int argc,
char* argv[])
31 std::string errstring =
"";
36 std::cout <<
"Wrong number of arguments. You need one image file." << std::endl;
42 typedef itk::Point<double, 3> PointType;
43 typedef itk::Image<float, 3> ImageType;
46 itk::PSMSurfaceNeighborhood<ImageType>::Pointer P
50 itk::ImageFileReader<ImageType>::Pointer reader
51 = itk::ImageFileReader<ImageType>::New();
52 reader->SetFileName(argv[1]);
53 reader->UpdateLargestPossibleRegion();
56 itk::PSMImplicitSurfaceDomain<float, 3>::Pointer domain
58 domain->
SetImage(reader->GetOutput());
63 PointType ptu = domain->GetUpperBound();
66 unsigned int SZ = 100;
70 for (
unsigned int i = 0; i < 3; i++)
72 range[i] = ptu[i]-ptl[i];
73 maxDist += range[i]*range[i];
76 for (
unsigned int i = 0; i < SZ; i++)
78 for (
unsigned int j = 0; j < 3; j++)
80 pt[j] =
static_cast<double>(i)/static_cast<double>(SZ)*range[j]+ptl[j]+0.1;
85 for (
unsigned int i = 0; i < 3; i++)
87 pt[i] = range[i]/2 + ptl[i];
89 itk::PSMSurfaceNeighborhood<ImageType>::PointVectorType vec;
90 std::vector<double> weights;
96 errstring += std::string(
"AddPosition method failed. ");
100 P->SetPosition(pt, SZ/4);
103 if (vec.size() != SZ)
106 errstring += std::string(
"SetPosition method failed. ");
114 errstring += std::string(
"FindNeighborhoodPoints size failed. ");
116 else if ((vec[0].Index != SZ/2 && vec[1].Index != SZ/2) ||
117 (vec[0].Index != SZ/4 && vec[1].Index != SZ/4))
120 errstring += std::string(
"FindNeightborhoodPoints index failed. ");
124 P->RemovePosition(SZ/4);
129 errstring += std::string(
"RemovePoints method failed. ");
132 catch(itk::ExceptionObject &e)
134 errstring =
"ITK exception with description: " + std::string(e.GetDescription())
135 + std::string(
"\n at location:") + std::string(e.GetLocation())
136 + std::string(
"\n in file:") + std::string(e.GetFile());
141 errstring =
"Unknown exception thrown";
147 std::cout <<
"All tests passed" << std::endl;
152 std::cout <<
"Test failed with the following error:" << std::endl;
153 std::cout << errstring << std::endl;
PSMSurfaceNeighborhood is a general purpose neighborhood object that computes neighborhoods based on ...
void AddPosition(const PointType &p, unsigned int idx, int threadId=0)
virtual const PointType & GetLowerBound() const
virtual PointVectorType FindNeighborhoodPointsWithWeights(const PointType &, std::vector< double > &, double) const
void SetImage(ImageType *I)
virtual void SetDomain(DomainType *p)