OpenCasCade是什么

Open CASCADE(简称OCC)平台是由法国Matra Datavision公司开发的CAD/CAE/CAM软件平台,可以说是世界上最重要的几何造型基础软件平台之一。开源OCC对象库是一个面向对象C++类库,用于快速开发设计领域的专业应用程序。

最近一直在利用OpenCasCade来进行空间几何的相关算法,于是有了这个教程让大家可以更直观的看到occ内部对象最终组装呈现的实际效果是什么。

利用OpenGL如何让occ做简单模型展示

1.依赖引用

预编译头stdafx.h中加入头文件引用与静态描述引用

#include <V3d_View.hxx>               //V3d_View
#include <WNT_Window.hxx>             //Handle_WNT_Window
#include <AIS_InteractiveContext.hxx> //AIS_InteractiveContext
#include <AIS_Shape.hxx>              //Handle_AIS_Shape
#include <Standard.hxx>
#include <Standard_PrimitiveTypes.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Line.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Point.hxx>
#include <AIS_TexturedShape.hxx>
#include <Aspect_Grid.hxx>
#include <Aspect_PolygonOffsetMode.hxx>
#include <Aspect_DisplayConnection.hxx>
#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax2d.hxx>
#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>
#include <gp_Lin2d.hxx>
#include <gp_Pln.hxx>
#include <gp.hxx>
#include <gp_Pnt2d.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GeomLib.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Curve.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom2d_Ellipse.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_Circle.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
#include <Graphic3d_ExportFormat.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectText3d.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_Texture1Dsegment.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <Prs3d_Root.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
#include <Prs3d_TextAspect.hxx>
#include <Prs3d_Text.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <Select3D_SensitiveCurve.hxx>
#include <Select3D_SensitiveGroup.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_SequenceOfOwner.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <ShapeBuild_Edge.hxx>
#include <StdSelect_ViewerSelector3d.hxx>
#include <StdPrs_ShadedShape.hxx>
#include <StdPrs_HLRPolyShape.hxx>
#include <StdSelect_BRepSelectionTool.hxx>
#include <StdPrs_WFShape.hxx>
#include <StdPrs_ToolRFace.hxx>
#include <StdSelect.hxx>
#include <StdSelect_BRepOwner.hxx>
#include <StdSelect_BRepSelectionTool.hxx>#include <TCollection_AsciiString.hxx>
#include "TopExp.hxx"
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Builder.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_ListOfShape.hxx>
#include <TopoDS_ListIteratorOfListOfShape.hxx>
#include <TopoDS_Iterator.hxx>
#include "TopoDS_Edge.hxx"
#include "TopoDS_Vertex.hxx"
#include <TopoDS_Wire.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <WNT_Window.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepLib.hxx>
#include <BRepOffsetAPI_MakeThickSolid.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRepBuilderAPI_NurbsConvert.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepBndLib.hxx>
#include <BRepAdaptor_HArray1OfCurve.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <GC_MakeSegment.hxx>
#include <TopTools_ListOfShape.hxx>
#include <GProp_PEquation.hxx>
#include <math_Matrix.hxx>
#include <gce_MakeCirc.hxx>
#include <geom2d_line.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <TopExp_Explorer.hxx>#pragma comment(lib,"TKVCAF.lib")
#pragma comment(lib,"TKVrml.lib")
#pragma comment(lib,"TKStl.lib")
#pragma comment(lib,"TKBrep.lib")
#pragma comment(lib,"TKIGES.lib")
#pragma comment(lib,"TKShHealing.lib")
#pragma comment(lib,"TKStep.lib")
#pragma comment(lib,"TKXSBase.lib")
#pragma comment(lib,"TKBool.lib")
#pragma comment(lib,"TKCAF.lib")
#pragma comment(lib,"TKCDF.lib")
#pragma comment(lib,"TKernel.lib")
#pragma comment(lib,"TKFeat.lib")
#pragma comment(lib,"TKFillet.lib")
#pragma comment(lib,"TKG2d.lib")
#pragma comment(lib,"TKG3d.lib")
#pragma comment(lib,"TKGeomAlgo.lib")
#pragma comment(lib,"TKGeomBase.lib")
#pragma comment(lib,"TKHLR.lib")
#pragma comment(lib,"TKMath.lib")
#pragma comment(lib,"TKOffset.lib")
#pragma comment(lib,"TKPrim.lib")
#pragma comment(lib,"TKService.lib")
#pragma comment(lib,"TKTopAlgo.lib")
#pragma comment(lib,"TKV3d.lib")
#pragma comment(lib,"TKOpenGl.lib")
#pragma comment(lib,"TKMesh.lib")
#pragma comment(lib,"TKBO.lib")

