vtkAppendPolyData中的多种颜色
问题描述:
我有包含4个vtkConeSource的vtkAppendPolyData。我想用不同的颜色为这4个锥体着色。有什么办法可以在vtk中实现这一点。如果您有任何其他建议,请告诉我。vtkAppendPolyData中的多种颜色
vtkConeSource *cone1 = vtkConeSource::New();
cone1->SetHeight(6.0);
cone1->SetRadius(3.0);
cone1->SetCenter(0, 0, 0);
cone1->SetResolution(10);
vtkPolyData *coneData1 = cone1->GetOutput();
unsigned char red[3] = {255, 0, 0};
vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
colors->InsertNextTupleValue(red);
coneData1->GetCellData()->SetScalars(colors);
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInput(coneData1);
mapper->Update();
mapper->StaticOn();
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper(mapper);
vtkRenderer *ren1= vtkRenderer::New();
ren1->AddActor(coneActor);
ren1->SetBackground(0.1, 0.2, 0.4);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
renWin->SetSize(300, 300);
vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
renWin->SetInteractor(interactor);
renWin->Render();
interactor->Start();
这是我的代码创建锥和我要的颜色它即使我已经设定coneData1-> GetCellData() - > SetScalars(色)它在红色不显示锥。
答
在将它们连接到追加过滤器之前,您必须将颜色数组附加到每个vtkConeSource输出。你会做这样的事情:
unsigned char red[3] = {255, 0, 0};
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
colors->InsertNextTupleValue(red);
polydata->GetCellData()->SetScalars(colors);
(这里是一个完整的例子:http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TriangleSolidColor)
这里是一个不同的方式来颜色的对象(直接着色的数据描述,与着色演员)这也可能是值得看的: https://docs.google.com/present/edit?id=0AcyIfGqnlfSoZGdqaGhnMnJfMjc0Z3EybnNkZzQ&hl=en
答
vtkConeSource *cone1 = vtkConeSource::New();
cone1->SetHeight(6.0);
cone1->SetRadius(3.0);
cone1->SetCenter(0, 0, 0);
cone1->SetResolution(10);
vtkPolyData *coneData1 = cone1->GetOutput();
unsigned char red[3] = {255, 0, 0};
vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
colors->InsertNextTupleValue(red);
// Before setting color to cell data
// Upadte coneSource
coneData1->GetCellData()->Update();
// This will give celldata Other wise Number of cell data will be zero
// Insert tuples equal to number of Cell present in Polydata
coneData1->GetCellData()->SetScalars(colors);
同样为我添加色素等锥,这解决我的问题
它不工作,你可以给一些更多的代码 – 2014-11-26 05:30:59
你如何发布你尝试的代码,以及任何错误或描述确切的什么不工作。 – 2014-11-26 12:44:22
David我已经添加了代码段请检查请让我知道我做错了什么 – 2014-11-28 11:39:07