From e45b41c04b672ca6729a01328770d41c695ccbdf Mon Sep 17 00:00:00 2001 From: Jason Hilton Date: Tue, 24 Sep 2024 11:58:57 -0700 Subject: [PATCH] fix: compile errors qt app I was able to hardcode load an ifc file, by uncommenting the hard coded parse ifcfile, but I was unable to open and load files with the qt menu. --- src/qtviewer/IfcViewerWidget.cpp | 21 ++++++++------- src/qtviewer/ParseIfcFile.cpp | 46 ++++++++++++++++++-------------- src/qtviewer/ParseIfcFile.h | 25 +++++++++-------- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/qtviewer/IfcViewerWidget.cpp b/src/qtviewer/IfcViewerWidget.cpp index ff9109ba62..0e8fcb3e21 100644 --- a/src/qtviewer/IfcViewerWidget.cpp +++ b/src/qtviewer/IfcViewerWidget.cpp @@ -1,5 +1,4 @@ #include "IfcViewerWidget.h" -#include #include #include #include @@ -186,14 +185,18 @@ void IfcViewerWidget::orientScene(osg::ref_ptr rootGroup) // In case a cameraManipulator is set, lookAt position setting does not work on the camera // as it is overridden. // So set it on the manipulator and reapply it to the viewer - m_mouseHandler->setHomePosition(eye, center, up); + if (m_mouseHandler.valid()) + { + m_mouseHandler->setHomePosition(eye, center, up); + } + m_viewer->setCameraManipulator(m_mouseHandler); - auto log = [center, radius, eye]() { - MessageLogger::log("center: " + std::to_string(center.length())); - MessageLogger::log("radius: " + std::to_string(radius)); - MessageLogger::log("center: " + std::to_string(center.x()) + ", " + std::to_string(center.y()) + ", " + std::to_string(center.z())); - MessageLogger::log("eye: " + std::to_string(eye.x()) + ", " + std::to_string(eye.y()) + ", " + std::to_string(eye.z())); - }; - //log(); + auto log = [center, radius, eye]() { + MessageLogger::log("center: " + std::to_string(center.length())); + MessageLogger::log("radius: " + std::to_string(radius)); + MessageLogger::log("center: " + std::to_string(center.x()) + ", " + std::to_string(center.y()) + ", " + std::to_string(center.z())); + MessageLogger::log("eye: " + std::to_string(eye.x()) + ", " + std::to_string(eye.y()) + ", " + std::to_string(eye.z())); + }; + //log(); } diff --git a/src/qtviewer/ParseIfcFile.cpp b/src/qtviewer/ParseIfcFile.cpp index 8e1967b42c..0936d5624b 100644 --- a/src/qtviewer/ParseIfcFile.cpp +++ b/src/qtviewer/ParseIfcFile.cpp @@ -1,21 +1,20 @@ #include "ParseIfcFile.h" -#include "MessageLogger.h" +#include "MessageLogger.h" #include "osg/Array" #include "osg/Geometry" #include "osg/Material" -#include "osg/MatrixTransform" #include "osg/Matrixd" +#include "osg/MatrixTransform" #include "osg/PrimitiveSet" +#include "osg/ref_ptr" #include "osg/StateAttribute" #include "osg/StateSet" #include "osg/Vec4" -#include "osg/ref_ptr" -#include -#include // size_t -#include +#include // size_t #include +#include #include ParseIfcFile::ParseIfcFile() {} @@ -27,11 +26,10 @@ bool ParseIfcFile::Parse( std::vector>& matrixTransforms ) { IfcParse::IfcFile file(filePath); - - IfcGeom::IteratorSettings settings; - settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, false); - settings.set(IfcGeom::IteratorSettings::WELD_VERTICES, false); - settings.set(IfcGeom::IteratorSettings::APPLY_DEFAULT_MATERIALS, true); + ifcopenshell::geometry::Settings settings; + settings.set("use-world-coords", false); + settings.set("weld-vertices", false); + settings.set("apply-default-materials", true); IfcGeom::Iterator* it = new IfcGeom::Iterator(settings, &file); if (!it->initialize()) { @@ -57,7 +55,16 @@ bool ParseIfcFile::Parse( //MessageLogger::log("id: " + id); // Transformation Matrix - const std::vector& matrixData = triElem->transformation().matrix().data(); + std::vector matrixData; + auto transform4x4 = triElem->transformation().data()->components(); + for (int col = 0; col<4; col++) + { + for (int row =0; row<3; row++) + { + matrixData.push_back(transform4x4(row,col)); + } + + } // Debugging: std::string matrixStr = ""; @@ -97,7 +104,7 @@ bool ParseIfcFile::Parse( const std::vector& elemFaces = triElemGeom->faces(); const std::vector& elemVertices = triElemGeom->verts(); const std::vector& elemNormals = triElemGeom->normals(); - const std::vector& elemMats = triElemGeom->materials(); + const std::vector& elemMats = triElemGeom->materials(); const std::vector& elemMatIds = triElemGeom->material_ids(); std::map> uniqueMaterials; @@ -190,15 +197,14 @@ void ParseIfcFile::buildTriangleNodes( addVertexAndNormal(index + 2); } -osg::ref_ptr ParseIfcFile::getOsgMaterial(const IfcGeom::Material& material) +osg::ref_ptr ParseIfcFile::getOsgMaterial(const ifcopenshell::geometry::taxonomy::style::ptr& material) { - const double* diffuseColor = material.diffuse(); + ifcopenshell::geometry::taxonomy::colour diffuseColor = material->diffuse; osg::Vec4 matOsgDiffuseColor( - diffuseColor[0], - diffuseColor[1], - diffuseColor[2], - material.transparency() - ); + diffuseColor.r(), + diffuseColor.g(), + diffuseColor.b(), + material->transparency); osg::ref_ptr osgMaterial = new osg::Material; osgMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, matOsgDiffuseColor); diff --git a/src/qtviewer/ParseIfcFile.h b/src/qtviewer/ParseIfcFile.h index 548b4ec487..f3370f3c20 100644 --- a/src/qtviewer/ParseIfcFile.h +++ b/src/qtviewer/ParseIfcFile.h @@ -1,38 +1,37 @@ #ifndef PARSEIFCFILE_H #define PARSEIFCFILE_H +#include "../ifcgeom/Iterator.h" +#include "osg/Geometry" +#include "osg/Material" +#include "osg/MatrixTransform" +#include "osg/ref_ptr" + #include #include #include #include -#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h" -#include "osg/Material" -#include "osg/MatrixTransform" -#include "osg/ref_ptr" -#include "osg/Geometry" -class ParseIfcFile : public QObject -{ +class ParseIfcFile : public QObject { -public: + public: ParseIfcFile(); ~ParseIfcFile(); bool Parse( const std::string& filePath, - std::vector>& matrixTransforms - ); + std::vector>& matrixTransforms); -private: + private: void buildTriangleNodes( const std::vector& fVertIds, - const std::vector& elemVertices, + const std::vector& elemVertices, const std::vector& elemNormals, size_t index, osg::ref_ptr osgVertices, osg::ref_ptr osgNormals); - osg::ref_ptr getOsgMaterial(const IfcGeom::Material& material); + osg::ref_ptr getOsgMaterial(const ifcopenshell::geometry::taxonomy::style::ptr& material); }; #endif // PARSEIFCFILE_H