22 #include <itkAffineGeometryFrame.h> 23 #include <itkBoundingBox.h> 25 #include <itkQuaternionRigidTransform.h> 26 #include <itkScalableAffineTransform.h> 28 #include <vtkMatrix4x4.h> 29 #include <vtkMatrixToLinearTransform.h> 38 class vtkMatrixToLinearTransform;
39 class vtkLinearTransform;
41 typedef itk::BoundingBox<unsigned long, 3, mitk::ScalarType>
BoundingBox;
51 DummyTestClass(
const DummyTestClass &other) :
BaseGeometry(other){};
52 ~DummyTestClass()
override{};
61 newGeometry->UnRegister();
62 return newGeometry.GetPointer();
66 void PrintSelf(std::ostream & , itk::Indent )
const override{};
80 CPPUNIT_TEST_SUITE(mitkBaseGeometryTestSuite);
93 MITK_TEST(TestSetIndexToWorldTransformWithoutChangingSpacing);
94 MITK_TEST(TestSetIndexToWorldTransform_WithPointerToSameTransform);
97 MITK_TEST(TestSetIndexToWorldTransformByVtkMatrix);
101 MITK_TEST(Equal_CloneAndOriginal_ReturnsTrue);
102 MITK_TEST(Equal_DifferentOrigin_ReturnsFalse);
103 MITK_TEST(Equal_DifferentIndexToWorldTransform_ReturnsFalse);
104 MITK_TEST(Equal_DifferentSpacing_ReturnsFalse);
105 MITK_TEST(Equal_InputIsNull_ReturnsFalse);
106 MITK_TEST(Equal_DifferentBoundingBox_ReturnsFalse);
107 MITK_TEST(Equal_Transforms_MinorDifferences_And_Eps);
114 MITK_TEST(TestCalculateBoundingBoxRelToTransform);
126 CPPUNIT_TEST_SUITE_END();
131 float aFloatSpacing[3];
133 mitk::AffineTransform3D::Pointer aTransform;
135 mitk::AffineTransform3D::MatrixType aMatrix;
141 mitk::AffineTransform3D::Pointer anotherTransform;
142 mitk::AffineTransform3D::Pointer aThirdTransform;
143 mitk::AffineTransform3D::MatrixType anotherMatrix;
144 mitk::AffineTransform3D::MatrixType aThirdMatrix;
151 void setUp()
override 158 aTransform = mitk::AffineTransform3D::New();
159 aTransform->SetIdentity();
161 aMatrix.SetIdentity();
163 anotherTransform = mitk::AffineTransform3D::New();
165 anotherMatrix.SetIdentity();
166 anotherMatrix(1, 1) = 2;
167 anotherTransform->SetMatrix(anotherMatrix);
169 aThirdTransform = mitk::AffineTransform3D::New();
171 aThirdMatrix.SetIdentity();
172 aThirdMatrix(1, 1) = 7;
173 aThirdTransform->SetMatrix(aThirdMatrix);
176 float bounds[6] = {0, 1, 0, 1, 0, 1};
178 const float *input = bounds;
180 for (mitk::BoundingBox::BoundsArrayType::Iterator it = b.Begin(); j < 6; ++j)
183 aBoundingBox = BoundingBoxType::New();
185 BoundingBoxType::PointsContainer::Pointer pointscontainer = BoundingBoxType::PointsContainer::New();
186 BoundingBoxType::PointType p;
187 BoundingBoxType::PointIdentifier pointid;
188 for (pointid = 0; pointid < 2; ++pointid)
191 for (i = 0; i < 3; ++i)
193 p[i] = bounds[2 * i + pointid];
195 pointscontainer->InsertElement(pointid, p);
198 aBoundingBox->SetPoints(pointscontainer);
199 aBoundingBox->ComputeBoundingBox();
201 anotherBoundingBox = BoundingBoxType::New();
205 pointscontainer->InsertElement(1, p);
206 anotherBoundingBox->SetPoints(pointscontainer);
207 anotherBoundingBox->ComputeBoundingBox();
209 aThirdBoundingBox = BoundingBoxType::New();
213 pointscontainer->InsertElement(1, p);
214 aThirdBoundingBox->SetPoints(pointscontainer);
215 aThirdBoundingBox->ComputeBoundingBox();
220 aDummyGeometry = DummyTestClass::New();
221 aDummyGeometry->Initialize();
222 anotherDummyGeometry = aDummyGeometry->Clone();
225 void tearDown()
override 227 aDummyGeometry =
nullptr;
228 anotherDummyGeometry =
nullptr;
236 dummy->SetOrigin(anotherPoint);
237 CPPUNIT_ASSERT(
mitk::Equal(anotherPoint, dummy->GetOrigin()));
240 dummy->SetOrigin(aPoint);
245 void TestSetImageGeometry()
248 dummy->SetImageGeometry(
true);
249 CPPUNIT_ASSERT(dummy->GetImageGeometry());
252 dummy->SetImageGeometry(
false);
253 CPPUNIT_ASSERT(dummy->GetImageGeometry() ==
false);
258 void TestSetFloatBounds()
260 float bounds[6] = {0, 11, 0, 12, 0, 13};
262 dummy->SetFloatBounds(bounds);
263 MITK_ASSERT_EQUAL(BoundingBox::ConstPointer(dummy->GetBoundingBox()), anotherBoundingBox,
"BoundingBox equality");
267 dummy->SetFloatBounds(bounds);
269 BoundingBox::ConstPointer(dummy->GetBoundingBox()), anotherBoundingBox,
"BoundingBox not equal");
272 float originalBounds[6] = {0, 1, 0, 1, 0, 1};
273 dummy->SetFloatBounds(originalBounds);
281 dummy->SetBounds(anotherBoundingBox->GetBounds());
282 MITK_ASSERT_EQUAL(BoundingBox::ConstPointer(dummy->GetBoundingBox()), anotherBoundingBox,
"Setting bounds");
285 dummy->SetBounds(aThirdBoundingBox->GetBounds());
287 BoundingBox::ConstPointer(dummy->GetBoundingBox()), anotherBoundingBox,
"Setting unequal bounds");
290 dummy->SetBounds(aBoundingBox->GetBounds());
295 void TestSetFloatBoundsDouble()
297 double bounds[6] = {0, 11, 0, 12, 0, 13};
299 dummy->SetFloatBounds(bounds);
300 MITK_ASSERT_EQUAL(BoundingBox::ConstPointer(dummy->GetBoundingBox()), anotherBoundingBox,
"Float bounds");
304 dummy->SetFloatBounds(bounds);
306 BoundingBox::ConstPointer(dummy->GetBoundingBox()), anotherBoundingBox,
"Float bounds unequal");
309 double originalBounds[6] = {0, 1, 0, 1, 0, 1};
310 dummy->SetFloatBounds(originalBounds);
315 void TestSetFrameOfReferenceID()
318 dummy->SetFrameOfReferenceID(5);
319 CPPUNIT_ASSERT(dummy->GetFrameOfReferenceID() == 5);
322 dummy->SetFrameOfReferenceID(0);
327 void TestSetIndexToWorldTransform()
330 dummy->SetIndexToWorldTransform(anotherTransform);
332 mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
333 "Compare IndexToWorldTransform 1");
336 dummy->SetIndexToWorldTransform(aThirdTransform);
338 mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
339 "Compare IndexToWorldTransform 2");
342 dummy->SetIndexToWorldTransform(aTransform);
347 void TestSetIndexToWorldTransformWithoutChangingSpacing()
350 dummy->SetIndexToWorldTransformWithoutChangingSpacing(anotherTransform);
355 mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;
356 vnlmatrix = anotherTransform->GetMatrix().GetVnlMatrix();
359 col = vnlmatrix.get_column(0);
362 vnlmatrix.set_column(0, col);
363 col = vnlmatrix.get_column(1);
366 vnlmatrix.set_column(1, col);
367 col = vnlmatrix.get_column(2);
370 vnlmatrix.set_column(2, col);
374 anotherTransform->SetMatrix(matrix);
376 CPPUNIT_ASSERT(
mitk::Equal(anotherTransform, dummy->GetIndexToWorldTransform(),
mitk::eps,
true));
379 void TestSetIndexToWorldTransform_WithPointerToSameTransform()
383 dummy->SetOrigin(anotherPoint);
384 dummy->SetIndexToWorldTransform(anotherTransform);
385 dummy->SetSpacing(anotherSpacing);
387 mitk::AffineTransform3D::Pointer testTransfrom = dummy->GetIndexToWorldTransform();
389 mitk::Vector3D modifiedPoint = anotherPoint.GetVectorFromOrigin() * 2.;
391 testTransfrom->SetOffset(modifiedPoint);
393 dummy->SetIndexToWorldTransform(testTransfrom);
395 CPPUNIT_ASSERT(
mitk::Equal(modifiedPoint, dummy->GetOrigin().GetVectorFromOrigin()));
398 void TestSetIndexToWorldTransformByVtkMatrix()
400 vtkMatrix4x4 *vtkmatrix;
401 vtkmatrix = vtkMatrix4x4::New();
402 vtkmatrix->Identity();
403 vtkmatrix->SetElement(1, 1, 2);
405 dummy->SetIndexToWorldTransformByVtkMatrix(vtkmatrix);
407 mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
408 "Compare IndexToWorldTransformByVtkMatrix 1");
411 vtkmatrix->SetElement(1, 1, 7);
412 dummy->SetIndexToWorldTransformByVtkMatrix(vtkmatrix);
414 mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
415 "Compare IndexToWorldTransformByVtkMatrix 2");
418 vtkmatrix->SetElement(1, 1, 1);
419 dummy->SetIndexToWorldTransformByVtkMatrix(vtkmatrix);
422 MITK_ASSERT_EQUAL(dummy, newDummy,
"Compare IndexToWorldTransformByVtkMatrix 3");
425 void TestSetIdentity()
429 dummy->SetIndexToWorldTransform(anotherTransform);
430 dummy->SetOrigin(anotherPoint);
433 dummy->SetIdentity();
436 aTransform, mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
"Test set identity 1");
437 CPPUNIT_ASSERT(
mitk::Equal(aPoint, dummy->GetOrigin()));
438 CPPUNIT_ASSERT(
mitk::Equal(aSpacing, dummy->GetSpacing()));
445 void TestSetSpacing()
448 dummy->SetSpacing(anotherSpacing);
449 CPPUNIT_ASSERT(
mitk::Equal(anotherSpacing, dummy->GetSpacing()));
452 dummy->SetSpacing(aSpacing);
457 void TestTransferItkToVtkTransform()
460 dummy->SetIndexToWorldTransform(anotherTransform);
461 mitk::AffineTransform3D::Pointer dummyTransform = dummy->GetIndexToWorldTransform();
465 void TestConstructors()
469 bool test = dummy1->IsValid();
470 CPPUNIT_ASSERT(test ==
true);
471 CPPUNIT_ASSERT(dummy1->GetFrameOfReferenceID() == 0);
472 CPPUNIT_ASSERT(dummy1->GetIndexToWorldTransformLastModified() == 0);
474 CPPUNIT_ASSERT(
mitk::Equal(dummy1->GetSpacing(), aSpacing));
475 CPPUNIT_ASSERT(
mitk::Equal(dummy1->GetOrigin(), aPoint));
477 CPPUNIT_ASSERT(dummy1->GetImageGeometry() ==
false);
480 mitk::AffineTransform3D::Pointer(dummy1->GetIndexToWorldTransform()), aTransform,
"Contructor test 1");
483 mitk::BaseGeometry::BoundingBoxType::ConstPointer(dummy1->GetBoundingBox()), aBoundingBox,
"Constructor test 2");
486 dummy2->SetOrigin(anotherPoint);
487 float bounds[6] = {0, 11, 0, 12, 0, 13};
488 dummy2->SetFloatBounds(bounds);
489 dummy2->SetIndexToWorldTransform(anotherTransform);
490 dummy2->SetSpacing(anotherSpacing);
498 void Equal_CloneAndOriginal_ReturnsTrue() {
MITK_ASSERT_EQUAL(aDummyGeometry, anotherDummyGeometry,
"Clone test"); }
499 void Equal_DifferentOrigin_ReturnsFalse()
501 anotherDummyGeometry->SetOrigin(anotherPoint);
506 void Equal_DifferentIndexToWorldTransform_ReturnsFalse()
508 anotherDummyGeometry->SetIndexToWorldTransform(anotherTransform);
513 void Equal_DifferentSpacing_ReturnsFalse()
515 anotherDummyGeometry->SetSpacing(anotherSpacing);
520 void Equal_InputIsNull_ReturnsFalse()
526 void Equal_DifferentBoundingBox_ReturnsFalse()
530 anotherDummyGeometry->SetBounds(bounds);
535 void Equal_Transforms_MinorDifferences_And_Eps()
539 aMatrix.SetIdentity();
540 anotherMatrix.SetIdentity();
542 aMatrix(0, 1) = 0.0002;
543 aTransform->SetMatrix(aMatrix);
544 anotherMatrix(0, 1) = 0.0002;
545 anotherTransform->SetMatrix(anotherMatrix);
546 anotherTransform->SetMatrix(aMatrix);
547 CPPUNIT_ASSERT_MESSAGE(
"Exact same transforms are mitk::Equal() for eps=mitk::eps",
549 CPPUNIT_ASSERT_MESSAGE(
"Exact same transforms are mitk::Equal() for eps=vnl_math::eps",
552 anotherMatrix(0, 1) = 0.0002 +
mitk::eps;
553 anotherTransform->SetMatrix(anotherMatrix);
554 CPPUNIT_ASSERT_MESSAGE(
"Transforms of diff mitk::eps are !mitk::Equal() for eps=vnl_math::eps",
556 CPPUNIT_ASSERT_MESSAGE(
"Transforms of diff mitk::eps are !mitk::Equal() for eps=mitk::eps-1%",
558 CPPUNIT_ASSERT_MESSAGE(
"Transforms of diff mitk::eps _are_ mitk::Equal() for eps=mitk::eps+1%",
562 void TestComposeTransform()
565 mitk::AffineTransform3D::Pointer transform1;
566 transform1 = mitk::AffineTransform3D::New();
567 mitk::AffineTransform3D::MatrixType matrix1;
568 matrix1.SetIdentity();
570 transform1->SetMatrix(matrix1);
572 mitk::AffineTransform3D::Pointer transform2;
573 transform2 = mitk::AffineTransform3D::New();
574 mitk::AffineTransform3D::MatrixType matrix2;
575 matrix2.SetIdentity();
577 transform2->SetMatrix(matrix2);
579 mitk::AffineTransform3D::Pointer transform3;
580 transform3 = mitk::AffineTransform3D::New();
581 mitk::AffineTransform3D::MatrixType matrix3;
582 matrix3.SetIdentity();
584 transform3->SetMatrix(matrix3);
586 mitk::AffineTransform3D::Pointer transform4;
587 transform4 = mitk::AffineTransform3D::New();
588 mitk::AffineTransform3D::MatrixType matrix4;
589 matrix4.SetIdentity();
590 matrix4(1, 1) = 0.25;
591 transform4->SetMatrix(matrix4);
595 expectedSpacing.Fill(1.0);
596 expectedSpacing[1] = 4;
599 dummy->SetIndexToWorldTransform(transform1);
600 dummy->Compose(transform2);
601 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetSpacing(), expectedSpacing));
603 transform3, mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
"Compose transform 2");
606 dummy->Compose(transform4);
611 void TestComposeVtkMatrix()
614 mitk::AffineTransform3D::Pointer transform1;
615 transform1 = mitk::AffineTransform3D::New();
616 mitk::AffineTransform3D::MatrixType matrix1;
617 matrix1.SetIdentity();
619 transform1->SetMatrix(matrix1);
621 vtkMatrix4x4 *vtkmatrix2;
622 vtkmatrix2 = vtkMatrix4x4::New();
623 vtkmatrix2->Identity();
624 vtkmatrix2->SetElement(1, 1, 2);
626 mitk::AffineTransform3D::Pointer transform3;
627 transform3 = mitk::AffineTransform3D::New();
628 mitk::AffineTransform3D::MatrixType matrix3;
629 matrix3.SetIdentity();
631 transform3->SetMatrix(matrix3);
633 vtkMatrix4x4 *vtkmatrix4;
634 vtkmatrix4 = vtkMatrix4x4::New();
635 vtkmatrix4->Identity();
636 vtkmatrix4->SetElement(1, 1, 0.25);
640 expectedSpacing.Fill(1.0);
641 expectedSpacing[1] = 4;
644 dummy->SetIndexToWorldTransform(transform1);
645 dummy->Compose(vtkmatrix2);
646 vtkmatrix2->Delete();
649 transform3, mitk::AffineTransform3D::Pointer(dummy->GetIndexToWorldTransform()),
"Compose vtk matrix");
650 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetSpacing(), expectedSpacing));
653 dummy->Compose(vtkmatrix4);
654 vtkmatrix4->Delete();
662 dummy->SetOrigin(anotherPoint);
663 CPPUNIT_ASSERT(
mitk::Equal(anotherPoint, dummy->GetOrigin()));
667 translationVector.SetElement(0, 17.5f);
668 translationVector.SetElement(1, -32.3f);
669 translationVector.SetElement(2, 4.0f);
673 dummy->Translate(translationVector);
674 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetOrigin(), tmpResult));
677 translationVector *= -1;
678 dummy->Translate(translationVector);
679 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetOrigin(), anotherPoint));
682 translationVector.SetElement(0, -1 * anotherPoint[0]);
683 translationVector.SetElement(1, -1 * anotherPoint[1]);
684 translationVector.SetElement(2, -1 * anotherPoint[2]);
685 dummy->Translate(translationVector);
699 dummyGeometry->WorldToIndex(origin, dummyPoint);
700 dummyGeometry->IndexToWorld(dummyPoint, dummyPoint);
708 dummyGeometry->WorldToIndex(origin, originContinuousIndex);
713 dummyGeometry->WorldToIndex(origin, itkindex);
719 mitk::Vector3D halfSpacingStep = dummyGeometry->GetSpacing() * 0.5;
722 dummyGeometry->WorldToIndex(originOffCenter, itkindex);
726 originOffCenter = origin + halfSpacingStep;
727 originOffCenter -= 0.0001;
728 dummyGeometry->WorldToIndex(originOffCenter, itkindex);
732 originOffCenter = origin + halfSpacingStep;
735 dummyGeometry->WorldToIndex(originOffCenter, itkindex);
741 dummyGeometry->WorldToIndex(center, centerContIndex);
742 mitk::BoundingBox::ConstPointer boundingBox = dummyGeometry->GetBoundingBox();
743 mitk::BoundingBox::PointType centerBounds = boundingBox->GetCenter();
744 CPPUNIT_ASSERT(
mitk::Equal(centerContIndex, centerBounds));
747 center = dummyGeometry->GetCenter();
749 dummyGeometry->IndexToWorld(centerBounds, centerBoundsInWorldCoords);
750 CPPUNIT_ASSERT(
mitk::Equal(center, centerBoundsInWorldCoords));
758 dummyGeometry->WorldToIndex(point, dummyPoint);
759 dummyGeometry->IndexToWorld(dummyPoint, dummyPoint);
772 origin = dummyGeometry->GetOrigin();
773 p[0] = xAxisMM[0] + origin[0];
774 p[1] = xAxisMM[1] + origin[1];
775 p[2] = xAxisMM[2] + origin[2];
777 dummyGeometry->WorldToIndex(p, pIndex);
779 dummyGeometry->WorldToIndex(xAxisMM, xAxisContinuousIndex);
780 CPPUNIT_ASSERT(
mitk::Equal(xAxisContinuousIndex[0], pIndex[0]));
781 CPPUNIT_ASSERT(
mitk::Equal(xAxisContinuousIndex[1], pIndex[1]));
782 CPPUNIT_ASSERT(
mitk::Equal(xAxisContinuousIndex[2], pIndex[2]));
784 dummyGeometry->IndexToWorld(xAxisContinuousIndex, xAxisContinuousIndex);
786 dummyGeometry->IndexToWorld(pIndex, p);
788 CPPUNIT_ASSERT(xAxisContinuousIndex == xAxisMM);
789 CPPUNIT_ASSERT(
mitk::Equal(xAxisContinuousIndex[0], p[0] - origin[0]));
790 CPPUNIT_ASSERT(
mitk::Equal(xAxisContinuousIndex[1], p[1] - origin[1]));
791 CPPUNIT_ASSERT(
mitk::Equal(xAxisContinuousIndex[2], p[2] - origin[2]));
798 p[0] = vector[0] + origin[0];
799 p[1] = vector[1] + origin[1];
800 p[2] = vector[2] + origin[2];
802 dummyGeometry->WorldToIndex(p, pIndex);
804 dummyGeometry->WorldToIndex(vector, vectorContinuousIndex);
805 CPPUNIT_ASSERT(
mitk::Equal(vectorContinuousIndex[0], pIndex[0]));
806 CPPUNIT_ASSERT(
mitk::Equal(vectorContinuousIndex[1], pIndex[1]));
807 CPPUNIT_ASSERT(
mitk::Equal(vectorContinuousIndex[2], pIndex[2]));
809 dummyGeometry->IndexToWorld(vectorContinuousIndex, vectorContinuousIndex);
811 dummyGeometry->IndexToWorld(pIndex, p);
813 CPPUNIT_ASSERT(vectorContinuousIndex == vector);
814 CPPUNIT_ASSERT(
mitk::Equal(vectorContinuousIndex[0], p[0] - origin[0]));
815 CPPUNIT_ASSERT(
mitk::Equal(vectorContinuousIndex[1], p[1] - origin[1]));
816 CPPUNIT_ASSERT(
mitk::Equal(vectorContinuousIndex[2], p[2] - origin[2]));
831 itkIndex4[0] = itkIndex4[1] = itkIndex4[2] = itkIndex4[3] = 4;
832 itkIndex3[0] = itkIndex3[1] = itkIndex3[2] = 6;
833 itkIndex2[0] = itkIndex2[1] = 2;
834 mitkIndex[0] = mitkIndex[1] = mitkIndex[2] = 13;
838 dummyGeometry->IndexToWorld(itkIndex2, point);
839 dummyGeometry->WorldToIndex(point, itkIndex2b);
841 CPPUNIT_ASSERT(((itkIndex2b[0] == itkIndex2[0]) && (itkIndex2b[1] == itkIndex2[1])));
844 dummyGeometry->IndexToWorld(itkIndex3, point);
845 dummyGeometry->WorldToIndex(point, itkIndex3b);
848 ((itkIndex3b[0] == itkIndex3[0]) && (itkIndex3b[1] == itkIndex3[1]) && (itkIndex3b[2] == itkIndex3[2])));
851 dummyGeometry->IndexToWorld(itkIndex4, point);
852 dummyGeometry->WorldToIndex(point, itkIndex4b);
854 CPPUNIT_ASSERT(((itkIndex4b[0] == itkIndex4[0]) && (itkIndex4b[1] == itkIndex4[1]) &&
855 (itkIndex4b[2] == itkIndex4[2]) && (itkIndex4b[3] == 0)));
858 dummyGeometry->IndexToWorld(mitkIndex, point);
859 dummyGeometry->WorldToIndex(point, mitkIndexb);
862 ((mitkIndexb[0] == mitkIndex[0]) && (mitkIndexb[1] == mitkIndex[1]) && (mitkIndexb[2] == mitkIndex[2])));
868 void TestIndexToWorld()
881 dummy->SetOrigin(anotherPoint);
886 dummy->SetIndexToWorldTransform(anotherTransform);
891 dummy->SetOrigin(anotherPoint);
896 dummy->SetSpacing(anotherSpacing);
902 void TestExecuteOperation()
911 dummy->ExecuteOperation(opN);
916 dummy->ExecuteOperation(opP);
917 CPPUNIT_ASSERT(
mitk::Equal(anotherPoint, dummy->GetOrigin()));
918 newDummy->SetOrigin(anotherPoint);
923 spacing[0] = anotherSpacing[0] - 1.;
924 spacing[1] = anotherSpacing[1] - 1.;
925 spacing[2] = anotherSpacing[2] - 1.;
928 dummy->ExecuteOperation(opS);
929 CPPUNIT_ASSERT(
mitk::Equal(anotherSpacing, dummy->GetSpacing()));
930 newDummy->SetSpacing(anotherSpacing);
934 dummy->SetIndexToWorldTransform(anotherTransform);
935 dummy->SetSpacing(anotherSpacing);
943 dummy->ExecuteOperation(opR);
949 dummy->WorldToIndex(voxelStep, voxelStepIndex);
951 expectedVoxelStepIndex.Fill(1);
952 CPPUNIT_ASSERT(
mitk::Equal(voxelStepIndex, expectedVoxelStepIndex));
960 void TestCalculateBoundingBoxRelToTransform()
963 dummy->SetExtentInMM(0, 15);
964 dummy->SetExtentInMM(1, 20);
965 dummy->SetExtentInMM(2, 8);
967 mitk::BoundingBox::Pointer dummyBoundingBox = dummy->CalculateBoundingBoxRelativeToTransform(anotherTransform);
969 mitk::BoundingBox::PointsContainer::Pointer pointscontainer = mitk::BoundingBox::PointsContainer::New();
970 mitk::BoundingBox::PointIdentifier pointid = 0;
972 mitk::AffineTransform3D::Pointer inverse = mitk::AffineTransform3D::New();
973 anotherTransform->GetInverse(inverse);
974 for (i = 0; i < 8; ++i)
975 pointscontainer->InsertElement(pointid++, inverse->TransformPoint(dummy->GetCornerPoint(i)));
976 mitk::BoundingBox::Pointer result = mitk::BoundingBox::New();
977 result->SetPoints(pointscontainer);
978 result->ComputeBoundingBox();
984 newDummy->SetExtentInMM(0, 15);
985 newDummy->SetExtentInMM(1, 20);
986 newDummy->SetExtentInMM(2, 8);
1010 void TestIs2DConvertable()
1015 CPPUNIT_ASSERT(dummy->Is2DConvertable());
1018 dummy->SetSpacing(anotherSpacing);
1019 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1021 dummy->SetSpacing(aSpacing);
1022 CPPUNIT_ASSERT(dummy->Is2DConvertable());
1025 dummy->SetOrigin(anotherPoint);
1026 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1028 dummy->SetOrigin(aPoint);
1029 CPPUNIT_ASSERT(dummy->Is2DConvertable());
1032 mitk::AffineTransform3D::Pointer dummyTransform = mitk::AffineTransform3D::New();
1033 mitk::AffineTransform3D::MatrixType dummyMatrix;
1034 dummyMatrix.SetIdentity();
1035 dummyTransform->SetMatrix(dummyMatrix);
1036 dummy->SetIndexToWorldTransform(dummyTransform);
1039 CPPUNIT_ASSERT(dummy->Is2DConvertable());
1041 dummyMatrix(0, 2) = 3;
1042 dummyTransform->SetMatrix(dummyMatrix);
1043 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1045 dummyMatrix.SetIdentity();
1046 dummyMatrix(1, 2) = 0.4;
1047 dummyTransform->SetMatrix(dummyMatrix);
1048 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1050 dummyMatrix.SetIdentity();
1051 dummyMatrix(2, 2) = 3;
1052 dummyTransform->SetMatrix(dummyMatrix);
1053 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1055 dummyMatrix.SetIdentity();
1056 dummyMatrix(2, 1) = 3;
1057 dummyTransform->SetMatrix(dummyMatrix);
1058 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1060 dummyMatrix.SetIdentity();
1061 dummyMatrix(2, 0) = 3;
1062 dummyTransform->SetMatrix(dummyMatrix);
1063 CPPUNIT_ASSERT(dummy->Is2DConvertable() ==
false);
1066 dummyMatrix.SetIdentity();
1067 dummyTransform->SetMatrix(dummyMatrix);
1072 void TestGetCornerPoint()
1075 dummy->SetIndexToWorldTransform(anotherTransform);
1076 double bounds[6] = {0, 11, 0, 12, 0, 13};
1077 dummy->SetFloatBounds(bounds);
1083 refCorner = anotherTransform->TransformPoint(refCorner);
1084 corner = dummy->GetCornerPoint(0);
1086 corner = dummy->GetCornerPoint(
true,
true,
true);
1091 refCorner = anotherTransform->TransformPoint(refCorner);
1092 corner = dummy->GetCornerPoint(1);
1094 corner = dummy->GetCornerPoint(
true,
true,
false);
1099 refCorner = anotherTransform->TransformPoint(refCorner);
1100 corner = dummy->GetCornerPoint(2);
1102 corner = dummy->GetCornerPoint(
true,
false,
true);
1107 refCorner = anotherTransform->TransformPoint(refCorner);
1108 corner = dummy->GetCornerPoint(3);
1110 corner = dummy->GetCornerPoint(
true,
false,
false);
1115 refCorner = anotherTransform->TransformPoint(refCorner);
1116 corner = dummy->GetCornerPoint(4);
1118 corner = dummy->GetCornerPoint(
false,
true,
true);
1123 refCorner = anotherTransform->TransformPoint(refCorner);
1124 corner = dummy->GetCornerPoint(5);
1126 corner = dummy->GetCornerPoint(
false,
true,
false);
1131 refCorner = anotherTransform->TransformPoint(refCorner);
1132 corner = dummy->GetCornerPoint(6);
1134 corner = dummy->GetCornerPoint(
false,
false,
true);
1139 refCorner = anotherTransform->TransformPoint(refCorner);
1140 corner = dummy->GetCornerPoint(7);
1142 corner = dummy->GetCornerPoint(
false,
false,
false);
1146 CPPUNIT_ASSERT_THROW(dummy->GetCornerPoint(20), itk::ExceptionObject);
1150 newDummy->SetIndexToWorldTransform(anotherTransform);
1151 newDummy->SetFloatBounds(bounds);
1155 void TestExtentInMM()
1158 dummy->SetExtentInMM(0, 50);
1159 CPPUNIT_ASSERT(
mitk::Equal(50., dummy->GetExtentInMM(0)));
1162 mitk::Equal(50., dummy->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0).magnitude()));
1165 dummy->SetExtentInMM(0, 5);
1166 CPPUNIT_ASSERT(
mitk::Equal(5., dummy->GetExtentInMM(0)));
1168 mitk::Equal(5., dummy->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0).magnitude()));
1170 dummy->SetExtentInMM(1, 4);
1171 CPPUNIT_ASSERT(
mitk::Equal(4., dummy->GetExtentInMM(1)));
1173 mitk::Equal(4., dummy->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1).magnitude()));
1175 dummy->SetExtentInMM(2, 2.5);
1176 CPPUNIT_ASSERT(
mitk::Equal(2.5, dummy->GetExtentInMM(2)));
1178 mitk::Equal(2.5, dummy->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2).magnitude()));
1181 void TestGetAxisVector()
1184 dummy->SetIndexToWorldTransform(anotherTransform);
1185 double bounds[6] = {0, 11, 0, 12, 0, 13};
1186 dummy->SetFloatBounds(bounds);
1190 dummy->IndexToWorld(vector, vector);
1191 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetAxisVector(0), vector));
1194 dummy->IndexToWorld(vector, vector);
1195 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetAxisVector(1), vector));
1198 dummy->IndexToWorld(vector, vector);
1199 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetAxisVector(2), vector));
1202 void TestGetCenter()
1205 dummy->SetIndexToWorldTransform(anotherTransform);
1206 double bounds[6] = {0, 11, 2, 12, 1, 13};
1207 dummy->SetFloatBounds(bounds);
1210 for (
int i = 0; i < 3; i++)
1211 refCenter.SetElement(i, (bounds[2 * i] + bounds[2 * i + 1]) / 2.0);
1213 dummy->IndexToWorld(refCenter, refCenter);
1215 CPPUNIT_ASSERT(
mitk::Equal(dummy->GetCenter(), refCenter));
1218 void TestGetDiagonalLength()
1221 double bounds[6] = {1, 3, 5, 8, 7.5, 11.5};
1222 dummy->SetFloatBounds(bounds);
1224 double expectedLength = sqrt(29.);
1231 newDummy->SetFloatBounds(bounds);
1235 void TestGetExtent()
1238 double bounds[6] = {1, 3, 5, 8, 7.5, 11.5};
1239 dummy->SetFloatBounds(bounds);
1241 CPPUNIT_ASSERT(
mitk::Equal(2., dummy->GetExtent(0)));
1242 CPPUNIT_ASSERT(
mitk::Equal(3., dummy->GetExtent(1)));
1243 CPPUNIT_ASSERT(
mitk::Equal(4., dummy->GetExtent(2)));
1247 newDummy->SetFloatBounds(bounds);
1254 double bounds[6] = {1, 3, 5, 8, 7.5, 11.5};
1255 dummy->SetFloatBounds(bounds);
1263 CPPUNIT_ASSERT(dummy->IsIndexInside(insidePoint));
1264 CPPUNIT_ASSERT(
false == dummy->IsIndexInside(outsidePoint));
1266 dummy->IndexToWorld(insidePoint, insidePoint);
1267 dummy->IndexToWorld(outsidePoint, outsidePoint);
1269 CPPUNIT_ASSERT(dummy->IsInside(insidePoint));
1270 CPPUNIT_ASSERT(
false == dummy->IsInside(outsidePoint));
1274 newDummy->SetFloatBounds(bounds);
1278 void TestInitialize()
1284 dummy2->SetOrigin(anotherPoint);
1285 dummy2->SetBounds(anotherBoundingBox->GetBounds());
1290 dummy2->SetIndexToWorldTransform(anotherTransform);
1291 dummy2->SetSpacing(anotherSpacing);
1293 dummy1->InitializeGeometry(dummy2);
1297 dummy1->Initialize();
1303 void TestGetMatrixColumn()
1306 dummy->SetIndexToWorldTransform(anotherTransform);
1309 testVector.SetVnlVector(dummy->GetMatrixColumn(0));
1311 CPPUNIT_ASSERT(testVector == refVector);
1313 testVector.SetVnlVector(dummy->GetMatrixColumn(1));
1315 CPPUNIT_ASSERT(testVector == refVector);
1317 testVector.SetVnlVector(dummy->GetMatrixColumn(2));
1319 CPPUNIT_ASSERT(testVector == refVector);
1323 newDummy->SetIndexToWorldTransform(anotherTransform);
bool EqualArray(TArrayType1 &arrayType1, TArrayType2 &arrayType2, int size, ScalarType eps=mitk::eps, bool verbose=false)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
void GetRotation(const mitk::BaseGeometry *geometry, TMatrixType &itkmatrix)
#define mitkNewMacro1Param(classname, type)
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.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Base class of all Operation-classes.
vnl_vector< ScalarType > VnlVector
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Constants for most interaction classes, due to the generic StateMachines.
int testIndexAndWorldConsistencyForVectors(mitk::Geometry3D *geometry3d)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
itk::SmartPointer< Self > Pointer
#define MITK_ASSERT_NOT_EQUAL(OBJ1, OBJ2, MSG)
Testing macro to test if two objects are not equal.
virtual void PreSetSpacing(const mitk::Vector3D &)
PreSetSpacing.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
#define mitkClassMacro(className, SuperClassName)
itk::BoundingBox< unsigned long, 3, mitk::ScalarType > BoundingBoxType
Test fixture for parameterized tests.
Operation that handles all actions on one Point.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
void vtk2itk(const Tin &in, Tout &out)
int testIndexAndWorldConsistencyForIndex(mitk::Geometry3D *geometry3d)
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.
The ScaleOperation is an operation to scale any mitk::BaseGeometry.
itk::BoundingBox< unsigned long, 3, mitk::ScalarType > BoundingBox
MITKCORE_EXPORT const ScalarType eps
int testIndexAndWorldConsistency(mitk::Geometry3D *geometry3d)
itk::LightObject::Pointer InternalClone() const override=0
clones the geometry
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
BoundingBoxType::Pointer BoundingBoxPointer
BaseGeometry Describes the geometry of a data object.
BoundingBoxType::BoundsArrayType BoundsArrayType