我想使用Visualization Toolkit来分散绘图点,每个绘图点都有不同的颜色。我已经使用给出here的建议来绘制灰色的点,但我不明白如何为每个点赋予颜色。
立方体示例的相关部分是:
vtkPolyData *cube = vtkPolyData::New();
vtkPoints *points = vtkPoints::New();
vtkCellArray *polys = vtkCellArray::New();
vtkFloatArray *scalars = vtkFloatArray::New();
// Load the point, cell, and data attributes.
for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
for (i=0; i<8; i++) scalars->InsertTuple1(i,i);
// We now assign the pieces to the vtkPolyData.
cube->SetPoints(points);
points->Delete();
cube->SetVerts(polys);
polys->Delete();
cube->GetPointData()->SetScalars(scalars);
scalars->Delete();
如何为每个Verts提供颜色?
答案 0 :(得分:6)
我找到了一个基本的教程,我正在尝试做什么。这显示了如何为每个点添加颜色:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColoredPoints
相关部分如下:
// Setup colors
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName ("Colors");
for (int i = 0; i < nV; ++i)
{
unsigned char tempColor[3] = {(int)c[i],
(int)c[i+nV],
(int)c[i+2*nV]};
colors->InsertNextTupleValue (tempColor);
}
polydata->GetPointData()->SetScalars(colors);
答案 1 :(得分:1)
您可能对VTK中新的2d绘图基础设施感兴趣。见这里的例子: http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot
另见3D绘图的讨论: http://www.kitware.com/source/home/post/40