opencascade官网文档学习之OCCT-visualization(可视化)(2)presentation
Introduction 介绍
可视化有两种方面:
- 存储要显示和选择的图元的几何和拓扑的数据
- presentation: 当对象显示在场景中时所看到的内容;selection: 以交互方式选择整个对象或其子部分的可能性,以将应用程序定义的操作应用于所选实体
Application Interactive Services :简写AIS
Fundamental Concepts 基本概念
Presentation: 服务与它们所代表的数据是分开的,这些数据是由应用算法生成的。此划分允许您在不修改可视化服务的情况下修改几何或拓扑算法及其结果对象。
Structure of the Presentation
在屏幕上显示对象涉及三种实体:
- 一个可呈现的对象,AIS_InteractiveObject
- a viewer
- 交互式上下文,AIS_InteractiveContext
The presentable object 对象
Graphic3d_Structure 提供对象的图形表示,调用适当的算法并保留该框架以供进一步显示。在第一次显示请求时,它通过调用适当的算法并保留此框架以供进一步显示来创建此结构。
StdPrs和Prs3d包中提供了标准表示算法。
Presentation packages
演示至少涉及AIS、PrsMgr、StdPrs和V3d软件包。如果您需要实现自己的表示算法,可以使用其他包,如Prs3d和Graphic3d。
- Standard Interactive Objects 标准交互对象
- AIS 包 提供了实现交互式对象(可显示和可选择的实体)的类。
- PrsDim 包为绘制尺寸和关系提供了可显示的对象。
- MeshVS 包提供了可显示的对象MeshVS_Mesh,用于处理网格数据。
- Standard presentation builders 标准演示生成器
- Prs3d 包该包为箭头(arrow)、圆柱体(cylinder)、球体(sphere)等简单几何图形提供了现成的标准表示算法。它还定义了Prs3d_Drawer类,用于控制要创建的演示文稿的颜色、线型(line type)、厚度(thickness)等属性。
- StdPrs 包为B-Rep形状提供了现成的标准表示算法。它提供了通用的表示算法,如着色(shading)、线框(wireframe)、等值线(isolines)和隐藏线删除(hidden line removal)。
- DsgPrs 包提供了用于显示尺寸(dimensions)、关系(relations)和XYZ三面体(trihedron)的工具。
- Low-level interfaces 低级接口
- PrsMgr 包定义可呈现对象的基本接口和工具。它包含实现表示过程所需的所有类:抽象类PrsMgr_presentation和PrsMgr_PresentableObject以及具体类PrsMgr_PresentationManager。
- Graphic3d包提供了底层的图形结构。它还定义了Graphic3d_GraphicDriver的接口,提供与OpenGL等低级图形API的连接。
3D Presentations
Glossary of 3D terms 术语表
- Group : 一组基元和这些基元上的属性。基元和属性可以添加到组中,但不能从组中删除,除非全局删除。一个组可以有一个pick标识。
- Light : 有五种光源——环境光源(ambient)、前照灯光源(headlight)、方向光源(directional)、位置光源(positional)和点光源(spot)。
- Primitive : 一种可绘制的元素。它在三维空间中有一个定义。基元可以是线、面、文字或标记。一旦显示,标记和文本的大小保持不变。可以修改线条和面,例如缩放。属性是在组中设置的。基本体必须存储在一个组中。
- Structure : 管理一组组(group).这些组是相互排斥的。可以编辑结构,添加或删除组。一个结构可以引用其他结构来形成层次结构。它有一个默认的(身份)变换,并且可以应用其他变换(旋转、平移、缩放等)。每个结构都有一个与之相关的显示优先级,这决定了它在3D查看器中重新绘制的顺序。
- View : 由视图方向、视图映射和上下文视图定义。
- Viewer : 管理一组视图。
- View orientation : 定义了观察者根据“视图参考坐标”查看场景的方式。
- View mapping : 定义从“视图参考坐标”到“规格化投影坐标”的转换。这遵循Phigs方案。
- Z-Buffering : 仅在着色模式下移除隐藏表面的一种形式。对于处于着色模式的视图,此选项始终处于活动状态,并且无法抑制。
Graphic primitives 图形图元
Graphic3d包用于在三维查看器中创建三维图形对象。这些称为结构的对象由一组基元组成,如线段、三角形、文本和标记,以及属性,如颜色、透明度、反射、线型、线宽和文本字体。组是结构中最小的可编辑元素。变换可以应用于结构。结构可以连接起来,形成一个由变换组成的结构树。结构由查看器全局操纵。
图形结构可以是:
- Displayed, 显示的
- Highlighted 高亮的
- Erased 擦除
- Transformed 转换
- 连接以形成结构的树状层次结构,通过转换创建
有以下类:
- 线条、面、标记、文本、材质的视觉属性
- 向量和顶点
- 图形对象、组和结构
Structure hierarchies 结构层次
根(root)是结构层次或结构网络的顶部。父结构的属性传递给其子结构。子结构的属性不会影响父结构。不支持递归结构网络。
Graphic primitives 图形图元
- Markers 标记
- 具有一个或多个顶点,
- 有一个类型、比例因子和颜色,
- 具有大小、形状和独立于变换的方向。
- Triangulation 三角形
- 至少有三个顶点
- 为着色定义了节点法线
- 具有内部属性——样式、颜色、正面和背面材质、纹理和反射比。
- Polylines or Segments 多线段或 线段
- 有两个或更多顶点
- 有以下属性--样式,宽度比例因子,颜色。
- Text 文本
- 具有几何和非几何属性,
- 几何属性–字符高度、字符向上矢量、文本路径、水平和垂直对齐、方向、三维位置、可缩放标志
- 非几何属性——文本字体、字符间距、字符扩展因子、颜色。
Primitive arrays 图元数组
不同类型的基元可以用以下基元数组表示:
- Graphic3d_ArrayOfPoints,
- Graphic3d_ArrayOfPolylines,
- Graphic3d_ArrayOfSegments,
- Graphic3d_ArrayOfTriangleFans,
- Graphic3d_ArrayOfTriangles,
- Graphic3d_ArrayOfTriangleStrips
Graphic3d_ArrayOfPrimitives是这些基本体阵列的基类。方法集Graphic3d_ArrayOfPrimitives::AddVertex允许将顶点及其属性(颜色、法线、纹理坐标)添加到基本体阵列中。也可以修改指定给顶点的值,或通过顶点索引查询这些值。
以下示例显示了如何定义点阵列:
1 // create an array 2 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints (theVerticiesMaxCount); 3 4 // add vertices to the array 5 anArray->AddVertex (10.0, 10.0, 10.0); 6 anArray->AddVertex (0.0, 10.0, 10.0); 7 8 // add the array to the structure 9 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); 10 aGroup->AddPrimitiveArray (anArray); 11 aGroup->SetGroupPrimitivesAspect (myDrawer->PointAspect()->Aspect());
如果基本体共享相同的顶点(多边形、三角形等),则可以将它们定义为顶点阵列的索引。方法Graphic3d_ArrayOfPrimitives::AddEdge允许通过索引定义基本体。此方法在数组中添加范围为[1,VertexNumber()]的“边”。也可以使用方法Graphic3d_ArrayOfPrimitives::edge查询由边定义的顶点。
以下示例显示了如何定义三角形阵列:
// create an array Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (theVerticesMaxCount, theEdgesMaxCount, Graphic3d_ArrayFlags_None); // add vertices to the array anArray->AddVertex (-1.0, 0.0, 0.0); // vertex 1 anArray->AddVertex ( 1.0, 0.0, 0.0); // vertex 2 anArray->AddVertex ( 0.0, 1.0, 0.0); // vertex 3 anArray->AddVertex ( 0.0,-1.0, 0.0); // vertex 4 // add edges to the array anArray->AddEdges (1, 2, 3); // first triangle anArray->AddEdges (1, 2, 4); // second triangle // add the array to the structure Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); aGroup->AddPrimitiveArray (anArray); aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
Text primitive 文本基元
TKOpenGl工具包使用纹理字体渲染文本标签。Graphic3d文本基元具有以下功能:
- 固定尺寸(不可缩放)或可缩放,
- 可以在视图平面中旋转到任何角度,
- 支持unicode字符集。
该组的文本属性可以使用Graphic3d_AspectText3d属性组定义。要将任何文本添加到图形结构中,可以使用以下方法:
void Graphic3d_Group::AddText (const Handle(Graphic3d_Text)& theTextParams, const Standard_Boolean theToEvalMinMax);
如果不希望Graphic3d结构边界受到文本位置的影响,可以将FALSE作为ToEvalMinMax传递
请注意,文本方向角度可以由Graphic3d_AspectText3d属性定义
1 // get the group 2 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); 3 4 // change the text aspect 5 Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d(); 6 aTextAspect->SetTextZoomable (true); 7 aTextAspect->SetTextAngle (45.0); 8 aGroup->SetPrimitivesAspect (aTextAspect); 9 10 // add a text primitive to the structure 11 Handle(Graphic3d_Text) aText = new Graphic3d_Text (16.0f); 12 aText->SetText ("Text"); 13 aText->SetPosition (gp_Pnt (1, 1, 1)); 14 aGroup->AddText (aText);
// create a default display connection Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection(); // create a Graphic Driver Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDispConnection); // create a Viewer to this Driver Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver); aViewer->SetDefaultBackgroundColor (Quantity_NOC_DARKVIOLET); // Create a structure in this Viewer Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (aViewer->StructureManager()); aStruct->SetVisual (Graphic3d_TOS_SHADING); // Type of structure // Create a group of primitives in this structure Handle(Graphic3d_Group) aPrsGroup = aStruct->NewGroup(); // Fill this group with one quad of size 100 Handle(Graphic3d_ArrayOfTriangleStrips) aTriangles = new Graphic3d_ArrayOfTriangleStrips (4); aTriangles->AddVertex (-100./2., -100./2., 0.0); aTriangles->AddVertex (-100./2., 100./2., 0.0); aTriangles->AddVertex ( 100./2., -100./2., 0.0); aTriangles->AddVertex ( 100./2., 100./2., 0.0); Handle(Graphic3d_AspectFillArea3d) anAspects = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, Quantity_NOC_RED, Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0f, Graphic3d_NameOfMaterial_Gold, Graphic3d_NameOfMaterial_Gold); aPrsGroup->SetGroupPrimitivesAspect (anAspects); aPrsGroup->AddPrimitiveArray (aTriangles); // Create Ambient and Infinite Lights in this Viewer Handle(V3d_AmbientLight) aLight1 = new V3d_AmbientLight (Quantity_NOC_GRAY50); Handle(V3d_DirectionalLight) aLight2 = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE, true); aViewer->AddLight (aLight1); aViewer->AddLight (aLight2); aViewer->SetLightOn(); // Create a 3D quality Window with the same DisplayConnection Handle(Xw_Window) aWindow = new Xw_Window (aDispConnection, "Test V3d", 100, 100, 500, 500); aWindow->Map(); // Map this Window to this screen // Create a Perspective View in this Viewer Handle(V3d_View) aView = new V3d_View (aViewer); aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective); // Associate this View with the Window aView->SetWindow (aWindow); // Display presentation in this View aStruct->Display(); // Finally update the Visualization in this View aView->Update(); // Fit view to object size aView->FitAll();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了