1

我想使用可视化工具包来分散绘图点,每个绘图点都有不同的颜色。我已使用此处给出的建议以灰色绘制点,但我无法理解如何为每个点赋予颜色。

多维数据集示例的相关部分是:

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 一种颜色?

4

2 回答 2

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);
于 2012-01-23T13:16:46.180 回答
1

您可能对 VTK 中的新二维绘图基础设施感兴趣。请参阅此处的示例: http ://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot

另请参阅有关 3D 绘图的讨论: http ://www.kitware.com/source/home/post/40

于 2012-01-04T16:14:58.627 回答