21 #include "itkPSMProcrustesFunction.h" 22 #include "itkCommand.h" 23 #include "itkPSMProjectReader.h" 25 int itkPSMProcrustesFunction2DTest(
int argc,
char* argv[] )
28 double value1, value2, value3;
29 itk::PSMProcrustesFunction<2>::PointType pt;
30 std::string errstring =
"";
31 std::string output_path =
"";
32 std::string input_path_prefix =
"";
33 itk::PSMProcrustesFunction<2>::ShapeType s;
34 itk::PSMProcrustesFunction<2>::ShapeListType sl;
39 std::cout <<
"Wrong number of arguments. \nUse: " 40 <<
"itkPSMProcrustesFunctionTest parameter_file [output_path] [input_path]\n" 41 <<
"See itk::PSMParameterFileReader for documentation on the parameter file format.\n" 42 <<
" Note that input_path will be prefixed to any file names and paths in the xml parameter file.\n" 49 output_path = std::string(argv[2]);
54 input_path_prefix = std::string(argv[3]);
60 itk::PSMProjectReader::Pointer xmlreader = itk::PSMProjectReader::New();
61 xmlreader->SetFileName(argv[1]);
64 itk::PSMProject::Pointer project = xmlreader->GetOutput();
67 const std::vector<std::string> &pt_files = project->GetModel(std::string(
"initialization"));
68 std::cout <<
"Reading the point files to be registered ..." << std::endl;
69 for (
unsigned int i = 0; i < pt_files.size(); i++)
75 in.open( (input_path_prefix + pt_files[i]).c_str() );
78 errstring +=
"Could not open point file for input.";
86 in>>value1>>value2>>value3;
97 std::cout <<
" " << pt_files[i] << std::endl;
100 std::cout <<
"Done!" << std::endl;
102 itk::PSMProcrustesFunction<2>::SimilarityTransformListType transforms;
108 itk::PSMProcrustesFunction<2>::ShapeType reference_shape;
109 itk::PSMProcrustesFunction<2>::ShapeIteratorType it_ref;
110 itk::PSMProcrustesFunction<2>::ShapeIteratorType it;
111 reference_shape = sl[0];
112 for (
unsigned int i = 1; i < pt_files.size(); i++)
115 for(it = s.begin(),it_ref = reference_shape.begin();it != s.end(),it_ref != reference_shape.end(); it++,it_ref++)
117 itk::PSMProcrustesFunction<2>::PointType & point1 = (*it_ref);
118 itk::PSMProcrustesFunction<2>::PointType & point2 = (*it);
120 for(
int j = 0; j<2; j++)
122 float diff = point1[j] - point2[j];
134 const std::vector<std::string> &out_files = project->GetModel(std::string(
"optimized"));
136 for (
unsigned int i = 0; i < out_files.size(); i++)
139 std::string fname = output_path + out_files[i];
141 out.open( fname.c_str() );
145 errstring +=
"Could not open point file for output: ";
149 for(itk::PSMProcrustesFunction<2>::ShapeIteratorType it = s.begin(); it != s.end(); it++)
151 itk::PSMProcrustesFunction<2>::PointType & point = (*it);
153 out << point[0] <<
" " << point[1] <<
" " << 0.0 << std::endl;
162 catch(itk::ExceptionObject &e)
164 errstring =
"ITK exception with description: " + std::string(e.GetDescription())
165 + std::string(
"\n at location:") + std::string(e.GetLocation())
166 + std::string(
"\n in file:") + std::string(e.GetFile());
171 errstring =
"Unknown exception thrown";
177 std::cout <<
"All tests passed" << std::endl;
182 std::cout <<
"Test failed with the following error:" << std::endl;
183 std::cout << errstring << std::endl;
Generalized Procrustes Analysis is the rigid registration between different input shapes represented ...
void RunGeneralizedProcrustes(SimilarityTransformListType &transform, ShapeListType &shapes)