10-1_Qt 5.9 C++开发指南_Data Visualization实现数据三维显示

本文介绍了Qt5.7及以上版本中DataVisualization模块,涵盖其在三维柱状图、散点图和曲面显示的应用,以及数据代理和坐标轴类的使用。通过实例展示了如何在项目中集成和使用这些功能。

Data Visualization 是 Qt 提供的用于数据三维显示的模块。在 Qt 5.7 以前只有商业版才有此模块,而从Qt5.7 开始此模块在社区版本里也可以免费使用了。Data Visualization 用于数据的三维显示,包括三维柱状图、三维空间散点、三维曲面等。Data Visualization 与 Qt Charts 类似,也是基于Qt的图形视图架构。Data Visualization 的功能无法和一些专业的三维显示类库相提并论,但是对于一些简单的三维数据显示是比较实用的,例如一些科学计算结果的三维显示。

本章介绍 Data Visualization 模块的一些主要功能的使用,主要是三维柱状图、三维空间散点和三维曲面的显示。

1. DataVisualization 模块概述

Data Visualization 的三维显示功能主要由 3种三维图形类来实现,分别是三维柱状图类Q3DBars,三维空间散点类Q3DScatter,三维曲面类Q3DSurface。这3 个类的父类是 QAbstract3DGraph,是从QWindow 继承而来的,继承关系如图10-1 所示。

在这里插入图片描述

Data Visualization与 Qt Charts 类似,都基于 Qt 的图形视图结构,所以一个三维图形也是由图表、序列、坐标轴等元素组成的。Q3DBars、Q3DScatter、Q3DSurface 相当于 Qt Charts 中的QChart,而每一种三维图形对应一种三维序列,Data Visualization 中的3种序列类见图10-2

在这里插入图片描述

一种序列类只能用于某种三维图形类,如QBar3DSeries只能用作三维柱状图Q3DBars 的序列而不能作为三维散点图 Q3DScatter 的序列。在一个图中可以有多个同类型的序列,如三维曲面图Q3DSurface 中可以有多个 QSurface3DSeries 序列,用于显示不同的曲面。

与QChart 有坐标轴类一样,三维图形也有坐标轴类。有两种三维坐标轴类,QValue3DAxis用于数值型坐标轴,QCategory3DAxis 用于文字型坐标轴,它们都继承自 QAbstract3DAxis(如图 10-3 所示)

在这里插入图片描述

Data Visualization 模块中有数据代理(data proxy)类,数据代理类就是与序列对应,用于存储序列的数据的类。因为三维图形类型不一样,存储数据的结构也不一样,例如三维散点序列 QSatter3DSerics 存储的是一些三维数据点的坐标,只需要用一维数组或列表就可以存储这些数据,而QSurface3DSeries 序列存储的数据点在水平面上是均匀网格分布的,需要二维数组才可以存储相应的数据。为此,对于每一种序列,都有一个数据代理类,它们都继承自QAbstractDataProxy,每个数据代理类还有一个基于项数据模型的数据代理子类(如图 10-4 所示)。

在这里插入图片描述

对于三维曲面序列 QSurface3DSeries,还有一个专门用于显示地图高程数据的数据代理类QHeightMapSurfaceDataProxy,可以将一个图片表示的高程数据显示为三维曲面。用户也可以根据需要从QAbstractDataProxy 继承,定义自己的数据代理类。

要在项目中使用 Data Visualization 模块,需要在项目配置文件中添加下面一行语句:

Qt += datavisualization

在使用 Data Visualization 模块中的类的头文件或源程序文件中,还需要加入下面两行语句。如果只需使用模块中的部分类,可以单独包含某些类。

#include <QtDataVisualization>
using namespace QtDataVisualization;

2. 利用 DataVisualization 模块实现数据三维显示

利用 DataVisualization 模块实现三维柱状图、三维散点图、三维曲面绘图、三维地形图实例需结合对应实例学习使用。

--------------------------- Qt Data Visualization 5.7.0 --------------------------- Qt Data Visualization module provides multiple graph types to visualize data in 3D space both with C++ and Qt Quick 2. System Requirements =================== - Qt 5.2.1 or newer - OpenGL 2.1 or newer (recommended) or OpenGL ES2 (reduced feature set) - Manipulating Qt Data Visualization graphs with QML Designer requires Qt Creator 3.3 or newer Building ======== Configure the project with qmake: qmake After running qmake, build the project with make: (Linux) make (Windows with MinGw) mingw32-make (Windows with Visual Studio) nmake (OS X) make The above generates the default makefiles for your configuration, which is typically the release build if you are using precompiled binary Qt distribution. To build both debug and release, or one specifically, use one of the following qmake lines instead. For debug builds: qmake CONFIG+=debug make or qmake CONFIG+=debug_and_release make debug For release builds: qmake CONFIG+=release make or qmake CONFIG+=debug_and_release make release For both builds (Windows/OS X only): qmake CONFIG+="debug_and_release build_all" make After building, install the module to your Qt directory: make install If you want to uninstall the module: make uninstall Building as a statically linked library ======================================= The same as above applies, you will just have to add static to the CONFIG: qmake CONFIG+=static Documentation ============= The documentation can be generated with: make docs The documentation is generated into the doc folder under the build folder. Both Qt Assistant (qtdatavisualization.qch) and in HTML format (qtdatavisualization subfolder) documentation is generated. Please refer to the generated documentation for more information: doc/qtdatavisualization/qtdatavisualization-index.html Known Issues ============ - Some platforms like Android and WinRT cannot handle multiple native windows properly, so only the Qt Quick 2 versions of graphs are available in practice for those platforms. - Shadows are not supported with OpenGL ES2 (including Angle builds in Windows). - Anti-aliasing doesn&#39;t work with OpenGL ES2 (including Angle builds in Windows). - QCustom3DVolume items are not supported with OpenGL ES2 (including Angle builds in Windows). - Surfaces with non-straight rows and columns do not always render properly. - Q3DLight class (and Light3D QML item) are currently not usable for anything. - Changing most of Q3DScene properties affecting subviewports currently has no effect. - Widget based examples layout incorrectly in iOS. - Reparenting a graph to an item in another QQuickWindow is not supported. - Android builds of QML applications importing QtDataVisualization also require "QT += datavisualization" in the pro file. This is because Qt Data Visualization QML plugin has a dependency to Qt Data Visualization C++ library, which Qt Creator doesn&#39;t automatically add to the deployment package. - Only OpenGL ES2 emulation is available for software renderer (that is, when using QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十月旧城

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值