读取到VTK数据后,将数据组织起来并添加属性值。
示例:
#include#include #include #include #include #include #include //Attribution #include //点数据 #include //单元数据 /// #include #include #include #include #include int main() { //几何结构数据:点集 vtkSmartPointer pts = vtkSmartPointer ::New(); 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 polygon = vtkSmartPointer ::New(); 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 triangle = vtkSmartPointer ::New(); triangle->GetPointIds()->SetId(0, 1); triangle->GetPointIds()->SetId(1, 2); triangle->GetPointIds()->SetId(2, 4); //构成拓扑结构集合 vtkSmartPointer cells = vtkSmartPointer ::New(); cells->InsertNextCell(polygon); cells->InsertNextCell(triangle); //合成几何拓扑结构用于显示(包括点数据和单元数据集) vtkSmartPointer polygonPolyData = vtkSmartPointer ::New(); 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 ptColor = vtkSmartPointer ::New();//有5个点数据 ptColor->SetNumberOfComponents(3);//指定每个元组的大小,RGB三色分量组成 ptColor->InsertNextTupleValue(red); ptColor->InsertNextTupleValue(green); ptColor->InsertNextTupleValue(blue); ptColor->InsertNextTupleValue(red); ptColor->InsertNextTupleValue(green); polygonPolyData->GetPointData()->SetScalars(ptColor); vtkSmartPointer cellColor = vtkSmartPointer ::New();//2个单元数据 cellColor->SetNumberOfComponents(3); cellColor->InsertNextTupleValue(blue); cellColor->InsertNextTupleValue(red); polygonPolyData->GetCellData()->SetScalars(cellColor);
vtkSmartPointermapper =
vtkSmartPointer::New();//将几何拓扑结构数据(可视化模型)进行映射到图形模型
mapper->SetInputData(polygonPolyData);
vtkSmartPointeractor =
vtkSmartPointer::New();
actor->SetMapper(mapper);
vtkSmartPointerrender =
vtkSmartPointer::New();
render->AddActor(actor);
render->SetBackground(0.0, 0.0, 0.0);
vtkSmartPointerrw =
vtkSmartPointer::New();
rw->AddRenderer(render);
rw->SetSize(320, 240);
rw->SetWindowName("Creating PolyData Structure");
vtkSmartPointerrwi =
vtkSmartPointer::New();
rwi->SetRenderWindow(rw);
rwi->Render();
rwi->Start();
return 0;
}
问题:1. 如何设置点的ID号,对比书籍,为什么解释不同。
步骤:导入点->设置点的ID->构建几何结构->构建拓扑结构集合-> 存储数据
属性结构: 创建属性结构-> 创建元组->创建单元数据->合并数据