diff --git a/src/hdf5_usecases/CMakeLists.txt b/src/hdf5_usecases/CMakeLists.txt index f44fe0680a..4cf2639558 100644 --- a/src/hdf5_usecases/CMakeLists.txt +++ b/src/hdf5_usecases/CMakeLists.txt @@ -19,3 +19,6 @@ ADD_EXECUTABLE(hdf5_federate federate.cpp) TARGET_LINK_LIBRARIES(hdf5_federate IfcParse) + +ADD_EXECUTABLE(hdf5_lod lod.cpp) +TARGET_LINK_LIBRARIES(hdf5_lod IfcParse IfcGeom) diff --git a/src/hdf5_usecases/lod.cpp b/src/hdf5_usecases/lod.cpp new file mode 100644 index 0000000000..d47da290d2 --- /dev/null +++ b/src/hdf5_usecases/lod.cpp @@ -0,0 +1,69 @@ +/******************************************************************************** + * * + * This file is part of IfcOpenShell. * + * * + * IfcOpenShell is free software: you can redistribute it and/or modify * + * it under the terms of the Lesser GNU General Public License as published by * + * the Free Software Foundation, either version 3.0 of the License, or * + * (at your option) any later version. * + * * + * IfcOpenShell is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Lesser GNU General Public License for more details. * + * * + * You should have received a copy of the Lesser GNU General Public License * + * along with this program. If not, see . * + * * + ********************************************************************************/ + +#include "../../../src/ifcparse/IfcHdf5File.h" +#include "../../../src/ifcgeom/IfcGeom.h" + +#include +#include + +int main(int, char** argv) { + IfcParse::IfcFile f; + f.Init(argv[1]); + + std::vector new_defs; + IfcSchema::IfcProductDefinitionShape::list::ptr defs = f.entitiesByType(); + + IfcGeom::Kernel kernel; + kernel.initializeUnits(*f.entitiesByType()->begin()); + + std::transform(defs->begin(), defs->end(), std::back_inserter(new_defs), [&kernel](IfcSchema::IfcProductDefinitionShape* def) { + Bnd_Box box; + auto reps = def->Representations(); + IfcSchema::IfcRepresentationContext* context; + + std::for_each(reps->begin(), reps->end(), [&kernel, &box, &context](auto rep) { + IfcGeom::IfcRepresentationShapeItems items; + + if (rep->RepresentationIdentifier() == "Body") { + kernel.convert(rep, items); + context = rep->ContextOfItems(); + } + + for (auto& i : items) { + BRepBndLib::AddClose(i.Shape(), box); + } + }); + + double x1, y1, z1, x2, y2, z2; + box.Get(x1, y1, z1, x2, y2, z2); + + IfcSchema::IfcCartesianPoint* corner = new IfcSchema::IfcCartesianPoint(std::vector{x1, y1, z1});; + IfcSchema::IfcBoundingBox* bbox = new IfcSchema::IfcBoundingBox(corner, x2-x1, y2-y1, z2-z1); + IfcSchema::IfcRepresentationItem::list::ptr items(new IfcSchema::IfcRepresentationItem::list); + items->push(bbox); + + IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(context, std::string("Body"), std::string("BoundingBox"), items); + IfcSchema::IfcRepresentation::list::ptr new_reps(new IfcSchema::IfcRepresentation::list); + new_reps->push(rep); + + IfcSchema::IfcProductDefinitionShape* new_def = new IfcSchema::IfcProductDefinitionShape(boost::none, boost::none, new_reps); + return new_def; + }); +} \ No newline at end of file