[vtkusers] coloring of point sets / scatter-plot
Erdem Heper
erdem.heper at comsoft.de
Mon Jun 23 10:22:24 EDT 2008
hello vtk community,
i am trying to display a set of points and colorize them according to
user settings. the coloring is done by selecting a set of points in a qt
table and setting the color. if i do so, the vtk display remains in the
initial coloring. i proceed as folows:
1. class with:
vtkPoints m_points,
vtkUnsignedCharArray m_scalar,
vtkLookupTable m_color_map,
vtkPointSource m_decoration_source,
vtkActor m_display_item.
2. the display is set up with initial data:
the lookuptable is set up (256 colors, color with id 0 is set black).
the points are added to m_points (the vtk ids are remembered).
the color id is added to m_scalar (the vtk ids are remembered).
code:
...
unsigned char * pointer = m_color_map->WritePointer(colour_index, 1);
//set black
pointer[0] = 0;
pointer[1] = 0;
pointer[2] = 0;
pointer[3] = 255;
...
vtk_point_id = m_points->InsertNextPoint(x, y, z);
vtk_color_id = m_scalar->InsertNextValue(color_index);
3. the pipeline is generated:
the display item is added to a renderer and is displayed correctly.
code:
vtkGlyph3D * glyph = vtkGlyph3D::New();
vtkPolyData * poly_data = vtkPolyData::New();
vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();
poly_data->SetPoints(m_points);
poly_data->GetPointData()->SetScalars(m_scalar);
//set up the decoration for the acquired point data.
glyph->SetInput(poly_data);
glyph->SetSourceConnection(m_decoration_source->GetOutputPort());
mapper->SetLookupTable(m_colouration);
mapper->SetColorModeToMapScalars();
mapper->SetInputConnection(glyph->GetOutputPort());
m_display_item->SetMapper(mapper);
glyph->Delete();
mapper->Delete();
poly_data->Delete();
4. set_color_for_selection function:
adds the commited color to the lookup table,
gets the vtk id of the selected point,
gets the corresponding scalar value,
sets the new color id in the scalar value of all selected points
code:
...
unsigned char * pointer = m_color_map->WritePointer(color_index, 1);
pointer[0] = color.red();
pointer[1] = color.green();
pointer[2] = color.blue();
pointer[3] = color.alpha();
...
m_scalar->SetValue(vtk_color_id, color_index);
i left out all qt and application specific stuff. this is a complete
outline of the vtk part i used (except the loops and destructor). i dont
know why the coloring does not work, because the initial values work
fine.
thank you in advance.
best regards,
Erdem
More information about the vtkusers
mailing list