QT+OSG+OSG-earth如何在窗口显示一个地球

news2024/9/20 19:54:31

1、环境配置

 系统:windows10系统

QT:版本5.15.2        编译器:MSVC2019_64bit        编辑器:QT  Creator

OSG版本:3.7.0   64位      为MSVC环境下编译

osgQt:为第三方编译的库,OSG因为版本不同已经不提供osgQt的封装。

osg-earth版本: 3.6.0

2、如何导入相关的库

衔接:QT+OSG+osg-earth显示一个球-CSDN博客

QT的pro文件:

QT       += core gui
QT      +=opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \ 
    osgshowwidget.cpp

HEADERS += \  
    osgshowwidget.h

FORMS += \
    osgshowwidget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/osg370MSVC2019_64bit/OSG/lib/ -losg  -losgDB -losgUtil  -losgViewer  -losgGA   -losgWidget   -lOpenThreads
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/osg370MSVC2019_64bit/OSG/lib/ -losgd  -losgDBd -losgUtild  -losgViewerd  -losgGAd  -losgWidgetd -lOpenThreadsd
else:unix: LIBS += -L$$PWD/osg370MSVC2019_64bit/OSG/lib/ -losg  -losgDB -losgUtil  -losgViewer  -losgGA  -losgWidget   -lOpenThreads

INCLUDEPATH += $$PWD/osg370MSVC2019_64bit/OSG/include
DEPENDPATH += $$PWD/osg370MSVC2019_64bit/OSG/include



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/lib/ -losgQOpenGL
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/lib/ -losgQOpenGLd
else:unix: LIBS += -L$$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/lib/ -losgQOpenGL

INCLUDEPATH += $$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/include
DEPENDPATH += $$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/include



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarthd
else:unix: LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth

INCLUDEPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include
DEPENDPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarthd
else:unix: LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth

INCLUDEPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include
DEPENDPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include

3、代码部分

.h

#ifndef OSGSHOWWIDGET_H
#define OSGSHOWWIDGET_H

#include <QWidget>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include<osgGA/FlightManipulator>
#include <osgViewer/View>
#include <osg/ArgumentParser>
#include <osgGA/CameraManipulator>
#include <osgEarth/EarthManipulator>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>
#include <osg/ArgumentParser>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include<osgGA/FlightManipulator>
#include <osgViewer/View>
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osg/Timer>
#include <osg/ArgumentParser>
#include <osgGA/CameraManipulator>

namespace Ui {
class osgShowWidget;
}

class osgShowWidget : public QWidget
{
    Q_OBJECT

public:
    explicit osgShowWidget(QWidget *parent = nullptr);
    ~osgShowWidget();
protected slots:
    void initWindow();

protected:
    osgQOpenGLWidget* _pOsgQOpenGLWidget;
    osg::ref_ptr<osgViewer::Viewer> pViewer;

private:
    Ui::osgShowWidget *ui;
};

#endif // OSGSHOWWIDGET_H

.cpp

#include "osgshowwidget.h"
#include "ui_osgshowwidget.h"
#include <QCoreApplication>
#include <QApplication>
#include <QDir>
#include <QString>
#include <QDebug>
osgShowWidget::osgShowWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::osgShowWidget)
{
    ui->setupUi(this);
    this->move(0,0);
    ui->widget->move(0,0);
    _pOsgQOpenGLWidget = new osgQOpenGLWidget(ui->widget);
    _pOsgQOpenGLWidget->setGeometry(ui->widget->geometry());

    connect(_pOsgQOpenGLWidget, SIGNAL(initialized()), this, SLOT(initWindow()));



}

osgShowWidget::~osgShowWidget()
{
    delete ui;
   if(_pOsgQOpenGLWidget != NULL)
        delete _pOsgQOpenGLWidget;
}


void osgShowWidget::initWindow()
{
//    osgViewer::Viewer* pViewer = _pOsgQOpenGLWidget->getOsgViewer();
//    pViewer->setCameraManipulator(new osgGA::TrackballManipulator);
//    osg::Node* node = osgDB::readNodeFile("model/F-22.ive");
//    pViewer->setSceneData(node);
   QString exeDir = QCoreApplication::applicationDirPath();
   QDir::setCurrent(exeDir);

    osgEarth::initialize();
    osgViewer::Viewer* pViewer = _pOsgQOpenGLWidget->getOsgViewer();
    //初始化View
    //pViewer = getOsgViewer();
    //设置相机
    pViewer->setCameraManipulator(new osgEarth::Util::EarthManipulator);
    osg::ref_ptr<osg::Group> root;		//根节点
    osg::ref_ptr<osg::Node>	earth;		//地球节点
    root = new osg::Group;

    QString relativeEarthFilePath = "Maps/ocean.earth";  // 请替换为你实际的.earth文件相对路径
    QString earthFilePath = exeDir + "/" + relativeEarthFilePath;
    earth = osgDB::readNodeFile(earthFilePath.toStdString());
    if (!earth.valid())

        qDebug() << "File not found";
    root->addChild(earth.get());
    pViewer->setSceneData(root.get());
    pViewer->realize();





}

main.cpp

#include <QCoreApplication>
#include <QApplication>
#include <QDir>
#include "osgshowwidget.h"
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/EarthManipulator>
#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>
#include <osg/ArgumentParser>
#include <osgViewer/Viewer>

#include <QWidget>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include<osgGA/FlightManipulator>
#include <osgViewer/View>
#include <osgQOpenGL/osgQOpenGLWidget>

#include <osg/Timer>
#include <osg/ArgumentParser>
#include <osgGA/CameraManipulator>

int main(int argc, char *argv[])
{
        QApplication a(argc, argv);

//    // 获取可执行文件的目录

   osgShowWidget w;
   w.show();


    // 初始化osgViewer
    // 初始化osgEarth
//    osgEarth::initialize();
//    osg::ArgumentParser args(&argc, argv);

//    // 创建Viewer实例
//    osgViewer::Viewer viewer(args);

//    // 使用相对于exe的相对路径来构建.earth文件的完整路径
//    QString relativeEarthFilePath = "Maps/ocean.earth";  // 请替换为你实际的.earth文件相对路径
//    QString earthFilePath = exeDir + "/" + relativeEarthFilePath;

//    // 请替换为你实际的.earth文件路径
//    osg::ref_ptr<osg::Node> earthNode = osgDB::readNodeFile(earthFilePath.toStdString());

//    if (!earthNode) {
//        std::cerr << "Failed to load .earth file: " << earthFilePath.toStdString() << std::endl;
//        return -1;  // 如果加载失败,返回错误码
//    }

//    // 设置场景数据为加载的.earth文件
//    viewer.setSceneData(earthNode.get());

//    // 设置地球操控器
//    viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator(args));

//    // 运行Viewer
//    return viewer.run();



    return a.exec();
}

4、运行结果

5、出现的问题

不知道还qt的bug还是什么问题,我的窗口直接show出来会发生偏移,窗口出现的位置默认就不是在0.0处,必须写代码,move移动到0.0才行,这应该是qt兼容性问题,不是我代码的问题,所以我的代码有一部分对于正常显示qt界面也就不需要。

6、相关资料参考

QT+OSG+osg-earth显示一个球-CSDN博客

QT+OSG显示一个三维模型_qt+osg加载obj模型-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2130785.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【一文就懂】计算机视觉期刊和会议缩写

下面IEEE相关的期刊及其缩写&#xff0c;并重新整理为期刊和会议两个部分。 期刊缩写 期刊全称缩写IEEE Transactions on Pattern Analysis and Machine IntelligenceIEEE Trans. Pattern Anal. Mach. Intell.IEEE Transactions on Image ProcessingIEEE Trans. Image Proce…

用于大数据分析的数据存储格式:Parquet、Avro 和 ORC 的性能和成本影响

高效的数据处理对于依赖大数据分析做出明智决策的企业和组织至关重要。显著影响数据处理性能的一个关键因素是数据的存储格式。本文探讨了不同存储格式&#xff08;特别是 Parquet、Avro 和 ORC&#xff09;对 Google Cloud Platform &#xff08;GCP&#xff09; 上大数据环境…

机器学习--支持向量机(SVM)

支持向量机(线性) S V M SVM SVM 引入 S V M SVM SVM 用于解决的问题也是 c l a s s i f i c a t i o n classification classification&#xff0c;这里 y ∈ { − 1 , 1 } y \in \{-1, 1\} y∈{−1,1} 比如说这样一个需要分类的训练数据&#xff1a; 我们可以有很多直线来…

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉&#xff0c;那么对 shallowRef 和 shallowReactive 是否了解呢&#xff1f; 在编程和数据结构中&#xff0c;“shallow”&#xff08;浅层&#xff09;通常指对数据结构的最外层进行操作&#xff0c;而不递归地处理其内部或嵌套的数据…

Brave编译指南2024 Windows篇:安装Git(四)

1.引言 在编译Brave浏览器的过程中&#xff0c;Git是必不可少的工具之一。作为最流行的分布式版本控制系统&#xff0c;Git允许开发者高效地管理和协作开发源码。通过Git&#xff0c;您可以轻松获取、更新和提交Brave的源码版本&#xff0c;并跟踪所有更改记录。无论是独立开发…

大模型入门 ch 03:注意力机制

本文是github上的大模型教程LLMs-from-scratch的学习笔记&#xff0c;教程地址&#xff1a;教程链接 Chapter 3&#xff1a; Attention Mechanism 本文首先从固定参数的注意力机制说起&#xff0c;然后拓展到可以训练的注意力机制&#xff0c;然后加入掩码mask&#xff0c;最后…

基于 onsemi NCV78343 NCV78964的汽车矩阵式大灯方案

