基本几何体与基本几何体属性的集合;可以增加不可删除,除非整体删除;Group有个pick的属性。
有五种光源:环境光(ambient),前灯(headlight),定向光(directional),定位光(positional),点光(spot);光源只有在shading context模式下才能激活。
基本几何体是一个可绘制单元,必须存储在Group中,marker和text是不可参与变换的,而点线面等是可以变换的(平移,放缩,旋转)。
structure用来管理groups。Groups之间是相互独立的,Structure没有默认属性,但是可以设置,只是会被Group覆盖。Structure有默认的刚性变换参数。Structure可以索引到别的Structure。Structure管理显示的优先级。
view由三个属性定义:显示朝向(orientation),显示的坐标映射(mapping),显示上下文(context)。
管理由View组成的集合。
定义观察者的观察角度。
定义为由显示相对坐标系到正交投影坐标系的变换。
Shading mode中的必有属性,用来定义隐藏体。
Graphic Structure(Structure)是全局的,由Viewer操作。Graphic Structure可以被隐藏、高亮、擦除、变换、组织成tree。
Graphic Structure属性具有继承特性。不支持循环网络的结构。
// 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());
三个特征: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);
Graphic3d_MaterialAspect由以下五条定义:
• 透明度 Transparency;
• 漫反射;
• 环境反射;
• 镜面反射Specular reflection;
• 折射系数Refraction index.
物体最终的颜色由以下四条来决定:
• 本身的颜色;
• 漫反射系数;
• 环境反射系数;
• 镜面反射系数.
纹理由名称定义,有以下三种类型的纹理:
- 1D
- 2D
- 环境贴图(environment mapping)
GLSL阴影。
// Create shader program
Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
// Attach vertex shader
aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, "" ));
// Attach fragment shader
aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, "" ));
// 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);
• 图形属性组 —— Groups of graphic attributes;
• 边、线、背景 —— Edges, lines, background;
• 窗口 —— Window;
• 显示驱动 —— Driver;
• 多重枚举 —— Enumerations for many of the above.
V3d 包。
提供Viewer与Views。
// 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();
• 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);
正交投影
// 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();
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();
三种视窗背景。
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.
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);
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();
OCC有11个显示等级。
最低的等级先重绘。
放入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);
设置和获取平面方程系数:
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();