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 <OpenGL/OpenGL.h>
#include <osg/ShapeDrawable>
#include <osg/Material>
#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
// 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();
}
+26 -20
View File
@@ -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 <OpenGL/OpenGL.h>
#include <cstddef> // size_t
#include <string>
#include <cstddef> // size_t
#include <osg/Vec3>
#include <string>
#include <vector>
ParseIfcFile::ParseIfcFile() {}
@@ -27,11 +26,10 @@ bool ParseIfcFile::Parse(
std::vector<osg::ref_ptr<osg::MatrixTransform>>& 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<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:
std::string matrixStr = "";
@@ -97,7 +104,7 @@ bool ParseIfcFile::Parse(
const std::vector<int>& elemFaces = triElemGeom->faces();
const std::vector<double>& elemVertices = triElemGeom->verts();
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();
std::map<int, osg::ref_ptr<osg::Material>> uniqueMaterials;
@@ -190,15 +197,14 @@ void ParseIfcFile::buildTriangleNodes(
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(
diffuseColor[0],
diffuseColor[1],
diffuseColor[2],
material.transparency()
);
diffuseColor.r(),
diffuseColor.g(),
diffuseColor.b(),
material->transparency);
osg::ref_ptr<osg::Material> osgMaterial = new osg::Material;
osgMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, matOsgDiffuseColor);
+12 -13
View File
@@ -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 <QObject>
#include <QString>
#include <string>
#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();
bool Parse(
const std::string& filePath,
std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms
);
std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms);
private:
private:
void buildTriangleNodes(
const std::vector<int>& fVertIds,
const std::vector<double>& elemVertices,
const std::vector<double>& elemVertices,
const std::vector<double>& elemNormals,
size_t index,
osg::ref_ptr<osg::Vec3Array> osgVertices,
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