26 #include <vnl/vnl_quaternion.h> 27 #include <vnl/vnl_quaternion.hxx> 38 CPPUNIT_TEST_SUITE(mitkPlaneGeometryTestSuite);
50 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 TestDominantAxesError()
120 auto matrix =
image->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().transpose();
122 CPPUNIT_ASSERT_MESSAGE(
"Domiant axes cannot be determined in this dataset. Output should be default ordering.", axes.at(0)==0 && axes.at(1)==1 && axes.at(2)==2);
125 void TestCheckRotationMatrix()
129 CPPUNIT_ASSERT_MESSAGE(
"Since the test data matrix is not quite a rotation matrix, this should be detected.", !is_rotation);
132 void TestLefthandedCoordinateSystem()
152 mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New();
154 mitk::AffineTransform3D::MatrixType matrix;
155 mitk::AffineTransform3D::MatrixType::InternalMatrixType &vnl_matrix = matrix.GetVnlMatrix();
157 vnl_matrix.set_column(0, right);
158 vnl_matrix.set_column(1, bottom);
159 vnl_matrix.set_column(2, normal);
162 assert(vnl_determinant(vnl_matrix) < 0.0);
164 transform->SetIdentity();
165 transform->SetMatrix(matrix);
167 planegeometry->InitializeStandardPlane(width, height, transform);
168 CPPUNIT_ASSERT_MESSAGE(
169 "Testing if IndexToWorldMatrix is correct after InitializeStandardPlane( width, height, transform ) ",
178 p_expectedResult[0] = 50.;
179 p_expectedResult[1] = 30.;
180 p_expectedResult[2] = 0.;
183 CPPUNIT_ASSERT_MESSAGE(
"Testing if IndexToWorld(a,b) function works correctly with lefthanded matrix ",
199 mitk::FillVector3D(down, 1.4012984643248170709237295832899161312802619418765e-45, 0, 0);
202 1.4713633875410579244699160624544119378442750389703e-43,
203 9.2806360452222355258639080851310540729807238879469e-32);
205 std::cout <<
"Testing InitializeStandardPlane(rightVector, downVector, spacing = nullptr): " << std::endl;
206 CPPUNIT_ASSERT_NO_THROW(planegeometry->InitializeStandardPlane(right, down, &spacing));
248 void TestIntersectionPoint()
263 myPlaneGeometry->InitializePlane(origin, normal);
278 lineDirection[0] = pointP2[0] - pointP1[0];
279 lineDirection[1] = pointP2[1] - pointP1[1];
280 lineDirection[2] = pointP2[2] - pointP1[2];
284 myPlaneGeometry->IntersectionPoint(xingline, calcXingPoint);
298 lineDirection2[0] = pointP4[0] - pointP3[0];
299 lineDirection2[1] = pointP4[1] - pointP3[1];
300 lineDirection2[2] = pointP4[2] - pointP3[2];
304 myPlaneGeometry->IntersectionPoint(xingline2, calcXingPoint2);
307 CPPUNIT_ASSERT_MESSAGE(
"Failed to calculate Intersection Point", calcXingPoint == calcXingPoint2);
316 void TestProjectPointOntoPlane()
328 origin[0] = -27.582859;
330 origin[2] = 200.27742;
333 myPlaneGeometry->InitializePlane(origin, normal);
336 std::cout <<
"Testing PlaneGeometry according to bug #3409" << std::endl;
337 std::cout <<
"Our normal is: " << normal << std::endl;
338 std::cout <<
"So ALL projected points should have exactly the same z-value!" << std::endl;
342 myPoints[0][0] = -27.582859;
343 myPoints[0][1] = 50.00;
344 myPoints[0][2] = 200.27742;
346 myPoints[1][0] = -26.58662;
347 myPoints[1][1] = 50.00;
348 myPoints[1][2] = 200.19026;
350 myPoints[2][0] = -26.58662;
351 myPoints[2][1] = 50.00;
352 myPoints[2][2] = 200.33124;
354 myPoints[3][0] = 104.58662;
355 myPoints[3][1] = 452.12313;
356 myPoints[3][2] = 866.41236;
358 myPoints[4][0] = -207.58662;
359 myPoints[4][1] = 312.00;
360 myPoints[4][2] = -300.12346;
364 for (
unsigned int i = 0; i < 5; ++i)
366 myProjectedPoints[i] = myPlaneGeometry->ProjectPointOntoPlane(myPoints[i]);
370 bool allPointsOnPlane =
true;
371 for (
auto &myProjectedPoint : myProjectedPoints)
375 allPointsOnPlane =
false;
378 CPPUNIT_ASSERT_MESSAGE(
"All points lie not on the same plane", allPointsOnPlane);
381 void TestPlaneGeometryCloning()
388 itk::Matrix<mitk::ScalarType, 3, 3> matrix = clone->GetIndexToWorldTransform()->GetMatrix();
389 CPPUNIT_ASSERT_MESSAGE(
"Test if matrix element exists...", matrix[0][0] == 31);
391 double origin = geometry2D->GetOrigin()[0];
392 CPPUNIT_ASSERT_MESSAGE(
"First Point of origin as expected...",
mitk::Equal(origin, 8));
394 double spacing = geometry2D->GetSpacing()[0];
395 CPPUNIT_ASSERT_MESSAGE(
"First Point of spacing as expected...",
mitk::Equal(spacing, 31));
399 CPPUNIT_FAIL(
"Error during access on a member of cloned geometry");
402 MITK_TEST_OUTPUT(<<
"Casting a rotated 2D ITK Image to a MITK Image and check if Geometry is still same");
405 void TestPlaneGeometryInitializeOrder()
415 mitk::AffineTransform3D::Pointer myTransform = mitk::AffineTransform3D::New();
416 itk::Matrix<mitk::ScalarType, 3, 3> transMatrix;
418 transMatrix[0][0] = 1;
419 transMatrix[1][1] = 2;
420 transMatrix[2][2] = 4;
422 myTransform->SetMatrix(transMatrix);
425 geometry2D1->SetIndexToWorldTransform(myTransform);
426 geometry2D1->SetSpacing(mySpacing);
427 geometry2D1->SetOrigin(myOrigin);
430 geometry2D2->SetSpacing(mySpacing);
431 geometry2D2->SetOrigin(myOrigin);
432 geometry2D2->SetIndexToWorldTransform(myTransform);
435 geometry2D3->SetIndexToWorldTransform(myTransform);
436 geometry2D3->SetSpacing(mySpacing);
437 geometry2D3->SetOrigin(myOrigin);
438 geometry2D3->SetIndexToWorldTransform(myTransform);
440 CPPUNIT_ASSERT_MESSAGE(
"Origin of Geometry 1 matches that of Geometry 2.",
441 mitk::Equal(geometry2D1->GetOrigin(), geometry2D2->GetOrigin()));
442 CPPUNIT_ASSERT_MESSAGE(
"Origin of Geometry 1 match those of Geometry 3.",
443 mitk::Equal(geometry2D1->GetOrigin(), geometry2D3->GetOrigin()));
444 CPPUNIT_ASSERT_MESSAGE(
"Origin of Geometry 2 match those of Geometry 3.",
445 mitk::Equal(geometry2D2->GetOrigin(), geometry2D3->GetOrigin()));
447 CPPUNIT_ASSERT_MESSAGE(
"Spacing of Geometry 1 match those of Geometry 2.",
448 mitk::Equal(geometry2D1->GetSpacing(), geometry2D2->GetSpacing()));
449 CPPUNIT_ASSERT_MESSAGE(
"Spacing of Geometry 1 match those of Geometry 3.",
450 mitk::Equal(geometry2D1->GetSpacing(), geometry2D3->GetSpacing()));
451 CPPUNIT_ASSERT_MESSAGE(
"Spacing of Geometry 2 match those of Geometry 3.",
452 mitk::Equal(geometry2D2->GetSpacing(), geometry2D3->GetSpacing()));
454 CPPUNIT_ASSERT_MESSAGE(
"Transformation of Geometry 1 match those of Geometry 2.",
455 compareMatrix(geometry2D1->GetIndexToWorldTransform()->GetMatrix(),
456 geometry2D2->GetIndexToWorldTransform()->GetMatrix()));
457 CPPUNIT_ASSERT_MESSAGE(
"Transformation of Geometry 1 match those of Geometry 3.",
458 compareMatrix(geometry2D1->GetIndexToWorldTransform()->GetMatrix(),
459 geometry2D3->GetIndexToWorldTransform()->GetMatrix()));
460 CPPUNIT_ASSERT_MESSAGE(
"Transformation of Geometry 2 match those of Geometry 3.",
461 compareMatrix(geometry2D2->GetIndexToWorldTransform()->GetMatrix(),
462 geometry2D3->GetIndexToWorldTransform()->GetMatrix()));
465 void TestInitializeStandardPlane()
467 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: width",
469 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: height",
471 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: depth",
474 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: width in mm",
476 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: heght in mm",
478 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: depth in mm",
481 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: AxisVectorRight",
483 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: AxisVectorBottom",
485 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with default Spacing: AxisVectorNormal",
491 normal *= thicknessInMM;
493 planegeometry->InitializeStandardPlane(right.GetVnlVector(), bottom.GetVnlVector(), &spacing);
495 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: width",
497 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: height",
499 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: depth",
502 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: width in mm",
504 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: height in mm",
506 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: depth in mm",
509 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: AxisVectorRight",
511 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: AxisVectorBottom",
513 CPPUNIT_ASSERT_MESSAGE(
"Testing correct Standard Plane initialization with custom Spacing: AxisVectorNormal",
519 void TestSetExtendInMM()
522 normal *= thicknessInMM;
523 planegeometry->SetExtentInMM(2, thicknessInMM);
524 CPPUNIT_ASSERT_MESSAGE(
"Testing SetExtentInMM(2, ...), querying by GetExtentInMM(2): ",
526 CPPUNIT_ASSERT_MESSAGE(
"Testing SetExtentInMM(2, ...), querying by GetAxisVector(2) and comparing to normal: ",
529 planegeometry->SetOrigin(origin);
530 CPPUNIT_ASSERT_MESSAGE(
"Testing SetOrigin",
mitk::Equal(planegeometry->GetOrigin(), origin,
testEps));
532 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() after SetOrigin: Right",
534 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() after SetOrigin: Bottom",
536 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() after SetOrigin: Normal",
539 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
545 mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New();
546 mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;
547 vnlmatrix = planegeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix();
551 vnl_quaternion<mitk::ScalarType>
rotation(axis, 0.223);
552 vnlmatrix = rotation.rotation_matrix_transpose() * vnlmatrix;
555 transform->SetMatrix(matrix);
556 transform->SetOffset(planegeometry->GetIndexToWorldTransform()->GetOffset());
558 right.SetVnlVector(rotation.rotation_matrix_transpose() * right.GetVnlVector());
559 bottom.SetVnlVector(rotation.rotation_matrix_transpose() * bottom.GetVnlVector());
560 normal.SetVnlVector(rotation.rotation_matrix_transpose() * normal.GetVnlVector());
561 planegeometry->SetIndexToWorldTransform(transform);
567 planegeometry->SetOrigin(origin);
569 CPPUNIT_ASSERT_MESSAGE(
"Testing whether SetIndexToWorldTransform kept origin: ",
576 planegeometry->WorldToIndex(point, dummy);
577 planegeometry->IndexToWorld(dummy, dummy);
578 CPPUNIT_ASSERT_MESSAGE(
"Testing consistency of index and world coordinates.", dummy == point);
580 CPPUNIT_ASSERT_MESSAGE(
"Testing width of rotated version: ",
582 CPPUNIT_ASSERT_MESSAGE(
"Testing height of rotated version: ",
584 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness of rotated version: ",
587 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of rotated version: right ",
589 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of rotated version: bottom",
591 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of rotated version: normal",
594 CPPUNIT_ASSERT_MESSAGE(
595 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
596 mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(), planegeometry->GetExtentInMM(0),
testEps));
597 CPPUNIT_ASSERT_MESSAGE(
598 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
599 mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(), planegeometry->GetExtentInMM(1),
testEps));
600 CPPUNIT_ASSERT_MESSAGE(
601 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
602 mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(), planegeometry->GetExtentInMM(2),
testEps));
604 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
608 planegeometry->SetSizeInUnits(width, height);
609 CPPUNIT_ASSERT_MESSAGE(
"Testing SetSizeInUnits() of rotated version: ",
611 CPPUNIT_ASSERT_MESSAGE(
"Testing SetSizeInUnits() of rotated version: ",
613 CPPUNIT_ASSERT_MESSAGE(
"Testing SetSizeInUnits() of rotated version: ",
616 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of version with changed size in units: ",
618 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of version with changed size in units: ",
620 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of version with changed size in units: ",
623 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of version with changed size in units: right ",
625 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of version with changed size in units: bottom",
627 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of version with changed size in units: normal",
630 CPPUNIT_ASSERT_MESSAGE(
631 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
632 mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(), planegeometry->GetExtentInMM(0),
testEps));
633 CPPUNIT_ASSERT_MESSAGE(
634 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
635 mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(), planegeometry->GetExtentInMM(1),
testEps));
636 CPPUNIT_ASSERT_MESSAGE(
637 "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ",
638 mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(), planegeometry->GetExtentInMM(2),
testEps));
640 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
648 CPPUNIT_ASSERT_MESSAGE(
"Testing Clone(): ",
649 !((clonedplanegeometry.IsNull()) || (clonedplanegeometry->GetReferenceCount() != 1)));
650 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of cloned version: ",
653 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in units) of cloned version: ",
655 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in units) of cloned version: ",
657 CPPUNIT_ASSERT_MESSAGE(
"Testing extent (in units) of cloned version: ",
660 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of cloned version: ",
662 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of cloned version: ",
664 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of cloned version: ",
667 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of cloned version: right",
669 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of cloned version: bottom",
671 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of cloned version: normal",
674 mappingTests2D(clonedplanegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
677 void TestSaggitalInitialization()
679 mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);
689 newthicknessInMM = widthInMM / width * 1.0;
691 newnormal.Normalize();
692 newnormal *= newthicknessInMM;
694 newbottom.Normalize();
695 newbottom *= thicknessInMM;
697 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of sagitally initialized version:",
701 origin = planegeometry->GetOrigin();
703 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of sagitally initialized version: ",
705 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of sagitally initialized version: ",
707 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of sagitally initialized version: ",
710 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of sagitally initialized version: ",
712 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of sagitally initialized version: ",
714 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of sagitally initialized version: ",
717 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of sagitally initialized version: ",
719 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of sagitally initialized version: ",
721 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of sagitally initialized version: ",
724 mappingTests2D(planegeometry, height, 1, heightInMM, thicknessInMM, origin, newright, newbottom);
727 origin = clonedplanegeometry->GetOrigin();
732 backsideorigin = origin + clonedplanegeometry->GetAxisVector(1);
734 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of backsidedly, axially initialized version: ",
738 backsidecornerpoint0 =
739 cornerpoint0 + clonedplanegeometry->GetAxisVector(1);
740 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of sagitally initialized version: ",
743 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of backsidedly, axially initialized version " 744 "(should be same as in mm due to unit spacing, except for thickness, which is always 1): ",
746 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of backsidedly, axially initialized version " 747 "(should be same as in mm due to unit spacing, except for thickness, which is always 1): ",
749 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in units) of backsidedly, axially initialized version " 750 "(should be same as in mm due to unit spacing, except for thickness, which is always 1): ",
753 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of backsidedly, axially initialized version: ",
755 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of backsidedly, axially initialized version: ",
757 CPPUNIT_ASSERT_MESSAGE(
"Testing width, height and thickness (in mm) of backsidedly, axially initialized version: ",
760 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of backsidedly, axially initialized version: ",
762 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of backsidedly, axially initialized version: ",
764 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of backsidedly, axially initialized version: ",
767 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, backsideorigin, right, -bottom);
770 void TestFrontalInitialization()
772 mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);
785 newbottom.Normalize();
786 newbottom *= thicknessInMM;
787 newthicknessInMM = heightInMM / height * 1.0 ;
789 newnormal.Normalize();
790 newnormal *= newthicknessInMM;
792 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of frontally initialized version: ",
796 origin = planegeometry->GetOrigin();
798 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in units) of frontally initialized version: ",
800 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in units) of frontally initialized version: ",
802 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in units) of frontally initialized version: ",
805 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of frontally initialized version: ",
807 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of frontally initialized version: ",
809 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of frontally initialized version: ",
812 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of frontally initialized version: ",
814 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of frontally initialized version: ",
816 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of frontally initialized version: ",
819 mappingTests2D(planegeometry, width, 1, widthInMM, thicknessInMM, origin, newright, newbottom);
822 planegeometry->SetSizeInUnits(planegeometry->GetExtentInMM(0), planegeometry->GetExtentInMM(1));
824 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of unit spaced, frontally initialized version: ",
827 CPPUNIT_ASSERT_MESSAGE(
828 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
830 CPPUNIT_ASSERT_MESSAGE(
831 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
833 CPPUNIT_ASSERT_MESSAGE(
834 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
837 CPPUNIT_ASSERT_MESSAGE(
838 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
840 CPPUNIT_ASSERT_MESSAGE(
841 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
843 CPPUNIT_ASSERT_MESSAGE(
844 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
847 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
849 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
851 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
854 mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom);
857 planegeometry->SetExtentInMM(2, 1.0);
858 newnormal.Normalize();
860 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of unit spaced, frontally initialized version: ",
863 CPPUNIT_ASSERT_MESSAGE(
864 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
866 CPPUNIT_ASSERT_MESSAGE(
867 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
869 CPPUNIT_ASSERT_MESSAGE(
870 "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ",
873 CPPUNIT_ASSERT_MESSAGE(
874 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
876 CPPUNIT_ASSERT_MESSAGE(
877 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
879 CPPUNIT_ASSERT_MESSAGE(
880 "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ",
883 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
885 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
887 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of unit spaced, frontally initialized version: ",
889 mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom);
892 void TestAxialInitialization()
894 mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);
900 CPPUNIT_ASSERT_MESSAGE(
"Testing Clone(): ",
901 !((clonedplanegeometry.IsNull()) || (clonedplanegeometry->GetReferenceCount() != 1)));
903 std::cout <<
"Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Axial, zPosition = 0, " 906 planegeometry->InitializeStandardPlane(clonedplanegeometry);
908 CPPUNIT_ASSERT_MESSAGE(
"Testing origin of axially initialized version: ",
911 CPPUNIT_ASSERT_MESSAGE(
"Testing GetCornerPoint(0) of axially initialized version: ",
912 mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0));
914 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in units) of axially initialized version (should be same as in mm due to " 915 "unit spacing, except for thickness, which is always 1): ",
917 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in units) of axially initialized version (should be same as in mm due to " 918 "unit spacing, except for thickness, which is always 1): ",
920 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in units) of axially initialized version (should be same as in mm due " 921 "to unit spacing, except for thickness, which is always 1): ",
924 CPPUNIT_ASSERT_MESSAGE(
"Testing width (in mm) of axially initialized version: ",
926 CPPUNIT_ASSERT_MESSAGE(
"Testing height (in mm) of axially initialized version: ",
928 CPPUNIT_ASSERT_MESSAGE(
"Testing thickness (in mm) of axially initialized version: ",
931 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of axially initialized version: ",
933 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of axially initialized version: ",
935 CPPUNIT_ASSERT_MESSAGE(
"Testing GetAxisVector() of axially initialized version: ",
938 mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
941 void TestPlaneComparison()
947 CPPUNIT_ASSERT_MESSAGE(
"Testing Clone(): ",
948 !((clonedplanegeometry2.IsNull()) || (clonedplanegeometry2->GetReferenceCount() != 1)));
949 CPPUNIT_ASSERT_MESSAGE(
"Testing wheter original and clone are at the same position",
950 clonedplanegeometry2->IsOnPlane(planegeometry.GetPointer()));
951 CPPUNIT_ASSERT_MESSAGE(
" Asserting that origin is on the plane cloned plane:",
952 clonedplanegeometry2->IsOnPlane(origin));
957 vnl_quaternion<mitk::ScalarType> rotation2(newaxis, 0.0);
960 mitk::Point3D clonedorigin = clonedplanegeometry2->GetOrigin();
964 clonedplanegeometry2->ExecuteOperation(planerot);
965 CPPUNIT_ASSERT_MESSAGE(
" Asserting that a flipped plane is still on the original plane: ",
966 clonedplanegeometry2->IsOnPlane(planegeometry.GetPointer()));
968 clonedorigin += clonednormal;
969 clonedplanegeometry2->SetOrigin(clonedorigin);
971 CPPUNIT_ASSERT_MESSAGE(
"Testing if the translated (cloned, flipped) plane is parallel to its origin plane: ",
972 clonedplanegeometry2->IsParallel(planegeometry));
976 clonedplanegeometry2->ExecuteOperation(planerot);
978 CPPUNIT_ASSERT_MESSAGE(
"Testing if a non-paralell plane gets recognized as not paralell [rotation +0.5 degree] : ",
979 !clonedplanegeometry2->IsParallel(planegeometry));
983 clonedplanegeometry2->ExecuteOperation(planerot);
985 CPPUNIT_ASSERT_MESSAGE(
"Testing if a non-paralell plane gets recognized as not paralell [rotation -0.5 degree] : ",
986 !clonedplanegeometry2->IsParallel(planegeometry));
990 clonedplanegeometry2->ExecuteOperation(planerot);
992 CPPUNIT_ASSERT_MESSAGE(
"Testing if a non-paralell plane gets recognized as paralell [rotation 360 degree] : ",
993 clonedplanegeometry2->IsParallel(planegeometry));
1009 mitk::AffineTransform3D::Pointer myTransform = mitk::AffineTransform3D::New();
1010 itk::Matrix<mitk::ScalarType, 3, 3> transMatrix;
1011 transMatrix.Fill(0);
1012 transMatrix[0][0] = 1;
1013 transMatrix[1][1] = 2;
1014 transMatrix[2][2] = 4;
1016 myTransform->SetMatrix(transMatrix);
1019 geometry2D->SetIndexToWorldTransform(myTransform);
1020 geometry2D->SetSpacing(mySpacing);
1021 geometry2D->SetOrigin(myOrigin);
1025 bool compareMatrix(itk::Matrix<mitk::ScalarType, 3, 3> left, itk::Matrix<mitk::ScalarType, 3, 3> right)
1028 for (
int i = 0; i < 3; ++i)
1029 for (
int j = 0; j < 3; ++j)
1046 std::cout <<
"Testing mapping Map(pt2d_mm(x=widthInMM/2.3,y=heightInMM/2.5), pt3d_mm) and compare with expected: ";
1049 pt2d_mm[0] = widthInMM / 2.3;
1050 pt2d_mm[1] = heightInMM / 2.5;
1051 expected_pt3d_mm = origin + right * (pt2d_mm[0] / right.GetNorm()) + bottom * (pt2d_mm[1] / bottom.GetNorm());
1052 planegeometry->
Map(pt2d_mm, pt3d_mm);
1053 CPPUNIT_ASSERT_MESSAGE(
1054 "Testing mapping Map(pt2d_mm(x=widthInMM/2.3,y=heightInMM/2.5), pt3d_mm) and compare with expected",
1057 std::cout <<
"Testing mapping Map(pt3d_mm, pt2d_mm) and compare with expected: ";
1059 planegeometry->
Map(pt3d_mm, testpt2d_mm);
1060 std::cout << std::setprecision(12) <<
"Expected pt2d_mm " << pt2d_mm << std::endl;
1061 std::cout << std::setprecision(12) <<
"Result testpt2d_mm " << testpt2d_mm << std::endl;
1062 std::cout << std::setprecision(12) <<
"10*mitk::eps " << 10 *
mitk::eps << std::endl;
1064 CPPUNIT_ASSERT_MESSAGE(
"Testing mapping Map(pt3d_mm, pt2d_mm) and compare with expected",
1067 std::cout <<
"Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ";
1069 pt2d_units[0] = width / 2.0;
1070 pt2d_units[1] = height / 2.0;
1071 pt2d_mm[0] = widthInMM / 2.0;
1072 pt2d_mm[1] = heightInMM / 2.0;
1074 std::cout << std::setprecision(12) <<
"Expected pt2d_mm " << pt2d_mm << std::endl;
1075 std::cout << std::setprecision(12) <<
"Result testpt2d_mm " << testpt2d_mm << std::endl;
1076 std::cout << std::setprecision(12) <<
"10*mitk::eps " << 10 *
mitk::eps << std::endl;
1078 CPPUNIT_ASSERT_MESSAGE(
"Testing IndexToWorld(pt2d_units, pt2d_mm) and compare with expected: ",
1081 std::cout <<
"Testing WorldToIndex(pt2d_mm, pt2d_units) and compare with expected: ";
1085 std::cout << std::setprecision(12) <<
"Expected pt2d_units " << pt2d_units << std::endl;
1086 std::cout << std::setprecision(12) <<
"Result testpt2d_units " << testpt2d_units << std::endl;
1087 std::cout << std::setprecision(12) <<
"10*mitk::eps " << 10 *
mitk::eps << std::endl;
1089 CPPUNIT_ASSERT_MESSAGE(
"Testing WorldToIndex(pt2d_mm, pt2d_units) and compare with expected:",
static std::vector< int > CalculateDominantAxes(mitk::AffineTransform3D::MatrixType::InternalMatrixType &rotation_matrix)
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.
vnl_vector< ScalarType > VnlVector
static bool CheckRotationMatrix(AffineTransform3D *transform, double epsilon=mitk::eps)
Check if matrix is a rotation matrix:
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
Constants for most interaction classes, due to the generic StateMachines.
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...
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
virtual void IndexToWorld(const Point2D &pt_units, Point2D &pt_mm) const
itk::SmartPointer< Self > Pointer
#define MITK_TEST_OUTPUT(x)
Output some text.
static void clone(T *&dst, S *src, int n)
virtual void WorldToIndex(const Point2D &pt_mm, Point2D &pt_units) const
Test fixture for parameterized tests.
static mitk::PlaneGeometry::Pointer createPlaneGeometry()
mitk::Image::Pointer image
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.