【无标题】Qt 3D 可视化demo

#pragma once

#include <QtWidgets/QWidget>
#include "ui_Saser_project_0001.h"
#include <qboxlayout.h>

#include <QTimer>

#include <qtdatavisualizationversion.h>
#include <q3dscatter.h>
#include <qscatter3dseries.h>
#include <QCustom3DLabel>

using namespace QtDataVisualization;

class Saser_project_0001 : public QWidget
{
    Q_OBJECT

public:
    Saser_project_0001(QWidget *parent = Q_NULLPTR);

    QTimer* testTime;

public slots:
    void timeout();

private:
    Ui::Saser_project_0001Class ui;

    /// <summary>
/// 设置分组样式
/// </summary>
/// <param name="parent"></param>
    QScatter3DSeries* _GroupType1 ;
    QScatter3DSeries* _GroupType2 ;
    QScatter3DSeries* _GroupType3 ;

};
#include "Saser_project_0001.h"

Saser_project_0001::Saser_project_0001(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);

    /// <summary>
    /// 3D Widget init
    /// </summary>
    /// <param name="parent"></param>
    Q3DScatter* _Group = new Q3DScatter();
    QWidget* _3DWidget = QWidget::createWindowContainer(_Group);

    /// <summary>
    /// 设置坐标轴范围
    /// </summary>
    /// <param name="parent"></param>
    _Group->axisX()->setRange(-300, 300);
    _Group->axisZ()->setRange(-300, 300);
    _Group->axisY()->setRange(0, 50);

    /// <summary>
    /// 设置坐标轴刻度值显示内容
    /// </summary>
    /// <param name="parent"></param>
    _Group->axisX()->setLabelFormat("%d m");
    _Group->axisY()->setLabelFormat("%.4f m");

    /// <summary>
    /// 设置坐标轴刻度密度,不得小于1
    /// </summary>
    /// <param name="parent"></param>
    _Group->axisX()->setSegmentCount(10);
    _Group->axisZ()->setSegmentCount(31);
    _Group->axisY()->setSegmentCount(1);

    /// <summary>
    /// 设置刻度线密度(每个线段中的子线段的数量)
    /// </summary>
    /// <param name="parent"></param>
    _Group->axisX()->setSubSegmentCount(2);
    _Group->axisZ()->setSubSegmentCount(2);

    /// <summary>
    /// 设置坐标轴 抬头
    /// </summary>
    /// <param name="parent"></param>
    _Group->axisX()->setTitle("Let");
    _Group->axisZ()->setTitle("Long");
    _Group->axisY()->setTitle("height");

    /// <summary>
    /// 设置坐标轴 抬头 可见/不可见
    /// </summary>
    /// <param name="parent"></param>
    _Group->axisX()->setTitleVisible(true);
    _Group->axisZ()->setTitleVisible(true);
    _Group->axisY()->setTitleVisible(false);


    /// <summary>
    /// 设置 主题样式
    ///   _Group->activeTheme()
    ///  使用Qt预设 : Q3DTheme::ThemeStoneMoss
    /// </summary>
    /// <param name="parent"></param>
    _Group->activeTheme()->setType(Q3DTheme::ThemeEbony);

    /// <summary>
    /// 光源设置 
    ///  _Group->scene()->activeLight()
    /// </summary>
    /// <param name="parent"></param>
    _Group->scene()->activeLight()->setAutoPosition(true); //跟随摄像机

    /// <summary>
    /// 摄像机
    /// _Group->scene()->activeCamera()
    /// </summary>
    /// <param name="parent"></param>
    _Group->scene()->activeCamera()->setCameraPosition(0.0f,0.0f,100.0f);

    /// <summary>
    /// 设置分组样式
    /// </summary>
    /// <param name="parent"></param>
    /*QScatter3DSeries**/ _GroupType1 = new QScatter3DSeries();
    /*QScatter3DSeries**/ _GroupType2 = new QScatter3DSeries();
    /*QScatter3DSeries**/ _GroupType3 = new QScatter3DSeries();

    _GroupType1->setMesh(QAbstract3DSeries::MeshSphere); //球体
    _GroupType1->setItemSize(0.03f);
    _GroupType1->setBaseColor(QColor(255, 0, 0));

    _GroupType2->setMesh(QAbstract3DSeries::MeshBar);    //长方体
    _GroupType2->setItemSize(0.03f);
    _GroupType2->setBaseColor(QColor(0, 255, 0));


    _GroupType3->setMesh(QAbstract3DSeries::MeshPyramid);    //四面体
    _GroupType3->setItemSize(0.03f);
    _GroupType3->setBaseColor(QColor(255, 0, 255));


    /// <summary>
    /// 添加数据分组
    /// </summary>
    /// <param name="parent"></param>
    _Group->addSeries(_GroupType1);
    _Group->addSeries(_GroupType2);
    _Group->addSeries(_GroupType3);


   
    

    /// <summary>
    /// 刷新球体数据 1
    /// </summary>
    /// <param name="parent"></param>
    QVector<QVector3D> _GroupType1_Data;
    _GroupType1_Data << QVector3D(0, 0, 0) << QVector3D(0, 50, 0) << QVector3D(0, 0, 50);

    QScatterDataArray* _dataArray1 = new QScatterDataArray();
    _dataArray1->resize(_GroupType1_Data.size());
    QScatterDataItem* ptrToDataArray1 = &_dataArray1->first();
    for (size_t i = 0; i < _GroupType1_Data.size(); i++)
    {
        ptrToDataArray1->setPosition(_GroupType1_Data[i]);
        ptrToDataArray1++;
    }
    _GroupType1->dataProxy()->resetArray(_dataArray1);
    // <summary>
    /// 刷新长方体数据 2
    /// </summary>
    /// <param name="parent"></param>
    QVector<QVector3D> _GroupType2_Data;
    _GroupType2_Data << QVector3D(50, 0, 0) << QVector3D(50, 50, 0) << QVector3D(50, 0,100);
    QScatterDataArray* _dataArray2 = new QScatterDataArray();
    for (size_t i = 0; i < _GroupType2_Data.size(); i++)
    {
        QScatterDataItem _ptrToDataArray;
        _ptrToDataArray.setPosition(_GroupType2_Data[i]);
        _dataArray2->append(_ptrToDataArray);

        /// <summary>
        /// 插入 描述文字
        /// </summary>
        /// <param name="parent"></param>
        QCustom3DLabel* tempLable = new QCustom3DLabel();
        tempLable->setText(QString("%1").arg(i));
        QVector3D temp((_GroupType2_Data[i]).x(), _GroupType2_Data[i].y() + 2, _GroupType2_Data[i].z());
        tempLable->setPosition(temp);
        tempLable->setScaling(QVector3D(0.3, 0.3, 0.3));
        tempLable->setBackgroundEnabled(false);
        //tempLable->setVisible(false);
        _Group->addCustomItem(tempLable);
    }
    _GroupType2->dataProxy()->resetArray(_dataArray2);
    // <summary>
    /// 刷新四面体数据 
    /// </summary>
    /// <param name="parent"></param>
    QVector<QVector3D> _GroupType3_Data;
    _GroupType3_Data << QVector3D(-50, 0, 0) << QVector3D(-50, 50, 0) << QVector3D(-50, 0, 150);
    QScatterDataArray* _dataArray3 = new QScatterDataArray();
    for (size_t i = 0; i < _GroupType3_Data.size(); i++)
    {
        QScatterDataItem _ptrToDataArray;
        _ptrToDataArray.setPosition(_GroupType3_Data[i]);
        _dataArray3->append(_ptrToDataArray);
    }
    _GroupType3->dataProxy()->resetArray(_dataArray3);


    /// <summary>
    /// init layout
    /// </summary>[[]]
    /// <param name="parent"></param>
    QVBoxLayout* qMainlayout = new QVBoxLayout;
    this->setLayout(qMainlayout);
    qMainlayout->addWidget(_3DWidget);



    testTime = new QTimer();
    connect(testTime, SIGNAL(timeout()), this, SLOT(timeout()));

    testTime->start(50);
}


