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 "mitkSurfaceToImageFilter.h"
00020 #include "mitkDataNodeFactory.h"
00021 #include "mitkPicFileWriter.h"
00022
00023 #include <vtkPolyData.h>
00024
00025 #include <fstream>
00026
00027 int mitkSurfaceToImageFilterTest(int argc, char* argv[])
00028 {
00029 mitk::SurfaceToImageFilter::Pointer s2iFilter;
00030 std::cout << "Testing mitk::Surface::New(): " << std::flush;
00031 s2iFilter = mitk::SurfaceToImageFilter::New();
00032 if (s2iFilter.IsNull())
00033 {
00034 std::cout<<"[FAILED]"<<std::endl;
00035 return EXIT_FAILURE;
00036 }
00037 else
00038 {
00039 std::cout<<"[PASSED]"<<std::endl;
00040 }
00041
00042 std::cout << "Loading file: " << std::flush;
00043 if(argc==0)
00044 {
00045 std::cout<<"no file specified [FAILED]"<<std::endl;
00046 return EXIT_FAILURE;
00047 }
00048 mitk::Surface::Pointer surface = NULL;
00049 mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New();
00050 try
00051 {
00052 std::cout<<argv[1]<<std::endl;
00053 factory->SetFileName( argv[1] );
00054 factory->Update();
00055
00056 if(factory->GetNumberOfOutputs()<1)
00057 {
00058 std::cout<<"file could not be loaded [FAILED]"<<std::endl;
00059 return EXIT_FAILURE;
00060 }
00061 mitk::DataNode::Pointer node = factory->GetOutput( 0 );
00062 surface = dynamic_cast<mitk::Surface*>(node->GetData());
00063 if(surface.IsNull())
00064 {
00065 std::cout<<"file not a surface - test will not be applied [PASSED]"<<std::endl;
00066 std::cout<<"[TEST DONE]"<<std::endl;
00067 return EXIT_SUCCESS;
00068 }
00069 }
00070 catch ( itk::ExceptionObject & ex )
00071 {
00072 std::cout << "Exception: " << ex << "[FAILED]" << std::endl;
00073 return EXIT_FAILURE;
00074 }
00075
00076 std::cout << "Testing number of points of surface: " << std::flush;
00077 if(surface->GetVtkPolyData()->GetNumberOfPoints() == 0)
00078 {
00079 std::cout<<"number of points is 0 - test will not be applied [PASSED]"<<std::endl;
00080 std::cout<<"[TEST DONE]"<<std::endl;
00081 return EXIT_SUCCESS;
00082 }
00083
00084 std::cout << "Testing creation of mitk::Image with same Geometry as Surface: " << std::flush;
00085 mitk::Image::Pointer image = mitk::Image::New();
00086
00087 image->Initialize(typeid(unsigned int), *surface->GetGeometry());
00088
00089 std::cout << "Testing mitk::SurfaceToImageFilter::MakeOutputBinaryOn(): " << std::flush;
00090 s2iFilter->MakeOutputBinaryOn();
00091 std::cout<<"[PASSED]"<<std::endl;
00092
00093 std::cout << "Testing mitk::SurfaceToImageFilter::SetInput(): " << std::flush;
00094 s2iFilter->SetInput(surface);
00095 std::cout<<"[PASSED]"<<std::endl;
00096
00097 std::cout << "Testing mitk::SurfaceToImageFilter::SetImage(): " << std::flush;
00098 s2iFilter->SetImage(image);
00099 std::cout<<"[PASSED]"<<std::endl;
00100
00101 std::cout << "Testing mitk::SurfaceToImageFilter::Update(): " << std::flush;
00102 s2iFilter->Update();
00103 std::cout<<"[PASSED]"<<std::endl;
00104
00105 #ifdef WIN32 // Unix based systems do not seem to resolve pixel type correctly
00106
00107 std::cout << "Testing if result image is of type unsigned char: " << std::flush;
00108 std::string typeId = s2iFilter->GetOutput()->GetPixelType().GetItkTypeAsString();
00109 std::cout << std::endl << "XXX: " << typeId << std::endl;
00110 if( typeId != "unsigned char" )
00111 {
00112 if(typeId != "unknown")
00113 return EXIT_FAILURE;
00114 else std::cout << "Warning: Pixel type can't be resolved." << std::flush;
00115 }
00116 std::cout<<"[PASSED]"<<std::endl;
00117
00118 #endif
00119
00120
00121
00122
00123
00124
00125 std::cout<<"[TEST DONE]"<<std::endl;
00126 return EXIT_SUCCESS;
00127 }