Qt with OpenCascade
Qt with OpenCascade
摘要Abstract:详细介绍了如何在Qt中使用OpenCascade。
关键字Key Words:Qt、OpenCascade
一、引言 Introduction
1.1 Overview of Qt
Qt是1991年奇趣科技开发的一个跨平台的C++图形用户界面应用程序框架。它提供给应用程序开发者建立艺术级的图形用户界面所需的所有功能。Qt很容易扩展,并且允许真正地组件编程。基本上,Qt同X Window上的Motif,Openwin,GTK等图形界面库和Windows平台上的MFC,OWL,VCL,ATL是同类型的东西。
Qt具有如下优点:
l 优良的跨平台特性:Qt支持下列操作系统:Microsoft Windows 95/98, NT, Linux, Solaris, SunOS, HP-UX, FreeBSD, SCO等;
l 面向对象:Qt良好的封装机制使得Qt的模块化程序非常高,可重用性较好,对于用户开发来说是非常方便的。Qt提供了一种称为signals/slots的安全类型来替代callback,这使得各个元件之间的协同工作变得非常简单;
l 丰富的API:Qt包含多达250个以上的C++类,还提供基于模板的collections, serialization, file, I/O device, directory management, data/time类。甚至还包括正则表达式的处理功能;
l 支持2D、3D图形渲染,支持OpenGL;
l 大量的开发文档;
l XML支持;
Qt按不同的版本进行发布:
n Qt商业版:提供给商业软件开发。它们提供传统商业软件发行版并且提供在协议有效期内的免费升级和技术支持服务。
n Qt开源版:仅为了开发自由和开放源码软件,提供了和商业版同样的功能。GNU通用公共许可证下,它是免费的。
2009年3月发布的Qt4.5起,NOKIA为Qt增添了开源LGPL授权选择。
1.2 Overview of OpenCascacde
OpenCascade(简称OCC)平台是由法国Matra Datavision公司开发的CAD/CAE/CAM软件平台,可以说是世界上最重要的几何造型平台之一。开源OCC对象库是一个面向对象的C++类库,用于快速设计领域的专业应用程序。OCC主要用于开发二维和三维几何建模应用程序,包括通用的或专业的计算机辅助设计(CAD)系统、计算机辅助制造(CAM)系统或分析领域的应用程序、仿真应用程序或图形演示工具。OCC通过有机组织的C++库文件提供了六个模块:
l FoundationClasses
l ModelingData
l ModelingAlgorithms
l Visualization
l ApplicationFramework
l DataExchange
OCCT库提供如下功能:
l 2D和3D几何造型工具箱,可对任何物体造型;
n 创建基本图元,如prism,cylinder, cone, torus;
n 对实体进行布尔操作,addition, subtraction and intersection;
n 根据倒圆、倒角、草图拉伸出几何实体;
n 使用偏移offsets、成壳shelling、挖空hollowing和挤压sweeps构造几何实体;
n 计算几何实体属性,如表面积、体积、重心、曲率半径;
n 使用插值interpolation、逼近approximation、投影projection计算出几何体;
l 可视化功能提供对几何实体的显示、控制功能,例如:
n 三维旋转3D rotation;
n 缩放Zoom;
n 着色Shading;
l 程序框架提供如下功能:
n 将非几何数据与几何实体关联;
n 参数化模型;
n Java Application Desktop(JAD);
OCCT库是由Open CASCADE公司开发和市场运作的。库被设计成模块化和易扩展。
![]()
Figure 1.1 OpenCascade架构图
二、Qt + OpenCascade
使用的开发工具为Qt Creator 2.7.0,Qt的版本为Qt 5.0.2。如下图所示:
![]()
Figure 3.1 Qt and Qt Creator version Info
OpenCascade的版本为OpenCASCADE6.5.5,如下图所示:
![]()
Figure 3.2 OpenCascade Version Info
在OpenCascade中创建三维场景的步骤分为:
1.Create attributes.
2.Create a 3D viewer.
3.Create a view.
4.Create an interactive context.
5.Create interactive objects.
6.Create primitives in the interactive object.
7.Display the interactive object.
详细说明请参考《Visualization User’s Guide》。下面结合程序代码进行说明。
1. Create attributes.
略;
2. Create a 3D viewer.
// Create a 3D viewer.
try
{
myGraphicDevice = new Graphic3d_WNTGraphicDevice;
}
catch (Standard_Failure)
{
QMessageBox::critical(this, tr("About occQt"),
tr("<h2>Fatal error in graphic initialisation!</h2>"),
QMessageBox::Apply);
} myViewer = new V3d_Viewer(myGraphicDevice, Standard_ExtString("Visu3D"));
myViewer->Init();
myViewer->SetDefaultLights();
myViewer->SetLightOn();
3. Create a view.
// Create the view.
myView = theContext->CurrentViewer()->CreateView();
4. Create an interactive context.
// Create an interactive context.
myContext = new AIS_InteractiveContext(myViewer);
myContext->SetDisplayMode(AIS_Shaded);
5. Create interactive objects.
略;
6. Create primitives in the interactive object.
Handle_AIS_Shape aBox = new AIS_Shape(MF.Shape());
Handle_AIS_Shape aCone = new AIS_Shape(BRepPrimAPI_MakeCone(, , ));
Handle_AIS_Shape aSphere = new AIS_Shape(BRepPrimAPI_MakeSphere());
7. Display the interactive object.
myContext->Display(aBox);
myContext->Display(aCone);
myContext->Display(aSphere);
三、结论 Conclusion
编译过程中遇到一些问题,主要是头文件包含及库引用问题。需要对Qt工程文件做如下设置:
l 因为程序使用了QGLWidget,所以在其工程中要引用OpenGL的库。设置方法如下:
QT += core gui opengl;
l 头文件目录的设置:
INCLUDEPATH += D:\OpenCASCADE6.5.5\ros\inc;
l 引用库的设置:
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKernel.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKMath.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKBRep.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKTopAlgo.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKPrim.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKService.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKV3d.lib
LIBS += D:\OpenCASCADE6.5.5\ros\win64\vc11\libd\TKFillet.lib
上述目录根据不同的计算机需要做相应修改。程序运行结果如下图所示:
![]()
Figure 3.1 Sphere in occQt
PDF Version and Sample Code: Qt with OpenCascade
Qt with OpenCascade的更多相关文章
- A Simple OpenCASCADE Qt Demo-occQt
A Simple OpenCASCADE Qt Demo-occQt eryar@163.com Abstract. OpenCASCADE have provided the Qt samples ...
- Use Qt in Debian for OpenCASCADE
Use Qt in Debian for OpenCASCADE eryar@163.com Recently several OpenCASCADE enthusiasts want to buil ...
- OpenCascade极简环境搭建(QT环境)
现在网上关于OpenCascade(OCCT)的环境搭建几乎都是下载源码,然后实时MinGW来编译生成源码.但是,官方有提供Windows平台下的可执行文件,如果想快速了解OpenCascade(OC ...
- OpenGL Shader in OpenCASCADE
OpenGL Shader in OpenCASCADE eryar@163.com Abstract. As implementation of one of the strategic steps ...
- Undo/Redo for Qt Tree Model
Undo/Redo for Qt Tree Model eryar@163.com Abstract. Qt contains a set of item view classes that use ...
- Qt Undo Framework Demo
Qt Undo Framework Demo eryar@163.com Abstract. Qt’s Undo Framework is an implementation of the Comma ...
- OpenCASCADE JT Assistant
OpenCASCADE JT Assistant eryar@163.com Abstract. Siemens’ JT data format accepted as the world’s fir ...
- Hello World of OpenCascade
Hello World of OpenCascade eryar@163.com 摘要Abstract:以一个经典的Hello World程序为例开始对开源几何造型内核OpenCascade的学习. ...
- Building third-party products of OpenCascade
Building third-party products of OpenCascade eryar@163.com Available distributives of third-party pr ...
随机推荐
- T-SQL Recipes之Dynamic PIVOT and UNPIVOT
PIVOT PIVOT在行转列的时候经常用到,最便捷的方式就是通过示例来理解它的作用. 示例1 Query to Return Select Product Data from AdventureWo ...
- Leetcode Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...
- 闭包和重写函数 返回IE浏览器版本号
开发过程中我们有时候需要知道IE的版本号,我们知道得到IE的版本号的方法: var v = 3, div = document.createElement('div'), all = div.getE ...
- cocoapods
iOS 最新版 CocoaPods 的安装流程 1.移除现有Ruby默认源 $gem sources --remove https://rubygems.org/ 2.使用新的源 $gem sourc ...
- css3复杂选择器+内容生成+Css Hack
1.复杂选择器2.内容生成3.多列4.CSS Hack(浏览器兼容性)=======================================1.复杂选择器 1.兄弟选择器 1.特点: 1.通过 ...
- android webView开发之js调用java代码示例
1.webView设置 webView.getSettings().setJavaScriptEnabled(true);//设置支持js webView.addJavascriptInterface ...
- JSPatch 中 defineClass 中覆盖方法的使用
今天研究了一下JSPatch,发现好神奇好奇妙,感觉这几天我都会乐此不彼的去研究这个高大上的东西. 出处来着:https://github.com/bang590/JSPatch 简单介绍一下这个 d ...
- problem-eclipse创建maven项目报错
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of ...
- 不用css3的响应式img(按比例缩小图片)
有时候自己为了控制图片的响应式,按比例缩小放大图片,如果解决这个问题,用js吧,很麻烦.也会损失很大的加载运行速度等:所以我们还是用css来解决这个问题,用css来强制按比例压缩图片的高度或宽度,看代 ...
- <!DOCTYPE html>很重要
噩梦开始的源头:之前写html或者jsp页面,从来不注意doctype的声明,也不太明白doctype的作用.直到最近碰到了一个非常奇葩的 bug:某一个页面在IE7和8,Chrome,ff等下正常, ...