vtkAppendPolyData 中的多种颜色
Multiple colors in vtkAppendPolyData
本文关键字:颜色 vtkAppendPolyData 更新时间:2023-10-16
I have vtkAppendPolyData,其中包含 4 个 vtkConeSource。我想用不同的颜色给这 4 个锥体着色。vtk 中有什么方法可以实现这一点。如果您有任何其他建议,请告诉我。
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();
这是我创建圆锥体的代码,我想给它上色,即使我已经设置了锥体数据1->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);
同样,对于其他锥体,我添加了颜色,这解决了我的问题
相关文章:
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 列表视图更改选择颜色
- GtkTreeView 交替行颜色
- dx11 渲染到纹理仅显示透明颜色
- 使用 OpenGL 4.5 更改所选顶点的颜色
- 为什么我的 LEGACY OPENGL 颜色反转了?
- 双击更改 mfc 中列表控件中的行的颜色
- 更改 QT 中按钮的颜色
- 当我使用CHAR_INFO结构时,控制台会无缘无故地改变颜色
- 列表视图项的替代颜色
- GLSL 将 uint 转换为浮点颜色
- std::带有颜色和标题的 clog 包装器无法正确打印整数
- Vec3b:r/g/b 颜色的最大值为 254,而不是 255
- 如何将矢量对象更改为不同的颜色?
- PPM 颜色显示错误
- 如何更改 QGraphicsItem 对象的颜色?
- 如何防止每次 Arduino 启动时颜色数组都是相同的随机数组