[vtkusers] vtkDataArray segmentation fault with GetRange
Charlotte Curtis
c.f.curtis at gmail.com
Tue Aug 21 18:22:33 EDT 2012
Hi all,
I'm trying to use a vtkDataArray to colour vtkGlyph3Ds. The following
code works perfectly when there is only one component (the comp
parameter is set to zero). However, when I have multiple components, I
get a segmentation fault on the call to values->GetRange(comp).
Strangely, the cout loop to print the values works just fine, so I'm
pretty confident that the data exists. I've tried calling
values->Modified(), with no change.
Any ideas?
Thanks,
Charlotte
P.S. As a side note, I'm not sure if I'm correctly colouring by the
selected component, but I can't test that yet because the range isn't
working!
DrawSpheres(vtkSmartPointer<vtkPoints> points, double size,
vtkSmartPointer<vtkDoubleArray> values, int comp)
{
// create a polydata object to pack the points into
vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
pd->SetPoints(points);
// define the sphere source and the glyphs
vtkSmartPointer<vtkSphereSource> spheresource =
vtkSmartPointer<vtkSphereSource>::New();
spheresource->SetRadius(size);
vtkSmartPointer<vtkGlyph3D> glyphs = vtkSmartPointer<vtkGlyph3D>::New();
glyphs->SetInput(pd);
glyphs->SetSource(spheresource->GetOutput());
glyphs->SetScaleModeToDataScalingOff();
if (values != NULL)
{
for (int i = 0; i < values->GetNumberOfTuples(); i++)
std::cout << values->GetComponent(i,comp) << std::endl;
double *range = values->GetRange(comp);
pd->GetPointData()->SetScalars(values);
glyphs->Update();
// since we need to modify the mapper, we can't just use the
Display method
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
// create the lookup table
vtkSmartPointer<vtkLookupTable> lut =
vtkSmartPointer<vtkLookupTable>::New();
lut->SetTableRange(range);
lut->Build();
mapper->SetScalarRange(range);
mapper->SetLookupTable(lut);
mapper->ColorByArrayComponent(0,comp);
mapper->SetInputConnection(glyphs->GetOutputPort());
actor->SetMapper(mapper);
renderer->AddActor(actor);
}
}
More information about the vtkusers
mailing list