30 #include <vnl/vnl_quaternion.h>
31 #include <vnl/vnl_quaternion.txx>
40 CPPUNIT_TEST_SUITE(mitkPlaneGeometryTestSuite);
52 MITK_TEST(TestLefthandedCoordinateSystem);
59 CPPUNIT_TEST_SUITE_END();
84 planegeometry->InitializeStandardPlane(right, bottom);
85 planegeometry->SetOrigin(origin);
86 planegeometry->SetSpacing(spacing);
89 void tearDown()
override {}
91 void TestInheritance()
95 CPPUNIT_ASSERT_MESSAGE(
"Planegeometry should not be castable to Geometry 3D", g3d.IsNull());
98 CPPUNIT_ASSERT_MESSAGE(
"Planegeometry should be castable to BaseGeometry", base.IsNotNull());
102 CPPUNIT_ASSERT_MESSAGE(
"Geometry3D should be castable to BaseGeometry", base.IsNotNull());
106 CPPUNIT_ASSERT_MESSAGE(
"SlicedGeometry3D should not be castable to Geometry3D", g3d.IsNull());
110 CPPUNIT_ASSERT_MESSAGE(
"AbstractTransformGeometry should be castable to PlaneGeometry", plane.IsNotNull());
114 CPPUNIT_ASSERT_MESSAGE(
"PlaneGeometry should not be castable to AbstractTransofrmGeometry", atg.IsNull());
117 void TestLefthandedCoordinateSystem()
139 mitk::AffineTransform3D::MatrixType matrix;
140 mitk::AffineTransform3D::MatrixType::InternalMatrixType &vnl_matrix = matrix.GetVnlMatrix();
142 vnl_matrix.set_column(0, right);
143 vnl_matrix.set_column(1, bottom);
144 vnl_matrix.set_column(2, normal);
147 assert(vnl_determinant(vnl_matrix) < 0.0);
149 transform->SetIdentity();
150 transform->SetMatrix(matrix);
152 planegeometry->InitializeStandardPlane(width, height, transform);
153 CPPUNIT_ASSERT_MESSAGE(
154 "Testing if IndexToWorldMatrix is correct after InitializeStandardPlane( width, height, transform ) ",
163 p_expectedResult[0] = 50.;
164 p_expectedResult[1] = 30.;
165 p_expectedResult[2] = 0.;
168 CPPUNIT_ASSERT_MESSAGE(
"Testing if IndexToWorld(a,b) function works correctly with lefthanded matrix ",
184 mitk::FillVector3D(down, 1.4012984643248170709237295832899161312802619418765e-45, 0, 0);
187 1.4713633875410579244699160624544119378442750389703e-43,
188 9.2806360452222355258639080851310540729807238879469e-32);
190 std::cout <<
"Testing InitializeStandardPlane(rightVector, downVector, spacing = NULL): " << std::endl;
191 CPPUNIT_ASSERT_NO_THROW(planegeometry->InitializeStandardPlane(right, down, &spacing));
233 void TestIntersectionPoint()
248 myPlaneGeometry->InitializePlane(origin, normal);
263 lineDirection[0] = pointP2[0] - pointP1[0];
264 lineDirection[1] = pointP2[1] - pointP1[1];
265 lineDirection[2] = pointP2[2] - pointP1[2];
269 myPlaneGeometry->IntersectionPoint(xingline, calcXingPoint);
283 lineDirection2[0] = pointP4[0] - pointP3[0];
284 lineDirection2[1] = pointP4[1] - pointP3[1];
285 lineDirection2[2] = pointP4[2] - pointP3[2];
289 myPlaneGeometry->IntersectionPoint(xingline2, calcXingPoint2);
292 CPPUNIT_ASSERT_MESSAGE(
"Failed to calculate Intersection Point", calcXingPoint == calcXingPoint2);
301 void TestProjectPointOntoPlane()
313 origin[0] = -27.582859;
315 origin[2] = 200.27742;
318 myPlaneGeometry->InitializePlane(origin, normal);
321 std::cout <<
"Testing PlaneGeometry according to bug #3409" << std::endl;
322 std::cout <<
"Our normal is: " << normal << std::endl;
323 std::cout <<
"So ALL projected points should have exactly the same z-value!" << std::endl;
327 myPoints[0][0] = -27.582859;
328 myPoints[0][1] = 50.00;
329 myPoints[0][2] = 200.27742;
331 myPoints[1][0] = -26.58662;
332 myPoints[1][1] = 50.00;
333 myPoints[1][2] = 200.19026;
335 myPoints[2][0] = -26.58662;
336 myPoints[2][1] = 50.00;
337 myPoints[2][2] = 200.33124;
339 myPoints[3][0] = 104.58662;
340 myPoints[3][1] = 452.12313;
341 myPoints[3][2] = 866.41236;
343 myPoints[4][0] = -207.58662;
344 myPoints[4][1] = 312.00;
345 myPoints[4][2] = -300.12346;
349 for (
unsigned int i = 0; i < 5; ++i)
351 myProjectedPoints[i] = myPlaneGeometry->ProjectPointOntoPlane(myPoints[i]);
355 bool allPointsOnPlane =
true;
356 for (
auto &myProjectedPoint : myProjectedPoints)
360 allPointsOnPlane =
false;
363 CPPUNIT_ASSERT_MESSAGE(
"All points lie not on the same plane", allPointsOnPlane);
366 void TestPlaneGeometryCloning()
373 itk::Matrix<mitk::ScalarType, 3, 3> matrix = clone->GetIndexToWorldTransform()->GetMatrix();
374 CPPUNIT_ASSERT_MESSAGE(
"Test if matrix element exists...", matrix[0][0] == 31);
376 double origin = geometry2D->GetOrigin()[0];
377 CPPUNIT_ASSERT_MESSAGE(
"First Point of origin as expected...",
mitk::Equal(origin, 8));
379 double spacing = geometry2D->GetSpacing()[0];
380 CPPUNIT_ASSERT_MESSAGE(
"First Point of spacing as expected...",
mitk::Equal(spacing, 31));
384 CPPUNIT_FAIL(
"Error during access on a member of cloned geometry");
387 MITK_TEST_OUTPUT(<<
"Casting a rotated 2D ITK Image to a MITK Image and check if Geometry is still same");
390 void TestPlaneGeometryInitializeOrder()
401 itk::Matrix<mitk::ScalarType, 3, 3> transMatrix;
403 transMatrix[0][0] = 1;
404 transMatrix[1][1] = 2;
405 transMatrix[2][2] = 4;
407 myTransform->SetMatrix(transMatrix);
410 geometry2D1->SetIndexToWorldTransform(myTransform);
411 geometry2D1->SetSpacing(mySpacing);
412 geometry2D1->SetOrigin(myOrigin);
415 geometry2D2->SetSpacing(mySpacing);
416 geometry2D2->SetOrigin(myOrigin);
417 geometry2D2->SetIndexToWorldTransform(myTransform);
420 geometry2D3->SetIndexToWorldTransform(myTransform);
421 geometry2D3->SetSpacing(mySpacing);
422 geometry2D3->SetOrigin(myOrigin);
423 geometry2D3->SetIndexToWorldTransform(myTransform);
425 CPPUNIT_ASSERT_MESSAGE(
"Origin of Geometry 1 matches that of Geometry 2.",
426 mitk::Equal(geometry2D1->GetOrigin(), geometry2D2->GetOrigin()));
427 CPPUNIT_ASSERT_MESSAGE(
"Origin of Geometry 1 match those of Geometry 3.",
428 mitk::Equal(geometry2D1->GetOrigin(), geometry2D3->GetOrigin()));
429 CPPUNIT_ASSERT_MESSAGE(
"Origin of Geometry 2 match those of Geometry 3.",
430 mitk::Equal(geometry2D2->GetOrigin(), geometry2D3->GetOrigin()));
432 CPPUNIT_ASSERT_MESSAGE(
"Spacing of Geometry 1 match those of Geometry 2.",
433 mitk::Equal(geometry2D1->GetSpacing(), geometry2D2->GetSpacing()));
434 CPPUNIT_ASSERT_MESSAGE(
"Spacing of Geometry 1 match those of Geometry 3.",
435 mitk::Equal(geometry2D1->GetSpacing(), geometry2D3->GetSpacing()));
436 CPPUNIT_ASSERT_MESSAGE(
"Spacing of Geometry 2 match those of Geometry 3.",
437 mitk::Equal(geometry2D2->GetSpacing(), geometry2D3->GetSpacing()));
439 CPPUNIT_ASSERT_MESSAGE(
"Transformation of Geometry 1 match those of Geometry 2.",
440 compareMatrix(geometry2D1->GetIndexToWorldTransform()->GetMatrix(),
441 geometry2D2->GetIndexToWorldTransform()->GetMatrix()));
442 CPPUNIT_ASSERT_MESSAGE(
"Transformation of Geometry 1 match those of Geometry 3.",
443 compareMatrix(geometry2D1->GetIndexToWorldTransform()->GetMatrix(),
444 geometry2D3->GetIndexToWorldTransform()->GetMatrix()));
445 CPPUNIT_ASSERT_MESSAGE(
"Transformation of Geometry 2 match those of Geometry 3.",
446 compareMatrix(geometry2D2->GetIndexToWorldTransform()->GetMatrix(),
447 geometry2D3->GetIndexToWorldTransform()->GetMatrix()));
450 void TestInitializeStandardPlane()
452 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: width",
454 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: height",
456 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: depth",
459 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: width in mm",
461 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: heght in mm",
463 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: depth in mm",
466 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: AxisVectorRight",
468 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: AxisVectorBottom",
470 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: AxisVectorNormal",
476 normal *= thicknessInMM;
478 planegeometry->InitializeStandardPlane(right.GetVnlVector(), bottom.GetVnlVector(), &spacing);
480 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: width",
482 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: height",
484 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: depth",
487 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: width in mm",
489 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: height in mm",
491 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: depth in mm",
494 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: AxisVectorRight",
496 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: AxisVectorBottom",
498 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: AxisVectorNormal",
504 void TestSetExtendInMM()
507 normal *= thicknessInMM;
508 planegeometry->SetExtentInMM(2, thicknessInMM);
509 CPPUNIT_ASSERT_MESSAGE(
"Testing SetExtentInMM(2, ...), querying by GetExtentInMM(2): ",
511 CPPUNIT_ASSERT_MESSAGE(
"Testing SetExtentInMM(2, ...), querying by GetAxisVector(2) and comparing to normal: ",
514 planegeometry->SetOrigin(origin);
515 CPPUNIT_ASSERT_MESSAGE(
"Testing SetOrigin",
mitk::Equal(planegeometry->GetOrigin(), origin,
testEps));
517 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() after SetOrigin: Right",
519 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() after SetOrigin: Bottom",
521 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() after SetOrigin: Normal",
524 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
531 mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;
532 vnlmatrix = planegeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix();
536 vnl_quaternion<mitk::ScalarType>
rotation(axis, 0.223);
537 vnlmatrix = rotation.rotation_matrix_transpose() * vnlmatrix;
540 transform->SetMatrix(matrix);
541 transform->SetOffset(planegeometry->GetIndexToWorldTransform()->GetOffset());
543 right.SetVnlVector(rotation.rotation_matrix_transpose() * right.GetVnlVector());
544 bottom.SetVnlVector(rotation.rotation_matrix_transpose() * bottom.GetVnlVector());
545 normal.SetVnlVector(rotation.rotation_matrix_transpose() * normal.GetVnlVector());
546 planegeometry->SetIndexToWorldTransform(transform);
552 planegeometry->SetOrigin(origin);
554 CPPUNIT_ASSERT_MESSAGE(
"Testing whether SetIndexToWorldTransform kept origin: ",
561 planegeometry->WorldToIndex(point, dummy);
562 planegeometry->IndexToWorld(dummy, dummy);
563 CPPUNIT_ASSERT_MESSAGE(
"Testing consistency of index and world coordinates.", dummy == point);
565 CPPUNIT_ASSERT_MESSAGE(
"Testing width of rotated version: ",
567 CPPUNIT_ASSERT_MESSAGE(
"Testing height of rotated version: ",
569 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness of rotated version: ",
572 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of rotated version: right ",
574 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of rotated version: bottom",
576 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of rotated version: normal",
579 CPPUNIT_ASSERT_MESSAGE(
580 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
581 mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(), planegeometry->GetExtentInMM(0),
testEps));
582 CPPUNIT_ASSERT_MESSAGE(
583 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
584 mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(), planegeometry->GetExtentInMM(1),
testEps));
585 CPPUNIT_ASSERT_MESSAGE(
586 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
587 mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(), planegeometry->GetExtentInMM(2),
testEps));
589 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
593 planegeometry->SetSizeInUnits(width, height);
594 CPPUNIT_ASSERT_MESSAGE(
"Testing SetSizeInUnits() of rotated version: ",
596 CPPUNIT_ASSERT_MESSAGE(
"Testing SetSizeInUnits() of rotated version: ",
598 CPPUNIT_ASSERT_MESSAGE(
"Testing SetSizeInUnits() of rotated version: ",
601 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of version with changed size in units: ",
603 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of version with changed size in units: ",
605 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of version with changed size in units: ",
608 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of version with changed size in units: right ",
610 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of version with changed size in units: bottom",
612 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of version with changed size in units: normal",
615 CPPUNIT_ASSERT_MESSAGE(
616 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
617 mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(), planegeometry->GetExtentInMM(0),
testEps));
618 CPPUNIT_ASSERT_MESSAGE(
619 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
620 mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(), planegeometry->GetExtentInMM(1),
testEps));
621 CPPUNIT_ASSERT_MESSAGE(
622 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
623 mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(), planegeometry->GetExtentInMM(2),
testEps));
625 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
633 CPPUNIT_ASSERT_MESSAGE(
"Testing Clone(): ",
634 !((clonedplanegeometry.IsNull()) || (clonedplanegeometry->GetReferenceCount() != 1)));
635 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of cloned version: ",
638 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in units) of cloned version: ",
640 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in units) of cloned version: ",
642 CPPUNIT_ASSERT_MESSAGE(
"Testing extent (in units) of cloned version: ",
645 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of cloned version: ",
647 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of cloned version: ",
649 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of cloned version: ",
652 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of cloned version: right",
654 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of cloned version: bottom",
656 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of cloned version: normal",
659 mappingTests2D(clonedplanegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
662 void TestSaggitalInitialization()
664 mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);
674 newthicknessInMM = widthInMM / width * 1.0;
676 newnormal.Normalize();
677 newnormal *= newthicknessInMM;
679 newbottom.Normalize();
680 newbottom *= thicknessInMM;
682 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of sagitally initialized version:",
686 origin = planegeometry->GetOrigin();
688 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of sagitally initialized version: ",
690 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of sagitally initialized version: ",
692 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of sagitally initialized version: ",
695 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of sagitally initialized version: ",
697 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of sagitally initialized version: ",
699 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of sagitally initialized version: ",
702 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of sagitally initialized version: ",
704 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of sagitally initialized version: ",
706 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of sagitally initialized version: ",
709 mappingTests2D(planegeometry, height, 1, heightInMM, thicknessInMM, origin, newright, newbottom);
712 origin = clonedplanegeometry->GetOrigin();
717 backsideorigin = origin + clonedplanegeometry->GetAxisVector(1);
719 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of backsidedly, axially initialized version: ",
723 backsidecornerpoint0 =
724 cornerpoint0 + clonedplanegeometry->GetAxisVector(1);
725 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of sagitally initialized version: ",
728 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of backsidedly, axially initialized version "
729 "(should be same as in mm due to unit spacing, except for thickness, which is always 1): ",
731 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of backsidedly, axially initialized version "
732 "(should be same as in mm due to unit spacing, except for thickness, which is always 1): ",
734 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of backsidedly, axially initialized version "
735 "(should be same as in mm due to unit spacing, except for thickness, which is always 1): ",
738 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of backsidedly, axially initialized version: ",
740 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of backsidedly, axially initialized version: ",
742 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of backsidedly, axially initialized version: ",
745 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of backsidedly, axially initialized version: ",
747 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of backsidedly, axially initialized version: ",
749 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of backsidedly, axially initialized version: ",
752 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, backsideorigin, right, -bottom);
755 void TestFrontalInitialization()
757 mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);
770 newbottom.Normalize();
771 newbottom *= thicknessInMM;
772 newthicknessInMM = heightInMM / height * 1.0 ;
774 newnormal.Normalize();
775 newnormal *= newthicknessInMM;
777 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of frontally initialized version: ",
781 origin = planegeometry->GetOrigin();
783 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in units) of frontally initialized version: ",
785 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in units) of frontally initialized version: ",
787 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in units) of frontally initialized version: ",
790 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of frontally initialized version: ",
792 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of frontally initialized version: ",
794 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of frontally initialized version: ",
797 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of frontally initialized version: ",
799 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of frontally initialized version: ",
801 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of frontally initialized version: ",
804 mappingTests2D(planegeometry, width, 1, widthInMM, thicknessInMM, origin, newright, newbottom);
807 planegeometry->SetSizeInUnits(planegeometry->GetExtentInMM(0), planegeometry->GetExtentInMM(1));
809 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of unit spaced, frontally initialized version: ",
812 CPPUNIT_ASSERT_MESSAGE(
813 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
815 CPPUNIT_ASSERT_MESSAGE(
816 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
818 CPPUNIT_ASSERT_MESSAGE(
819 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
822 CPPUNIT_ASSERT_MESSAGE(
823 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
825 CPPUNIT_ASSERT_MESSAGE(
826 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
828 CPPUNIT_ASSERT_MESSAGE(
829 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
832 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
834 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
836 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
839 mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom);
842 planegeometry->SetExtentInMM(2, 1.0);
843 newnormal.Normalize();
845 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of unit spaced, frontally initialized version: ",
848 CPPUNIT_ASSERT_MESSAGE(
849 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
851 CPPUNIT_ASSERT_MESSAGE(
852 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
854 CPPUNIT_ASSERT_MESSAGE(
855 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
858 CPPUNIT_ASSERT_MESSAGE(
859 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
861 CPPUNIT_ASSERT_MESSAGE(
862 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
864 CPPUNIT_ASSERT_MESSAGE(
865 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
868 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
870 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
872 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
874 mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom);
877 void TestAxialInitialization()
879 mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);
885 CPPUNIT_ASSERT_MESSAGE(
"Testing Clone(): ",
886 !((clonedplanegeometry.IsNull()) || (clonedplanegeometry->GetReferenceCount() != 1)));
888 std::cout <<
"Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Axial, zPosition = 0, "
891 planegeometry->InitializeStandardPlane(clonedplanegeometry);
893 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of axially initialized version: ",
896 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of axially initialized version: ",
897 mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0));
899 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in units) of axially initialized version (should be same as in mm due to "
900 "unit spacing, except for thickness, which is always 1): ",
902 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in units) of axially initialized version (should be same as in mm due to "
903 "unit spacing, except for thickness, which is always 1): ",
905 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in units) of axially initialized version (should be same as in mm due "
906 "to unit spacing, except for thickness, which is always 1): ",
909 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of axially initialized version: ",
911 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of axially initialized version: ",
913 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of axially initialized version: ",
916 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of axially initialized version: ",
918 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of axially initialized version: ",
920 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of axially initialized version: ",
923 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
926 void TestPlaneComparison()
932 CPPUNIT_ASSERT_MESSAGE(
"Testing Clone(): ",
933 !((clonedplanegeometry2.IsNull()) || (clonedplanegeometry2->GetReferenceCount() != 1)));
934 CPPUNIT_ASSERT_MESSAGE(
"Testing wheter original and clone are at the same position",
935 clonedplanegeometry2->IsOnPlane(planegeometry.GetPointer()));
936 CPPUNIT_ASSERT_MESSAGE(
" Asserting that origin is on the plane cloned plane:",
937 clonedplanegeometry2->IsOnPlane(origin));
942 vnl_quaternion<mitk::ScalarType> rotation2(newaxis, 0.0);
945 mitk::Point3D clonedorigin = clonedplanegeometry2->GetOrigin();
949 clonedplanegeometry2->ExecuteOperation(planerot);
950 CPPUNIT_ASSERT_MESSAGE(
" Asserting that a flipped plane is still on the original plane: ",
951 clonedplanegeometry2->IsOnPlane(planegeometry.GetPointer()));
953 clonedorigin += clonednormal;
954 clonedplanegeometry2->SetOrigin(clonedorigin);
956 CPPUNIT_ASSERT_MESSAGE(
"Testing if the translated (cloned, flipped) plane is parallel to its origin plane: ",
957 clonedplanegeometry2->IsParallel(planegeometry));
961 clonedplanegeometry2->ExecuteOperation(planerot);
963 CPPUNIT_ASSERT_MESSAGE(
"Testing if a non-paralell plane gets recognized as not paralell [rotation +0.5 degree] : ",
964 !clonedplanegeometry2->IsParallel(planegeometry));
968 clonedplanegeometry2->ExecuteOperation(planerot);
970 CPPUNIT_ASSERT_MESSAGE(
"Testing if a non-paralell plane gets recognized as not paralell [rotation -0.5 degree] : ",
971 !clonedplanegeometry2->IsParallel(planegeometry));
975 clonedplanegeometry2->ExecuteOperation(planerot);
977 CPPUNIT_ASSERT_MESSAGE(
"Testing if a non-paralell plane gets recognized as paralell [rotation 360 degree] : ",
978 clonedplanegeometry2->IsParallel(planegeometry));
995 itk::Matrix<mitk::ScalarType, 3, 3> transMatrix;
997 transMatrix[0][0] = 1;
998 transMatrix[1][1] = 2;
999 transMatrix[2][2] = 4;
1001 myTransform->SetMatrix(transMatrix);
1004 geometry2D->SetIndexToWorldTransform(myTransform);
1005 geometry2D->SetSpacing(mySpacing);
1006 geometry2D->SetOrigin(myOrigin);
1010 bool compareMatrix(itk::Matrix<mitk::ScalarType, 3, 3> left, itk::Matrix<mitk::ScalarType, 3, 3> right)
1013 for (
int i = 0; i < 3; ++i)
1014 for (
int j = 0; j < 3; ++j)
1031 std::cout <<
"Testing mapping Map(pt2d_mm(x=widthInMM/2.3,y=heightInMM/2.5), pt3d_mm) and compare with expected: ";
1034 pt2d_mm[0] = widthInMM / 2.3;
1035 pt2d_mm[1] = heightInMM / 2.5;
1036 expected_pt3d_mm = origin + right * (pt2d_mm[0] / right.GetNorm()) + bottom * (pt2d_mm[1] / bottom.GetNorm());
1037 planegeometry->
Map(pt2d_mm, pt3d_mm);
1038 CPPUNIT_ASSERT_MESSAGE(
1039 "Testing mapping Map(pt2d_mm(x=widthInMM/2.3,y=heightInMM/2.5), pt3d_mm) and compare with expected",
1042 std::cout <<
"Testing mapping Map(pt3d_mm, pt2d_mm) and compare with expected: ";
1044 planegeometry->
Map(pt3d_mm, testpt2d_mm);
1045 std::cout << std::setprecision(12) <<
"Expected pt2d_mm " << pt2d_mm << std::endl;
1046 std::cout << std::setprecision(12) <<
"Result testpt2d_mm " << testpt2d_mm << std::endl;
1047 std::cout << std::setprecision(12) <<
"10*mitk::eps " << 10 *
mitk::eps << std::endl;
1049 CPPUNIT_ASSERT_MESSAGE(
"Testing mapping Map(pt3d_mm, pt2d_mm) and compare with expected",
1052 std::cout <<
"Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ";
1054 pt2d_units[0] = width / 2.0;
1055 pt2d_units[1] = height / 2.0;
1056 pt2d_mm[0] = widthInMM / 2.0;
1057 pt2d_mm[1] = heightInMM / 2.0;
1059 std::cout << std::setprecision(12) <<
"Expected pt2d_mm " << pt2d_mm << std::endl;
1060 std::cout << std::setprecision(12) <<
"Result testpt2d_mm " << testpt2d_mm << std::endl;
1061 std::cout << std::setprecision(12) <<
"10*mitk::eps " << 10 *
mitk::eps << std::endl;
1063 CPPUNIT_ASSERT_MESSAGE(
"Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ",
1066 std::cout <<
"Testing WorldToIndex(pt2d_mm, pt2d_units) and compare with expected: ";
1070 std::cout << std::setprecision(12) <<
"Expected pt2d_units " << pt2d_units << std::endl;
1071 std::cout << std::setprecision(12) <<
"Result testpt2d_units " << testpt2d_units << std::endl;
1072 std::cout << std::setprecision(12) <<
"10*mitk::eps " << 10 *
mitk::eps << std::endl;
1074 CPPUNIT_ASSERT_MESSAGE(
"Testing WorldToIndex(pt2d_mm, pt2d_units) and compare with expected:",
itk::SmartPointer< Self > Pointer
Standard implementation of BaseGeometry.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
bool MatrixEqualElementWise(const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix1, const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix2, mitk::ScalarType epsilon=mitk::eps)
Check for element-wise matrix equality with a user defined accuracy.
virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 2D point in mm (pt2d_m...
vnl_vector< ScalarType > VnlVector
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Constants for most interaction classes, due to the generic StateMachines.
virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const
virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
itk::SmartPointer< Self > Pointer
#define MITK_TEST_OUTPUT(x)
Output some text.
static void clone(T *&dst, S *src, int n)
Test fixture for parameterized tests.
static mitk::PlaneGeometry::Pointer createPlaneGeometry()
static const mitk::ScalarType testEps
MITKCORE_EXPORT const ScalarType sqrteps
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
MITKCORE_EXPORT const ScalarType eps
Describes a two-dimensional, rectangular plane.
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
BaseGeometry Describes the geometry of a data object.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.