vtkModifiedBSPTree IntersectWithLine does not work when VTK built in RELEASE mode
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
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 #include #include
int main(int, char *[]) { // Read the scene geometry vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName("corner.vtp"); reader->Update();
double p0[3] = {0, 0, 0}; double p1[3] = {22.2073, -15.8678, -96.2032};
vtkSmartPointer tree = vtkSmartPointer::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.