您好,欢迎访问三七文档
地学信息可视化三、VTK基本应用4.1渲染非结构格网中的多个形体vtkPyramidpyramid=newvtkPyramid();pyramid.GetPointIds().SetId(0,0);pyramid.GetPointIds().SetId(1,3);pyramid.GetPointIds().SetId(2,5);pyramid.GetPointIds().SetId(3,1);pyramid.GetPointIds().SetId(4,2);vtkTetratetra=newvtkTetra();tetra.GetPointIds().SetId(0,5);tetra.GetPointIds().SetId(1,1);tetra.GetPointIds().SetId(2,2);tetra.GetPointIds().SetId(3,4);vtkUnstructuredGridaGrid=newvtkUnstructuredGrid();aGrid.Allocate(1,1);aGrid.InsertNextCell(pyramid.GetCellType(),pyramid.GetPointIds());aGrid.InsertNextCell(tetra.GetCellType(),tetra.GetPointIds());vtkActoractor=newvtkActor();vtkDataSetMapperaMapper=newvtkDataSetMapper();aMapper.SetInput(aGrid);actor.SetMapper(aMapper);actor.GetProperty().SetColor(1.0,0,0);分开渲染:vtkUnstructuredGridaGrid1=newvtkUnstructuredGrid();aGrid1.Allocate(1,1);aGrid1.InsertNextCell(pyramid.GetCellType(),pyramid.GetPointIds());aGrid1.SetPoints(wedgePoints);vtkActoractor1=newvtkActor();vtkDataSetMapperaMapper1=newvtkDataSetMapper();aMapper1.SetInput(aGrid1);actor1.SetMapper(aMapper1);actor1.GetProperty().SetColor(1.0,0,0);vtkUnstructuredGridaGrid2=newvtkUnstructuredGrid();aGrid2.Allocate(1,1);aGrid2.InsertNextCell(tetra.GetCellType(),tetra.GetPointIds());aGrid2.SetPoints(wedgePoints);vtkActoractor2=newvtkActor();vtkDataSetMapperaMapper2=newvtkDataSetMapper();aMapper2.SetInput(aGrid2);actor2.SetMapper(aMapper2);actor2.GetProperty().SetColor(0,1.0,1.0);ren.AddActor(actor1);ren.AddActor(actor2);三角化:把一系列散点连成三角网vtkPointspoints=newvtkPoints();for(inti=0;iDrillingInfos.size();i++){points.InsertPoint(i,DrillingInfos.get(i).getX(),DrillingInfos.get(i).getY(),1500);}vtkPolyDataprofile=newvtkPolyData();profile.SetPoints(points);vtkDelaunay2Ddelny=newvtkDelaunay2D();delny.SetInput(profile);delny.SetTolerance(0.001);delny.Update();vtkPolyDataMappermapMesh=newvtkPolyDataMapper();mapMesh.SetInputConnection(delny.GetOutputPort());vtkActoractor=newvtkActor();actor.SetMapper(mapMesh);actor.GetProperty().SetColor(0.9,0.8,.1);actor.GetProperty().SetLineStipplePattern(0xf0f0);actor.GetProperty().SetSpecularColor(1,1,1);actor.GetProperty().SetSpecular(0.3);actor.GetProperty().SetLineWidth(2);actor.GetProperty().SetSpecularPower(20);actor.GetProperty().SetAmbient(0.2);actor.GetProperty().SetDiffuse(0.8);actor.GetProperty().SetRepresentationToWireframe();多边形填充:将多边形剖分成三角形,进行填充地质剖面可视化:将每一个剖面多边形的数据加载进来,按照不同的属性分别进行渲染(颜色、纹理)读取每一个多边形数据并构建成vtkPolygon对象:vtkPolygonpolygon=newvtkPolygon();polygon.GetPointIds().SetNumberOfIds(6);polygon.GetPointIds().SetId(0,0);polygon.GetPointIds().SetId(1,1);polygon.GetPointIds().SetId(2,2);polygon.GetPointIds().SetId(3,3);polygon.GetPointIds().SetId(4,4);polygon.GetPointIds().SetId(5,5);polygon.GetPoints().SetNumberOfPoints(6);polygon.SetPoints(wedgePoints);多边形的纹理填充:构建纹理对象,并使用该渲染属性:vtkBMPReaderbmpReader=newvtkBMPReader();bmpReader.SetFileName(E:\\vtk\\VTKData\\Data\\masonry.bmp);vtkTextureatext=newvtkTexture();atext.SetInputConnection(bmpReader.GetOutputPort());atext.InterpolateOn();vtkPlaneSourceplane=newvtkPlaneSource();vtkPolyDataMapperplaneMapper=newvtkPolyDataMapper();planeMapper.SetInputConnection(plane.GetOutputPort());vtkActorplaneActor=newvtkActor();planeActor.SetMapper(planeMapper);planeActor.SetTexture(atext);标量场可视化标量数据(scalar)是应用最多的可视化类型。如污染物浓度分布数据、温度分布数据、高程数据等。标量场可视化按数据划分为:•二维数据等值线法,分层设色法•三维数据等值面法•断层数据表面重构•体素数据体可视化二维标量场可看成是位于某二维面上的一维标量函数F(x,y).常见的如数字高程模型DEM、TIN、数字地形模型等。基本上是以规整格网或非规整格网表示某二维面,二维面网格上每一点有二维空间坐标(x,y),在网格点或网格拓扑单元上附属有标量数据。二维标量场的可视化主要任务是把二维面上的标量数据的分布特征表现出来。主要有等值线法和分层设色法。颜色插值:利用某种色空间内的原始颜色数据,计算出颜色空间中未知颜色数据的过程插值的原理:颜色空间中,某种颜色的数据可以利用其周围8个已知(已存储)的数据经线性或曲线计算得到。为可视化数据集上的每一个点设置对应的标量值doublex[][]={{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1},{1,1,1},{0,1,1}};//定义单元,每4个顶点建立一个四边形单元,共计6个单元intpts[][]={{0,1,2,3},{4,5,6,7},{0,1,5,4},{1,2,6,5},{2,3,7,6},{3,0,4,7}};//创建对象vtkPolyDatacube=newvtkPolyData();vtkPointspoints=newvtkPoints();vtkCellArraypolys=newvtkCellArray();//存储标量值vtkFloatArrayscalars=newvtkFloatArray();//存储顶点for(i=0;i8;i++)points.InsertPoint(i,x[i]);//设定单元for(i=0;i6;i++){polys.InsertNextCell(4);polys.InsertCellPoint(pts[i][0]);polys.InsertCellPoint(pts[i][1]);polys.InsertCellPoint(pts[i][2]);polys.InsertCellPoint(pts[i][3]);//polys.inInsertNextCell(4,pts[i]);}//设定每个顶点的标量值for(i=0;i8;i++)scalars.InsertTuple1(i,i);//创建多边形数据cube.SetPoints(points);//设定单元类型为多边形cube.SetPolys(polys);//设定每个顶点的标量值cube.GetPointData().SetScalars(scalars);vtkLookupTablepColorTable=newvtkLookupTable();//设置颜色表中的颜色pColorTable.SetNumberOfColors(4);pColorTable.SetTableValue(0,1.0,0.0,0.0,1.0);pColorTable.SetTableValue(1,0.0,1.0,0.0,1.0);pColorTable.SetTableValue(2,1.0,1.0,0.0,1.0);pColorTable.SetTableValue(3,0.0,0.0,1.0,1.0);pColorTable.SetRampToSQRT();pColorTable.Build();vtkPolyDataMappercubeMapper=newvtkPolyDataMapper();cubeMapper.SetInput(cube);cubeMapper.SetScalarRange(0,7);cubeMapper.SetLookupTable(pColorTable);vtkActorcubeActor=newvtkActor();cubeActor.SetMapper(cubeMapper);
本文标题:可视化2
链接地址:https://www.777doc.com/doc-2573197 .html