Shapeworks Studio  2.1
Shape analysis software suite
itkPSMMeanCurvatureAttributeTest.cxx
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #include <iostream>
19 #include "itkImage.h"
20 #include "itkImageFileReader.h"
21 #include "itkPSMMeanCurvatureAttribute.h"
22 #include "itkPSMSurfaceNeighborhood.h"
23 #include "itkMacro.h"
24 
26 int itkPSMMeanCurvatureAttributeTest(int argc, char* argv[] )
27 {
28  bool passed = true;
29  std::string errstring = "";
30 
31  // Check for proper arguments
32  if (argc < 2)
33  {
34  std::cout << "Wrong number of arguments. You need one image file." << std::endl;
35  return EXIT_FAILURE;
36  }
37 
38  try
39  {
40  typedef itk::Point<double, 3> PointType;
41  typedef itk::Image<float, 3> ImageType;
42 
43  itk::PSMMeanCurvatureAttribute<float, 3>::Pointer P
45 
46  // Read image file
47  itk::ImageFileReader<ImageType>::Pointer reader
48  = itk::ImageFileReader<ImageType>::New();
49  reader->SetFileName(argv[1]);
50  reader->UpdateLargestPossibleRegion();
51 
52  itk::PSMSurfaceNeighborhood<ImageType>::Pointer sn
54 
55  // Setup Domain
56  itk::PSMImageDomainWithCurvature<float, 3>::Pointer domain
58  domain->SetImage(reader->GetOutput());
59 
60  // Get Bounds
61  PointType ptl = domain->GetLowerBound();
62  PointType ptu = domain->GetUpperBound();
63 
64  itk::PSMParticleSystem<3>::Pointer ps =
66  ps->RegisterAttribute(P);
67  ps->AddDomain(domain);
68  ps->SetNeighborhood(0, sn);
69 
70  // Add points
71  unsigned int SZ = 100;
72  PointType pt;
73  double range[3] = { ptu[0]-ptl[0], ptu[1]-ptl[1], ptu[2]-ptl[2] };
74  for (unsigned int i = 0; i < SZ; i++)
75  {
76  pt[0] = static_cast<double>(i)/static_cast<double>(SZ)*range[0]+ptl[0]+0.1;
77  pt[1] = static_cast<double>(i)/static_cast<double>(SZ)*range[1]+ptl[1]+0.1;
78  pt[2] = static_cast<double>(i)/static_cast<double>(SZ)*range[2]+ptl[2]+0.1;
79  ps->AddPosition(pt, 0);
80  }
81 
83 
84  if (P->GetMeanCurvature(0) == 0.0f)
85  {
86  passed = false;
87  errstring += std::string("GetMeanCurvature method failed. ");
88  }
89  if (P->GetCurvatureStandardDeviation(0) == 0.0f)
90  {
91  passed = false;
92  errstring += std::string("GetCurvatureStandardDeviation method failed. ");
93  }
94  }
95  catch(itk::ExceptionObject &e)
96  {
97  errstring = "ITK exception with description: " + std::string(e.GetDescription())
98  + std::string("\n at location:") + std::string(e.GetLocation())
99  + std::string("\n in file:") + std::string(e.GetFile());
100  passed = false;
101  }
102  catch(...)
103  {
104  errstring = "Unknown exception thrown";
105  passed = false;
106  }
107 
108  if (passed)
109  {
110  std::cout << "All tests passed" << std::endl;
111  return EXIT_SUCCESS;
112  }
113  else
114  {
115  std::cout << "Test failed with the following error:" << std::endl;
116  std::cout << errstring << std::endl;
117  return EXIT_FAILURE;
118  }
119 }
PSMSurfaceNeighborhood is a general purpose neighborhood object that computes neighborhoods based on ...
virtual void ComputeCurvatureStatistics(const ParticleSystemType *, unsigned int d)
void AddDomain(DomainType *, int threadId=0)
void SetNeighborhood(unsigned int, NeighborhoodType *, int threadId=0)
void RegisterAttribute(PSMAttribute< VDimension > *)
const PointType & AddPosition(const PointType &, unsigned int d=0, int threadId=0)
virtual const PointType & GetLowerBound() const
A facade class that manages interactions with a particle system.