[vtkusers] How to set colors for contour edges?
Vladimir Dudnik
vladimir.dudnik at gmail.com
Thu Feb 16 11:58:54 EST 2012
Well, seems I've found out how to set different colors to contour edges
http://vtk.1045678.n5.nabble.com/file/n5490071/vtk_color_lines_1.png
but still have questions.
So, what I did is
1. create unsigned char array of colors I want to use (number of entries for
this array is number of points/edges in my data set
2. construct vtkPolyData object from points in my data set
3. assign array of colors to the cell data scalars
4. render this
The questions are:
I see the different results depending on how I construct the PolyData
object. If it is like this:
---------
// r0 is array of nPoints point coordinates that form closed contour
// create vtkPoints for rectangular contour
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
for(int i = 0; i < nPoints; i++)
points->InsertNextPoint(r0[i].x, r0[i].y, 0.0);
// connect polyline's point ids
vtkSmartPointer<vtkPolyLine> polyline =
vtkSmartPointer<vtkPolyLine>::New();
for(vtkIdType i = 0; i < nPoints; i++)
{
polyline->GetPointIds()->InsertNextId(i);
}
// close contour
polyline->GetPointIds()->InsertNextId(0);
// create cell array for polyline
vtkSmartPointer<vtkCellArray> polylines =
vtkSmartPointer<vtkCellArray>::New();
polylines->InsertNextCell(polyline);
// create cell array for edges
vtkSmartPointer<vtkCellArray> edges =
vtkSmartPointer<vtkCellArray>::New();
// connect edge's point ids
for(vtkIdType i = 0; i < nPoints; i++)
{
vtkSmartPointer<vtkLine> edge = vtkSmartPointer<vtkLine>::New();
edge->GetPointIds()->SetId(0, i);
edge->GetPointIds()->SetId(1, (i+1) % nPoints);
edges->InsertNextCell(edge);
}
// create polydata obj
vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
data->SetPoints(points);
data->SetLines(edges);
data->SetVerts(polylines);
// set edges color
data->GetCellData()->SetScalars(edgeColors);
------
then I got result shown on the screenshot above.
But if I construct PolyData as following:
------
// create cell array for edges
vtkSmartPointer<vtkCellArray> edges =
vtkSmartPointer<vtkCellArray>::New();
// create cell array for vertexes
vtkSmartPointer<vtkCellArray> vertexes =
vtkSmartPointer<vtkCellArray>::New();
// connect edge's and vertexes point ids
for(vtkIdType i = 0; i < nPoints; i++)
{
vtkSmartPointer<vtkLine> edge = vtkSmartPointer<vtkLine>::New();
edge->GetPointIds()->SetId(0, i);
edge->GetPointIds()->SetId(1, (i+1) % nPoints);
edges->InsertNextCell(edge);
vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
vertex->GetPointIds()->SetId(0, i);
vertexes->InsertNextCell(vertex);
}
// create polydata obj
vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
data->SetPoints(points);
data->SetVerts(vertexes);
data->SetLines(edges);
data->GetCellData()->SetScalars(edgeColors);
------
I've got result like this
http://vtk.1045678.n5.nabble.com/file/n5490071/vtk_color_lines_2.png
so why I can't use vtkCellArray for list of vertexes? From the other hand,
how it is possible that vertexes can be described by vtkPolyLine object?
And finally, is it possible to control the color of points independently
from color of lines?
When I tried to call data->GetPointData()->SetScalars(vertexColors) in
addition to data->GetCellData()->SetScalars() I've got result like this
http://vtk.1045678.n5.nabble.com/file/n5490071/vtk_color_lines_3.png
seems setting scalars to PointData takes precedence over setting scalars for
CellData. Also, the strange thing is why there gradually change in color
over lines?
The compilable example of code (for the first described result) is attached
http://vtk.1045678.n5.nabble.com/file/n5490071/vtk_polyline_colors.cxx
vtk_polyline_colors.cxx
what I'm doing wrong here?
Regards,
Vladimir
--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-set-colors-for-contour-edges-tp5488892p5490071.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list