diff --git a/Core/Code/DataManagement/mitkTimeGeometry.cpp b/Core/Code/DataManagement/mitkTimeGeometry.cpp index 530f6c4779..6914435a51 100644 --- a/Core/Code/DataManagement/mitkTimeGeometry.cpp +++ b/Core/Code/DataManagement/mitkTimeGeometry.cpp @@ -1,153 +1,166 @@ /*=================================================================== 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 mitk::TimeGeometry::TimeGeometry() : m_BoundingBox(BoundingBox::New()) { typedef BoundingBox::PointsContainer ContainerType; ContainerType::Pointer points = ContainerType::New(); m_BoundingBox->SetPoints(points.GetPointer()); } mitk::TimeGeometry::~TimeGeometry() { } void mitk::TimeGeometry::Initialize() { } /* \brief short description * parameters * */ mitk::Point3D mitk::TimeGeometry::GetCornerPointInWorld(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."); return NULL; } } // TimeGeometry has no Transformation. Therefore the bounding box // contains all data in world coordinates return cornerpoint; } mitk::Point3D mitk::TimeGeometry::GetCornerPointInWorld(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]); return cornerpoint; } mitk::Point3D mitk::TimeGeometry::GetCenterInWorld() const { assert(m_BoundingBox.IsNotNull()); return m_BoundingBox->GetCenter(); } double mitk::TimeGeometry::GetDiagonalLength2InWorld() const { Vector3D diagonalvector = GetCornerPointInWorld()-GetCornerPointInWorld(false, false, false); return diagonalvector.GetSquaredNorm(); } double mitk::TimeGeometry::GetDiagonalLengthinWorld() const { return sqrt(GetDiagonalLength2InWorld()); } bool mitk::TimeGeometry::IsWorldPointInside(const mitk::Point3D& p) const { return m_BoundingBox->IsInside(p); } void mitk::TimeGeometry::UpdateBoundingBox () { assert(m_BoundingBox.IsNotNull()); typedef BoundingBox::PointsContainer ContainerType; unsigned long lastModifiedTime = 0; unsigned long currentModifiedTime = 0; ContainerType::Pointer points = ContainerType::New(); points->reserve(2*GetNumberOfTimeSteps()); for (TimeStepType step = 0; step GetMTime(); if (currentModifiedTime > lastModifiedTime) lastModifiedTime = currentModifiedTime; Point3D minimum = GetGeometryForTimeStep(step)->GetCornerPoint(false,false,false); Point3D maximum = GetGeometryForTimeStep(step)->GetCornerPoint(true,true,true); points->push_back(minimum); points->push_back(maximum); } m_BoundingBox->SetPoints(points); m_BoundingBox->ComputeBoundingBox(); if (this->GetMTime() < lastModifiedTime) this->Modified(); } mitk::ScalarType mitk::TimeGeometry::GetExtendInWorld (unsigned int direction) const { assert(direction < 3); assert(m_BoundingBox.IsNotNull()); BoundingBox::BoundsArrayType bounds = m_BoundingBox->GetBounds(); return bounds[direction * 2 + 1] - bounds[direction * 2]; } void mitk::TimeGeometry::Update() { this->UpdateBoundingBox(); this->UpdateWithoutBoundingBox(); } void mitk::TimeGeometry::ExecuteOperation(mitk::Operation* op) { for (TimeStepType step = 0; step < GetNumberOfTimeSteps(); ++step) { GetGeometryForTimeStep(step)->ExecuteOperation(op); } } + +void mitk::TimeGeometry::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + //Superclass::PrintSelf(os,indent); + os << indent << " TimeSteps: " << this->GetNumberOfTimeSteps() << std::endl; + + os << std::endl; + os << indent << " GetGeometryForTimeStep(0): "; + if(GetGeometryForTimeStep(0)==NULL) + os << "NULL" << std::endl; + else + GetGeometryForTimeStep(0)->Print(os, indent); +} diff --git a/Core/Code/DataManagement/mitkTimeGeometry.h b/Core/Code/DataManagement/mitkTimeGeometry.h index 7bf375e97a..e6453a84f3 100644 --- a/Core/Code/DataManagement/mitkTimeGeometry.h +++ b/Core/Code/DataManagement/mitkTimeGeometry.h @@ -1,231 +1,233 @@ /*=================================================================== 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 TimeGeometry_h #define TimeGeometry_h //ITK #include #include #include //MITK #include #include #include "mitkOperationActor.h" #include "mitkVector.h" // To be replaced #include // STL #include namespace mitk { // typedef itk::BoundingBox BoundingBox; // typedef itk::FixedArray TimeBounds; // typedef unsigned long TimePointType; typedef float TimePointType; typedef std::size_t TimeStepType; /** * \brief Manages the geometries of a data object for each time step * * For each time step a geometry object is kept, which defines * the position and transformation of the BasicObject. */ class MITK_CORE_EXPORT TimeGeometry : public itk::Object, public OperationActor { protected: TimeGeometry(); virtual ~TimeGeometry(); /** * \brief Contains a bounding box which includes all time steps */ BoundingBox::Pointer m_BoundingBox; public: mitkClassMacro(TimeGeometry, itk::Object); /** * \brief Returns the number of time steps. */ virtual TimeStepType GetNumberOfTimeSteps() const = 0; /** * \brief Returns the first time point for which the object is valid. */ virtual TimePointType GetMinimumTimePoint () const = 0; /** * \brief Returns the last time point for which the object is valid */ virtual TimePointType GetMaximumTimePoint () const = 0; /** * \brief Get the time bounds (in ms) */ virtual TimeBounds GetTimeBounds( ) const = 0; /** * \brief Tests if a given time point is covered by this object */ virtual bool IsValidTimePoint (TimePointType timePoint) const = 0; /** * \brief Test for the given time step if a geometry is availible */ virtual bool IsValidTimeStep (TimeStepType timeStep) const = 0; /** * \brief Converts a time step to a time point */ virtual TimePointType TimeStepToTimePoint (TimeStepType timeStep) const = 0; /** * \brief Converts a time point to the corresponding time step */ virtual TimeStepType TimePointToTimeStep (TimePointType timePoint) const = 0; /** * \brief Returns the geometry of a specific time point */ virtual Geometry3D* GetGeometryForTimePoint ( TimePointType timePoint) const = 0; /** * \brief Returns the geometry which corresponds to the given time step */ virtual Geometry3D* GetGeometryForTimeStep ( TimeStepType timeStep) const = 0; /** * \brief Returns a clone of the geometry of a specific time point */ virtual Geometry3D::Pointer GetGeometryCloneForTimeStep( TimeStepType timeStep) const = 0; /** * \brief Sets the geometry for a given time step */ virtual void SetTimeStepGeometry(Geometry3D* geometry, TimeStepType timeStep) = 0; /** * \brief Expands to the given number of time steps * * Expands to the given number of time steps. Each new created time * step is filled with an empty geometry. * Shrinking is not supported! */ virtual void Expand(TimeStepType size) = 0; /** * \brief Tests if all necessary informations are set and the object is valid */ virtual bool IsValid () = 0; /** * \brief Get the position of the corner number \a id (in world coordinates) * * See SetImageGeometry for how a corner is defined on images. */ Point3D GetCornerPointInWorld(int id) const; /** * \brief Get the position of a corner (in world coordinates) * * See SetImageGeometry for how a corner is defined on images. */ Point3D GetCornerPointInWorld(bool xFront=true, bool yFront=true, bool zFront=true) const; /** * \brief Get the center of the bounding-box in mm */ Point3D GetCenterInWorld() const; /** * \brief Get the squared length of the diagonal of the bounding-box in mm */ double GetDiagonalLength2InWorld() const; /** * \brief Get the length of the diagonal of the bounding-box in mm */ double GetDiagonalLengthinWorld() const; /** * \brief Test whether the point \a p (world coordinates in mm) is inside the bounding box */ bool IsWorldPointInside(const mitk::Point3D& p) const; /** * \brief Updates the bounding box to cover the area used in all time steps * * The bounding box is updated by this method. The new bounding box * covers an area which includes all bounding boxes during * all times steps. */ void UpdateBoundingBox(); /** * \brief Returns a bounding box that covers all time steps */ BoundingBox* GetBoundingBoxInWorld() const { return m_BoundingBox; } /** * \brief Returns the world bounds of the object that cover all time steps */ BoundingBox::BoundsArrayType GetBoundsInWorld() const { return m_BoundingBox->GetBounds(); } /** * \brief Returns the Extend of the bounding in the given direction */ ScalarType GetExtendInWorld (unsigned int direction) const; /** * \brief Makes a deep copy of the current object */ virtual TimeGeometry::Pointer Clone () const = 0 ; /** * \brief Initializes the TimeGeometry */ virtual void Initialize(); /** * \brief Updates the geometry */ void Update(); /** * \brief Updates everything except the Bounding box * * This class should be overwritten by child classes. * The method is called when Update() is required. */ virtual void UpdateWithoutBoundingBox() {}; /** * \brief Executes the given operation on all time steps */ virtual void ExecuteOperation(Operation *op); + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + }; // end class TimeGeometry } // end namespace MITK #endif // TimeGeometry_h \ No newline at end of file