2012-01-04 7 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); 
관련 문제