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 <mitkImageDataItem.h>
00021 #include <mitkImageCast.h>
00022
00023 #include <mitkBoundingObject.h>
00024 #include <mitkCuboid.h>
00025 #include <mitkBoundingObjectCutter.h>
00026
00027 #include <itkImage.h>
00028
00029 #include <fstream>
00030 #include <itkSmartPointerForwardReference.txx>
00031 #include <mitkDataNodeFactory.h>
00032
00033 #include <vtkImageData.h>
00034
00035 #include <mitkTestingMacros.h>
00036
00037
00038 int mitkBoundingObjectCutterTest(int , char* [])
00039 {
00040 MITK_TEST_BEGIN(mitkBoundingObjectCutterTest);
00041
00042
00043 mitk::Image::Pointer image;
00044 mitk::PixelType pt(typeid(int));
00045 unsigned int dim[]={100,100,20};
00046
00047 MITK_TEST_OUTPUT(<< "Creating Image as imput for cutting: ");
00048 image=mitk::Image::New();
00049 image->Initialize(mitk::PixelType(typeid(int)), 3, dim);
00050 int *p = (int*)image->GetData();
00051 unsigned int i;
00052 unsigned int size = dim[0]*dim[1]*dim[2];
00053 for(i=0; i<size; ++i, ++p)
00054 *p= (signed int)i;
00055 std::cout<<"[PASSED]"<<std::endl;
00056
00057 MITK_TEST_OUTPUT(<< "Testing mitk::BoundingObject::FitGeometry(image->GetGeometry()) with an mitk::Cuboid (sub-class of mitk::BoundingObject): ");
00058 mitk::Cuboid::Pointer cuboid = mitk::Cuboid::New();
00059 cuboid->FitGeometry(image->GetGeometry());
00060 std::cout<<"[PASSED]"<<std::endl;
00061
00062 MITK_TEST_OUTPUT(<< "Testing whether corners of the cuboid are identical to corners of the image: ");
00063 int c;
00064 for(c=0; c<6; ++c)
00065 {
00066 MITK_TEST_OUTPUT(<< " Testing GetCornerPoint(" << c << "): ");
00067 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetCornerPoint(c),cuboid->GetGeometry()->GetCornerPoint(c)), "");
00068 }
00069
00070 MITK_TEST_OUTPUT(<< "Testing whether diagonal^2 of fitted mitk::Cuboid is identical to diagonal^2 of image: ");
00071 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetDiagonalLength2(),cuboid->GetGeometry()->GetDiagonalLength2()), "");
00072
00073
00074 MITK_TEST_OUTPUT(<< "Testing mitk::BoundingObjectCutter: ");
00075 mitk::BoundingObjectCutter::Pointer boCutter = mitk::BoundingObjectCutter::New();
00076 boCutter->SetInput(image);
00077 boCutter->SetBoundingObject(cuboid);
00078 MITK_TEST_OUTPUT(<< " Testing mitk::BoundingObjectCutter::UpdateLargestPossibleRegion():: ");
00079 boCutter->UpdateLargestPossibleRegion();
00080 std::cout<<"[PASSED]"<<std::endl;
00081
00082 mitk::Image::Pointer cuttedImage = boCutter->GetOutput();
00083
00084 MITK_TEST_OUTPUT(<< " Testing whether origin of cutted image is identical to origin of original image: ");
00085 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetOrigin(),cuttedImage->GetGeometry()->GetOrigin()), "");
00086
00087 MITK_TEST_OUTPUT(<< " Testing whether spacing of cutted image is identical to spacing of original image: ");
00088 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetSpacing(),cuttedImage->GetGeometry()->GetSpacing()), "");
00089
00090 MITK_TEST_OUTPUT(<< " Testing whether center of cutted image is identical to center of original image: ");
00091 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetCenter(),cuttedImage->GetGeometry()->GetCenter()), "");
00092
00093 MITK_TEST_OUTPUT(<< " Testing whether diagonal^2 of cutted image is identical to diagonal^2 of original image: ");
00094 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetDiagonalLength2(),cuttedImage->GetGeometry()->GetDiagonalLength2()), "");
00095
00096 MITK_TEST_OUTPUT(<< " Testing whether corners of cutted image are identical to corners of original image: ");
00097 for(c=0; c<6; ++c)
00098 {
00099 MITK_TEST_OUTPUT(<< " Testing GetCornerPoint(" << c << "): ");
00100 MITK_TEST_CONDITION_REQUIRED( mitk::Equal(image->GetGeometry()->GetCornerPoint(c),cuttedImage->GetGeometry()->GetCornerPoint(c)), "");
00101 }
00102
00103 MITK_TEST_OUTPUT(<< " Testing whether pixel data of cutted image are identical to pixel data of original image: ");
00104 p = (int*)image->GetData();
00105 int *pCutted = (int*)cuttedImage->GetData();
00106 for(i=0; i<size; ++i, ++p, ++pCutted)
00107 {
00108 if(*p!=*pCutted)
00109 break;
00110 }
00111 MITK_TEST_CONDITION_REQUIRED(i==size, "");
00112
00113 MITK_TEST_OUTPUT(<< " Testing whether geometry of cutted image has ImageGeometry==true: ");
00114 MITK_TEST_CONDITION_REQUIRED(cuttedImage->GetGeometry()->GetImageGeometry(), "");
00115
00116 MITK_TEST_END();
00117
00118 return EXIT_SUCCESS;
00119 }
00120