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
00019 #include "mitkImage.h"
00020 #include "mitkPicFileReader.h"
00021 #include "mitkPicHelper.h"
00022 #include "mitkTimeSlicedGeometry.h"
00023 #include "mitkSlicedGeometry3D.h"
00024 #include <itksys/SystemTools.hxx>
00025
00026 #include <fstream>
00027 int mitkPicFileReaderTest(int argc, char* argv[])
00028 {
00029
00030 mitkIpPicDescriptor *picheader=NULL;
00031 if(argc>=1)
00032 {
00033 if(itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameExtension(argv[1])).find(".pic")!=std::string::npos)
00034 picheader = mitkIpPicGetHeader(argv[1], NULL);
00035 }
00036 if(picheader==NULL)
00037 {
00038 std::cout<<"file not found/not a pic-file - test not applied [PASSED]"<<std::endl;
00039 std::cout<<"[TEST DONE]"<<std::endl;
00040 return EXIT_SUCCESS;
00041 }
00042 mitkIpPicGetTags(argv[1], picheader);
00043
00044
00045 mitk::PicFileReader::Pointer reader = mitk::PicFileReader::New();
00046 reader->SetFileName(argv[1]);
00047 reader->Update();
00048
00049 std::cout << "Testing IsInitialized(): ";
00050 if(reader->GetOutput()->IsInitialized()==false)
00051 {
00052 std::cout<<"[FAILED]"<<std::endl;
00053 return EXIT_FAILURE;
00054 }
00055 std::cout<<"[PASSED]"<<std::endl;
00056
00057 std::cout << "Testing IsSliceSet(): ";
00058 if(reader->GetOutput()->IsSliceSet(0)==false)
00059 {
00060 std::cout<<"[FAILED]"<<std::endl;
00061 return EXIT_FAILURE;
00062 }
00063 std::cout<<"[PASSED]"<<std::endl;
00064
00065 std::cout << "Testing availability of geometry: ";
00066 if(reader->GetOutput()->GetGeometry()==NULL)
00067 {
00068 std::cout<<"[FAILED]"<<std::endl;
00069 return EXIT_FAILURE;
00070 }
00071 std::cout<<"[PASSED]"<<std::endl;
00072
00073 std::cout << "Testing type of geometry (TimeSlicedGeometry expected): ";
00074 mitk::TimeSlicedGeometry* timegeometry;
00075 timegeometry = reader->GetOutput()->GetTimeSlicedGeometry();
00076 if(timegeometry==NULL)
00077 {
00078 std::cout<<"[FAILED]"<<std::endl;
00079 return EXIT_FAILURE;
00080 }
00081 std::cout<<"[PASSED]"<<std::endl;
00082
00083 std::cout << "Testing availability of first geometry contained in the TimeSlicedGeometry: ";
00084 if(timegeometry->GetGeometry3D(0)==NULL)
00085 {
00086 std::cout<<"[FAILED]"<<std::endl;
00087 return EXIT_FAILURE;
00088 }
00089 std::cout<<"[PASSED]"<<std::endl;
00090
00091 std::cout << "Testing type of first geometry contained in the TimeSlicedGeometry (SlicedGeometry3D expected): ";
00092 mitk::SlicedGeometry3D* slicedgeometry;
00093 slicedgeometry = dynamic_cast<mitk::SlicedGeometry3D*>(timegeometry->GetGeometry3D(0));
00094 if(slicedgeometry==NULL)
00095 {
00096 std::cout<<"[FAILED]"<<std::endl;
00097 return EXIT_FAILURE;
00098 }
00099 std::cout<<"[PASSED]"<<std::endl;
00100
00101 std::cout << "Testing availability of first geometry contained in the SlicedGeometry3D: ";
00102 mitk::Geometry2D* geometry2d = slicedgeometry->GetGeometry2D(0);
00103 if(geometry2d==NULL)
00104 {
00105 std::cout<<"[FAILED]"<<std::endl;
00106 return EXIT_FAILURE;
00107 }
00108 std::cout<<"[PASSED]"<<std::endl;
00109
00110 std::cout << "Testing extent in units of first geometry contained in the SlicedGeometry3D: ";
00111 if((fabs(geometry2d->GetExtent(0)-picheader->n[0])>mitk::eps) || (fabs(geometry2d->GetExtent(1)-picheader->n[1])>mitk::eps))
00112 {
00113 std::cout<<"[FAILED]"<<std::endl;
00114 return EXIT_FAILURE;
00115 }
00116 std::cout<<"[PASSED]"<<std::endl;
00117
00118 std::cout << "Testing extent in units of image of SlicedGeometry3D: ";
00119 if((fabs(slicedgeometry->GetExtent(0)-picheader->n[0])>mitk::eps) || (fabs(slicedgeometry->GetExtent(1)-picheader->n[1])>mitk::eps)
00120 || (picheader->dim>2 && (fabs(slicedgeometry->GetExtent(2)-picheader->n[2])>mitk::eps))
00121 )
00122 {
00123 std::cout<<"[FAILED]"<<std::endl;
00124 return EXIT_FAILURE;
00125 }
00126 std::cout<<"[PASSED]"<<std::endl;
00127
00128 std::cout << "Testing extent in units of image of TimeSlicedGeometry: ";
00129 if((fabs(timegeometry->GetExtent(0)-picheader->n[0])>mitk::eps) || (fabs(timegeometry->GetExtent(1)-picheader->n[1])>mitk::eps)
00130 || (picheader->dim>2 && (fabs(timegeometry->GetExtent(2)-picheader->n[2])>mitk::eps))
00131 || (picheader->dim>3 && (abs((mitkIpInt4_t) timegeometry->GetTimeSteps()- (mitkIpInt4_t) picheader->n[3])>0))
00132 )
00133 {
00134 std::cout<<"[FAILED]"<<std::endl;
00135 return EXIT_FAILURE;
00136 }
00137 std::cout<<"[PASSED]"<<std::endl;
00138
00139 std::cout << "Testing consistency of spacing from matrix and stored spacing in the first SlicedGeometry3D: ";
00140 mitk::Vector3D spacing;
00141 spacing[0] = slicedgeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0).two_norm();
00142 spacing[1] = slicedgeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1).two_norm();
00143 spacing[2] = slicedgeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2).two_norm();
00144 mitk::Vector3D readspacing=slicedgeometry->GetSpacing();
00145 mitk::Vector3D dist = spacing-readspacing;
00146 if(dist.GetSquaredNorm()>mitk::eps)
00147 {
00148 std::cout<<"[FAILED]"<<std::endl;
00149 return EXIT_FAILURE;
00150 }
00151 std::cout<<"[PASSED]"<<std::endl;
00152
00153
00154 spacing.Fill(1);
00155 mitk::PicHelper::GetSpacing(picheader, spacing);
00156
00157 std::cout << "Testing correct reading of overall spacing stored in the first SlicedGeometry3D: ";
00158 dist = spacing-readspacing;
00159 if(dist.GetSquaredNorm()>mitk::eps)
00160 {
00161 std::cout<<"[FAILED]"<<std::endl;
00162 return EXIT_FAILURE;
00163 }
00164 std::cout<<"[PASSED]"<<std::endl;
00165
00166 if(picheader->dim==4)
00167 {
00168 std::cout << "4D dataset: Testing that timebounds are not infinite: ";
00169 if((slicedgeometry->GetTimeBounds()[0] == mitk::ScalarTypeNumericTraits::NonpositiveMin()) &&
00170 (slicedgeometry->GetTimeBounds()[1] == mitk::ScalarTypeNumericTraits::max())
00171 )
00172 {
00173 std::cout<<"[FAILED]"<<std::endl;
00174 return EXIT_FAILURE;
00175 }
00176 std::cout<<"[PASSED]"<<std::endl;
00177 }
00178
00179 mitkIpPicFree(picheader);
00180
00181 std::cout<<"[TEST DONE]"<<std::endl;
00182 return EXIT_SUCCESS;
00183 }