#if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include #include #include "itkEllipseBoundaryToImageFilter.h" //#define SAVEIMAGE int usage(void) { std::cout << "Testing"<< std::endl; std::cout << std::endl; return 1; } int itkEllipseBoundaryToImageFilterTest( ) { typedef itk::EllipseSpatialObject<3> EllipseType; EllipseType::Pointer ellipse = EllipseType::New(); ellipse->SetRadius(100); // Center the circle in the image EllipseType::TransformType::OffsetType offset; offset.Fill(125); ellipse->GetObjectToParentTransform()->SetOffset(offset); ellipse->ComputeObjectToWorldTransform(); EllipseType::Pointer ellipse1 = EllipseType::New(); ellipse1->SetRadius(15); // Center the circle in the image EllipseType::TransformType::OffsetType offset1; offset1.Fill(55); ellipse1->GetObjectToParentTransform()->SetOffset(offset1); ellipse1->ComputeObjectToWorldTransform(); typedef itk::Image ImageType; typedef itk::EllipseBoundaryToImageFilter<3,ImageType> EllipseBoundaryToImageFilterType; EllipseBoundaryToImageFilterType::Pointer imageFilter = EllipseBoundaryToImageFilterType::New(); imageFilter->SetInput(0, ellipse); imageFilter->SetInput(1, ellipse1); imageFilter->SetInsideValue(2); imageFilter->GetInsideValue(); imageFilter->SetOutsideValue(0); imageFilter->GetOutsideValue(); imageFilter->SetChildrenDepth(1); imageFilter->GetChildrenDepth(); ImageType::SizeType size; size[0]=250; size[1]=250; size[2]=250; imageFilter->SetSize(size); // Testing spacing std::cout << "Testing Spacing: "; float spacing_float[3]; double spacing_double[3]; for(unsigned int i=0;i<3;i++) { spacing_float[i]=1.0; spacing_double[i]=1.0; } imageFilter->SetSpacing(spacing_float); imageFilter->SetSpacing(spacing_double); const double* spacing_result = imageFilter->GetSpacing(); for(unsigned int i=0;i<3;i++) { if(spacing_result[i]!=1.0) { std::cout << "[FAILURE]" << std::endl; return EXIT_FAILURE; } } std::cout << "[PASSED]" << std::endl; // Testing Origin std::cout << "Testing Origin: "; float origin_float[3]; double origin_double[3]; for(unsigned int i=0;i<3;i++) { origin_float[i]=0.0; origin_double[i]=0.0; } imageFilter->SetOrigin(origin_float); imageFilter->SetOrigin(origin_double); const double* origin_result = imageFilter->GetOrigin(); for(unsigned int i=0;i<3;i++) { if(origin_result[i]!=0.0) { std::cout << "[FAILURE]" << std::endl; return EXIT_FAILURE; } } std::cout << "[PASSED]" << std::endl; // Testing PrintSelf std::cout << imageFilter << std::endl; //Update the filter imageFilter->Update(); ImageType::Pointer image = imageFilter->GetOutput(); std::cout << "Testing Output Image: "; #ifdef SAVEIMAGE typedef itk::ImageFileWriter< ImageType > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetInput( image ); writer -> UseCompressionOn ( ) ; writer->SetFileName("temp3.mhd"); writer->Update(); #endif ImageType::IndexType index; //The center should be outsidevalue index [ 0 ] = 125; index [ 1 ] = 125; index [ 2 ] = 125 ; if(image->GetPixel(index) == 2.0) { std::cout << "[FAILURE]" << std::endl; return EXIT_FAILURE; } index [ 0 ] = 190; index [ 1 ] = 111; index [ 2 ] = 199 ; //Test one boundary point if(image->GetPixel(index) != 2.0) { std::cout << "[FAILURE]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; index [ 0 ] = 55; index [ 1 ] = 55; index [ 2 ] = 55 ; if(image->GetPixel(index) == 2.0) { std::cout << "[FAILURE]" << std::endl; return EXIT_FAILURE; } index [ 0 ] = 62; index [ 1 ] = 62; index [ 2 ] = 45 ; //Test one boundary point if(image->GetPixel(index) != 2.0) { std::cout << "[FAILURE]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "[PASSED]" << std::endl; std::cout << "Test [DONE]" << std::endl; return EXIT_SUCCESS; } int main(int argc, char **argv) { return itkEllipseBoundaryToImageFilterTest ( ) ; }