View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013714VTK(No Category)public2012-12-07 16:292014-10-02 16:54
ReporterDavid Doria 
Assigned ToAndy Bauer 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version6.2.0 
Summary0013714: vtkModifiedBSPTree IntersectWithLine does not work when VTK built in RELEASE mode
DescriptionThe 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.
TagsNo tags attached.
ProjectTBD
Typeincorrect functionality
Attached Filesgz file icon demo.tar.gz [^] (7,260 bytes) 2012-12-07 16:29

 Relationships

  Notes
(0029857)
David Doria (reporter)
2012-12-07 17:12

It also does not work when VTK is built in RelWithDebInfo mode.
(0029858)
David Doria (reporter)
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 (reporter)
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 (reporter)
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 (reporter)
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 (developer)
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.

 Issue History
Date Modified Username Field Change
2012-12-07 16:29 David Doria New Issue
2012-12-07 16:29 David Doria File Added: demo.tar.gz
2012-12-07 17:12 David Doria Note Added: 0029857
2012-12-08 09:23 David Doria Note Added: 0029858
2012-12-09 08:09 David Doria Note Added: 0029859
2012-12-09 08:15 David Doria Note Added: 0029860
2012-12-09 10:36 David Doria Note Added: 0029861
2014-10-02 16:14 Andy Bauer Assigned To => Andy Bauer
2014-10-02 16:54 Andy Bauer Note Added: 0033544
2014-10-02 16:54 Andy Bauer Status backlog => closed
2014-10-02 16:54 Andy Bauer Resolution open => fixed
2014-10-02 16:54 Andy Bauer Fixed in Version => 6.2.0


Copyright © 2000 - 2018 MantisBT Team