Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkPointSet.h"
00019 #include "mitkPointSetWriter.h"
00020 #include "mitkPointSetReader.h"
00021 #include "mitkTestingMacros.h"
00022 #include <vector>
00023 #include <itksys/SystemTools.hxx>
00024 #include <time.h>
00025
00026
00027 unsigned int numberOfTimeSeries = 5;
00028
00029
00030 class mitkPointSetFileIOTestClass
00031 {
00032 public:
00033
00034 std::vector<mitk::PointSet::Pointer> m_SavedPointSet;
00035
00036 mitkPointSetFileIOTestClass()
00037 {
00038
00039 }
00040
00041 mitk::PointSet::Pointer CreateTestPointSet()
00042 {
00043 mitk::PointSet::Pointer pointSet = mitk::PointSet::New();
00044
00045 for (unsigned int t = 0; t < numberOfTimeSeries; t++)
00046 {
00047 unsigned int position(0);
00048 mitk::Point3D point;
00049 mitk::FillVector3D(point, (rand()%1000) /1000.0 , (rand()%1000) /1000.0, (rand()%1000)/1000.0);
00050 pointSet->SetPoint(position, point, t);
00051
00052 mitk::FillVector3D(point, (rand()%1000) /1000.0 , (rand()%1000) /1000.0, (rand()%1000)/1000.0);
00053 ++position;
00054 pointSet->SetPoint(position, point, t);
00055
00056 mitk::FillVector3D(point, (rand()%1000) /1000.0 , (rand()%1000) /1000.0, (rand()%1000)/1000.0);
00057 ++position;
00058 pointSet->SetPoint(position, point, t);
00059 }
00060 m_SavedPointSet.push_back(pointSet);
00061
00062 return pointSet;
00063
00064 }
00065
00066 void PointSetCompare(mitk::PointSet::Pointer pointSet2,
00067 mitk::PointSet::Pointer pointSet1, bool& )
00068 {
00069
00070 MITK_TEST_CONDITION(pointSet1->GetSize() == pointSet2->GetSize(), "Testing if PointSet size is correct" );
00071
00072 for (unsigned int t = 0; t < numberOfTimeSeries; t++)
00073 {
00074 for (unsigned int i = 0; i < (unsigned int) pointSet1->GetSize(t); ++i)
00075 {
00076 mitk::Point3D p1 = pointSet1->GetPoint(i);
00077 mitk::Point3D p2 = pointSet2->GetPoint(i);
00078
00079
00080 std::cout << "r point: " << p2 << std::endl;
00081 std::cout << "w point: " << p1 << std::endl;
00082
00083
00084
00085 MITK_TEST_CONDITION((p1[0] - p2[0]) <= 0.0001, "Testing if X coordinates of the Point are at the same Position" );
00086 MITK_TEST_CONDITION((p1[1] - p2[1]) <= 0.0001, "Testing if Y coordinates of the Point are at the same Position" );
00087 MITK_TEST_CONDITION((p1[2] - p2[2]) <= 0.0001, "Testing if Z coordinates of the Point are at the same Position" );
00088
00089 }
00090 }
00091
00092 }
00093
00094 bool PointSetWrite(unsigned int numberOfPointSets)
00095 {
00096 try
00097 {
00098 m_SavedPointSet.clear();
00099
00100 mitk::PointSetWriter::Pointer pointSetWriter = mitk::PointSetWriter::New();
00101 pointSetWriter->SetFileName("test_pointset_new.mps");
00102
00103 for (unsigned int i = 0; i < numberOfPointSets; i++)
00104 {
00105 pointSetWriter->SetInput(i, CreateTestPointSet());
00106 }
00107
00108 pointSetWriter->Write();
00109 }
00110 catch (std::exception& )
00111 {
00112 return false;
00113 }
00114
00115 return true;
00116 }
00117
00118 void PointSetLoadAndCompareTest(unsigned int numberOfPointSets)
00119 {
00120 try
00121 {
00122 mitk::PointSetReader::Pointer pointSetReader =
00123 mitk::PointSetReader::New();
00124 mitk::PointSet::Pointer pointSet;
00125
00126 pointSetReader->SetFileName("test_pointset_new.mps");
00127 for (unsigned int i = 0; i < numberOfPointSets; i++)
00128 {
00129 pointSetReader->Update();
00130 pointSet = pointSetReader->GetOutput(i);
00131 MITK_TEST_CONDITION(pointSet.IsNotNull(), "Testing if the loaded Data are NULL" );
00132
00133 bool identical(true);
00134 PointSetCompare(pointSet.GetPointer(), m_SavedPointSet.at(i).GetPointer(),
00135 identical);
00136 }
00137 } catch (std::exception& )
00138 {
00139 }
00140 }
00141
00142 };
00143
00144
00145 int mitkPointSetFileIOTest(int, char*[])
00146 {
00147 MITK_TEST_BEGIN("PointSet");
00148 unsigned int numberOfPointSets(5);
00149
00150 mitkPointSetFileIOTestClass* test = new mitkPointSetFileIOTestClass();
00151
00152
00153 MITK_TEST_CONDITION(test->PointSetWrite(numberOfPointSets), "Testing if the PointSetWriter writes Data" );
00154
00155
00156 test->PointSetLoadAndCompareTest(numberOfPointSets);
00157
00158
00159 delete test;
00160
00161 MITK_TEST_END();
00162 }
00163