Fix transformation in serialization element, accept geometry library in more geom functions

This commit is contained in:
Thomas Krijnen
2023-08-26 11:35:23 +02:00
parent 5336b2f987
commit 4bb3cc5c90
10 changed files with 67 additions and 35 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ namespace IfcGeom {
public:
virtual void Triangulate(const IteratorSettings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, Representation::Triangulation* t, int surface_style_id) const = 0;
virtual void Serialize(std::string&) const = 0;
virtual void Serialize(const ifcopenshell::geometry::taxonomy::matrix4& place, std::string&) const = 0;
virtual ConversionResultShape* clone() const = 0;
virtual int surface_genus() const = 0;
virtual bool is_manifold() const = 0;
+3 -2
View File
@@ -173,12 +173,13 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
if (brep.begin() != brep.end()) {
if (dynamic_cast<ifcopenshell::geometry::OpenCascadeShape*>(brep.begin()->Shape())) {
ConversionResultShape* shape = brep.as_compound();
shape->Serialize(brep_data_);
ifcopenshell::geometry::taxonomy::matrix4 identity;
shape->Serialize(identity, brep_data_);
delete shape;
} else {
for (auto it = brep.begin(); it != brep.end(); ++it) {
std::string part;
it->Shape()->Serialize(part);
it->Shape()->Serialize(*it->Placement(), part);
if (brep_data_.size()) {
brep_data_ = brep_data_ + "\n---\n" + part;
} else {
@@ -102,9 +102,26 @@ void ifcopenshell::geometry::CgalShape::Triangulate(const IfcGeom::IteratorSetti
}
void ifcopenshell::geometry::CgalShape::Serialize(std::string& r) const {
void ifcopenshell::geometry::CgalShape::Serialize(const ifcopenshell::geometry::taxonomy::matrix4& place, std::string& r) const {
cgal_shape_t s = shape_;
if (!place.is_identity()) {
const auto& m = place.ccomponents();
// @todo check
const cgal_placement_t trsf(
m(0, 0), m(0, 1), m(0, 2), m(0, 3),
m(1, 0), m(1, 1), m(1, 2), m(1, 3),
m(2, 0), m(2, 1), m(2, 2), m(2, 3));
// Apply transformation
for (auto &vertex : vertices(s)) {
vertex->point() = vertex->point().transform(trsf);
}
}
std::stringstream sstream;
sstream << shape_;
sstream << s;
r = sstream.str();
}
@@ -96,7 +96,7 @@ namespace ifcopenshell { namespace geometry {
virtual void Triangulate(const IfcGeom::IteratorSettings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const;
virtual void Serialize(std::string&) const;
virtual void Serialize(const ifcopenshell::geometry::taxonomy::matrix4& place, std::string&) const;
virtual IfcGeom::ConversionResultShape* clone() const {
return new CgalShape(shape_);
@@ -2,6 +2,7 @@
#include "../../../ifcparse/IfcLogger.h"
#include "../../../ifcgeom/IfcGeomRepresentation.h"
#include "base_utils.h"
#include <TopoDS.hxx>
#include <Geom_SphericalSurface.hxx>
@@ -217,9 +218,10 @@ void ifcopenshell::geometry::OpenCascadeShape::Triangulate(const IfcGeom::Iterat
BRepTools::Clean(shape_);
}
void ifcopenshell::geometry::OpenCascadeShape::Serialize(std::string& r) const {
void ifcopenshell::geometry::OpenCascadeShape::Serialize(const ifcopenshell::geometry::taxonomy::matrix4& place, std::string& r) const {
auto s = IfcGeom::util::apply_transformation(shape_, place);
std::stringstream sstream;
BRepTools::Write(shape_, sstream);
BRepTools::Write(s, sstream);
r = sstream.str();
}
@@ -49,7 +49,7 @@ namespace ifcopenshell {
virtual void Triangulate(const IfcGeom::IteratorSettings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const;
virtual void Serialize(std::string&) const;
virtual void Serialize(const ifcopenshell::geometry::taxonomy::matrix4& place, std::string&) const;
virtual IfcGeom::ConversionResultShape* clone() const {
return new OpenCascadeShape(shape_);
@@ -138,10 +138,6 @@ public:
bool convert(const taxonomy::solid::ptr, TopoDS_Shape&);
bool convert(const taxonomy::bspline_surface::ptr bs, Handle(Geom_Surface) surf);
TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const taxonomy::matrix4& t);
TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_GTrsf& t);
TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_Trsf& t);
virtual bool convert_impl(const taxonomy::face::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const taxonomy::solid::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const taxonomy::shell::ptr, IfcGeom::ConversionResults&);
+17 -1
View File
@@ -286,15 +286,31 @@ TopoDS_Shape IfcGeom::util::apply_transformation(const TopoDS_Shape& s, const gp
}
}
TopoDS_Shape IfcGeom::util::apply_transformation(const TopoDS_Shape& s, const gp_GTrsf& t) {
if (t.Form() == gp_Other) {
return BRepBuilderAPI_GTransform(s, t, true);
} else {
return apply_transformation(s, t.Trsf());
}
}
TopoDS_Shape IfcGeom::util::apply_transformation(const TopoDS_Shape& s, const ifcopenshell::geometry::taxonomy::matrix4& t) {
// @todo this probably discards non-uniform scale?
gp_GTrsf trsf;
if (t.components_) {
gp_Trsf tr;
const auto& m = t.ccomponents();
tr.SetValues(
m(0, 0), m(0, 1), m(0, 2), m(0, 3),
m(1, 0), m(1, 1), m(1, 2), m(1, 3),
m(2, 0), m(2, 1), m(2, 2), m(2, 3)
);
trsf = tr;
}
return apply_transformation(s, trsf);
}
bool IfcGeom::util::fit_halfspace(const TopoDS_Shape& a, const TopoDS_Shape& b, TopoDS_Shape& box, double& height, double tol) {
TopExp_Explorer exp(b, TopAbs_FACE);
if (!exp.More()) {
+1 -1
View File
@@ -66,10 +66,10 @@ namespace IfcGeom {
bool project(const Handle_Geom_Curve&, const gp_Pnt&, gp_Pnt& p, double& u, double& d);
bool project(const Handle_Geom_Surface&, const TopoDS_Shape&, double& u1, double& v1, double& u2, double& v2, double widen = 0.1);
double shape_volume(const TopoDS_Shape& s);
double face_area(const TopoDS_Face& f);
TopoDS_Shape apply_transformation(const TopoDS_Shape&, const ifcopenshell::geometry::taxonomy::matrix4& t);
TopoDS_Shape apply_transformation(const TopoDS_Shape&, const gp_Trsf&);
TopoDS_Shape apply_transformation(const TopoDS_Shape&, const gp_GTrsf&);