From 6ca0d8f9e877c42e1a64c83101cfe58fe4847bcc Mon Sep 17 00:00:00 2001 From: Danial Saruji Date: Fri, 7 Oct 2011 09:07:57 +0200 Subject: [PATCH] changed range of value t (which is used to determine whether the line segment intersects with the plane) --- .../mitkClippedSurfaceBoundsCalculator.cpp | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp b/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp index f4c309a..445bb31 100644 --- a/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp +++ b/Core/Code/Algorithms/mitkClippedSurfaceBoundsCalculator.cpp @@ -1,7 +1,7 @@ #include "mitkClippedSurfaceBoundsCalculator.h" #include "mitkLine.h" -#define ROUND_P(x) ((int)((x)+0.5)) +#define ROUND_P(x) ((x)>=0?(int)((x)+0.5):(int)((x)-0.5)) mitk::ClippedSurfaceBoundsCalculator::ClippedSurfaceBoundsCalculator( const mitk::PlaneGeometry* geometry, @@ -231,26 +231,25 @@ void mitk::ClippedSurfaceBoundsCalculator::CalculateIntersectionPoints(const mit // Get intersection point of line and plane geometry double t = -1.0; - bool isIntersectionPointOnLine; - Vector3D lineVector = line.GetPoint1() - line.GetPoint2(); - if(lineVector[0] == 0 && lineVector[1] == 0 && lineVector[2] == 0 - && geometry->IsOnPlane(line.GetPoint1())) + bool doesLineIntersectWithPlane(false); + + if(line.GetDirection().GetNorm() < mitk::eps && geometry->Distance(line.GetPoint1()) < mitk::sqrteps) { t = 1.0; - isIntersectionPointOnLine = true; + doesLineIntersectWithPlane = true; intersectionWorldPoint = line.GetPoint1(); } else { geometry->IntersectionPoint(line, intersectionWorldPoint); - isIntersectionPointOnLine = geometry->IntersectionPointParam(line, t); + doesLineIntersectWithPlane = geometry->IntersectionPointParam(line, t); } mitk::Point3D intersectionIndexPoint; //Get index point m_Image->GetGeometry()->WorldToIndex(intersectionWorldPoint, intersectionIndexPoint); - if(0.0 <= t && t <= 1.0 && isIntersectionPointOnLine) + if ( doesLineIntersectWithPlane && -mitk::sqrteps <= t && t <= 1.0 + mitk::sqrteps ) { for(int dim = 0; dim < 3; dim++) { -- 1.7.0.4