2.设置驱动环境

在 App 类头文件中初始化一个驱动设备对象的实例 myGraphicDriver

 class CMFCApplication1App : public CWinAppEx
{public:CMFCApplication1App() noexcept;Handle(Aspect_DisplayConnection) myDisplayConnection;Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver(myDisplayConnection);Handle(OpenGl_GraphicDriver) GetGraphicDriver() const { return aGraphicDriver; }//为C**App提供调用接口函数

3.设置View容器

在Doc类头文件中声明V3d_Viewer 和 AIS_InteractiveContext两个类
V3d_Viewer 是一个 V3d_View也就是视图的管理器(做一个承载)

public:Handle_V3d_Viewer myViewer;Handle_AIS_InteractiveContext myAISContext;Handle(V3d_Viewer) GetViewer() { return myViewer; }Handle(AIS_InteractiveContext)& GetAISContext() { return myAISContext; }

源文件构造中进行初始化

CMFCApplication1Doc::CMFCApplication1Doc() noexcept
{// TODO: 在此添加一次性构造代码Handle(Graphic3d_GraphicDriver) theGraphicDriver =((CMFCApplication1App*)AfxGetApp())->GetGraphicDriver();myViewer = new V3d_Viewer(theGraphicDriver);myViewer->SetDefaultLights();myViewer->SetLightOn();myAISContext = new AIS_InteractiveContext(myViewer);
}

4.在view绘制图形

做完了上边三步occ的view就已经基本配置完毕,接下来就是装在到窗口上,并且在上面绘制图形
下面是源文件内容

//将Occ的view绑到窗口的view上去
void CMFCApplication1View::OnInitialUpdate()
{myView = GetDocument()->GetViewer()->CreateView();bool myHlrModeIsOn = Standard_False;myView->SetComputedMode(myHlrModeIsOn);Handle(Graphic3d_GraphicDriver) theGraphicDriver = ((CMFCApplication1App*)AfxGetApp())->GetGraphicDriver();Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd());//,Quantity_NOC_MATRAGRAY);myView->SetWindow(aWNTWindow);//if(!aWNTWindow->IsMapped()) aWNTWindow->Map();
}

绘制图形方法(这里我就画一个长方体)

//绘制图形修改这里
void CMFCApplication1View::OnDraw(CDC* /*pDC*/)
{CMFCApplication1Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);if (!pDoc)return;// TODO: 在此处为本机数据添加绘制代码BRepBuilderAPI_MakePolygon MP;MP.Add(gp_Pnt(0, 0, 0));MP.Add(gp_Pnt(100, 0, 0));MP.Add(gp_Pnt(100, 100, 0));MP.Add(gp_Pnt(0, 100, 0));MP.Close();//完成构造 封闭空间TopoDS_Face F = BRepBuilderAPI_MakeFace(MP.Wire());gp_Vec aPrimVec(0, 0, 300);//拉伸 形成拉伸体TopoDS_Shape shape = BRepPrimAPI_MakePrism(F, aPrimVec);Handle(AIS_Shape) anAISShape = new AIS_Shape(shape);pDoc->myAISContext->Display(anAISShape);//绘制图形
}

5.最终呈现

本工程于vs2017用X64编译选项编译,完整工程代码可以密我(最近正在整理GitHub到时候会放到上边)

