openCASCade——3D presentation

1 术语

1.1 Group

基本几何体与基本几何体属性的集合;可以增加不可删除,除非整体删除;Group有个pick的属性。

1.2 Light

有五种光源:环境光(ambient),前灯(headlight),定向光(directional),定位光(positional),点光(spot);光源只有在shading context模式下才能激活。

1.3 Primitive

基本几何体是一个可绘制单元,必须存储在Group中,marker和text是不可参与变换的,而点线面等是可以变换的(平移,放缩,旋转)。

1.4 Structure

structure用来管理groups。Groups之间是相互独立的,Structure没有默认属性,但是可以设置,只是会被Group覆盖。Structure有默认的刚性变换参数。Structure可以索引到别的Structure。Structure管理显示的优先级。

1.5 View

view由三个属性定义:显示朝向(orientation),显示的坐标映射(mapping),显示上下文(context)。

1.6 Viewer

管理由View组成的集合。

1.7 View orientation

定义观察者的观察角度。

1.8 View mapping

定义为由显示相对坐标系到正交投影坐标系的变换。

1.9 Z-Buffering

Shading mode中的必有属性,用来定义隐藏体。

2 图形显示元素Graphic primitives

Graphic Structure(Structure)是全局的,由Viewer操作。Graphic Structure可以被隐藏、高亮、擦除、变换、组织成tree。

2.1 Structure hierarchies

Graphic Structure属性具有继承特性。不支持循环网络的结构。

2.2 Graphic primitives

  • Markers
    1 一到多个顶点。
    2 一个type,放缩因子,颜色。
    3 一个shape,尺寸,独立的变换。
  • Triangulation
    1 至少三个顶点。
    2 节点有法矢用来定义阴影。
    3 内部属性:类型,颜色,字体,背景材料,纹理,反射率。
  • Polylines or Segments
    1 两个或以上顶点。
    2 线性,线宽,颜色。
  • Text
    1 几何与非几何属性。
    2 几何属性:高度、朝向、水平还是垂直对齐、是否可放缩、三维位置、路径。
    3 字体,字符间距,放缩系数,颜色。

2.3 Primitive arrays

  • Graphic3d_ArrayOfPoints
  • Graphic3d_ArrayOfPolylines
  • Graphic3d_ArrayOfSegments
  • Graphic3d_ArrayOfTriangleFans
  • Graphic3d_ArrayOfTriangles
  • Graphic3d_ArrayOfTriangleStrips.
    都是Graphic3d_ArrayOfPrimitive的子类。
// create an array 
Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints (theVerticiesMaxCount);
// add vertices to the array 
anArray->AddVertex (10.0, 10.0, 10.0); 
anArray->AddVertex (0.0, 10.0, 10.0);
// add the array to the structure 
Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); 
aGroup->AddPrimitiveArray (anArray); 
aGroup->SetGroupPrimitivesAspect (myDrawer->PointAspect()->Aspect());

2.4 Text primitive

三个特征:fixed size (non-zoomable) or zoomable;rotated to any angle in the view plane;support unicode charset.

// get the group 
Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
// change the text aspect 
Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d(); 
aTextAspect->SetTextZoomable (true); 
aTextAspect->SetTextAngle (45.0); 
aGroup->SetPrimitivesAspect (aTextAspect);
// add a text primitive to the structure 
Graphic3d_Vertex aPoint (1, 1, 1); 
aGroup->Text (Standard_CString ("Text"), aPoint, 16.0);

2.5 Materials

Graphic3d_MaterialAspect由以下五条定义:
• 透明度 Transparency;
• 漫反射;
• 环境反射;
• 镜面反射Specular reflection;
• 折射系数Refraction index.
物体最终的颜色由以下四条来决定:
• 本身的颜色;
• 漫反射系数;
• 环境反射系数;
• 镜面反射系数.

2.6 Textures

纹理由名称定义,有以下三种类型的纹理:
- 1D
- 2D
- 环境贴图(environment mapping)

2.7 Shaders

