[vtkusers] Segmentation fault on call to FindCell()

John Haiducek jhaiduce at gmail.com
Thu Oct 21 18:00:01 EDT 2010


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/20101021/7cc433a9/attachment.htm>


More information about the vtkusers mailing list