Hi,<div><br></div><div>I have found a numerical precision problem with the method vtkCellLocator::IntersectWithLine.</div><div><div><br></div><div>in line 287 of revision 1.89:</div><div>  if (cell-&gt;IntersectWithLine(a0, a1, tol, t, x, pcoords, subId) )</div>
<div>    {</div><div>    if ( ! this-&gt;IsInOctantBounds(x) ) </div><div><br></div></div><div>sometimes the resulting intersection point returned by the cell-&gt;IntersectWithLine is a (0.000000000000004) little out of the bounds and the call to IsInOctantBounds discard the point :(</div>
<div><br></div><div>following is an example that illustrates that.</div><div>a vtkCellLocator is filled with a cube and a line going from dPoint to dPoint2 intersect the box.</div><div>in Z axis, the bounds of the box are (1.0; -20)</div>
<div><br></div><div>if dPoint2[2] = -77.76333863288239, the resulting intersection point is at -20 and all is correct</div><div>if dPoint2[2] = -77.76333863288238, the resulting intersection point is at -20.000000000000004, so out of bounds.</div>
<div><br></div><div><br></div><div>So will it be a good thing to add a tolerance to the method vtkCellLocator::IsInOctantBounds(double x[3]) ?</div><div><div><br></div></div><div><br></div><div><br></div><div><div>#include &lt;vtk/vtkActor.h&gt;</div>
<div>#include &lt;vtk/vtkCamera.h&gt;</div><div>#include &lt;vtk/vtkCellLocator.h&gt;</div><div>#include &lt;vtk/vtkCubeSource.h&gt;</div><div>#include &lt;vtk/vtkGenericCell.h&gt;</div><div>#include &lt;vtk/vtkInteractorStyleTrackballCamera.h&gt;</div>
<div>#include &lt;vtk/vtkLineSource.h&gt;</div><div>#include &lt;vtk/vtkPolyData.h&gt;</div><div>#include &lt;vtk/vtkPolyDataMapper.h&gt;</div><div>#include &lt;vtk/vtkProperty.h&gt;</div><div>#include &lt;vtk/vtkRenderer.h&gt;</div>
<div>#include &lt;vtk/vtkRenderWindow.h&gt;</div><div>#include &lt;vtk/vtkRenderWindowInteractor.h&gt;</div><div>#include &lt;vtk/vtkSmartPointer.h&gt;</div><div>#include &lt;vtk/vtkSphereSource.h&gt;</div><div>#include &lt;vtk/vtkSTLReader.h&gt;</div>
<div>#include &lt;vtk/vtkTriangleFilter.h&gt;</div><div><br></div><div>#define MY_SP(class, variable)\</div><div>   vtkSmartPointer&lt;class&gt; variable = vtkSmartPointer&lt;class&gt;::New();</div><div><br></div><div>double dPoint[3] = {</div>
<div>   19.277858734130859,</div><div>   23.247093200683594,</div><div>   -0.45018148422241211</div><div>};</div><div><br></div><div>double dPoint2[3] = {</div><div>   19.277858734130859,</div><div>   23.247093200683594,</div>
<div>   // error</div><div>   -77.76333863288238</div><div>   // ok</div><div>   //-77.76333863288239</div><div>};</div><div><br></div><div>//---------------------------------------------------------------------------------------------</div>
<div>void Test(vtkPolyData *data, double sourcePnt[3], double destinPnt[3])</div><div>{</div><div>   MY_SP(vtkCellLocator, loc);</div><div>   loc-&gt;SetTolerance(0.0);</div><div>   loc-&gt;FreeSearchStructure();</div><div>
   loc-&gt;CacheCellBoundsOn();</div><div>   loc-&gt;AutomaticOn();</div><div>   loc-&gt;SetDataSet(data);</div><div>   loc-&gt;BuildLocator();</div><div>   loc-&gt;Update();</div><div><br></div><div>   vtkIdType cellId;</div>
<div>   int subId;</div><div>   double param_t, intersect[3], paraCoord[3];</div><div>   vtkGenericCell *cell = vtkGenericCell::New();</div><div><br></div><div>   if(! loc-&gt;IntersectWithLine(sourcePnt, destinPnt, 0.0010, param_t, </div>
<div>      intersect, paraCoord, subId, cellId, cell) )</div><div>   {</div><div>      cout &lt;&lt; &quot;error&quot; &lt;&lt; endl;</div><div>   }</div><div><br></div><div>   cout &lt;&lt; &quot;intersection point: &quot; &lt;&lt; intersect[0] &lt;&lt; &quot; &quot; &lt;&lt; intersect[1] &lt;&lt; &quot; &quot; &lt;&lt; intersect[2] &lt;&lt; endl;</div>
<div><br></div><div>   cell-&gt;Delete();</div><div>}</div><div><br></div><div>//---------------------------------------------------------------------------------------------</div><div>int main(int , char* [])</div><div>{</div>
<div>   MY_SP(vtkRenderer, ren1);</div><div>   ren1-&gt;SetBackground(0.2, 0.2, 0.2);</div><div>   MY_SP(vtkRenderWindow, renWin);</div><div>   renWin-&gt;SetSize( 800, 800 );</div><div>   renWin-&gt;AddRenderer(ren1);</div>
<div>   MY_SP(vtkRenderWindowInteractor, iren);</div><div>   iren-&gt;SetRenderWindow(renWin);</div><div><br></div><div>   MY_SP(vtkInteractorStyleTrackballCamera, vtk_style);</div><div>   iren-&gt;SetInteractorStyle(vtk_style);</div>
<div><br></div><div>   /////</div><div>   MY_SP(vtkCubeSource, cube);</div><div>   cube-&gt;SetBounds(-43.5, 43.5, -35.0, 35.0, -20.0, 1.0);</div><div><br></div><div>   MY_SP(vtkTriangleFilter, tri);</div><div>   tri-&gt;SetInputConnection(cube-&gt;GetOutputPort());</div>
<div>   tri-&gt;Update();</div><div><br></div><div>   MY_SP(vtkPolyDataMapper, Mapper);</div><div>   Mapper-&gt;SetInputConnection(tri-&gt;GetOutputPort());</div><div>   Mapper-&gt;ImmediateModeRenderingOn();</div><div><br>
</div><div>   MY_SP(vtkActor, Actor);</div><div>   Actor-&gt;SetMapper(Mapper);</div><div>   Actor-&gt;GetProperty()-&gt;SetRepresentationToWireframe();</div><div><br></div><div>   ren1-&gt;AddActor(Actor);</div><div><br>
</div><div>   //////</div><div>   MY_SP(vtkSphereSource, sph);</div><div>   sph-&gt;SetCenter(dPoint);</div><div>   sph-&gt;SetRadius(1);</div><div>   MY_SP(vtkPolyDataMapper, MapperSph);</div><div>   MapperSph-&gt;SetInputConnection(sph-&gt;GetOutputPort());</div>
<div>   MapperSph-&gt;ImmediateModeRenderingOn();</div><div><br></div><div>   MY_SP(vtkActor, ActorSph);</div><div>   ActorSph-&gt;SetMapper(MapperSph);</div><div>   ActorSph-&gt;GetProperty()-&gt;SetColor(1.0, 0.0, 0.0);</div>
<div>   ren1-&gt;AddActor(ActorSph);</div><div><br></div><div>   MY_SP(vtkSphereSource, sph2);</div><div>   sph2-&gt;SetCenter(dPoint2);</div><div>   sph2-&gt;SetRadius(1);</div><div>   MY_SP(vtkPolyDataMapper, MapperSph2);</div>
<div>   MapperSph2-&gt;SetInputConnection(sph2-&gt;GetOutputPort());</div><div>   MapperSph2-&gt;ImmediateModeRenderingOn();</div><div><br></div><div>   MY_SP(vtkActor, ActorSph2);</div><div>   ActorSph2-&gt;SetMapper(MapperSph2);</div>
<div>   ActorSph2-&gt;GetProperty()-&gt;SetColor(0.0, 0.0, 1.0);</div><div>   ren1-&gt;AddActor(ActorSph2);</div><div><br></div><div>   MY_SP(vtkLineSource, line);</div><div>   line-&gt;SetPoint1(dPoint);</div><div>   line-&gt;SetPoint2(dPoint2);</div>
<div>   MY_SP(vtkPolyDataMapper, Mapperline);</div><div>   Mapperline-&gt;SetInputConnection(line-&gt;GetOutputPort());</div><div>   Mapperline-&gt;ImmediateModeRenderingOn();</div><div><br></div><div>   MY_SP(vtkActor, Actorline);</div>
<div>   Actorline-&gt;SetMapper(Mapperline);</div><div>   Actorline-&gt;GetProperty()-&gt;SetColor(0.0, 1.0, 0.0);</div><div>   ren1-&gt;AddActor(Actorline);</div><div><br></div><div>   Test(cube-&gt;GetOutput(), dPoint, dPoint2);</div>
<div><br></div><div>   ren1-&gt;ResetCamera();</div><div>   renWin-&gt;Render();</div><div>   iren-&gt;Start();</div><div><br></div><div>   ren1 = 0;</div><div><br></div><div>   return 0;</div><div>}</div><div>//---------------------------------------------------------------------------------------------</div>
<div><br></div></div>