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 <mitkDataNodeFactory.h>
00021 #include <mitkCylindricToCartesianFilter.h>
00022 #include <mitkImageSliceSelector.h>
00023 #include <itksys/SystemTools.hxx>
00024
00025 #include <fstream>
00026 int mitkImageSliceSelectorTest(int argc, char* argv[])
00027 {
00028 int slice_nr = 1;
00029 std::cout << "Loading file: ";
00030 if(argc==0)
00031 {
00032 std::cout<<"no file specified [FAILED]"<<std::endl;
00033 return EXIT_FAILURE;
00034 }
00035 mitk::Image::Pointer image = NULL;
00036 mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New();
00037 try
00038 {
00039 std::cout<<argv[1]<<std::endl;
00040 factory->SetFileName( argv[1] );
00041 factory->Update();
00042
00043 if(factory->GetNumberOfOutputs()<1)
00044 {
00045 std::cout<<"file could not be loaded [FAILED]"<<std::endl;
00046 return EXIT_FAILURE;
00047 }
00048 mitk::DataNode::Pointer node = factory->GetOutput( 0 );
00049 image = dynamic_cast<mitk::Image*>(node->GetData());
00050 if(image.IsNull())
00051 {
00052 std::cout<<"file not an image - test will not be applied [PASSED]"<<std::endl;
00053 std::cout<<"[TEST DONE]"<<std::endl;
00054 return EXIT_SUCCESS;
00055 }
00056 }
00057 catch ( itk::ExceptionObject & ex )
00058 {
00059 std::cout << "Exception: " << ex << "[FAILED]" << std::endl;
00060 return EXIT_FAILURE;
00061 }
00062
00063 if(image->GetDimension(2)<2)
00064 slice_nr = 0;
00065
00066
00067 mitk::ImageSliceSelector::Pointer slice = mitk::ImageSliceSelector::New();
00068 slice->SetInput(image);
00069 slice->SetSliceNr(slice_nr);
00070 slice->Update();
00071
00072 std::cout << "Testing IsInitialized(): ";
00073 if(slice->GetOutput()->IsInitialized()==false)
00074 {
00075 std::cout<<"[FAILED]"<<std::endl;
00076 return EXIT_FAILURE;
00077 }
00078 std::cout<<"[PASSED]"<<std::endl;
00079
00080 std::cout << "Testing IsSliceSet(): ";
00081 if(slice->GetOutput()->IsSliceSet(0)==false)
00082 {
00083 std::cout<<"[FAILED]"<<std::endl;
00084 return EXIT_FAILURE;
00085 }
00086 std::cout<<"[PASSED]"<<std::endl;
00087
00088 if(itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameExtension(argv[1])).find(".pic")!=std::string::npos)
00089 {
00090 std::cout << "Testing whether the slice is identical with a slice loaded by mitkIpPicGetSlice:";
00091 mitkIpPicDescriptor *picslice = mitkIpPicGetSlice(argv[1], NULL, (image->GetDimension(2)-1-slice_nr)+1);
00092 int i, size = _mitkIpPicSize(picslice);
00093 char * p1 = (char*)slice->GetPic()->data;
00094 char * p2 = (char*)picslice->data;
00095
00096
00097
00098 for(i=0; i<size; ++i, ++p1, ++p2)
00099 {
00100 if((*p1) != (*p2))
00101 {
00102 std::cout<<"[FAILED]"<<std::endl;
00103 return EXIT_FAILURE;
00104 }
00105 }
00106 std::cout<<"[PASSED]"<<std::endl;
00107 mitkIpPicFree(picslice);
00108 }
00109
00110 try
00111 {
00112 std::cout << "Testing another, smaller (!!) input with the same slice-selector(): ";
00113
00114 mitk::CylindricToCartesianFilter::Pointer cyl2cart = mitk::CylindricToCartesianFilter::New();
00115 cyl2cart->SetInput(image);
00116
00117 cyl2cart->SetTargetXSize( 64 );
00118
00119
00120
00121 slice->SetInput(cyl2cart->GetOutput());
00122 slice->SetSliceNr(1);
00123
00124
00125
00126
00127 slice->Update();
00128
00129
00130
00131 if(cyl2cart->GetOutput()->GetLargestPossibleRegion().GetSize()[0]!=64)
00132 {
00133 std::cout<<"Part 1 [FAILED]"<<std::endl;
00134 return EXIT_FAILURE;
00135 }
00136 std::cout<<"Part 1 (without exception) [PASSED] ";
00137
00138
00139 if((cyl2cart->GetOutput()->GetDimensions()[0]!=64) || (cyl2cart->GetOutput()->GetDimensions()[1]!=64))
00140 {
00141 std::cout<<"Part 1b [FAILED]"<<std::endl;
00142 return EXIT_FAILURE;
00143 }
00144 std::cout<<"Part 1b [PASSED] ";
00145 }
00146 catch ( itk::ExceptionObject &err)
00147 {
00148 std::cout<<"Part 1(with expected exception) ... seems to be not ITK 2.0.0 [PASSED]"<<std::endl;
00149 std::cout<<err<<std::endl;
00150
00151 slice->ResetPipeline();
00152 }
00153
00154 try
00155 {
00156 slice->UpdateLargestPossibleRegion();
00157 }
00158 catch ( itk::ExceptionObject )
00159 {
00160 std::cout<<"Part 2 [FAILED]"<<std::endl;
00161 return EXIT_FAILURE;
00162 }
00163 std::cout<<"Part 2 [PASSED]"<<std::endl;
00164
00165 std::cout << "Testing IsInitialized(): ";
00166 if(slice->GetOutput()->IsInitialized()==false)
00167 {
00168 std::cout<<"[FAILED]"<<std::endl;
00169 return EXIT_FAILURE;
00170 }
00171 std::cout<<"[PASSED]"<<std::endl;
00172
00173 std::cout << "Testing IsSliceSet(): ";
00174 if(slice->GetOutput()->IsSliceSet(0)==false)
00175 {
00176 std::cout<<"[FAILED]"<<std::endl;
00177 return EXIT_FAILURE;
00178 }
00179 std::cout<<"[PASSED]"<<std::endl;
00180
00181 if(image->GetDimension(3) > 1)
00182 {
00183 int time=image->GetDimension(3)-1;
00184
00185 std::cout << "Testing 3D+t: Setting time to " << time << ": ";
00186 slice->SetTimeNr(time);
00187 if(slice->GetTimeNr()!=time)
00188 {
00189 std::cout<<"[FAILED]"<<std::endl;
00190 return EXIT_FAILURE;
00191 }
00192 std::cout<<"[PASSED]"<<std::endl;
00193
00194 std::cout << "Testing 3D+t: Updating slice: ";
00195 slice->Update();
00196 if(slice->GetOutput()->IsInitialized()==false)
00197 {
00198 std::cout<<"[FAILED]"<<std::endl;
00199 return EXIT_FAILURE;
00200 }
00201 std::cout<<"[PASSED]"<<std::endl;
00202
00203 std::cout << "Testing 3D+t: IsSliceSet(): ";
00204 if(slice->GetOutput()->IsSliceSet(0)==false)
00205 {
00206 std::cout<<"[FAILED]"<<std::endl;
00207 return EXIT_FAILURE;
00208 }
00209 std::cout<<"[PASSED]"<<std::endl;
00210
00211 std::cout << "Testing 3D+t: First slice in reader available: ";
00212 if(image->IsSliceSet(0, time)==false)
00213 {
00214 std::cout<<"[FAILED]"<<std::endl;
00215 return EXIT_FAILURE;
00216 }
00217 std::cout<<"[PASSED]"<<std::endl;
00218 }
00219
00220 std::cout<<"[TEST DONE]"<<std::endl;
00221 return EXIT_SUCCESS;
00222 }