[vtkusers] Segmentation fault on call to FindCell()

John Haiducek jhaiduce at gmail.com
Fri Oct 22 12:54:37 EDT 2010


After obtaining and examining a traceback, I found the segmentation fault
was occurring in vtkHexahedron::InterpolationFunctions, which apparently
expects the double*weights to be an array of 8 doubles. This is aggravating,
since the documentation says nothing about the expected length of *weights.
The example at
http://www.cmake.org/Wiki/VTK/Examples/Cxx/PolyData/PointInsideObject2 uses
double weights[3], which also makes no sense since there's no way to make a
3-dimensional cell with only 3 faces/vertices. Can anyone tell me exactly
what's expected to be passed to vtkPointSet::FindCell()??

traceback:

#0  0x00000031c31885ee in vtkHexahedron::InterpolationFunctions (
    pcoords=0x7fffffffd8a0, sf=0x0)
    at /usr/src/debug/VTK/Filtering/vtkHexahedron.cxx:202
#1  0x00000031c3189bdf in vtkHexahedron::EvaluatePosition (
    this=<value optimized out>, x=<value optimized out>,
    closestPoint=<value optimized out>, subId=<value optimized out>,
    pcoords=0x7fffffffd8a0, dist2=@0x7fffffffd7f8, weights=0x0)
    at /usr/src/debug/VTK/Filtering/vtkHexahedron.cxx:82
#2  0x00000031c320927f in vtkPointSet::FindCell (this=0x6250d0,
    x=<value optimized out>, cell=0x0, gencell=<value optimized out>,
    cellId=43508, tol2=<value optimized out>, subId=<value optimized out>,
    pcoords=0x7fffffffd8a0, weights=0x0)
    at /usr/src/debug/VTK/Filtering/vtkPointSet.cxx:217
#3  0x0000000000401187 in vtkBlenderTexture::SamplePoint (this=0x6238a0,
    x=0.01, y=0, z=0, array=0) at vtkFindCellTest.cpp:73
#4  0x0000000000401420 in main (argc=1, argv=0x7fffffffdb38)
    at vtkFindCellTest.cpp:111


On Thu, Oct 21, 2010 at 4:00 PM, John Haiducek <jhaiduce at gmail.com> wrote:

> I'm writing a program that samples points from a VTKUnstructuredGrid
> dataset by using calls to vtkDataSet::FindPoint(). Every call to FindPoint
> results in a segmentation fault. Any help would be appreciated.
>
> John
>
> [code]
> #include <sstream>
> #include <iostream>
>
> #include <cstddef>
> #include "vtkDataSetReader.h"
> #include "vtkSmartPointer.h"
> #include "vtkDataSet.h"
> #include "vtkGenericCell.h"
> #include "vtkPointData.h"
>
> class vtkBlenderTexture
> {
>     private:
>         vtkSmartPointer <vtkDataSet> dataset;
>         int dims[3];
>
>         void load_vtk(char* filename);
>         char vtkfilename[240];
>         vtkGenericCell *gencell;
>
>     public:
>
>         vtkBlenderTexture();
>
>         double SamplePoint(double x, double y, double z, int array);
>
>         void SetInputFilename(char* filename);
>
>         char* GetInputFilename();
> };
>
> void vtkBlenderTexture::load_vtk(char filename[240])
>         {
>             strcpy(vtkfilename,filename);
>             vtkSmartPointer<vtkDataSetReader> reader =
> vtkSmartPointer<vtkDataSetReader>::New();
>             reader->SetFileName(filename);
>
> if(reader->IsFileValid("unstructured_grid")||reader->IsFileValid("structured_grid"))
>             {
>                 reader->Update();
>                 dataset=reader->GetOutput();
>                 cout << "Done reading "<< filename <<endl;
>             }
>             else
>             {
>                 cout << "Invalid VTK file "<<filename<<endl;
>                 dataset=NULL;
>             }
>         }
>
> vtkBlenderTexture::vtkBlenderTexture()
>         {
>                 gencell = vtkGenericCell::New();
>         }
>
> double vtkBlenderTexture::SamplePoint(double x, double y, double z, int
> array)
>         {
>             double value=0;
>             if(dataset!=NULL)
>             {
>                 double pos[3]={x,y,z};
>                 double pcoords[3];
>                 vtkIdType cellId=NULL;
>                 int subId;
>                 double * weights;
>                 cellId =
> dataset->FindCell(pos,NULL,gencell,cellId,0.01,subId,pcoords,weights);
>                 if(cellId>=0)
>                 {
>                     vtkIdList*pointIds;
>                     dataset->GetCellPoints(cellId,pointIds);
>                     value =
> dataset->GetPointData()->GetScalars()->GetComponent(pointIds->GetId(0),array);
>                 }
>             }
>
>             return value;
>         }
>
> void vtkBlenderTexture::SetInputFilename(char filename[240])
>         {
>             load_vtk(filename);
>         }
>
> char* vtkBlenderTexture::GetInputFilename()
>         {
>             return vtkfilename;
>         }
>
>
> int main( int argc, const char* argv[] )
> {
>     vtkBlenderTexture * texobj = new vtkBlenderTexture();
>
>     char filename[240]="/home/haiduced/PumpStudy/pumpstudy.vtk";
>     texobj->SetInputFilename(filename);
>     double value = texobj->SamplePoint(0.01, 0, 0,0);
>     cout << value << endl;
>     return 0;
> }
> [/code]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101022/7987ae21/attachment.htm>


More information about the vtkusers mailing list