15 #include <vnl/vnl_quaternion.h> 16 #include <vnl/vnl_quaternion.hxx> 30 for (direction = 0; direction < 3; ++direction)
45 std::cout <<
"Testing GetAxisVector(int) vs GetAxisVector(bool, bool, bool): ";
48 std::cout <<
"[FAILED]" << std::endl;
51 std::cout <<
"[PASSED]" << std::endl;
59 for (direction = 0; direction < 3; ++direction)
63 std::cout <<
"[FAILED]" << std::endl;
66 std::cout <<
"[PASSED]" << std::endl;
74 MITK_TEST_OUTPUT(<<
"Testing consistency of index and world coordinate systems: ");
83 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin, mitk::Point3D)==(0,0,0)");
98 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin-0.5*spacing, itk::Index)==(0,0,0)");
105 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)");
106 originOffCenter = origin + halfSpacingStep;
107 originOffCenter -= 0.0001;
111 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)");
112 originOffCenter = origin + halfSpacingStep;
118 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(GetCenter())==BoundingBox.GetCenter: ");
122 mitk::BoundingBox::ConstPointer boundingBox = geometry3d->
GetBoundingBox();
123 mitk::BoundingBox::PointType centerBounds = boundingBox->GetCenter();
128 centerBounds[0] -= 0.5;
129 centerBounds[1] -= 0.5;
130 centerBounds[2] -= 0.5;
134 MITK_TEST_OUTPUT(<<
" Testing GetCenter()==IndexToWorld(BoundingBox.GetCenter): ");
137 geometry3d->
IndexToWorld(centerBounds, centerBoundsInWorldCoords);
145 MITK_TEST_OUTPUT(<<
"Testing consistency of index and world coordinate systems for vectors: ");
158 geometry3d->
WorldToIndex(xAxisMM, xAxisContinuousIndexDeprecated);
159 geometry3d->
WorldToIndex(xAxisMM, xAxisContinuousIndex);
172 geometry3d->
IndexToWorld(xAxisContinuousIndex, xAxisContinuousIndex);
173 geometry3d->
IndexToWorld(xAxisContinuousIndexDeprecated, xAxisContinuousIndexDeprecated);
191 MITK_TEST_OUTPUT(<<
"Testing consistency of index and world coordinate systems: ");
199 itkIndex4[0] = itkIndex4[1] = itkIndex4[2] = itkIndex4[3] = 4;
200 itkIndex3[0] = itkIndex3[1] = itkIndex3[2] = 6;
201 itkIndex2[0] = itkIndex2[1] = 2;
202 mitkIndex[0] = mitkIndex[1] = mitkIndex[2] = 13;
210 "Testing itk::index<2> for IndexToWorld/WorldToIndex consistency");
216 ((itkIndex3b[0] == itkIndex3[0]) && (itkIndex3b[1] == itkIndex3[1]) && (itkIndex3b[2] == itkIndex3[2])),
217 "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency");
223 (itkIndex4b[2] == itkIndex4[2]) && (itkIndex4b[3] == 0)),
224 "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency");
230 ((mitkIndexb[0] == mitkIndex[0]) && (mitkIndexb[1] == mitkIndex[1]) && (mitkIndexb[2] == mitkIndex[2])),
231 "Testing mitk::Index for IndexToWorld/WorldToIndex consistency");
236 #include <itkImage.h> 240 MITK_TEST_OUTPUT(<<
"Testing whether itk::Image coordinates are center-based.");
241 typedef itk::Image<int, 3> ItkIntImage3D;
242 ItkIntImage3D::Pointer itkintimage = ItkIntImage3D::New();
243 ItkIntImage3D::SizeType size;
247 itkintimage->Initialize();
248 itkintimage->SetRegions(size);
249 itkintimage->SetOrigin(origin);
250 std::cout <<
"[PASSED]" << std::endl;
252 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToContinuousIndex(origin)==(0,0,0)");
256 itk::ContinuousIndex<mitk::ScalarType, 3> originContinuousIndex;
257 itkintimage->TransformPhysicalPointToContinuousIndex(origin, originContinuousIndex);
260 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToIndex(origin)==(0,0,0)");
262 itkintimage->TransformPhysicalPointToIndex(origin, itkindex);
267 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToIndex(origin-0.5*spacing)==(0,0,0)");
271 itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex);
275 <<
" Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)");
276 originOffCenter = origin + halfSpacingStep;
277 originOffCenter -= 0.0001;
278 itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex);
281 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)");
282 originOffCenter = origin + halfSpacingStep;
285 itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex);
297 float bounds[] = {-10.0, 17.0, -12.0, 188.0, 13.0, 211.0};
300 geometry3d->Initialize();
303 geometry3d->SetImageGeometry(imageGeometry);
306 geometry3d->SetFloatBounds(bounds);
316 mitk::AffineTransform3D::MatrixType matrix;
317 matrix.SetIdentity();
319 mitk::AffineTransform3D::Pointer transform;
320 transform = mitk::AffineTransform3D::New();
321 transform->SetMatrix(matrix);
324 geometry3d->SetIndexToWorldTransform(transform);
329 expectedSpacing.Fill(1.0);
330 expectedSpacing[1] = 2;
331 if (
mitk::Equal(spacing1, expectedSpacing) ==
false)
338 geometry3d->Compose(transform);
342 expectedSpacing[1] = 4;
343 if (
mitk::Equal(spacing2, expectedSpacing) ==
false)
352 geometry3d->SetSpacing(newspacing);
371 geometry3d->ExecuteOperation(op);
378 geometry3d->WorldToIndex(voxelStep, voxelStepIndex);
380 expectedVoxelStepIndex.Fill(1);
383 std::cout <<
"[PASSED]" << std::endl;
385 MITK_TEST_OUTPUT(<<
"Testing that ImageGeometry is still " << imageGeometry);
393 translationVector.SetElement(0, 17.5f);
394 translationVector.SetElement(1, -32.3f);
395 translationVector.SetElement(2, 4.0f);
397 mitk::Point3D tmpResult = geometry3d->GetOrigin() + translationVector;
398 geometry3d->Translate(translationVector);
401 translationVector *= -1;
402 geometry3d->Translate(translationVector);
405 "Testing if the translation could be done vice versa.");
416 typedef itk::Image<double, 2> Image2DType;
417 typedef itk::Image<double, 3> Image3DType;
420 Image3DType::Pointer image3DItk = Image3DType::New();
421 Image3DType::RegionType myRegion;
422 Image3DType::SizeType mySize;
423 Image3DType::IndexType myIndex;
424 Image3DType::SpacingType mySpacing;
425 Image3DType::DirectionType myDirection, rotMatrixX, rotMatrixY, rotMatrixZ;
435 myRegion.SetSize(mySize);
436 myRegion.SetIndex(myIndex);
437 image3DItk->SetSpacing(mySpacing);
438 image3DItk->SetRegions(myRegion);
439 image3DItk->Allocate();
440 image3DItk->FillBuffer(0);
442 myDirection.SetIdentity();
443 rotMatrixX.SetIdentity();
444 rotMatrixY.SetIdentity();
445 rotMatrixZ.SetIdentity();
450 MITK_TEST_OUTPUT(<<
"Casting a rotated 3D ITK Image to a MITK Image and check if Geometry is still same");
451 for (
double rotX = 0; rotX < (itk::Math::pi * 2); rotX += 0.4)
454 rotMatrixX[1][1] = cos(rotX);
455 rotMatrixX[1][2] = -sin(rotX);
456 rotMatrixX[2][1] = sin(rotX);
457 rotMatrixX[2][2] = cos(rotX);
459 for (
double rotY = 0; rotY < (itk::Math::pi * 2); rotY += 0.33)
462 rotMatrixY[0][0] = cos(rotY);
463 rotMatrixY[0][2] = sin(rotY);
464 rotMatrixY[2][0] = -sin(rotY);
465 rotMatrixY[2][2] = cos(rotY);
467 for (
double rotZ = 0; rotZ < (itk::Math::pi * 2); rotZ += 0.5)
470 rotMatrixZ[0][0] = cos(rotZ);
471 rotMatrixZ[0][1] = -sin(rotZ);
472 rotMatrixZ[1][0] = sin(rotZ);
473 rotMatrixZ[1][1] = cos(rotZ);
476 myDirection = myDirection * rotMatrixX * rotMatrixY * rotMatrixZ;
477 image3DItk->SetDirection(myDirection);
479 const mitk::AffineTransform3D::MatrixType &matrix =
480 mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix();
482 for (
int row = 0; row < 3; row++)
484 for (
int col = 0; col < 3; col++)
486 double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col];
487 double itkValue = myDirection[row][col];
488 double diff = mitkValue - itkValue;
492 std::cout <<
"Had a difference of : " << diff;
493 std::cout <<
"Error: Casting altered Geometry!";
494 std::cout <<
"ITK Matrix:\n" << myDirection;
495 std::cout <<
"Mitk Matrix (With Spacing):\n" << matrix;
496 std::cout <<
"Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing();
507 Image2DType::Pointer image2DItk = Image2DType::New();
508 Image2DType::RegionType myRegion2D;
509 Image2DType::SizeType mySize2D;
510 Image2DType::IndexType myIndex2D;
511 Image2DType::SpacingType mySpacing2D;
512 Image2DType::DirectionType myDirection2D, rotMatrix;
514 mySpacing2D[1] = 0.1;
519 myRegion2D.SetSize(mySize2D);
520 myRegion2D.SetIndex(myIndex2D);
521 image2DItk->SetSpacing(mySpacing2D);
522 image2DItk->SetRegions(myRegion2D);
523 image2DItk->Allocate();
524 image2DItk->FillBuffer(0);
526 myDirection2D.SetIdentity();
527 rotMatrix.SetIdentity();
530 MITK_TEST_OUTPUT(<<
"Casting a rotated 2D ITK Image to a MITK Image and check if Geometry is still same");
531 for (
double rotTheta = 0; rotTheta < (itk::Math::pi * 2); rotTheta += 0.1)
534 rotMatrix[0][0] = cos(rotTheta);
535 rotMatrix[0][1] = -sin(rotTheta);
536 rotMatrix[1][0] = sin(rotTheta);
537 rotMatrix[1][1] = cos(rotTheta);
540 myDirection2D = myDirection2D * rotMatrix;
541 image2DItk->SetDirection(myDirection2D);
543 const mitk::AffineTransform3D::MatrixType &matrix =
544 mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix();
547 for (
int row = 0; row < 3; row++)
549 for (
int col = 0; col < 3; col++)
551 double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col];
552 if ((row == 2) && (col == row))
556 MITK_TEST_OUTPUT(<<
"After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 " 557 "MUST be 0 and value for 2|2 must be 1");
561 else if ((row == 2) || (col == 2))
565 MITK_TEST_OUTPUT(<<
"After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 " 566 "MUST be 0 and value for 2|2 must be 1");
572 double itkValue = myDirection2D[row][col];
573 double diff = mitkValue - itkValue;
577 std::cout <<
"Had a difference of : " << diff;
578 std::cout <<
"Error: Casting altered Geometry!";
579 std::cout <<
"ITK Matrix:\n" << myDirection2D;
580 std::cout <<
"Mitk Matrix (With Spacing):\n" << matrix;
581 std::cout <<
"Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing();
610 MITK_TEST_OUTPUT(<<
"Running main part of test with ImageGeometry = false");
616 MITK_TEST_OUTPUT(<<
"Running test to see if Casting MITK to ITK and the other way around destroys geometry");
bool testGetAxisVectorVariants(mitk::Geometry3D *geometry)
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
virtual bool GetImageGeometry() const
Is this an ImageGeometry?
Standard implementation of BaseGeometry.
void GetRotation(const mitk::BaseGeometry *geometry, TMatrixType &itkmatrix)
Vector3D GetAxisVector(unsigned int direction) const
Get vector along bounding-box in the specified direction in mm.
int mitkGeometry3DTest(int, char *[])
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
Point3D GetCornerPoint(int id) const
Get the position of the corner number id (in world coordinates)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Constants for most interaction classes, due to the generic StateMachines.
int testIndexAndWorldConsistencyForVectors(mitk::Geometry3D *geometry3d)
Point3D GetCenter() const
Get the center of the bounding-box in mm.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
ScalarType GetExtentInMM(int direction) const
Get the extent of the bounding-box in the specified direction in mm.
int testItkImageIsCenterBased()
int testGeometry3D(bool imageGeometry)
#define MITK_TEST_OUTPUT(x)
Output some text.
#define MITK_TEST_CONDITION(COND, MSG)
void vtk2itk(const Tin &in, Tout &out)
bool testGetAxisVectorExtent(mitk::Geometry3D *geometry)
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
void WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const
Convert world coordinates (in mm) of a point to (continuous!) index coordinates.
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.
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
MITKCORE_EXPORT const ScalarType eps
int testIndexAndWorldConsistency(mitk::Geometry3D *geometry3d)
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
int testGeometryAfterCasting()
virtual const BoundingBoxType * GetBoundingBox()