21 #include "itkPSMProcrustesFunction.h" 22 #include "itkCommand.h" 23 #include "itkPSMProjectReader.h" 25 int itkPSMProcrustesFunctionTest(
int argc,
char* argv[] )
28 double value1, value2, value3;
29 itk::PSMProcrustesFunction<3>::PointType pt;
30 std::string errstring =
"";
31 std::string output_path =
"";
32 std::string input_path_prefix =
"";
33 itk::PSMProcrustesFunction<3>::ShapeType s;
34 itk::PSMProcrustesFunction<3>::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;
98 std::cout <<
" " << pt_files[i] << std::endl;
101 std::cout <<
"Done!" << std::endl;
103 itk::PSMProcrustesFunction<3>::SimilarityTransformListType transforms;
109 itk::PSMProcrustesFunction<3>::ShapeType reference_shape;
110 itk::PSMProcrustesFunction<3>::ShapeIteratorType it_ref;
111 itk::PSMProcrustesFunction<3>::ShapeIteratorType it;
112 reference_shape = sl[0];
113 for (
unsigned int i = 1; i < pt_files.size(); i++)
116 for(it = s.begin(),it_ref = reference_shape.begin();it != s.end(),it_ref != reference_shape.end(); it++,it_ref++)
118 itk::PSMProcrustesFunction<3>::PointType & point1 = (*it_ref);
119 itk::PSMProcrustesFunction<3>::PointType & point2 = (*it);
121 for(
int j = 0; j<3; j++)
123 float diff = point1[j] - point2[j];
135 const std::vector<std::string> &out_files = project->GetModel(std::string(
"optimized"));
137 for (
unsigned int i = 0; i < out_files.size(); i++)
140 std::string fname = output_path + out_files[i];
142 out.open( fname.c_str() );
146 errstring +=
"Could not open point file for output: ";
150 for(itk::PSMProcrustesFunction<3>::ShapeIteratorType it = s.begin(); it != s.end(); it++)
152 itk::PSMProcrustesFunction<3>::PointType & point = (*it);
153 out << point[0] <<
" " << point[1] <<
" " << point[2] << std::endl;
161 catch(itk::ExceptionObject &e)
163 errstring =
"ITK exception with description: " + std::string(e.GetDescription())
164 + std::string(
"\n at location:") + std::string(e.GetLocation())
165 + std::string(
"\n in file:") + std::string(e.GetFile());
170 errstring =
"Unknown exception thrown";
176 std::cout <<
"All tests passed" << std::endl;
181 std::cout <<
"Test failed with the following error:" << std::endl;
182 std::cout << errstring << std::endl;
Generalized Procrustes Analysis is the rigid registration between different input shapes represented ...
void RunGeneralizedProcrustes(SimilarityTransformListType &transform, ShapeListType &shapes)