[vtkusers] How to use vtkRibbonFilter to show a scalar field
Jean-Do Barnichon
jeando.barnichon at free.fr
Sat Mar 22 08:14:26 EDT 2008
Hello all,
I want to display a scalar field along a polyline, by making the color
of each line segment depending on some color scale defined through a
vtkLookupTable.
Actually, the scalars are known at the polyline nodes, and theses
scalars are stored in a vtkFloatArray with 1 component.
Well the thing is that I do not get the ribbon in the display, so I
guess I'm probably doing something wrong.
Note that if I set a given color for the whole actor (obviously it's not
really what I want, but just for testing) by uncommenting the last line
of the code snippet given below :
RibonActor->GetProperty()->SetColor(1.,0.,0.);
it works in the sense that the ribbon is displayed in full red.
Any idea where the problem might come from in my code ?
Thanks,
J-D
Code Snippet
...
/////////////////////////////////////////////////////////////////////////////
// Create a lookup table that consists of the full hue circle (from
HSV).
/////////////////////////////////////////////////////////////////////////////
vtkLookupTable *hueLut = vtkLookupTable::New();
hueLut->SetHueRange (160./240., 0.);
hueLut->SetSaturationRange (1, 1);
hueLut->SetTableRange (minEnergy, maxEnergy);
hueLut->Build();
/////////////////////////////////////////////////////////////////////////////
// Add the traj in the vertical polyplane
/////////////////////////////////////////////////////////////////////////////
vtkPoints* trajpoints = vtkPoints::New(VTK_DOUBLE);
vtkCellArray* trajpolyline = vtkCellArray::New();
// Fill trajpoints and trajpolyline
...
// Set it to a polydata
vtkPolyData *trajPD = vtkPolyData::New();
trajPD->SetPoints(trajpoints);
trajPD->SetLines(trajpolyline);
trajPD->Update();
// Define filter
vtkRibbonFilter *rf = vtkRibbonFilter::New();
rf->SetInput(trajPD);
rf->SetWidth(0.5);
rf->SetWidthFactor(5);
// Link mapper
vtkPolyDataMapper *RibonMapper = vtkPolyDataMapper::New();
RibonMapper->SetInputConnection(rf->GetOutputPort());
RibonMapper->SetScalarRange(minEnergy, maxEnergy);
RibonMapper->SetLookupTable(hueLut);
RibonMapper->ScalarVisibilityOn();
RibonMapper->SelectColorArray("EnergyArray");
RibonMapper->SetScalarModeToUsePointFieldData();
RibonMapper->SetColorModeToMapScalars();
// Add actor
vtkActor *RibonActor = vtkActor::New();
RibonActor->SetMapper(RibonMapper);
(RibonActor->GetProperty())->SetInterpolationToFlat();
// RibonActor->GetProperty()->SetColor(1.,0.,0.);
// Do usual stuff
...
More information about the vtkusers
mailing list