Hi guys,

first, a simple one. The new crosshair rendering mechanism didn't work correctly for me when I added the geometry for the small reslice rendering window (going along the vessel path). At first it crashed and after I fixed that - I noticed that the computation results are incorrect in some cases.

I have changed the code to used boost::icl and corrected the intersection rejection approach. Now it works correctly, however if you want to leave boost as an optional dependency, some other interval arithmetic library or own implementation could be used.

Bug:
Patch attached.

Rostislav.
>From 0c83dd214e7211782917bd1caed232af53094499 Mon Sep 17 00:00:00 2001
From: Rostislav Khlebnikov <[email protected]>
Date: Mon, 10 Aug 2015 18:18:58 +0100
Subject: [PATCH] Plane geometry data mapper crash and correctness fix

---
 .../Rendering/mitkPlaneGeometryDataMapper2D.cpp    | 52 +++++++++++-----------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/Modules/Core/src/Rendering/mitkPlaneGeometryDataMapper2D.cpp 
b/Modules/Core/src/Rendering/mitkPlaneGeometryDataMapper2D.cpp
index 47e5192..3b8c128 100644
--- a/Modules/Core/src/Rendering/mitkPlaneGeometryDataMapper2D.cpp
+++ b/Modules/Core/src/Rendering/mitkPlaneGeometryDataMapper2D.cpp
@@ -40,6 +40,10 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include <vtkPolyData.h>
 #include <vtkPolyDataMapper2D.h>
 
+#include <boost/icl/interval.hpp>
+#include <boost/icl/interval_set.hpp>
+
+
 mitk::PlaneGeometryDataMapper2D::AllInstancesContainer 
mitk::PlaneGeometryDataMapper2D::s_AllInstances;
 
 // input for this mapper ( = PlaneGeometryData)
@@ -178,12 +182,16 @@ void 
mitk::PlaneGeometryDataMapper2D::CreateVtkCrosshair(mitk::BaseRenderer *ren
 
       // Then, clip this line with the (transformed) bounding box of the
       // reference geometry.
-      Line3D::BoxLineIntersection(
+      int nIntersections = Line3D::BoxLineIntersection(
             boundingBoxMin[0], boundingBoxMin[1], boundingBoxMin[2],
           boundingBoxMax[0], boundingBoxMax[1], boundingBoxMax[2],
           indexLinePoint, indexLineDirection,
           point1, point2 );
 
+      if (nIntersections < 2) {
+        return;
+      }
+
       referenceGeometry->IndexToWorld(point1,point1);
       referenceGeometry->IndexToWorld(point2,point2);
       crossLine.SetPoints(point1,point2);
@@ -200,14 +208,13 @@ void 
mitk::PlaneGeometryDataMapper2D::CreateVtkCrosshair(mitk::BaseRenderer *ren
       NodesVectorType::iterator otherPlanesIt = m_OtherPlaneGeometries.begin();
       NodesVectorType::iterator otherPlanesEnd = m_OtherPlaneGeometries.end();
 
-      std::vector<Point3D> intersections;
-
-      intersections.push_back(point1);
-
       otherPlanesIt = m_OtherPlaneGeometries.begin();
       int gapsize = 32;
-      this->GetDataNode()->GetPropertyValue( "Crosshair.Gap Size",gapsize, 
NULL );
+      this->GetDataNode()->GetPropertyValue("Crosshair.Gap Size", gapsize, 
NULL);
+
 
+      boost::icl::interval_set<double> intervals;
+      intervals += boost::icl::interval<double>::closed(0, 1);
 
       ScalarType lineLength = point1.EuclideanDistanceTo(point2);
       DisplayGeometry *displayGeometry = renderer->GetDisplayGeometry();
@@ -218,35 +225,30 @@ void 
mitk::PlaneGeometryDataMapper2D::CreateVtkCrosshair(mitk::BaseRenderer *ren
 
       while ( otherPlanesIt != otherPlanesEnd )
       {
+        bool ignorePlane = false;
+        (*otherPlanesIt)->GetPropertyValue("Crosshair.Ignore", ignorePlane);
+        if (ignorePlane) 
+        {
+            ++otherPlanesIt;
+            continue;
+        }
+
         PlaneGeometry *otherPlane = static_cast< PlaneGeometry * >(
               static_cast< PlaneGeometryData * >((*otherPlanesIt)->GetData() 
)->GetPlaneGeometry() );
 
         if (otherPlane != inputPlaneGeometry && otherPlane != 
worldPlaneGeometry)
         {
-          Point3D planeIntersection;
-          otherPlane->IntersectionPoint(crossLine,planeIntersection);
-          ScalarType sectionLength = 
point1.EuclideanDistanceTo(planeIntersection);
-          ScalarType lineValue = sectionLength/lineLength;
-          if(lineValue-gapSizeParam > 0.0)
-            
intersections.push_back(crossLine.GetPoint(lineValue-gapSizeParam));
-          else intersections.pop_back();
-          if(lineValue+gapSizeParam < 1.0)
-            
intersections.push_back(crossLine.GetPoint(lineValue+gapSizeParam));
+            double intersectionParam;
+            if (otherPlane->IntersectionPointParam(crossLine, 
intersectionParam) && intersectionParam > 0 && intersectionParam < 1) {
+                intervals -= 
boost::icl::interval<double>::open(intersectionParam - gapSizeParam, 
intersectionParam + gapSizeParam);
+          }
         }
         ++otherPlanesIt;
       }
-      if(intersections.size()%2 == 1)
-        intersections.push_back(point2);
 
-      if(intersections.empty())
-      {
-        this->DrawLine(point1,point2,lines,points);
+      for (const auto& interval : intervals) {
+          this->DrawLine(crossLine.GetPoint(interval.lower()), 
crossLine.GetPoint(interval.upper()), lines, points);
       }
-      else
-        for(unsigned int i = 0 ; i< intersections.size()-1 ; i+=2)
-        {
-          this->DrawLine(intersections[i],intersections[i+1],lines,points);
-        }
 
       // Add the points to the dataset
       linesPolyData->SetPoints(points);
-- 
1.8.4.msysgit.0

------------------------------------------------------------------------------
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to