diff --git a/Core/Code/DataManagement/mitkBaseGeometry.cpp b/Core/Code/DataManagement/mitkBaseGeometry.cpp index 1fa89f46d2..746f6d0170 100644 --- a/Core/Code/DataManagement/mitkBaseGeometry.cpp +++ b/Core/Code/DataManagement/mitkBaseGeometry.cpp @@ -1,194 +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_RotationQuaternion( other.m_RotationQuaternion ), m_Origin(other.m_Origin) + 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 index bf97cce7d8..81471ed15b 100644 --- a/Core/Code/DataManagement/mitkBaseGeometry.h +++ b/Core/Code/DataManagement/mitkBaseGeometry.h @@ -1,586 +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 origin as VnlVector - //## - //## \sa GetOrigin - // xx This was not vitrual! - virtual VnlVector GetOriginVnl() const = 0 ; //ToDo - //##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) = 0 ; //ToDo - // ********************************** other functions ********************************** - //##Documentation - //## @brief Is this Geometry3D in a state that is valid? - virtual bool IsValid() const = 0 ; //ToDo - //##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); - // ********************************** Functions Initialize ********************************** + //##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]); - //##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 = 0 ; //ToDo - - virtual void PrintSelf(std::ostream& os, itk::Indent indent) const = 0 ; //ToDo: This was protected! - // ********************************** 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); - //##Documentation - //## @brief Convenience method for setting the ITK transform - //## (m_IndexToWorldTransform) via an vtkMatrix4x4 - //## \sa SetIndexToWorldTransform - virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4* vtkmatrix) = 0 ; //ToDo - /** Set/Get the IndexToWorldTransform */ itkGetConstObjectMacro(IndexToWorldTransform, AffineTransform3D); itkGetObjectMacro(IndexToWorldTransform, AffineTransform3D); - //##Documentation - //## @brief Get the m_IndexToWorldTransform as a vtkLinearTransform - // xx This was not vitrual! - virtual vtkLinearTransform* GetVtkTransform() const = 0 ; //ToDo - - //##Documentation - //## @brief Set the transform to identity and origin to 0 - //## - virtual void SetIdentity() = 0 ; //ToDo - - //##Documentation - //## @brief Get the parametric transform - //## - //## See AbstractTransformGeometry for an example usage of this. - virtual const Transform3D* GetParametricTransform() const = 0 ; //ToDo - // ********************************** Transformations ********************************** //##Documentation //## @brief Copy the ITK transform //## (m_IndexToWorldTransform) to the VTK transform //## \sa SetIndexToWorldTransform virtual void TransferItkToVtkTransform(); - //##Documentation - //## @brief Copy the VTK transform - //## to the ITK transform (m_IndexToWorldTransform) - //## \sa SetIndexToWorldTransform - // xx This was not vitrual! - virtual void TransferVtkToItkTransform() = 0 ; //ToDo - - //##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 BaseGeometry::TransformType * other, bool pre = 0 ) = 0 ; //ToDo - - //##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 ) = 0 ; //ToDo - - //##Documentation - //## @brief Translate the origin by a vector - //## - virtual void Translate(const Vector3D& vector) = 0 ; //ToDo - - //##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 - // xx This was not vitrual! - virtual void WorldToIndex(const mitk::Point3D& pt_mm, mitk::Point3D& pt_units) const = 0 ; //ToDo - - //##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 - // xx This was not vitrual! - virtual void IndexToWorld(const mitk::Point3D& pt_units, mitk::Point3D& pt_mm) const = 0 ; //ToDo - - //##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 = 0 ; //ToDo - - //##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 - // xx This was not vitrual! - virtual void WorldToIndex(const mitk::Vector3D& vec_mm, mitk::Vector3D& vec_units) const = 0 ; //ToDo - - //##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 - // xx This was not vitrual! - virtual void IndexToWorld(const mitk::Vector3D& vec_units, mitk::Vector3D& vec_mm) const = 0 ; //ToDo - - //##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 = 0 ; //ToDo - - //##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 = 0 ; //ToDo - - //##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 = 0 ; //ToDo - - //Without redundant parameter Point3D - virtual void BackTransform(const mitk::Vector3D& in, mitk::Vector3D& out) const = 0 ; //This was protected! //ToDo - virtual void BackTransform(const mitk::Point3D& in, mitk::Point3D& out) const = 0 ;//This was protected! //ToDo - - /** 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() = 0 ; //This was protected! Empty Function! //ToDo - - //##Documentation - //##@brief executes affine operations (translate, rotate, scale) - virtual void ExecuteOperation(Operation* operation) = 0 ; //ToDo - - //xxxx static const std::string GetTransformAsString( TransformType* transformType );//This was protected! //ToDo - // ********************************** 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 - - //##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) = 0; //This was protected! //ToDo - - //##Documentation - //## @brief Calculates a bounding-box around the geometry relative - //## to a coordinate system defined by a transform - //## - // xx This was not vitrual! - virtual mitk::BoundingBox::Pointer CalculateBoundingBoxRelativeToTransform(const mitk::AffineTransform3D* transform) const = 0 ; //ToDo + //virtual const BoundingBox::BoundsArrayType& GetParametricBounds() const = 0 ; //ToDo /** Get the bounding box */ itkGetConstObjectMacro(BoundingBox, BoundingBoxType); - //##Documentation - //## @brief Get a VnlVector along bounding-box in the specified - //## @a direction, length is spacing - //## - //## \sa GetAxisVector - // xx This was not vitrual! - virtual VnlVector GetMatrixColumn(unsigned int direction) const = 0 ; //ToDo - //##Documentation //## @brief Get the time bounds (in ms) itkGetConstReferenceMacro(TimeBounds, TimeBounds); - const BoundsArrayType GetBounds() const - { - assert(m_BoundingBox.IsNotNull()); - return m_BoundingBox->GetBounds(); - } + 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 - { - assert(m_BoundingBox.IsNotNull()); - return m_BoundingBox->GetBounds(); - } + 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 + //virtual void SetTimeBounds(const TimeBounds& timebounds) = 0 ; //ToDo // ********************************** Geometry ********************************** - //##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() = 0 ; //ToDo - - //##Documentation - //## @brief Get the position of the corner number \a id (in world coordinates) - //## - //## See SetImageGeometry for how a corner is defined on images. - // xx This was not vitrual! - virtual Point3D GetCornerPoint(int id) const = 0 ; //ToDo - - //##Documentation - //## @brief Get the position of a corner (in world coordinates) - //## - //## See SetImageGeometry for how a corner is defined on images. - // xx This was not vitrual! - virtual Point3D GetCornerPoint(bool xFront=true, bool yFront=true, bool zFront=true) const = 0 ; //ToDo - - //##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 - // xx This was not vitrual! - virtual Vector3D GetAxisVector(unsigned int direction) const = 0 ; //ToDo - - //##Documentation - //## @brief Get the center of the bounding-box in mm - //## - // xx This was not vitrual! - virtual Point3D GetCenter() const = 0 ; //ToDo - - //##Documentation - //## @brief Get the squared length of the diagonal of the bounding-box in mm - //## - // xx This was not vitrual! - virtual double GetDiagonalLength2() const = 0 ; //ToDo - - //##Documentation - //## @brief Get the length of the diagonal of the bounding-box in mm - //## - // xx This was not vitrual! - virtual double GetDiagonalLength() const = 0 ; //ToDo - #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 - //##Documentation - //## @brief Get the extent of the bounding-box in the specified @a direction in mm - //## - //## Equals length of GetAxisVector(direction). - // xx This was not vitrual! - virtual ScalarType GetExtentInMM(int direction) const = 0 ; //ToDo - - //##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) = 0 ; //ToDo - - //##Documentation - //## @brief Test whether the point \a p (world coordinates in mm) is - //## inside the bounding box - // xx This was not vitrual! - virtual bool IsInside(const mitk::Point3D& p) const = 0 ; //ToDo - - //##Documentation - //## @brief Test whether the point \a p ((continous!)index coordinates in units) is - //## inside the bounding box - // xx This was not vitrual! - virtual bool IsIndexInside(const mitk::Point3D& index) const = 0 ; //ToDo - - //##Documentation - //## @brief Get the parametric extent - //## - //## See AbstractTransformGeometry for an example usage of this. - // xx This was not vitrual! - virtual mitk::ScalarType GetParametricExtent(int direction) const = 0 ; //ToDo - - //##Documentation - //## @brief Get the parametric extent in mm - //## - //## See AbstractTransformGeometry for an example usage of this. - virtual mitk::ScalarType GetParametricExtentInMM(int direction) const = 0 ; //ToDo - 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 - VnlQuaternionType m_RotationQuaternion; //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/mitkGeometry3D.h b/Core/Code/DataManagement/mitkGeometry3D.h index 798da3a2e8..fb30f4e7aa 100644 --- a/Core/Code/DataManagement/mitkGeometry3D.h +++ b/Core/Code/DataManagement/mitkGeometry3D.h @@ -1,642 +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 "itkScalableAffineTransform.h" #include #include "mitkBaseGeometry.h" class vtkLinearTransform; namespace mitk { //##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; #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 { 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) { dim=3; } 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) { index.Fill(0); dim=3; } for(i=0;i( pt_units[i] ); } } //##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 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 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/mitkBaseGeometryTest.cpp b/Core/Code/Testing/mitkBaseGeometryTest.cpp index a3fbbc2dfb..f5215b425d 100644 --- a/Core/Code/Testing/mitkBaseGeometryTest.cpp +++ b/Core/Code/Testing/mitkBaseGeometryTest.cpp @@ -1,106 +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; - /* // for standard test: get() missing - CPPUNIT_ASSERT(dummy1.m_ImageGeometry==false); - CPPUNIT_ASSERT(dummy1.m_Valid==true); + + 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; + // DummyTestClass dummy2; //CPPUNIT_ASSERT(Equal(dummy1,dummy2,mitk::eps,true)); } }; MITK_TEST_SUITE_REGISTRATION(mitkBaseGeometry)