MantisBT - VTK
View Issue Details
0013714VTK(No Category)public2012-12-07 16:292014-10-02 16:54
David Doria 
Andy Bauer 
normalminorhave not tried
closedfixed 
 
6.2.0 
TBD
incorrect functionality
0013714: vtkModifiedBSPTree IntersectWithLine does not work when VTK built in RELEASE mode
The vtkModifiedBSPTree IntersectWithLine works if VTK is built in DEBUG mode, but not RELEASE mode. I have attached a screenshot of the scenario to show that the line clearly intersects the object. The demo code is:

#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkCellArray.h>
#include <vtkMath.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkModifiedBSPTree.h>

#include <fstream>
#include <limits>
#include <sstream>

int main(int, char *[])
{
  // Read the scene geometry
  vtkSmartPointer<vtkXMLPolyDataReader> reader =
      vtkSmartPointer<vtkXMLPolyDataReader>::New();
  reader->SetFileName("corner.vtp");
  reader->Update();

  double p0[3] = {0, 0, 0};
  double p1[3] = {22.2073, -15.8678, -96.2032};

  vtkSmartPointer<vtkModifiedBSPTree> tree =
      vtkSmartPointer<vtkModifiedBSPTree>::New();
  tree->SetDataSet(reader->GetOutput());
  tree->BuildLocator();

  float tolerance = .001;

  double t;
  double x[3];
  double pcoords[3];
  int subId = 0;
  vtkIdType cellId = 0;

  std::cout << "Casting ray between " << p0[0] << " " << p0[1] << " " << p0[2]
              << " and " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl;
  // Perform the intersection using the tree
  int treeHit = tree->IntersectWithLine(p0, p1, tolerance, t, x, pcoords, subId, cellId);
  std::cout << "tree hit? " << treeHit << std::endl;

  if(treeHit)
  {
    std::cout << "tree intersection " << x[0] << " " << x[1] << " " << x[2] << std::endl;
  }

  // Do the intersection manually (not using the tree)
  unsigned int numberOfManualHits = 0;

  bool manualHit = false;

  for(vtkIdType cellIndex = 0; cellIndex < reader->GetOutput()->GetNumberOfCells(); ++cellIndex)
  {
    vtkIdType intersect = reader->GetOutput()->GetCell(cellIndex)->IntersectWithLine(p0, p1, tolerance, t, x, pcoords, cellId);
    if(intersect)
    {
      manualHit = true;
      break;
    }
  }

  if(manualHit)
  {
    std::cout << "manual intersection " << x[0] << " " << x[1] << " " << x[2] << std::endl;
    numberOfManualHits++;
  }
  std::cout << "manual hit? " << manualHit << std::endl;

  return EXIT_SUCCESS;
}

The output when VTK was built in DEBUG mode is (correctly):

Casting ray between 0 0 0 and 22.2073 -15.8678 -96.2032
tree hit? 1
tree intersection 0.279686 -0.199844 -1.21162
manual intersection 0.279686 -0.199844 -1.21162
manual hit? 1

However, the output when VTK was built in RELEASE mode is (incorrectly):

Casting ray between 0 0 0 and 22.2073 -15.8678 -96.2032
tree hit? 0
manual intersection 0.279686 -0.199844 -1.21162
manual hit? 1

We see here that the tree indicates that there was no intersection, when there should have been one.
No tags attached.
gz demo.tar.gz (7,260) 2012-12-07 16:29
https://www.vtk.org/Bug/file/9364/demo.tar.gz
Issue History
2012-12-07 16:29David DoriaNew Issue
2012-12-07 16:29David DoriaFile Added: demo.tar.gz
2012-12-07 17:12David DoriaNote Added: 0029857
2012-12-08 09:23David DoriaNote Added: 0029858
2012-12-09 08:09David DoriaNote Added: 0029859
2012-12-09 08:15David DoriaNote Added: 0029860
2012-12-09 10:36David DoriaNote Added: 0029861
2014-10-02 16:14Andy BauerAssigned To => Andy Bauer
2014-10-02 16:54Andy BauerNote Added: 0033544
2014-10-02 16:54Andy BauerStatusbacklog => closed
2014-10-02 16:54Andy BauerResolutionopen => fixed
2014-10-02 16:54Andy BauerFixed in Version => 6.2.0

Notes
(0029857)
David Doria   
2012-12-07 17:12   
It also does not work when VTK is built in RelWithDebInfo mode.
(0029858)
David Doria   
2012-12-08 09:23   
I removed all of the CMAKE_CXX_FLAGS_* and CXX_C_FLAGS and built VTK with no flags. The tree worked properly. Then I added -O0 to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS and the tree still worked properly. When I changed CMAKE_CXX_FLAGS and CMAKE_C_FLAGS to -O1, the error occurs.
(0029859)
David Doria   
2012-12-09 08:09   
If I compile with

-O1 -ffloat-store

it works as expected. Any ideas how to make it work without --ffloat-store
(0029860)
David Doria   
2012-12-09 08:15   
It seems as thought this might actually be caused by a gcc bug?

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 [^]
(0029861)
David Doria   
2012-12-09 10:36   
I have confirmed that compiling VTK with the standard CMake "Release" flags this error occurs, but by adding either:

-mpc64

or

-ffloat-store

it works as expected.
(0033544)
Andy Bauer   
2014-10-02 16:54   
I think this has been fixed. I tested it and got the expected result with a release build with GCC 4.6.4. I tested with VTK commit SHA a1c574ea874885fc76a297bfdd13855cbbae48fd. If this is still an issue though then add in a specific compiler that the issue is happening with and what version of VTK you're using.