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.
This commit is contained in:
Jason Hilton
2024-09-24 11:58:57 -07:00
committed by Thomas Krijnen
parent 86367e9c1f
commit e45b41c04b
3 changed files with 50 additions and 42 deletions
+12 -9
View File
@@ -1,5 +1,4 @@
#include "IfcViewerWidget.h" #include "IfcViewerWidget.h"
#include <OpenGL/OpenGL.h>
#include <osg/ShapeDrawable> #include <osg/ShapeDrawable>
#include <osg/Material> #include <osg/Material>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
@@ -186,14 +185,18 @@ void IfcViewerWidget::orientScene(osg::ref_ptr<osg::Group> rootGroup)
// In case a cameraManipulator is set, lookAt position setting does not work on the camera // In case a cameraManipulator is set, lookAt position setting does not work on the camera
// as it is overridden. // as it is overridden.
// So set it on the manipulator and reapply it to the viewer // 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); m_viewer->setCameraManipulator(m_mouseHandler);
auto log = [center, radius, eye]() { auto log = [center, radius, eye]() {
MessageLogger::log("center: " + std::to_string(center.length())); MessageLogger::log("center: " + std::to_string(center.length()));
MessageLogger::log("radius: " + std::to_string(radius)); 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("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())); MessageLogger::log("eye: " + std::to_string(eye.x()) + ", " + std::to_string(eye.y()) + ", " + std::to_string(eye.z()));
}; };
//log(); //log();
} }
+26 -20
View File
@@ -1,21 +1,20 @@
#include "ParseIfcFile.h" #include "ParseIfcFile.h"
#include "MessageLogger.h"
#include "MessageLogger.h"
#include "osg/Array" #include "osg/Array"
#include "osg/Geometry" #include "osg/Geometry"
#include "osg/Material" #include "osg/Material"
#include "osg/MatrixTransform"
#include "osg/Matrixd" #include "osg/Matrixd"
#include "osg/MatrixTransform"
#include "osg/PrimitiveSet" #include "osg/PrimitiveSet"
#include "osg/ref_ptr"
#include "osg/StateAttribute" #include "osg/StateAttribute"
#include "osg/StateSet" #include "osg/StateSet"
#include "osg/Vec4" #include "osg/Vec4"
#include "osg/ref_ptr"
#include <OpenGL/OpenGL.h>
#include <cstddef> // size_t
#include <string>
#include <cstddef> // size_t
#include <osg/Vec3> #include <osg/Vec3>
#include <string>
#include <vector> #include <vector>
ParseIfcFile::ParseIfcFile() {} ParseIfcFile::ParseIfcFile() {}
@@ -27,11 +26,10 @@ bool ParseIfcFile::Parse(
std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms
) { ) {
IfcParse::IfcFile file(filePath); IfcParse::IfcFile file(filePath);
ifcopenshell::geometry::Settings settings;
IfcGeom::IteratorSettings settings; settings.set("use-world-coords", false);
settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, false); settings.set("weld-vertices", false);
settings.set(IfcGeom::IteratorSettings::WELD_VERTICES, false); settings.set("apply-default-materials", true);
settings.set(IfcGeom::IteratorSettings::APPLY_DEFAULT_MATERIALS, true);
IfcGeom::Iterator* it = new IfcGeom::Iterator(settings, &file); IfcGeom::Iterator* it = new IfcGeom::Iterator(settings, &file);
if (!it->initialize()) { if (!it->initialize()) {
@@ -57,7 +55,16 @@ bool ParseIfcFile::Parse(
//MessageLogger::log("id: " + id); //MessageLogger::log("id: " + id);
// Transformation Matrix // Transformation Matrix
const std::vector<double>& matrixData = triElem->transformation().matrix().data(); std::vector<double> 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: // Debugging:
std::string matrixStr = ""; std::string matrixStr = "";
@@ -97,7 +104,7 @@ bool ParseIfcFile::Parse(
const std::vector<int>& elemFaces = triElemGeom->faces(); const std::vector<int>& elemFaces = triElemGeom->faces();
const std::vector<double>& elemVertices = triElemGeom->verts(); const std::vector<double>& elemVertices = triElemGeom->verts();
const std::vector<double>& elemNormals = triElemGeom->normals(); const std::vector<double>& elemNormals = triElemGeom->normals();
const std::vector<IfcGeom::Material>& elemMats = triElemGeom->materials(); const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& elemMats = triElemGeom->materials();
const std::vector<int>& elemMatIds = triElemGeom->material_ids(); const std::vector<int>& elemMatIds = triElemGeom->material_ids();
std::map<int, osg::ref_ptr<osg::Material>> uniqueMaterials; std::map<int, osg::ref_ptr<osg::Material>> uniqueMaterials;
@@ -190,15 +197,14 @@ void ParseIfcFile::buildTriangleNodes(
addVertexAndNormal(index + 2); addVertexAndNormal(index + 2);
} }
osg::ref_ptr<osg::Material> ParseIfcFile::getOsgMaterial(const IfcGeom::Material& material) osg::ref_ptr<osg::Material> ParseIfcFile::getOsgMaterial(const ifcopenshell::geometry::taxonomy::style::ptr& material)
{ {
const double* diffuseColor = material.diffuse(); ifcopenshell::geometry::taxonomy::colour diffuseColor = material->diffuse;
osg::Vec4 matOsgDiffuseColor( osg::Vec4 matOsgDiffuseColor(
diffuseColor[0], diffuseColor.r(),
diffuseColor[1], diffuseColor.g(),
diffuseColor[2], diffuseColor.b(),
material.transparency() material->transparency);
);
osg::ref_ptr<osg::Material> osgMaterial = new osg::Material; osg::ref_ptr<osg::Material> osgMaterial = new osg::Material;
osgMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, matOsgDiffuseColor); osgMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, matOsgDiffuseColor);
+11 -12
View File
@@ -1,29 +1,28 @@
#ifndef PARSEIFCFILE_H #ifndef PARSEIFCFILE_H
#define PARSEIFCFILE_H #define PARSEIFCFILE_H
#include "../ifcgeom/Iterator.h"
#include "osg/Geometry"
#include "osg/Material"
#include "osg/MatrixTransform"
#include "osg/ref_ptr"
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <string> #include <string>
#include <vector> #include <vector>
#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();
~ParseIfcFile(); ~ParseIfcFile();
bool Parse( bool Parse(
const std::string& filePath, const std::string& filePath,
std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms);
);
private: private:
void buildTriangleNodes( void buildTriangleNodes(
const std::vector<int>& fVertIds, const std::vector<int>& fVertIds,
const std::vector<double>& elemVertices, const std::vector<double>& elemVertices,
@@ -32,7 +31,7 @@ private:
osg::ref_ptr<osg::Vec3Array> osgVertices, osg::ref_ptr<osg::Vec3Array> osgVertices,
osg::ref_ptr<osg::Vec3Array> osgNormals); osg::ref_ptr<osg::Vec3Array> osgNormals);
osg::ref_ptr<osg::Material> getOsgMaterial(const IfcGeom::Material& material); osg::ref_ptr<osg::Material> getOsgMaterial(const ifcopenshell::geometry::taxonomy::style::ptr& material);
}; };
#endif // PARSEIFCFILE_H #endif // PARSEIFCFILE_H