读取到VTK数据后,将数据组织起来并添加属性值。
示例:
#include
#include
#include
#include
#include
#include
#include
#include
#include
///
#include
#include
#include
#include
#include
int main()
{
//几何结构数据:点集
vtkSmartPointer
vtkSmartPointer
pts->InsertNextPoint(0.0, 0.0, 0.0);
pts->InsertNextPoint(1.0, 0.0, 0.0);
pts->InsertNextPoint(1.0, 1.0, 0.0);
pts->InsertNextPoint(0.0, 1.0, 0.0);
pts->InsertNextPoint(2.0, 0.0, 0.0);
//拓扑结构数据,正四边形
//构建多边形单元
vtkSmartPointer
vtkSmartPointer
polygon->GetPointIds()->SetNumberOfIds(4);
polygon->GetPointIds()->SetId(0, 0);//为对应索引的点设置坐标,坐标为vtkpionts中定义的5个坐标点
polygon->GetPointIds()->SetId(1, 1);
polygon->GetPointIds()->SetId(2, 2);//setId为指定的点设置索引
polygon->GetPointIds()->SetId(3, 3);
//拓扑结构数据:三角形
vtkSmartPointer
vtkSmartPointer
triangle->GetPointIds()->SetId(0, 1);
triangle->GetPointIds()->SetId(1, 2);
triangle->GetPointIds()->SetId(2, 4);
//构成拓扑结构集合
vtkSmartPointer
vtkSmartPointer
cells->InsertNextCell(polygon);
cells->InsertNextCell(triangle);
//合成几何拓扑结构用于显示(包括点数据和单元数据集)
vtkSmartPointer
vtkSmartPointer
polygonPolyData->SetPoints(pts);
polygonPolyData->SetPolys(cells);
//添加属性结构
unsigned char red[3] = { 255, 0, 0 };
unsigned char green[3] = { 0, 255, 0 };
unsigned char blue[3] = { 0, 0, 255 };
vtkSmartPointer
vtkSmartPointer
ptColor->SetNumberOfComponents(3);//指定每个元组的大小,RGB三色分量组成
ptColor->InsertNextTupleValue(red);
ptColor->InsertNextTupleValue(green);
ptColor->InsertNextTupleValue(blue);
ptColor->InsertNextTupleValue(red);
ptColor->InsertNextTupleValue(green);
polygonPolyData->GetPointData()->SetScalars(ptColor);
vtkSmartPointer<vtkUnsignedCharArray> cellColor =
vtkSmartPointer<vtkUnsignedCharArray>::New();//2个单元数据
cellColor->SetNumberOfComponents(3);
cellColor->InsertNextTupleValue(blue);
cellColor->InsertNextTupleValue(red);
polygonPolyData->GetCellData()->SetScalars(cellColor);
vtkSmartPointer
vtkSmartPointer
mapper->SetInputData(polygonPolyData);
vtkSmartPointer
vtkSmartPointer
actor->SetMapper(mapper);
vtkSmartPointer
vtkSmartPointer
render->AddActor(actor);
render->SetBackground(0.0, 0.0, 0.0);
vtkSmartPointer
vtkSmartPointer
rw->AddRenderer(render);
rw->SetSize(320, 240);
rw->SetWindowName("Creating PolyData Structure");
vtkSmartPointer
vtkSmartPointer
rwi->SetRenderWindow(rw);
rwi->Render();
rwi->Start();
return 0;
}
问题:1. 如何设置点的ID号,对比书籍,为什么解释不同。
步骤:导入点->设置点的ID->构建几何结构->构建拓扑结构集合-> 存储数据
属性结构: 创建属性结构-> 创建元组->创建单元数据->合并数据
手机扫一扫
移动阅读更方便
你可能感兴趣的文章