osg qt ifc

Posted herd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了osg qt ifc相关的知识,希望对你有一定的参考价值。

ui_ifcproject_20190702.h

#pragma once
/********************************************************************************
** Form generated from reading UI file ‘ifcproject_201907.ui‘
**
** Created by: Qt User Interface Compiler version 5.12.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_IFCPROJECT_201907_H
#define UI_IFCPROJECT_201907_H

#include <QFile>
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>

#include <QTableView>
#include <QDockWidget>
#include <QSplitter>

QT_BEGIN_NAMESPACE

class Ui_IFCProject_201907Class

public:
    QMenuBar *menuBar;
    QToolBar *mainToolBar;
    QWidget *centralWidget;
    QStatusBar *statusBar;
    QSplitter *qsplitter1;
    QHBoxLayout *horizontalLayout;


    QDockWidget *centerDockWidget;

    void setupUi(QMainWindow *IFCProject_201907Class)
    
        if (IFCProject_201907Class->objectName().isEmpty())
            IFCProject_201907Class->setObjectName(QString::fromUtf8("IFCProject_201907Class"));
        
        //QFile stylefile("F:\\\\IFCProject\\\\IFCProject_201907\\\\IFCProject_201907\\\\Resources\\\\styles.qss");
        QFile stylefile("./Resources/styles.qss");

        stylefile.open(QFile::ReadOnly);
        QString styleSheet = QLatin1String(stylefile.readAll());
        IFCProject_201907Class->setStyleSheet(styleSheet);
        
        IFCProject_201907Class->resize(600, 400);
        menuBar = new QMenuBar(IFCProject_201907Class);
        menuBar->setObjectName(QString::fromUtf8("menuBar"));
        IFCProject_201907Class->setMenuBar(menuBar);

        mainToolBar = new QToolBar(IFCProject_201907Class);
        mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
        IFCProject_201907Class->addToolBar(mainToolBar);

        centralWidget = new QWidget(IFCProject_201907Class);
        centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
        IFCProject_201907Class->setCentralWidget(centralWidget);
        //IFCProject_201907Class->addDockWidget();

        horizontalLayout = new QHBoxLayout(centralWidget);
        horizontalLayout->setSpacing(6);
        horizontalLayout->setContentsMargins(11, 11, 11, 11);
        horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));

        qsplitter1 = new QSplitter(centralWidget);
        

        QDockWidget *dock = new QDockWidget(qsplitter1);
        dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        //addDockWidget(Qt::RightDockWidgetArea, dock);
        //dock->setTitleBarWidget(IFCProject_201907Class);
        //IFCProject_201907Class->addDockWidget(Qt::LeftDockWidgetArea, dock);
        qsplitter1->addWidget(dock);
        //qsplitter1->setOrientation(Qt::Vertical);
        qsplitter1->setOrientation(Qt::Horizontal);

        
        centerDockWidget = new QDockWidget(qsplitter1);
        //IFCProject_201907Class->addDockWidget(Qt::LeftDockWidgetArea, centerDockWidget);

        QTableView *tableView1 = new QTableView(dock);
        tableView1->setMinimumHeight(500);
        dock->setWidget(tableView1);

        qsplitter1->addWidget(centerDockWidget);
        

        QDockWidget *dockRight = new QDockWidget(qsplitter1);
        dockRight->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        //addDockWidget(Qt::RightDockWidgetArea, dock);
        //IFCProject_201907Class->addDockWidget(Qt::RightDockWidgetArea, dockRight);
        qsplitter1->addWidget(dockRight);

        horizontalLayout->addWidget(qsplitter1);







        statusBar = new QStatusBar(IFCProject_201907Class);
        statusBar->setObjectName(QString::fromUtf8("statusBar"));
        IFCProject_201907Class->setStatusBar(statusBar);

        retranslateUi(IFCProject_201907Class);

        QMetaObject::connectSlotsByName(IFCProject_201907Class);
     // setupUi

    void retranslateUi(QMainWindow *IFCProject_201907Class)
    
        IFCProject_201907Class->setWindowTitle(QApplication::translate("IFCProject_201907Class", "IFCProject_201907", nullptr));
     // retranslateUi

;

namespace Ui 
    class IFCProject_201907Class : public Ui_IFCProject_201907Class ;
 // namespace Ui

QT_END_NAMESPACE

#endif // UI_IFCPROJECT_201907_H

 

 

ifcproject_201907.cpp

#include "ifcproject_201907.h"

IFCProject_201907::IFCProject_201907(QWidget *parent)
    : QMainWindow(parent)

    ui.setupUi(this);
    loadIfcModel();


IFCProject_201907::~IFCProject_201907()




void IFCProject_201907::loadIfcModel()

    std::wstring m_file_path = L"D://yd0014.ifc"; 
    IfcVCTool* ifcVCTool1 = new IfcVCTool();
    osg::ref_ptr<osg::Switch> model_switch = ifcVCTool1->getModelNode();
    SceneGraphUtils::clearAllChildNodes(model_switch);
    ifcVCTool1->clearSelection();

    // reset the IFC model
    shared_ptr<GeometryConverter> geometry_converter = ifcVCTool1->getGeometryConverter();
    geometry_converter->clearMessagesCallback();
    geometry_converter->resetModel();
    std::stringstream err;

    try
    
        // load file to IFC model
        ifcVCTool1->getModelReader()->loadModelFromFile(m_file_path, geometry_converter->getBuildingModel());

        // convert IFC geometric representations into Carve geometry
        geometry_converter->convertGeometry();

        // convert Carve geometry to OSG
        shared_ptr<ConverterOSG> converter_osg(new ConverterOSG(geometry_converter->getGeomSettings()));
        converter_osg->setMessageTarget(geometry_converter.get());
        converter_osg->convertToOSG(geometry_converter->getShapeInputData(), model_switch);

        // in case there are IFC entities that are not in the spatial structure
        const std::map<int, shared_ptr<BuildingObject> >& objects_outside_spatial_structure = geometry_converter->getObjectsOutsideSpatialStructure();
        if (objects_outside_spatial_structure.size() > 0)
        
            osg::ref_ptr<osg::Switch> sw_objects_outside_spatial_structure = new osg::Switch();
            sw_objects_outside_spatial_structure->setName("IfcProduct objects outside spatial structure");

            converter_osg->addNodes(objects_outside_spatial_structure, sw_objects_outside_spatial_structure);
            if (sw_objects_outside_spatial_structure->getNumChildren() > 0)
            
                model_switch->addChild(sw_objects_outside_spatial_structure);
            
        
    
    catch (OutOfMemoryException& e)
    
        throw e;
    
    catch (BuildingException& e)
    
        err << e.what();
    
    catch (std::exception& e)
    
        err << e.what();
    
    catch (...)
    
        err << "loadModelFromFile, createGeometryOSG failed" << std::endl;
    

    try
    
        if (model_switch)
        
            bool optimize = true;
            if (optimize)
            
                osgUtil::Optimizer opt;
                opt.optimize(model_switch);
            

            // if model bounding sphere is far from origin, move to origin
            const osg::BoundingSphere& bsphere = model_switch->getBound();
            if (bsphere.center().length() > 10000)
            
                if (bsphere.center().length() / bsphere.radius() > 100)
                
                    std::unordered_set<osg::Geode*> set_applied;
                    SceneGraphUtils::translateGroup(model_switch, -bsphere.center(), set_applied);
                
            
        
    
    catch (std::exception& e)
    
        err << e.what();
    

    geometry_converter->clearInputCache();

    if (err.tellp() > 0)
    
        throw BuildingException(err.str().c_str());
    


    ViewerWidget* viewer_widget = new ViewerWidget(ifcVCTool1);
    viewer_widget->setRootNode(ifcVCTool1->getRootNode());

    this->ui.centerDockWidget->setWidget(viewer_widget);

    //IfcTreeWidget* ifc_tree_widget = new IfcTreeWidget(ifcVCTool1);
    //dock->setWidget(ifc_tree_widget);

 

main.cpp

#include "ifcproject_201907.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])

    QApplication a(argc, argv);
    IFCProject_201907 w;
    //w.show();
    w.showMaximized();
    return a.exec();

技术图片

 

技术图片

技术图片

技术图片

技术图片

技术图片

 

以上是关于osg qt ifc的主要内容,如果未能解决你的问题,请参考以下文章

osg 渲染ifc数据-测试

load ifc

osg qt 三维模型加载

Qt + OpenSenceGraph(osg) 加载OSG模型

如何在 vs 2015 上将 OSG 和 Qt 集成在一起

OSG QT :获取鼠标的world坐标