[C++] OpenCasCade空间几何库的模型展现相关推荐

  1. Opencascade源码学习之模型数据

    Opencascade源码学习之模型数据 1.模型数据 2.几何工具 1.插值和拟合 1.分析一组点 2.基本插值和近似 3.2D 插值 4.3D 插值 5.2D 拟合 6.3D 拟合 7.曲面拟合 ...

  2. JTS Java空间几何计算、距离、最近点、subLine等计算

    文章目录 前言 地理坐标系和投影坐标系 地理坐标系 投影坐标系 地图投影 墨卡托/Web墨卡托 常见坐标系 地理坐标系和投影坐标系互转 EPSG:3857和EPSG:4326 Java各坐标系之间的转 ...

  3. JTS Java空间几何计算、距离、最近点、subLine等 稳健的一比,持续更新中

    文章目录 前言 地理坐标系和投影坐标系 地理坐标系 投影坐标系 地图投影 墨卡托/Web墨卡托 常见坐标系 地理坐标系和投影坐标系互转 EPSG:3857和EPSG:4326 Java各坐标系之间的转 ...

  4. Opencascade源码学习之模型算法_TKO模块文件介绍

    Opencascade源码学习之模型数据_TKO模块文件介绍 1.TKO 1.BOPAlgo 2.BOPDS 3.BOPTools 4.BRepAlgoAPI 5.IntTools 1.TKO 1.B ...

  5. Opencascade源码学习之模型数据——TKGeomBase模块文件介绍

    Opencascade源码学习之模型数据--TKGeomBase模块文件介绍 1.AdvApp2Var 2.AppCont 3.AppDef 4.AppParCurves 5.Approx 6.Bnd ...

  6. 30分钟学会shapely空间几何分析

    shapely是python中开源的空间几何对象库,支持Point(点),LineString(线),        Polygon(面)等几何对象及相关空间操作. 公众号后台回复关键字:" ...

  7. 1.用户界面原理和界面库编程模型

    从最早的图形用户界面操作系统Apply Lisa,到空前的windows 1.0,再到最新的Windows.苹果.Linux操作系统,图形用户界面已经是个人电脑不可缺少的部分.图形用户界面的发展是建立 ...

  8. 开源的前端GIS空间分析库介绍 (一)jsts与turf

    文章目录 1 前言 2 JSTS 3 turf 4 安装使用 4.1 jsts 4.1.1 直接引入 4.1.2 NPM 4.2 turf 4.1.1 直接引入 4.1.2 NPM 5 空间分析 5. ...

  9. 开源的前端GIS空间分析库介绍 (三)turf与ol结合

    前言 turf是mapbox出品的前端空间分析库,官网:http://turfjs.org/ turf库中包含的空间分析计算功能比较多,也非常简单易用.相比于jsts,turf的官方文档维护的非常好, ...

最新文章

  1. 多媒体音量条显示异常跳动
  2. (C++)1037 在霍格沃茨找零钱的两种解法
  3. 绝密 | 机器学习老手不会轻易告诉你的12件事儿
  4. Android 游戏开发必备的基础知识
  5. mysql去除输入的字符串中的中文_Sql得到(去除)字符串中所有汉字,字母,数字的函数...
  6. ZedGraph怎样实现将图形右键菜单的打印和页面设置合并为打印的二级子菜单
  7. Promise学习——解决回调地狱问题
  8. asp.net937-图书馆座位管理系统
  9. VMware 镜像安装
  10. mouseenter、mouseleave、mouseover和mouseout的区别
  11. 关于matlab表情包,matlab表情包 - matlab微信表情包 - matlabQQ表情包 - 发表情 fabiaoqing.com...
  12. 深度学习优化策略---权重、权重初始化与权重衰减
  13. 中超16强内援转会更新 陕西重金打造中国银河战舰
  14. Alibaba(实习准备)—SOFARPC学习总结
  15. 用java制作扑克牌_java实现简单扑克牌游戏
  16. 人工智能之人工神经网络
  17. 工业物联网安全需要一揽子服务商
  18. 数据结构与算法之左高树
  19. Netty网络编程(三):Channel详解
  20. 中国最初开始发展计算机是在哪一年,中国从哪一年开始有手机了,手机出现最早的城市在哪里...

热门文章

  1. 无线蓝牙模块增加传输距离的几个小技巧
  2. Rust学习(1)[rand]Rng::gen_range在0.8版本改动与生成随机数
  3. rs232接口_充分利用M.2接口:乐扩M.2转2口RS232串口卡
  4. 【iMessage苹果源码家庭推】tils扩大软件安装大概释放事变是由程序员筑造的,很轻易发生MemoryLeak控制
  5. 图像数据增强方法一览(附python代码)
  6. ubuntu 图片剪裁
  7. 中国经济下一步何去何从?
  8. 欧拉角表示的旋转相乘计算
  9. python进阶练习之——求未知数❤️
  10. 会议报道丨心语心“悦”——抑郁症诊疗进展“大咖”谈(三)