mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 06:18:09 +00:00
Using transformation-matrix data; Turned off world-coords; Re-using geometry of repeating IDs
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "MessageLogger.h"
|
#include "MessageLogger.h"
|
||||||
#include "osg/Geode"
|
#include "osg/Geode"
|
||||||
#include "osg/Geometry"
|
#include "osg/Geometry"
|
||||||
|
#include "osg/Group"
|
||||||
#include "osg/StateSet"
|
#include "osg/StateSet"
|
||||||
#include "osg/Vec3"
|
#include "osg/Vec3"
|
||||||
#include "osg/ref_ptr"
|
#include "osg/ref_ptr"
|
||||||
@@ -142,33 +143,31 @@ void IfcViewerWidget::setupViewController()
|
|||||||
|
|
||||||
void IfcViewerWidget::loadFile(const std::string& filePath)
|
void IfcViewerWidget::loadFile(const std::string& filePath)
|
||||||
{
|
{
|
||||||
std::vector<osg::ref_ptr<osg::Geometry>> geometries;
|
std::vector<osg::ref_ptr<osg::MatrixTransform>> matrixTransforms;
|
||||||
|
|
||||||
if(!m_parser.Parse(filePath, geometries)) {
|
if(!m_parser.Parse(filePath, matrixTransforms)) {
|
||||||
MessageLogger::log("Failed to prepare IFC geometry");
|
MessageLogger::log("Failed to prepare IFC geometry");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageLogger::log("\nIFC geometry prepared");
|
MessageLogger::log("\nIFC geometry prepared");
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
for (auto matrixTransform : matrixTransforms) {
|
||||||
for (auto geometry : geometries) {
|
root->addChild(matrixTransform);
|
||||||
geode->addDrawable(geometry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the model to the root node
|
|
||||||
root->addChild(geode);
|
|
||||||
|
|
||||||
// set initial camera position
|
// set initial camera position
|
||||||
orientScene(geode);
|
orientScene(root);
|
||||||
|
|
||||||
|
// request redraw
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfcViewerWidget::orientScene(osg::ref_ptr<osg::Geode> geode)
|
void IfcViewerWidget::orientScene(osg::ref_ptr<osg::Group> rootGroup)
|
||||||
{
|
{
|
||||||
// Get the bounding-box
|
// Get the bounding-box
|
||||||
osg::ComputeBoundsVisitor cbv;
|
osg::ComputeBoundsVisitor cbv;
|
||||||
geode->accept(cbv);
|
rootGroup->accept(cbv);
|
||||||
//root.get()->accept(cbv);
|
|
||||||
const osg::BoundingBox& bb = cbv.getBoundingBox();
|
const osg::BoundingBox& bb = cbv.getBoundingBox();
|
||||||
|
|
||||||
// Center (average of opposite corners of bb)
|
// Center (average of opposite corners of bb)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ private:
|
|||||||
|
|
||||||
void setupViewController();
|
void setupViewController();
|
||||||
|
|
||||||
void orientScene(osg::ref_ptr<osg::Geode> geode);
|
void orientScene(osg::ref_ptr<osg::Group> rootGroup);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IFCVIEWERWIDGET_H
|
#endif // IFCVIEWERWIDGET_H
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#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/PrimitiveSet"
|
#include "osg/PrimitiveSet"
|
||||||
#include "osg/StateAttribute"
|
#include "osg/StateAttribute"
|
||||||
#include "osg/StateSet"
|
#include "osg/StateSet"
|
||||||
@@ -22,12 +24,12 @@ ParseIfcFile::~ParseIfcFile() {}
|
|||||||
|
|
||||||
bool ParseIfcFile::Parse(
|
bool ParseIfcFile::Parse(
|
||||||
const std::string& filePath,
|
const std::string& filePath,
|
||||||
std::vector<osg::ref_ptr<osg::Geometry>>& geometries
|
std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms
|
||||||
) {
|
) {
|
||||||
IfcParse::IfcFile file(filePath);
|
IfcParse::IfcFile file(filePath);
|
||||||
|
|
||||||
IfcGeom::IteratorSettings settings;
|
IfcGeom::IteratorSettings settings;
|
||||||
settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, true);
|
settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, false);
|
||||||
settings.set(IfcGeom::IteratorSettings::WELD_VERTICES, false);
|
settings.set(IfcGeom::IteratorSettings::WELD_VERTICES, false);
|
||||||
settings.set(IfcGeom::IteratorSettings::APPLY_DEFAULT_MATERIALS, true);
|
settings.set(IfcGeom::IteratorSettings::APPLY_DEFAULT_MATERIALS, true);
|
||||||
|
|
||||||
@@ -38,6 +40,9 @@ bool ParseIfcFile::Parse(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lastId;
|
||||||
|
std::vector<osg::ref_ptr<osg::Geometry>> lastGeometrySet;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
//const IfcGeom::BRepElement* bRepElem = it->get_native();
|
//const IfcGeom::BRepElement* bRepElem = it->get_native();
|
||||||
const IfcGeom::TriangulationElement* triElem = static_cast<const IfcGeom::TriangulationElement*>(it->get());
|
const IfcGeom::TriangulationElement* triElem = static_cast<const IfcGeom::TriangulationElement*>(it->get());
|
||||||
@@ -46,22 +51,46 @@ bool ParseIfcFile::Parse(
|
|||||||
std::string elemInfo = triElem->type();
|
std::string elemInfo = triElem->type();
|
||||||
elemInfo += triElem->name() == "" ? "" : ": " + triElem->name();
|
elemInfo += triElem->name() == "" ? "" : ": " + triElem->name();
|
||||||
MessageLogger::log(elemInfo);
|
MessageLogger::log(elemInfo);
|
||||||
|
|
||||||
|
const std::string id = triElem->geometry().id();
|
||||||
|
|
||||||
|
//MessageLogger::log("id: " + id);
|
||||||
|
|
||||||
// Transformation Matrix
|
// Transformation Matrix
|
||||||
const std::vector<double>& matrixData = triElem->transformation().matrix().data();
|
const std::vector<double>& matrixData = triElem->transformation().matrix().data();
|
||||||
|
|
||||||
|
// Debugging:
|
||||||
std::string matrixStr = "";
|
std::string matrixStr = "";
|
||||||
int di = 0;
|
int col = 0;
|
||||||
|
int row = 0;
|
||||||
for (auto d : matrixData) {
|
for (auto d : matrixData) {
|
||||||
if (di == 4) {
|
|
||||||
matrixStr += "\n";
|
|
||||||
di = 0;
|
|
||||||
}
|
|
||||||
matrixStr += std::to_string(d) + " ";
|
matrixStr += std::to_string(d) + " ";
|
||||||
di++;
|
if (++col == 3) {
|
||||||
|
std::string lastCol = (row == 3) ? "1" : "0";
|
||||||
|
matrixStr += lastCol + "\n";
|
||||||
|
col = 0;
|
||||||
|
row++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//MessageLogger::log(matrixStr); // Print matrix data
|
//MessageLogger::log(matrixStr); // Print matrix data
|
||||||
|
|
||||||
|
const osg::Matrixd matrixd (
|
||||||
|
matrixData[0], matrixData[1], matrixData[2], 0,
|
||||||
|
matrixData[3], matrixData[4], matrixData[5], 0,
|
||||||
|
matrixData[6], matrixData[7], matrixData[8], 0,
|
||||||
|
matrixData[9], matrixData[10], matrixData[11], 1
|
||||||
|
);
|
||||||
|
|
||||||
//MessageLogger::log(triElem->geometry().id());
|
const osg::ref_ptr<osg::MatrixTransform> matrixTransform = new osg::MatrixTransform;
|
||||||
|
matrixTransform->setMatrix(matrixd);
|
||||||
|
|
||||||
|
if (id == lastId) {
|
||||||
|
for (auto geometry : lastGeometrySet) {
|
||||||
|
matrixTransform->addChild(geometry);
|
||||||
|
}
|
||||||
|
matrixTransforms.push_back(matrixTransform);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const boost::shared_ptr<IfcGeom::Representation::Triangulation>& triElemGeom = triElem->geometry_pointer();
|
const boost::shared_ptr<IfcGeom::Representation::Triangulation>& triElemGeom = triElem->geometry_pointer();
|
||||||
|
|
||||||
@@ -84,6 +113,8 @@ bool ParseIfcFile::Parse(
|
|||||||
if (fit != elemFaces.end())
|
if (fit != elemFaces.end())
|
||||||
MessageLogger::log("** Failed to map the faces to material IDs!");
|
MessageLogger::log("** Failed to map the faces to material IDs!");
|
||||||
|
|
||||||
|
std::vector<osg::ref_ptr<osg::Geometry>> geometrySet;
|
||||||
|
|
||||||
for (const auto& group : elemFaces_grouped) {
|
for (const auto& group : elemFaces_grouped) {
|
||||||
int matId = group.first;
|
int matId = group.first;
|
||||||
const std::vector<int>& fVertIds = group.second;
|
const std::vector<int>& fVertIds = group.second;
|
||||||
@@ -111,9 +142,16 @@ bool ParseIfcFile::Parse(
|
|||||||
osg::ref_ptr<osg::Material> osgMaterial = getOsgMaterial(elemMats[matId]);
|
osg::ref_ptr<osg::Material> osgMaterial = getOsgMaterial(elemMats[matId]);
|
||||||
geometry->getOrCreateStateSet()->setAttributeAndModes(osgMaterial.get());
|
geometry->getOrCreateStateSet()->setAttributeAndModes(osgMaterial.get());
|
||||||
|
|
||||||
geometries.push_back(geometry);
|
matrixTransform->addChild(geometry);
|
||||||
|
|
||||||
|
geometrySet.push_back(geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matrixTransforms.push_back(matrixTransform);
|
||||||
|
|
||||||
|
lastId = id;
|
||||||
|
lastGeometrySet = geometrySet;
|
||||||
|
|
||||||
} while (it->next());
|
} while (it->next());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
||||||
#include "osg/Material"
|
#include "osg/Material"
|
||||||
|
#include "osg/MatrixTransform"
|
||||||
#include "osg/ref_ptr"
|
#include "osg/ref_ptr"
|
||||||
#include "osg/Geometry"
|
#include "osg/Geometry"
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ public:
|
|||||||
|
|
||||||
bool Parse(
|
bool Parse(
|
||||||
const std::string& filePath,
|
const std::string& filePath,
|
||||||
std::vector<osg::ref_ptr<osg::Geometry>>& geometries
|
std::vector<osg::ref_ptr<osg::MatrixTransform>>& matrixTransforms
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user