一、方案描述 大联大世平集团针对汽车矩阵大灯&#xff0c;推出 基于 onsemi NCV78343 & NCV78964的汽车矩阵式大灯方案。 开发板搭载的主要器件有 onsemi 的 Matrix Controller NCV78343、LED Driver NCV78964、Motor Driver NCV70517、以及 NXP 的 MCU S32K344。 二、开…

抖音微信超火国庆节国旗头像生成源码

源码介绍&#xff1a; 抖音微信超火国庆节国旗头像生成源码&#xff0c;静态页前端生成速度超快&#xff01;源码直接上传到服务器即可使用。 1、打开地址后点击上传->选一张你喜欢的头像->然后点右边箭头符合选款式->最后点保存头像->按照提示 2、保存到手机即…

开源多场景问答社区论坛Apache Answer本地部署并发布至公网使用

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

CCDO|数据跃动未来:首席数据官如何引领构建活数据引擎

在数字化浪潮汹涌澎湃的今天&#xff0c;数据已成为企业最宝贵的资产之一&#xff0c;它不仅记录着过去&#xff0c;更预示着未来的方向。随着大数据、人工智能、云计算等技术的飞速发展&#xff0c;数据的潜力被前所未有地激发&#xff0c;而首席数据官&#xff08;CDO&#x…

T4周:猴痘病识别

>- **&#x1f368; 本文为[&#x1f517;365天深度学习训练营](https://mp.weixin.qq.com/s/0dvHCaOoFnW8SCp3JpzKxg) 中的学习记录博客** >- **&#x1f356; 原作者&#xff1a;[K同学啊](https://mtyjkh.blog.csdn.net/)** 1. 设置GPU 如果使用的是CPU可以忽略这步 …

Eclipse折叠if、else、try catch的{}

下载插件com.cb.eclipse.folding_1.0.6.jar。将插件放到eclipse的dropins文件夹中。修改配置&#xff0c;然后保存&#xff0c;重启Eclipse即可。

Flink快速上手

Flink快速上手 批处理Maven配置pom文件java编写wordcount代码 有界流处理无界流处理 批处理 Maven配置pom文件 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://ww…

《深度学习》深度学习 框架、流程解析、动态展示及推导

目录 一、深度学习 1、什么是深度学习 2、特点 3、神经网络构造 1&#xff09;单层神经元 • 推导 • 示例 2&#xff09;多层神经网络 3&#xff09;小结 4、感知器 神经网络的本质 5、多层感知器 6、动态图像示例 1&#xff09;一个神经元 相当于下列状态&…

通信原理:绪论

1、消息、信号与信息 消息&#xff1a; 通信系统要传输的对象&#xff0c;是具体的、物理上存在的东西。也是信息的载体。形式多种&#xff1a; 连续消息&#xff1a;语音、温度、活动图片.离散消息&#xff1a;数据、符号、文字. 信息&#xff1a; 消息中所蕴含的内容&…

proteus+51单片机+实验(LCD1620、定时器)

目录 1.LCD1602液晶显示屏 1.1基本概念 1.1.1LCD的简介 1.1.2LCD的显示原理 ​​​1.1.3LCD的硬件电路 1.1.4LCD的常见指令 1.1.5LCD的时序 ​​​​​​​1.2代码 1.2.1写命令和写数据操作 1.2.2初始化和测试代码 1. 3.3功能函数 1.3proteus代码 1.3.1器件代码 1.…

几种手段mfc140u.dll丢失的解决方法,了解mfc140u.dll

在使用Windows操作系统时&#xff0c;许多用户可能会遇到“找不到mfc140u.dll”或“mfc140u.dll未找到”的错误提示。这个错误通常是由于该文件丢失或损坏所致。本文将详细介绍mfc140u.dll文件的作用、丢失的原因及其解决方法&#xff0c;帮助您快速恢复系统的正常运行。 一、m…

无人机视角的道路损害数据集,2400张图像,包括纵向裂缝(LC)、横向裂缝(TC)、鳄鱼裂缝(AC)、斜裂(OC)、修补(RP)和坑洞(PH),共2.3GB

数据集名称 无人机视角的道路损害数据集 数据集描述 这是一个专注于道路损害检测的数据集&#xff0c;包含了从无人机视角拍摄的2400张高清图像&#xff0c;涵盖了六种典型的道路损害类型&#xff1a;纵向裂缝&#xff08;LC&#xff09;、横向裂缝&#xff08;TC&#xff0…

c++ 点云生成二维俯视图

🙋 结果预览 一、代码实现 #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include

S7_1200配方功能快速入门

配方数据文件按照标准 CSV 格式存储在 S7-1200 CPU 装载存储器或 S7-1200 SIMATIC 存储卡“程序卡”中。分别可通过 PLC Web 服务器或对于存储卡文件操作&#xff0c;将数据文件传送到 PC 进行管理和查看。也可将修改过后的配方数据文件上传至PLC&#xff0c;再通过“RecipeImp…