QML 3D曲面图(Surface3D)技术

3D曲面图是科学计算和工程可视化中常用的图表类型,它通过起伏的曲面展示二维数据的变化趋势。Qt Data Visualization 模块中的 Surface3D 类型提供了强大的曲面可视化能力。

Surface3D 核心属性与方法

表:Surface3D主要属性与方法

属性/方法 类型 描述 示例
width real 曲面图宽度 width: parent.width
height real 曲面图高度 height: parent.height
selectionMode enum 选择模式(无/单项/行/列/行与列/切片) AbstractGraph3D.SelectionItem
shadowQuality enum 阴影质量(无/低/中/高/软低/软中/软高) AbstractGraph3D.ShadowQualityHigh
scene.activeCamera Q3DCamera 控制场景相机 scene.activeCamera.xRotation: 60.0
theme Theme3D 设置图表主题 theme: Theme3D { type: Theme3D.ThemeArmyBlue }
axisX Value3DAxis X轴配置 axisX: Value3DAxis { title: "经度"; min: -180; max: 180 }
axisY Value3DAxis Y轴配置 axisY: Value3DAxis { title: "高度"; min: 0; max: 10000 }
axisZ Value3DAxis Z轴配置 axisZ: Value3DAxis { title: "纬度"; min: -90; max: 90 }
flipHorizontalGrid bool 是否翻转水平网格 flipHorizontalGrid: true
surfaceSeries list 曲面系列列表 surfaceSeries: [heightMapSeries, temperatureSeries]
addSeries() method 添加曲面系列 surface3D.addSeries(newSeries)
removeSeries() method 移除曲面系列 surface3D.removeSeries(oldSeries)
release() method 释放资源 Component.onDestruction: surface3D.release()

基本曲面图实现

以下是一个完整的地形高度图示例,展示了如何使用Surface3D显示地理高程数据:

复制代码
import QtQuick
import QtQuick.Controls
import QtDataVisualization

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    
    Surface3D {
        id: surfaceGraph
        anchors.fill: parent
        theme: Theme3D { type: Theme3D.ThemeArmyBlue }
        
        // 设置坐标轴
        axisX: ValueAxis3D {
            title: "东西方向 (km)"
        }
        
        axisY: ValueAxis3D {
            title: "高度 (m)"
            min: 30
            max: 200
        }
        
        axisZ: ValueAxis3D {
            title: "南北方向 (km)"
        }
        
        // 添加曲面系列
        Surface3DSeries {
            id: terrainSeries
            itemLabelFormat: "(@xLabel km, @zLabel km): @yLabel m"
            drawMode: Surface3DSeries.DrawSurfaceAndWireframe
            flatShadingEnabled: false
            
            // 使用高度图数据代理
            HeightMapSurfaceDataProxy {
                id: heightMapProxy
                heightMapFile: ":/layer_1.png"
            }
            
            // 自定义渐变颜色
            baseGradient: ColorGradient {
                ColorGradientStop { position: 0.0; color: "#0000ff" }  // 深水区
                ColorGradientStop { position: 0.2; color: "#00ffff" }  // 浅水区
                ColorGradientStop { position: 0.25; color: "#00aa00" } // 海滩
                ColorGradientStop { position: 0.5; color: "#ffff00" }  // 平原
                ColorGradientStop { position: 0.75; color: "#aa5500" } // 山地
                ColorGradientStop { position: 1.0; color: "#ffffff" } // 雪山
            }
            
            // 网格线样式
            wireframeColor: "#555555"
        }
        
        // 相机初始位置
        scene.activeCamera.xRotation: 20.0
        scene.activeCamera.yRotation: 45.0
    }
    
    // 控制面板
    Row {
        anchors.top: parent.top
        anchors.right: parent.right
        spacing: 10
        padding: 10
        
        Button {
            text: "俯视图"
            onClicked: {
                surfaceGraph.scene.activeCamera.cameraPreset = Camera3D.CameraPresetFrontHigh
            }
        }
        
        Button {
            text: "侧视图"
            onClicked: {
                surfaceGraph.scene.activeCamera.cameraPreset = Camera3D.CameraPresetRightLow
            }
        }
        
        Button {
            text: "等轴测"
            onClicked: {
                surfaceGraph.scene.activeCamera.cameraPreset = Camera3D.CameraPresetIsometricRight
            }
        }
        
        ComboBox {
            id: drawModeCombo
            model: ["Surface", "Wireframe", "Both"]
            onCurrentIndexChanged: {
                switch(currentIndex) {
                case 0: terrainSeries.drawMode = Surface3DSeries.DrawSurface; break;
                case 1: terrainSeries.drawMode = Surface3DSeries.DrawWireframe; break;
                case 2: terrainSeries.drawMode = Surface3DSeries.DrawSurfaceAndWireframe; break;
                }
            }
        }
    }
}
相关推荐
Quz8 小时前
QML MouseArea:鼠标拖拽与滚轮缩放
qt·qml
PhotonixBay15 小时前
3D共聚焦显微镜与探针式粗糙度仪:谁更适合亚表面损伤检测?
图像处理·人工智能·测试工具·3d
自动化监测Learner17 小时前
Cesium 加载大雁塔 3D Tiles 实录:从模型结构剖析到局部虚拟化(剖切 + 骨架线)实现
3d
FOORIR 客流统计19 小时前
智能客流系统未来趋势:3D视觉、AI识别与数据分析的融合架构
人工智能·3d·数据分析
3D小将1 天前
3D格式转换之Rhino转换为IGS格式技术
3d·stp模型·igs模型·glb模型
PhotonixBay2 天前
InGaAs微透镜3D形貌怎么测?共聚焦显微镜在光通信的应用实践
功能测试·测试工具·3d·测试标准
学习星球2 天前
AI 一句话生成 3D 游戏世界:腾讯 HY-World 2.0 开源深度解析与本地实战
开发语言·人工智能·游戏·3d·ai·课程设计·ai编程
ai小陈2 天前
Hunyuan3D-2云端部署实战:图生3D、文生3D怎么跑更稳
人工智能·科技·3d·ai·音视频·gpu算力
独立开发之道3 天前
Three.js 创建 VR 内容:四步把一个普通 3D 场景送进头显
javascript·3d·vr
k4m7v2pz3 天前
Bevy 0.18.1 雨雪天气粒子系统排障实录:四个“想当然“如何让 3D/2D 粒子全部不可见
3d·游戏开发·3d渲染·bevy·天气粒子·2d渲染