00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkImage.h"
00020 #include "mitkPlaneGeometry.h"
00021 #include "mitkTimeSlicedGeometry.h"
00022 #include "mitkSlicedGeometry3D.h"
00023
00024 #include <vnl/vnl_quaternion.h>
00025 #include <vnl/vnl_quaternion.txx>
00026
00027 #include <fstream>
00028
00029 int mitkSlicedGeometry3DTest(int , char* [])
00030 {
00031 mitk::PlaneGeometry::Pointer planegeometry1 = mitk::PlaneGeometry::New();
00032
00033 mitk::Point3D origin;
00034 mitk::Vector3D right, bottom, normal;
00035 mitk::ScalarType width, height;
00036 mitk::ScalarType widthInMM, heightInMM, thicknessInMM;
00037
00038 width = 100; widthInMM = width;
00039 height = 200; heightInMM = height;
00040 thicknessInMM = 3.5;
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 mitk::FillVector3D(normal, 0, 0, thicknessInMM);
00045
00046 std::cout << "Initializing planegeometry1 by InitializeStandardPlane(rightVector, downVector, spacing = NULL): "<<std::endl;
00047 planegeometry1->InitializeStandardPlane(right.Get_vnl_vector(), bottom.Get_vnl_vector());
00048
00049 std::cout << "Setting planegeometry2 to a cloned version of planegeometry1: "<<std::endl;
00050 mitk::PlaneGeometry::Pointer planegeometry2;
00051 planegeometry2 = dynamic_cast<mitk::PlaneGeometry*>(planegeometry1->Clone().GetPointer());;
00052
00053 std::cout << "Changing the IndexToWorldTransform of planegeometry2 to a rotated version by SetIndexToWorldTransform() (keep origin): "<<std::endl;
00054 mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New();
00055 mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;
00056 vnlmatrix = planegeometry2->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix();
00057 mitk::VnlVector axis(3);
00058 mitk::FillVector3D(axis, 1.0, 1.0, 1.0); axis.normalize();
00059 vnl_quaternion<mitk::ScalarType> rotation(axis, 0.123);
00060 vnlmatrix = rotation.rotation_matrix_transpose()*vnlmatrix;
00061 mitk::Matrix3D matrix;
00062 matrix = vnlmatrix;
00063 transform->SetMatrix(matrix);
00064 transform->SetOffset(planegeometry2->GetIndexToWorldTransform()->GetOffset());
00065
00066 right.Set_vnl_vector( rotation.rotation_matrix_transpose()*right.Get_vnl_vector() );
00067 bottom.Set_vnl_vector(rotation.rotation_matrix_transpose()*bottom.Get_vnl_vector());
00068 normal.Set_vnl_vector(rotation.rotation_matrix_transpose()*normal.Get_vnl_vector());
00069 planegeometry2->SetIndexToWorldTransform(transform);
00070
00071
00072 std::cout << "Setting planegeometry3 to the backside of planegeometry2: " <<std::endl;
00073 mitk::PlaneGeometry::Pointer planegeometry3 = mitk::PlaneGeometry::New();
00074 planegeometry3->InitializeStandardPlane(planegeometry2, mitk::PlaneGeometry::Transversal, 0, false);
00075
00076
00077 std::cout << "Testing SlicedGeometry3D::InitializeEvenlySpaced(planegeometry3, zSpacing = 1, slices = 5, flipped = false): " <<std::endl;
00078 mitk::SlicedGeometry3D::Pointer slicedWorldGeometry=mitk::SlicedGeometry3D::New();
00079 unsigned int numSlices = 5;
00080 slicedWorldGeometry->InitializeEvenlySpaced(planegeometry3, 1, numSlices, false);
00081
00082 std::cout << "Testing availability and type (PlaneGeometry) of first geometry in the SlicedGeometry3D: ";
00083 mitk::PlaneGeometry* accessedplanegeometry3 = dynamic_cast<mitk::PlaneGeometry*>(slicedWorldGeometry->GetGeometry2D(0));
00084 if(accessedplanegeometry3==NULL)
00085 {
00086 std::cout<<"[FAILED]"<<std::endl;
00087 return EXIT_FAILURE;
00088 }
00089 std::cout<<"[PASSED]"<<std::endl;
00090
00091 std::cout << "Testing whether the first geometry in the SlicedGeometry3D is identical to planegeometry3 by axis comparison and origin: "<<std::endl;
00092 if((mitk::Equal(accessedplanegeometry3->GetAxisVector(0), planegeometry3->GetAxisVector(0))==false) ||
00093 (mitk::Equal(accessedplanegeometry3->GetAxisVector(1), planegeometry3->GetAxisVector(1))==false) ||
00094 (mitk::Equal(accessedplanegeometry3->GetAxisVector(2), planegeometry3->GetAxisVector(2))==false) ||
00095 (mitk::Equal(accessedplanegeometry3->GetOrigin(), planegeometry3->GetOrigin())==false))
00096 {
00097 std::cout<<"[FAILED]"<<std::endl;
00098 return EXIT_FAILURE;
00099 }
00100 std::cout<<"[PASSED]"<<std::endl;
00101
00102 std::cout << "Testing availability and type (PlaneGeometry) of the last geometry in the SlicedGeometry3D: ";
00103 mitk::PlaneGeometry* accessedplanegeometry3last = dynamic_cast<mitk::PlaneGeometry*>(slicedWorldGeometry->GetGeometry2D(numSlices-1));
00104 mitk::Point3D origin3last; origin3last = planegeometry3->GetOrigin()+slicedWorldGeometry->GetDirectionVector()*(numSlices-1);
00105 if(accessedplanegeometry3last==NULL)
00106 {
00107 std::cout<<"[FAILED]"<<std::endl;
00108 return EXIT_FAILURE;
00109 }
00110 std::cout<<"[PASSED]"<<std::endl;
00111
00112 std::cout << "Testing whether the last geometry in the SlicedGeometry3D is identical to planegeometry3 by axis comparison: "<<std::endl;
00113 if((mitk::Equal(accessedplanegeometry3last->GetAxisVector(0), planegeometry3->GetAxisVector(0))==false) ||
00114 (mitk::Equal(accessedplanegeometry3last->GetAxisVector(1), planegeometry3->GetAxisVector(1))==false) ||
00115 (mitk::Equal(accessedplanegeometry3last->GetAxisVector(2), planegeometry3->GetAxisVector(2))==false) ||
00116 (mitk::Equal(accessedplanegeometry3last->GetOrigin(), origin3last)==false) ||
00117 (mitk::Equal(accessedplanegeometry3last->GetIndexToWorldTransform()->GetOffset(), origin3last.GetVectorFromOrigin())==false))
00118 {
00119 std::cout<<"[FAILED]"<<std::endl;
00120 return EXIT_FAILURE;
00121 }
00122 std::cout<<"[PASSED]"<<std::endl;
00123
00124 std::cout << "Again for first slice - Testing availability and type (PlaneGeometry) of first geometry in the SlicedGeometry3D: ";
00125 accessedplanegeometry3 = dynamic_cast<mitk::PlaneGeometry*>(slicedWorldGeometry->GetGeometry2D(0));
00126 if(accessedplanegeometry3==NULL)
00127 {
00128 std::cout<<"[FAILED]"<<std::endl;
00129 return EXIT_FAILURE;
00130 }
00131 std::cout<<"[PASSED]"<<std::endl;
00132
00133 std::cout << "Again for first slice - Testing whether the first geometry in the SlicedGeometry3D is identical to planegeometry3 by axis comparison and origin: "<<std::endl;
00134 if((mitk::Equal(accessedplanegeometry3->GetAxisVector(0), planegeometry3->GetAxisVector(0))==false) ||
00135 (mitk::Equal(accessedplanegeometry3->GetAxisVector(1), planegeometry3->GetAxisVector(1))==false) ||
00136 (mitk::Equal(accessedplanegeometry3->GetAxisVector(2), planegeometry3->GetAxisVector(2))==false) ||
00137 (mitk::Equal(accessedplanegeometry3->GetOrigin(), planegeometry3->GetOrigin())==false) ||
00138 (mitk::Equal(accessedplanegeometry3->GetIndexToWorldTransform()->GetOffset(), planegeometry3->GetOrigin().GetVectorFromOrigin())==false))
00139 {
00140 std::cout<<"[FAILED]"<<std::endl;
00141 return EXIT_FAILURE;
00142 }
00143 std::cout<<"[PASSED]"<<std::endl;
00144
00145
00146 std::cout<<"[TEST DONE]"<<std::endl;
00147 return EXIT_SUCCESS;
00148 }