簡體   English   中英

使用VTK繪制不同顏色的點

[英]Use VTK to plot points of different colours

我想使用Visualization Toolkit分散繪圖點,每個繪圖點將具有不同的顏色。 我已使用此處給出的建議以灰色繪制點,但無法理解如何為每種顏色賦予顏色。

多維數據集示例的相關部分包括:

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();

我該如何給每個Vert顏色?

我找到了自己想做的基本教程。 這顯示了如何為每個點添加顏色:

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);

您可能對VTK中新的二維繪圖基礎結構感興趣。 在此處查看示例: http : //www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot

另請參閱以下有關3D繪圖的討論: http : //www.kitware.com/source/home/post/40

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM