From 44ddc5e6dc3086852c1541b1a651576cf1f4abb8 Mon Sep 17 00:00:00 2001 From: aothms Date: Fri, 9 Oct 2015 14:23:38 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Don't=20use=20IfcMappedItems=20for=20IfcOpe?= =?UTF-8?q?nHouse=20walls,=20as=20suggested=20by=20Ian=20Cl=C3=A9vy=20in?= =?UTF-8?q?=20https://sourceforge.net/p/ifcopenshell/discussion/1782716/th?= =?UTF-8?q?read/f9b586ca/=3Flimit=3D25#ab87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/examples/IfcOpenHouse.cpp | 43 +++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/examples/IfcOpenHouse.cpp b/src/examples/IfcOpenHouse.cpp index 9f4887c5f9..00cfe1503d 100644 --- a/src/examples/IfcOpenHouse.cpp +++ b/src/examples/IfcOpenHouse.cpp @@ -195,43 +195,46 @@ int main(int argc, char** argv) { file.addBuildingProduct(north_wall); file.setSurfaceColour(north_wall->Representation(), wall_colour); - IfcSchema::IfcShapeRepresentation* clipped_wall_body_rep = file.addEmptyRepresentation(); - file.addBox(clipped_wall_body_rep, 5000, 360, 6000); - // The east wall geometry is clipped using two IfcHalfSpaceSolids, created from an - // 'axis 3d placement' that specifies the plane against which the geometry is clipped. - file.clipRepresentation(clipped_wall_body_rep, file.addPlacement3d(-2500, 0, 3000, -1, 0, 1), false); - file.clipRepresentation(clipped_wall_body_rep, file.addPlacement3d(2500, 0, 3000, 1, 0, 1), false); + // Two identical representations are created for the two remaining walls. Mapped items + // are not used, because it is not allowed by the standard for wall body representations. + // MappedItems are not allowed for Axis representations as per CV-2x3-161 + IfcSchema::IfcProductDefinitionShape* clipped_wall_body_reps[2]; + for (int i = 0; i < 2; ++i) { + IfcSchema::IfcShapeRepresentation* body = file.addEmptyRepresentation(); + file.addBox(body, 5000, 360, 6000); + // The wall geometry is clipped using two IfcHalfSpaceSolids, created from an + // 'axis 3d placement' that specifies the plane against which the geometry is clipped. + file.clipRepresentation(body, file.addPlacement3d(-2500, 0, 3000, -1, 0, 1), false); + file.clipRepresentation(body, file.addPlacement3d(2500, 0, 3000, 1, 0, 1), false); + file.setSurfaceColour(body, wall_colour); + + IfcSchema::IfcShapeRepresentation* axis = file.addEmptyRepresentation("Axis", "Curve2D"); + file.addAxis(axis, 5000); + + IfcSchema::IfcRepresentation::list::ptr reps(new IfcSchema::IfcRepresentation::list); + reps->push(body); + reps->push(axis); + clipped_wall_body_reps[i] = new IfcSchema::IfcProductDefinitionShape(null, null, reps); + } // Now create a wall on the east of the building, again starting with just a box shape IfcSchema::IfcWallStandardCase* east_wall = new IfcSchema::IfcWallStandardCase(guid(), file.getSingle(), - S("East wall"), null, null, file.addLocalPlacement(storey_placement, 4820, 2500, 0, 0, 0, 1, 0, 1, 0), file.addMappedItem(clipped_wall_body_rep), null + S("East wall"), null, null, file.addLocalPlacement(storey_placement, 4820, 2500, 0, 0, 0, 1, 0, 1, 0), clipped_wall_body_reps[0], null #ifdef USE_IFC4 , IfcSchema::IfcWallTypeEnum::IfcWallType_STANDARD #endif ); file.addBuildingProduct(east_wall); - file.setSurfaceColour(clipped_wall_body_rep, wall_colour); - // The east wall is copied to the west location of the house IfcSchema::IfcWallStandardCase* west_wall = new IfcSchema::IfcWallStandardCase(guid(), file.getSingle(), - S("West wall"), null, null, file.addLocalPlacement(storey_placement, -4820, 2500, 0, 0, 0, 1, 0, -1, 0), file.addMappedItem(clipped_wall_body_rep), null + S("West wall"), null, null, file.addLocalPlacement(storey_placement, -4820, 2500, 0, 0, 0, 1, 0, -1, 0), clipped_wall_body_reps[1], null #ifdef USE_IFC4 , IfcSchema::IfcWallTypeEnum::IfcWallType_STANDARD #endif ); file.addBuildingProduct(west_wall); - for (int i = 0; i < 2; ++i) { - // CV-2x3-161: MappedItems are not allowed for Axis representations - IfcSchema::IfcWallStandardCase* wall = i == 0 ? east_wall : west_wall; - IfcSchema::IfcShapeRepresentation* wall_axis_rep = file.addEmptyRepresentation("Axis", "Curve2D"); - file.addAxis(wall_axis_rep, 5000); - IfcSchema::IfcRepresentation::list::ptr reps = wall->Representation()->Representations(); - reps->push(wall_axis_rep); - wall->Representation()->setRepresentations(reps); - } - // The west wall is assigned an opening element we created for the south wall, opening elements are // not shared accross building elements, even if they share the same representation. Hence, the east // wall will not feature this opening. From f3af39546be9ecd485737ff0954cfb92807fca1d Mon Sep 17 00:00:00 2001 From: aothms Date: Tue, 13 Oct 2015 11:15:45 +0200 Subject: [PATCH 2/3] Don't construct transformation from matrix, but use original data. --- src/ifcconvert/OpenCascadeBasedSerializer.cpp | 14 +------------- src/ifcconvert/SvgSerializer.cpp | 12 +----------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/ifcconvert/OpenCascadeBasedSerializer.cpp b/src/ifcconvert/OpenCascadeBasedSerializer.cpp index 77bc7e7fc9..3dc8ad9386 100644 --- a/src/ifcconvert/OpenCascadeBasedSerializer.cpp +++ b/src/ifcconvert/OpenCascadeBasedSerializer.cpp @@ -40,19 +40,7 @@ void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement* o) { for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) { gp_GTrsf gtrsf = it->Placement(); - const std::vector& matrix = o->transformation().matrix().data(); - - // Convert the matrix back into a transformation object. The tolerance values - // are taken into consideration to reconstruct the form of the transformation. - gp_Trsf o_trsf; - o_trsf.SetValues( - matrix[0], matrix[3], matrix[6], matrix[ 9], - matrix[1], matrix[4], matrix[7], matrix[10], - matrix[2], matrix[5], matrix[8], matrix[11] -#if OCC_VERSION_HEX < 0x60800 - , Precision::Angular(), Precision::Confusion() -#endif - ); + const gp_Trsf& o_trsf = o->transformation().data(); gtrsf.PreMultiply(o_trsf); const TopoDS_Shape& s = it->Shape(); diff --git a/src/ifcconvert/SvgSerializer.cpp b/src/ifcconvert/SvgSerializer.cpp index 8319393ff8..7c03241971 100644 --- a/src/ifcconvert/SvgSerializer.cpp +++ b/src/ifcconvert/SvgSerializer.cpp @@ -217,17 +217,7 @@ void SvgSerializer::write(const IfcGeom::BRepElement* o) { for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) { gp_GTrsf gtrsf = it->Placement(); - gp_Trsf o_trsf; - const std::vector& matrix = o->transformation().matrix().data(); - o_trsf.SetValues( - matrix[0], matrix[3], matrix[6], matrix[ 9], - matrix[1], matrix[4], matrix[7], matrix[10], - matrix[2], matrix[5], matrix[8], matrix[11] -#if OCC_VERSION_HEX < 0x60800 - , Precision::Angular(), Precision::Confusion() -#endif - ); - gtrsf.PreMultiply(o_trsf); + const gp_Trsf& o_trsf = o->transformation().data(); const TopoDS_Shape& s = it->Shape(); bool trsf_valid = false; From fdf1b296829e7e0538c783bd9be27c6525c77b13 Mon Sep 17 00:00:00 2001 From: aothms Date: Thu, 22 Oct 2015 12:04:49 +0200 Subject: [PATCH 3/3] Return shape for arbitrary representation items in ifcopenshell.geom.create_shape() --- src/ifcgeom/IfcRegister.cpp | 9 ++ .../ifcopenshell/geom/occ_utils.py | 15 +++- src/ifcwrap/IfcGeomWrapper.i | 84 ++++++++++++++----- 3 files changed, 82 insertions(+), 26 deletions(-) diff --git a/src/ifcgeom/IfcRegister.cpp b/src/ifcgeom/IfcRegister.cpp index e00654da5d..2b7d836c63 100644 --- a/src/ifcgeom/IfcRegister.cpp +++ b/src/ifcgeom/IfcRegister.cpp @@ -24,6 +24,15 @@ using namespace IfcSchema; using namespace IfcUtil; bool IfcGeom::Kernel::convert_shapes(const IfcBaseClass* l, IfcRepresentationShapeItems& r) { + if (shape_type(l) != ST_SHAPELIST) { + TopoDS_Shape shp; + if (convert_shape(l, shp)) { + r.push_back(IfcGeom::IfcRepresentationShapeItem(shp, get_style(l->as()))); + return true; + } + return false; + } + #include "IfcRegisterConvertShapes.h" Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity); return false; diff --git a/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py b/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py index be5c93e8b3..591b0b1909 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py @@ -52,8 +52,14 @@ def get_bounding_box_center(bbox): def create_shape_from_serialization(brep_object): brep_data, occ_shape = None, None - try: brep_data = brep_object.geometry.brep_data - except: pass + is_product_shape = True + try: + brep_data = brep_object.geometry.brep_data + except: + try: + brep_data = brep_object.brep_data + is_product_shape = False + except: pass if not brep_data: return tuple(brep_object, None) try: @@ -62,5 +68,8 @@ def create_shape_from_serialization(brep_object): occ_shape = ss.Shape(ss.NbShapes()) except: pass - return tuple(brep_object, occ_shape) + if is_product_shape: + return tuple(brep_object, occ_shape) + else: + return occ_shape diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 1069f6ba30..84a435b69e 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -72,17 +72,35 @@ } } +// A visitor +%{ +struct ShapeRTTI : public boost::static_visitor +{ + PyObject* operator()(IfcGeom::Element* elem) const { + IfcGeom::SerializedElement* serialized_elem = dynamic_cast*>(elem); + IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast*>(elem); + if (triangulation_elem) { + return SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElementT_double_t, SWIG_POINTER_OWN); + } else if (serialized_elem) { + return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElementT_double_t, SWIG_POINTER_OWN); + } + } + PyObject* operator()(IfcGeom::Representation::Representation* representation) const { + IfcGeom::Representation::Serialization* serialized_representation = dynamic_cast(representation); + IfcGeom::Representation::Triangulation* triangulated_representation = dynamic_cast*>(representation); + if (serialized_representation) { + return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_representation), SWIGTYPE_p_IfcGeom__Representation__Serialization, SWIG_POINTER_OWN); + } else if (triangulated_representation) { + return SWIG_NewPointerObj(SWIG_as_voidptr(triangulated_representation), SWIGTYPE_p_IfcGeom__Representation__TriangulationT_double_t, SWIG_POINTER_OWN); + } + } +}; +%} + // Note that these elements ARE to be owned by SWIG/Python %typemap(out) boost::variant*, IfcGeom::Representation::Representation*> { // See which type is set and return appropriate - IfcGeom::Element* elem = boost::get*>($1); - IfcGeom::SerializedElement* serialized_elem = dynamic_cast*>(elem); - IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast*>(elem); - if (triangulation_elem) { - $result = SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElementT_double_t, SWIG_POINTER_OWN); - } else if (serialized_elem) { - $result = SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElementT_double_t, SWIG_POINTER_OWN); - } + $result = boost::apply_visitor(ShapeRTTI(), $1); } // This does not seem to work: @@ -218,25 +236,25 @@ %inline %{ boost::variant*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcParse::IfcLateBoundEntity* instance, IfcParse::IfcLateBoundEntity* representation = 0) { + IfcParse::IfcFile* file = instance->entity->file; + IfcSchema::IfcProject::list::ptr projects = file->entitiesByType(); + if (projects->size() != 1) { + throw IfcParse::IfcException("Not a single IfcProject instance"); + } + IfcSchema::IfcProject* project = *projects->begin(); + + IfcGeom::Kernel kernel; + kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.sew_shells() ? 1000 : -1); + kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.)); + std::pair length_unit = kernel.initializeUnits(project->UnitsInContext()); + if (instance->is(IfcSchema::Type::IfcProduct)) { if (representation) { if (!representation->is(IfcSchema::Type::IfcRepresentation)) { throw IfcParse::IfcException("Supplied representation not of type IfcRepresentation"); } } - - IfcParse::IfcFile* file = instance->entity->file; - - IfcSchema::IfcProject::list::ptr projects = file->entitiesByType(); - if (projects->size() != 1) { - throw IfcParse::IfcException("Not a single IfcProject instance"); - } - IfcSchema::IfcProject* project = *projects->begin(); - - IfcGeom::Kernel kernel; - kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.sew_shells() ? 1000 : -1); - kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.)); - + IfcSchema::IfcProduct* product = (IfcSchema::IfcProduct*) instance; if (!representation && !product->hasRepresentation()) { @@ -318,7 +336,6 @@ if (context->hasPrecision()) { precision = context->Precision(); } - std::pair length_unit = kernel.initializeUnits(project->UnitsInContext()); precision *= length_unit.second; // Some arbitrary factor that has proven to work better for the models in the set of test files. @@ -342,7 +359,28 @@ throw IfcParse::IfcException("No element to return based on provided settings"); } } else { - throw IfcParse::IfcException("Only obtaining representations for IfcProduct instances is currently supported"); + if (!representation) { + if (instance->is(IfcSchema::Type::IfcRepresentationItem) || instance->is(IfcSchema::Type::IfcRepresentation)) { + IfcGeom::IfcRepresentationShapeItems shapes; + if (kernel.convert_shapes(instance, shapes)) { + IfcGeom::ElementSettings element_settings(settings, kernel.getValue(IfcGeom::Kernel::GV_LENGTH_UNIT), IfcSchema::Type::ToString(instance->type())); + IfcGeom::Representation::BRep brep(element_settings, instance->entity->id(), shapes); + try { + if (settings.use_brep_data()) { + return new IfcGeom::Representation::Serialization(brep); + } else if (!settings.disable_triangulation()) { + return new IfcGeom::Representation::Triangulation(brep); + } + } catch (...) { + throw IfcParse::IfcException("Error during shape serialization"); + } + } else { + throw IfcParse::IfcException("Geometrical element not understood"); + } + } + } else { + throw IfcParse::IfcException("Invalid additional representation specified"); + } } } %}