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 "mitkManualSegmentationToSurfaceFilter.h"
00020 #include <itksys/SystemTools.hxx>
00021 #include "mitkDataNodeFactory.h"
00022 #include <mitkSurfaceVtkWriter.h>
00023 #include <vtkSTLWriter.h>
00024
00025 #include <fstream>
00032 int mitkManualSegmentationToSurfaceFilterTest(int argc, char* argv[])
00033 {
00034
00035 if(argc==0)
00036 {
00037 std::cout<<"no file specified [FAILED]"<<std::endl;
00038 return EXIT_FAILURE;
00039 }
00040
00041 std::string path = argv[1];
00042 itksys::SystemTools::ConvertToUnixSlashes(path);
00043 std::string fileIn = path;
00044 std::string fileOut = "BallBinary30x30x30.stl";
00045
00046
00047 fileIn = itksys::SystemTools::ConvertToOutputPath(fileIn.c_str());
00048 fileOut = itksys::SystemTools::ConvertToOutputPath(fileOut.c_str());
00049 std::cout<<"Eingabe Datei: "<<fileIn<<std::endl;
00050 std::cout<<"Ausgabe Datei: "<<fileOut<<std::endl;
00051 mitk::Image::Pointer image = NULL;
00052 mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New();
00053 try
00054 {
00055 std::cout << "Loading file: "<<std::flush;
00056 factory->SetFileName( fileIn.c_str() );
00057 factory->Update();
00058
00059 if(factory->GetNumberOfOutputs()<1)
00060 {
00061 std::cout<<"file could not be loaded [FAILED]"<<std::endl;
00062 return EXIT_FAILURE;
00063 }
00064 mitk::DataNode::Pointer node = factory->GetOutput( 0 );
00065 image = dynamic_cast<mitk::Image*>(node->GetData());
00066 if(image.IsNull())
00067 {
00068 std::cout<<"file not an image - test will not be applied [PASSED]"<<std::endl;
00069 std::cout<<"[TEST DONE]"<<std::endl;
00070 return EXIT_SUCCESS;
00071 }
00072 }
00073 catch ( itk::ExceptionObject & ex )
00074 {
00075 std::cout << "Exception: " << ex << "[FAILED]" << std::endl;
00076 return EXIT_FAILURE;
00077 }
00078
00079
00080 mitk::ManualSegmentationToSurfaceFilter::Pointer filter;
00081 std::cout << "Instantiat mitk::ManualSegmentationToSurfaceFilter - implicit: mitk::ImageToSurface: ";
00082 filter = mitk::ManualSegmentationToSurfaceFilter::New();
00083
00084 if (filter.IsNull())
00085 {
00086 std::cout<<"[FAILED]"<<std::endl;
00087 return EXIT_FAILURE;
00088 }
00089 else {
00090 std::cout<<"[PASSED]"<<std::endl;
00091 }
00092
00093
00094
00095 mitk::SurfaceVtkWriter<vtkSTLWriter>::Pointer writer = mitk::SurfaceVtkWriter<vtkSTLWriter>::New();
00096 if (filter.IsNull())
00097 {
00098 std::cout<<"Instantiat SurfaceVtkWirter: [FAILED]"<<std::endl;
00099 return EXIT_FAILURE;
00100 }
00101 else {
00102 writer->GlobalWarningDisplayOn();
00103 writer->SetFileName(fileOut.c_str());
00104 writer->GetVtkWriter()->SetFileTypeToBinary();
00105
00106 }
00107
00108 std::cout << "Create surface with default settings: ";
00109 if (image->GetDimension()==3)
00110 {
00111 filter->SetInput(image);
00112 filter->Update();
00113 writer->SetInput(filter->GetOutput());
00114 writer->Write();
00115
00116 if( writer->GetNumberOfInputs() < 1 )
00117 {
00118 std::cout<<"[FAILED]"<<std::endl;
00119 writer->Delete();
00120 return EXIT_FAILURE;
00121 }
00122 else
00123 {
00124 std::cout<<"[PASSED]"<<std::endl;
00125 }
00126
00127 std::cout << "Create surface all optimised settings: ";
00128
00129 filter->MedianFilter3DOn();
00130 filter->SetGaussianStandardDeviation(1.5);
00131 filter->InterpolationOn();
00132 filter->UseGaussianImageSmoothOn();
00133 filter->SetThreshold( 1 );
00134 filter->SetDecimate( mitk::ImageToSurfaceFilter::DecimatePro );
00135 filter->SetTargetReduction(0.05f);
00136 filter->SmoothOn();
00137
00138 try
00139 {
00140 filter->Update();
00141 }
00142 catch( itk::ExceptionObject & err )
00143 {
00144 MITK_INFO << " ERROR!" << std::endl;
00145 MITK_ERROR << "ExceptionObject caught!" << std::endl;
00146 MITK_ERROR << err << std::endl;
00147 return EXIT_FAILURE;
00148 }
00149
00150 writer->SetInput( filter->GetOutput() );
00151 if( writer->GetNumberOfInputs() < 1 )
00152 {
00153 std::cout<<"[FAILED]"<<std::endl;
00154 return EXIT_FAILURE;
00155 }
00156 else
00157 {
00158 std::cout<<"[PASSED]"<<std::endl;
00159 try {
00160 writer->Write();
00161 }
00162 catch( itk::ExceptionObject e)
00163 {
00164 std::cout<<"caught exception: "<<e<<std::endl;
00165 }
00166 }
00167 }
00168 else
00169 {
00170 std::cout<<"Image not suitable for filter: Dimension!=3"<<std::endl;
00171 }
00172
00173 std::cout<<"[TEST DONE]"<<std::endl;
00174
00175
00176
00177 return EXIT_SUCCESS;
00178 }
00179
00180
00181