2012-01-04 17 views
1

視覚化ツールキットを使用して、それぞれ異なる色を持つプロット点を散布したいと思います。私は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(); 

はどうすればVertsに、それぞれに色を与えることができますか?

答えて

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); 
関連する問題