[vtkusers] vtkSurfaceReconstruction coordinate error

Nens nicolas.narbonne at gmail.com
Tue Feb 18 07:48:26 EST 2014


Hello,

I have a problem to draw the correct surface. Indeep, the surface created by
the code bellow don't have the correct coordinate. The surface seems good
but values are false.

I try to reset origin and spinning, but i didn't find how to do this good.

I use vtk 5.

*Code :*

 vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
        polydata->SetPoints(points);
        double bounds0[6];
        polydata->GetBounds(bounds0);
        // Find min and max z
        double min0z = bounds0[4];
        double max0z = bounds0[5];
        std::cout << "min0z: " << min0z << std::endl;
        std::cout << "max0z: " << max0z << std::endl;


        // // Construct the surface and create isosurface.
        vtkSmartPointer<vtkSurfaceReconstructionFilter> surf =
vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
#if VTK_MAJOR_VERSION <= 5
        surf->SetInput(polydata);
#else
        surf->SetInputData(polydata);
#endif
        surf->Update();

        std::cout << "t 0" <<  std::endl;
     
        // Create a new instance of the same type as surf->GetOutput() and
make it
        // a shallow copy
        vtkImageData* signedDist  = surf->GetOutput()->NewInstance();
        signedDist->ShallowCopy(surf->GetOutput());

//               vtkInformation* signedDistInfo =
surf->GetOutputPortInformation(0);
//        vtkInformation* signedDistInfo = polydata->GetInformation();
//        double *spacing = signedDistInfo->Get(vtkDataObject::SPACING());
//        signedDist->SetSpacing(spacing);        
//------------------------------------->crash
        
std::cout << "t 1" <<  std::endl;

//        signedDist->SetSpacing((bounds0[1] - bounds0[0])/XY.dim1()
,(bounds0[3] - bounds0[2])/XY.dim2()  , (bounds0[5] - bounds0[4]) );

        std::cout << "bounds : " << bounds0[0] <<" / "<<  bounds0[1] <<" /
"<< bounds0[2] <<" / "<< bounds0[3] <<" / "<< bounds0[4] <<" / "<<
bounds0[5] <<" / "<< std::endl;
        std::cout << "dim XY : "<< XY.dim1()<<" / "<< XY.dim2() << 
std::endl;
        std::cout << "dim field : "<< field.dim1()<<" / "<< field.dim2() << 
std::endl;
        std::cout << bounds0[1]-bounds0[0] / XY.dim1()<<" 000 "
<<bounds0[3]-bounds0[2] / XY.dim2() <<  std::endl;

        std::cout << "t 2" <<  std::endl;

//        double *origin = signedDistInfo->Get(vtkDataObject::ORIGIN());
        signedDist->SetOrigin(bounds0[0],bounds0[2], bounds0[4]);
//        signedDist->SetOrigin(0,0, 0);

        std::cout << "t 3" <<  std::endl;

        vtkSmartPointer<vtkContourFilter> contourFilter =
vtkSmartPointer<vtkContourFilter>::New();
//        contourFilter->SetInputConnection(surf->GetOutputPort());
        contourFilter->SetInput(signedDist);
        double bounds1[6];
        contourFilter->GetOutput()->GetBounds(bounds1);

        // Find min and max z
        double min1z = bounds1[4];
        double max1z = bounds1[5];
        std::cout << "min1z: " << min1z << std::endl;
        std::cout << "max1z: " << max1z << std::endl;

         // Sometimes the contouring algorithm can create a volume whose
gradient
        // vector and ordering of polygon (using the right hand rule) are
        // inconsistent. vtkReverseSense cures this problem.
        vtkSmartPointer<vtkReverseSense> reverse =
vtkSmartPointer<vtkReverseSense>::New();
        reverse->SetInput(contourFilter->GetOutput());
        reverse->ReverseCellsOn();
        reverse->ReverseNormalsOn();
        reverse->Update();


        // // Color surface
        vtkPolyData* outputPolyData = reverse->GetOutput();

        double bounds[6];
        outputPolyData->GetBounds(bounds);

        // Find min and max z
        double minz = bounds[4];
        double maxz = bounds[5];
        std::cout << "minz: " << minz << std::endl;
        std::cout << "maxz: " << maxz << std::endl;


*Console return :*

min0z: -3.63994                       // correct values
max0z: 8.62691                       //
t 0
t 1
bounds : -100 / 100 / -100 / 100 / -3.63994 / 8.62691 / 
dim XY : 21 / 41
dim field : 21 / 41
104.762 000 102.439
t 2
t 3
min1z: 1
max1z: -1
minz: -1.93855                     // wrong values
maxz: -0.409277                  //





--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkSurfaceReconstruction-coordinate-error-tp5725988.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list