2012-01-04 255 views
1

我想使用Visualization Toolkit来绘制绘图点,每个点都会有不同的颜色。我使用了here给出的建议以灰色绘制点,但我没有理解如何为每个点赋予颜色。使用VTK绘制不同颜色的点

立方体示例的相关部分:

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

我怎么可以给每个绿党的颜色?

回答

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); 
相关问题