void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<real_t>* o) { for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) { gp_GTrsf gtrsf = it->Placement(); const gp_Trsf& o_trsf = o->transformation().data(); gtrsf.PreMultiply(o_trsf); if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) { gp_Trsf scale; scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude()); gtrsf.PreMultiply(scale); } const TopoDS_Shape& s = it->Shape(); bool trsf_valid = false; gp_Trsf trsf; try { trsf = gtrsf.Trsf(); trsf_valid = true; } catch (...) {} const TopoDS_Shape moved_shape = trsf_valid ? BRepBuilderAPI_Transform(s, trsf, true).Shape() : BRepBuilderAPI_GTransform(s, gtrsf, true).Shape(); writeShape(moved_shape); } }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcDerivedProfileDef* l, TopoDS_Shape& face) { TopoDS_Face f; gp_Trsf2d trsf2d; if (convert_face(l->ParentProfile(), f) && IfcGeom::Kernel::convert(l->Operator(), trsf2d)) { gp_Trsf trsf = trsf2d; face = TopoDS::Face(BRepBuilderAPI_Transform(f, trsf)); return true; } else { return false; } }
void grivySerializer::writeShapeModel(const IfcGeomObjects::IfcGeomShapeModelObject* o) { IfcGeom::ShapeList new_topo_shapes; for (IfcGeom::ShapeList::const_iterator it = o->mesh->begin(); it != o->mesh->end(); ++ it) { //iterate over shapelist gp_GTrsf gtrsf = *it->first; // Read specific transformation gtrsf.PreMultiply(o->trsf); // Read+apply common transformation const TopoDS_Shape& s = *it->second; // Read TopoDS_Shape bool trsf_valid = false; gp_Trsf trsf; try { trsf = gtrsf.Trsf(); // Test transformation trsf_valid = true; // Check when succesfull } catch (...) {} // Do Boolean ops here? no const TopoDS_Shape moved_shape = trsf_valid ? BRepBuilderAPI_Transform(s, trsf, true).Shape() // Valid transfmation : BRepBuilderAPI_GTransform(s, gtrsf, true).Shape(); // Invalid transfmation // Use to recreate IfcGeomShapeModelObject o using moved_shape IfcGeom::LocationShape* new_loc_shape; new_loc_shape = new IfcGeom::LocationShape(>rsf,&moved_shape); //moved_shape / s? new_topo_shapes.push_back(*new_loc_shape); // store in new_shapes } IfcGeomObjects::IfcRepresentationShapeModel* rep_shape; rep_shape = new IfcGeomObjects::IfcRepresentationShapeModel(o->mesh->getId(),new_topo_shapes); IfcGeomObjects::IfcGeomShapeModelObject* new_o; new_o = new IfcGeomObjects::IfcGeomShapeModelObject(o->id,o->parent_id,o->name,o->type,o->guid,o->trsf,rep_shape); ////IfcGeomObjects::IfcGeomShapeModelObject( //// Convert to BRep //IfcGeomObjects::IfcGeomBrepDataObject* brep_object; //brep_object = new IfcGeomObjects::IfcGeomBrepDataObject(*o); //brep_object->mesh->brep_data; //// Convert to triangulated BRep IfcGeomObjects::IfcGeomObject* geom_object; geom_object = new IfcGeomObjects::IfcGeomObject(*new_o); //// Write CityGML writeTesselated(geom_object); }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcRectangularPyramid* l, TopoDS_Shape& shape) { const double dx = l->XLength() * getValue(GV_LENGTH_UNIT); const double dy = l->YLength() * getValue(GV_LENGTH_UNIT); const double dz = l->Height() * getValue(GV_LENGTH_UNIT); BRepPrimAPI_MakeWedge builder(dx, dz, dy, dx / 2., dy / 2., dx / 2., dy / 2.); gp_Trsf trsf1, trsf2; trsf2.SetValues( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 #if OCC_VERSION_HEX < 0x60800 , Precision::Angular(), Precision::Confusion() #endif ); IfcGeom::Kernel::convert(l->Position(), trsf1); shape = BRepBuilderAPI_Transform(builder.Solid(), trsf1 * trsf2); return true; }
QString Dr=*(parameterList["PARIMD0"]); x=LVPS_Utility::ToDouble(Dr); Dr=*(parameterList["PARIMD1"]); y=LVPS_Utility::ToDouble(Dr); Dr=*(parameterList["PARIMD2"]); double length=LVPS_Utility::ToDouble(Dr); Dr=*(parameterList["PARIMD3"]); double con=LVPS_Utility::ToDouble(Dr); gp_Pnt A=gp_Pnt(x+length/2,y,0); gp_Pnt B=gp_Pnt(x-length/2,y,0); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(A , B); Shape = BRepBuilderAPI_MakeWire(aEdge1); gp_Trsf trsf; trsf.SetRotation(gp_Ax1(gp_Pnt(x,y,0),gp_Dir(0,0,1)),con); Shape = BRepBuilderAPI_Transform(Shape,trsf); myAISShape = new AIS_Shape (Shape); myAISShape->SetMaterial (Graphic3d_NOM_PLASTIC); SetColor(myAISShape); return 0; }; LVPS_GraphicModel* LVPS_Lined::Clone() { return (LVPS_GraphicModel*)(new LVPS_Lined()); }
void SvgSerializer::write(const IfcGeom::BRepElement<double>* o) { IfcSchema::IfcBuildingStorey* storey = 0; IfcSchema::IfcObjectDefinition* obdef = static_cast<IfcSchema::IfcObjectDefinition*>(file->entityById(o->id())); #ifndef USE_IFC4 typedef IfcSchema::IfcRelDecomposes decomposition_element; #else typedef IfcSchema::IfcRelAggregates decomposition_element; #endif while (true) { // Iterate over the decomposing element to find the parent IfcBuildingStorey decomposition_element::list::ptr decomposes = obdef->Decomposes(); if (!decomposes->size()) { if (obdef->is(IfcSchema::Type::IfcElement)) { IfcSchema::IfcRelContainedInSpatialStructure::list::ptr containment = ((IfcSchema::IfcElement*)obdef)->ContainedInStructure(); if (!containment->size()) { break; } for (IfcSchema::IfcRelContainedInSpatialStructure::list::it it = containment->begin(); it != containment->end(); ++it) { IfcSchema::IfcRelContainedInSpatialStructure* container = *it; if (container->RelatingStructure() != obdef) { obdef = container->RelatingStructure(); } } } else { break; } } else { for (decomposition_element::list::it it = decomposes->begin(); it != decomposes->end(); ++it) { decomposition_element* decompose = *it; if (decompose->RelatingObject() != obdef) { obdef = decompose->RelatingObject(); } } } if (obdef->is(IfcSchema::Type::IfcBuildingStorey)) { storey = static_cast<IfcSchema::IfcBuildingStorey*>(obdef); break; } } if (!storey) return; path_object& p = start_path(storey, nameElement(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<double>& 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 TopoDS_Shape& s = it->Shape(); bool trsf_valid = false; gp_Trsf trsf; try { trsf = gtrsf.Trsf(); trsf_valid = true; } catch (...) {} const TopoDS_Shape moved_shape = trsf_valid ? BRepBuilderAPI_Transform(s, trsf, true).Shape() : BRepBuilderAPI_GTransform(s, gtrsf, true).Shape(); const double inf = std::numeric_limits<double>::infinity(); double zmin = inf; double zmax = -inf; {TopExp_Explorer exp(moved_shape, TopAbs_VERTEX); for (; exp.More(); exp.Next()) { const TopoDS_Vertex& vertex = TopoDS::Vertex(exp.Current()); gp_Pnt pnt = BRep_Tool::Pnt(vertex); if (pnt.Z() < zmin) { zmin = pnt.Z(); } if (pnt.Z() > zmax) { zmax = pnt.Z(); } }} if (section_height) { if (zmin > section_height || zmax < section_height) continue; } else { if (zmin == inf || (zmax - zmin) < 1.) continue; } const double cut_z = section_height.get_value_or(zmin + 1.); // Create a horizontal cross section 1 meter above the bottom point of the shape TopoDS_Shape result = BRepAlgoAPI_Section(moved_shape, gp_Pln(gp_Pnt(0, 0, cut_z), gp::DZ())); Handle(TopTools_HSequenceOfShape) edges = new TopTools_HSequenceOfShape(); Handle(TopTools_HSequenceOfShape) wires = new TopTools_HSequenceOfShape(); {TopExp_Explorer exp(result, TopAbs_EDGE); for (; exp.More(); exp.Next()) { edges->Append(exp.Current()); }} ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edges, 1e-5, false, wires); gp_Pnt prev; for (int i = 1; i <= wires->Length(); ++i) { const TopoDS_Wire& wire = TopoDS::Wire(wires->Value(i)); write(p, wire); } } }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcSurfaceCurveSweptAreaSolid* l, TopoDS_Shape& shape) { gp_Trsf directrix, position; TopoDS_Shape face; TopoDS_Wire wire, section; if (!l->ReferenceSurface()->is(IfcSchema::Type::IfcPlane)) { Logger::Message(Logger::LOG_WARNING, "Reference surface not supported", l->ReferenceSurface()->entity); return false; } if (!IfcGeom::Kernel::convert(l->Position(), position) || !convert_face(l->SweptArea(), face) || !convert_wire(l->Directrix(), wire) ) { return false; } gp_Pln pln; gp_Pnt directrix_origin; gp_Vec directrix_tangent; bool directrix_on_plane = true; IfcGeom::Kernel::convert((IfcSchema::IfcPlane*) l->ReferenceSurface(), pln); // As per Informal propositions 2: The Directrix shall lie on the ReferenceSurface. // This is not always the case with the test files in the repository. I am not sure // how to deal with this and whether my interpretation of the propositions is // correct. However, if it has been asserted that the vertices of the directrix do // not conform to the ReferenceSurface, the ReferenceSurface is ignored. { for (TopExp_Explorer exp(wire, TopAbs_VERTEX); exp.More(); exp.Next()) { if (pln.Distance(BRep_Tool::Pnt(TopoDS::Vertex(exp.Current()))) > ALMOST_ZERO) { directrix_on_plane = false; Logger::Message(Logger::LOG_WARNING, "The Directrix does not lie on the ReferenceSurface", l->entity); break; } } } { TopExp_Explorer exp(wire, TopAbs_EDGE); TopoDS_Edge edge = TopoDS::Edge(exp.Current()); double u0, u1; Handle(Geom_Curve) crv = BRep_Tool::Curve(edge, u0, u1); crv->D1(u0, directrix_origin, directrix_tangent); } if (pln.Axis().Direction().IsNormal(directrix_tangent, Precision::Approximation()) && directrix_on_plane) { directrix.SetTransformation(gp_Ax3(directrix_origin, directrix_tangent, pln.Axis().Direction()), gp::XOY()); } else { directrix.SetTransformation(gp_Ax3(directrix_origin, directrix_tangent), gp::XOY()); } face = BRepBuilderAPI_Transform(face, directrix); // NB: Note that StartParam and EndParam param are ignored and the assumption is // made that the parametric range over which to be swept matches the IfcCurve in // its entirety. BRepOffsetAPI_MakePipeShell builder(wire); { TopExp_Explorer exp(face, TopAbs_WIRE); section = TopoDS::Wire(exp.Current()); } builder.Add(section); builder.SetTransitionMode(BRepBuilderAPI_RightCorner); if (directrix_on_plane) { builder.SetMode(pln.Axis().Direction()); } builder.Build(); builder.MakeSolid(); shape = builder.Shape(); shape.Move(position); return true; }