diff --git a/Core/Code/DataManagement/mitkProportionalTimeGeometry.cpp b/Core/Code/DataManagement/mitkProportionalTimeGeometry.cpp index 1289f57e33..82d6206c0c 100644 --- a/Core/Code/DataManagement/mitkProportionalTimeGeometry.cpp +++ b/Core/Code/DataManagement/mitkProportionalTimeGeometry.cpp @@ -1,211 +1,213 @@ /*=================================================================== 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 mitk::ProportionalTimeGeometry::ProportionalTimeGeometry() : m_FirstTimePoint(0.0), m_StepDuration(1.0) { } mitk::ProportionalTimeGeometry::~ProportionalTimeGeometry() { } void mitk::ProportionalTimeGeometry::Initialize() { m_FirstTimePoint = 0.0; m_StepDuration = 1.0; } mitk::TimeStepType mitk::ProportionalTimeGeometry::GetNumberOfTimeSteps () const { return static_cast(m_GeometryVector.size() ); } mitk::TimePointType mitk::ProportionalTimeGeometry::GetMinimumTimePoint () const { return m_FirstTimePoint; } mitk::TimePointType mitk::ProportionalTimeGeometry::GetMaximumTimePoint () const { return m_FirstTimePoint + m_StepDuration * GetNumberOfTimeSteps(); } mitk::TimeBounds mitk::ProportionalTimeGeometry::GetTimeBounds () const { TimeBounds bounds; bounds[0] = this->GetMinimumTimePoint(); bounds[1] = this->GetMaximumTimePoint(); return bounds; } bool mitk::ProportionalTimeGeometry::IsValidTimePoint (TimePointType timePoint) const { return this->GetMinimumTimePoint() <= timePoint && timePoint < this->GetMaximumTimePoint(); } bool mitk::ProportionalTimeGeometry::IsValidTimeStep (TimeStepType timeStep) const { return 0 <= timeStep && timeStep < this->GetNumberOfTimeSteps(); } mitk::TimePointType mitk::ProportionalTimeGeometry::TimeStepToTimePoint( TimeStepType timeStep) const { if (m_FirstTimePoint <= std::numeric_limits::min() || m_FirstTimePoint >= std::numeric_limits::max() || m_StepDuration <= std::numeric_limits::min() || m_StepDuration >= std::numeric_limits::max()) { return static_cast(timeStep); } return m_FirstTimePoint + timeStep * m_StepDuration; } mitk::TimeStepType mitk::ProportionalTimeGeometry::TimePointToTimeStep( TimePointType timePoint) const { if (m_FirstTimePoint <= timePoint) return static_cast((timePoint -m_FirstTimePoint) / m_StepDuration); else return 0; } mitk::Geometry3D* mitk::ProportionalTimeGeometry::GetGeometryForTimeStep( TimeStepType timeStep) const { if (IsValidTimeStep(timeStep)) { return dynamic_cast(m_GeometryVector[timeStep].GetPointer()); } else { return NULL; } } mitk::Geometry3D* mitk::ProportionalTimeGeometry::GetGeometryForTimePoint(TimePointType timePoint) const { TimeStepType timeStep = this->TimePointToTimeStep(timePoint); return this->GetGeometryForTimeStep(timeStep); } mitk::Geometry3D::Pointer mitk::ProportionalTimeGeometry::GetGeometryCloneForTimeStep( TimeStepType timeStep) const { - return m_GeometryVector[timeStep].GetPointer(); + if (timeStep > m_GeometryVector.size()) + return 0; + return m_GeometryVector[timeStep]->Clone(); } bool mitk::ProportionalTimeGeometry::IsValid() { bool isValid = true; isValid &= m_GeometryVector.size() > 0; isValid &= m_StepDuration > 0; return isValid; } void mitk::ProportionalTimeGeometry::ClearAllGeometries() { m_GeometryVector.clear(); } void mitk::ProportionalTimeGeometry::ReserveSpaceForGeometries(TimeStepType numberOfGeometries) { m_GeometryVector.reserve(numberOfGeometries); } void mitk::ProportionalTimeGeometry::Expand(mitk::TimeStepType size) { m_GeometryVector.reserve(size); while (m_GeometryVector.size() < size) { m_GeometryVector.push_back(Geometry3D::New()); } } void mitk::ProportionalTimeGeometry::SetTimeStepGeometry(Geometry3D *geometry, TimeStepType timeStep) { assert(timeStep<=m_GeometryVector.size()); assert(timeStep >= 0); if (timeStep == m_GeometryVector.size()) m_GeometryVector.push_back(geometry); m_GeometryVector[timeStep] = geometry; } itk::LightObject::Pointer mitk::ProportionalTimeGeometry::InternalClone() const { ProportionalTimeGeometry::Pointer newTimeGeometry = ProportionalTimeGeometry::New(); newTimeGeometry->m_BoundingBox = m_BoundingBox->DeepCopy(); newTimeGeometry->m_FirstTimePoint = this->m_FirstTimePoint; newTimeGeometry->m_StepDuration = this->m_StepDuration; newTimeGeometry->m_GeometryVector.clear(); newTimeGeometry->Expand(this->GetNumberOfTimeSteps()); for (TimeStepType i =0; i < GetNumberOfTimeSteps(); ++i) { Geometry3D::Pointer tempGeometry = GetGeometryForTimeStep(i)->Clone(); newTimeGeometry->SetTimeStepGeometry(tempGeometry.GetPointer(),i); } itk::LightObject::Pointer finalPointer = dynamic_cast(newTimeGeometry.GetPointer()); return finalPointer; } void mitk::ProportionalTimeGeometry::Initialize (Geometry3D * geometry, TimeStepType timeSteps) { timeSteps = (timeSteps > 0) ? timeSteps : 1; m_FirstTimePoint = geometry->GetTimeBounds()[0]; m_StepDuration = geometry->GetTimeBounds()[1] - geometry->GetTimeBounds()[0]; this->ReserveSpaceForGeometries(timeSteps); try{ for (TimeStepType currentStep = 0; currentStep < timeSteps; ++currentStep) { mitk::TimeBounds timeBounds; if (timeSteps > 1) { timeBounds[0] = m_FirstTimePoint + currentStep * m_StepDuration; timeBounds[1] = m_FirstTimePoint + (currentStep+1) * m_StepDuration; } else { timeBounds = geometry->GetTimeBounds(); } Geometry3D::Pointer clonedGeometry = geometry->Clone(); this->SetTimeStepGeometry(clonedGeometry.GetPointer(), currentStep); GetGeometryForTimeStep(currentStep)->SetTimeBounds(timeBounds); } } catch (...) { MITK_INFO << "Cloning of geometry produced an error!"; } Update(); } void mitk::ProportionalTimeGeometry::Initialize (TimeStepType timeSteps) { mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); geometry->Initialize(); if ( timeSteps > 1 ) { mitk::ScalarType timeBounds[] = {0.0, 1.0}; geometry->SetTimeBounds( timeBounds ); } this->Initialize(geometry.GetPointer(), timeSteps); } diff --git a/Core/Code/DataManagement/mitkProportionalTimeGeometry.h b/Core/Code/DataManagement/mitkProportionalTimeGeometry.h index 786514948b..7854697d42 100644 --- a/Core/Code/DataManagement/mitkProportionalTimeGeometry.h +++ b/Core/Code/DataManagement/mitkProportionalTimeGeometry.h @@ -1,109 +1,208 @@ /*=================================================================== 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 ProportialTimeGeometry_h #define ProportialTimeGeometry_h //ITK #include #include #include //MITK #include #include #include #include "mitkOperationActor.h" #include "mitkVector.h" // To be replaced #include // STL #include namespace mitk { -// typedef itk::BoundingBox BoundingBox; -// typedef itk::FixedArray TimeBounds; - + /** + * \brief la + * + * + * \addtogroup geometry + */ class MITK_CORE_EXPORT ProportionalTimeGeometry : public TimeGeometry { public: mitkClassMacro(ProportionalTimeGeometry, TimeGeometry); ProportionalTimeGeometry(); typedef ProportionalTimeGeometry self; itkNewMacro(self); + /** + * \brief Returns the number of time steps. + * + * Returns the number of time steps for which + * geometries are saved. The number of time steps + * is also the upper bound of the time steps. The + * minimum time steps is always 0. + */ virtual TimeStepType GetNumberOfTimeSteps() const; + /** + * \brief Returns the first time point for which the object is valid. + * + * Returns the first valid time point for this geometry. If only one + * time steps available it usually goes from -max to +max. The time point + * is given in ms. + */ virtual TimePointType GetMinimumTimePoint () const; + /** + * \brief Returns the last time point for which the object is valid + * + * Gives the last time point for which a valid geometrie is saved in + * this time geometry. The time point is given in ms. + */ virtual TimePointType GetMaximumTimePoint () const; - //##Documentation - //## @brief Get the time bounds (in ms) + /** + * \brief Get the time bounds (in ms) + */ virtual TimeBounds GetTimeBounds( ) const; - + /** + * \brief Tests if a given time point is covered by this object + * + * Returns true if a geometry can be returned for the given time + * point and falls if not. The time point must be given in ms. + */ virtual bool IsValidTimePoint (TimePointType timePoint) const; + /** + * \brief Test for the given time step if a geometry is availible + * + * Returns true if a geometry is defined for the given time step. + * Otherwise false is returned. + * The time step is defined as positiv number. + */ virtual bool IsValidTimeStep (TimeStepType timeStep) const; + /** + * \brief Converts a time step to a time point + * + * Converts a time step to a time point in a way that + * the new time point indicates the same geometry as the time step. + * If the original time steps does not point to a valid geometry, + * a time point is calculated that also does not point to a valid + * geometry, but no exception is raised. + */ virtual TimePointType TimeStepToTimePoint (TimeStepType timeStep) const; + /** + * \brief Converts a time point to the corresponding time step + * + * Converts a time point to a time step in a way that + * the new time step indicates the same geometry as the time point. + * If a negativ invalid time point is given always time step 0 is + * returned. If an positiv invalid time step is given an invalid + * time step will be returned. + */ virtual TimeStepType TimePointToTimeStep (TimePointType timePoint) const; + /** + * \brief Returns the geometry which corresponds to the given time step + * + * Returns a clone of the geometry which defines the given time step. If + * the given time step is invalid an null-pointer is returned. + */ virtual Geometry3D::Pointer GetGeometryCloneForTimeStep( TimeStepType timeStep) const; + /** + * \brief Returns the geometry which corresponds to the given time point + * + * Returns the geometry which defines the given time point. If + * the given time point is invalid an null-pointer is returned. + * + * If the returned geometry is changed this will affect the saved + * geometry. + */ virtual Geometry3D* GetGeometryForTimePoint ( TimePointType timePoint) const; + /** + * \brief Returns the geometry which corresponds to the given time step + * + * Returns the geometry which defines the given time step. If + * the given time step is invalid an null-pointer is returned. + * + * If the returned geometry is changed this will affect the saved + * geometry. + */ virtual Geometry3D* GetGeometryForTimeStep ( TimeStepType timeStep) const; + /** + * \brief Tests if all necessary informations are set and the object is valid + */ virtual bool IsValid (); + /** + * \brief Initilizes a new object with one time steps which contains an empty geometry. + */ virtual void Initialize(); + /** + * \brief Expands the time geometry to the given number of time steps. + * + * Initializes the new time steps with empty geometries. + * Shrinking is not supported. + */ virtual void Expand(TimeStepType size); + /** + * \brief Sets the geometry for the given time step + * + * This method does not afflict other time steps, since the geometry for + * each time step is saved individually. + */ virtual void SetTimeStepGeometry(Geometry3D* geometry, TimeStepType timeStep); /** * \brief Makes a deep copy of the current object */ virtual itk::LightObject::Pointer InternalClone () const; itkGetMacro(FirstTimePoint, TimePointType); itkSetMacro(FirstTimePoint, TimePointType); itkGetMacro(StepDuration, TimePointType); itkSetMacro(StepDuration, TimePointType); // void SetGeometryForTimeStep(TimeStepType timeStep, BaseGeometry& geometry); void ClearAllGeometries (); // void AddGeometry(BaseGeometry geometry); void ReserveSpaceForGeometries (TimeStepType numberOfGeometries); /** * \brief Initializes the TimeGeometry with equally time Step geometries + * + * Saves a copy for each time step. */ void Initialize (Geometry3D * geometry, TimeStepType timeSteps); /** * \brief Initialize the TimeGeometry with empty Geometry3D */ void Initialize (TimeStepType timeSteps); protected: virtual ~ProportionalTimeGeometry(); std::vector m_GeometryVector; TimePointType m_FirstTimePoint; TimePointType m_StepDuration; }; // end class ProportialTimeGeometry } // end namespace MITK #endif // ProportialTimeGeometry_h \ No newline at end of file diff --git a/Core/Code/DataManagement/mitkSlicedData.cpp b/Core/Code/DataManagement/mitkSlicedData.cpp index efaa8239dd..99dc3d67bd 100644 --- a/Core/Code/DataManagement/mitkSlicedData.cpp +++ b/Core/Code/DataManagement/mitkSlicedData.cpp @@ -1,343 +1,344 @@ /*=================================================================== 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 "mitkSlicedData.h" #include "mitkBaseProcess.h" #include mitk::SlicedData::SlicedData() : m_UseLargestPossibleRegion(false) { unsigned int i; for(i=0;i<4;++i) { m_LargestPossibleRegion.SetIndex(i, 0); m_LargestPossibleRegion.SetSize (i, 1); } } mitk::SlicedData::SlicedData( const SlicedData &other ): BaseData(other), m_LargestPossibleRegion(other.m_LargestPossibleRegion), m_RequestedRegion(other.m_RequestedRegion), m_BufferedRegion(other.m_BufferedRegion), m_UseLargestPossibleRegion(other.m_UseLargestPossibleRegion) { } mitk::SlicedData::~SlicedData() { } void mitk::SlicedData::UpdateOutputInformation() { Superclass::UpdateOutputInformation(); if (this->GetSource().IsNull()) // If we don't have a source, then let's make our Image // span our buffer { m_UseLargestPossibleRegion = true; } // Now we should know what our largest possible region is. If our // requested region was not set yet, (or has been set to something // invalid - with no data in it ) then set it to the largest possible // region. if ( ! m_RequestedRegionInitialized) { this->SetRequestedRegionToLargestPossibleRegion(); m_RequestedRegionInitialized = true; } m_LastRequestedRegionWasOutsideOfTheBufferedRegion = 0; } void mitk::SlicedData::PrepareForNewData() { if ( GetUpdateMTime() < GetPipelineMTime() || GetDataReleased() ) { ReleaseData(); } } void mitk::SlicedData::SetRequestedRegionToLargestPossibleRegion() { m_UseLargestPossibleRegion = true; if(GetGeometry()==NULL) return; unsigned int i; const RegionType::IndexType & index = GetLargestPossibleRegion().GetIndex(); const RegionType::SizeType & size = GetLargestPossibleRegion().GetSize(); for(i=0;i(requestedRegionSize[4]); if(requestedRegionSize[3] == largestPossibleRegionSize[3]) { for (; c< cEnd; ++c) if(IsChannelSet(c)==false) return true; return false; } // are whole volumes requested? int t, tEnd; t=requestedRegionIndex[3]; tEnd=t+static_cast(requestedRegionSize[3]); if(requestedRegionSize[2] == largestPossibleRegionSize[2]) { for (; c< cEnd; ++c) for (; t< tEnd; ++t) if(IsVolumeSet(t, c)==false) return true; return false; } // ok, only slices are requested. Check if they are available. int s, sEnd; s=requestedRegionIndex[2]; sEnd=s+static_cast(requestedRegionSize[2]); for (; c< cEnd; ++c) for (; t< tEnd; ++t) for (; s< sEnd; ++s) if(IsSliceSet(s, t, c)==false) return true; return false; } bool mitk::SlicedData::VerifyRequestedRegion() { if(GetTimeGeometry() == NULL) return false; unsigned int i; // Is the requested region within the LargestPossibleRegion? // Note that the test is indeed against the largest possible region // rather than the buffered region; see DataObject::VerifyRequestedRegion. const IndexType &requestedRegionIndex = m_RequestedRegion.GetIndex(); const IndexType &largestPossibleRegionIndex = GetLargestPossibleRegion().GetIndex(); const SizeType& requestedRegionSize = m_RequestedRegion.GetSize(); const SizeType& largestPossibleRegionSize = GetLargestPossibleRegion().GetSize(); for (i=0; i< RegionDimension; ++i) { if ( (requestedRegionIndex[i] < largestPossibleRegionIndex[i]) || ((requestedRegionIndex[i] + static_cast(requestedRegionSize[i])) > (largestPossibleRegionIndex[i]+static_cast(largestPossibleRegionSize[i])))) { return false; } } return true; } void mitk::SlicedData::SetRequestedRegion( const itk::DataObject *data) { m_UseLargestPossibleRegion=false; const mitk::SlicedData *slicedData = dynamic_cast(data); if (slicedData) { m_RequestedRegion = slicedData->GetRequestedRegion(); m_RequestedRegionInitialized = true; } else { // pointer could not be cast back down itkExceptionMacro( << "mitk::SlicedData::SetRequestedRegion(DataObject*) cannot cast " << typeid(data).name() << " to " << typeid(SlicedData*).name() ); } } void mitk::SlicedData::SetRequestedRegion(SlicedData::RegionType *region) { m_UseLargestPossibleRegion=false; if(region!=NULL) { m_RequestedRegion = *region; m_RequestedRegionInitialized = true; } else { // pointer could not be cast back down itkExceptionMacro( << "mitk::SlicedData::SetRequestedRegion(SlicedData::RegionType*) cannot cast " << typeid(region).name() << " to " << typeid(SlicedData*).name() ); } } void mitk::SlicedData::CopyInformation(const itk::DataObject *data) { // Standard call to the superclass' method Superclass::CopyInformation(data); const mitk::SlicedData *slicedData; slicedData = dynamic_cast(data); if (slicedData) { m_LargestPossibleRegion = slicedData->GetLargestPossibleRegion(); } else { // pointer could not be cast back down itkExceptionMacro( << "mitk::SlicedData::CopyInformation(const DataObject *data) cannot cast " << typeid(data).name() << " to " << typeid(SlicedData*).name() ); } } //const mitk::Geometry2D* mitk::SlicedData::GetGeometry2D(int s, int t) const //{ // const_cast(this)->SetRequestedRegionToLargestPossibleRegion(); // // const_cast(this)->UpdateOutputInformation(); // // return GetSlicedGeometry(t)->GetGeometry2D(s); //} // mitk::SlicedGeometry3D* mitk::SlicedData::GetSlicedGeometry(unsigned int t) const { if (GetTimeGeometry() == NULL) return NULL; return dynamic_cast(GetTimeGeometry()->GetGeometryForTimeStep(t)); } const mitk::SlicedGeometry3D* mitk::SlicedData::GetUpdatedSlicedGeometry(unsigned int t) { SetRequestedRegionToLargestPossibleRegion(); UpdateOutputInformation(); return GetSlicedGeometry(t); } void mitk::SlicedData::SetGeometry(Geometry3D* aGeometry3D) { if(aGeometry3D!=NULL) { ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New(); SlicedGeometry3D::Pointer slicedGeometry = dynamic_cast(aGeometry3D); if(slicedGeometry.IsNull()) { Geometry2D* geometry2d = dynamic_cast(aGeometry3D); if(geometry2d!=NULL) { if((GetSlicedGeometry()->GetGeometry2D(0)==geometry2d) && (GetSlicedGeometry()->GetSlices()==1)) return; slicedGeometry = SlicedGeometry3D::New(); slicedGeometry->InitializeEvenlySpaced(geometry2d, 1); } else { slicedGeometry = SlicedGeometry3D::New(); PlaneGeometry::Pointer planeGeometry = PlaneGeometry::New(); planeGeometry->InitializeStandardPlane(aGeometry3D); slicedGeometry->InitializeEvenlySpaced(planeGeometry, (unsigned int)(aGeometry3D->GetExtent(2))); } } assert(slicedGeometry.IsNotNull()); timeGeometry->Initialize(slicedGeometry, 1); Superclass::SetTimeGeometry(timeGeometry); } else { if(GetGeometry()==NULL) return; Superclass::SetGeometry(NULL); } } void mitk::SlicedData::SetSpacing(const float aSpacing[3]) { this->SetSpacing((mitk::Vector3D)aSpacing); } void mitk::SlicedData::SetOrigin(const mitk::Point3D& origin) { TimeGeometry* timeGeometry = GetTimeGeometry(); assert(timeGeometry!=NULL); mitk::SlicedGeometry3D* slicedGeometry; unsigned int steps = timeGeometry->GetNumberOfTimeSteps(); for(unsigned int timestep = 0; timestep < steps; ++timestep) { slicedGeometry = GetSlicedGeometry(timestep); if(slicedGeometry != NULL) { slicedGeometry->SetOrigin(origin); if(slicedGeometry->GetEvenlySpaced()) { mitk::Geometry2D* geometry2D = slicedGeometry->GetGeometry2D(0); geometry2D->SetOrigin(origin); slicedGeometry->InitializeEvenlySpaced(geometry2D, slicedGeometry->GetSlices()); } } //ProportionalTimeGeometry* timeGeometry = dynamic_cast(GetTimeGeometry()); //if(timeGeometry != NULL) //{ // timeGeometry->Initialize(slicedGeometry, steps); // break; //} } } void mitk::SlicedData::SetSpacing(mitk::Vector3D aSpacing) { TimeGeometry* timeGeometry = GetTimeGeometry(); assert(timeGeometry!=NULL); mitk::SlicedGeometry3D* slicedGeometry; unsigned int steps = timeGeometry->GetNumberOfTimeSteps(); for(unsigned int timestep = 0; timestep < steps; ++timestep) { slicedGeometry = GetSlicedGeometry(timestep); if(slicedGeometry != NULL) { slicedGeometry->SetSpacing(aSpacing); } } + timeGeometry->Update(); } diff --git a/Core/Code/DataManagement/mitkTimeGeometry.cpp b/Core/Code/DataManagement/mitkTimeGeometry.cpp index 8835b4c753..6f97b31e30 100644 --- a/Core/Code/DataManagement/mitkTimeGeometry.cpp +++ b/Core/Code/DataManagement/mitkTimeGeometry.cpp @@ -1,166 +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 Point3D(); } } // 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 +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 +mitk::ScalarType mitk::TimeGeometry::GetExtentInWorld (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 b58e2911cd..f4ec455188 100644 --- a/Core/Code/DataManagement/mitkTimeGeometry.h +++ b/Core/Code/DataManagement/mitkTimeGeometry.h @@ -1,242 +1,294 @@ /*=================================================================== 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. + * This class is an abstract class. The concrete implementation + * depends on the way the different time steps are managed. + * + * The time is defined either by a time step or a time point. Time steps + * are non-negativ integers starting from 0. A time point is is an float value + * which gives the passed time since start in ms. Be aware that the starting + * point is not fixed so it is possible that the same time point defines two + * different time depending on the start time of the used time geometry. */ 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); - + itkCloneMacro(Self); /** * \brief Returns the number of time steps. + * + * Returns the number of time steps for which + * geometries are saved. The number of time steps + * is also the upper bound of the time steps. The + * minimum time steps is always 0. */ virtual TimeStepType GetNumberOfTimeSteps() const = 0; /** * \brief Returns the first time point for which the object is valid. + * + * Returns the first valid time point for this geometry. If only one + * time steps available it usually goes from -max to +max. The time point + * is given in ms. */ virtual TimePointType GetMinimumTimePoint () const = 0; /** * \brief Returns the last time point for which the object is valid + * + * Gives the last time point for which a valid geometrie is saved in + * this time geometry. The time point is given in ms. */ 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 + * + * Returns true if a geometry can be returned for the given time + * point and falls if not. The time point must be given in ms. */ virtual bool IsValidTimePoint (TimePointType timePoint) const = 0; /** * \brief Test for the given time step if a geometry is availible + * + * Returns true if a geometry is defined for the given time step. + * Otherwise false is returned. + * The time step is defined as positiv number. */ virtual bool IsValidTimeStep (TimeStepType timeStep) const = 0; /** * \brief Converts a time step to a time point * - * Wenn keine gültige Zeit wird theoretischer Puntk berechnet + * Converts a time step to a time point in a way that + * the new time point indicates the same geometry as the time step. + * If the original time steps does not point to a valid geometry, + * a time point is calculated that also does not point to a valid + * geometry, but no exception is raised. */ virtual TimePointType TimeStepToTimePoint (TimeStepType timeStep) const = 0; /** * \brief Converts a time point to the corresponding time step * - * Wenn negative invalide Zeit Zeitschritt gleich 0 - * wenn positive invalide Zeit virtueller Zeitschritt + * Converts a time point to a time step in a way that + * the new time step indicates the same geometry as the time point. + * If a negativ invalid time point is given always time step 0 is + * returned. If an positiv invalid time step is given an invalid + * time step will be returned. */ virtual TimeStepType TimePointToTimeStep (TimePointType timePoint) const = 0; /** * \brief Returns the geometry of a specific time point * - * Kann, aber muss keine tatsaechliche Variante sein + * Returns the geometry which defines the given time point. If + * the given time point is invalid an null-pointer is returned. + * + * The pointer to the returned geometry may point to the saved + * geometry but this is not necessarily the case. So a change to + * the returned geometry may or may not afflict the geometry for the + * time point or all time points depending on the used implementation + * of TimeGeometry. */ virtual Geometry3D* GetGeometryForTimePoint ( TimePointType timePoint) const = 0; /** * \brief Returns the geometry which corresponds to the given time step + * + * Returns the geometry which defines the given time step. If + * the given time step is invalid an null-pointer is returned. + * + * The pointer to the returned geometry may point to the saved + * geometry but this is not necessarily the case. So a change to + * the returned geometry may or may not afflict the geometry for the + * time step or all time steps depending on the used implementation + * of TimeGeometry. */ virtual Geometry3D* GetGeometryForTimeStep ( TimeStepType timeStep) const = 0; /** * \brief Returns a clone of the geometry of a specific time point * - * Invalid time steps returns a null-pointer + * If an invalid time step is given (e.g. no geometry is defined for this time step) + * a null-pointer will be returned. */ virtual Geometry3D::Pointer GetGeometryCloneForTimeStep( TimeStepType timeStep) const = 0; /** * \brief Sets the geometry for a given time step + * + * Sets the geometry for the given time steps. This may also afflects other + * time steps, depending on the implementation of TimeGeometry. */ 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; + 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; + ScalarType GetExtentInWorld (unsigned int direction) const; /** * \brief Makes a deep copy of the current object */ virtual itk::LightObject::Pointer InternalClone () 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 diff --git a/Core/Code/Testing/mitkTimeGeometryTest.cpp b/Core/Code/Testing/mitkTimeGeometryTest.cpp index 05c3613246..c62a665d33 100644 --- a/Core/Code/Testing/mitkTimeGeometryTest.cpp +++ b/Core/Code/Testing/mitkTimeGeometryTest.cpp @@ -1,405 +1,689 @@ /*=================================================================== 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 "mitkTimeGeometry.h" #include "mitkGeometry3D.h" #include "mitkRotationOperation.h" #include "mitkInteractionConst.h" #include #include #include "mitkTestingMacros.h" #include #include #include #include "mitkImageGenerator.h" #include class mitkTimeGeometryTestClass { public: void Translation_Image_MovedOrigin(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { // DimX, DimY, DimZ, mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::Geometry3D::Pointer geometry = image->GetTimeGeometry()->GetGeometryForTimeStep(0); mitk::Point3D imageOrigin = geometry->GetOrigin(); mitk::Point3D expectedOrigin; expectedOrigin[0] = 0; expectedOrigin[1] = 0; expectedOrigin[2] = 0; MITK_TEST_CONDITION(mitk::Equal(imageOrigin, expectedOrigin), "Original origin match expected origin"); expectedOrigin[0] = 0.325; expectedOrigin[1] = 0.487; expectedOrigin[2] = 0.78; mitk::Vector3D translationVector; translationVector[0] = expectedOrigin[0]; translationVector[1] = expectedOrigin[1]; translationVector[2] = expectedOrigin[2]; for (mitk::TimeStepType timeStep = 0; timeStep < image->GetTimeGeometry()->GetNumberOfTimeSteps(); ++timeStep) { image->GetTimeGeometry()->GetGeometryForTimeStep(timeStep)->Translate(translationVector); } imageOrigin = image->GetGeometry(0)->GetOrigin(); MITK_TEST_CONDITION(mitk::Equal(imageOrigin, expectedOrigin), "Translated origin match expected origin"); expectedOrigin[0] = 2*translationVector[0]; expectedOrigin[1] = 2*translationVector[1]; expectedOrigin[2] = 2*translationVector[2]; for (mitk::TimeStepType timeStep = 0; timeStep < image->GetTimeGeometry()->GetNumberOfTimeSteps(); ++timeStep) { image->GetTimeGeometry()->GetGeometryForTimeStep(timeStep)->Translate(translationVector); } imageOrigin = image->GetGeometry(0)->GetOrigin(); MITK_TEST_CONDITION(mitk::Equal(imageOrigin, expectedOrigin), "Translated origin match expected origin"); } void Rotate_Image_RotatedPoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); mitk::DataNode::Pointer dataNode = mitk::DataNode::New(); // DimX, DimY, DimZ, mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); dataNode->SetData(image); ds->Add(dataNode); mitk::Geometry3D::Pointer geometry = image->GetTimeGeometry()->GetGeometryForTimeStep(0); mitk::Point3D expectedPoint; expectedPoint[0] = 3*0.5; expectedPoint[1] = 3*0.33; expectedPoint[2] = 3*0.78; mitk::Point3D originalPoint; originalPoint[0] = 3; originalPoint[1] = 3; originalPoint[2] = 3; mitk::Point3D worldPoint; geometry->IndexToWorld(originalPoint, worldPoint); MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Index-to-World without rotation as expected "); mitk::Point3D pointOfRotation; pointOfRotation[0] = 0; pointOfRotation[1] = 0; pointOfRotation[2] = 0; mitk::Vector3D vectorOfRotation; vectorOfRotation[0] = 1; vectorOfRotation[1] = 0.5; vectorOfRotation[2] = 0.2; float angleOfRotation = 73.0; mitk::RotationOperation* rotation = new mitk::RotationOperation(mitk::OpROTATE,pointOfRotation, vectorOfRotation, angleOfRotation); image->GetTimeGeometry()->ExecuteOperation(rotation); + delete rotation; expectedPoint[0] = 2.6080379; expectedPoint[1] = -0.75265157; expectedPoint[2] = 1.1564401; image->GetGeometry(0)->IndexToWorld(originalPoint,worldPoint); MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Rotation returns expected values "); } void Scale_Image_ScaledPoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { // DimX, DimY, DimZ, mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::Geometry3D::Pointer geometry = image->GetTimeGeometry()->GetGeometryForTimeStep(0); mitk::Point3D expectedPoint; expectedPoint[0] = 3*0.5; expectedPoint[1] = 3*0.33; expectedPoint[2] = 3*0.78; mitk::Point3D originalPoint; originalPoint[0] = 3; originalPoint[1] = 3; originalPoint[2] = 3; mitk::Point3D worldPoint; geometry->IndexToWorld(originalPoint, worldPoint); MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Index-to-World with old Scaling as expected "); mitk::Vector3D newSpacing; newSpacing[0] = 2; newSpacing[1] = 1.254; newSpacing[2] = 0.224; image->SetSpacing(newSpacing); expectedPoint[0] = 3*2; expectedPoint[1] = 3*1.254; expectedPoint[2] = 3*0.224; image->GetGeometry(0)->IndexToWorld(originalPoint,worldPoint); MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Index-toWorld with new Scaling returns expected values "); } void GetMinimumTimePoint_4DImage_Zero(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType expectedTimePoint = geometry->GetMinimumTimePoint(); MITK_TEST_CONDITION(mitk::Equal(expectedTimePoint, 0), "Returns correct minimum time point "); } void GetMaximumTimePoint_4DImage_DimT(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType expectedTimePoint = geometry->GetMaximumTimePoint(); MITK_TEST_CONDITION(mitk::Equal(expectedTimePoint, DimT), "Returns correct maximum time point "); } void GetNumberOfTimeSteps_Image_ReturnDimT(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimeStepType expectedTimeSteps = geometry->GetNumberOfTimeSteps(); MITK_TEST_CONDITION(mitk::Equal(expectedTimeSteps, DimT), "Returns correct number of time Steps "); } void GetMinimumTimePoint_3DImage_Min(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType expectedTimePoint = geometry->GetMinimumTimePoint(); MITK_TEST_CONDITION(mitk::Equal(expectedTimePoint, -std::numeric_limits().max()), "Returns correct minimum time point "); } void GetMaximumTimePoint_3DImage_Max(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType expectedTimePoint = geometry->GetMaximumTimePoint(); MITK_INFO << expectedTimePoint; MITK_INFO << std::numeric_limits().max(); MITK_TEST_CONDITION(mitk::Equal(expectedTimePoint, std::numeric_limits().max()), "Returns correct maximum time point "); } void GetTimeBounds_4DImage_ZeroAndDimT(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimeBounds expectedTimeBounds = geometry->GetTimeBounds(); MITK_TEST_CONDITION(mitk::Equal(expectedTimeBounds[0], 0), "Returns correct minimum time point "); MITK_TEST_CONDITION(mitk::Equal(expectedTimeBounds[1], DimT), "Returns correct maximum time point "); } void GetTimeBounds_3DImage_ZeroAndDimT(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimeBounds expectedTimeBounds = geometry->GetTimeBounds(); MITK_TEST_CONDITION(mitk::Equal(expectedTimeBounds[0], -std::numeric_limits().max()), "Returns correct minimum time point "); MITK_TEST_CONDITION(mitk::Equal(expectedTimeBounds[1], std::numeric_limits().max()), "Returns correct maximum time point "); } void IsValidTimePoint_ImageValidTimePoint_True(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); bool isValid = geometry->IsValidTimePoint(DimT-1); MITK_TEST_CONDITION(mitk::Equal(isValid, true), "Is valid time Point correct minimum time point "); } void IsValidTimePoint_ImageNegativInvalidTimePoint_False(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); bool isValid = geometry->IsValidTimePoint(-DimT); MITK_TEST_CONDITION(mitk::Equal(isValid, false), "Is invalid time Point correct minimum time point "); } void IsValidTimePoint_ImageInvalidTimePoint_False(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); bool isValid = geometry->IsValidTimePoint(DimT+1); MITK_TEST_CONDITION(mitk::Equal(isValid, false), "Is invalid time Point correct minimum time point "); } void IsValidTimeStep_ImageValidTimeStep_True(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); bool isValid = geometry->IsValidTimeStep(DimT-1); MITK_TEST_CONDITION(mitk::Equal(isValid, true), "Is valid time Point correct minimum time point "); } void IsValidTimeStep_ImageNegativInvalidTimeStep_False(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); bool isValid = geometry->IsValidTimeStep(-DimT); MITK_TEST_CONDITION(mitk::Equal(isValid, false), "Is invalid time Point correct minimum time point "); } void IsValidTimeStep_ImageInvalidTimeStep_False(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); bool isValid = geometry->IsValidTimeStep(DimT); MITK_TEST_CONDITION(mitk::Equal(isValid, false), "Is invalid time Point correct minimum time point "); } void TimeStepToTimePoint_ImageValidTimeStep_TimePoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType timePoint= geometry->TimeStepToTimePoint(DimT-1); MITK_TEST_CONDITION(mitk::Equal(timePoint, DimT-1), "Calculated right time Point for Time Step "); } void TimeStepToTimePoint_ImageInvalidTimeStep_TimePoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType timePoint= geometry->TimeStepToTimePoint(DimT+1); MITK_TEST_CONDITION(mitk::Equal(timePoint, DimT+1), "Calculated right time Point for invalid Time Step "); } void TimePointToTimeStep_ImageValidTimePoint_TimePoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimeStepType timePoint= geometry->TimePointToTimeStep(DimT-0.5); MITK_TEST_CONDITION(mitk::Equal(timePoint, DimT-1), "Calculated right time step for valid time point"); } void TimePointToTimeStep_4DImageInvalidTimePoint_TimePoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimeStepType timePoint= geometry->TimePointToTimeStep(DimT+1.5); MITK_TEST_CONDITION(mitk::Equal(timePoint, DimT+1), "Calculated right time step for invalid time point"); } void TimePointToTimeStep_4DImageNegativInvalidTimePoint_TimePoint(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::TimePointType negativTimePoint = (-1.0*DimT) - 1.5; mitk::TimeStepType timePoint= geometry->TimePointToTimeStep(negativTimePoint); MITK_TEST_CONDITION(mitk::Equal(timePoint, 0), "Calculated right time step for negativ invalid time point"); } void GetGeometryForTimeStep_ImageValidTimeStep_CorrectGeometry(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryForTimeStep(DimT-1); MITK_TEST_CONDITION(geometry3D.IsNotNull(), "Non-zero geometry returned"); mitk::Point3D expectedPoint; expectedPoint[0] = 3*0.5; expectedPoint[1] = 3*0.33; expectedPoint[2] = 3*0.78; mitk::Point3D originalPoint; originalPoint[0] = 3; originalPoint[1] = 3; originalPoint[2] = 3; mitk::Point3D worldPoint; geometry3D->IndexToWorld(originalPoint, worldPoint); MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Geometry transformation match expection. "); } - void GetGeometryForTimeStep_ImageInvalidTimeStep_CorrectGeometry(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + void GetGeometryForTimeStep_ImageInvalidTimeStep_NullPointer(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) { mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryForTimeStep(DimT+1); MITK_TEST_CONDITION(geometry3D.IsNull(), "Null-Pointer geometry returned"); } + + void GetGeometryForTimePoint_ImageValidTimePoint_CorrectGeometry(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryForTimePoint(DimT-0.5); + MITK_TEST_CONDITION(geometry3D.IsNotNull(), "Non-zero geometry returned"); + + mitk::Point3D expectedPoint; + expectedPoint[0] = 3*0.5; + expectedPoint[1] = 3*0.33; + expectedPoint[2] = 3*0.78; + mitk::Point3D originalPoint; + originalPoint[0] = 3; + originalPoint[1] = 3; + originalPoint[2] = 3; + mitk::Point3D worldPoint; + geometry3D->IndexToWorld(originalPoint, worldPoint); + MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Geometry transformation match expection. "); + } + + void GetGeometryForTimePoint_4DImageInvalidTimePoint_NullPointer(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryForTimePoint(DimT+1); + MITK_TEST_CONDITION(geometry3D.IsNull(), "Null-Pointer geometry returned with invalid time point"); + } + + void GetGeometryForTimePoint_4DImageNEgativInvalidTimePoint_NullPointer(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + mitk::TimePointType timePoint = (-1.0*(DimT)) -1; + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryForTimePoint(timePoint); + MITK_TEST_CONDITION(geometry3D.IsNull(), "Null-Pointer geometry returned with invalid negativ time point"); + } + + void GetGeometryCloneForTimeStep_ImageValidTimeStep_CorrectGeometry(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryCloneForTimeStep(DimT-1); + MITK_TEST_CONDITION(geometry3D.IsNotNull(), "Non-zero geometry returned"); + + mitk::Point3D expectedPoint; + expectedPoint[0] = 3*0.5; + expectedPoint[1] = 3*0.33; + expectedPoint[2] = 3*0.78; + mitk::Point3D originalPoint; + originalPoint[0] = 3; + originalPoint[1] = 3; + originalPoint[2] = 3; + mitk::Point3D worldPoint; + geometry3D->IndexToWorld(originalPoint, worldPoint); + MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Geometry transformation match expection. "); + + mitk::Vector3D translationVector; + translationVector[0] = 5; + translationVector[1] = 8; + translationVector[2] = 7; + geometry3D->Translate(translationVector); + + geometry3D = geometry->GetGeometryForTimeStep(DimT-1); + geometry3D->IndexToWorld(originalPoint, worldPoint); + MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Geometry transformation not changed. "); + } + + void GetGeometryCloneForTimeStep_ImageInvalidTimeStep_NullPointer(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryCloneForTimeStep(DimT+1); + MITK_TEST_CONDITION(geometry3D.IsNull(), "Null-Pointer geometry returned"); + } + + void SetTimeStepGeometry_ImageValidTimeStep_CorrectGeometry(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryCloneForTimeStep(DimT-1); + MITK_TEST_CONDITION(geometry3D.IsNotNull(), "Non-zero geometry returned"); + + mitk::Vector3D translationVector; + translationVector[0] = 5; + translationVector[1] = 8; + translationVector[2] = 7; + geometry3D->Translate(translationVector); + + geometry->SetTimeStepGeometry(geometry3D,DimT-1); + + mitk::Point3D expectedPoint; + expectedPoint[0] = 3*0.5+5; + expectedPoint[1] = 3*0.33+8; + expectedPoint[2] = 3*0.78+7; + mitk::Point3D originalPoint; + originalPoint[0] = 3; + originalPoint[1] = 3; + originalPoint[2] = 3; + mitk::Point3D worldPoint; + geometry->GetGeometryForTimeStep(DimT-1)->IndexToWorld(originalPoint, worldPoint); + MITK_TEST_CONDITION(mitk::Equal(worldPoint, expectedPoint), "Geometry transformation match expection. "); + } + + void Expand_ImageDoubleSize_SizeChanged(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + MITK_TEST_CONDITION(geometry->GetNumberOfTimeSteps()==DimT, "Number of time Steps match expection. "); + + geometry->Expand(DimT * 2); + MITK_TEST_CONDITION(geometry->GetNumberOfTimeSteps()==DimT*2, "Number of time Steps match expection. "); + + mitk::Geometry3D::Pointer geometry3D = geometry->GetGeometryForTimeStep(DimT*2 -1); + MITK_TEST_CONDITION(geometry3D.IsNotNull(), "Non-zero geometry is generated. "); + } + + void CheckBounds_Image_PointsAsExpected(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + + mitk::Point3D expectedPoint; + + expectedPoint[0] = -0.5*0.5; + expectedPoint[1] = -0.5*0.33; + expectedPoint[2] = -0.5*0.78; + mitk::Point3D point = geometry->GetCornerPointInWorld(0); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 0 as expected "); + point = geometry->GetCornerPointInWorld(true,true,true); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 0 as expected "); + + point = geometry->GetCornerPointInWorld(1); + expectedPoint[0] = -0.5*0.5; + expectedPoint[1] = -0.5*0.33; + expectedPoint[2] = 19.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "GBounding Point 1 as expected "); + point = geometry->GetCornerPointInWorld(true,true,false); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 1 as expected "); + + point = geometry->GetCornerPointInWorld(2); + expectedPoint[0] = -0.5*0.5; + expectedPoint[1] = 24.5*0.33; + expectedPoint[2] = -0.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 2 as expected "); + point = geometry->GetCornerPointInWorld(true,false,true); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 2 as expected "); + + point = geometry->GetCornerPointInWorld(3); + expectedPoint[0] = -0.5*0.5; + expectedPoint[1] = 24.5*0.33; + expectedPoint[2] = 19.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 3 as expected "); + point = geometry->GetCornerPointInWorld(true,false,false); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 3 as expected "); + + point = geometry->GetCornerPointInWorld(4); + expectedPoint[0] = 29.5*0.5; + expectedPoint[1] = -0.5*0.33; + expectedPoint[2] = -0.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 4 as expected "); + point = geometry->GetCornerPointInWorld(false,true,true); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 4 as expected "); + + point = geometry->GetCornerPointInWorld(5); + expectedPoint[0] = 29.5*0.5; + expectedPoint[1] = -0.5*0.33; + expectedPoint[2] = 19.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 5 as expected "); + point = geometry->GetCornerPointInWorld(false,true,false); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 5 as expected "); + + point = geometry->GetCornerPointInWorld(6); + expectedPoint[0] = 29.5*0.5; + expectedPoint[1] = 24.5*0.33; + expectedPoint[2] = -0.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 6 as expected "); + point = geometry->GetCornerPointInWorld(false,false,true); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 6 as expected "); + + point = geometry->GetCornerPointInWorld(7); + expectedPoint[0] = 29.5*0.5; + expectedPoint[1] = 24.5*0.33; + expectedPoint[2] = 19.5*0.78; + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 7 as expected "); + point = geometry->GetCornerPointInWorld(false,false,false); + MITK_TEST_CONDITION(mitk::Equal(expectedPoint, point), "Bounding Point 7 as expected "); + } + + void CheckLength_Image_AsExpected(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + + double dimension = geometry->GetDiagonalLengthInWorld(); + MITK_TEST_CONDITION(mitk::Equal(dimension,23.160796233014466 ), "Length as expected "); + + dimension = geometry->GetDiagonalLength2InWorld(); + MITK_TEST_CONDITION(mitk::Equal(dimension,536.42248214721712 ), "Square length as expected "); + } + + void CheckPointInside_ImagePointInside_True(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + + mitk::Point3D expectedPoint; + + expectedPoint[0] = 10; + expectedPoint[1] = 5; + expectedPoint[2] = 5; + bool isInside = geometry->IsWorldPointInside(expectedPoint); + MITK_TEST_CONDITION(isInside, "Point is inside Image..."); + } + + void CheckPointInside_ImagePointOutside_False(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + + mitk::Point3D expectedPoint; + + expectedPoint[0] = 100; + expectedPoint[1] = 500; + expectedPoint[2] = 500; + bool isInside = geometry->IsWorldPointInside(expectedPoint); + MITK_TEST_CONDITION(!isInside, "Point is outside Image..."); + } + + void CheckBounds_Image_AsSet(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + + mitk::BoundingBox::BoundsArrayType bound = geometry->GetBoundsInWorld(); + bool isEqual = true; + isEqual = isEqual && mitk::Equal(bound[0], -0.5*0.5); + isEqual = isEqual && mitk::Equal(bound[1], 29.5*0.5); + isEqual = isEqual && mitk::Equal(bound[2], -0.5*0.33); + isEqual = isEqual && mitk::Equal(bound[3], 24.5*0.33); + isEqual = isEqual && mitk::Equal(bound[4], -0.5*0.78); + isEqual = isEqual && mitk::Equal(bound[5], 19.5*0.78); + + MITK_TEST_CONDITION(isEqual, "Bounds as precalculated..."); + } + + void CheckExtent_Image_AsSet(unsigned int DimX, unsigned int DimY, unsigned int DimZ, unsigned int DimT) + { + mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage(DimX, DimY, DimZ, DimT,0.5,0.33,0.78,100); + mitk::TimeGeometry::Pointer geometry = image->GetTimeGeometry(); + + mitk::BoundingBox::BoundsArrayType bound = geometry->GetBoundsInWorld(); + bool isEqual = true; + isEqual = isEqual && mitk::Equal(geometry->GetExtentInWorld(0), 30*0.5); + isEqual = isEqual && mitk::Equal(geometry->GetExtentInWorld(1), 25*0.33); + isEqual = isEqual && mitk::Equal(geometry->GetExtentInWorld(2), 20*0.78); + + MITK_TEST_CONDITION(isEqual, "Extent as precalculated..."); + } }; int mitkTimeGeometryTest(int /*argc*/, char* /*argv*/[]) { MITK_TEST_BEGIN(mitkTimeGeometryTest); mitkTimeGeometryTestClass testClass; MITK_TEST_OUTPUT(<< "Test for 3D image"); testClass.Translation_Image_MovedOrigin(30,25,20,1); testClass.Rotate_Image_RotatedPoint(30,25,20,1); testClass.Scale_Image_ScaledPoint(30,25,20,1); testClass.GetNumberOfTimeSteps_Image_ReturnDimT(30,25,20,1); testClass.GetMinimumTimePoint_3DImage_Min(30,25,20,1); testClass.GetMaximumTimePoint_3DImage_Max(30,25,20,1); testClass.GetTimeBounds_3DImage_ZeroAndDimT(30,25,20,1); testClass.IsValidTimePoint_ImageValidTimePoint_True(30,25,20,1); testClass.IsValidTimeStep_ImageValidTimeStep_True(30,25,20,1); testClass.IsValidTimeStep_ImageNegativInvalidTimeStep_False(30,25,20,1); testClass.IsValidTimeStep_ImageInvalidTimeStep_False(30,25,20,1); testClass.TimeStepToTimePoint_ImageValidTimeStep_TimePoint(30,25,20,1); testClass.TimeStepToTimePoint_ImageInvalidTimeStep_TimePoint(30,25,20,1); testClass.TimePointToTimeStep_ImageValidTimePoint_TimePoint(30,25,20,1); testClass.GetGeometryForTimeStep_ImageValidTimeStep_CorrectGeometry(30,25,20,1); - testClass.GetGeometryForTimeStep_ImageInvalidTimeStep_CorrectGeometry(30,25,20,1); + testClass.GetGeometryForTimeStep_ImageInvalidTimeStep_NullPointer(30,25,20,1); + testClass.GetGeometryForTimePoint_ImageValidTimePoint_CorrectGeometry(30,25,20,1); + testClass.GetGeometryCloneForTimeStep_ImageValidTimeStep_CorrectGeometry(30,25,20,1); + testClass.GetGeometryCloneForTimeStep_ImageInvalidTimeStep_NullPointer(30,25,20,1); + testClass.SetTimeStepGeometry_ImageValidTimeStep_CorrectGeometry(30,25,20,1); + testClass.Expand_ImageDoubleSize_SizeChanged(30,25,20,1); + testClass.CheckBounds_Image_PointsAsExpected(30,25,20,1); + testClass.CheckLength_Image_AsExpected(30,25,20,1); + testClass.CheckPointInside_ImagePointInside_True(30,25,20,1); + testClass.CheckPointInside_ImagePointOutside_False(30,25,20,1); + testClass.CheckBounds_Image_AsSet(30,25,20,1); + testClass.CheckExtent_Image_AsSet(30,25,20,1); /* MITK_TEST_OUTPUT(<< "Test for 2D image"); testClass.Translation_Image_MovedOrigin(30,25,1 ,1); // Test with 2D-Image testClass.Rotate_Image_RotatedPoint(30,25,1 ,1); // Test with 2D-Image testClass.Scale_Image_ScaledPoint(30,25,1 ,1); // Test with 2D-Image */ MITK_TEST_OUTPUT(<< "Test for 3D+time image"); testClass.Translation_Image_MovedOrigin(30,25,20,5); // Test with 3D+t-Image testClass.Rotate_Image_RotatedPoint(30,25,20,5); // Test with 3D+t-Image testClass.Scale_Image_ScaledPoint(30,25,20,5); // Test with 3D+t-Image testClass.GetNumberOfTimeSteps_Image_ReturnDimT(30,25,20,5); testClass.GetMinimumTimePoint_4DImage_Zero(30,25,20,5); testClass.GetMaximumTimePoint_4DImage_DimT(30,25,20,5); testClass.GetTimeBounds_4DImage_ZeroAndDimT(30,25,20,5); testClass.IsValidTimePoint_ImageValidTimePoint_True(30,25,20,5); testClass.IsValidTimePoint_ImageNegativInvalidTimePoint_False(30,25,20,5); testClass.IsValidTimePoint_ImageInvalidTimePoint_False(30,25,20,5); testClass.IsValidTimeStep_ImageValidTimeStep_True(30,25,20,5); testClass.IsValidTimeStep_ImageNegativInvalidTimeStep_False(30,25,20,5); testClass.IsValidTimeStep_ImageInvalidTimeStep_False(30,25,20,5); testClass.TimeStepToTimePoint_ImageValidTimeStep_TimePoint(30,25,20,5); testClass.TimeStepToTimePoint_ImageInvalidTimeStep_TimePoint(30,25,20,5); testClass.TimePointToTimeStep_ImageValidTimePoint_TimePoint(30,25,20,5); testClass.TimePointToTimeStep_4DImageInvalidTimePoint_TimePoint(30,25,20,5); testClass.TimePointToTimeStep_4DImageNegativInvalidTimePoint_TimePoint(30,25,20,5); testClass.GetGeometryForTimeStep_ImageValidTimeStep_CorrectGeometry(30,25,20,5); - testClass.GetGeometryForTimeStep_ImageInvalidTimeStep_CorrectGeometry(30,25,20,5); + testClass.GetGeometryForTimeStep_ImageInvalidTimeStep_NullPointer(30,25,20,5); + testClass.GetGeometryForTimePoint_ImageValidTimePoint_CorrectGeometry(30,25,20,5); + testClass.GetGeometryForTimePoint_4DImageInvalidTimePoint_NullPointer(30,25,20,5); + testClass.GetGeometryForTimePoint_4DImageNEgativInvalidTimePoint_NullPointer(30,25,20,5); + testClass.GetGeometryCloneForTimeStep_ImageValidTimeStep_CorrectGeometry(30,25,20,5); + testClass.GetGeometryCloneForTimeStep_ImageInvalidTimeStep_NullPointer(30,25,20,5); + testClass.SetTimeStepGeometry_ImageValidTimeStep_CorrectGeometry(30,25,20,5); + testClass.Expand_ImageDoubleSize_SizeChanged(30,25,20,5); + testClass.CheckBounds_Image_PointsAsExpected(30,25,20,5); + testClass.CheckLength_Image_AsExpected(30,25,20,5); + testClass.CheckPointInside_ImagePointInside_True(30,25,20,5); + testClass.CheckPointInside_ImagePointOutside_False(30,25,20,5); + testClass.CheckBounds_Image_AsSet(30,25,20,5); + testClass.CheckExtent_Image_AsSet(30,25,20,5); /* MITK_TEST_OUTPUT(<< "Test for 2D+time image"); testClass.Translation_Image_MovedOrigin(30,25,1 ,5); // Test with 2D+t-Image testClass.Rotate_Image_RotatedPoint(30,25,1 ,5); // Test with 2D+t-Image testClass.Scale_Image_ScaledPoint(30,25,1 ,5); // Test with 2D+t-Image */ MITK_TEST_END(); return EXIT_SUCCESS; } diff --git a/Modules/MitkExt/DataManagement/mitkCone.cpp b/Modules/MitkExt/DataManagement/mitkCone.cpp index 4e3081b609..e9831614ef 100644 --- a/Modules/MitkExt/DataManagement/mitkCone.cpp +++ b/Modules/MitkExt/DataManagement/mitkCone.cpp @@ -1,65 +1,65 @@ /*=================================================================== 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 "mitkCone.h" #include "vtkLinearTransform.h" #include "mitkVector.h" #include "vtkConeSource.h" mitk::Cone::Cone() : BoundingObject() { // Set up Cone Surface. Radius 1.0, height 2.0, , centered around the origin vtkConeSource* cone = vtkConeSource::New(); cone->SetRadius(1.0); cone->SetHeight(2.0); cone->SetDirection(0.0, -1.0, 0.0); cone->SetCenter(0.0, 0.0, 0.0); cone->SetResolution(20); cone->CappingOn(); cone->Update(); SetVtkPolyData(cone->GetOutput()); cone->Delete(); } mitk::Cone::~Cone() { } bool mitk::Cone::IsInside(const Point3D& worldPoint) const { // transform point from world to object coordinates ScalarType p[4]; p[0] = worldPoint[0]; p[1] = worldPoint[1]; p[2] = worldPoint[2]; p[3] = 1; GetGeometry()->GetVtkTransform()->GetInverse()->TransformPoint(p, p); p[1] += 1; // translate point, so that it fits to the formula below, which describes a cone that has its cone vertex at the origin return (sqrt(p[0] * p[0] + p[2] * p[2]) <= p[1] * 0.5) && (p[1] <= 2); // formula to calculate if a given point is inside a cone that has its cone vertex at the origin, is aligned on the second axis, has a radius of one an a height of two } mitk::ScalarType mitk::Cone::GetVolume() { TimeGeometry* geometry = GetTimeGeometry(); - return geometry->GetExtendInWorld(0) * 0.5 - * geometry->GetExtendInWorld(2) * 0.5 + return geometry->GetExtentInWorld(0) * 0.5 + * geometry->GetExtentInWorld(2) * 0.5 * vnl_math::pi / 3.0 - * geometry->GetExtendInWorld(1); + * geometry->GetExtentInWorld(1); } diff --git a/Modules/MitkExt/DataManagement/mitkCuboid.cpp b/Modules/MitkExt/DataManagement/mitkCuboid.cpp index ffbc76e3eb..4ba86b8101 100644 --- a/Modules/MitkExt/DataManagement/mitkCuboid.cpp +++ b/Modules/MitkExt/DataManagement/mitkCuboid.cpp @@ -1,64 +1,64 @@ /*=================================================================== 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 "mitkCuboid.h" #include "vtkLinearTransform.h" #include "mitkVector.h" #include "vtkCubeSource.h" #include mitk::Cuboid::Cuboid() : BoundingObject() { vtkCubeSource* cube = vtkCubeSource::New(); cube->SetXLength(2.0); cube->SetYLength(2.0); cube->SetZLength(2.0); cube->Update(); SetVtkPolyData(cube->GetOutput()); cube->Delete(); } mitk::Cuboid::~Cuboid() { } bool mitk::Cuboid::IsInside(const Point3D& worldPoint) const { // transform point from world to object coordinates ScalarType p[4]; p[0] = worldPoint[0]; p[1] = worldPoint[1]; p[2] = worldPoint[2]; p[3] = 1; GetGeometry()->GetVtkTransform()->GetInverse()->TransformPoint(p, p); return (p[0] >= -1) && (p[0] <= 1) && (p[1] >= -1) && (p[1] <= 1) && (p[2] >= -1) && (p[2] <= 1); } mitk::ScalarType mitk::Cuboid::GetVolume() { TimeGeometry* geometry = GetTimeGeometry(); - return geometry->GetExtendInWorld(0) - * geometry->GetExtendInWorld(1) - * geometry->GetExtendInWorld(2); + return geometry->GetExtentInWorld(0) + * geometry->GetExtentInWorld(1) + * geometry->GetExtentInWorld(2); } diff --git a/Modules/MitkExt/DataManagement/mitkCylinder.cpp b/Modules/MitkExt/DataManagement/mitkCylinder.cpp index 3809d10028..454869e2f2 100644 --- a/Modules/MitkExt/DataManagement/mitkCylinder.cpp +++ b/Modules/MitkExt/DataManagement/mitkCylinder.cpp @@ -1,68 +1,68 @@ /*=================================================================== 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 "mitkCylinder.h" #include "vtkLinearTransform.h" #include "mitkVector.h" #include "vtkCylinderSource.h" mitk::Cylinder::Cylinder() : BoundingObject() { vtkCylinderSource* cylinder = vtkCylinderSource::New(); cylinder->SetRadius(1.0); cylinder->SetHeight(2.0); cylinder->SetCenter(0.0, 0.0, 0.0); cylinder->SetResolution(100); cylinder->CappingOn(); cylinder->Update(); SetVtkPolyData(cylinder->GetOutput()); cylinder->Delete(); } mitk::Cylinder::~Cylinder() { } bool mitk::Cylinder::IsInside(const Point3D& worldPoint) const { // transform point from world to object coordinates ScalarType p[4]; p[0] = worldPoint[0]; p[1] = worldPoint[1]; p[2] = worldPoint[2]; p[3] = 1; GetGeometry()->GetVtkTransform()->GetInverse()->TransformPoint(p, p); mitk::ScalarType v = pow(p[0], 2) + pow(p[2], 2); bool retval = (v <= 1) && (p[1] >= -1) && (p[1] <= 1); return retval; } mitk::ScalarType mitk::Cylinder::GetVolume() { TimeGeometry* geometry = GetTimeGeometry(); - return geometry->GetExtendInWorld(0) * 0.5 - * geometry->GetExtendInWorld(2) * 0.5 + return geometry->GetExtentInWorld(0) * 0.5 + * geometry->GetExtentInWorld(2) * 0.5 * vnl_math::pi - * geometry->GetExtendInWorld(1); + * geometry->GetExtentInWorld(1); }