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