From 4b312af1f601b12fe6e43db4d25dc316231f681f Mon Sep 17 00:00:00 2001 From: Danial Saruji Date: Wed, 5 Oct 2011 09:23:58 +0200 Subject: [PATCH] enhanced clippedsurfaceboundscalculator so that the intersection points of 2 Geometry3D can be determined --- .../mitkClippedSurfaceBoundsCalculator.cpp | 71 +++++++++++++++++-- .../mitkClippedSurfaceBoundsCalculator.h | 5 ++ 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp b/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp index 7f1aebe..a60674f 100644 --- a/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp +++ b/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp @@ -5,7 +5,10 @@ mitk::ClippedSurfaceBoundsCalculator::ClippedSurfaceBoundsCalculator( const mitk::PlaneGeometry* geometry, - mitk::Image::Pointer image) + mitk::Image::Pointer image): + m_PlaneGeometry(NULL), + m_Geometry3D(NULL), + m_Image(NULL) { // initialize with meaningless slice indices m_MinMaxOutput.clear(); @@ -20,6 +23,26 @@ mitk::ClippedSurfaceBoundsCalculator::ClippedSurfaceBoundsCalculator( this->SetInput(geometry, image); } +mitk::ClippedSurfaceBoundsCalculator::ClippedSurfaceBoundsCalculator( + const mitk::Geometry3D* geometry, + mitk::Image::Pointer image): + m_PlaneGeometry(NULL), + m_Geometry3D(NULL), + m_Image(NULL) +{ + // initialize with meaningless slice indices + m_MinMaxOutput.clear(); + for(int i = 0; i < 3; i++) + { + m_MinMaxOutput.push_back( + OutputType( std::numeric_limits::max() , + std::numeric_limits::min() )); + } + + + this->SetInput(geometry, image); +} + mitk::ClippedSurfaceBoundsCalculator::~ClippedSurfaceBoundsCalculator() { } @@ -33,6 +56,20 @@ mitk::ClippedSurfaceBoundsCalculator::SetInput( { this->m_PlaneGeometry = geometry; this->m_Image = image; + this->m_Geometry3D = NULL; //Not possible to set both + } +} + +void +mitk::ClippedSurfaceBoundsCalculator::SetInput( + const mitk::Geometry3D* geometry, + mitk::Image* image) +{ + if(geometry && image) + { + this->m_Geometry3D = geometry; + this->m_Image = image; + this->m_PlaneGeometry = NULL; //Not possible to set both } } @@ -56,16 +93,34 @@ mitk::ClippedSurfaceBoundsCalculator::GetMinMaxSpatialDirectionZ() void mitk::ClippedSurfaceBoundsCalculator::Update() { - // SEE HEADER DOCUMENTATION for explanation - - typedef std::vector< std::pair > EdgesVector; - this->m_MinMaxOutput.clear(); for(int i = 0; i < 3; i++) { this->m_MinMaxOutput.push_back(OutputType( std::numeric_limits::max() , std::numeric_limits::min() )); } + if(m_PlaneGeometry.IsNotNull()) + { + this->CalculateIntersectionPoints(m_PlaneGeometry); + } + else if(m_Geometry3D.IsNotNull()) + { + // go through all slices of the image, ... + const mitk::SlicedGeometry3D* slicedGeometry3D = dynamic_cast( m_Geometry3D.GetPointer() ); + int allSlices = slicedGeometry3D->GetSlices(); + for ( int slice=0; sliceCalculateIntersectionPoints(dynamic_cast(slicedGeometry3D->GetGeometry2D(slice))); + } + } +} + +void mitk::ClippedSurfaceBoundsCalculator::CalculateIntersectionPoints(const mitk::PlaneGeometry* geometry) +{ + // SEE HEADER DOCUMENTATION for explanation + + typedef std::vector< std::pair > EdgesVector; + Point3D origin; Vector3D xDirection, yDirection, zDirection; const Vector3D spacing = m_Image->GetGeometry()->GetSpacing(); @@ -181,7 +236,7 @@ void mitk::ClippedSurfaceBoundsCalculator::Update() bool isIntersectionPointOnLine; Vector3D lineVector = line.GetPoint1() - line.GetPoint2(); if(lineVector[0] == 0 && lineVector[1] == 0 && lineVector[2] == 0 - && m_PlaneGeometry->IsOnPlane(line.GetPoint1())) + && geometry->IsOnPlane(line.GetPoint1())) { t = 1.0; isIntersectionPointOnLine = true; @@ -189,8 +244,8 @@ void mitk::ClippedSurfaceBoundsCalculator::Update() } else { - m_PlaneGeometry->IntersectionPoint(line, intersectionWorldPoint); - isIntersectionPointOnLine = m_PlaneGeometry->IntersectionPointParam(line, t); + geometry->IntersectionPoint(line, intersectionWorldPoint); + isIntersectionPointOnLine = geometry->IntersectionPointParam(line, t); } mitk::Point3D intersectionIndexPoint; diff --git a/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.h b/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.h index 89201b1..b5eca2a 100644 --- a/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.h +++ b/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.h @@ -50,10 +50,13 @@ class MITK_CORE_EXPORT ClippedSurfaceBoundsCalculator ClippedSurfaceBoundsCalculator(const mitk::PlaneGeometry* geometry = NULL, mitk::Image::Pointer image = NULL); + ClippedSurfaceBoundsCalculator(const mitk::Geometry3D* geometry, + mitk::Image::Pointer image); virtual ~ClippedSurfaceBoundsCalculator(); void SetInput(const mitk::PlaneGeometry* geometry, mitk::Image* image); + void SetInput(const mitk::Geometry3D *geometry, mitk::Image *image); /** \brief Request calculation. @@ -89,8 +92,10 @@ class MITK_CORE_EXPORT ClippedSurfaceBoundsCalculator OutputType GetMinMaxSpatialDirectionZ(); protected: + void CalculateIntersectionPoints(const mitk::PlaneGeometry* geometry); mitk::PlaneGeometry::ConstPointer m_PlaneGeometry; + mitk::Geometry3D::ConstPointer m_Geometry3D; mitk::Image::Pointer m_Image; std::vector< OutputType > m_MinMaxOutput; -- 1.7.0.4