GLSL阴影。

// Create shader program 
Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
// Attach vertex shader 
aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, "<Path to VS>"));
// Attach fragment shader 
aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, "<Path to FS>"));
// Set values for custom uniform variables (if they are) 
aProgram->PushVariable ("MyColor", Graphic3d_Vec3 (0.0f, 1.0f, 0.0f));
// Set aspect property for specific AIS_Shape 
theAISShape->Attributes()->ShadingAspect()->Aspect()->SetShaderProgram (aProgram);

3 图形显示属性Graphic attributes

3.1 Aspect

• 图形属性组 —— Groups of graphic attributes;
• 边、线、背景 —— Edges, lines, background;
• 窗口 —— Window;
• 显示驱动 —— Driver;
• 多重枚举 —— Enumerations for many of the above.

4 3D显示设备

V3d 包。
提供Viewer与Views。

4.1 程序设计样例

// 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) VM = new V3d_Viewer (aGraphicDriver); 
VM->SetDefaultBackgroundColor (Quantity_NOC_DARKVIOLET); 
VM->SetDefaultViewProj (V3d_Xpos); 
// Create a structure in this Viewer 
Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (VM->Viewer());
// Type of structure 
aStruct->SetVisual (Graphic3d_TOS_SHADING);
// Create a group of primitives in this structure 
Handle(Graphic3d_Group) aPrsGroup = new Graphic3d_Group (aStruct);
// 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); 
aPrsGroup->AddPrimitiveArray (aTriangles); 
aPrsGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectFillArea3d());
// Create Ambient and Infinite Lights in this Viewer 
Handle(V3d_AmbientLight) aLight1 = new V3d_AmbientLight (VM, Quantity_NOC_GRAY50); 
Handle(V3d_DirectionalLight) aLight2 = new V3d_DirectionalLight (VM, V3d_XnegYnegZneg, Quantity_NOC_WHITE);
// Create a 3D quality Window with the same DisplayConnection 
Handle(Xw_Window) aWindow = new Xw_Window (aDispConnection, "Test V3d", 0.5, 0.5, 0.5, 0.5);
// Map this Window to this screen 
aWindow->Map();
// Create a Perspective View in this Viewer 
Handle(V3d_View) aView = new V3d_View (VM); 
aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective); 
// Associate this View with the Window 
aView ->SetWindow (aWindow); 
// Display ALL structures in this View 
VM->Viewer()->Display(); 
// Finally update the Visualization in this View 
aView->Update(); 
// Fit view to object size 
V->FitAll();

4.2 View 参数

• Eye – 相机(观察者)位置。
• Center – View坐标系原点,观察目标点。
• Direction – 视线(from the Eye to the Center)。
• Distance – 观察距离(distance between the Eye and the Center)。
• Front Plane – View坐标系统前裁切点。
• Back Plane – View坐标系统后裁切点。
• ZNear – 近点(distance between the Eye and the Front plane)。
• ZFar – 远点(defines the distance between the Eye and the Back plane)。

// rotate camera by X axis on 30.0 degrees 
gp_Trsf aTrsf; 
aTrsf.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0)), 30.0); 
aView->Camera()->Transform (aTrsf);

4.3 正交投影与透视投影

正交投影

// Create an orthographic View in this Viewer 
Handle(V3d_View) aView = new V3d_View (VM); 
aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); 
// update the Visualization in this View 
aView->Update();

透视投影

// Create a perspective View in this Viewer 
Handle(V3d_View) aView = new V3d_View(VM); 
aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective); 
aView->Update();

4.4 立体投影

Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver(); 
OpenGl_Caps& aCaps = aDriver->ChangeOptions(); 
aCaps.contextStereo = Standard_True;
//The following code configures the camera for stereographic rendering:
// Create a Stereographic View in this Viewer 
Handle(V3d_View) aView = new V3d_View(VM); 
aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Stereo); 
// Change stereo parameters 
aView->Camera()->SetIOD (IODType_Absolute, 5.0); 
// Finally update the Visualization in this View 
aView->Update();

