diff --git a/Core/Code/DataManagement/mitkBaseGeometry.cpp b/Core/Code/DataManagement/mitkBaseGeometry.cpp new file mode 100644 index 0000000000..746f6d0170 --- /dev/null +++ b/Core/Code/DataManagement/mitkBaseGeometry.cpp @@ -0,0 +1,206 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include +#include + +#include "mitkBaseGeometry.h" +#include "mitkvector.h" +#include "mitkMatrixConvert.h" +#include +#include + +mitk::BaseGeometry::BaseGeometry(): Superclass(), mitk::OperationActor(), + m_Valid(true), m_FrameOfReferenceID(0), m_IndexToWorldTransformLastModified(0) +{ + FillVector3D(m_FloatSpacing, 1,1,1); + m_VtkMatrix = vtkMatrix4x4::New(); + m_VtkIndexToWorldTransform = vtkMatrixToLinearTransform::New(); + m_VtkIndexToWorldTransform->SetInput(m_VtkMatrix); + Initialize(); +} + +mitk::BaseGeometry::BaseGeometry(const BaseGeometry& other): Superclass(), m_ParametricBoundingBox(other.m_ParametricBoundingBox), m_TimeBounds(other.m_TimeBounds), + m_Valid(other.m_Valid), m_FrameOfReferenceID(other.m_FrameOfReferenceID), m_IndexToWorldTransformLastModified(other.m_IndexToWorldTransformLastModified), m_Origin(other.m_Origin) +{ + // DEPRECATED(m_RotationQuaternion = other.m_RotationQuaternion); + // AffineGeometryFrame + SetBounds(other.GetBounds()); + //SetIndexToObjectTransform(other.GetIndexToObjectTransform()); + //SetObjectToNodeTransform(other.GetObjectToNodeTransform()); + //SetIndexToWorldTransform(other.GetIndexToWorldTransform()); + // this is not used in AffineGeometryFrame of ITK, thus there are not Get and Set methods + // m_IndexToNodeTransform = other.m_IndexToNodeTransform; + // m_InvertedTransform = TransformType::New(); + // m_InvertedTransform = TransformType::New(); + // m_InvertedTransform->DeepCopy(other.m_InvertedTransform); + m_VtkMatrix = vtkMatrix4x4::New(); + m_VtkMatrix->DeepCopy(other.m_VtkMatrix); + if (other.m_ParametricBoundingBox.IsNotNull()) + { + m_ParametricBoundingBox = other.m_ParametricBoundingBox->DeepCopy(); + } + FillVector3D(m_FloatSpacing,other.m_FloatSpacing[0],other.m_FloatSpacing[1],other.m_FloatSpacing[2]); + m_VtkIndexToWorldTransform = vtkMatrixToLinearTransform::New(); + m_VtkIndexToWorldTransform->DeepCopy(other.m_VtkIndexToWorldTransform); + m_VtkIndexToWorldTransform->SetInput(m_VtkMatrix); + other.InitializeGeometry(this); +} + +mitk::BaseGeometry::~BaseGeometry() +{ + m_VtkMatrix->Delete(); + m_VtkIndexToWorldTransform->Delete(); +} + +const mitk::Point3D& mitk::BaseGeometry::GetOrigin() const +{ + return m_Origin; +} + +void mitk::BaseGeometry::SetOrigin(const Point3D & origin) +{ + if(origin!=GetOrigin()) + { + m_Origin = origin; + m_IndexToWorldTransform->SetOffset(m_Origin.GetVectorFromOrigin()); + Modified(); + TransferItkToVtkTransform(); + } +} + +void mitk::BaseGeometry::TransferItkToVtkTransform() +{ + // copy m_IndexToWorldTransform into m_VtkIndexToWorldTransform + + TransferItkTransformToVtkMatrix(m_IndexToWorldTransform.GetPointer(), m_VtkMatrix); + m_VtkIndexToWorldTransform->Modified(); +} + +void mitk::BaseGeometry::CopySpacingFromTransform(mitk::AffineTransform3D* transform, mitk::Vector3D& spacing, float floatSpacing[3]) +{ + mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix; + vnlmatrix = transform->GetMatrix().GetVnlMatrix(); + + spacing[0]=vnlmatrix.get_column(0).magnitude(); + spacing[1]=vnlmatrix.get_column(1).magnitude(); + spacing[2]=vnlmatrix.get_column(2).magnitude(); + floatSpacing[0]=spacing[0]; + floatSpacing[1]=spacing[1]; + floatSpacing[2]=spacing[2]; +} + +void mitk::BaseGeometry::Initialize() +{ + float b[6] = {0,1,0,1,0,1}; + SetFloatBounds(b); + + if(m_IndexToWorldTransform.IsNull()) + m_IndexToWorldTransform = TransformType::New(); + else + m_IndexToWorldTransform->SetIdentity(); + CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing, m_FloatSpacing); + vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin); + + m_VtkMatrix->Identity(); + + m_TimeBounds[0]=ScalarTypeNumericTraits::NonpositiveMin(); m_TimeBounds[1]=ScalarTypeNumericTraits::max(); + + m_FrameOfReferenceID = 0; +} + +void mitk::BaseGeometry::SetFloatBounds(const float bounds[6]) +{ + mitk::BoundingBox::BoundsArrayType b; + const float *input = bounds; + int i=0; + for(mitk::BoundingBox::BoundsArrayType::Iterator it = b.Begin(); i < 6 ;++i) *it++ = (mitk::ScalarType)*input++; + SetBounds(b); +} + +void mitk::BaseGeometry::SetFloatBounds(const double bounds[6]) +{ + mitk::BoundingBox::BoundsArrayType b; + const double *input = bounds; + int i=0; + for(mitk::BoundingBox::BoundsArrayType::Iterator it = b.Begin(); i < 6 ;++i) *it++ = (mitk::ScalarType)*input++; + SetBounds(b); +} + +/** Initialize the geometry */ +void + mitk::BaseGeometry::InitializeGeometry(BaseGeometry* newGeometry) const +{ + newGeometry->SetBounds(m_BoundingBox->GetBounds()); + // we have to create a new transform!! + + if(m_IndexToWorldTransform) + { + TransformType::Pointer indexToWorldTransform = TransformType::New(); + indexToWorldTransform->SetCenter( m_IndexToWorldTransform->GetCenter() ); + indexToWorldTransform->SetMatrix( m_IndexToWorldTransform->GetMatrix() ); + indexToWorldTransform->SetOffset( m_IndexToWorldTransform->GetOffset() ); + newGeometry->SetIndexToWorldTransform(indexToWorldTransform); + } +} + +/** Set the bounds */ +void mitk::BaseGeometry::SetBounds(const BoundsArrayType& bounds) +{ + m_BoundingBox = BoundingBoxType::New(); + + BoundingBoxType::PointsContainer::Pointer pointscontainer = + BoundingBoxType::PointsContainer::New(); + BoundingBoxType::PointType p; + BoundingBoxType::PointIdentifier pointid; + + for(pointid=0; pointid<2;++pointid) + { + unsigned int i; + for(i=0; iInsertElement(pointid, p); + } + + m_BoundingBox->SetPoints(pointscontainer); + m_BoundingBox->ComputeBoundingBox(); + this->Modified(); +} + +void mitk::BaseGeometry::SetIndexToWorldTransform(mitk::AffineTransform3D* transform) +{ + if(m_IndexToWorldTransform.GetPointer() != transform) + { + m_IndexToWorldTransform = transform; + CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing, m_FloatSpacing); + vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin); + TransferItkToVtkTransform(); + Modified(); + } +} + +const mitk::BaseGeometry::BoundsArrayType mitk::BaseGeometry::GetBounds() const +{ + assert(m_BoundingBox.IsNotNull()); + return m_BoundingBox->GetBounds(); +} + +bool mitk::BaseGeometry::IsValid() const +{ + return m_Valid; +} diff --git a/Core/Code/DataManagement/mitkBaseGeometry.h b/Core/Code/DataManagement/mitkBaseGeometry.h new file mode 100644 index 0000000000..81471ed15b --- /dev/null +++ b/Core/Code/DataManagement/mitkBaseGeometry.h @@ -0,0 +1,307 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef BaseGeometry_H_HEADER_INCLUDED +#define BaseGeometry_H_HEADER_INCLUDED + +#include +#include +#include "mitkoperationactor.h" + +#include +#include "mitkvector.h" +#include +#include +#include "itkScalableAffineTransform.h" +#include + +class vtkMatrix4x4; +class vtkMatrixToLinearTransform; +class vtkLinearTransform; + +namespace mitk { + //##Documentation + //## @brief Standard 3D-BoundingBox typedef + //## + //## Standard 3D-BoundingBox typedef to get rid of template arguments (3D, type). + typedef itk::BoundingBox BoundingBox; + + //##Documentation + //## @brief Standard typedef for time-bounds + typedef itk::FixedArray TimeBounds; + typedef itk::FixedArray FixedArrayType; + + //##Documentation + //## @brief BaseGeometry xxxxxxxxxxxxxx + //## + //## xxxxxxxxxxx + //## + //## Rule: everything is in mm (ms) if not stated otherwise. + //## @ingroup Geometry + class MITK_CORE_EXPORT BaseGeometry : public itk::Object, public OperationActor + { + public: + mitkClassMacro(BaseGeometry, itk::Object); + + // ********************************** TypeDef ********************************** + + typedef itk::QuaternionRigidTransform< ScalarType > QuaternionTransformType; + typedef QuaternionTransformType::VnlQuaternionType VnlQuaternionType; + + typedef itk::ScalableAffineTransform TransformType; + typedef itk::BoundingBox BoundingBoxType; + typedef BoundingBoxType::BoundsArrayType BoundsArrayType; + typedef BoundingBoxType::Pointer BoundingBoxPointer; + + // ********************************** Origin, Spacing ********************************** + + //##Documentation + //## @brief Get the origin, e.g. the upper-left corner of the plane + const Point3D& GetOrigin() const; + + //##Documentation + //## @brief Set the origin, i.e. the upper-left corner of the plane + //## + virtual void SetOrigin(const Point3D& origin); + + //##Documentation + //## @brief Get the spacing (size of a pixel). + //## + itkGetConstReferenceMacro(Spacing, mitk::Vector3D); + + //##Documentation + //## @brief Get the spacing as a float[3] array. + const float* GetFloatSpacing() const; + + // ********************************** other functions ********************************** + + //##Documentation + //## @brief Get the DICOM FrameOfReferenceID referring to the + //## used world coordinate system + itkGetConstMacro(FrameOfReferenceID, unsigned int); + //##Documentation + //## @brief Set the DICOM FrameOfReferenceID referring to the + //## used world coordinate system + itkSetMacro(FrameOfReferenceID, unsigned int); + + //##Documentation + //## @brief Is this Geometry3D in a state that is valid? + virtual bool IsValid() const; + + // ********************************** Initialize ********************************** + + //##Documentation + //## @brief Initialize the Geometry3D + virtual void Initialize(); + + virtual void InitializeGeometry(Self * newGeometry) const; + + static void CopySpacingFromTransform(mitk::AffineTransform3D* transform, mitk::Vector3D& spacing, float floatSpacing[3]); + + // ********************************** Transformations Set/Get ********************************** + + // a bit of a misuse, but we want only doxygen to see the following: +#ifdef DOXYGEN_SKIP + //##Documentation + //## @brief Get the transformation used to convert from index + //## to world coordinates + itkGetObjectMacro(IndexToWorldTransform, AffineTransform3D); +#endif + //## @brief Set the transformation used to convert from index + //## to world coordinates + virtual void SetIndexToWorldTransform(mitk::AffineTransform3D* transform); + + /** Set/Get the IndexToWorldTransform */ + itkGetConstObjectMacro(IndexToWorldTransform, AffineTransform3D); + itkGetObjectMacro(IndexToWorldTransform, AffineTransform3D); + + // ********************************** Transformations ********************************** + + //##Documentation + //## @brief Copy the ITK transform + //## (m_IndexToWorldTransform) to the VTK transform + //## \sa SetIndexToWorldTransform + virtual void TransferItkToVtkTransform(); + + // ********************************** BoundingBox ********************************** + + //##Documentation + //## @brief Get the parametric bounding-box + //## + //## See AbstractTransformGeometry for an example usage of this. + itkGetConstObjectMacro(ParametricBoundingBox, BoundingBox); + //##Documentation + //## @brief Get the parametric bounds + //## + //## See AbstractTransformGeometry for an example usage of this. + // xx This was not vitrual! + //virtual const BoundingBox::BoundsArrayType& GetParametricBounds() const = 0 ; //ToDo + + /** Get the bounding box */ + itkGetConstObjectMacro(BoundingBox, BoundingBoxType); + + //##Documentation + //## @brief Get the time bounds (in ms) + itkGetConstReferenceMacro(TimeBounds, TimeBounds); + + const BoundsArrayType GetBounds() const; + + // a bit of a misuse, but we want only doxygen to see the following: +#ifdef DOXYGEN_SKIP + //##Documentation + //## @brief Get bounding box (in index/unit coordinates) + itkGetConstObjectMacro(BoundingBox, BoundingBoxType); + //##Documentation + //## @brief Get bounding box (in index/unit coordinates) as a BoundsArrayType + const BoundsArrayType GetBounds() const; +#endif + + //##Documentation + //## \brief Set the bounding box (in index/unit coordinates) + //## + //## Only possible via the BoundsArray to make clear that a + //## copy of the bounding-box is stored, not a reference to it. + virtual void SetBounds(const BoundsArrayType& bounds); + + //##Documentation + //## @brief Set the bounding box (in index/unit coordinates) via a float array + virtual void SetFloatBounds(const float bounds[6]); + //##Documentation + //## @brief Set the bounding box (in index/unit coordinates) via a double array + virtual void SetFloatBounds(const double bounds[6]); + + //##Documentation + //## @brief Set the time bounds (in ms) + //virtual void SetTimeBounds(const TimeBounds& timebounds) = 0 ; //ToDo + + // ********************************** Geometry ********************************** + +#ifdef DOXYGEN_SKIP + //##Documentation + //## @brief Get the extent of the bounding box (in index/unit coordinates) + //## + //## To access the extent in mm use GetExtentInMM + ScalarType GetExtent(unsigned int direction) const; +#endif + + protected: + + // ********************************** Constructor ********************************** + BaseGeometry(); + BaseGeometry(const BaseGeometry& other); + virtual ~BaseGeometry(); + + // ********************************** Variables ********************************** + + AffineTransform3D::Pointer m_IndexToWorldTransform; + + vtkMatrixToLinearTransform* m_VtkIndexToWorldTransform; + + vtkMatrix4x4* m_VtkMatrix; + + bool m_Valid; + + unsigned int m_FrameOfReferenceID; + + mutable mitk::BoundingBox::Pointer m_ParametricBoundingBox; + + mutable mitk::TimeBounds m_TimeBounds; + + mutable BoundingBoxPointer m_BoundingBox; + + //##Documentation + //## @brief Origin, i.e. upper-left corner of the plane + //## + Point3D m_Origin; + + //##Documentation + //## @brief Spacing of the data. Only significant if the geometry describes + //## an Image (m_ImageGeometry==true). + mitk::Vector3D m_Spacing; + + static const unsigned int NDimensions = 3; + + mutable TransformType::Pointer m_InvertedTransform; //this was private + + mutable unsigned long m_IndexToWorldTransformLastModified; //this was private + + float m_FloatSpacing[3]; //this was private + + // DEPRECATED(VnlQuaternionType m_RotationQuaternion); //this was private + }; +} // namespace mitk + +// ********************************** Equal Functions ********************************** + +// +// Static compare functions mainly for testing +// + +/** +* @brief Equal A function comparing two bounding boxes (BoundingBoxType) for beeing identical. +* +* @ingroup MITKTestingAPI +* +* The function compares the bounds (elementwise). +* +* The parameter eps is a tolarence value for all methods which are internally used for comparion. +* @param rightHandSide Compare this against leftHandSide. +* @param leftHandSide Compare this against rightHandSide. +* @param eps Tolarence for comparison. You can use mitk::eps in most cases. +* @param verbose Flag indicating if the user wants detailed console output or not. +* @return True, if all comparison are true. False in any other case. +*/ +MITK_CORE_EXPORT bool Equal( const mitk::BaseGeometry::BoundingBoxType *leftHandSide, const mitk::BaseGeometry::BoundingBoxType *rightHandSide, mitk::ScalarType eps, bool verbose); //ToDo + +// +// Static compare functions mainly for testing +// +/** +* @brief Equal A function comparing two geometries for beeing identical. +* +* @ingroup MITKTestingAPI +* +* The function compares the spacing, origin, axisvectors, extents, the matrix of the +* IndexToWorldTransform (elementwise), the bounding (elementwise) and the ImageGeometry flag. +* +* The parameter eps is a tolarence value for all methods which are internally used for comparion. +* If you want to use different tolarance values for different parts of the geometry, feel free to use +* the other comparison methods and write your own implementation of Equal. +* @param rightHandSide Compare this against leftHandSide. +* @param leftHandSide Compare this against rightHandSide. +* @param eps Tolarence for comparison. You can use mitk::eps in most cases. +* @param verbose Flag indicating if the user wants detailed console output or not. +* @return True, if all comparison are true. False in any other case. +*/ +MITK_CORE_EXPORT bool Equal(const mitk::BaseGeometry* leftHandSide, const mitk::BaseGeometry* rightHandSide, mitk::ScalarType eps, bool verbose); //ToDo + +/** +* @brief Equal A function comparing two transforms (TransformType) for beeing identical. +* +* @ingroup MITKTestingAPI +* +* The function compares the IndexToWorldTransform (elementwise). +* +* The parameter eps is a tolarence value for all methods which are internally used for comparion. +* @param rightHandSide Compare this against leftHandSide. +* @param leftHandSide Compare this against rightHandSide. +* @param eps Tolarence for comparison. You can use mitk::eps in most cases. +* @param verbose Flag indicating if the user wants detailed console output or not. +* @return True, if all comparison are true. False in any other case. +*/ +MITK_CORE_EXPORT bool Equal(const mitk::BaseGeometry::TransformType *leftHandSide, const mitk::BaseGeometry::TransformType *rightHandSide, mitk::ScalarType eps, bool verbose); //ToDo + +#endif /* BaseGeometry_H_HEADER_INCLUDED */ diff --git a/Core/Code/DataManagement/mitkGeometry2D.cpp b/Core/Code/DataManagement/mitkGeometry2D.cpp index 6f23c91710..2418c54ce0 100644 --- a/Core/Code/DataManagement/mitkGeometry2D.cpp +++ b/Core/Code/DataManagement/mitkGeometry2D.cpp @@ -1,284 +1,268 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ - #include "mitkGeometry2D.h" #include - mitk::Geometry2D::Geometry2D() : m_ScaleFactorMMPerUnitX( 1.0 ), - m_ScaleFactorMMPerUnitY( 1.0 ), - m_ReferenceGeometry( NULL ) + m_ScaleFactorMMPerUnitY( 1.0 ), + m_ReferenceGeometry( NULL ) { } mitk::Geometry2D::Geometry2D(const Geometry2D& other) : Geometry3D(other), m_ScaleFactorMMPerUnitX( other.m_ScaleFactorMMPerUnitX), - m_ScaleFactorMMPerUnitY( other.m_ScaleFactorMMPerUnitY), - m_ReferenceGeometry( other.m_ReferenceGeometry ) + m_ScaleFactorMMPerUnitY( other.m_ScaleFactorMMPerUnitY), + m_ReferenceGeometry( other.m_ReferenceGeometry ) { } - - mitk::Geometry2D::~Geometry2D() { } - void -mitk::Geometry2D::SetIndexToWorldTransform( + mitk::Geometry2D::SetIndexToWorldTransform( mitk::AffineTransform3D* transform) { Superclass::SetIndexToWorldTransform(transform); m_ScaleFactorMMPerUnitX=GetExtentInMM(0)/GetExtent(0); m_ScaleFactorMMPerUnitY=GetExtentInMM(1)/GetExtent(1); assert(m_ScaleFactorMMPerUnitX(m_BoundingBox.GetPointer())->IsInside(pt3d_units); } - void -mitk::Geometry2D::Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const + mitk::Geometry2D::Map(const mitk::Point2D &pt2d_mm, mitk::Point3D &pt3d_mm) const { Point3D pt3d_units; pt3d_units[0]=pt2d_mm[0]/m_ScaleFactorMMPerUnitX; pt3d_units[1]=pt2d_mm[1]/m_ScaleFactorMMPerUnitY; pt3d_units[2]=0; pt3d_mm = GetParametricTransform()->TransformPoint(pt3d_units); } - void -mitk::Geometry2D::IndexToWorld( + mitk::Geometry2D::IndexToWorld( const mitk::Point2D &/*pt_units*/, mitk::Point2D &/*pt_mm*/) const { itkExceptionMacro(<< "No general transform possible (only affine) ==> no general" \ " IndexToWorld(const mitk::Point2D &pt_mm, mitk::Point2D &pt_units)" \ " possible. Has to be implemented in sub-class."); } - void -mitk::Geometry2D::WorldToIndex( + mitk::Geometry2D::WorldToIndex( const mitk::Point2D &/*pt_mm*/, mitk::Point2D &/*pt_units*/) const { itkExceptionMacro(<< "No general back transform possible (only affine) ==> no general" \ " WorldToIndex(const mitk::Point2D &pt_mm, mitk::Point2D &pt_units)" \ " possible. Has to be implemented in sub-class."); } - void -mitk::Geometry2D::IndexToWorld(const mitk::Point2D &/*atPt2d_units*/, + mitk::Geometry2D::IndexToWorld(const mitk::Point2D &/*atPt2d_units*/, const mitk::Vector2D &/*vec_units*/, mitk::Vector2D &/*vec_mm*/) const { itkExceptionMacro(<< "No general transform possible (only affine) ==> no general" \ " IndexToWorld(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units)" \ " possible. Has to be implemented in sub-class."); } - void -mitk::Geometry2D::WorldToIndex(const mitk::Point2D &/*atPt2d_mm*/, + mitk::Geometry2D::WorldToIndex(const mitk::Point2D &/*atPt2d_mm*/, const mitk::Vector2D &/*vec_mm*/, mitk::Vector2D &/*vec_units*/) const { itkExceptionMacro(<< "No general back transform possible (only affine) ==> no general" \ " WorldToIndex(const mitk::Vector2D &vec_mm, mitk::Vector2D &vec_units)" \ " possible. Has to be implemented in sub-class."); } void -mitk::Geometry2D::SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height) + mitk::Geometry2D::SetSizeInUnits(mitk::ScalarType width, mitk::ScalarType height) { ScalarType bounds[6]={0, width, 0, height, 0, 1}; ScalarType extent, newextentInMM; if(GetExtent(0)>0) { extent = GetExtent(0); if(width>extent) newextentInMM = GetExtentInMM(0)/width*extent; else newextentInMM = GetExtentInMM(0)*extent/width; SetExtentInMM(0, newextentInMM); } if(GetExtent(1)>0) { extent = GetExtent(1); if(width>extent) newextentInMM = GetExtentInMM(1)/height*extent; else newextentInMM = GetExtentInMM(1)*extent/height; SetExtentInMM(1, newextentInMM); } SetBounds(bounds); } - bool -mitk::Geometry2D::Project( + mitk::Geometry2D::Project( const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const { assert(m_BoundingBox.IsNotNull()); Point3D pt3d_units; BackTransform(pt3d_mm, pt3d_units); pt3d_units[2] = 0; projectedPt3d_mm = GetParametricTransform()->TransformPoint(pt3d_units); return const_cast(m_BoundingBox.GetPointer())->IsInside(pt3d_units); } bool -mitk::Geometry2D::Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const + mitk::Geometry2D::Project(const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const { - assert(m_BoundingBox.IsNotNull()); + assert(m_BoundingBox.IsNotNull()); - Vector3D vec3d_units; - BackTransform(vec3d_mm, vec3d_units); - vec3d_units[2] = 0; - projectedVec3d_mm = GetParametricTransform()->TransformVector(vec3d_units); - return true; + Vector3D vec3d_units; + BackTransform(vec3d_mm, vec3d_units); + vec3d_units[2] = 0; + projectedVec3d_mm = GetParametricTransform()->TransformVector(vec3d_units); + return true; } bool -mitk::Geometry2D::Project(const mitk::Point3D & atPt3d_mm, - const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const + mitk::Geometry2D::Project(const mitk::Point3D & atPt3d_mm, + const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm) const { - MITK_WARN << "Deprecated function! Call Project(vec3D,vec3D) instead."; - assert(m_BoundingBox.IsNotNull()); + MITK_WARN << "Deprecated function! Call Project(vec3D,vec3D) instead."; + assert(m_BoundingBox.IsNotNull()); - Vector3D vec3d_units; - BackTransform(atPt3d_mm, vec3d_mm, vec3d_units); - vec3d_units[2] = 0; - projectedVec3d_mm = GetParametricTransform()->TransformVector(vec3d_units); + Vector3D vec3d_units; + BackTransform(atPt3d_mm, vec3d_mm, vec3d_units); + vec3d_units[2] = 0; + projectedVec3d_mm = GetParametricTransform()->TransformVector(vec3d_units); - Point3D pt3d_units; - BackTransform(atPt3d_mm, pt3d_units); - return const_cast(m_BoundingBox.GetPointer())->IsInside(pt3d_units); + Point3D pt3d_units; + BackTransform(atPt3d_mm, pt3d_units); + return const_cast(m_BoundingBox.GetPointer())->IsInside(pt3d_units); } - bool -mitk::Geometry2D::Map(const mitk::Point3D & atPt3d_mm, + mitk::Geometry2D::Map(const mitk::Point3D & atPt3d_mm, const mitk::Vector3D &vec3d_mm, mitk::Vector2D &vec2d_mm) const { Point2D pt2d_mm_start, pt2d_mm_end; Point3D pt3d_mm_end; bool inside=Map(atPt3d_mm, pt2d_mm_start); pt3d_mm_end = atPt3d_mm+vec3d_mm; inside&=Map(pt3d_mm_end, pt2d_mm_end); vec2d_mm=pt2d_mm_end-pt2d_mm_start; return inside; } - void -mitk::Geometry2D::Map(const mitk::Point2D &/*atPt2d_mm*/, + mitk::Geometry2D::Map(const mitk::Point2D &/*atPt2d_mm*/, const mitk::Vector2D &/*vec2d_mm*/, mitk::Vector3D &/*vec3d_mm*/) const { //@todo implement parallel to the other Map method! assert(false); } - mitk::ScalarType -mitk::Geometry2D::SignedDistance(const mitk::Point3D& pt3d_mm) const + mitk::Geometry2D::SignedDistance(const mitk::Point3D& pt3d_mm) const { Point3D projectedPoint; Project(pt3d_mm, projectedPoint); Vector3D direction = pt3d_mm-projectedPoint; ScalarType distance = direction.GetNorm(); if(IsAbove(pt3d_mm) == false) distance*=-1.0; return distance; } bool -mitk::Geometry2D::IsAbove(const mitk::Point3D& pt3d_mm) const + mitk::Geometry2D::IsAbove(const mitk::Point3D& pt3d_mm) const { Point3D pt3d_units; Geometry3D::WorldToIndex(pt3d_mm, pt3d_units); return (pt3d_units[2] > m_BoundingBox->GetBounds()[4]); } itk::LightObject::Pointer -mitk::Geometry2D::InternalClone() const + mitk::Geometry2D::InternalClone() const { Self::Pointer newGeometry = new Geometry2D(*this); newGeometry->UnRegister(); return newGeometry.GetPointer(); } void -mitk::Geometry2D::PrintSelf(std::ostream& os, itk::Indent indent) const + mitk::Geometry2D::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os,indent); os << indent << " ScaleFactorMMPerUnitX: " - << m_ScaleFactorMMPerUnitX << std::endl; + << m_ScaleFactorMMPerUnitX << std::endl; os << indent << " ScaleFactorMMPerUnitY: " - << m_ScaleFactorMMPerUnitY << std::endl; + << m_ScaleFactorMMPerUnitY << std::endl; } void -mitk::Geometry2D::SetReferenceGeometry( mitk::Geometry3D *geometry ) + mitk::Geometry2D::SetReferenceGeometry( mitk::Geometry3D *geometry ) { m_ReferenceGeometry = geometry; } mitk::Geometry3D * -mitk::Geometry2D::GetReferenceGeometry() const + mitk::Geometry2D::GetReferenceGeometry() const { return m_ReferenceGeometry; } bool -mitk::Geometry2D::HasReferenceGeometry() const + mitk::Geometry2D::HasReferenceGeometry() const { return ( m_ReferenceGeometry != NULL ); } diff --git a/Core/Code/DataManagement/mitkGeometry3D.cpp b/Core/Code/DataManagement/mitkGeometry3D.cpp index c208fc1293..1e41208028 100644 --- a/Core/Code/DataManagement/mitkGeometry3D.cpp +++ b/Core/Code/DataManagement/mitkGeometry3D.cpp @@ -1,973 +1,815 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ - #include #include #include "mitkGeometry3D.h" -#include "mitkMatrixConvert.h" + #include "mitkRotationOperation.h" #include "mitkRestorePlanePositionOperation.h" #include "mitkApplyTransformMatrixOperation.h" #include "mitkPointOperation.h" #include "mitkInteractionConst.h" - #include #include +#include "mitkMatrixConvert.h" // Standard constructor for the New() macro. Sets the geometry to 3 dimensions -mitk::Geometry3D::Geometry3D() - : m_ParametricBoundingBox(NULL), - m_ImageGeometry(false), m_Valid(true), m_FrameOfReferenceID(0), m_IndexToWorldTransformLastModified(0) -{ - FillVector3D(m_FloatSpacing, 1,1,1); - m_VtkMatrix = vtkMatrix4x4::New(); - m_VtkIndexToWorldTransform = vtkMatrixToLinearTransform::New(); - m_VtkIndexToWorldTransform->SetInput(m_VtkMatrix); - Initialize(); -} -mitk::Geometry3D::Geometry3D(const Geometry3D& other) : Superclass(), mitk::OperationActor(), m_ParametricBoundingBox(other.m_ParametricBoundingBox),m_TimeBounds(other.m_TimeBounds), - m_ImageGeometry(other.m_ImageGeometry), m_Valid(other.m_Valid), m_FrameOfReferenceID(other.m_FrameOfReferenceID), m_IndexToWorldTransformLastModified(other.m_IndexToWorldTransformLastModified), m_RotationQuaternion( other.m_RotationQuaternion ) , m_Origin(other.m_Origin) -{ - // AffineGeometryFrame - SetBounds(other.GetBounds()); - //SetIndexToObjectTransform(other.GetIndexToObjectTransform()); - //SetObjectToNodeTransform(other.GetObjectToNodeTransform()); - //SetIndexToWorldTransform(other.GetIndexToWorldTransform()); - // this is not used in AffineGeometryFrame of ITK, thus there are not Get and Set methods - // m_IndexToNodeTransform = other.m_IndexToNodeTransform; - // m_InvertedTransform = TransformType::New(); - // m_InvertedTransform = TransformType::New(); - // m_InvertedTransform->DeepCopy(other.m_InvertedTransform); - m_VtkMatrix = vtkMatrix4x4::New(); - m_VtkMatrix->DeepCopy(other.m_VtkMatrix); - if (other.m_ParametricBoundingBox.IsNotNull()) - { - m_ParametricBoundingBox = other.m_ParametricBoundingBox->DeepCopy(); - } - FillVector3D(m_FloatSpacing,other.m_FloatSpacing[0],other.m_FloatSpacing[1],other.m_FloatSpacing[2]); - m_VtkIndexToWorldTransform = vtkMatrixToLinearTransform::New(); - m_VtkIndexToWorldTransform->DeepCopy(other.m_VtkIndexToWorldTransform); - m_VtkIndexToWorldTransform->SetInput(m_VtkMatrix); - other.InitializeGeometry(this); -} - -mitk::Geometry3D::~Geometry3D() +mitk::Geometry3D::Geometry3D() : m_ImageGeometry(false) { - m_VtkMatrix->Delete(); - m_VtkIndexToWorldTransform->Delete(); } - - -static void CopySpacingFromTransform(mitk::AffineTransform3D* transform, mitk::Vector3D& spacing, float floatSpacing[3]) +mitk::Geometry3D::Geometry3D(const Geometry3D& other) : BaseGeometry(other), m_ImageGeometry(other.m_ImageGeometry) { - mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix; - vnlmatrix = transform->GetMatrix().GetVnlMatrix(); - - spacing[0]=vnlmatrix.get_column(0).magnitude(); - spacing[1]=vnlmatrix.get_column(1).magnitude(); - spacing[2]=vnlmatrix.get_column(2).magnitude(); - floatSpacing[0]=spacing[0]; - floatSpacing[1]=spacing[1]; - floatSpacing[2]=spacing[2]; } - -void mitk::Geometry3D::Initialize() -{ - float b[6] = {0,1,0,1,0,1}; - SetFloatBounds(b); - - if(m_IndexToWorldTransform.IsNull()) - m_IndexToWorldTransform = TransformType::New(); - else - m_IndexToWorldTransform->SetIdentity(); - CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing, m_FloatSpacing); - vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin); - - m_VtkMatrix->Identity(); - - m_TimeBounds[0]=ScalarTypeNumericTraits::NonpositiveMin(); m_TimeBounds[1]=ScalarTypeNumericTraits::max(); - - m_FrameOfReferenceID = 0; - - m_ImageGeometry = false; -} - -void mitk::Geometry3D::TransferItkToVtkTransform() +mitk::Geometry3D::~Geometry3D() { - // copy m_IndexToWorldTransform into m_VtkIndexToWorldTransform - TransferItkTransformToVtkMatrix(m_IndexToWorldTransform.GetPointer(), m_VtkMatrix); - m_VtkIndexToWorldTransform->Modified(); } void mitk::Geometry3D::TransferVtkToItkTransform() { TransferVtkMatrixToItkTransform(m_VtkMatrix, m_IndexToWorldTransform.GetPointer()); CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing, m_FloatSpacing); vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin); } void mitk::Geometry3D::SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4* vtkmatrix) { m_VtkMatrix->DeepCopy(vtkmatrix); TransferVtkToItkTransform(); } void mitk::Geometry3D::SetTimeBounds(const TimeBounds& timebounds) { if(m_TimeBounds != timebounds) { m_TimeBounds = timebounds; Modified(); } } -void mitk::Geometry3D::SetFloatBounds(const float bounds[6]) -{ - mitk::BoundingBox::BoundsArrayType b; - const float *input = bounds; - int i=0; - for(mitk::BoundingBox::BoundsArrayType::Iterator it = b.Begin(); i < 6 ;++i) *it++ = (mitk::ScalarType)*input++; - SetBounds(b); -} - -void mitk::Geometry3D::SetFloatBounds(const double bounds[6]) -{ - mitk::BoundingBox::BoundsArrayType b; - const double *input = bounds; - int i=0; - for(mitk::BoundingBox::BoundsArrayType::Iterator it = b.Begin(); i < 6 ;++i) *it++ = (mitk::ScalarType)*input++; - SetBounds(b); -} - void mitk::Geometry3D::SetParametricBounds(const BoundingBox::BoundsArrayType& bounds) { m_ParametricBoundingBox = BoundingBoxType::New(); BoundingBoxType::PointsContainer::Pointer pointscontainer = - BoundingBoxType::PointsContainer::New(); + BoundingBoxType::PointsContainer::New(); BoundingBoxType::PointType p; BoundingBoxType::PointIdentifier pointid; for(pointid=0; pointid<2;++pointid) - { + { unsigned int i; for(i=0; iInsertElement(pointid, p); } + pointscontainer->InsertElement(pointid, p); + } m_ParametricBoundingBox->SetPoints(pointscontainer); m_ParametricBoundingBox->ComputeBoundingBox(); this->Modified(); } void mitk::Geometry3D::WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const { BackTransform(pt_mm, pt_units); } void mitk::Geometry3D::IndexToWorld(const mitk::Point3D &pt_units, mitk::Point3D &pt_mm) const { pt_mm = m_IndexToWorldTransform->TransformPoint(pt_units); } void mitk::Geometry3D::WorldToIndex(const mitk::Point3D & /*atPt3d_mm*/, const mitk::Vector3D &vec_mm, mitk::Vector3D &vec_units) const { MITK_WARN<<"Warning! Call of the deprecated function Geometry3D::WorldToIndex(point, vec, vec). Use Geometry3D::WorldToIndex(vec, vec) instead!"; //BackTransform(atPt3d_mm, vec_mm, vec_units); this->WorldToIndex(vec_mm, vec_units); } void mitk::Geometry3D::WorldToIndex( const mitk::Vector3D &vec_mm, mitk::Vector3D &vec_units) const { BackTransform( vec_mm, vec_units); } void mitk::Geometry3D::IndexToWorld(const mitk::Point3D &/*atPt3d_units*/, const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const { MITK_WARN<<"Warning! Call of the deprecated function Geometry3D::IndexToWorld(point, vec, vec). Use Geometry3D::IndexToWorld(vec, vec) instead!"; //vec_mm = m_IndexToWorldTransform->TransformVector(vec_units); this->IndexToWorld(vec_units, vec_mm); } void mitk::Geometry3D::IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const { vec_mm = m_IndexToWorldTransform->TransformVector(vec_units); } -void mitk::Geometry3D::SetIndexToWorldTransform(mitk::AffineTransform3D* transform) -{ - if(m_IndexToWorldTransform.GetPointer() != transform) - { - m_IndexToWorldTransform = transform; - CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing, m_FloatSpacing); - vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin); - TransferItkToVtkTransform(); - Modified(); - } -} - itk::LightObject::Pointer mitk::Geometry3D::InternalClone() const { Self::Pointer newGeometry = new Self(*this); newGeometry->UnRegister(); return newGeometry.GetPointer(); } /* void mitk::Geometry3D::InitializeGeometry(Geometry3D * newGeometry) const { - Superclass::InitializeGeometry(newGeometry); +Superclass::InitializeGeometry(newGeometry); - newGeometry->SetTimeBounds(m_TimeBounds); +newGeometry->SetTimeBounds(m_TimeBounds); - //newGeometry->GetVtkTransform()->SetMatrix(m_VtkIndexToWorldTransform->GetMatrix()); IW - //newGeometry->TransferVtkToItkTransform(); //MH +//newGeometry->GetVtkTransform()->SetMatrix(m_VtkIndexToWorldTransform->GetMatrix()); IW +//newGeometry->TransferVtkToItkTransform(); //MH - newGeometry->SetFrameOfReferenceID(GetFrameOfReferenceID()); - newGeometry->m_ImageGeometry = m_ImageGeometry; +newGeometry->SetFrameOfReferenceID(GetFrameOfReferenceID()); +newGeometry->m_ImageGeometry = m_ImageGeometry; } */ void mitk::Geometry3D::SetExtentInMM(int direction, ScalarType extentInMM) { ScalarType len = GetExtentInMM(direction); if(fabs(len - extentInMM)>=mitk::eps) { AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix; vnlmatrix = m_IndexToWorldTransform->GetMatrix().GetVnlMatrix(); if(len>extentInMM) vnlmatrix.set_column(direction, vnlmatrix.get_column(direction)/len*extentInMM); else vnlmatrix.set_column(direction, vnlmatrix.get_column(direction)*extentInMM/len); Matrix3D matrix; matrix = vnlmatrix; m_IndexToWorldTransform->SetMatrix(matrix); Modified(); } } mitk::BoundingBox::Pointer mitk::Geometry3D::CalculateBoundingBoxRelativeToTransform(const mitk::AffineTransform3D* transform) const { mitk::BoundingBox::PointsContainer::Pointer pointscontainer=mitk::BoundingBox::PointsContainer::New(); mitk::BoundingBox::PointIdentifier pointid=0; unsigned char i; if(transform!=NULL) { mitk::AffineTransform3D::Pointer inverse = mitk::AffineTransform3D::New(); transform->GetInverse(inverse); for(i=0; i<8; ++i) pointscontainer->InsertElement( pointid++, inverse->TransformPoint( GetCornerPoint(i) )); } else { for(i=0; i<8; ++i) pointscontainer->InsertElement( pointid++, GetCornerPoint(i) ); } mitk::BoundingBox::Pointer result = mitk::BoundingBox::New(); result->SetPoints(pointscontainer); result->ComputeBoundingBox(); return result; } #include void mitk::Geometry3D::ExecuteOperation(Operation* operation) { vtkTransform *vtktransform = vtkTransform::New(); vtktransform->SetMatrix(m_VtkMatrix); switch (operation->GetOperationType()) { case OpNOTHING: break; case OpMOVE: { mitk::PointOperation *pointOp = dynamic_cast(operation); if (pointOp == NULL) { //mitk::StatusBar::GetInstance()->DisplayText("received wrong type of operation!See mitkAffineInteractor.cpp", 10000); return; } mitk::Point3D newPos = pointOp->GetPoint(); ScalarType data[3]; vtktransform->GetPosition(data); vtktransform->PostMultiply(); vtktransform->Translate(newPos[0], newPos[1], newPos[2]); vtktransform->PreMultiply(); break; } case OpSCALE: { mitk::PointOperation *pointOp = dynamic_cast(operation); if (pointOp == NULL) { //mitk::StatusBar::GetInstance()->DisplayText("received wrong type of operation!See mitkAffineInteractor.cpp", 10000); return; } mitk::Point3D newScale = pointOp->GetPoint(); ScalarType data[3]; /* calculate new scale: newscale = oldscale * (oldscale + scaletoadd)/oldscale */ data[0] = 1 + (newScale[0] / GetMatrixColumn(0).magnitude()); data[1] = 1 + (newScale[1] / GetMatrixColumn(1).magnitude()); data[2] = 1 + (newScale[2] / GetMatrixColumn(2).magnitude()); mitk::Point3D center = const_cast(m_BoundingBox.GetPointer())->GetCenter(); ScalarType pos[3]; vtktransform->GetPosition(pos); vtktransform->PostMultiply(); vtktransform->Translate(-pos[0], -pos[1], -pos[2]); vtktransform->Translate(-center[0], -center[1], -center[2]); vtktransform->PreMultiply(); vtktransform->Scale(data[0], data[1], data[2]); vtktransform->PostMultiply(); vtktransform->Translate(+center[0], +center[1], +center[2]); vtktransform->Translate(pos[0], pos[1], pos[2]); vtktransform->PreMultiply(); break; } case OpROTATE: { mitk::RotationOperation *rotateOp = dynamic_cast(operation); if (rotateOp == NULL) { //mitk::StatusBar::GetInstance()->DisplayText("received wrong type of operation!See mitkAffineInteractor.cpp", 10000); return; } Vector3D rotationVector = rotateOp->GetVectorOfRotation(); Point3D center = rotateOp->GetCenterOfRotation(); ScalarType angle = rotateOp->GetAngleOfRotation(); vtktransform->PostMultiply(); vtktransform->Translate(-center[0], -center[1], -center[2]); vtktransform->RotateWXYZ(angle, rotationVector[0], rotationVector[1], rotationVector[2]); vtktransform->Translate(center[0], center[1], center[2]); vtktransform->PreMultiply(); break; } case OpRESTOREPLANEPOSITION: - { + { //Copy necessary to avoid vtk warning vtkMatrix4x4* matrix = vtkMatrix4x4::New(); TransferItkTransformToVtkMatrix(dynamic_cast(operation)->GetTransform().GetPointer(), matrix); vtktransform->SetMatrix(matrix); break; - } + } case OpAPPLYTRANSFORMMATRIX: - { - ApplyTransformMatrixOperation *applyMatrixOp = dynamic_cast< ApplyTransformMatrixOperation* >( operation ); - vtktransform->SetMatrix(applyMatrixOp->GetMatrix()); - break; - } + { + ApplyTransformMatrixOperation *applyMatrixOp = dynamic_cast< ApplyTransformMatrixOperation* >( operation ); + vtktransform->SetMatrix(applyMatrixOp->GetMatrix()); + break; + } default: vtktransform->Delete(); return; } m_VtkMatrix->DeepCopy(vtktransform->GetMatrix()); TransferVtkToItkTransform(); Modified(); vtktransform->Delete(); } void mitk::Geometry3D::BackTransform(const mitk::Point3D &in, mitk::Point3D& out) const { ScalarType temp[3]; unsigned int i, j; const TransformType::OffsetType& offset = m_IndexToWorldTransform->GetOffset(); // Remove offset for (j = 0; j < 3; j++) { temp[j] = in[j] - offset[j]; } // Get WorldToIndex transform if (m_IndexToWorldTransformLastModified != m_IndexToWorldTransform->GetMTime()) { m_InvertedTransform = TransformType::New(); if (!m_IndexToWorldTransform->GetInverse( m_InvertedTransform.GetPointer() )) { itkExceptionMacro( "Internal ITK matrix inversion error, cannot proceed." ); } m_IndexToWorldTransformLastModified = m_IndexToWorldTransform->GetMTime(); } // Check for valid matrix inversion const TransformType::MatrixType& inverse = m_InvertedTransform->GetMatrix(); if(inverse.GetVnlMatrix().has_nans()) { itkExceptionMacro( "Internal ITK matrix inversion error, cannot proceed. Matrix was: " << std::endl << m_IndexToWorldTransform->GetMatrix() << "Suggested inverted matrix is:" << std::endl << inverse ); } // Transform point for (i = 0; i < 3; i++) { out[i] = 0.0; for (j = 0; j < 3; j++) { out[i] += inverse[i][j]*temp[j]; } } } void mitk::Geometry3D::BackTransform(const mitk::Point3D &/*at*/, const mitk::Vector3D &in, mitk::Vector3D& out) const { MITK_INFO<<"Warning! Call of the deprecated function Geometry3D::BackTransform(point, vec, vec). Use Geometry3D::BackTransform(vec, vec) instead!"; //// Get WorldToIndex transform //if (m_IndexToWorldTransformLastModified != m_IndexToWorldTransform->GetMTime()) //{ // m_InvertedTransform = TransformType::New(); // if (!m_IndexToWorldTransform->GetInverse( m_InvertedTransform.GetPointer() )) // { // itkExceptionMacro( "Internal ITK matrix inversion error, cannot proceed." ); // } // m_IndexToWorldTransformLastModified = m_IndexToWorldTransform->GetMTime(); //} //// Check for valid matrix inversion //const TransformType::MatrixType& inverse = m_InvertedTransform->GetMatrix(); //if(inverse.GetVnlMatrix().has_nans()) //{ // itkExceptionMacro( "Internal ITK matrix inversion error, cannot proceed. Matrix was: " << std::endl // << m_IndexToWorldTransform->GetMatrix() << "Suggested inverted matrix is:" << std::endl // << inverse ); //} //// Transform vector //for (unsigned int i = 0; i < 3; i++) //{ // out[i] = 0.0; // for (unsigned int j = 0; j < 3; j++) // { // out[i] += inverse[i][j]*in[j]; // } //} this->BackTransform(in, out); } void mitk::Geometry3D::BackTransform(const mitk::Vector3D& in, mitk::Vector3D& out) const { // Get WorldToIndex transform if (m_IndexToWorldTransformLastModified != m_IndexToWorldTransform->GetMTime()) { m_InvertedTransform = TransformType::New(); if (!m_IndexToWorldTransform->GetInverse( m_InvertedTransform.GetPointer() )) { itkExceptionMacro( "Internal ITK matrix inversion error, cannot proceed." ); } m_IndexToWorldTransformLastModified = m_IndexToWorldTransform->GetMTime(); } // Check for valid matrix inversion const TransformType::MatrixType& inverse = m_InvertedTransform->GetMatrix(); if(inverse.GetVnlMatrix().has_nans()) { itkExceptionMacro( "Internal ITK matrix inversion error, cannot proceed. Matrix was: " << std::endl << m_IndexToWorldTransform->GetMatrix() << "Suggested inverted matrix is:" << std::endl << inverse ); } // Transform vector for (unsigned int i = 0; i < 3; i++) { out[i] = 0.0; for (unsigned int j = 0; j < 3; j++) { out[i] += inverse[i][j]*in[j]; } } } const float* mitk::Geometry3D::GetFloatSpacing() const { return m_FloatSpacing; } void mitk::Geometry3D::SetSpacing(const mitk::Vector3D& aSpacing) { if(mitk::Equal(m_Spacing, aSpacing) == false) { assert(aSpacing[0]>0 && aSpacing[1]>0 && aSpacing[2]>0); m_Spacing = aSpacing; AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix; vnlmatrix = m_IndexToWorldTransform->GetMatrix().GetVnlMatrix(); mitk::VnlVector col; col = vnlmatrix.get_column(0); col.normalize(); col*=aSpacing[0]; vnlmatrix.set_column(0, col); col = vnlmatrix.get_column(1); col.normalize(); col*=aSpacing[1]; vnlmatrix.set_column(1, col); col = vnlmatrix.get_column(2); col.normalize(); col*=aSpacing[2]; vnlmatrix.set_column(2, col); Matrix3D matrix; matrix = vnlmatrix; AffineTransform3D::Pointer transform = AffineTransform3D::New(); transform->SetMatrix(matrix); transform->SetOffset(m_IndexToWorldTransform->GetOffset()); SetIndexToWorldTransform(transform.GetPointer()); itk2vtk(m_Spacing, m_FloatSpacing); } } -void mitk::Geometry3D::SetOrigin(const Point3D & origin) +void mitk::Geometry3D::Translate(const Vector3D & vector) { - if(origin!=GetOrigin()) + if((vector[0] != 0) || (vector[1] != 0) || (vector[2] != 0)) { - m_Origin = origin; - m_IndexToWorldTransform->SetOffset(m_Origin.GetVectorFromOrigin()); - Modified(); - TransferItkToVtkTransform(); + this->SetOrigin(m_Origin + vector); + // m_IndexToWorldTransform->SetOffset(m_IndexToWorldTransform->GetOffset()+vector); + // TransferItkToVtkTransform(); + // Modified(); } } -void mitk::Geometry3D::Translate(const Vector3D & vector) -{ - if((vector[0] != 0) || (vector[1] != 0) || (vector[2] != 0)) - { - this->SetOrigin(m_Origin + vector); -// m_IndexToWorldTransform->SetOffset(m_IndexToWorldTransform->GetOffset()+vector); -// TransferItkToVtkTransform(); -// Modified(); - } -} - void mitk::Geometry3D::SetIdentity() { m_IndexToWorldTransform->SetIdentity(); m_Origin.Fill(0); Modified(); TransferItkToVtkTransform(); } void mitk::Geometry3D::Compose( const mitk::Geometry3D::TransformType * other, bool pre ) { m_IndexToWorldTransform->Compose(other, pre); CopySpacingFromTransform(m_IndexToWorldTransform, m_Spacing, m_FloatSpacing); vtk2itk(m_IndexToWorldTransform->GetOffset(), m_Origin); Modified(); TransferItkToVtkTransform(); } void mitk::Geometry3D::Compose( const vtkMatrix4x4 * vtkmatrix, bool pre ) { mitk::Geometry3D::TransformType::Pointer itkTransform = mitk::Geometry3D::TransformType::New(); TransferVtkMatrixToItkTransform(vtkmatrix, itkTransform.GetPointer()); Compose(itkTransform, pre); } const std::string mitk::Geometry3D::GetTransformAsString( TransformType* transformType ) { std::ostringstream out; out << '['; for( int i=0; i<3; ++i ) { out << '['; for( int j=0; j<3; ++j ) out << transformType->GetMatrix().GetVnlMatrix().get(i, j) << ' '; out << ']'; } out << "]["; for( int i=0; i<3; ++i ) out << transformType->GetOffset()[i] << ' '; out << "]\0"; return out.str(); } void mitk::Geometry3D::PrintSelf(std::ostream& os, itk::Indent indent) const { os << indent << " IndexToWorldTransform: "; if(m_IndexToWorldTransform.IsNull()) os << "NULL" << std::endl; else { // from itk::MatrixOffsetTransformBase unsigned int i, j; os << std::endl; os << indent << "Matrix: " << std::endl; for (i = 0; i < 3; i++) { os << indent.GetNextIndent(); for (j = 0; j < 3; j++) { os << m_IndexToWorldTransform->GetMatrix()[i][j] << " "; } os << std::endl; } os << indent << "Offset: " << m_IndexToWorldTransform->GetOffset() << std::endl; os << indent << "Center: " << m_IndexToWorldTransform->GetCenter() << std::endl; os << indent << "Translation: " << m_IndexToWorldTransform->GetTranslation() << std::endl; os << indent << "Inverse: " << std::endl; for (i = 0; i < 3; i++) { os << indent.GetNextIndent(); for (j = 0; j < 3; j++) { os << m_IndexToWorldTransform->GetInverseMatrix()[i][j] << " "; } os << std::endl; } // from itk::ScalableAffineTransform os << indent << "Scale : "; for (i = 0; i < 3; i++) { os << m_IndexToWorldTransform->GetScale()[i] << " "; } os << std::endl; } os << indent << " BoundingBox: "; if(m_BoundingBox.IsNull()) os << "NULL" << std::endl; else { os << indent << "( "; for (unsigned int i=0; i<3; i++) { os << m_BoundingBox->GetBounds()[2*i] << "," << m_BoundingBox->GetBounds()[2*i+1] << " "; } os << " )" << std::endl; } os << indent << " Origin: " << m_Origin << std::endl; os << indent << " ImageGeometry: " << m_ImageGeometry << std::endl; os << indent << " Spacing: " << m_Spacing << std::endl; os << indent << " TimeBounds: " << m_TimeBounds << std::endl; } mitk::Point3D mitk::Geometry3D::GetCornerPoint(int id) const { assert(id >= 0); assert(m_BoundingBox.IsNotNull()); BoundingBox::BoundsArrayType bounds = m_BoundingBox->GetBounds(); Point3D cornerpoint; switch(id) { case 0: FillVector3D(cornerpoint, bounds[0],bounds[2],bounds[4]); break; case 1: FillVector3D(cornerpoint, bounds[0],bounds[2],bounds[5]); break; case 2: FillVector3D(cornerpoint, bounds[0],bounds[3],bounds[4]); break; case 3: FillVector3D(cornerpoint, bounds[0],bounds[3],bounds[5]); break; case 4: FillVector3D(cornerpoint, bounds[1],bounds[2],bounds[4]); break; case 5: FillVector3D(cornerpoint, bounds[1],bounds[2],bounds[5]); break; case 6: FillVector3D(cornerpoint, bounds[1],bounds[3],bounds[4]); break; case 7: FillVector3D(cornerpoint, bounds[1],bounds[3],bounds[5]); break; default: { itkExceptionMacro(<<"A cube only has 8 corners. These are labeled 0-7."); } } if(m_ImageGeometry) { // Here i have to adjust the 0.5 offset manually, because the cornerpoint is the corner of the // bounding box. The bounding box itself is no image, so it is corner-based FillVector3D(cornerpoint, cornerpoint[0]-0.5, cornerpoint[1]-0.5, cornerpoint[2]-0.5); } return m_IndexToWorldTransform->TransformPoint(cornerpoint); } mitk::Point3D mitk::Geometry3D::GetCornerPoint(bool xFront, bool yFront, bool zFront) const { assert(m_BoundingBox.IsNotNull()); BoundingBox::BoundsArrayType bounds = m_BoundingBox->GetBounds(); Point3D cornerpoint; cornerpoint[0] = (xFront ? bounds[0] : bounds[1]); cornerpoint[1] = (yFront ? bounds[2] : bounds[3]); cornerpoint[2] = (zFront ? bounds[4] : bounds[5]); if(m_ImageGeometry) { // Here i have to adjust the 0.5 offset manually, because the cornerpoint is the corner of the // bounding box. The bounding box itself is no image, so it is corner-based FillVector3D(cornerpoint, cornerpoint[0]-0.5, cornerpoint[1]-0.5, cornerpoint[2]-0.5); } return m_IndexToWorldTransform->TransformPoint(cornerpoint); } void -mitk::Geometry3D::ResetSubTransforms() + mitk::Geometry3D::ResetSubTransforms() { } void -mitk::Geometry3D::ChangeImageGeometryConsideringOriginOffset( const bool isAnImageGeometry ) + mitk::Geometry3D::ChangeImageGeometryConsideringOriginOffset( const bool isAnImageGeometry ) { // If Geometry is switched to ImageGeometry, you have to put an offset to the origin, because // imageGeometries origins are pixel-center-based // ... and remove the offset, if you switch an imageGeometry back to a normal geometry // For more information please see the Geometry documentation page if(m_ImageGeometry == isAnImageGeometry) return; const BoundingBox::BoundsArrayType& boundsarray = this->GetBoundingBox()->GetBounds(); Point3D originIndex; FillVector3D(originIndex, boundsarray[0], boundsarray[2], boundsarray[4]); if(isAnImageGeometry == true) FillVector3D( originIndex, - originIndex[0] + 0.5, - originIndex[1] + 0.5, - originIndex[2] + 0.5 ); + originIndex[0] + 0.5, + originIndex[1] + 0.5, + originIndex[2] + 0.5 ); else FillVector3D( originIndex, - originIndex[0] - 0.5, - originIndex[1] - 0.5, - originIndex[2] - 0.5 ); + originIndex[0] - 0.5, + originIndex[1] - 0.5, + originIndex[2] - 0.5 ); Point3D originWorld; originWorld = GetIndexToWorldTransform() ->TransformPoint( originIndex ); // instead could as well call IndexToWorld(originIndex,originWorld); SetOrigin(originWorld); this->SetImageGeometry(isAnImageGeometry); } bool mitk::Geometry3D::Is2DConvertable() { - bool isConvertableWithoutLoss = true; - do - { - if (this->GetSpacing()[2] != 1) - { - isConvertableWithoutLoss = false; - break; - } - if (this->GetOrigin()[2] != 0) - { - isConvertableWithoutLoss = false; - break; - } - mitk::Vector3D col0, col1, col2; - col0.SetVnlVector(this->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0)); - col1.SetVnlVector(this->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1)); - col2.SetVnlVector(this->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)); + bool isConvertableWithoutLoss = true; + do + { + if (this->GetSpacing()[2] != 1) + { + isConvertableWithoutLoss = false; + break; + } + if (this->GetOrigin()[2] != 0) + { + isConvertableWithoutLoss = false; + break; + } + mitk::Vector3D col0, col1, col2; + col0.SetVnlVector(this->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0)); + col1.SetVnlVector(this->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1)); + col2.SetVnlVector(this->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)); - if ((col0[2] != 0) || (col1[2] != 0) || (col2[0] != 0) || (col2[1] != 0) || (col2[2] != 1)) - { - isConvertableWithoutLoss = false; - break; - } - } while (0); + if ((col0[2] != 0) || (col1[2] != 0) || (col2[0] != 0) || (col2[1] != 0) || (col2[2] != 1)) + { + isConvertableWithoutLoss = false; + break; + } + } while (0); - return isConvertableWithoutLoss; + return isConvertableWithoutLoss; } bool mitk::Equal( const mitk::Geometry3D::BoundingBoxType *leftHandSide, const mitk::Geometry3D::BoundingBoxType *rightHandSide, ScalarType eps, bool verbose ) { bool result = true; if( rightHandSide == NULL ) { if(verbose) MITK_INFO << "[( Geometry3D::BoundingBoxType )] rightHandSide NULL."; return false; } if( leftHandSide == NULL ) { if(verbose) MITK_INFO << "[( Geometry3D::BoundingBoxType )] leftHandSide NULL."; return false; } Geometry3D::BoundsArrayType rightBounds = rightHandSide->GetBounds(); Geometry3D::BoundsArrayType leftBounds = leftHandSide->GetBounds(); Geometry3D::BoundsArrayType::Iterator itLeft = leftBounds.Begin(); for( Geometry3D::BoundsArrayType::Iterator itRight = rightBounds.Begin(); itRight != rightBounds.End(); ++itRight) { if(( !mitk::Equal( *itLeft, *itRight, eps )) ) { if(verbose) { MITK_INFO << "[( Geometry3D::BoundingBoxType )] bounds are not equal."; MITK_INFO << "rightHandSide is " << setprecision(12) << *itRight << " : leftHandSide is " << *itLeft << " and tolerance is " << eps; } result = false; } itLeft++; } return result; } bool mitk::Equal(const mitk::Geometry3D *leftHandSide, const mitk::Geometry3D *rightHandSide, ScalarType eps, bool verbose) { bool result = true; if( rightHandSide == NULL ) { if(verbose) MITK_INFO << "[( Geometry3D )] rightHandSide NULL."; return false; } if( leftHandSide == NULL) { if(verbose) MITK_INFO << "[( Geometry3D )] leftHandSide NULL."; return false; } //Compare spacings if( !mitk::Equal( leftHandSide->GetSpacing(), rightHandSide->GetSpacing(), eps ) ) { if(verbose) { MITK_INFO << "[( Geometry3D )] Spacing differs."; MITK_INFO << "rightHandSide is " << setprecision(12) << rightHandSide->GetSpacing() << " : leftHandSide is " << leftHandSide->GetSpacing() << " and tolerance is " << eps; } result = false; } //Compare Origins if( !mitk::Equal( leftHandSide->GetOrigin(), rightHandSide->GetOrigin(), eps ) ) { if(verbose) { MITK_INFO << "[( Geometry3D )] Origin differs."; MITK_INFO << "rightHandSide is " << setprecision(12) << rightHandSide->GetOrigin() << " : leftHandSide is " << leftHandSide->GetOrigin() << " and tolerance is " << eps; } result = false; } //Compare Axis and Extents for( unsigned int i=0; i<3; ++i) { if( !mitk::Equal( leftHandSide->GetAxisVector(i), rightHandSide->GetAxisVector(i), eps)) { if(verbose) { MITK_INFO << "[( Geometry3D )] AxisVector #" << i << " differ"; MITK_INFO << "rightHandSide is " << setprecision(12) << rightHandSide->GetAxisVector(i) << " : leftHandSide is " << leftHandSide->GetAxisVector(i) << " and tolerance is " << eps; } result = false; } if( !mitk::Equal( leftHandSide->GetExtent(i), rightHandSide->GetExtent(i), eps) ) { if(verbose) { MITK_INFO << "[( Geometry3D )] Extent #" << i << " differ"; MITK_INFO << "rightHandSide is " << setprecision(12) << rightHandSide->GetExtent(i) << " : leftHandSide is " << leftHandSide->GetExtent(i) << " and tolerance is " << eps; } result = false; } } //Compare ImageGeometry Flag if( rightHandSide->GetImageGeometry() != leftHandSide->GetImageGeometry() ) { if(verbose) { MITK_INFO << "[( Geometry3D )] GetImageGeometry is different."; MITK_INFO << "rightHandSide is " << rightHandSide->GetImageGeometry() << " : leftHandSide is " << leftHandSide->GetImageGeometry(); } result = false; } //Compare BoundingBoxes if( !mitk::Equal( leftHandSide->GetBoundingBox(), rightHandSide->GetBoundingBox(), eps, verbose) ) { result = false; } //Compare IndexToWorldTransform Matrix if( !mitk::Equal( leftHandSide->GetIndexToWorldTransform(), rightHandSide->GetIndexToWorldTransform(), eps, verbose) ) { result = false; } return result; } bool mitk::Equal(const Geometry3D::TransformType *leftHandSide, const Geometry3D::TransformType *rightHandSide, ScalarType eps, bool verbose ) { //Compare IndexToWorldTransform Matrix if( !mitk::MatrixEqualElementWise( leftHandSide->GetMatrix(), - rightHandSide->GetMatrix() ) ) + rightHandSide->GetMatrix() ) ) { if(verbose) { MITK_INFO << "[( Geometry3D::TransformType )] Index to World Transformation matrix differs."; MITK_INFO << "rightHandSide is " << setprecision(12) << rightHandSide->GetMatrix() << " : leftHandSide is " << leftHandSide->GetMatrix() << " and tolerance is " << eps; } return false; } return true; } - -/** Initialize the geometry */ -void -mitk::Geometry3D::InitializeGeometry(Geometry3D* newGeometry) const -{ - newGeometry->SetBounds(m_BoundingBox->GetBounds()); - // we have to create a new transform!! - - if(m_IndexToWorldTransform) - { - TransformType::Pointer indexToWorldTransform = TransformType::New(); - indexToWorldTransform->SetCenter( m_IndexToWorldTransform->GetCenter() ); - indexToWorldTransform->SetMatrix( m_IndexToWorldTransform->GetMatrix() ); - indexToWorldTransform->SetOffset( m_IndexToWorldTransform->GetOffset() ); - newGeometry->SetIndexToWorldTransform(indexToWorldTransform); - } -} - -/** Set the bounds */ -void mitk::Geometry3D::SetBounds(const BoundsArrayType& bounds) -{ - m_BoundingBox = BoundingBoxType::New(); - - BoundingBoxType::PointsContainer::Pointer pointscontainer = - BoundingBoxType::PointsContainer::New(); - BoundingBoxType::PointType p; - BoundingBoxType::PointIdentifier pointid; - - for(pointid=0; pointid<2;++pointid) - { - unsigned int i; - for(i=0; iInsertElement(pointid, p); - } - - m_BoundingBox->SetPoints(pointscontainer); - m_BoundingBox->ComputeBoundingBox(); - this->Modified(); -} diff --git a/Core/Code/DataManagement/mitkGeometry3D.h b/Core/Code/DataManagement/mitkGeometry3D.h index 1331e6a8b4..fb30f4e7aa 100644 --- a/Core/Code/DataManagement/mitkGeometry3D.h +++ b/Core/Code/DataManagement/mitkGeometry3D.h @@ -1,771 +1,630 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef GEOMETRY3D_H_HEADER_INCLUDED_C1EBD0AD #define GEOMETRY3D_H_HEADER_INCLUDED_C1EBD0AD #include #include -#include "mitkVector.h" -#include "mitkOperationActor.h" -#include -#include -#include -#include #include "itkScalableAffineTransform.h" -#include "itkBoundingBox.h" +#include + +#include "mitkBaseGeometry.h" class vtkLinearTransform; -class vtkMatrixToLinearTransform; -class vtkMatrix4x4; namespace mitk { - //##Documentation - //## @brief Standard 3D-BoundingBox typedef - //## - //## Standard 3D-BoundingBox typedef to get rid of template arguments (3D, type). - typedef itk::BoundingBox BoundingBox; - - //##Documentation - //## @brief Standard typedef for time-bounds - typedef itk::FixedArray TimeBounds; - typedef itk::FixedArray FixedArrayType; - - typedef itk::AffineGeometryFrame AffineGeometryFrame3D; - - //##Documentation - //## @brief Describes the geometry of a data object - //## - //## At least, it can return the bounding box of the data object. - //## - //## The class holds - //## \li a bounding box which is axes-parallel in intrinsic coordinates - //## (often integer indices of pixels), to be accessed by - //## GetBoundingBox() - //## \li a transform to convert intrinsic coordinates into a - //## world-coordinate system with coordinates in millimeters - //## and milliseconds (all are floating point values), to - //## be accessed by GetIndexToWorldTransform() - //## \li a life span, i.e. a bounding box in time in ms (with - //## start and end time), to be accessed by GetTimeBounds(). - //## The default is minus infinity to plus infinity. - //## - //## Geometry3D and its sub-classes allow converting between - //## intrinsic coordinates (called index or unit coordinates) - //## and world-coordinates (called world or mm coordinates), - //## e.g. WorldToIndex. - //## In case you need integer index coordinates, provide an - //## mitk::Index3D (or itk::Index) as target variable to - //## WorldToIndex, otherwise you will get a continuous index - //## (floating point values). - //## - //## An important sub-class is SlicedGeometry3D, which descibes - //## data objects consisting of slices, e.g., objects of type Image. - //## Conversions between world coordinates (in mm) and unit coordinates - //## (e.g., pixels in the case of an Image) can be performed. - //## - //## For more information on related classes, see \ref Geometry. - //## - //## Geometry3D instances referring to an Image need a slightly - //## different definition of corners, see SetImageGeometry. This - //## is usualy automatically called by Image. - //## - //## Geometry3D have to be initialized in the method GenerateOutputInformation() - //## of BaseProcess (or CopyInformation/ UpdateOutputInformation of BaseData, - //## if possible, e.g., by analyzing pic tags in Image) subclasses. See also - //## itk::ProcessObject::GenerateOutputInformation(), - //## itk::DataObject::CopyInformation() and - //## itk::DataObject::UpdateOutputInformation(). - //## - //## Rule: everything is in mm (ms) if not stated otherwise. - //## @ingroup Geometry - class MITK_CORE_EXPORT Geometry3D : public itk::Object, public OperationActor - { - public: - mitkClassMacro(Geometry3D, itk::Object); - - typedef itk::QuaternionRigidTransform< ScalarType > QuaternionTransformType; - typedef QuaternionTransformType::VnlQuaternionType VnlQuaternionType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - typedef itk::ScalableAffineTransform TransformType; - typedef itk::BoundingBox BoundingBoxType; - typedef BoundingBoxType::BoundsArrayType BoundsArrayType; - typedef BoundingBoxType::Pointer BoundingBoxPointer; - - // a bit of a misuse, but we want only doxygen to see the following: -#ifdef DOXYGEN_SKIP - //##Documentation - //## @brief Get the transformation used to convert from index - //## to world coordinates - itkGetObjectMacro(IndexToWorldTransform, AffineTransform3D); -#endif - //## @brief Set the transformation used to convert from index - //## to world coordinates - virtual void SetIndexToWorldTransform(mitk::AffineTransform3D* transform); - //##Documentation - //## @brief Convenience method for setting the ITK transform - //## (m_IndexToWorldTransform) via an vtkMatrix4x4 - //## \sa SetIndexToWorldTransform - virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4* vtkmatrix); - -#ifdef DOXYGEN_SKIP - //##Documentation - //## @brief Get bounding box (in index/unit coordinates) - itkGetConstObjectMacro(BoundingBox, BoundingBoxType); - //##Documentation - //## @brief Get bounding box (in index/unit coordinates) as a BoundsArrayType - const BoundsArrayType GetBounds() const - { - assert(m_BoundingBox.IsNotNull()); - return m_BoundingBox->GetBounds(); - } -#endif - //##Documentation - //## \brief Set the bounding box (in index/unit coordinates) - //## - //## Only possible via the BoundsArray to make clear that a - //## copy of the bounding-box is stored, not a reference to it. - virtual void SetBounds(const BoundsArrayType& bounds); - //##Documentation - //## @brief Set the bounding box (in index/unit coordinates) via a float array - virtual void SetFloatBounds(const float bounds[6]); - //##Documentation - //## @brief Set the bounding box (in index/unit coordinates) via a double array - virtual void SetFloatBounds(const double bounds[6]); - - //##Documentation - //## @brief When switching from an Image Geometry to a normal Geometry (and the other way around), you have to change the origin as well (See Geometry Documentation)! This function will change the "isImageGeometry" bool flag and changes the origin respectively. - virtual void ChangeImageGeometryConsideringOriginOffset( const bool isAnImageGeometry ); - - //##Documentation - //## @brief Checks, if the given geometry can be converted to 2D without information loss - //## e.g. when a 2D image is saved, the matrix is usually cropped to 2x2, and when you load it back to MITK - //## it will be filled with standard values. This function checks, if information would be lost during this - //## procedure - virtual bool Is2DConvertable(); - - //##Documentation - //## @brief Get the time bounds (in ms) - itkGetConstReferenceMacro(TimeBounds, TimeBounds); - //##Documentation - //## @brief Set the time bounds (in ms) - virtual void SetTimeBounds(const TimeBounds& timebounds); - - //##Documentation - //## @brief Get the position of the corner number \a id (in world coordinates) - //## - //## See SetImageGeometry for how a corner is defined on images. - Point3D GetCornerPoint(int id) const; - - //##Documentation - //## @brief Get the position of a corner (in world coordinates) - //## - //## See SetImageGeometry for how a corner is defined on images. - Point3D GetCornerPoint(bool xFront=true, bool yFront=true, bool zFront=true) const; - - //##Documentation - //## @brief Get vector along bounding-box in the specified @a direction in mm - //## - //## The length of the vector is the size of the bounding-box in the - //## specified @a direction in mm - //## \sa GetMatrixColumn - Vector3D GetAxisVector(unsigned int direction) const - { - Vector3D frontToBack; - frontToBack.SetVnlVector(m_IndexToWorldTransform->GetMatrix().GetVnlMatrix().get_column(direction)); - frontToBack *= GetExtent(direction); - return frontToBack; - } - - //##Documentation - //## @brief Get the center of the bounding-box in mm - //## - Point3D GetCenter() const - { - assert(m_BoundingBox.IsNotNull()); - return m_IndexToWorldTransform->TransformPoint(m_BoundingBox->GetCenter()); - } - - //##Documentation - //## @brief Get the squared length of the diagonal of the bounding-box in mm - //## - double GetDiagonalLength2() const - { - Vector3D diagonalvector = GetCornerPoint()-GetCornerPoint(false, false, false); - return diagonalvector.GetSquaredNorm(); - } - - //##Documentation - //## @brief Get the length of the diagonal of the bounding-box in mm - //## - double GetDiagonalLength() const - { - return sqrt(GetDiagonalLength2()); - } - - //##Documentation - //## @brief Get a VnlVector along bounding-box in the specified - //## @a direction, length is spacing - //## - //## \sa GetAxisVector - VnlVector GetMatrixColumn(unsigned int direction) const - { - return m_IndexToWorldTransform->GetMatrix().GetVnlMatrix().get_column(direction); - } + //##Documentation + //## @brief Standard typedef for time-bounds + typedef itk::FixedArray TimeBounds; + typedef itk::FixedArray FixedArrayType; + + //##Documentation + //## @brief Standard 3D-BoundingBox typedef + //## + //## Standard 3D-BoundingBox typedef to get rid of template arguments (3D, type). + typedef itk::BoundingBox BoundingBox; + + //##Documentation + //## @brief Describes the geometry of a data object + //## + //## At least, it can return the bounding box of the data object. + //## + //## The class holds + //## \li a bounding box which is axes-parallel in intrinsic coordinates + //## (often integer indices of pixels), to be accessed by + //## GetBoundingBox() + //## \li a transform to convert intrinsic coordinates into a + //## world-coordinate system with coordinates in millimeters + //## and milliseconds (all are floating point values), to + //## be accessed by GetIndexToWorldTransform() + //## \li a life span, i.e. a bounding box in time in ms (with + //## start and end time), to be accessed by GetTimeBounds(). + //## The default is minus infinity to plus infinity. + //## + //## Geometry3D and its sub-classes allow converting between + //## intrinsic coordinates (called index or unit coordinates) + //## and world-coordinates (called world or mm coordinates), + //## e.g. WorldToIndex. + //## In case you need integer index coordinates, provide an + //## mitk::Index3D (or itk::Index) as target variable to + //## WorldToIndex, otherwise you will get a continuous index + //## (floating point values). + //## + //## An important sub-class is SlicedGeometry3D, which descibes + //## data objects consisting of slices, e.g., objects of type Image. + //## Conversions between world coordinates (in mm) and unit coordinates + //## (e.g., pixels in the case of an Image) can be performed. + //## + //## For more information on related classes, see \ref Geometry. + //## + //## Geometry3D instances referring to an Image need a slightly + //## different definition of corners, see SetImageGeometry. This + //## is usualy automatically called by Image. + //## + //## Geometry3D have to be initialized in the method GenerateOutputInformation() + //## of BaseProcess (or CopyInformation/ UpdateOutputInformation of BaseData, + //## if possible, e.g., by analyzing pic tags in Image) subclasses. See also + //## itk::ProcessObject::GenerateOutputInformation(), + //## itk::DataObject::CopyInformation() and + //## itk::DataObject::UpdateOutputInformation(). + //## + //## Rule: everything is in mm (ms) if not stated otherwise. + //## @ingroup Geometry + class MITK_CORE_EXPORT Geometry3D : public BaseGeometry + { + public: + mitkClassMacro(Geometry3D, mitk::BaseGeometry); + + typedef itk::QuaternionRigidTransform< ScalarType > QuaternionTransformType; + typedef QuaternionTransformType::VnlQuaternionType VnlQuaternionType; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + //##Documentation + //## @brief Convenience method for setting the ITK transform + //## (m_IndexToWorldTransform) via an vtkMatrix4x4 + //## \sa SetIndexToWorldTransform + virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4* vtkmatrix); + + //##Documentation + //## @brief When switching from an Image Geometry to a normal Geometry (and the other way around), you have to change the origin as well (See Geometry Documentation)! This function will change the "isImageGeometry" bool flag and changes the origin respectively. + virtual void ChangeImageGeometryConsideringOriginOffset( const bool isAnImageGeometry ); + + //##Documentation + //## @brief Checks, if the given geometry can be converted to 2D without information loss + //## e.g. when a 2D image is saved, the matrix is usually cropped to 2x2, and when you load it back to MITK + //## it will be filled with standard values. This function checks, if information would be lost during this + //## procedure + virtual bool Is2DConvertable(); + + //##Documentation + //## @brief Set the time bounds (in ms) + virtual void SetTimeBounds(const TimeBounds& timebounds); + + //##Documentation + //## @brief Get the position of the corner number \a id (in world coordinates) + //## + //## See SetImageGeometry for how a corner is defined on images. + Point3D GetCornerPoint(int id) const; + + //##Documentation + //## @brief Get the position of a corner (in world coordinates) + //## + //## See SetImageGeometry for how a corner is defined on images. + Point3D GetCornerPoint(bool xFront=true, bool yFront=true, bool zFront=true) const; + + //##Documentation + //## @brief Get vector along bounding-box in the specified @a direction in mm + //## + //## The length of the vector is the size of the bounding-box in the + //## specified @a direction in mm + //## \sa GetMatrixColumn + Vector3D GetAxisVector(unsigned int direction) const + { + Vector3D frontToBack; + frontToBack.SetVnlVector(m_IndexToWorldTransform->GetMatrix().GetVnlMatrix().get_column(direction)); + frontToBack *= GetExtent(direction); + return frontToBack; + } + + //##Documentation + //## @brief Get the center of the bounding-box in mm + //## + Point3D GetCenter() const + { + assert(m_BoundingBox.IsNotNull()); + return m_IndexToWorldTransform->TransformPoint(m_BoundingBox->GetCenter()); + } + + //##Documentation + //## @brief Get the squared length of the diagonal of the bounding-box in mm + //## + double GetDiagonalLength2() const + { + Vector3D diagonalvector = GetCornerPoint()-GetCornerPoint(false, false, false); + return diagonalvector.GetSquaredNorm(); + } + + //##Documentation + //## @brief Get the length of the diagonal of the bounding-box in mm + //## + double GetDiagonalLength() const + { + return sqrt(GetDiagonalLength2()); + } + + //##Documentation + //## @brief Get a VnlVector along bounding-box in the specified + //## @a direction, length is spacing + //## + //## \sa GetAxisVector + VnlVector GetMatrixColumn(unsigned int direction) const + { + return m_IndexToWorldTransform->GetMatrix().GetVnlMatrix().get_column(direction); + } #ifdef DOXYGEN_SKIP - //##Documentation - //## @brief Get the extent of the bounding box (in index/unit coordinates) - //## - //## To access the extent in mm use GetExtentInMM - ScalarType GetExtent(unsigned int direction) const; + //##Documentation + //## @brief Get the extent of the bounding box (in index/unit coordinates) + //## + //## To access the extent in mm use GetExtentInMM + ScalarType GetExtent(unsigned int direction) const; #endif - //##Documentation - //## @brief Get the extent of the bounding-box in the specified @a direction in mm - //## - //## Equals length of GetAxisVector(direction). - ScalarType GetExtentInMM(int direction) const + //##Documentation + //## @brief Get the extent of the bounding-box in the specified @a direction in mm + //## + //## Equals length of GetAxisVector(direction). + ScalarType GetExtentInMM(int direction) const + { + return m_IndexToWorldTransform->GetMatrix().GetVnlMatrix().get_column(direction).magnitude()*GetExtent(direction); + } + + //##Documentation + //## @brief Set the extent of the bounding-box in the specified @a direction in mm + //## + //## @note This changes the matrix in the transform, @a not the bounds, which are given in units! + virtual void SetExtentInMM(int direction, ScalarType extentInMM); + + //##Documentation + //## @brief Get the m_IndexToWorldTransform as a vtkLinearTransform + vtkLinearTransform* GetVtkTransform() const + { + return (vtkLinearTransform*)m_VtkIndexToWorldTransform; + } + + //##Documentation + //## @brief Translate the origin by a vector + //## + virtual void Translate(const Vector3D& vector); + + //##Documentation + //## @brief Set the transform to identity and origin to 0 + //## + virtual void SetIdentity(); + + //##Documentation + //## @brief Compose new IndexToWorldTransform with a given transform. + //## + //## This method composes m_IndexToWorldTransform with another transform, + //## modifying self to be the composition of self and other. + //## If the argument pre is true, then other is precomposed with self; + //## that is, the resulting transformation consists of first applying + //## other to the source, followed by self. If pre is false or omitted, + //## then other is post-composed with self; that is the resulting + //## transformation consists of first applying self to the source, + //## followed by other. + virtual void Compose( const Geometry3D::TransformType * other, bool pre = 0 ); + + //##Documentation + //## @brief Compose new IndexToWorldTransform with a given vtkMatrix4x4. + //## + //## Converts the vtkMatrix4x4 into a itk-transform and calls the previous method. + virtual void Compose( const vtkMatrix4x4 * vtkmatrix, bool pre = 0 ); + + //##Documentation + //## @brief Get the origin as VnlVector + //## + //## \sa GetOrigin + VnlVector GetOriginVnl() const + { + return const_cast(this)->m_Origin.GetVnlVector(); + } + + //##Documentation + //## @brief Convert world coordinates (in mm) of a \em point to (continuous!) index coordinates + //## \warning If you need (discrete) integer index coordinates (e.g., for iterating easily over an image), + //## use WorldToIndex(const mitk::Point3D& pt_mm, itk::Index &index). + //## For further information about coordinates types, please see the Geometry documentation + void WorldToIndex(const mitk::Point3D& pt_mm, mitk::Point3D& pt_units) const; + + //##Documentation + //## @brief Convert (continuous or discrete) index coordinates of a \em point to world coordinates (in mm) + //## For further information about coordinates types, please see the Geometry documentation + void IndexToWorld(const mitk::Point3D& pt_units, mitk::Point3D& pt_mm) const; + + //##Documentation + //## @brief Convert (discrete) index coordinates of a \em point to world coordinates (in mm) + //## For further information about coordinates types, please see the Geometry documentation + template + void IndexToWorld(const itk::Index &index, mitk::Point3D& pt_mm ) const + { + mitk::Point3D pt_units; + pt_units.Fill(0); + int i, dim=index.GetIndexDimension(); + if(dim>3) { - return m_IndexToWorldTransform->GetMatrix().GetVnlMatrix().get_column(direction).magnitude()*GetExtent(direction); + dim=3; } - - //##Documentation - //## @brief Set the extent of the bounding-box in the specified @a direction in mm - //## - //## @note This changes the matrix in the transform, @a not the bounds, which are given in units! - virtual void SetExtentInMM(int direction, ScalarType extentInMM); - - //##Documentation - //## @brief Get the m_IndexToWorldTransform as a vtkLinearTransform - vtkLinearTransform* GetVtkTransform() const + for(i=0;i + void WorldToIndex(const mitk::Point3D& pt_mm, itk::Index &index) const + { + typedef itk::Index IndexType; + mitk::Point3D pt_units; + this->WorldToIndex(pt_mm, pt_units); + int i, dim=index.GetIndexDimension(); + if(dim>3) { - return m_Origin; + index.Fill(0); + dim=3; } - - //##Documentation - //## @brief Get the origin as VnlVector - //## - //## \sa GetOrigin - VnlVector GetOriginVnl() const - { - return const_cast(this)->m_Origin.GetVnlVector(); - } - - //##Documentation - //## @brief Convert world coordinates (in mm) of a \em point to (continuous!) index coordinates - //## \warning If you need (discrete) integer index coordinates (e.g., for iterating easily over an image), - //## use WorldToIndex(const mitk::Point3D& pt_mm, itk::Index &index). - //## For further information about coordinates types, please see the Geometry documentation - void WorldToIndex(const mitk::Point3D& pt_mm, mitk::Point3D& pt_units) const; - - //##Documentation - //## @brief Convert (continuous or discrete) index coordinates of a \em point to world coordinates (in mm) - //## For further information about coordinates types, please see the Geometry documentation - void IndexToWorld(const mitk::Point3D& pt_units, mitk::Point3D& pt_mm) const; - - //##Documentation - //## @brief Convert (discrete) index coordinates of a \em point to world coordinates (in mm) - //## For further information about coordinates types, please see the Geometry documentation - template - void IndexToWorld(const itk::Index &index, mitk::Point3D& pt_mm ) const - { - mitk::Point3D pt_units; - pt_units.Fill(0); - int i, dim=index.GetIndexDimension(); - if(dim>3) - { - dim=3; - } - for(i=0;i( pt_units[i] ); } - - //##Documentation - //## @brief Convert world coordinates (in mm) of a \em vector - //## \a vec_mm to (continuous!) index coordinates. - //## @deprecated First parameter (Point3D) is not used. If possible, please use void WorldToIndex(const mitk::Vector3D& vec_mm, mitk::Vector3D& vec_units) const. - //## For further information about coordinates types, please see the Geometry documentation - void WorldToIndex(const mitk::Point3D& atPt3d_mm, const mitk::Vector3D& vec_mm, mitk::Vector3D& vec_units) const; - - //##Documentation - //## @brief Convert world coordinates (in mm) of a \em vector - //## \a vec_mm to (continuous!) index coordinates. - //## For further information about coordinates types, please see the Geometry documentation - void WorldToIndex(const mitk::Vector3D& vec_mm, mitk::Vector3D& vec_units) const; - - //##Documentation - //## @brief Convert (continuous or discrete) index coordinates of a \em vector - //## \a vec_units to world coordinates (in mm) - //## @deprecated First parameter (Point3D) is not used. If possible, please use void IndexToWorld(const mitk::Vector3D& vec_units, mitk::Vector3D& vec_mm) const. - //## For further information about coordinates types, please see the Geometry documentation - void IndexToWorld(const mitk::Point3D& atPt3d_units, const mitk::Vector3D& vec_units, mitk::Vector3D& vec_mm) const; - - //##Documentation - //## @brief Convert (continuous or discrete) index coordinates of a \em vector - //## \a vec_units to world coordinates (in mm) - //## For further information about coordinates types, please see the Geometry documentation - void IndexToWorld(const mitk::Vector3D& vec_units, mitk::Vector3D& vec_mm) const; - - //##Documentation - //## @brief Convert world coordinates (in mm) of a \em point to (discrete!) index coordinates. - //## This method rounds to integer indices! - //## For further information about coordinates types, please see the Geometry documentation - template - void WorldToIndex(const mitk::Point3D& pt_mm, itk::Index &index) const + } + + //##Documentation + //## @brief Deprecated for use with ITK version 3.10 or newer. + //## Convert world coordinates (in mm) of a \em point to + //## ITK physical coordinates (in mm, but without a possible rotation) + //## + //## This method is useful if you have want to access an mitk::Image + //## via an itk::Image. ITK v3.8 and older did not support rotated (tilted) + //## images, i.e., ITK images are always parallel to the coordinate axes. + //## When accessing a (possibly rotated) mitk::Image via an itk::Image + //## the rotational part of the transformation in the Geometry3D is + //## simply discarded; in other word: only the origin and spacing is + //## used by ITK, not the complete matrix available in MITK. + //## With WorldToItkPhysicalPoint you can convert an MITK world + //## coordinate (including the rotation) into a coordinate that + //## can be used with the ITK image as a ITK physical coordinate + //## (excluding the rotation). + template + void WorldToItkPhysicalPoint(const mitk::Point3D& pt_mm, + itk::Point& itkPhysicalPoint) const + { + mitk::vtk2itk(pt_mm, itkPhysicalPoint); + } + + //##Documentation + //## @brief Deprecated for use with ITK version 3.10 or newer. + //## Convert ITK physical coordinates of a \em point (in mm, + //## but without a rotation) into MITK world coordinates (in mm) + //## + //## For more information, see WorldToItkPhysicalPoint. + template + void ItkPhysicalPointToWorld(const itk::Point& itkPhysicalPoint, + mitk::Point3D& pt_mm) const + { + mitk::vtk2itk(itkPhysicalPoint, pt_mm); + } + + //##Documentation + //## @brief Is this an ImageGeometry? + //## + //## For more information, see SetImageGeometry + itkGetConstMacro(ImageGeometry, bool); + //##Documentation + //## @brief Define that this Geometry3D is refering to an Image + //## + //## A geometry referring to an Image needs a slightly different + //## definition of the position of the corners (see GetCornerPoint). + //## The position of a voxel is defined by the position of its center. + //## If we would use the origin (position of the (center of) the first + //## voxel) as a corner and display this point, it would seem to be + //## \em not at the corner but a bit within the image. Even worse for + //## the opposite corner of the image: here the corner would appear + //## outside the image (by half of the voxel diameter). Thus, we have + //## to correct for this and to be able to do that, we need to know + //## that the Geometry3D is referring to an Image. + itkSetMacro(ImageGeometry, bool); + itkBooleanMacro(ImageGeometry); + + //##Documentation + //## @brief Test whether the point \a p (world coordinates in mm) is + //## inside the bounding box + bool IsInside(const mitk::Point3D& p) const + { + mitk::Point3D index; + WorldToIndex(p, index); + return IsIndexInside(index); + } + + //##Documentation + //## @brief Test whether the point \a p ((continous!)index coordinates in units) is + //## inside the bounding box + bool IsIndexInside(const mitk::Point3D& index) const + { + bool inside = false; + //if it is an image geometry, we need to convert the index to discrete values + //this is done by applying the rounding function also used in WorldToIndex (see line 323) + if (m_ImageGeometry) { - typedef itk::Index IndexType; - mitk::Point3D pt_units; - this->WorldToIndex(pt_mm, pt_units); - int i, dim=index.GetIndexDimension(); - if(dim>3) - { - index.Fill(0); - dim=3; - } - for(i=0;i( pt_units[i] ); - } + mitk::Point3D discretIndex; + discretIndex[0]=itk::Math::RoundHalfIntegerUp( index[0] ); + discretIndex[1]=itk::Math::RoundHalfIntegerUp( index[1] ); + discretIndex[2]=itk::Math::RoundHalfIntegerUp( index[2] ); + + inside = m_BoundingBox->IsInside(discretIndex); + //we have to check if the index is at the upper border of each dimension, + // because the boundingbox is not centerbased + if (inside) + { + const BoundingBox::BoundsArrayType& bounds = m_BoundingBox->GetBounds(); + if((discretIndex[0] == bounds[1]) || + (discretIndex[1] == bounds[3]) || + (discretIndex[2] == bounds[5])) + inside = false; + } } - - //##Documentation - //## @brief Deprecated for use with ITK version 3.10 or newer. - //## Convert world coordinates (in mm) of a \em point to - //## ITK physical coordinates (in mm, but without a possible rotation) - //## - //## This method is useful if you have want to access an mitk::Image - //## via an itk::Image. ITK v3.8 and older did not support rotated (tilted) - //## images, i.e., ITK images are always parallel to the coordinate axes. - //## When accessing a (possibly rotated) mitk::Image via an itk::Image - //## the rotational part of the transformation in the Geometry3D is - //## simply discarded; in other word: only the origin and spacing is - //## used by ITK, not the complete matrix available in MITK. - //## With WorldToItkPhysicalPoint you can convert an MITK world - //## coordinate (including the rotation) into a coordinate that - //## can be used with the ITK image as a ITK physical coordinate - //## (excluding the rotation). - template - void WorldToItkPhysicalPoint(const mitk::Point3D& pt_mm, - itk::Point& itkPhysicalPoint) const - { - mitk::vtk2itk(pt_mm, itkPhysicalPoint); - } - - //##Documentation - //## @brief Deprecated for use with ITK version 3.10 or newer. - //## Convert ITK physical coordinates of a \em point (in mm, - //## but without a rotation) into MITK world coordinates (in mm) - //## - //## For more information, see WorldToItkPhysicalPoint. - template - void ItkPhysicalPointToWorld(const itk::Point& itkPhysicalPoint, - mitk::Point3D& pt_mm) const - { - mitk::vtk2itk(itkPhysicalPoint, pt_mm); - } - - //##Documentation - //## @brief Initialize the Geometry3D - virtual void Initialize(); - - //##Documentation - //## @brief Is this an ImageGeometry? - //## - //## For more information, see SetImageGeometry - itkGetConstMacro(ImageGeometry, bool); - //##Documentation - //## @brief Define that this Geometry3D is refering to an Image - //## - //## A geometry referring to an Image needs a slightly different - //## definition of the position of the corners (see GetCornerPoint). - //## The position of a voxel is defined by the position of its center. - //## If we would use the origin (position of the (center of) the first - //## voxel) as a corner and display this point, it would seem to be - //## \em not at the corner but a bit within the image. Even worse for - //## the opposite corner of the image: here the corner would appear - //## outside the image (by half of the voxel diameter). Thus, we have - //## to correct for this and to be able to do that, we need to know - //## that the Geometry3D is referring to an Image. - itkSetMacro(ImageGeometry, bool); - itkBooleanMacro(ImageGeometry); - - //##Documentation - //## @brief Is this Geometry3D in a state that is valid? - virtual bool IsValid() const - { - return m_Valid; - } - - //##Documentation - //## @brief Test whether the point \a p (world coordinates in mm) is - //## inside the bounding box - bool IsInside(const mitk::Point3D& p) const - { - mitk::Point3D index; - WorldToIndex(p, index); - return IsIndexInside(index); - } - - //##Documentation - //## @brief Test whether the point \a p ((continous!)index coordinates in units) is - //## inside the bounding box - bool IsIndexInside(const mitk::Point3D& index) const - { - bool inside = false; - //if it is an image geometry, we need to convert the index to discrete values - //this is done by applying the rounding function also used in WorldToIndex (see line 323) - if (m_ImageGeometry) - { - mitk::Point3D discretIndex; - discretIndex[0]=itk::Math::RoundHalfIntegerUp( index[0] ); - discretIndex[1]=itk::Math::RoundHalfIntegerUp( index[1] ); - discretIndex[2]=itk::Math::RoundHalfIntegerUp( index[2] ); - - inside = m_BoundingBox->IsInside(discretIndex); - //we have to check if the index is at the upper border of each dimension, - // because the boundingbox is not centerbased - if (inside) - { - const BoundingBox::BoundsArrayType& bounds = m_BoundingBox->GetBounds(); - if((discretIndex[0] == bounds[1]) || - (discretIndex[1] == bounds[3]) || - (discretIndex[2] == bounds[5])) - inside = false; - } - } - else - inside = m_BoundingBox->IsInside(index); - - return inside; - } - - //##Documentation - //## @brief Convenience method for working with ITK indices - template - bool IsIndexInside(const itk::Index &index) const - { - int i, dim=index.GetIndexDimension(); - Point3D pt_index; - pt_index.Fill(0); - for ( i = 0; i < dim; ++i ) - { - pt_index[i] = index[i]; - } - return IsIndexInside(pt_index); - } - - //##Documentation - //## @brief Get the spacing (size of a pixel). - //## - itkGetConstReferenceMacro(Spacing, mitk::Vector3D); - - //##Documentation - //## @brief Get the spacing as a float[3] array. - const float* GetFloatSpacing() const; - - //##Documentation - //## @brief Set the spacing (m_Spacing) - virtual void SetSpacing(const mitk::Vector3D& aSpacing); - - //##Documentation - //## @brief Get the DICOM FrameOfReferenceID referring to the - //## used world coordinate system - itkGetConstMacro(FrameOfReferenceID, unsigned int); - //##Documentation - //## @brief Set the DICOM FrameOfReferenceID referring to the - //## used world coordinate system - itkSetMacro(FrameOfReferenceID, unsigned int); - - //##Documentation - //## @brief Copy the ITK transform - //## (m_IndexToWorldTransform) to the VTK transform - //## \sa SetIndexToWorldTransform - void TransferItkToVtkTransform(); - - //##Documentation - //## @brief Copy the VTK transform - //## to the ITK transform (m_IndexToWorldTransform) - //## \sa SetIndexToWorldTransform - void TransferVtkToItkTransform(); - - //##Documentation - //## @brief Get the parametric bounding-box - //## - //## See AbstractTransformGeometry for an example usage of this. - itkGetConstObjectMacro(ParametricBoundingBox, BoundingBox); - //##Documentation - //## @brief Get the parametric bounds - //## - //## See AbstractTransformGeometry for an example usage of this. - const BoundingBox::BoundsArrayType& GetParametricBounds() const - { - assert(m_ParametricBoundingBox.IsNotNull()); - return m_ParametricBoundingBox->GetBounds(); - } - - //##Documentation - //## @brief Get the parametric extent - //## - //## See AbstractTransformGeometry for an example usage of this. - mitk::ScalarType GetParametricExtent(int direction) const - { - if (direction < 0 || direction>=3) - mitkThrow() << "Invalid direction. Must be between either 0, 1 or 2. "; - assert(m_ParametricBoundingBox.IsNotNull()); - - BoundingBoxType::BoundsArrayType bounds = m_ParametricBoundingBox->GetBounds(); - return bounds[direction*2+1]-bounds[direction*2]; - } - - //##Documentation - //## @brief Get the parametric extent in mm - //## - //## See AbstractTransformGeometry for an example usage of this. - virtual mitk::ScalarType GetParametricExtentInMM(int direction) const - { - return GetExtentInMM(direction); - } - - //##Documentation - //## @brief Get the parametric transform - //## - //## See AbstractTransformGeometry for an example usage of this. - virtual const Transform3D* GetParametricTransform() const - { - return m_IndexToWorldTransform; - } - - //##Documentation - //## @brief Calculates a bounding-box around the geometry relative - //## to a coordinate system defined by a transform - //## - mitk::BoundingBox::Pointer CalculateBoundingBoxRelativeToTransform(const mitk::AffineTransform3D* transform) const; - - //##Documentation - //## @brief clones the geometry - //## - //## Overwrite in all sub-classes. - //## Normally looks like: - //## \code - //## Self::Pointer newGeometry = new Self(*this); - //## newGeometry->UnRegister(); - //## return newGeometry.GetPointer(); - //## \endcode - virtual itk::LightObject::Pointer InternalClone() const; - - //##Documentation - //##@brief executes affine operations (translate, rotate, scale) - virtual void ExecuteOperation(Operation* operation); - - /** Set/Get the IndexToWorldTransform */ - itkGetConstObjectMacro(IndexToWorldTransform, AffineTransform3D); - itkGetObjectMacro(IndexToWorldTransform, AffineTransform3D); - /** Get the bounding box */ - itkGetConstObjectMacro(BoundingBox, BoundingBoxType); - - const BoundsArrayType GetBounds() const - { - assert(m_BoundingBox.IsNotNull()); - return m_BoundingBox->GetBounds(); - } - - /** Get the extent of the bounding box */ - ScalarType GetExtent(unsigned int direction) const + else + inside = m_BoundingBox->IsInside(index); + + return inside; + } + + //##Documentation + //## @brief Convenience method for working with ITK indices + template + bool IsIndexInside(const itk::Index &index) const + { + int i, dim=index.GetIndexDimension(); + Point3D pt_index; + pt_index.Fill(0); + for ( i = 0; i < dim; ++i ) { - assert(m_BoundingBox.IsNotNull()); - if (direction>=NDimensions) - mitkThrow() << "Direction is too big. This geometry is for 3D Data"; - BoundsArrayType bounds = m_BoundingBox->GetBounds(); - return bounds[direction*2+1]-bounds[direction*2]; + pt_index[i] = index[i]; } - protected: - Geometry3D(); - Geometry3D(const Geometry3D& other); - - virtual void InitializeGeometry(Self * newGeometry) const; - - static const std::string GetTransformAsString( TransformType* transformType ); - static const unsigned int NDimensions = 3; - - virtual ~Geometry3D(); - - virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; - - virtual void BackTransform(const mitk::Point3D& in, mitk::Point3D& out) const; - //##Documentation - //## @brief Deprecated - virtual void BackTransform(const mitk::Point3D& at, const mitk::Vector3D& in, mitk::Vector3D& out) const; - - //Without redundant parameter Point3D - virtual void BackTransform(const mitk::Vector3D& in, mitk::Vector3D& out) const; - - //##Documentation - //## @brief Set the parametric bounds - //## - //## Protected in this class, made public in some sub-classes, e.g., - //## ExternAbstractTransformGeometry. - virtual void SetParametricBounds(const BoundingBox::BoundsArrayType& bounds); - - /** Resets sub-transforms that compose m_IndexToWorldTransform, by using - * the current value of m_IndexToWorldTransform and setting the rotation - * component to zero. */ - virtual void ResetSubTransforms(); - - mutable mitk::BoundingBox::Pointer m_ParametricBoundingBox; - - mutable mitk::TimeBounds m_TimeBounds; - - vtkMatrix4x4* m_VtkMatrix; - - bool m_ImageGeometry; - - AffineTransform3D::Pointer m_IndexToWorldTransform; - mutable BoundingBoxPointer m_BoundingBox; - - //##Documentation - //## @brief Spacing of the data. Only significant if the geometry describes - //## an Image (m_ImageGeometry==true). - mitk::Vector3D m_Spacing; - - bool m_Valid; - - unsigned int m_FrameOfReferenceID; - - static const std::string INDEX_TO_OBJECT_TRANSFORM; - static const std::string OBJECT_TO_NODE_TRANSFORM; - static const std::string INDEX_TO_NODE_TRANSFORM; - static const std::string INDEX_TO_WORLD_TRANSFORM; - - private: - mutable TransformType::Pointer m_InvertedTransform; - mutable unsigned long m_IndexToWorldTransformLastModified; - - VnlQuaternionType m_RotationQuaternion; - - float m_FloatSpacing[3]; - vtkMatrixToLinearTransform* m_VtkIndexToWorldTransform; - - //##Documentation - //## @brief Origin, i.e. upper-left corner of the plane - //## - Point3D m_Origin; - }; - - // - // Static compare functions mainly for testing - // - /** - * @brief Equal A function comparing two geometries for beeing identical. - * - * @ingroup MITKTestingAPI - * - * The function compares the spacing, origin, axisvectors, extents, the matrix of the - * IndexToWorldTransform (elementwise), the bounding (elementwise) and the ImageGeometry flag. - * - * The parameter eps is a tolarence value for all methods which are internally used for comparion. - * If you want to use different tolarance values for different parts of the geometry, feel free to use - * the other comparison methods and write your own implementation of Equal. - * @param rightHandSide Compare this against leftHandSide. - * @param leftHandSide Compare this against rightHandSide. - * @param eps Tolarence for comparison. You can use mitk::eps in most cases. - * @param verbose Flag indicating if the user wants detailed console output or not. - * @return True, if all comparison are true. False in any other case. - */ - MITK_CORE_EXPORT bool Equal(const mitk::Geometry3D* leftHandSide, const mitk::Geometry3D* rightHandSide, ScalarType eps, bool verbose); - - /** - * @brief Equal A function comparing two transforms (TransformType) for beeing identical. - * - * @ingroup MITKTestingAPI - * - * The function compares the IndexToWorldTransform (elementwise). - * - * The parameter eps is a tolarence value for all methods which are internally used for comparion. - * @param rightHandSide Compare this against leftHandSide. - * @param leftHandSide Compare this against rightHandSide. - * @param eps Tolarence for comparison. You can use mitk::eps in most cases. - * @param verbose Flag indicating if the user wants detailed console output or not. - * @return True, if all comparison are true. False in any other case. - */ - MITK_CORE_EXPORT bool Equal(const mitk::Geometry3D::TransformType *leftHandSide, const mitk::Geometry3D::TransformType *rightHandSide, ScalarType eps, bool verbose); - - /** - * @brief Equal A function comparing two bounding boxes (BoundingBoxType) for beeing identical. - * - * @ingroup MITKTestingAPI - * - * The function compares the bounds (elementwise). - * - * The parameter eps is a tolarence value for all methods which are internally used for comparion. - * @param rightHandSide Compare this against leftHandSide. - * @param leftHandSide Compare this against rightHandSide. - * @param eps Tolarence for comparison. You can use mitk::eps in most cases. - * @param verbose Flag indicating if the user wants detailed console output or not. - * @return True, if all comparison are true. False in any other case. - */ - MITK_CORE_EXPORT bool Equal( const mitk::Geometry3D::BoundingBoxType *leftHandSide, const mitk::Geometry3D::BoundingBoxType *rightHandSide, ScalarType eps, bool verbose); + return IsIndexInside(pt_index); + } + + //##Documentation + //## @brief Get the spacing as a float[3] array. + const float* GetFloatSpacing() const; + + //##Documentation + //## @brief Set the spacing (m_Spacing) + virtual void SetSpacing(const mitk::Vector3D& aSpacing); + + //##Documentation + //## @brief Copy the VTK transform + //## to the ITK transform (m_IndexToWorldTransform) + //## \sa SetIndexToWorldTransform + void TransferVtkToItkTransform(); + + //##Documentation + //## @brief Get the parametric bounding-box + //## + //## See AbstractTransformGeometry for an example usage of this. + itkGetConstObjectMacro(ParametricBoundingBox, BoundingBox); + //##Documentation + //## @brief Get the parametric bounds + //## + //## See AbstractTransformGeometry for an example usage of this. + const BoundingBox::BoundsArrayType& GetParametricBounds() const + { + assert(m_ParametricBoundingBox.IsNotNull()); + return m_ParametricBoundingBox->GetBounds(); + } + + //##Documentation + //## @brief Get the parametric extent + //## + //## See AbstractTransformGeometry for an example usage of this. + mitk::ScalarType GetParametricExtent(int direction) const + { + if (direction < 0 || direction>=3) + mitkThrow() << "Invalid direction. Must be between either 0, 1 or 2. "; + assert(m_ParametricBoundingBox.IsNotNull()); + + BoundingBoxType::BoundsArrayType bounds = m_ParametricBoundingBox->GetBounds(); + return bounds[direction*2+1]-bounds[direction*2]; + } + + //##Documentation + //## @brief Get the parametric extent in mm + //## + //## See AbstractTransformGeometry for an example usage of this. + virtual mitk::ScalarType GetParametricExtentInMM(int direction) const + { + return GetExtentInMM(direction); + } + + //##Documentation + //## @brief Get the parametric transform + //## + //## See AbstractTransformGeometry for an example usage of this. + virtual const Transform3D* GetParametricTransform() const + { + return m_IndexToWorldTransform; + } + + //##Documentation + //## @brief Calculates a bounding-box around the geometry relative + //## to a coordinate system defined by a transform + //## + mitk::BoundingBox::Pointer CalculateBoundingBoxRelativeToTransform(const mitk::AffineTransform3D* transform) const; + + //##Documentation + //## @brief clones the geometry + //## + //## Overwrite in all sub-classes. + //## Normally looks like: + //## \code + //## Self::Pointer newGeometry = new Self(*this); + //## newGeometry->UnRegister(); + //## return newGeometry.GetPointer(); + //## \endcode + virtual itk::LightObject::Pointer InternalClone() const; + + //##Documentation + //##@brief executes affine operations (translate, rotate, scale) + virtual void ExecuteOperation(Operation* operation); + + /** Get the extent of the bounding box */ + ScalarType GetExtent(unsigned int direction) const + { + assert(m_BoundingBox.IsNotNull()); + if (direction>=NDimensions) + mitkThrow() << "Direction is too big. This geometry is for 3D Data"; + BoundsArrayType bounds = m_BoundingBox->GetBounds(); + return bounds[direction*2+1]-bounds[direction*2]; + } + protected: + Geometry3D(); + Geometry3D(const Geometry3D& other); + + static const std::string GetTransformAsString( TransformType* transformType ); + + virtual ~Geometry3D(); + + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + + virtual void BackTransform(const mitk::Point3D& in, mitk::Point3D& out) const; + //##Documentation + //## @brief Deprecated + virtual void BackTransform(const mitk::Point3D& at, const mitk::Vector3D& in, mitk::Vector3D& out) const; + + //Without redundant parameter Point3D + virtual void BackTransform(const mitk::Vector3D& in, mitk::Vector3D& out) const; + + //##Documentation + //## @brief Set the parametric bounds + //## + //## Protected in this class, made public in some sub-classes, e.g., + //## ExternAbstractTransformGeometry. + virtual void SetParametricBounds(const BoundingBox::BoundsArrayType& bounds); + + /** Resets sub-transforms that compose m_IndexToWorldTransform, by using + * the current value of m_IndexToWorldTransform and setting the rotation + * component to zero. */ + virtual void ResetSubTransforms(); + + bool m_ImageGeometry; + + static const std::string INDEX_TO_OBJECT_TRANSFORM; + static const std::string OBJECT_TO_NODE_TRANSFORM; + static const std::string INDEX_TO_NODE_TRANSFORM; + static const std::string INDEX_TO_WORLD_TRANSFORM; + }; + + // + // Static compare functions mainly for testing + // + /** + * @brief Equal A function comparing two geometries for beeing identical. + * + * @ingroup MITKTestingAPI + * + * The function compares the spacing, origin, axisvectors, extents, the matrix of the + * IndexToWorldTransform (elementwise), the bounding (elementwise) and the ImageGeometry flag. + * + * The parameter eps is a tolarence value for all methods which are internally used for comparion. + * If you want to use different tolarance values for different parts of the geometry, feel free to use + * the other comparison methods and write your own implementation of Equal. + * @param rightHandSide Compare this against leftHandSide. + * @param leftHandSide Compare this against rightHandSide. + * @param eps Tolarence for comparison. You can use mitk::eps in most cases. + * @param verbose Flag indicating if the user wants detailed console output or not. + * @return True, if all comparison are true. False in any other case. + */ + MITK_CORE_EXPORT bool Equal(const mitk::Geometry3D* leftHandSide, const mitk::Geometry3D* rightHandSide, ScalarType eps, bool verbose); + + /** + * @brief Equal A function comparing two transforms (TransformType) for beeing identical. + * + * @ingroup MITKTestingAPI + * + * The function compares the IndexToWorldTransform (elementwise). + * + * The parameter eps is a tolarence value for all methods which are internally used for comparion. + * @param rightHandSide Compare this against leftHandSide. + * @param leftHandSide Compare this against rightHandSide. + * @param eps Tolarence for comparison. You can use mitk::eps in most cases. + * @param verbose Flag indicating if the user wants detailed console output or not. + * @return True, if all comparison are true. False in any other case. + */ + MITK_CORE_EXPORT bool Equal(const mitk::Geometry3D::TransformType *leftHandSide, const mitk::Geometry3D::TransformType *rightHandSide, ScalarType eps, bool verbose); + + /** + * @brief Equal A function comparing two bounding boxes (BoundingBoxType) for beeing identical. + * + * @ingroup MITKTestingAPI + * + * The function compares the bounds (elementwise). + * + * The parameter eps is a tolarence value for all methods which are internally used for comparion. + * @param rightHandSide Compare this against leftHandSide. + * @param leftHandSide Compare this against rightHandSide. + * @param eps Tolarence for comparison. You can use mitk::eps in most cases. + * @param verbose Flag indicating if the user wants detailed console output or not. + * @return True, if all comparison are true. False in any other case. + */ + MITK_CORE_EXPORT bool Equal( const mitk::Geometry3D::BoundingBoxType *leftHandSide, const mitk::Geometry3D::BoundingBoxType *rightHandSide, ScalarType eps, bool verbose); } // namespace mitk #endif /* GEOMETRY3D_H_HEADER_INCLUDED_C1EBD0AD */ diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 25c1ef4505..2f67a23e30 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,179 +1,180 @@ # tests with no extra command line parameter set(MODULE_TESTS mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkDispatcherTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry2DTest.cpp mitkGeometry3DTest.cpp mitkGeometry3DEqualTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageEqualTest.cpp mitkImageDataItemTest.cpp mitkImageGeneratorTest.cpp mitkIOUtilTest.cpp mitkBaseDataTest.cpp mitkImportItkImageTest.cpp mitkGrabItkImageMemoryTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkInteractorTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetEqualTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetWriterTest.cpp mitkPointSetReaderTest.cpp mitkPointSetInteractorTest.cpp mitkPropertyTest.cpp mitkPropertyListTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceEqualTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp mitkExceptionTest.cpp mitkExtractSliceFilterTest.cpp mitkLogTest.cpp mitkImageDimensionConverterTest.cpp mitkLoggingAdapterTest.cpp mitkUIDGeneratorTest.cpp mitkShaderRepositoryTest.cpp mitkPlanePositionManagerTest.cpp mitkAffineTransformBaseTest.cpp mitkPropertyAliasesTest.cpp mitkPropertyDescriptionsTest.cpp mitkPropertyExtensionsTest.cpp mitkPropertyFiltersTest.cpp mitkTinyXMLTest.cpp mitkRawImageFileReaderTest.cpp mitkInteractionEventTest.cpp mitkLookupTableTest.cpp mitkSTLFileReaderTest.cpp + mitkBaseGeometryTest.cpp ################## DISABLED TESTS ################################################# #mitkAbstractTransformGeometryTest.cpp #seems as tested class mitkExternAbstractTransformGeometry doesnt exist any more #mitkStateMachineContainerTest.cpp #rewrite test, indirect since no longer exported Bug 14529 #mitkRegistrationBaseTest.cpp #tested class mitkRegistrationBase doesn't exist any more #mitkSegmentationInterpolationTest.cpp #file doesn't exist! #mitkPipelineSmartPointerCorrectnessTest.cpp #file doesn't exist! #mitkITKThreadingTest.cpp #test outdated because itk::Semaphore was removed from ITK #mitkAbstractTransformPlaneGeometryTest.cpp #mitkVtkAbstractTransformPlaneGeometry doesn't exist any more #mitkTestUtilSharedLibrary.cpp #Linker problem with this test... #mitkTextOverlay2DSymbolsRenderingTest.cpp #Implementation of the tested feature is not finished yet. Ask Christoph or see bug 15104 for details. ) # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkImageTimeSelectorTest.cpp #only runs on images mitkImageAccessorTest.cpp #only runs on images mitkDataNodeFactoryTest.cpp #runs on all types of data ) set(MODULE_SURFACE_TESTS mitkSurfaceVtkWriterTest.cpp #only runs on surfaces mitkDataNodeFactoryTest.cpp #runs on all types of data ) # list of images for which the tests are run set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) set(MODULE_TESTSURFACES binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkDicomSeriesReaderTest.cpp mitkDICOMLocaleTest.cpp mitkEventMapperTest.cpp mitkEventConfigTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkStateMachineFactoryTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageWriterTest.cpp mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp mitkImageVtkMapper2DTransferFunctionTest.cpp mitkImageVtkMapper2DLookupTableTest.cpp mitkSurfaceVtkMapper3DTest mitkSurfaceVtkMapper3DTexturedSphereTest.cpp mitkSurfaceGLMapper2DColorTest.cpp mitkSurfaceGLMapper2DOpacityTest.cpp mitkVolumeCalculatorTest.cpp mitkLevelWindowManagerTest.cpp mitkPointSetVtkMapper2DTest.cpp mitkPointSetVtkMapper2DImageTest.cpp mitkPointSetVtkMapper2DGlyphTypeTest.cpp mitkPointSetVtkMapper2DTransformedPointsTest.cpp mitkLabelOverlay3DRendering2DTest.cpp mitkLabelOverlay3DRendering3DTest.cpp mitkTextOverlay2DRenderingTest.cpp mitkTextOverlay2DLayouterRenderingTest.cpp mitkTextOverlay3DRendering2DTest.cpp mitkTextOverlay3DRendering3DTest.cpp mitkTextOverlay3DColorRenderingTest.cpp mitkVTKRenderWindowSizeTest.cpp mitkMultiComponentImageDataComparisonFilterTest.cpp mitkImageToItkTest.cpp mitkImageSliceSelectorTest.cpp ) set(MODULE_RESOURCE_FILES Interactions/AddAndRemovePoints.xml Interactions/globalConfig.xml Interactions/StatemachineTest.xml Interactions/StatemachineConfigTest.xml ) # Create an artificial module initializing class for # the usServiceListenerTest.cpp usFunctionGenerateExecutableInit(testdriver_init_file IDENTIFIER ${MODULE_NAME}TestDriver ) # Embed the resources set(testdriver_resources ) usFunctionEmbedResources(testdriver_resources EXECUTABLE_NAME ${MODULE_NAME}TestDriver ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Resources FILES ${MODULE_RESOURCE_FILES} ) set(TEST_CPP_FILES ${testdriver_init_file} ${testdriver_resources}) diff --git a/Core/Code/Testing/mitkBaseGeometryTest.cpp b/Core/Code/Testing/mitkBaseGeometryTest.cpp new file mode 100644 index 0000000000..f5215b425d --- /dev/null +++ b/Core/Code/Testing/mitkBaseGeometryTest.cpp @@ -0,0 +1,107 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkTestingMacros.h" +#include +#include + +#include +#include +#include + +#include + +//typedef itk::BoundingBox BoundingBox; +//typedef BoundingBoxType::Pointer BoundingBoxPointer; + +// Dummy instance of abstract base class +class DummyTestClass : public mitk::BaseGeometry +{ +public: + DummyTestClass():BaseGeometry(){} + DummyTestClass(const DummyTestClass& other) : BaseGeometry(other){} + ~DummyTestClass(){} + + void DummyTestClass::ExecuteOperation(mitk::Operation* operation){} +}; + +class mitkBaseGeometryTestSuite : public mitk::TestFixture +{ + // List of Tests + CPPUNIT_TEST_SUITE(mitkBaseGeometryTestSuite); + MITK_TEST(TestConstructor); + MITK_TEST(TestSetOrigin); + CPPUNIT_TEST_SUITE_END(); + + // Used Variables +private: + mitk::Point3D aPoint; + +public: + + // Set up for variables + void setUp() + { + mitk::FillVector3D(aPoint, 2,3,4); + } + + // Test functions + + void TestSetOrigin() + { + DummyTestClass dummy1; + dummy1.SetOrigin(aPoint); + CPPUNIT_ASSERT(aPoint==dummy1.GetOrigin()); + } + + void TestConstructor() + { + //test standard constructor + DummyTestClass dummy1; + + CPPUNIT_ASSERT(dummy1.IsValid() == true); + CPPUNIT_ASSERT(2==1); + /* + CPPUNIT_ASSERT(dummy1.m_FrameOfReferenceID==0); + CPPUNIT_ASSERT(dummy1.m_IndexToWorldTransformLastModified==0); + float l_FloatSpacing[3]; + mitk::FillVector3D(l_FloatSpacing, 1,1,1); + CPPUNIT_ASSERT(dummy1.m_FloatSpacing[0]==l_FloatSpacing[0]); + CPPUNIT_ASSERT(dummy1.m_FloatSpacing[1]==l_FloatSpacing[1]); + CPPUNIT_ASSERT(dummy1.m_FloatSpacing[2]==l_FloatSpacing[2]); + mitk::Vector3D l_Spacing; + mitk::FillVector3D(l_Spacing, 1,1,1); + CPPUNIT_ASSERT(dummy1.m_Spacing[0]==l_Spacing[0]); + CPPUNIT_ASSERT(dummy1.m_Spacing[1]==l_Spacing[1]); + CPPUNIT_ASSERT(dummy1.m_Spacing[2]==l_Spacing[2]); + mitk::Point3D l_Origin; + mitk::FillVector3D(l_Origin,0,0,0); + CPPUNIT_ASSERT(dummy1.GetOrigin()==l_Origin); + + //xx missing: Bounding box test m_ParametricBoundingBox m_BoundingBox m_TimeBounds[0] + // m_IndexToWorldTransform->SetIdentity(); + // m_VtkMatrix + // m_VtkIndexToWorldTransform + // m_RotationQuaternion + // m_InvertedTransform*/ + + //test BaseGeometry(const BaseGeometry& other) constructor + // DummyTestClass dummy2; + //CPPUNIT_ASSERT(Equal(dummy1,dummy2,mitk::eps,true)); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkBaseGeometry) diff --git a/Core/Code/Testing/mitkGeometry3DTest.cpp b/Core/Code/Testing/mitkGeometry3DTest.cpp index fff1266cea..486683b9cd 100644 --- a/Core/Code/Testing/mitkGeometry3DTest.cpp +++ b/Core/Code/Testing/mitkGeometry3DTest.cpp @@ -1,614 +1,614 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkGeometry3D.h" #include #include #include "mitkRotationOperation.h" #include "mitkInteractionConst.h" #include #include #include "mitkTestingMacros.h" #include #include bool testGetAxisVectorVariants(mitk::Geometry3D* geometry) { - int direction; - for(direction=0; direction<3; ++direction) - { - mitk::Vector3D frontToBack; - switch(direction) - { - case 0: frontToBack = geometry->GetCornerPoint(false, false, false)-geometry->GetCornerPoint(true , false, false); break; //7-3 - case 1: frontToBack = geometry->GetCornerPoint(false, false, false)-geometry->GetCornerPoint(false, true , false); break; //7-5 - case 2: frontToBack = geometry->GetCornerPoint(false, false, false)-geometry->GetCornerPoint(false , false, true); break; //7-2 - } - std::cout << "Testing GetAxisVector(int) vs GetAxisVector(bool, bool, bool): "; - if(mitk::Equal(geometry->GetAxisVector(direction), frontToBack) == false) - { - std::cout<<"[FAILED]"<GetCornerPoint(false, false, false)-geometry->GetCornerPoint(true , false, false); break; //7-3 + case 1: frontToBack = geometry->GetCornerPoint(false, false, false)-geometry->GetCornerPoint(false, true , false); break; //7-5 + case 2: frontToBack = geometry->GetCornerPoint(false, false, false)-geometry->GetCornerPoint(false , false, true); break; //7-2 + } + std::cout << "Testing GetAxisVector(int) vs GetAxisVector(bool, bool, bool): "; + if(mitk::Equal(geometry->GetAxisVector(direction), frontToBack) == false) + { + std::cout<<"[FAILED]"<GetAxisVector(direction).GetNorm(), geometry->GetExtentInMM(direction)) == false) - { - std::cout<<"[FAILED]"<GetAxisVector(direction).GetNorm(), geometry->GetExtentInMM(direction)) == false) + { + std::cout<<"[FAILED]"<GetOrigin(); - mitk::Point3D dummy; - - MITK_TEST_OUTPUT( << " Testing index->world->index conversion consistency"); - geometry3d->WorldToIndex(origin, dummy); - geometry3d->IndexToWorld(dummy, dummy); - MITK_TEST_CONDITION_REQUIRED(dummy == origin, ""); - - MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin, mitk::Point3D)==(0,0,0)"); - mitk::Point3D globalOrigin; - mitk::FillVector3D(globalOrigin, 0,0,0); - - mitk::Point3D originContinuousIndex; - geometry3d->WorldToIndex(origin, originContinuousIndex); - MITK_TEST_CONDITION_REQUIRED(originContinuousIndex == globalOrigin, ""); - - MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin, itk::Index)==(0,0,0)"); - itk::Index<3> itkindex; - geometry3d->WorldToIndex(origin, itkindex); - itk::Index<3> globalOriginIndex; - mitk::vtk2itk(globalOrigin, globalOriginIndex); - MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); - - MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin-0.5*spacing, itk::Index)==(0,0,0)"); - mitk::Vector3D halfSpacingStep = geometry3d->GetSpacing()*0.5; - mitk::Matrix3D rotation; - mitk::Point3D originOffCenter = origin-halfSpacingStep; - geometry3d->WorldToIndex(originOffCenter, itkindex); - MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); - - MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)"); - originOffCenter = origin+halfSpacingStep; - originOffCenter -= 0.0001; - geometry3d->WorldToIndex( originOffCenter, itkindex); - MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); - - MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)"); - originOffCenter = origin+halfSpacingStep; - itk::Index<3> global111; - mitk::FillVector3D(global111, 1,1,1); - geometry3d->WorldToIndex( originOffCenter, itkindex); - MITK_TEST_CONDITION_REQUIRED(itkindex == global111, ""); - - MITK_TEST_OUTPUT( << " Testing WorldToIndex(GetCenter())==BoundingBox.GetCenter: "); - mitk::Point3D center = geometry3d->GetCenter(); - mitk::Point3D centerContIndex; - geometry3d->WorldToIndex(center, centerContIndex); - mitk::BoundingBox::ConstPointer boundingBox = geometry3d->GetBoundingBox(); - mitk::BoundingBox::PointType centerBounds = boundingBox->GetCenter(); - MITK_TEST_CONDITION_REQUIRED(mitk::Equal(centerContIndex,centerBounds), ""); - - MITK_TEST_OUTPUT( << " Testing GetCenter()==IndexToWorld(BoundingBox.GetCenter): "); - center = geometry3d->GetCenter(); - mitk::Point3D centerBoundsInWorldCoords; - geometry3d->IndexToWorld(centerBounds, centerBoundsInWorldCoords); - MITK_TEST_CONDITION_REQUIRED(mitk::Equal(center,centerBoundsInWorldCoords), ""); - - return EXIT_SUCCESS; + MITK_TEST_OUTPUT( << "Testing consistency of index and world coordinate systems: "); + mitk::Point3D origin = geometry3d->GetOrigin(); + mitk::Point3D dummy; + + MITK_TEST_OUTPUT( << " Testing index->world->index conversion consistency"); + geometry3d->WorldToIndex(origin, dummy); + geometry3d->IndexToWorld(dummy, dummy); + MITK_TEST_CONDITION_REQUIRED(dummy == origin, ""); + + MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin, mitk::Point3D)==(0,0,0)"); + mitk::Point3D globalOrigin; + mitk::FillVector3D(globalOrigin, 0,0,0); + + mitk::Point3D originContinuousIndex; + geometry3d->WorldToIndex(origin, originContinuousIndex); + MITK_TEST_CONDITION_REQUIRED(originContinuousIndex == globalOrigin, ""); + + MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin, itk::Index)==(0,0,0)"); + itk::Index<3> itkindex; + geometry3d->WorldToIndex(origin, itkindex); + itk::Index<3> globalOriginIndex; + mitk::vtk2itk(globalOrigin, globalOriginIndex); + MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); + + MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin-0.5*spacing, itk::Index)==(0,0,0)"); + mitk::Vector3D halfSpacingStep = geometry3d->GetSpacing()*0.5; + mitk::Matrix3D rotation; + mitk::Point3D originOffCenter = origin-halfSpacingStep; + geometry3d->WorldToIndex(originOffCenter, itkindex); + MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); + + MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)"); + originOffCenter = origin+halfSpacingStep; + originOffCenter -= 0.0001; + geometry3d->WorldToIndex( originOffCenter, itkindex); + MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); + + MITK_TEST_OUTPUT( << " Testing WorldToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)"); + originOffCenter = origin+halfSpacingStep; + itk::Index<3> global111; + mitk::FillVector3D(global111, 1,1,1); + geometry3d->WorldToIndex( originOffCenter, itkindex); + MITK_TEST_CONDITION_REQUIRED(itkindex == global111, ""); + + MITK_TEST_OUTPUT( << " Testing WorldToIndex(GetCenter())==BoundingBox.GetCenter: "); + mitk::Point3D center = geometry3d->GetCenter(); + mitk::Point3D centerContIndex; + geometry3d->WorldToIndex(center, centerContIndex); + mitk::BoundingBox::ConstPointer boundingBox = geometry3d->GetBoundingBox(); + mitk::BoundingBox::PointType centerBounds = boundingBox->GetCenter(); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(centerContIndex,centerBounds), ""); + + MITK_TEST_OUTPUT( << " Testing GetCenter()==IndexToWorld(BoundingBox.GetCenter): "); + center = geometry3d->GetCenter(); + mitk::Point3D centerBoundsInWorldCoords; + geometry3d->IndexToWorld(centerBounds, centerBoundsInWorldCoords); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(center,centerBoundsInWorldCoords), ""); + + return EXIT_SUCCESS; } int testIndexAndWorldConsistencyForVectors(mitk::Geometry3D* geometry3d) { - MITK_TEST_OUTPUT( << "Testing consistency of index and world coordinate systems for vectors: "); - mitk::Vector3D xAxisMM = geometry3d->GetAxisVector(0); - mitk::Vector3D xAxisContinuousIndex; - mitk::Vector3D xAxisContinuousIndexDeprecated; - - mitk::Point3D p, pIndex, origin; - origin = geometry3d->GetOrigin(); - p[0] = xAxisMM[0]; - p[1] = xAxisMM[1]; - p[2] = xAxisMM[2]; - - geometry3d->WorldToIndex(p,pIndex); - - geometry3d->WorldToIndex(xAxisMM, xAxisContinuousIndexDeprecated); - geometry3d->WorldToIndex(xAxisMM,xAxisContinuousIndex); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[0] == pIndex[0],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[1] == pIndex[1],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[2] == pIndex[2],""); - - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[0] == xAxisContinuousIndexDeprecated[0],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[1] == xAxisContinuousIndexDeprecated[1],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[2] == xAxisContinuousIndexDeprecated[2],""); - - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[0] == pIndex[0],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[1] == pIndex[1],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[2] == pIndex[2],""); - - geometry3d->IndexToWorld(xAxisContinuousIndex,xAxisContinuousIndex); - geometry3d->IndexToWorld(xAxisContinuousIndexDeprecated,xAxisContinuousIndexDeprecated); - geometry3d->IndexToWorld(pIndex,p); - - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex == xAxisMM,""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[0] == p[0],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[1] == p[1],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[2] == p[2],""); - - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated == xAxisMM,""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[0] == p[0],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[1] == p[1],""); - MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[2] == p[2],""); - - return EXIT_SUCCESS; + MITK_TEST_OUTPUT( << "Testing consistency of index and world coordinate systems for vectors: "); + mitk::Vector3D xAxisMM = geometry3d->GetAxisVector(0); + mitk::Vector3D xAxisContinuousIndex; + mitk::Vector3D xAxisContinuousIndexDeprecated; + + mitk::Point3D p, pIndex, origin; + origin = geometry3d->GetOrigin(); + p[0] = xAxisMM[0]; + p[1] = xAxisMM[1]; + p[2] = xAxisMM[2]; + + geometry3d->WorldToIndex(p,pIndex); + + geometry3d->WorldToIndex(xAxisMM, xAxisContinuousIndexDeprecated); + geometry3d->WorldToIndex(xAxisMM,xAxisContinuousIndex); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[0] == pIndex[0],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[1] == pIndex[1],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[2] == pIndex[2],""); + + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[0] == xAxisContinuousIndexDeprecated[0],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[1] == xAxisContinuousIndexDeprecated[1],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[2] == xAxisContinuousIndexDeprecated[2],""); + + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[0] == pIndex[0],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[1] == pIndex[1],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[2] == pIndex[2],""); + + geometry3d->IndexToWorld(xAxisContinuousIndex,xAxisContinuousIndex); + geometry3d->IndexToWorld(xAxisContinuousIndexDeprecated,xAxisContinuousIndexDeprecated); + geometry3d->IndexToWorld(pIndex,p); + + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex == xAxisMM,""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[0] == p[0],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[1] == p[1],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndex[2] == p[2],""); + + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated == xAxisMM,""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[0] == p[0],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[1] == p[1],""); + MITK_TEST_CONDITION_REQUIRED(xAxisContinuousIndexDeprecated[2] == p[2],""); + + return EXIT_SUCCESS; } int testIndexAndWorldConsistencyForIndex(mitk::Geometry3D* geometry3d) { - MITK_TEST_OUTPUT( << "Testing consistency of index and world coordinate systems: "); - - // creating testing data - itk::Index<4> itkIndex4, itkIndex4b; - itk::Index<3> itkIndex3, itkIndex3b; - itk::Index<2> itkIndex2, itkIndex2b; - mitk::Index3D mitkIndex, mitkIndexb; - - itkIndex4[0] = itkIndex4[1] = itkIndex4[2] = itkIndex4[3] = 4; - itkIndex3[0] = itkIndex3[1] = itkIndex3[2] = 6; - itkIndex2[0] = itkIndex2[1] = 2; - mitkIndex[0] = mitkIndex[1] = mitkIndex[2] = 13; - - // check for constistency - mitk::Point3D point; - geometry3d->IndexToWorld(itkIndex2,point); - geometry3d->WorldToIndex(point,itkIndex2b); - - MITK_TEST_CONDITION_REQUIRED( - ((itkIndex2b[0] == itkIndex2[0]) && - (itkIndex2b[1] == itkIndex2[1])), - "Testing itk::index<2> for IndexToWorld/WorldToIndex consistency"); - - geometry3d->IndexToWorld(itkIndex3,point); - geometry3d->WorldToIndex(point,itkIndex3b); - - MITK_TEST_CONDITION_REQUIRED( - ((itkIndex3b[0] == itkIndex3[0]) && - (itkIndex3b[1] == itkIndex3[1]) && - (itkIndex3b[2] == itkIndex3[2])), - "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency"); - - geometry3d->IndexToWorld(itkIndex4,point); - geometry3d->WorldToIndex(point,itkIndex4b); - - MITK_TEST_CONDITION_REQUIRED( - ((itkIndex4b[0] == itkIndex4[0]) && - (itkIndex4b[1] == itkIndex4[1]) && - (itkIndex4b[2] == itkIndex4[2]) && - (itkIndex4b[3] == 0)), - "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency"); - - geometry3d->IndexToWorld(mitkIndex,point); - geometry3d->WorldToIndex(point,mitkIndexb); - - MITK_TEST_CONDITION_REQUIRED( - ((mitkIndexb[0] == mitkIndex[0]) && - (mitkIndexb[1] == mitkIndex[1]) && - (mitkIndexb[2] == mitkIndex[2])), - "Testing mitk::Index for IndexToWorld/WorldToIndex consistency"); - - return EXIT_SUCCESS; + MITK_TEST_OUTPUT( << "Testing consistency of index and world coordinate systems: "); + + // creating testing data + itk::Index<4> itkIndex4, itkIndex4b; + itk::Index<3> itkIndex3, itkIndex3b; + itk::Index<2> itkIndex2, itkIndex2b; + mitk::Index3D mitkIndex, mitkIndexb; + + itkIndex4[0] = itkIndex4[1] = itkIndex4[2] = itkIndex4[3] = 4; + itkIndex3[0] = itkIndex3[1] = itkIndex3[2] = 6; + itkIndex2[0] = itkIndex2[1] = 2; + mitkIndex[0] = mitkIndex[1] = mitkIndex[2] = 13; + + // check for constistency + mitk::Point3D point; + geometry3d->IndexToWorld(itkIndex2,point); + geometry3d->WorldToIndex(point,itkIndex2b); + + MITK_TEST_CONDITION_REQUIRED( + ((itkIndex2b[0] == itkIndex2[0]) && + (itkIndex2b[1] == itkIndex2[1])), + "Testing itk::index<2> for IndexToWorld/WorldToIndex consistency"); + + geometry3d->IndexToWorld(itkIndex3,point); + geometry3d->WorldToIndex(point,itkIndex3b); + + MITK_TEST_CONDITION_REQUIRED( + ((itkIndex3b[0] == itkIndex3[0]) && + (itkIndex3b[1] == itkIndex3[1]) && + (itkIndex3b[2] == itkIndex3[2])), + "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency"); + + geometry3d->IndexToWorld(itkIndex4,point); + geometry3d->WorldToIndex(point,itkIndex4b); + + MITK_TEST_CONDITION_REQUIRED( + ((itkIndex4b[0] == itkIndex4[0]) && + (itkIndex4b[1] == itkIndex4[1]) && + (itkIndex4b[2] == itkIndex4[2]) && + (itkIndex4b[3] == 0)), + "Testing itk::index<3> for IndexToWorld/WorldToIndex consistency"); + + geometry3d->IndexToWorld(mitkIndex,point); + geometry3d->WorldToIndex(point,mitkIndexb); + + MITK_TEST_CONDITION_REQUIRED( + ((mitkIndexb[0] == mitkIndex[0]) && + (mitkIndexb[1] == mitkIndex[1]) && + (mitkIndexb[2] == mitkIndex[2])), + "Testing mitk::Index for IndexToWorld/WorldToIndex consistency"); + + return EXIT_SUCCESS; } #include int testItkImageIsCenterBased() { - MITK_TEST_OUTPUT(<< "Testing whether itk::Image coordinates are center-based."); - typedef itk::Image ItkIntImage3D; - ItkIntImage3D::Pointer itkintimage = ItkIntImage3D::New(); - ItkIntImage3D::SizeType size; - size.Fill(10); - mitk::Point3D origin; - mitk::FillVector3D(origin, 2,3,7); - itkintimage->Initialize(); - itkintimage->SetRegions(size); - itkintimage->SetOrigin(origin); - std::cout<<"[PASSED]"< originContinuousIndex; - itkintimage->TransformPhysicalPointToContinuousIndex(origin, originContinuousIndex); - MITK_TEST_CONDITION_REQUIRED(originContinuousIndex == globalOrigin, ""); - - MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin)==(0,0,0)"); - itk::Index<3> itkindex; - itkintimage->TransformPhysicalPointToIndex(origin, itkindex); - itk::Index<3> globalOriginIndex; - mitk::vtk2itk(globalOrigin, globalOriginIndex); - MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); - - MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin-0.5*spacing)==(0,0,0)"); - mitk::Vector3D halfSpacingStep = itkintimage->GetSpacing()*0.5; - mitk::Matrix3D rotation; - mitk::Point3D originOffCenter = origin-halfSpacingStep; - itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex); - MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); - - MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)"); - originOffCenter = origin+halfSpacingStep; - originOffCenter -= 0.0001; - itkintimage->TransformPhysicalPointToIndex( originOffCenter, itkindex); - MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); - - MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)"); - originOffCenter = origin+halfSpacingStep; - itk::Index<3> global111; - mitk::FillVector3D(global111, 1,1,1); - itkintimage->TransformPhysicalPointToIndex( originOffCenter, itkindex); - MITK_TEST_CONDITION_REQUIRED(itkindex == global111, ""); - - MITK_TEST_OUTPUT( << "=> Yes, itk::Image coordinates are center-based."); - - return EXIT_SUCCESS; + MITK_TEST_OUTPUT(<< "Testing whether itk::Image coordinates are center-based."); + typedef itk::Image ItkIntImage3D; + ItkIntImage3D::Pointer itkintimage = ItkIntImage3D::New(); + ItkIntImage3D::SizeType size; + size.Fill(10); + mitk::Point3D origin; + mitk::FillVector3D(origin, 2,3,7); + itkintimage->Initialize(); + itkintimage->SetRegions(size); + itkintimage->SetOrigin(origin); + std::cout<<"[PASSED]"< originContinuousIndex; + itkintimage->TransformPhysicalPointToContinuousIndex(origin, originContinuousIndex); + MITK_TEST_CONDITION_REQUIRED(originContinuousIndex == globalOrigin, ""); + + MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin)==(0,0,0)"); + itk::Index<3> itkindex; + itkintimage->TransformPhysicalPointToIndex(origin, itkindex); + itk::Index<3> globalOriginIndex; + mitk::vtk2itk(globalOrigin, globalOriginIndex); + MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); + + MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin-0.5*spacing)==(0,0,0)"); + mitk::Vector3D halfSpacingStep = itkintimage->GetSpacing()*0.5; + mitk::Matrix3D rotation; + mitk::Point3D originOffCenter = origin-halfSpacingStep; + itkintimage->TransformPhysicalPointToIndex(originOffCenter, itkindex); + MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); + + MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)"); + originOffCenter = origin+halfSpacingStep; + originOffCenter -= 0.0001; + itkintimage->TransformPhysicalPointToIndex( originOffCenter, itkindex); + MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, ""); + + MITK_TEST_OUTPUT( << " Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)"); + originOffCenter = origin+halfSpacingStep; + itk::Index<3> global111; + mitk::FillVector3D(global111, 1,1,1); + itkintimage->TransformPhysicalPointToIndex( originOffCenter, itkindex); + MITK_TEST_CONDITION_REQUIRED(itkindex == global111, ""); + + MITK_TEST_OUTPUT( << "=> Yes, itk::Image coordinates are center-based."); + + return EXIT_SUCCESS; } int testGeometry3D(bool imageGeometry) { - // Build up a new image Geometry - mitk::Geometry3D::Pointer geometry3d = mitk::Geometry3D::New(); - float bounds[ ] = {-10.0, 17.0, -12.0, 188.0, 13.0, 211.0}; - - MITK_TEST_OUTPUT( << "Initializing"); - geometry3d->Initialize(); - - MITK_TEST_OUTPUT(<< "Setting ImageGeometry to " << imageGeometry); - geometry3d->SetImageGeometry(imageGeometry); - - MITK_TEST_OUTPUT(<< "Setting bounds by SetFloatBounds(): " << bounds); - geometry3d->SetFloatBounds(bounds); - - MITK_TEST_OUTPUT( << "Testing AxisVectors"); - if(testGetAxisVectorVariants(geometry3d) == false) - return EXIT_FAILURE; - - if(testGetAxisVectorExtent(geometry3d) == false) - return EXIT_FAILURE; - - MITK_TEST_OUTPUT( << "Creating an AffineTransform3D transform"); - mitk::AffineTransform3D::MatrixType matrix; - matrix.SetIdentity(); - matrix(1,1) = 2; - mitk::AffineTransform3D::Pointer transform; - transform = mitk::AffineTransform3D::New(); - transform->SetMatrix(matrix); - - MITK_TEST_OUTPUT( << "Testing a SetIndexToWorldTransform"); - geometry3d->SetIndexToWorldTransform(transform); - - MITK_TEST_OUTPUT( << "Testing correctness of value returned by GetSpacing"); - const mitk::Vector3D& spacing1 = geometry3d->GetSpacing(); - mitk::Vector3D expectedSpacing; - expectedSpacing.Fill(1.0); - expectedSpacing[1] = 2; - if( mitk::Equal(spacing1, expectedSpacing) == false ) - { - MITK_TEST_OUTPUT( << " [FAILED]"); - return EXIT_FAILURE; - } - - MITK_TEST_OUTPUT( << "Testing a Compose(transform)"); - geometry3d->Compose(transform); - - MITK_TEST_OUTPUT( << "Testing correctness of value returned by GetSpacing"); - const mitk::Vector3D& spacing2 = geometry3d->GetSpacing(); - expectedSpacing[1] = 4; - if( mitk::Equal(spacing2, expectedSpacing) == false ) - { - MITK_TEST_OUTPUT( << " [FAILED]"); - return EXIT_FAILURE; - } - - MITK_TEST_OUTPUT( << "Testing correctness of SetSpacing"); - mitk::Vector3D newspacing; - mitk::FillVector3D(newspacing, 1.5, 2.5, 3.5); - geometry3d->SetSpacing(newspacing); - const mitk::Vector3D& spacing3 = geometry3d->GetSpacing(); - if( mitk::Equal(spacing3, newspacing) == false ) - { - MITK_TEST_OUTPUT( << " [FAILED]"); - return EXIT_FAILURE; - } - - // Seperate Test function for Index and World consistency - testIndexAndWorldConsistency(geometry3d); - testIndexAndWorldConsistencyForVectors(geometry3d); - testIndexAndWorldConsistencyForIndex(geometry3d); - - MITK_TEST_OUTPUT( << "Testing a rotation of the geometry"); - double angle = 35.0; - mitk::Vector3D rotationVector; mitk::FillVector3D( rotationVector, 1, 0, 0 ); - mitk::Point3D center = geometry3d->GetCenter(); - mitk::RotationOperation* op = new mitk::RotationOperation( mitk::OpROTATE, center, rotationVector, angle ); - geometry3d->ExecuteOperation(op); - - MITK_TEST_OUTPUT( << "Testing mitk::GetRotation() and success of rotation"); - mitk::Matrix3D rotation; - mitk::GetRotation(geometry3d, rotation); - mitk::Vector3D voxelStep=rotation*newspacing; - mitk::Vector3D voxelStepIndex; - geometry3d->WorldToIndex(voxelStep, voxelStepIndex); - mitk::Vector3D expectedVoxelStepIndex; - expectedVoxelStepIndex.Fill(1); - MITK_TEST_CONDITION_REQUIRED(mitk::Equal(voxelStepIndex,expectedVoxelStepIndex), ""); - delete op; - std::cout<<"[PASSED]"<GetImageGeometry() == imageGeometry, ""); - - //Test if the translate function moves the origin correctly. - mitk::Point3D oldOrigin = geometry3d->GetOrigin(); - - //use some random values for translation - mitk::Vector3D translationVector; - translationVector.SetElement(0, 17.5f); - translationVector.SetElement(1, -32.3f); - translationVector.SetElement(2, 4.0f); - //compute ground truth - mitk::Point3D tmpResult = geometry3d->GetOrigin() + translationVector; - geometry3d->Translate(translationVector); - MITK_TEST_CONDITION( mitk::Equal( geometry3d->GetOrigin(), tmpResult ), "Testing if origin was translated."); - - translationVector*=-1; //vice versa - geometry3d->Translate(translationVector); - - MITK_TEST_CONDITION( mitk::Equal( geometry3d->GetOrigin(), oldOrigin ), "Testing if the translation could be done vice versa." ); - - return EXIT_SUCCESS; + // Build up a new image Geometry + mitk::Geometry3D::Pointer geometry3d = mitk::Geometry3D::New(); + float bounds[ ] = {-10.0, 17.0, -12.0, 188.0, 13.0, 211.0}; + + MITK_TEST_OUTPUT( << "Initializing"); + geometry3d->Initialize(); + + MITK_TEST_OUTPUT(<< "Setting ImageGeometry to " << imageGeometry); + geometry3d->SetImageGeometry(imageGeometry); + + MITK_TEST_OUTPUT(<< "Setting bounds by SetFloatBounds(): " << bounds); + geometry3d->SetFloatBounds(bounds); + + MITK_TEST_OUTPUT( << "Testing AxisVectors"); + if(testGetAxisVectorVariants(geometry3d) == false) + return EXIT_FAILURE; + + if(testGetAxisVectorExtent(geometry3d) == false) + return EXIT_FAILURE; + + MITK_TEST_OUTPUT( << "Creating an AffineTransform3D transform"); + mitk::AffineTransform3D::MatrixType matrix; + matrix.SetIdentity(); + matrix(1,1) = 2; + mitk::AffineTransform3D::Pointer transform; + transform = mitk::AffineTransform3D::New(); + transform->SetMatrix(matrix); + + MITK_TEST_OUTPUT( << "Testing a SetIndexToWorldTransform"); + geometry3d->SetIndexToWorldTransform(transform); + + MITK_TEST_OUTPUT( << "Testing correctness of value returned by GetSpacing"); + const mitk::Vector3D& spacing1 = geometry3d->GetSpacing(); + mitk::Vector3D expectedSpacing; + expectedSpacing.Fill(1.0); + expectedSpacing[1] = 2; + if( mitk::Equal(spacing1, expectedSpacing) == false ) + { + MITK_TEST_OUTPUT( << " [FAILED]"); + return EXIT_FAILURE; + } + + MITK_TEST_OUTPUT( << "Testing a Compose(transform)"); + geometry3d->Compose(transform); + + MITK_TEST_OUTPUT( << "Testing correctness of value returned by GetSpacing"); + const mitk::Vector3D& spacing2 = geometry3d->GetSpacing(); + expectedSpacing[1] = 4; + if( mitk::Equal(spacing2, expectedSpacing) == false ) + { + MITK_TEST_OUTPUT( << " [FAILED]"); + return EXIT_FAILURE; + } + + MITK_TEST_OUTPUT( << "Testing correctness of SetSpacing"); + mitk::Vector3D newspacing; + mitk::FillVector3D(newspacing, 1.5, 2.5, 3.5); + geometry3d->SetSpacing(newspacing); + const mitk::Vector3D& spacing3 = geometry3d->GetSpacing(); + if( mitk::Equal(spacing3, newspacing) == false ) + { + MITK_TEST_OUTPUT( << " [FAILED]"); + return EXIT_FAILURE; + } + + // Seperate Test function for Index and World consistency + testIndexAndWorldConsistency(geometry3d); + testIndexAndWorldConsistencyForVectors(geometry3d); + testIndexAndWorldConsistencyForIndex(geometry3d); + + MITK_TEST_OUTPUT( << "Testing a rotation of the geometry"); + double angle = 35.0; + mitk::Vector3D rotationVector; mitk::FillVector3D( rotationVector, 1, 0, 0 ); + mitk::Point3D center = geometry3d->GetCenter(); + mitk::RotationOperation* op = new mitk::RotationOperation( mitk::OpROTATE, center, rotationVector, angle ); + geometry3d->ExecuteOperation(op); + + MITK_TEST_OUTPUT( << "Testing mitk::GetRotation() and success of rotation"); + mitk::Matrix3D rotation; + mitk::GetRotation(geometry3d, rotation); + mitk::Vector3D voxelStep=rotation*newspacing; + mitk::Vector3D voxelStepIndex; + geometry3d->WorldToIndex(voxelStep, voxelStepIndex); + mitk::Vector3D expectedVoxelStepIndex; + expectedVoxelStepIndex.Fill(1); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(voxelStepIndex,expectedVoxelStepIndex), ""); + delete op; + std::cout<<"[PASSED]"<GetImageGeometry() == imageGeometry, ""); + + //Test if the translate function moves the origin correctly. + mitk::Point3D oldOrigin = geometry3d->GetOrigin(); + + //use some random values for translation + mitk::Vector3D translationVector; + translationVector.SetElement(0, 17.5f); + translationVector.SetElement(1, -32.3f); + translationVector.SetElement(2, 4.0f); + //compute ground truth + mitk::Point3D tmpResult = geometry3d->GetOrigin() + translationVector; + geometry3d->Translate(translationVector); + MITK_TEST_CONDITION( mitk::Equal( geometry3d->GetOrigin(), tmpResult ), "Testing if origin was translated."); + + translationVector*=-1; //vice versa + geometry3d->Translate(translationVector); + + MITK_TEST_CONDITION( mitk::Equal( geometry3d->GetOrigin(), oldOrigin ), "Testing if the translation could be done vice versa." ); + + return EXIT_SUCCESS; } int testGeometryAfterCasting() { - // Epsilon. Allowed difference for rotationvalue - float eps = 0.0001; - - // Cast ITK and MITK images and see if geometry stays - typedef itk::Image Image2DType; - typedef itk::Image Image3DType; - - // Create 3D ITK Image from Scratch, cast to 3D MITK image, compare Geometries - Image3DType::Pointer image3DItk = Image3DType::New(); - Image3DType::RegionType myRegion; - Image3DType::SizeType mySize; - Image3DType::IndexType myIndex; - Image3DType::SpacingType mySpacing; - Image3DType::DirectionType myDirection, rotMatrixX, rotMatrixY, rotMatrixZ; - mySpacing[0] = 31; - mySpacing[1] = 0.1; - mySpacing[2] = 2.9; - myIndex[0] = -15; - myIndex[1] = 15; - myIndex[2] = 12; - mySize[0] = 10; - mySize[1] = 2; - mySize[2] = 555; - myRegion.SetSize( mySize); - myRegion.SetIndex( myIndex ); - image3DItk->SetSpacing(mySpacing); - image3DItk->SetRegions( myRegion); - image3DItk->Allocate(); - image3DItk->FillBuffer(0); - - myDirection.SetIdentity(); - rotMatrixX.SetIdentity(); - rotMatrixY.SetIdentity(); - rotMatrixZ.SetIdentity(); - - mitk::Image::Pointer mitkImage; - - // direction [row] [coloum] - MITK_TEST_OUTPUT( << "Casting a rotated 3D ITK Image to a MITK Image and check if Geometry is still same" ); - for (double rotX=0; rotX < (itk::Math::pi*2); rotX+=0.4 ) - { - // Set Rotation X - rotMatrixX[1][1] = cos( rotX ); - rotMatrixX[1][2] = -sin( rotX ); - rotMatrixX[2][1] = sin( rotX ); - rotMatrixX[2][2] = cos( rotX ); - - for (double rotY=0; rotY < (itk::Math::pi*2); rotY+=0.33 ) + // Epsilon. Allowed difference for rotationvalue + float eps = 0.0001; + + // Cast ITK and MITK images and see if geometry stays + typedef itk::Image Image2DType; + typedef itk::Image Image3DType; + + // Create 3D ITK Image from Scratch, cast to 3D MITK image, compare Geometries + Image3DType::Pointer image3DItk = Image3DType::New(); + Image3DType::RegionType myRegion; + Image3DType::SizeType mySize; + Image3DType::IndexType myIndex; + Image3DType::SpacingType mySpacing; + Image3DType::DirectionType myDirection, rotMatrixX, rotMatrixY, rotMatrixZ; + mySpacing[0] = 31; + mySpacing[1] = 0.1; + mySpacing[2] = 2.9; + myIndex[0] = -15; + myIndex[1] = 15; + myIndex[2] = 12; + mySize[0] = 10; + mySize[1] = 2; + mySize[2] = 555; + myRegion.SetSize( mySize); + myRegion.SetIndex( myIndex ); + image3DItk->SetSpacing(mySpacing); + image3DItk->SetRegions( myRegion); + image3DItk->Allocate(); + image3DItk->FillBuffer(0); + + myDirection.SetIdentity(); + rotMatrixX.SetIdentity(); + rotMatrixY.SetIdentity(); + rotMatrixZ.SetIdentity(); + + mitk::Image::Pointer mitkImage; + + // direction [row] [coloum] + MITK_TEST_OUTPUT( << "Casting a rotated 3D ITK Image to a MITK Image and check if Geometry is still same" ); + for (double rotX=0; rotX < (itk::Math::pi*2); rotX+=0.4 ) + { + // Set Rotation X + rotMatrixX[1][1] = cos( rotX ); + rotMatrixX[1][2] = -sin( rotX ); + rotMatrixX[2][1] = sin( rotX ); + rotMatrixX[2][2] = cos( rotX ); + + for (double rotY=0; rotY < (itk::Math::pi*2); rotY+=0.33 ) + { + // Set Rotation Y + rotMatrixY[0][0] = cos( rotY ); + rotMatrixY[0][2] = sin( rotY ); + rotMatrixY[2][0] = -sin( rotY ); + rotMatrixY[2][2] = cos( rotY ); + + for (double rotZ=0; rotZ < (itk::Math::pi*2); rotZ+=0.5 ) { - // Set Rotation Y - rotMatrixY[0][0] = cos( rotY ); - rotMatrixY[0][2] = sin( rotY ); - rotMatrixY[2][0] = -sin( rotY ); - rotMatrixY[2][2] = cos( rotY ); - - for (double rotZ=0; rotZ < (itk::Math::pi*2); rotZ+=0.5 ) - { - // Set Rotation Z - rotMatrixZ[0][0] = cos( rotZ ); - rotMatrixZ[0][1] = -sin( rotZ ); - rotMatrixZ[1][0] = sin( rotZ ); - rotMatrixZ[1][1] = cos( rotZ ); - - // Multiply matrizes - myDirection = myDirection * rotMatrixX * rotMatrixY * rotMatrixZ; - image3DItk->SetDirection(myDirection); - mitk::CastToMitkImage(image3DItk, mitkImage); - const mitk::AffineTransform3D::MatrixType& matrix = mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix(); - - for (int row=0; row<3; row++) + // Set Rotation Z + rotMatrixZ[0][0] = cos( rotZ ); + rotMatrixZ[0][1] = -sin( rotZ ); + rotMatrixZ[1][0] = sin( rotZ ); + rotMatrixZ[1][1] = cos( rotZ ); + + // Multiply matrizes + myDirection = myDirection * rotMatrixX * rotMatrixY * rotMatrixZ; + image3DItk->SetDirection(myDirection); + mitk::CastToMitkImage(image3DItk, mitkImage); + const mitk::AffineTransform3D::MatrixType& matrix = mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix(); + + for (int row=0; row<3; row++) + { + for (int col=0; col<3; col++) + { + double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col]; + double itkValue = myDirection[row][col]; + double diff = mitkValue - itkValue; + // if you decrease this value, you can see that there might be QUITE high inaccuracy!!! + if (diff > eps) // need to check, how exact it SHOULD be .. since it is NOT EXACT! { - for (int col=0; col<3; col++) - { - double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col]; - double itkValue = myDirection[row][col]; - double diff = mitkValue - itkValue; - // if you decrease this value, you can see that there might be QUITE high inaccuracy!!! - if (diff > eps) // need to check, how exact it SHOULD be .. since it is NOT EXACT! - { - std::cout << "Had a difference of : " << diff; - std::cout << "Error: Casting altered Geometry!"; - std::cout << "ITK Matrix:\n" << myDirection; - std::cout << "Mitk Matrix (With Spacing):\n" << matrix; - std::cout << "Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing(); - MITK_TEST_CONDITION_REQUIRED(false == true, ""); - return false; - } - } + std::cout << "Had a difference of : " << diff; + std::cout << "Error: Casting altered Geometry!"; + std::cout << "ITK Matrix:\n" << myDirection; + std::cout << "Mitk Matrix (With Spacing):\n" << matrix; + std::cout << "Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing(); + MITK_TEST_CONDITION_REQUIRED(false == true, ""); + return false; } - } + } + } } - } - - // Create 2D ITK Image from Scratch, cast to 2D MITK image, compare Geometries - Image2DType::Pointer image2DItk = Image2DType::New(); - Image2DType::RegionType myRegion2D; - Image2DType::SizeType mySize2D; - Image2DType::IndexType myIndex2D; - Image2DType::SpacingType mySpacing2D; - Image2DType::DirectionType myDirection2D, rotMatrix; - mySpacing2D[0] = 31; - mySpacing2D[1] = 0.1; - myIndex2D[0] = -15; - myIndex2D[1] = 15; - mySize2D[0] = 10; - mySize2D[1] = 2; - myRegion2D.SetSize( mySize2D); - myRegion2D.SetIndex( myIndex2D ); - image2DItk->SetSpacing(mySpacing2D); - image2DItk->SetRegions( myRegion2D); - image2DItk->Allocate(); - image2DItk->FillBuffer(0); - - myDirection2D.SetIdentity(); - rotMatrix.SetIdentity(); - - // direction [row] [coloum] - MITK_TEST_OUTPUT( << "Casting a rotated 2D ITK Image to a MITK Image and check if Geometry is still same" ); - for (double rotTheta=0; rotTheta < (itk::Math::pi*2); rotTheta+=0.1 ) - { - // Set Rotation - rotMatrix[0][0] = cos(rotTheta); - rotMatrix[0][1] = -sin(rotTheta); - rotMatrix[1][0] = sin(rotTheta); - rotMatrix[1][1] = cos(rotTheta); - - // Multiply matrizes - myDirection2D = myDirection2D * rotMatrix; - image2DItk->SetDirection(myDirection2D); - mitk::CastToMitkImage(image2DItk, mitkImage); - const mitk::AffineTransform3D::MatrixType& matrix = mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix(); - - // Compare MITK and ITK matrix - for (int row=0; row<3; row++) + } + } + + // Create 2D ITK Image from Scratch, cast to 2D MITK image, compare Geometries + Image2DType::Pointer image2DItk = Image2DType::New(); + Image2DType::RegionType myRegion2D; + Image2DType::SizeType mySize2D; + Image2DType::IndexType myIndex2D; + Image2DType::SpacingType mySpacing2D; + Image2DType::DirectionType myDirection2D, rotMatrix; + mySpacing2D[0] = 31; + mySpacing2D[1] = 0.1; + myIndex2D[0] = -15; + myIndex2D[1] = 15; + mySize2D[0] = 10; + mySize2D[1] = 2; + myRegion2D.SetSize( mySize2D); + myRegion2D.SetIndex( myIndex2D ); + image2DItk->SetSpacing(mySpacing2D); + image2DItk->SetRegions( myRegion2D); + image2DItk->Allocate(); + image2DItk->FillBuffer(0); + + myDirection2D.SetIdentity(); + rotMatrix.SetIdentity(); + + // direction [row] [coloum] + MITK_TEST_OUTPUT( << "Casting a rotated 2D ITK Image to a MITK Image and check if Geometry is still same" ); + for (double rotTheta=0; rotTheta < (itk::Math::pi*2); rotTheta+=0.1 ) + { + // Set Rotation + rotMatrix[0][0] = cos(rotTheta); + rotMatrix[0][1] = -sin(rotTheta); + rotMatrix[1][0] = sin(rotTheta); + rotMatrix[1][1] = cos(rotTheta); + + // Multiply matrizes + myDirection2D = myDirection2D * rotMatrix; + image2DItk->SetDirection(myDirection2D); + mitk::CastToMitkImage(image2DItk, mitkImage); + const mitk::AffineTransform3D::MatrixType& matrix = mitkImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix(); + + // Compare MITK and ITK matrix + for (int row=0; row<3; row++) + { + for (int col=0; col<3; col++) { - for (int col=0; col<3; col++) - { - double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col]; - if ((row == 2) && (col == row)) - { - if (mitkValue != 1) - { - MITK_TEST_OUTPUT(<< "After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 MUST be 0 and value for 2|2 must be 1"); - return false; - } - } - else if ((row == 2) || (col == 2)) - { - if (mitkValue != 0) - { - MITK_TEST_OUTPUT(<< "After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 MUST be 0 and value for 2|2 must be 1"); - return false; - } - } - else - { - double itkValue = myDirection2D[row][col]; - double diff = mitkValue - itkValue; - // if you decrease this value, you can see that there might be QUITE high inaccuracy!!! - if (diff > eps) // need to check, how exact it SHOULD be .. since it is NOT EXACT! - { - std::cout << "Had a difference of : " << diff; - std::cout << "Error: Casting altered Geometry!"; - std::cout << "ITK Matrix:\n" << myDirection2D; - std::cout << "Mitk Matrix (With Spacing):\n" << matrix; - std::cout << "Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing(); - MITK_TEST_CONDITION_REQUIRED(false == true, ""); - return false; - } - } - } + double mitkValue = matrix[row][col] / mitkImage->GetGeometry()->GetSpacing()[col]; + if ((row == 2) && (col == row)) + { + if (mitkValue != 1) + { + MITK_TEST_OUTPUT(<< "After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 MUST be 0 and value for 2|2 must be 1"); + return false; + } + } + else if ((row == 2) || (col == 2)) + { + if (mitkValue != 0) + { + MITK_TEST_OUTPUT(<< "After casting a 2D ITK to 3D MITK images, MITK matrix values for 0|2, 1|2, 2|0, 2|1 MUST be 0 and value for 2|2 must be 1"); + return false; + } + } + else + { + double itkValue = myDirection2D[row][col]; + double diff = mitkValue - itkValue; + // if you decrease this value, you can see that there might be QUITE high inaccuracy!!! + if (diff > eps) // need to check, how exact it SHOULD be .. since it is NOT EXACT! + { + std::cout << "Had a difference of : " << diff; + std::cout << "Error: Casting altered Geometry!"; + std::cout << "ITK Matrix:\n" << myDirection2D; + std::cout << "Mitk Matrix (With Spacing):\n" << matrix; + std::cout << "Mitk Spacing: " << mitkImage->GetGeometry()->GetSpacing(); + MITK_TEST_CONDITION_REQUIRED(false == true, ""); + return false; + } + } } - } + } + } - // THIS WAS TESTED: - // 2D ITK -> 2D MITK, - // 3D ITK -> 3D MITK, + // THIS WAS TESTED: + // 2D ITK -> 2D MITK, + // 3D ITK -> 3D MITK, - // Still need to test: 2D MITK Image with ADDITIONAL INFORMATION IN MATRIX -> 2D ITK - // 1. Possibility: 3x3 MITK matrix can be converted without loss into 2x2 ITK matrix - // 2. Possibility: 3x3 MITK matrix can only be converted with loss into 2x2 ITK matrix - // .. before implementing this, we wait for further development in geometry classes (e.g. Geoemtry3D::SetRotation(..)) + // Still need to test: 2D MITK Image with ADDITIONAL INFORMATION IN MATRIX -> 2D ITK + // 1. Possibility: 3x3 MITK matrix can be converted without loss into 2x2 ITK matrix + // 2. Possibility: 3x3 MITK matrix can only be converted with loss into 2x2 ITK matrix + // .. before implementing this, we wait for further development in geometry classes (e.g. Geoemtry3D::SetRotation(..)) - return EXIT_SUCCESS; + return EXIT_SUCCESS; } int mitkGeometry3DTest(int /*argc*/, char* /*argv*/[]) { - MITK_TEST_BEGIN(mitkGeometry3DTest); + MITK_TEST_BEGIN(mitkGeometry3DTest); - int result; + int result; - MITK_TEST_CONDITION_REQUIRED( (result = testItkImageIsCenterBased()) == EXIT_SUCCESS, ""); + MITK_TEST_CONDITION_REQUIRED( (result = testItkImageIsCenterBased()) == EXIT_SUCCESS, ""); - MITK_TEST_OUTPUT(<< "Running main part of test with ImageGeometry = false"); - MITK_TEST_CONDITION_REQUIRED( (result = testGeometry3D(false)) == EXIT_SUCCESS, ""); + MITK_TEST_OUTPUT(<< "Running main part of test with ImageGeometry = false"); + MITK_TEST_CONDITION_REQUIRED( (result = testGeometry3D(false)) == EXIT_SUCCESS, ""); - MITK_TEST_OUTPUT(<< "Running main part of test with ImageGeometry = true"); - MITK_TEST_CONDITION_REQUIRED( (result = testGeometry3D(true)) == EXIT_SUCCESS, ""); + MITK_TEST_OUTPUT(<< "Running main part of test with ImageGeometry = true"); + MITK_TEST_CONDITION_REQUIRED( (result = testGeometry3D(true)) == EXIT_SUCCESS, ""); - MITK_TEST_OUTPUT(<< "Running test to see if Casting MITK to ITK and the other way around destroys geometry"); - MITK_TEST_CONDITION_REQUIRED( (result = testGeometryAfterCasting()) == EXIT_SUCCESS, ""); + MITK_TEST_OUTPUT(<< "Running test to see if Casting MITK to ITK and the other way around destroys geometry"); + MITK_TEST_CONDITION_REQUIRED( (result = testGeometryAfterCasting()) == EXIT_SUCCESS, ""); - MITK_TEST_END(); + MITK_TEST_END(); - return EXIT_SUCCESS; -} \ No newline at end of file + return EXIT_SUCCESS; +} diff --git a/Core/Code/Testing/mitkIOUtilTest.cpp b/Core/Code/Testing/mitkIOUtilTest.cpp index f273d03d7e..bbe74167ad 100644 --- a/Core/Code/Testing/mitkIOUtilTest.cpp +++ b/Core/Code/Testing/mitkIOUtilTest.cpp @@ -1,204 +1,202 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" #include #include #include #include #include class mitkIOUtilTestSuite : public mitk::TestFixture { - CPPUNIT_TEST_SUITE(mitkIOUtilTestSuite); MITK_TEST(TestTempMethods); MITK_TEST(TestLoadAndSaveImage); MITK_TEST(TestLoadAndSavePointSet); MITK_TEST(TestLoadAndSaveSurface); MITK_TEST(TestTempMethodsForUniqueFilenames); CPPUNIT_TEST_SUITE_END(); private: std::string m_ImagePath; std::string m_SurfacePath; std::string m_PointSetPath; public: void setUp() { m_ImagePath = GetTestDataFilePath("Pic3D.nrrd"); m_SurfacePath = GetTestDataFilePath("binary.stl"); m_PointSetPath = GetTestDataFilePath("pointSet.mps"); } void TestTempMethods() { std::string tmpPath = mitk::IOUtil::GetTempPath(); CPPUNIT_ASSERT(!tmpPath.empty()); std::ofstream tmpFile; std::string tmpFilePath = mitk::IOUtil::CreateTemporaryFile(tmpFile); CPPUNIT_ASSERT(tmpFile && tmpFile.is_open()); CPPUNIT_ASSERT(tmpFilePath.size() > tmpPath.size()); CPPUNIT_ASSERT(tmpFilePath.substr(0, tmpPath.size()) == tmpPath); tmpFile.close(); CPPUNIT_ASSERT(std::remove(tmpFilePath.c_str()) == 0); std::string programPath = mitk::IOUtil::GetProgramPath(); CPPUNIT_ASSERT(!programPath.empty()); std::ofstream tmpFile2; std::string tmpFilePath2 = mitk::IOUtil::CreateTemporaryFile(tmpFile2, "my-XXXXXX", programPath); CPPUNIT_ASSERT(tmpFile2 && tmpFile2.is_open()); CPPUNIT_ASSERT(tmpFilePath2.size() > programPath.size()); CPPUNIT_ASSERT(tmpFilePath2.substr(0, programPath.size()) == programPath); tmpFile2.close(); CPPUNIT_ASSERT(std::remove(tmpFilePath2.c_str()) == 0); std::ofstream tmpFile3; std::string tmpFilePath3 = mitk::IOUtil::CreateTemporaryFile(tmpFile3, std::ios_base::binary, - "my-XXXXXX.TXT", programPath); + "my-XXXXXX.TXT", programPath); CPPUNIT_ASSERT(tmpFile3 && tmpFile3.is_open()); CPPUNIT_ASSERT(tmpFilePath3.size() > programPath.size()); CPPUNIT_ASSERT(tmpFilePath3.substr(0, programPath.size()) == programPath); CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 13, 3) == "my-"); CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 4) == ".TXT"); tmpFile3.close(); //CPPUNIT_ASSERT(std::remove(tmpFilePath3.c_str()) == 0) std::string tmpFilePath4 = mitk::IOUtil::CreateTemporaryFile(); std::ofstream file; file.open(tmpFilePath4.c_str()); CPPUNIT_ASSERT_MESSAGE("Testing if file exists after CreateTemporaryFile()",file.is_open()); CPPUNIT_ASSERT_THROW(mitk::IOUtil::CreateTemporaryFile(tmpFile2, "XX"), mitk::Exception); std::string tmpDir = mitk::IOUtil::CreateTemporaryDirectory(); CPPUNIT_ASSERT(tmpDir.size() > tmpPath.size()); CPPUNIT_ASSERT(tmpDir.substr(0, tmpPath.size()) == tmpPath); CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir.c_str())); std::string tmpDir2 = mitk::IOUtil::CreateTemporaryDirectory("my-XXXXXX", programPath); CPPUNIT_ASSERT(tmpDir2.size() > programPath.size()); CPPUNIT_ASSERT(tmpDir2.substr(0, programPath.size()) == programPath); CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir2.c_str())); } void TestTempMethodsForUniqueFilenames() { int numberOfFiles = 100; //create 100 empty files std::vector v100filenames; for(int i=0; i(4,4,4,1); std::string imagePath3 = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.nrrd"); tmpStream.close(); mitk::IOUtil::SaveImage(relativImage, imagePath3); CPPUNIT_ASSERT_NO_THROW(mitk::IOUtil::LoadImage(imagePath3)); std::remove(imagePath3.c_str()); } void TestLoadAndSavePointSet() { mitk::PointSet::Pointer pointset = mitk::IOUtil::LoadPointSet(m_PointSetPath); CPPUNIT_ASSERT( pointset.IsNotNull()); std::ofstream tmpStream; std::string pointSetPath = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.mps"); tmpStream.close(); std::string pointSetPathWithDefaultExtension = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.mps"); tmpStream.close(); std::string pointSetPathWithoutDefaultExtension = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.xXx"); tmpStream.close(); // the cases where no exception should be thrown CPPUNIT_ASSERT(mitk::IOUtil::SavePointSet(pointset, pointSetPathWithDefaultExtension)); // test if defaultextension is inserted if no extension is present CPPUNIT_ASSERT(mitk::IOUtil::SavePointSet(pointset, pointSetPathWithoutDefaultExtension.c_str())); //delete the files after the test is done std::remove(pointSetPath.c_str()); std::remove(pointSetPathWithDefaultExtension.c_str()); std::remove(pointSetPathWithoutDefaultExtension.c_str()); } void TestLoadAndSaveSurface() { mitk::Surface::Pointer surface = mitk::IOUtil::LoadSurface(m_SurfacePath); CPPUNIT_ASSERT( surface.IsNotNull()); std::ofstream tmpStream; std::string surfacePath = mitk::IOUtil::CreateTemporaryFile(tmpStream, "diffsurface-XXXXXX.stl"); // the cases where no exception should be thrown CPPUNIT_ASSERT(mitk::IOUtil::SaveSurface(surface, surfacePath)); // test if exception is thrown as expected on unknown extsension CPPUNIT_ASSERT_THROW(mitk::IOUtil::SaveSurface(surface,"testSurface.xXx"), mitk::Exception); //delete the files after the test is done std::remove(surfacePath.c_str()); } - }; MITK_TEST_SUITE_REGISTRATION(mitkIOUtil) diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index 142cbdaf41..3dd56530d6 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,409 +1,410 @@ set(H_FILES Algorithms/itkImportMitkImageContainer.h Algorithms/itkImportMitkImageContainer.txx Algorithms/itkLocalVariationImageFilter.h Algorithms/itkLocalVariationImageFilter.txx Algorithms/itkMITKScalarImageToHistogramGenerator.h Algorithms/itkMITKScalarImageToHistogramGenerator.txx Algorithms/itkTotalVariationDenoisingImageFilter.h Algorithms/itkTotalVariationDenoisingImageFilter.txx Algorithms/itkTotalVariationSingleIterationImageFilter.h Algorithms/itkTotalVariationSingleIterationImageFilter.txx Algorithms/mitkBilateralFilter.h Algorithms/mitkBilateralFilter.cpp Algorithms/mitkInstantiateAccessFunctions.h Algorithms/mitkPixelTypeList.h Algorithms/mitkPPArithmeticDec.h Algorithms/mitkPPArgCount.h Algorithms/mitkPPCat.h Algorithms/mitkPPConfig.h Algorithms/mitkPPControlExprIIf.h Algorithms/mitkPPControlIf.h Algorithms/mitkPPControlIIf.h Algorithms/mitkPPDebugError.h Algorithms/mitkPPDetailAutoRec.h Algorithms/mitkPPDetailDMCAutoRec.h Algorithms/mitkPPExpand.h Algorithms/mitkPPFacilitiesEmpty.h Algorithms/mitkPPFacilitiesExpand.h Algorithms/mitkPPLogicalBool.h Algorithms/mitkPPRepetitionDetailDMCFor.h Algorithms/mitkPPRepetitionDetailEDGFor.h Algorithms/mitkPPRepetitionDetailFor.h Algorithms/mitkPPRepetitionDetailMSVCFor.h Algorithms/mitkPPRepetitionFor.h Algorithms/mitkPPSeqElem.h Algorithms/mitkPPSeqForEach.h Algorithms/mitkPPSeqForEachProduct.h Algorithms/mitkPPSeq.h Algorithms/mitkPPSeqEnum.h Algorithms/mitkPPSeqSize.h Algorithms/mitkPPSeqToTuple.h Algorithms/mitkPPStringize.h Algorithms/mitkPPTupleEat.h Algorithms/mitkPPTupleElem.h Algorithms/mitkPPTupleRem.h Algorithms/mitkClippedSurfaceBoundsCalculator.h Algorithms/mitkExtractSliceFilter.h Algorithms/mitkConvert2Dto3DImageFilter.h Algorithms/mitkPlaneClipping.h Common/mitkCommon.h Common/mitkExceptionMacro.h DataManagement/mitkProportionalTimeGeometry.h DataManagement/mitkTimeGeometry.h DataManagement/mitkImageAccessByItk.h DataManagement/mitkImageCast.h DataManagement/mitkImagePixelAccessor.h DataManagement/mitkImagePixelReadAccessor.h DataManagement/mitkImagePixelWriteAccessor.h DataManagement/mitkImageReadAccessor.h DataManagement/mitkImageWriteAccessor.h DataManagement/mitkITKImageImport.h DataManagement/mitkITKImageImport.txx DataManagement/mitkImageToItk.h DataManagement/mitkImageToItk.txx DataManagement/mitkTimeSlicedGeometry.h # Deprecated, empty for compatibilty reasons. DataManagement/mitkPropertyListReplacedObserver.cpp Interactions/mitkEventMapperAddOn.h Interfaces/mitkIDataNodeReader.h Rendering/mitkLocalStorageHandler.h IO/mitkPixelTypeTraits.h ) set(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkCompareImageDataFilter.cpp Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkGeometry2DDataToSurfaceFilter.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkImageToSurfaceFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkConvert2Dto3DImageFilter.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkCoreActivator.cpp Controllers/mitkFocusManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSlicesCoordinator.cpp Controllers/mitkSlicesRotator.cpp Controllers/mitkSlicesSwiveller.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkInteractorCameraController.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkProportionalTimeGeometry.cpp DataManagement/mitkTimeGeometry.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkBaseData.cpp + DataManagement/mitkBaseGeometry.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkDataStorage.cpp # DataManagement/mitkDataTree.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataNodeFactory.cpp # DataManagement/mitkDataTreeStorage.cpp DataManagement/mitkDisplayGeometry.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkGeometry2D.cpp DataManagement/mitkGeometry2DData.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageVtkAccessor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkLandmarkBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTables.cpp # specializations of GenericLookupTable DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModeOperation.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFirstLevel.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateSource.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkPropertyObserver.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkApplyTransformMatrixOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStateTransitionOperation.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkVector.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkVtkVolumeRenderingProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkRenderingModeProperty.cpp DataManagement/mitkShaderProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkMaterial.cpp DataManagement/mitkPointSetShapeProperty.cpp DataManagement/mitkFloatPropertyExtension.cpp DataManagement/mitkIntPropertyExtension.cpp DataManagement/mitkPropertyExtension.cpp DataManagement/mitkPropertyFilter.cpp DataManagement/mitkPropertyAliases.cpp DataManagement/mitkPropertyDescriptions.cpp DataManagement/mitkPropertyExtensions.cpp DataManagement/mitkPropertyFilters.cpp Interactions/mitkAction.cpp Interactions/mitkAffineInteractor.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkCoordinateSupplier.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkDisplayPositionEvent.cpp # Interactions/mitkDisplayVectorInteractorLevelWindow.cpp # legacy, prob even now unneeded # Interactions/mitkDisplayVectorInteractorScroll.cpp Interactions/mitkEvent.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventDescription.cpp Interactions/mitkEventFactory.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkEventMapper.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkGlobalInteraction.cpp Interactions/mitkInteractor.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkInteractionEvent.cpp Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkMouseDoubleClickEvent.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMovePointSetInteractor.cpp Interactions/mitkMoveBaseDataInteractor.cpp Interactions/mitkNodeDepententPointSetInteractor.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkPointSetInteractor.cpp Interactions/mitkPositionEvent.cpp Interactions/mitkPositionTracker.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineCondition.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkState.cpp Interactions/mitkStateMachineContainer.cpp Interactions/mitkStateEvent.cpp Interactions/mitkStateMachine.cpp Interactions/mitkStateMachineFactory.cpp Interactions/mitkTransition.cpp Interactions/mitkWheelEvent.cpp Interactions/mitkKeyEvent.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkCrosshairPositionEvent.cpp Interfaces/mitkInteractionEventObserver.cpp Interfaces/mitkIShaderRepository.cpp Interfaces/mitkIPropertyAliases.cpp Interfaces/mitkIPropertyDescriptions.cpp Interfaces/mitkIPropertyExtensions.cpp Interfaces/mitkIPropertyFilters.cpp Interfaces/mitkIPersistenceService.cpp IO/mitkBaseDataIOFactory.cpp IO/mitkCoreDataNodeReader.cpp IO/mitkDicomSeriesReader.cpp IO/mitkDicomSR_LoadDICOMScalar.cpp IO/mitkDicomSR_LoadDICOMScalar4D.cpp IO/mitkDicomSR_LoadDICOMRGBPixel.cpp IO/mitkDicomSR_LoadDICOMRGBPixel4D.cpp IO/mitkDicomSR_ImageBlockDescriptor.cpp IO/mitkDicomSR_GantryTiltInformation.cpp IO/mitkDicomSR_SliceGroupingResult.cpp IO/mitkFileReader.cpp IO/mitkFileSeriesReader.cpp IO/mitkFileWriter.cpp # IO/mitkIpPicGet.c IO/mitkImageGenerator.cpp IO/mitkImageWriter.cpp IO/mitkImageWriterFactory.cpp IO/mitkItkImageFileIOFactory.cpp IO/mitkItkImageFileReader.cpp IO/mitkItkLoggingAdapter.cpp IO/mitkItkPictureWrite.cpp IO/mitkIOUtil.cpp IO/mitkLookupTableProperty.cpp IO/mitkOperation.cpp # IO/mitkPicFileIOFactory.cpp # IO/mitkPicFileReader.cpp # IO/mitkPicFileWriter.cpp # IO/mitkPicHelper.cpp # IO/mitkPicVolumeTimeSeriesIOFactory.cpp # IO/mitkPicVolumeTimeSeriesReader.cpp IO/mitkPixelType.cpp IO/mitkPointSetIOFactory.cpp IO/mitkPointSetReader.cpp IO/mitkPointSetWriter.cpp IO/mitkPointSetWriterFactory.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSTLFileIOFactory.cpp IO/mitkSTLFileReader.cpp IO/mitkSurfaceVtkWriter.cpp IO/mitkSurfaceVtkWriterFactory.cpp IO/mitkVtkLoggingAdapter.cpp IO/mitkVtiFileIOFactory.cpp IO/mitkVtiFileReader.cpp IO/mitkVtkImageIOFactory.cpp IO/mitkVtkImageReader.cpp IO/mitkVtkSurfaceIOFactory.cpp IO/mitkVtkSurfaceReader.cpp IO/vtkPointSetXMLParser.cpp IO/mitkLog.cpp Rendering/mitkBaseRenderer.cpp Rendering/mitkVtkMapper.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkGeometry2DDataMapper2D.cpp Rendering/mitkGeometry2DDataVtkMapper3D.cpp Rendering/mitkGLMapper.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkManufacturerLogo.cpp Rendering/mitkMapper.cpp Rendering/mitkPointSetGLMapper2D.cpp Rendering/mitkPointSetVtkMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkPolyDataGLMapper2D.cpp Rendering/mitkSurfaceGLMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVolumeDataVtkMapper3D.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowBase.cpp Rendering/mitkShaderRepository.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkMitkLevelWindowFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp Rendering/mitkOverlay.cpp Rendering/mitkVtkOverlay.cpp Rendering/mitkVtkOverlay2D.cpp Rendering/mitkVtkOverlay3D.cpp Rendering/mitkOverlayManager.cpp Rendering/mitkAbstractOverlayLayouter.cpp Rendering/mitkTextOverlay2D.cpp Rendering/mitkTextOverlay3D.cpp Rendering/mitkLabelOverlay3D.cpp Rendering/mitkOverlay2DLayouter.cpp Rendering/mitkScaleLegendOverlay Common/mitkException.cpp Common/mitkCommon.h Common/mitkCoreObjectFactoryBase.cpp Common/mitkCoreObjectFactory.cpp Common/mitkCoreServices.cpp ) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfig.xml Interactions/DisplayConfigPACS.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigMITK.xml Interactions/PointSet.xml Interactions/Legacy/StateMachine.xml Interactions/Legacy/DisplayConfigMITKTools.xml Interactions/PointSetConfig.xml Shaders/mitkShaderLighting.xml mitkLevelWindowPresets.xml )