00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkImage.h"
00020 #include "mitkExternAbstractTransformGeometry.h"
00021 #include "mitkPlaneGeometry.h"
00022 #include "mitkTimeSlicedGeometry.h"
00023 #include "mitkSlicedGeometry3D.h"
00024
00025 #include <vtkSphericalTransform.h>
00026
00027 #include <fstream>
00028
00029 int mitkAbstractTransformGeometryTest(int , char* [])
00030 {
00031 mitk::Point3D origin;
00032 mitk::Vector3D right, bottom;
00033 mitk::ScalarType width, height;
00034 mitk::ScalarType widthInMM, heightInMM;
00035
00036 std::cout << "Initializing an x-/y-plane (xyPlane) as parameter plane by InitializeStandardPlane(rightVector, downVector, spacing = NULL): "<<std::endl;
00037 mitk::PlaneGeometry::Pointer xyPlane = mitk::PlaneGeometry::New();
00038 width = 100; widthInMM = width;
00039 height = 200; heightInMM = height;
00040 mitk::ScalarType bounds[6] = {0, width, 0, height, 0, 1};
00041 mitk::FillVector3D(origin, 4.5, 7.3, 11.2);
00042 mitk::FillVector3D(right, widthInMM, 0, 0);
00043 mitk::FillVector3D(bottom, 0, heightInMM, 0);
00044 xyPlane->InitializeStandardPlane(right, bottom);
00045 xyPlane->SetOrigin(origin);
00046 xyPlane->SetSizeInUnits(width, height);
00047
00048 std::cout << "Creating AbstractTransformGeometry: " <<std::endl;
00049 mitk::ExternAbstractTransformGeometry::Pointer abstractgeometry=mitk::ExternAbstractTransformGeometry::New();
00050
00051 std::cout << "Setting xyPlane as parameter plane of AbstractTransformGeometry: "<<std::endl;
00052 abstractgeometry->SetPlane(xyPlane);
00053
00054 std::cout << "Testing whether the bounds of xyPlane and the parametric bounds of AbstractTransformGeometry are equal: ";
00055 if((mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(), const_cast<mitk::BoundingBox*>(xyPlane->GetBoundingBox())->GetMinimum())==false) ||
00056 (mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(), const_cast<mitk::BoundingBox*>(xyPlane->GetBoundingBox())->GetMaximum())==false))
00057 {
00058 std::cout<<"[FAILED]"<<std::endl;
00059 return EXIT_FAILURE;
00060 }
00061 std::cout<<"[PASSED]"<<std::endl;
00062
00063 std::cout << "Testing whether the parametic bounds of AbstractTransformGeometry and the bounds of the plane accessed from there are equal: ";
00064 if((mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum())==false) ||
00065 (mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum())==false))
00066 {
00067 std::cout<<"[FAILED]"<<std::endl;
00068 return EXIT_FAILURE;
00069 }
00070 std::cout<<"[PASSED]"<<std::endl;
00071
00072 std::cout << "Change parametic bounds of AbstractTransformGeometry and test whether they are equal to the bounds of the plane accessed from there: "<<std::endl;
00073 height = 300;
00074 bounds[3] = height;
00075 abstractgeometry->SetParametricBounds(bounds);
00076 if((mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum())==false) ||
00077 (mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum())==false))
00078 {
00079 std::cout<<"[FAILED]"<<std::endl;
00080 return EXIT_FAILURE;
00081 }
00082 std::cout<<"[PASSED]"<<std::endl;
00083
00084
00085
00086 std::cout << "Initializing an phi-/theta-plane (sphereParameterPlane) as parameter plane by InitializeStandardPlane(rightVector, downVector, spacing = NULL): "<<std::endl;
00087 mitk::PlaneGeometry::Pointer sphereParameterPlane = mitk::PlaneGeometry::New();
00088 width = 100; widthInMM = 2*vnl_math::pi;
00089 height = 200; heightInMM = vnl_math::pi;
00090 mitk::ScalarType radiusInMM = 2.5;
00091
00092 mitk::FillVector3D(origin, radiusInMM, 0, widthInMM);
00093 mitk::FillVector3D(right, 0, 0, -widthInMM);
00094 mitk::FillVector3D(bottom, 0, heightInMM, 0);
00095 sphereParameterPlane->InitializeStandardPlane(right, bottom);
00096 sphereParameterPlane->SetOrigin(origin);
00097 sphereParameterPlane->SetSizeInUnits(width, height);
00098
00099 std::cout << "Creating an vtkSphericalTransform (sphericalTransform) to use with sphereParameterPlane: "<<std::endl;
00100 vtkSphericalTransform* sphericalTransform = vtkSphericalTransform::New();
00101
00102 std::cout << "Setting sphereParameterPlane as parameter plane and sphericalTransform as transform of AbstractTransformGeometry: "<<std::endl;
00103 abstractgeometry->SetPlane(sphereParameterPlane);
00104 abstractgeometry->SetVtkAbstractTransform(sphericalTransform);
00105
00106 std::cout << "Testing whether the bounds of sphereParameterPlane and the parametric bounds of AbstractTransformGeometry are equal: ";
00107 if((mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(), const_cast<mitk::BoundingBox*>(sphereParameterPlane->GetBoundingBox())->GetMinimum())==false) ||
00108 (mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(), const_cast<mitk::BoundingBox*>(sphereParameterPlane->GetBoundingBox())->GetMaximum())==false))
00109 {
00110 std::cout<<"[FAILED]"<<std::endl;
00111 return EXIT_FAILURE;
00112 }
00113 std::cout<<"[PASSED]"<<std::endl;
00114
00115 std::cout << "Testing whether the parametic bounds of AbstractTransformGeometry and the bounds of the plane accessed from there are equal: ";
00116 if((mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum())==false) ||
00117 (mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum())==false))
00118 {
00119 std::cout<<"[FAILED]"<<std::endl;
00120 return EXIT_FAILURE;
00121 }
00122 std::cout<<"[PASSED]"<<std::endl;
00123
00124 std::cout << "Testing mapping Map(pt2d_mm(phi=Pi,theta=Pi/2.0), pt3d_mm) and compare with expected (-radius, 0, 0): ";
00125 mitk::Point2D pt2d_mm;
00126 mitk::Point3D pt3d_mm, expected_pt3d_mm;
00127 pt2d_mm[0] = vnl_math::pi; pt2d_mm[1] = vnl_math::pi_over_2;
00128 mitk::FillVector3D(expected_pt3d_mm, -radiusInMM, 0, 0);
00129 abstractgeometry->Map(pt2d_mm, pt3d_mm);
00130 if(mitk::Equal(pt3d_mm, expected_pt3d_mm) == false)
00131 {
00132 std::cout<<"[FAILED]"<<std::endl;
00133 return EXIT_FAILURE;
00134 }
00135 std::cout<<"[PASSED]"<<std::endl;
00136
00137 std::cout << "Testing mapping Map(pt3d_mm, pt2d_mm) and compare with expected: ";
00138 mitk::Point2D testpt2d_mm;
00139 abstractgeometry->Map(pt3d_mm, testpt2d_mm);
00140 if(mitk::Equal(pt2d_mm, testpt2d_mm) == false)
00141 {
00142 std::cout<<"[FAILED]"<<std::endl;
00143 return EXIT_FAILURE;
00144 }
00145 std::cout<<"[PASSED]"<<std::endl;
00146
00147 std::cout << "Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ";
00148 mitk::Point2D pt2d_units;
00149 pt2d_units[0] = width/2.0; pt2d_units[1] = height/2.0;
00150 pt2d_mm[0] = widthInMM/2.0; pt2d_mm[1] = heightInMM/2.0;
00151 abstractgeometry->IndexToWorld(pt2d_units, testpt2d_mm);
00152 if(mitk::Equal(pt2d_mm, testpt2d_mm) == false)
00153 {
00154 std::cout<<"[FAILED]"<<std::endl;
00155 return EXIT_FAILURE;
00156 }
00157 std::cout<<"[PASSED]"<<std::endl;
00158
00159 std::cout << "Change parametic bounds of AbstractTransformGeometry and test whether they are equal to the bounds of the plane accessed from there: "<<std::endl;
00160 height = 300;
00161 bounds[3] = height;
00162 abstractgeometry->SetParametricBounds(bounds);
00163 if((mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMinimum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMinimum())==false) ||
00164 (mitk::Equal(const_cast<mitk::BoundingBox*>(abstractgeometry->GetParametricBoundingBox())->GetMaximum(), const_cast<mitk::BoundingBox*>(abstractgeometry->GetPlane()->GetBoundingBox())->GetMaximum())==false))
00165 {
00166 std::cout<<"[FAILED]"<<std::endl;
00167 return EXIT_FAILURE;
00168 }
00169 std::cout<<"[PASSED]"<<std::endl;
00170
00171 std::cout << "Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ";
00172 pt2d_units[0] = width/2.0; pt2d_units[1] = height/2.0;
00173 pt2d_mm[0] = widthInMM/2.0; pt2d_mm[1] = heightInMM/2.0;
00174 abstractgeometry->IndexToWorld(pt2d_units, testpt2d_mm);
00175 if(mitk::Equal(pt2d_mm, testpt2d_mm) == false)
00176 {
00177 std::cout<<"[FAILED]"<<std::endl;
00178 return EXIT_FAILURE;
00179 }
00180 std::cout<<"[PASSED]"<<std::endl;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 sphericalTransform->Delete();
00203
00204 std::cout<<"[TEST DONE]"<<std::endl;
00205 return EXIT_SUCCESS;
00206 }