立体投影

4.5 视窗背景

三种视窗背景。

  • 单色
void V3d_View::SetBackgroundColor (const Quantity_Color& theColor);
  • 渐近色
void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1, const Quantity_Color& theColor2, const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate = false);
  • 图片
void V3d_View::SetBackgroundImage (const Standard_CString theFileName, const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate = false);

第二个参数

• Aspect_FM_NONE – draws the image in the default position;
• Aspect_FM_CENTERED – draws the image at the center of the view;
• Aspect_FM_TILED – tiles the view with the image;
• Aspect_FM_STRETCH – stretches the image over the view.

4.6 当前窗口转为图片

Standard_Boolean V3d_View::Dump (const Standard_CString theFile, const Image_TypeOfImage theBufferType);
Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, const V3d_ImageDumpOptions& theParams);

4.7 光线跟踪

Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); 
// specifies rendering mode 
aParams.Method = Graphic3d_RM_RAYTRACING; 
// maximum ray-tracing depth 
aParams.RaytracingDepth = 3; 
// enable shadows rendering 
aParams.IsShadowEnabled = true; 
// enable specular reflections. 
aParams.IsReflectionEnabled = true; 
// enable adaptive anti-aliasing 
aParams.IsAntialiasingEnabled = true; 
// enable light propagation through transparent media. 
aParams.IsTransparentShadowEnabled = true; 
// update the view 
aView->Update();

4.8 显示优先等级

OCC有11个显示等级。
最低的等级先重绘。

4.9 z-layer

放入z-layer:

// set z-layer to an interactive object 
Handle(AIS_InteractiveContext) theContext; 
Handle(AIS_InteractiveObject) theInterObj; 
Standard_Integer anId = 3; 
aViewer->AddZLayer (anId); 
theContext->SetZLayer (theInterObj, anId);

设置z-layer

// change z-layer settings 
Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); 
aSettings.SetEnableDepthTest (true); 
aSettings.SetEnableDepthWrite(true); 
aSettings.SetClearDepth (true); 
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); 
aViewer->SetZLayerSettings (anId, aSettings);

4.10 截面

设置和获取平面方程系数:

Graphic3d_ClipPlane::Graphic3d_ClipPlane (const gp_Pln& thePlane) 
void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane) 
Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Equation& theEquation) 
void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation) 
gp_Pln Graphic3d_ClipPlane::ToPlane() const

激活:

void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)

裁切面限制:

// get the limit of clipping planes for the current view 
Standard_Integer aMaxClipPlanes = aView->Viewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxNbClipPlanes);

完整例子:

// create a new clipping plane 
const Handle(Graphic3d_ClipPlane)& aClipPlane = new Graphic3d_ClipPlane(); 
// change equation of the clipping plane 
Standard_Real aCoeffA = ... 
Standard_Real aCoeffB = ... 
Standard_Real aCoeffC = ... 
Standard_Real aCoeffD = ... 
aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); 
// set capping 
aClipPlane->SetCapping (aCappingArg == "on"); 
// set the material with red color of clipping plane Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); 
Quantity_Color aColor (1.0, 0.0, 0.0, Quantity_TOC_RGB); 
aMat.SetAmbientColor (aColor); 
aMat.SetDiffuseColor (aColor); 
aClipPlane->SetCappingMaterial (aMat); 
// set the texture of clipping plane
Handle(Graphic3d_Texture2Dmanual) aTexture = ... 
aTexture->EnableModulate(); 
aTexture->EnableRepeat(); 
aClipPlane->SetCappingTexture (aTexture); 
// add the clipping plane to an interactive object 
Handle(AIS_InteractiveObject) aIObj = ... 
aIObj->AddClipPlane (aClipPlane); 
// or to the whole view a
View->AddClipPlane (aClipPlane); 
// activate the clipping plane 
aClipPlane->SetOn(Standard_True); 
// update the view 
aView->Update();

4.11 Automatic back face culling

  • 3
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值