From 8f88c601c6bccbcaa4b8bbf587cd25935696e922 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 18 Aug 2019 14:31:22 +0200 Subject: [PATCH] IfcConvert links on windows --- src/ifcgeom/abstract_mapping.h | 2 +- .../kernel_agnostic/AbstractKernel.cpp | 10 ++ src/ifcgeom/kernel_agnostic/AbstractKernel.h | 13 +- src/ifcgeom/kernels/opencascade/IfcGeomTree.h | 2 +- .../OpenCascadeConversionResult.cpp | 37 ++--- .../opencascade/OpenCascadeConversionResult.h | 2 +- .../kernels/opencascade/OpenCascadeKernel.h | 2 +- src/ifcgeom/schema/mapping.cpp | 16 ++ src/ifcgeom/schema/mapping.h | 1 + src/ifcgeom/schema/mapping.i | 148 +++++++++--------- src/ifcgeom/schema_agnostic/Converter.cpp | 116 +++----------- src/ifcgeom/schema_agnostic/Converter.h | 6 - src/ifcgeom/schema_agnostic/IfcGeomElement.h | 6 + .../schema_agnostic/IfcGeomRepresentation.cpp | 2 +- src/ifcgeom/taxonomy.h | 1 + src/ifcgeomserver/IfcGeomServer.cpp | 2 +- src/serializers/ColladaSerializer.cpp | 19 ++- src/serializers/OpenCascadeBasedSerializer.h | 2 +- src/serializers/SvgSerializer.cpp | 2 +- src/serializers/XmlSerializer.cpp | 12 +- 20 files changed, 173 insertions(+), 228 deletions(-) rename src/ifcgeom/{schema_agnostic => kernels}/opencascade/OpenCascadeConversionResult.cpp (81%) rename src/ifcgeom/{schema_agnostic => kernels}/opencascade/OpenCascadeConversionResult.h (93%) diff --git a/src/ifcgeom/abstract_mapping.h b/src/ifcgeom/abstract_mapping.h index 7dbb4d413e..5ff2e575bc 100644 --- a/src/ifcgeom/abstract_mapping.h +++ b/src/ifcgeom/abstract_mapping.h @@ -33,7 +33,7 @@ namespace geometry { virtual ifcopenshell::geometry::taxonomy::item* map(const IfcUtil::IfcBaseClass*) = 0; virtual void get_representations(std::vector& tasks, std::vector& filters, settings& s) = 0; virtual IfcUtil::IfcBaseEntity* get_decomposing_entity(IfcUtil::IfcBaseEntity* product, bool include_openings = true) = 0; - virtual std::map get_layers(IfcUtil::IfcBaseEntity*); + virtual std::map get_layers(IfcUtil::IfcBaseEntity*) = 0; }; namespace impl { diff --git a/src/ifcgeom/kernel_agnostic/AbstractKernel.cpp b/src/ifcgeom/kernel_agnostic/AbstractKernel.cpp index 18f5d0c53d..4c1d7dcce1 100644 --- a/src/ifcgeom/kernel_agnostic/AbstractKernel.cpp +++ b/src/ifcgeom/kernel_agnostic/AbstractKernel.cpp @@ -1,6 +1,7 @@ #include "AbstractKernel.h" #include "../../ifcgeom/schema_agnostic/IfcGeomElement.h" +#include "../../ifcgeom/kernels/opencascade/OpenCascadeKernel.h" namespace { /* A compile-time for loop over the taxonomy kinds */ @@ -28,6 +29,15 @@ bool ifcopenshell::geometry::kernels::AbstractKernel::convert(const taxonomy::it return dispatch_conversion<0>::dispatch(this, item, results); } +ifcopenshell::geometry::kernels::AbstractKernel* ifcopenshell::geometry::kernels::construct(const std::string& geometry_library, IfcParse::IfcFile* file) { + const std::string geometry_library_lower = boost::to_lower_copy(geometry_library); + if (geometry_library_lower == "opencascade") { + return new OpenCascadeKernel; + } else { + throw IfcParse::IfcException("No geometry kernel registered for " + geometry_library); + } +} + //void ifcopenshell::geometry::kernels::AbstractKernel::set_conversion_placement_rel_to(const IfcParse::declaration* type) { // placement_rel_to = type; //} diff --git a/src/ifcgeom/kernel_agnostic/AbstractKernel.h b/src/ifcgeom/kernel_agnostic/AbstractKernel.h index dcff03cebc..51673a6143 100644 --- a/src/ifcgeom/kernel_agnostic/AbstractKernel.h +++ b/src/ifcgeom/kernel_agnostic/AbstractKernel.h @@ -53,18 +53,7 @@ namespace ifcopenshell { namespace geometry { namespace kernels { virtual bool convert_impl(const taxonomy::node*, ifcopenshell::geometry::ConversionResults&) { throw std::runtime_error("Not implemented"); } }; - namespace impl { - typedef boost::function1 < AbstractKernel*, const std::string&> kernel_fn; - - class KernelFactoryImplementation : public std::map { - public: - KernelFactoryImplementation(); - void bind(const std::string& geometry_library, kernel_fn); - AbstractKernel* construct(const std::string& geometry_library, IfcParse::IfcFile*); - }; - - KernelFactoryImplementation& kernel_implementations(); - } + AbstractKernel* construct(const std::string& geometry_library, IfcParse::IfcFile*); } } diff --git a/src/ifcgeom/kernels/opencascade/IfcGeomTree.h b/src/ifcgeom/kernels/opencascade/IfcGeomTree.h index c5c657a370..73869ae50c 100644 --- a/src/ifcgeom/kernels/opencascade/IfcGeomTree.h +++ b/src/ifcgeom/kernels/opencascade/IfcGeomTree.h @@ -24,7 +24,7 @@ #include "../../../ifcgeom/schema_agnostic/IfcGeomElement.h" #include "../../../ifcgeom/schema_agnostic/IfcGeomIterator.h" #include "../../../ifcgeom/schema_agnostic/Kernel.h" -#include "../../../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h" +#include "../../../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h" #include #include diff --git a/src/ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.cpp b/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.cpp similarity index 81% rename from src/ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.cpp rename to src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.cpp index b113ba45ce..9478a64c15 100644 --- a/src/ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.cpp +++ b/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.cpp @@ -7,17 +7,19 @@ #include -template -void triangulate_helper(const TopoDS_Shape& s, const IfcGeom::IteratorSettings& settings, const IfcGeom::ConversionResultPlacement* place, IfcGeom::Representation::Triangulation* t, int surface_style_id) { +void ifcopenshell::geometry::OpenCascadeShape::Triangulate(const settings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, Representation::Triangulation* t, int surface_style_id) const { + // @todo check gp_GTrsf trsf; - if (place) { - trsf = dynamic_cast(place)->trsf(); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < j; ++i) { + trsf.SetValue(i + 1, j + 1, place.components(i, j)); + } } // Triangulate the shape try { - BRepMesh_IncrementalMesh(s, settings.deflection_tolerance()); + BRepMesh_IncrementalMesh(shape_, settings.deflection_tolerance()); } catch (...) { // TODO: Catch outside @@ -29,7 +31,7 @@ void triangulate_helper(const TopoDS_Shape& s, const IfcGeom::IteratorSettings& // Iterates over the faces of the shape int num_faces = 0; TopExp_Explorer exp; - for (exp.Init(s, TopAbs_FACE); exp.More(); exp.Next(), ++num_faces) { + for (exp.Init(shape_, TopAbs_FACE); exp.More(); exp.Next(), ++num_faces) { TopoDS_Face face = TopoDS::Face(exp.Current()); TopLoc_Location loc; Handle_Poly_Triangulation tri = BRep_Tool::Triangulation(face, loc); @@ -51,8 +53,8 @@ void triangulate_helper(const TopoDS_Shape& s, const IfcGeom::IteratorSettings& std::map dict; // Vertex normals are only calculated if vertices are not welded and calculation is not disable explicitly. - const bool calculate_normals = !settings.get(IfcGeom::IteratorSettings::WELD_VERTICES) && - !settings.get(IfcGeom::IteratorSettings::NO_NORMALS); + const bool calculate_normals = !settings.get(ifcopenshell::geometry::settings::WELD_VERTICES) && + !settings.get(ifcopenshell::geometry::settings::NO_NORMALS); for (int i = 1; i <= nodes.Length(); ++i) { coords.push_back(nodes(i).Transformed(loc).XYZ()); @@ -114,7 +116,7 @@ void triangulate_helper(const TopoDS_Shape& s, const IfcGeom::IteratorSettings& if (!t.normals().empty() && settings().get(IfcGeom::IteratorSettings::GENERATE_UVS)) { t.uvs() = box_project_uvs(t.verts(), t.normals()); } - + if (num_faces == 0) { // Edges are only emitted if there are no faces. A mixed representation of faces // and loose edges is discouraged by the standard. An alternative would be to use @@ -184,18 +186,13 @@ void triangulate_helper(const TopoDS_Shape& s, const IfcGeom::IteratorSettings& */ - BRepTools::Clean(s); + BRepTools::Clean(shape_); } -void IfcGeom::OpenCascadeShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const { - triangulate_helper(shape_, settings, place, t, surface_style_id); -} - -void IfcGeom::OpenCascadeShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const { - triangulate_helper(shape_, settings, place, t, surface_style_id); -} - -int IfcGeom::OpenCascadeShape::surface_genus() const { +int ifcopenshell::geometry::OpenCascadeShape::surface_genus() const { + throw std::runtime_error("Not implemented"); +} + +bool ifcopenshell::geometry::OpenCascadeShape::is_manifold() const { throw std::runtime_error("Not implemented"); - // return IfcGeom::Kernel::surface_genus(shape_); } \ No newline at end of file diff --git a/src/ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h b/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h similarity index 93% rename from src/ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h rename to src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h index 864e7f68fe..8083e33fed 100644 --- a/src/ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h +++ b/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h @@ -47,7 +47,7 @@ namespace ifcopenshell { const TopoDS_Shape& shape() const { return shape_; } operator const TopoDS_Shape& () { return shape_; } - virtual void Triangulate(const settings & settings, const ifcopenshell::geometry::taxonomy::matrix4& place, Representation::Triangulation* t, int surface_style_id) const; + virtual void Triangulate(const settings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, Representation::Triangulation* t, int surface_style_id) const; virtual void Serialize(std::string&) const { throw std::runtime_error("Not implemented"); diff --git a/src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h b/src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h index e274fe3ab5..0d5b37dfe6 100644 --- a/src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h +++ b/src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h @@ -55,7 +55,7 @@ inline static bool ALMOST_THE_SAME(const T& a, const T& b, double tolerance=ALMO #include "../../../ifcgeom/schema_agnostic/ConversionResult.h" #include "../../../ifcgeom/kernels/opencascade/IfcGeomShapeType.h" -#include "../../../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h" +#include "../../../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h" #include "../../../ifcgeom/schema_agnostic/ifc_geom_api.h" diff --git a/src/ifcgeom/schema/mapping.cpp b/src/ifcgeom/schema/mapping.cpp index c2c74fcb27..a7b8a46871 100644 --- a/src/ifcgeom/schema/mapping.cpp +++ b/src/ifcgeom/schema/mapping.cpp @@ -699,3 +699,19 @@ IfcUtil::IfcBaseEntity* mapping::get_decomposing_entity(IfcUtil::IfcBaseEntity* return parent; } + +std::map mapping::get_layers(IfcUtil::IfcBaseEntity* inst) { + auto prod = inst->as(); + std::map layers; + if (prod->hasRepresentation()) { + IfcEntityList::ptr r = IfcParse::traverse(prod->Representation()); + IfcSchema::IfcRepresentation::list::ptr representations = r->as(); + for (IfcSchema::IfcRepresentation::list::it it = representations->begin(); it != representations->end(); ++it) { + IfcSchema::IfcPresentationLayerAssignment::list::ptr a = (*it)->LayerAssignments(); + for (IfcSchema::IfcPresentationLayerAssignment::list::it jt = a->begin(); jt != a->end(); ++jt) { + layers[(*jt)->Name()] = *jt; + } + } + } + return layers; +} diff --git a/src/ifcgeom/schema/mapping.h b/src/ifcgeom/schema/mapping.h index ff63308389..4083966f0d 100644 --- a/src/ifcgeom/schema/mapping.h +++ b/src/ifcgeom/schema/mapping.h @@ -20,6 +20,7 @@ namespace geometry { POSTFIX_SCHEMA(mapping)(IfcParse::IfcFile* file) : file_(file) {} virtual ifcopenshell::geometry::taxonomy::item* map(const IfcUtil::IfcBaseClass*); virtual void get_representations(std::vector& tasks, std::vector& filters, settings& s); + virtual std::map get_layers(IfcUtil::IfcBaseEntity*); const IfcSchema::IfcMaterial* get_single_material_association(const IfcSchema::IfcProduct* product); IfcSchema::IfcRepresentation* representation_mapped_to(const IfcSchema::IfcRepresentation* representation); diff --git a/src/ifcgeom/schema/mapping.i b/src/ifcgeom/schema/mapping.i index 1c86d47634..2875100592 100644 --- a/src/ifcgeom/schema/mapping.i +++ b/src/ifcgeom/schema/mapping.i @@ -24,110 +24,110 @@ * * ********************************************************************************/ -BIND(IfcShellBasedSurfaceModel); -BIND(IfcFaceBasedSurfaceModel); -BIND(IfcRepresentation); -BIND(IfcMappedItem); +// BIND(IfcShellBasedSurfaceModel); +// BIND(IfcFaceBasedSurfaceModel); +// BIND(IfcRepresentation); +// BIND(IfcMappedItem); // IfcFacetedBrep included // IfcAdvancedBrep included // IfcFacetedBrepWithVoids included // IfcAdvancedBrepWithVoids included -BIND(IfcManifoldSolidBrep); -BIND(IfcGeometricSet); +// BIND(IfcManifoldSolidBrep); +// BIND(IfcGeometricSet); #ifdef SCHEMA_HAS_IfcCylindricalSurface -BIND(IfcCylindricalSurface); +// BIND(IfcCylindricalSurface); #endif #ifdef SCHEMA_HAS_IfcAdvancedBrep -BIND(IfcAdvancedBrep); +// BIND(IfcAdvancedBrep); #endif // FIXME: Surfaces should have a shape type of their own #ifdef SCHEMA_HAS_IfcBSplineSurfaceWithKnots -BIND(IfcBSplineSurfaceWithKnots); +// BIND(IfcBSplineSurfaceWithKnots); #endif #ifdef SCHEMA_HAS_IfcTriangulatedFaceSet -BIND(IfcTriangulatedFaceSet); +// BIND(IfcTriangulatedFaceSet); #endif #ifdef SCHEMA_HAS_IfcExtrudedAreaSolidTapered -BIND(IfcExtrudedAreaSolidTapered); +// BIND(IfcExtrudedAreaSolidTapered); #endif BIND(IfcExtrudedAreaSolid); -BIND(IfcRevolvedAreaSolid); -BIND(IfcConnectedFaceSet); -BIND(IfcBooleanResult); -BIND(IfcPolygonalBoundedHalfSpace); -BIND(IfcHalfSpaceSolid); -BIND(IfcSurfaceOfLinearExtrusion); -BIND(IfcSurfaceOfRevolution); -BIND(IfcBlock); -BIND(IfcRectangularPyramid); -BIND(IfcRightCircularCylinder); -BIND(IfcRightCircularCone); -BIND(IfcSphere); -BIND(IfcCsgSolid); -BIND(IfcCurveBoundedPlane); -BIND(IfcRectangularTrimmedSurface); -BIND(IfcSurfaceCurveSweptAreaSolid); -BIND(IfcSweptDiskSolid); +// BIND(IfcRevolvedAreaSolid); +// BIND(IfcConnectedFaceSet); +// BIND(IfcBooleanResult); +// BIND(IfcPolygonalBoundedHalfSpace); +// BIND(IfcHalfSpaceSolid); +// BIND(IfcSurfaceOfLinearExtrusion); +// BIND(IfcSurfaceOfRevolution); +// BIND(IfcBlock); +// BIND(IfcRectangularPyramid); +// BIND(IfcRightCircularCylinder); +// BIND(IfcRightCircularCone); +// BIND(IfcSphere); +// BIND(IfcCsgSolid); +// BIND(IfcCurveBoundedPlane); +// BIND(IfcRectangularTrimmedSurface); +// BIND(IfcSurfaceCurveSweptAreaSolid); +// BIND(IfcSweptDiskSolid); -BIND(IfcArbitraryProfileDefWithVoids); -BIND(IfcArbitraryClosedProfileDef); -BIND(IfcRoundedRectangleProfileDef); -BIND(IfcRectangleHollowProfileDef); -BIND(IfcRectangleProfileDef); -BIND(IfcTrapeziumProfileDef) -BIND(IfcCShapeProfileDef); +// BIND(IfcArbitraryProfileDefWithVoids); +// BIND(IfcArbitraryClosedProfileDef); +// BIND(IfcRoundedRectangleProfileDef); +// BIND(IfcRectangleHollowProfileDef); +// BIND(IfcRectangleProfileDef); +// BIND(IfcTrapeziumProfileDef) +// BIND(IfcCShapeProfileDef); // IfcAsymmetricIShapeProfileDef included -BIND(IfcIShapeProfileDef); -BIND(IfcLShapeProfileDef); -BIND(IfcTShapeProfileDef); -BIND(IfcUShapeProfileDef); -BIND(IfcZShapeProfileDef); -BIND(IfcCircleHollowProfileDef); -BIND(IfcCircleProfileDef); -BIND(IfcEllipseProfileDef); -BIND(IfcCenterLineProfileDef); -BIND(IfcCompositeProfileDef); -BIND(IfcDerivedProfileDef); +// BIND(IfcIShapeProfileDef); +// BIND(IfcLShapeProfileDef); +// BIND(IfcTShapeProfileDef); +// BIND(IfcUShapeProfileDef); +// BIND(IfcZShapeProfileDef); +// BIND(IfcCircleHollowProfileDef); +// BIND(IfcCircleProfileDef); +// BIND(IfcEllipseProfileDef); +// BIND(IfcCenterLineProfileDef); +// BIND(IfcCompositeProfileDef); +// BIND(IfcDerivedProfileDef); // IfcFaceSurface included // IfcAdvancedFace included in case of IFC4 -BIND(IfcFace); +// BIND(IfcFace); -BIND(IfcEdgeCurve); -BIND(IfcSubedge); -BIND(IfcOrientedEdge); -BIND(IfcEdge); -BIND(IfcEdgeLoop); -BIND(IfcPolyline); -BIND(IfcPolyLoop); -BIND(IfcCompositeCurve); -BIND(IfcTrimmedCurve); -BIND(IfcArbitraryOpenProfileDef); +// BIND(IfcEdgeCurve); +// BIND(IfcSubedge); +// BIND(IfcOrientedEdge); +// BIND(IfcEdge); +// BIND(IfcEdgeLoop); +// BIND(IfcPolyline); +// BIND(IfcPolyLoop); +// BIND(IfcCompositeCurve); +// BIND(IfcTrimmedCurve); +// BIND(IfcArbitraryOpenProfileDef); #ifdef SCHEMA_HAS_IfcIndexedPolyCurve -BIND(IfcIndexedPolyCurve) +// BIND(IfcIndexedPolyCurve) #endif -BIND(IfcCircle); -BIND(IfcEllipse); -BIND(IfcLine); +// BIND(IfcCircle); +// BIND(IfcEllipse); +// BIND(IfcLine); #ifdef SCHEMA_HAS_IfcBSplineCurveWithKnots // IfcRationalBSplineCurveWithKnots included -BIND(IfcBSplineCurveWithKnots); +// BIND(IfcBSplineCurveWithKnots); #endif -BIND(IfcCartesianPoint); -BIND(IfcDirection); -BIND(IfcAxis2Placement2D); +// BIND(IfcCartesianPoint); +// BIND(IfcDirection); +// BIND(IfcAxis2Placement2D); BIND(IfcAxis2Placement3D); -BIND(IfcAxis1Placement); -BIND(IfcCartesianTransformationOperator2DnonUniform); -BIND(IfcCartesianTransformationOperator3DnonUniform); -BIND(IfcCartesianTransformationOperator2D); -BIND(IfcCartesianTransformationOperator3D); -BIND(IfcObjectPlacement); -BIND(IfcVector); -BIND(IfcPlane); +// BIND(IfcAxis1Placement); +// BIND(IfcCartesianTransformationOperator2DnonUniform); +// BIND(IfcCartesianTransformationOperator3DnonUniform); +// BIND(IfcCartesianTransformationOperator2D); +// BIND(IfcCartesianTransformationOperator3D); +// BIND(IfcObjectPlacement); +// BIND(IfcVector); +// BIND(IfcPlane); -BIND(IfcColourRgb); +// BIND(IfcColourRgb); BIND(IfcMaterial); BIND(IfcStyledItem); diff --git a/src/ifcgeom/schema_agnostic/Converter.cpp b/src/ifcgeom/schema_agnostic/Converter.cpp index cee8ad501f..751b68ec8f 100644 --- a/src/ifcgeom/schema_agnostic/Converter.cpp +++ b/src/ifcgeom/schema_agnostic/Converter.cpp @@ -3,7 +3,7 @@ #include "../../ifcgeom/schema_agnostic/IfcGeomElement.h" ifcopenshell::geometry::Converter::Converter(const std::string& geometry_library, IfcParse::IfcFile* file) { - kernel_ = kernels::impl::kernel_implementations().construct(geometry_library, file); + kernel_ = kernels::construct(geometry_library, file); mapping_ = impl::mapping_implementations().construct(file); } @@ -26,15 +26,6 @@ ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create Logger::Error(e); } - ConversionResultPlacement* trsf = nullptr; - try { - convert_placement(product, trsf); - } catch (const std::exception& e) { - Logger::Error(e); - } catch (...) { - Logger::Error("Failed to construct placement"); - } - const std::string guid = product->get_value("GlobalId"); const std::string name = product->get_value_or("Name", ""); @@ -44,7 +35,8 @@ ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create ifcopenshell::geometry::ConversionResults shapes; auto rep_item = mapping_->map(representation); - auto placement = mapping_->map(product); + // @todo decide how to get placement from product + auto placement = (taxonomy::geom_item*) mapping_->map(product); kernel_->convert(rep_item, shapes); shape = new ifcopenshell::geometry::Representation::BRep(s, representation_id_builder.str(), shapes); @@ -57,7 +49,7 @@ ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create guid, // @todo "", - trsf, + placement->matrix, boost::shared_ptr(shape), product ); @@ -202,55 +194,50 @@ ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create */ } -/* -template -ifcopenshell::geometry::kernels::NativeElement* ifcopenshell::geometry::kernels::AbstractKernel::create_brep_for_processed_representation( - const IteratorSettings& //* settings /, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, - ifcopenshell::geometry::kernels::NativeElement* brep) { +ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create_brep_for_processed_representation( + const ifcopenshell::geometry::settings& /* settings */, IfcUtil::IfcBaseEntity* /* representation */, IfcUtil::IfcBaseEntity* product, + ifcopenshell::geometry::NativeElement* brep) +{ int parent_id = -1; try { - IfcUtil::IfcBaseEntity* parent_object = get_decomposing_entity(product); - if (parent_object && parent_object->as()) { + IfcUtil::IfcBaseEntity* parent_object = mapping_->get_decomposing_entity(product); + if (parent_object) { parent_id = parent_object->data().id(); } } catch (const std::exception& e) { Logger::Error(e); } - const std::string name = product->hasName() ? product->Name() : ""; - const std::string guid = product->GlobalId(); + const std::string guid = product->get_value("GlobalId"); + const std::string name = product->get_value_or("Name", ""); - ConversionResultPlacement* trsf = nullptr; - try { - convert_placement(product->ObjectPlacement(), trsf); - } catch (const std::exception& e) { - Logger::Error(e); - } catch (...) { - Logger::Error("Failed to construct placement"); - } + auto placement = (taxonomy::geom_item*) mapping_->map(product); + /* std::string context_string = ""; if (representation->hasRepresentationIdentifier()) { context_string = representation->RepresentationIdentifier(); } else if (representation->ContextOfItems()->hasContextType()) { context_string = representation->ContextOfItems()->ContextType(); } + */ const std::string product_type = product->declaration().name(); - return new NativeElement( + return new NativeElement( product->data().id(), parent_id, name, product_type, guid, - context_string, - trsf, + // @todo + "", + placement->matrix, brep->geometry_pointer(), product ); } -*/ + //#include "../../ifcparse/Ifc2x3.h" //#include "../../ifcparse/Ifc4.h" // @@ -308,42 +295,6 @@ ifcopenshell::geometry::kernels::NativeElement* ifcopenshell::geometry::k // return genus; //} // -//IfcGeom::impl::KernelFactoryImplementation& IfcGeom::impl::kernel_implementations() { -// static KernelFactoryImplementation impl; -// return impl; -//} -// -//extern void init_KernelImplementation_opencascade_Ifc2x3(IfcGeom::impl::KernelFactoryImplementation*); -//extern void init_KernelImplementation_opencascade_Ifc4(IfcGeom::impl::KernelFactoryImplementation*); -//#ifdef IFOPSH_USE_CGAL -//extern void init_KernelImplementation_cgal_Ifc2x3(IfcGeom::impl::KernelFactoryImplementation*); -//extern void init_KernelImplementation_cgal_Ifc4(IfcGeom::impl::KernelFactoryImplementation*); -//#endif -// -//IfcGeom::impl::KernelFactoryImplementation::KernelFactoryImplementation() { -// init_KernelImplementation_opencascade_Ifc2x3(this); -// init_KernelImplementation_opencascade_Ifc4(this); -//#ifdef IFOPSH_USE_CGAL -// init_KernelImplementation_cgal_Ifc2x3(this); -// init_KernelImplementation_cgal_Ifc4(this); -//#endif -//} -// -//void IfcGeom::impl::KernelFactoryImplementation::bind(const std::string& schema_name, const std::string& geometry_library, IfcGeom::impl::kernel_fn fn) { -// const std::string schema_name_lower = boost::to_lower_copy(schema_name); -// this->insert(std::make_pair(std::make_pair(schema_name_lower, geometry_library), fn)); -//} -// -//IfcGeom::Kernel* IfcGeom::impl::KernelFactoryImplementation::construct(const std::string& schema_name, const std::string& geometry_library, IfcParse::IfcFile* file) { -// const std::string schema_name_lower = boost::to_lower_copy(schema_name); -// std::map, IfcGeom::impl::kernel_fn>::const_iterator it; -// it = this->find(std::make_pair(schema_name_lower, geometry_library)); -// if (it == end()) { -// throw IfcParse::IfcException("No geometry kernel registered for " + schema_name); -// } -// return it->second(file); -//} -// // //IfcUtil::IfcBaseEntity* IfcGeom::Kernel::get_decomposing_entity(IfcUtil::IfcBaseEntity* inst, bool include_openings) { // if (inst->as()) { @@ -357,33 +308,6 @@ ifcopenshell::geometry::kernels::NativeElement* ifcopenshell::geometry::k // } //} // -//namespace { -// template -// static std::map get_layers_impl(typename Schema::IfcProduct* prod) { -// std::map layers; -// if (prod->hasRepresentation()) { -// IfcEntityList::ptr r = IfcParse::traverse(prod->Representation()); -// typename Schema::IfcRepresentation::list::ptr representations = r->template as(); -// for (typename Schema::IfcRepresentation::list::it it = representations->begin(); it != representations->end(); ++it) { -// typename Schema::IfcPresentationLayerAssignment::list::ptr a = (*it)->LayerAssignments(); -// for (typename Schema::IfcPresentationLayerAssignment::list::it jt = a->begin(); jt != a->end(); ++jt) { -// layers[(*jt)->Name()] = *jt; -// } -// } -// } -// return layers; -// } -//} -// -//std::map IfcGeom::Kernel::get_layers(IfcUtil::IfcBaseEntity* inst) { -// if (inst->as()) { -// return get_layers_impl(inst->as()); -// } else if (inst->as()) { -// return get_layers_impl(inst->as()); -// } else { -// throw IfcParse::IfcException("Unexpected entity " + inst->declaration().name()); -// } -//} // //bool IfcGeom::Kernel::is_manifold(const ConversionResultShape* s_) { // // @todo make kernel agnostic diff --git a/src/ifcgeom/schema_agnostic/Converter.h b/src/ifcgeom/schema_agnostic/Converter.h index 06cd31ad3b..598123f360 100644 --- a/src/ifcgeom/schema_agnostic/Converter.h +++ b/src/ifcgeom/schema_agnostic/Converter.h @@ -81,11 +81,6 @@ namespace ifcopenshell { namespace geometry { return results; } - bool convert_placement(IfcUtil::IfcBaseClass* item, ifcopenshell::geometry::ConversionResultPlacement*& trsf) { - throw std::runtime_error("not implemented"); - // return implementation_->convert_placement(item, trsf); - } - ifcopenshell::geometry::NativeElement* create_brep_for_representation_and_product(const ifcopenshell::geometry::settings& settings, IfcUtil::IfcBaseEntity* representation, IfcUtil::IfcBaseEntity* product); ifcopenshell::geometry::NativeElement* create_brep_for_processed_representation(const ifcopenshell::geometry::settings& settings, IfcUtil::IfcBaseEntity* representation, IfcUtil::IfcBaseEntity* product, ifcopenshell::geometry::NativeElement* brep); @@ -95,7 +90,6 @@ namespace ifcopenshell { namespace geometry { static bool is_manifold(const ifcopenshell::geometry::ConversionResultShape*); static IfcUtil::IfcBaseEntity* get_decomposing_entity(IfcUtil::IfcBaseEntity*, bool include_openings=true); - static std::map get_layers(IfcUtil::IfcBaseEntity*); static IfcEntityList::ptr find_openings(IfcUtil::IfcBaseEntity* product); */ }; diff --git a/src/ifcgeom/schema_agnostic/IfcGeomElement.h b/src/ifcgeom/schema_agnostic/IfcGeomElement.h index cc8544be5f..a21db0ede1 100644 --- a/src/ifcgeom/schema_agnostic/IfcGeomElement.h +++ b/src/ifcgeom/schema_agnostic/IfcGeomElement.h @@ -54,6 +54,9 @@ namespace ifcopenshell { namespace geometry { } } const ifcopenshell::geometry::taxonomy::matrix4& data() const { return matrix_; } + const element_settings& settings() const { return settings_; } + + EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; class Element { @@ -131,7 +134,10 @@ namespace ifcopenshell { namespace geometry { _unique_id = oss.str(); } + virtual ~Element() {} + + EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; class NativeElement : public Element { diff --git a/src/ifcgeom/schema_agnostic/IfcGeomRepresentation.cpp b/src/ifcgeom/schema_agnostic/IfcGeomRepresentation.cpp index e71ef2fad0..fcca0ad6be 100644 --- a/src/ifcgeom/schema_agnostic/IfcGeomRepresentation.cpp +++ b/src/ifcgeom/schema_agnostic/IfcGeomRepresentation.cpp @@ -28,7 +28,7 @@ #include #include "IfcGeomRepresentation.h" -#include "../../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h" +#include "../../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h" ifcopenshell::geometry::Representation::Serialization::Serialization(const BRep& brep) : Representation(brep.settings()) diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index 4f32f05bb6..725ce46722 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -39,6 +39,7 @@ struct matrix4 : public item { Eigen::Matrix4d components; + matrix4(const Eigen::Matrix4d& c) : components(c), tag(OTHER) {} matrix4() : components(Eigen::Matrix4d::Identity()), tag(IDENTITY) {} virtual item* clone() const { return new matrix4(*this); } diff --git a/src/ifcgeomserver/IfcGeomServer.cpp b/src/ifcgeomserver/IfcGeomServer.cpp index 1acef29553..9dfcd12519 100644 --- a/src/ifcgeomserver/IfcGeomServer.cpp +++ b/src/ifcgeomserver/IfcGeomServer.cpp @@ -47,7 +47,7 @@ #include #endif -#include "../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h" +#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h" #include #include diff --git a/src/serializers/ColladaSerializer.cpp b/src/serializers/ColladaSerializer.cpp index d5434c92da..b9ca3a6786 100644 --- a/src/serializers/ColladaSerializer.cpp +++ b/src/serializers/ColladaSerializer.cpp @@ -191,20 +191,20 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add( node.setNodeName(node_name); node.setType(COLLADASW::Node::NODE); - // The matrix attribute of an entity is basically a 4x3 representation of its ObjectPlacement. - // Note that this placement is absolute, ie it is multiplied with all parent placements. - ifcopenshell::geometry::Transformation* relative_trsf = 0; const ifcopenshell::geometry::Transformation* transformation_towrite = &transformation; // If this is not the first parent, get the relative placement if (parentNodes.size() > 0) { - relative_trsf = new ifcopenshell::geometry::Transformation(matrixStack.top().multiplied(transformation)); + auto m4 = ifcopenshell::geometry::taxonomy::matrix4(matrixStack.top().data().components * transformation.data().components); + relative_trsf = new ifcopenshell::geometry::Transformation(transformation.settings(), m4); transformation_towrite = relative_trsf; } - const std::vector& posmatrix = transformation_towrite->matrix().data(); + // @todo verify + + const double* posmatrix = transformation_towrite->data().components.data(); double matrix_array[4][4] = { { (double)posmatrix[0], (double)posmatrix[3], (double)posmatrix[6], (double)posmatrix[9] }, @@ -251,11 +251,14 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const ifcopensh // If this is not the first parent, get the relative placement if (parentNodes.size() > 0) { - relative_trsf = new ifcopenshell::geometry::Transformation(matrixStack.top().multiplied(parent_trsf)); + auto m4 = ifcopenshell::geometry::taxonomy::matrix4(matrixStack.top().data().components * parent_trsf.data().components); + relative_trsf = new ifcopenshell::geometry::Transformation(parent_trsf.settings(), m4); transformation_towrite = relative_trsf; } - const std::vector& parentMatrix = transformation_towrite->matrix().data(); + // @todo verify + + const double* parentMatrix = transformation_towrite->data().components.data(); double matrix_array[4][4] = { { (double)parentMatrix[0], (double)parentMatrix[3], (double)parentMatrix[6], (double)parentMatrix[9] }, @@ -277,7 +280,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const ifcopensh current_node->addMatrix(matrix_array); // Add the node to the parent stack - matrixStack.push(parent_trsf.inverted()); + matrixStack.push(ifcopenshell::geometry::Transformation(parent_trsf.settings(), ifcopenshell::geometry::taxonomy::matrix4(parent_trsf.data().components.inverse()))); parentNodes.push(current_node); serializer->parentStackId.push(parent.id()); } diff --git a/src/serializers/OpenCascadeBasedSerializer.h b/src/serializers/OpenCascadeBasedSerializer.h index a8e72feddd..185945d6d0 100644 --- a/src/serializers/OpenCascadeBasedSerializer.h +++ b/src/serializers/OpenCascadeBasedSerializer.h @@ -20,7 +20,7 @@ #ifndef OPENCASCADEBASEDSERIALIZER_H #define OPENCASCADEBASEDSERIALIZER_H -#include "../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h" +#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h" #include "../serializers/GeometrySerializer.h" class OpenCascadeBasedSerializer : public GeometrySerializer { diff --git a/src/serializers/SvgSerializer.cpp b/src/serializers/SvgSerializer.cpp index 846a9bac14..323351010b 100644 --- a/src/serializers/SvgSerializer.cpp +++ b/src/serializers/SvgSerializer.cpp @@ -19,7 +19,7 @@ * * ********************************************************************************/ -#include "../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h" +#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h" #include #include diff --git a/src/serializers/XmlSerializer.cpp b/src/serializers/XmlSerializer.cpp index c9e0ae06f8..66ab4c879c 100644 --- a/src/serializers/XmlSerializer.cpp +++ b/src/serializers/XmlSerializer.cpp @@ -1,11 +1,15 @@ #include "XmlSerializer.h" -extern void init_XmlSerializerIfc2x3(XmlSerializerFactory::Factory*); -extern void init_XmlSerializerIfc4(XmlSerializerFactory::Factory*); +extern void init_XmlSerializer_Ifc2x3(XmlSerializerFactory::Factory*); +extern void init_XmlSerializer_Ifc4(XmlSerializerFactory::Factory*); +extern void init_XmlSerializer_Ifc4x1(XmlSerializerFactory::Factory*); +extern void init_XmlSerializer_Ifc4x2(XmlSerializerFactory::Factory*); XmlSerializerFactory::Factory::Factory() { - init_XmlSerializerIfc2x3(this); - init_XmlSerializerIfc4(this); + init_XmlSerializer_Ifc2x3(this); + init_XmlSerializer_Ifc4(this); + init_XmlSerializer_Ifc4x1(this); + init_XmlSerializer_Ifc4x2(this); } void XmlSerializerFactory::Factory::bind(const std::string& schema_name, fn f) {