19 #include <vnl/vnl_quaternion.h>
20 #include <vnl/vnl_quaternion.txx>
34 for (direction = 0; direction < 3; ++direction)
49 std::cout <<
"Testing GetAxisVector(int) vs GetAxisVector(bool, bool, bool): ";
52 std::cout <<
"[FAILED]" << std::endl;
55 std::cout <<
"[PASSED]" << std::endl;
63 for (direction = 0; direction < 3; ++direction)
67 std::cout <<
"[FAILED]" << std::endl;
70 std::cout <<
"[PASSED]" << std::endl;
78 MITK_TEST_OUTPUT(<<
"Testing consistency of index and world coordinate systems: ");
87 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin, mitk::Point3D)==(0,0,0)");
102 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin-0.5*spacing, itk::Index)==(0,0,0)");
109 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)");
110 originOffCenter = origin + halfSpacingStep;
111 originOffCenter -= 0.0001;
115 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)");
116 originOffCenter = origin + halfSpacingStep;
122 MITK_TEST_OUTPUT(<<
" Testing WorldToIndex(GetCenter())==BoundingBox.GetCenter: ");
132 centerBounds[0] -= 0.5;
133 centerBounds[1] -= 0.5;
134 centerBounds[2] -= 0.5;
138 MITK_TEST_OUTPUT(<<
" Testing GetCenter()==IndexToWorld(BoundingBox.GetCenter): ");
141 geometry3d->
IndexToWorld(centerBounds, centerBoundsInWorldCoords);
149 MITK_TEST_OUTPUT(<<
"Testing consistency of index and world coordinate systems for vectors: ");
162 geometry3d->
WorldToIndex(xAxisMM, xAxisContinuousIndexDeprecated);
163 geometry3d->
WorldToIndex(xAxisMM, xAxisContinuousIndex);
176 geometry3d->
IndexToWorld(xAxisContinuousIndex, xAxisContinuousIndex);
177 geometry3d->
IndexToWorld(xAxisContinuousIndexDeprecated, xAxisContinuousIndexDeprecated);
195 MITK_TEST_OUTPUT(<<
"Testing consistency of index and world coordinate systems: ");
203 itkIndex4[0] = itkIndex4[1] = itkIndex4[2] = itkIndex4[3] = 4;
204 itkIndex3[0] = itkIndex3[1] = itkIndex3[2] = 6;
205 itkIndex2[0] = itkIndex2[1] = 2;
206 mitkIndex[0] = mitkIndex[1] = mitkIndex[2] = 13;
214 "Testing itk::index<2> for IndexToWorld/WorldToIndex consistency");
220 ((itkIndex3b[0] == itkIndex3[0]) && (itkIndex3b[1] == itkIndex3[1]) && (itkIndex3b[2] == itkIndex3[2])),
221 "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency");
227 (itkIndex4b[2] == itkIndex4[2]) && (itkIndex4b[3] == 0)),
228 "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency");
234 ((mitkIndexb[0] == mitkIndex[0]) && (mitkIndexb[1] == mitkIndex[1]) && (mitkIndexb[2] == mitkIndex[2])),
235 "Testing mitk::Index for IndexToWorld/WorldToIndex consistency");
240 #include <itkImage.h>
244 MITK_TEST_OUTPUT(<<
"Testing whether itk::Image coordinates are center-based.");
245 typedef itk::Image<int, 3> ItkIntImage3D;
247 ItkIntImage3D::SizeType size;
251 itkintimage->Initialize();
252 itkintimage->SetRegions(size);
253 itkintimage->SetOrigin(origin);
254 std::cout <<
"[PASSED]" << std::endl;
256 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToContinuousIndex(origin)==(0,0,0)");
260 itk::ContinuousIndex<mitk::ScalarType, 3> originContinuousIndex;
261 itkintimage->TransformPhysicalPointToContinuousIndex(origin, originContinuousIndex);
264 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToIndex(origin)==(0,0,0)");
266 itkintimage->TransformPhysicalPointToIndex(origin, itkindex);
271 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToIndex(origin-0.5*spacing)==(0,0,0)");
275 itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex);
279 <<
" Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)");
280 originOffCenter = origin + halfSpacingStep;
281 originOffCenter -= 0.0001;
282 itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex);
285 MITK_TEST_OUTPUT(<<
" Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)");
286 originOffCenter = origin + halfSpacingStep;
289 itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex);
301 float bounds[] = {-10.0, 17.0, -12.0, 188.0, 13.0, 211.0};
304 geometry3d->Initialize();
307 geometry3d->SetImageGeometry(imageGeometry);
310 geometry3d->SetFloatBounds(bounds);
320 mitk::AffineTransform3D::MatrixType matrix;
321 matrix.SetIdentity();
325 transform->SetMatrix(matrix);
328 geometry3d->SetIndexToWorldTransform(transform);
333 expectedSpacing.Fill(1.0);
334 expectedSpacing[1] = 2;
335 if (
mitk::Equal(spacing1, expectedSpacing) ==
false)
342 geometry3d->Compose(transform);
346 expectedSpacing[1] = 4;
347 if (
mitk::Equal(spacing2, expectedSpacing) ==
false)
356 geometry3d->SetSpacing(newspacing);
375 geometry3d->ExecuteOperation(op);
382 geometry3d->WorldToIndex(voxelStep, voxelStepIndex);
384 expectedVoxelStepIndex.Fill(1);
387 std::cout <<
"[PASSED]" << std::endl;
389 MITK_TEST_OUTPUT(<<
"Testing that ImageGeometry is still " << imageGeometry);
397 translationVector.SetElement(0, 17.5f);
398 translationVector.SetElement(1, -32.3f);
399 translationVector.SetElement(2, 4.0f);
401 mitk::Point3D tmpResult = geometry3d->GetOrigin() + translationVector;
402 geometry3d->Translate(translationVector);
405 translationVector *= -1;
406 geometry3d->Translate(translationVector);
409 "Testing if the translation could be done vice versa.");
420 typedef itk::Image<double, 2> Image2DType;
421 typedef itk::Image<double, 3> Image3DType;
425 Image3DType::RegionType myRegion;
426 Image3DType::SizeType mySize;
427 Image3DType::IndexType myIndex;
428 Image3DType::SpacingType mySpacing;
429 Image3DType::DirectionType myDirection, rotMatrixX, rotMatrixY, rotMatrixZ;
439 myRegion.SetSize(mySize);
440 myRegion.SetIndex(myIndex);
441 image3DItk->SetSpacing(mySpacing);
442 image3DItk->SetRegions(myRegion);
443 image3DItk->Allocate();
444 image3DItk->FillBuffer(0);
446 myDirection.SetIdentity();
447 rotMatrixX.SetIdentity();
448 rotMatrixY.SetIdentity();
449 rotMatrixZ.SetIdentity();
454 MITK_TEST_OUTPUT(<<
"Casting a rotated 3D ITK Image to a MITK Image and check if Geometry is still same");
455 for (
double rotX = 0; rotX < (itk::Math::pi * 2); rotX += 0.4)
458 rotMatrixX[1][1] = cos(rotX);
459 rotMatrixX[1][2] = -sin(rotX);
460 rotMatrixX[2][1] = sin(rotX);
461 rotMatrixX[2][2] = cos(rotX);
463 for (
double rotY = 0; rotY < (itk::Math::pi * 2); rotY += 0.33)
466 rotMatrixY[0][0] = cos(rotY);
467 rotMatrixY[0][2] = sin(rotY);
468 rotMatrixY[2][0] = -sin(rotY);
469 rotMatrixY[2][2] = cos(rotY);
471 for (
double rotZ = 0; rotZ < (itk::Math::pi * 2); rotZ += 0.5)
474 rotMatrixZ[0][0] = cos(rotZ);
475 rotMatrixZ[0][1] = -sin(rotZ);
476 rotMatrixZ[1][0] = sin(rotZ);
477 rotMatrixZ[1][1] = cos(rotZ);
480 myDirection = myDirection * rotMatrixX * rotMatrixY * rotMatrixZ;
481 image3DItk->SetDirection(myDirection);
483 const mitk::AffineTransform3D::MatrixType &matrix =
484 mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix();
486 for (
int row = 0; row < 3; row++)
488 for (
int col = 0; col < 3; col++)
490 double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col];
491 double itkValue = myDirection[row][col];
492 double diff = mitkValue - itkValue;
496 std::cout <<
"Had a difference of : " << diff;
497 std::cout <<
"Error: Casting altered Geometry!";
498 std::cout <<
"ITK Matrix:\n" << myDirection;
499 std::cout <<
"Mitk Matrix (With Spacing):\n" << matrix;
500 std::cout <<
"Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing();
512 Image2DType::RegionType myRegion2D;
513 Image2DType::SizeType mySize2D;
514 Image2DType::IndexType myIndex2D;
515 Image2DType::SpacingType mySpacing2D;
516 Image2DType::DirectionType myDirection2D, rotMatrix;
518 mySpacing2D[1] = 0.1;
523 myRegion2D.SetSize(mySize2D);
524 myRegion2D.SetIndex(myIndex2D);
525 image2DItk->SetSpacing(mySpacing2D);
526 image2DItk->SetRegions(myRegion2D);
527 image2DItk->Allocate();
528 image2DItk->FillBuffer(0);
530 myDirection2D.SetIdentity();
531 rotMatrix.SetIdentity();
534 MITK_TEST_OUTPUT(<<
"Casting a rotated 2D ITK Image to a MITK Image and check if Geometry is still same");
535 for (
double rotTheta = 0; rotTheta < (itk::Math::pi * 2); rotTheta += 0.1)
538 rotMatrix[0][0] = cos(rotTheta);
539 rotMatrix[0][1] = -sin(rotTheta);
540 rotMatrix[1][0] = sin(rotTheta);
541 rotMatrix[1][1] = cos(rotTheta);
544 myDirection2D = myDirection2D * rotMatrix;
545 image2DItk->SetDirection(myDirection2D);
547 const mitk::AffineTransform3D::MatrixType &matrix =
548 mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix();
551 for (
int row = 0; row < 3; row++)
553 for (
int col = 0; col < 3; col++)
555 double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col];
556 if ((row == 2) && (col == row))
560 MITK_TEST_OUTPUT(<<
"After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 "
561 "MUST be 0 and value for 2|2 must be 1");
565 else if ((row == 2) || (col == 2))
569 MITK_TEST_OUTPUT(<<
"After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 "
570 "MUST be 0 and value for 2|2 must be 1");
576 double itkValue = myDirection2D[row][col];
577 double diff = mitkValue - itkValue;
581 std::cout <<
"Had a difference of : " << diff;
582 std::cout <<
"Error: Casting altered Geometry!";
583 std::cout <<
"ITK Matrix:\n" << myDirection2D;
584 std::cout <<
"Mitk Matrix (With Spacing):\n" << matrix;
585 std::cout <<
"Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing();
614 MITK_TEST_OUTPUT(<<
"Running main part of test with ImageGeometry = false");
620 MITK_TEST_OUTPUT(<<
"Running test to see if Casting MITK to ITK and the other way around destroys geometry");
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
bool testGetAxisVectorVariants(mitk::Geometry3D *geometry)
itk::SmartPointer< Self > Pointer
Standard implementation of BaseGeometry.
void GetRotation(const mitk::BaseGeometry *geometry, TMatrixType &itkmatrix)
int mitkGeometry3DTest(int, char *[])
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
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)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
itk::SmartPointer< const Self > ConstPointer
int testItkImageIsCenterBased()
int testGeometry3D(bool imageGeometry)
#define MITK_TEST_OUTPUT(x)
Output some text.
Vector3D GetAxisVector(unsigned int direction) const
Get vector along bounding-box in the specified direction in mm.
#define MITK_TEST_CONDITION(COND, MSG)
void vtk2itk(const Tin &in, Tout &out)
bool testGetAxisVectorExtent(mitk::Geometry3D *geometry)
Point3D GetCenter() const
Get the center of the bounding-box in mm.
Point3D GetCornerPoint(int id) const
Get the position of the corner number id (in world 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.
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)...
MITKCORE_EXPORT const ScalarType eps
int testIndexAndWorldConsistency(mitk::Geometry3D *geometry3d)
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
ScalarType GetExtentInMM(int direction) const
Get the extent of the bounding-box in the specified direction in mm.
virtual bool GetImageGeometry() const
Is this an ImageGeometry?
int testGeometryAfterCasting()
void WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const
Convert world coordinates (in mm) of a point to (continuous!) index coordinates.
virtual const BoundingBoxType * GetBoundingBox()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.