From 45136fce6c9c6e0fc9dc302b5bba91a92ab027d9 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 20 Feb 2019 12:29:44 +0100 Subject: [PATCH] GeomServer: precision on double formatting, compound in meters, bounding box also from compound --- src/ifcgeom/IfcGeomRepresentation.cpp | 4 ++-- src/ifcgeom/IfcGeomRepresentation.h | 2 +- src/ifcgeomserver/IfcGeomServer.cpp | 29 +++++++++++++++------------ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/ifcgeom/IfcGeomRepresentation.cpp b/src/ifcgeom/IfcGeomRepresentation.cpp index 4a6158601a..0656899114 100644 --- a/src/ifcgeom/IfcGeomRepresentation.cpp +++ b/src/ifcgeom/IfcGeomRepresentation.cpp @@ -82,7 +82,7 @@ TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_GTrsf& t) { } } -TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const { +TopoDS_Compound IfcGeom::Representation::BRep::as_compound(bool force_meters) const { TopoDS_Compound compound; BRep_Builder builder; builder.MakeCompound(compound); @@ -90,7 +90,7 @@ TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const { const TopoDS_Shape& s = it->Shape(); gp_GTrsf trsf = it->Placement(); - if (settings().get(IteratorSettings::CONVERT_BACK_UNITS)) { + if (!force_meters && settings().get(IteratorSettings::CONVERT_BACK_UNITS)) { gp_Trsf scale; scale.SetScaleFactor(1.0 / settings().unit_magnitude()); trsf.PreMultiply(scale); diff --git a/src/ifcgeom/IfcGeomRepresentation.h b/src/ifcgeom/IfcGeomRepresentation.h index 7f1eb8f9e5..cf5401704f 100644 --- a/src/ifcgeom/IfcGeomRepresentation.h +++ b/src/ifcgeom/IfcGeomRepresentation.h @@ -75,7 +75,7 @@ namespace IfcGeom { IfcGeom::IfcRepresentationShapeItems::const_iterator end() const { return shapes_.end(); } const IfcGeom::IfcRepresentationShapeItems& shapes() const { return shapes_; } const std::string& id() const { return id_; } - TopoDS_Compound as_compound() const; + TopoDS_Compound as_compound(bool force_meters = false) const; bool calculate_volume(double&) const; bool calculate_surface_area(double&) const; diff --git a/src/ifcgeomserver/IfcGeomServer.cpp b/src/ifcgeomserver/IfcGeomServer.cpp index 64057e9641..1f0c210b0b 100644 --- a/src/ifcgeomserver/IfcGeomServer.cpp +++ b/src/ifcgeomserver/IfcGeomServer.cpp @@ -91,10 +91,18 @@ std::string format_json(const std::string& s) { return "\"" + s + "\""; } +template <> +std::string format_json(const double& d) { + std::stringstream ss; + ss << std::setprecision(std::numeric_limits::digits10) << d; + return ss.str(); +} + template <> std::string format_json(const gp_Dir& d) { std::stringstream ss; - ss << "[" << d.X() << "," << d.Y() << "," << d.Z() << "]"; + ss << std::setprecision(std::numeric_limits::digits10) + << "[" << d.X() << "," << d.Y() << "," << d.Z() << "]"; return ss.str(); } @@ -470,7 +478,7 @@ public: boost::optional largest_face_dir; { - TopoDS_Compound compound = elem_->geometry().as_compound(); + TopoDS_Compound compound = elem_->geometry().as_compound(true); TopExp_Explorer exp(compound, TopAbs_FACE); for (; exp.More(); exp.Next()) { GProp_GProps prop; @@ -488,20 +496,11 @@ public: } } } - } - if (largest_face_dir) { - put_json(LARGEST_FACE_DIRECTION, *largest_face_dir); - put_json(LARGEST_FACE_AREA, largest_face_area); - } - - { Bnd_Box box; - double xyz[6]; + double xyz[6]; - for (auto& part : elem->geometry()) { - BRepBndLib::AddClose(part.Shape(), box); - } + BRepBndLib::AddClose(compound, box); if (!box.IsVoid()) { box.Get(xyz[0], xyz[1], xyz[2], xyz[3], xyz[4], xyz[5]); @@ -510,7 +509,11 @@ public: put_json(BOUNDING_BOX_SIZE_ALONG_ + XYZ[i], bsz); } } + } + if (largest_face_dir) { + put_json(LARGEST_FACE_DIRECTION, *largest_face_dir); + put_json(LARGEST_FACE_AREA, largest_face_area); } } };