void Saser_project_0001::timeout()
{
    static double z =-300;
    static double  x = -10;
    static double y = 0;

    QVector<QVector3D> _GroupType1_Data;
    if (z >= 300)
    {
        z = 0;

    }
    if (x >= 10)
    {
        x = -10;
    }

    if (y >= 50)
    {
        y = 0;
    }

   
    _GroupType1_Data << QVector3D(x++, y++, z++) ;
    for (size_t i = 0; i < 1000; i++)
    {
        _GroupType1_Data << QVector3D(x + (i*1.0 / 10), y, z +(i*1.0 / 40));
    }

    QScatterDataArray* _dataArray1 = new QScatterDataArray();
    _dataArray1->resize(_GroupType1_Data.size());
    QScatterDataItem* ptrToDataArray1 = &_dataArray1->first();
    for (size_t i = 0; i < _GroupType1_Data.size(); i++)
    {
        ptrToDataArray1->setPosition(_GroupType1_Data[i]);
        ptrToDataArray1++;
    }
    _GroupType1->dataProxy()->resetArray(_dataArray1);


}
This directory contains the Qt3D project for Qt5: * Qt3D QML bindings and * Qt3D C++ APIs Building Qt3D ================== Qt5 is a rapidly changing bleeding edge environment. This branch is our initial support for it and thus is also rapidly changing and bleeding edge. This branch is experimental, and unsupported. This information is provided for advanced use only. No guarantees about API stability or even if this works at all are supplied, use at your own risk. First fetch the Qt5 source tree and Qt3D master branch: cd ~/depot git clone ssh://codereview.qt-project.org:29418/qt/qt5.git cd qt5 ./init-repository --codereview-username \ --module-subset=qtbase,qtsvg,qtdeclarative,qttools,qtxmlpatterns,qtdoc,qlalr,qtrepotools,qtqa,qtlocation,qt3d git submodule foreach "git fetch gerrit && git reset --hard gerrit/master" cd qt3d scp -p -P 29418 codereview.qt-project.org:hooks/commit-msg .git/hooks/ git fetch gerrit git checkout --track -b master gerrit/master If you are reading this file then somehow you probably already got this far anyway. Now build Qt5, which will also build Qt3D as a module: cd ~/build mkdir qt5 cd qt5 ~/depot/qt5/configure -developer-build -opensource -confirm-license -no-webkit -no-phonon -nomake tests \ -nomake examples -declarative -opengl -svg && make -j 4 What&#39;s in Qt3D ================== Directory structure: src/threed/ This is the main library of the Qt3D project, containing abstractions for cross-platform GL, shaders, lighting models, and so on. src/plugins/ Scene format loading plugins. src/imports/ QML import plugins. util/ Various utilities that are useful when working with Qt3D. examples/ Some examples of using Qt3D QML bindings and Qt3D C++ API. demos/ Some more complex demos of using Qt3D QML bindings and Qt3D C++ API. tests/auto/qml3d/ Unit tests for the QML bindings. tests/auto/threed/ Unit tests for the C++ API doc/ Documentation. devices/symbian/ Symbian deployment file Documentation ============= The documentation can be generated with "make docs". It will be placed into "doc/html" in the build directory. Packages ======== This section is only for those developing Qt3D. Read on to discover how the building of packages works. This section is also important if you want to change how the structure of the Qt3D pro files work. To build Qt3D, run: qmake && make The .pro files will cause the toolchain to place the libraries, QML files and meshes of Qt3D directly into place, as part of the compile process. The files go into the bin/ directory, and the executables can be run directly from there. If you are doing a developer build, plugins will be installed in such a way that Qt will find them. After building the tree the install step is invoked using the INSTALL_ROOT environment export to cause the installation rules to place all the files into a sandboxed install tree, ready for packaging: INSTALL_ROOT=tmp make install Examples ======== Some examples require assimp library to parse the content. Go to http://assimp.sourceforge.net/ and build and install the assimp library. Then configure Qt3D to include assimp and run qmake && make.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值