Major update: taxonomy shared pointers, collection type safety, work towards hashing

This commit is contained in:
Thomas Krijnen
2023-07-27 16:42:06 +08:00
parent 98a73f1646
commit 65a5646bf0
122 changed files with 1669 additions and 1203 deletions
+41 -43
View File
@@ -29,59 +29,57 @@ using namespace ifcopenshell::geometry::kernels;
using namespace IfcGeom;
using namespace IfcGeom::util;
bool OpenCascadeKernel::convert(const taxonomy::solid* solid, TopoDS_Shape& result) {
bool OpenCascadeKernel::convert(const taxonomy::solid::ptr solid, TopoDS_Shape& result) {
BRep_Builder BB;
TopoDS_Solid S;
for (auto& s : solid->children) {
if (s->kind() == taxonomy::FACE) {
// halfspace
if (solid->children.size() != 1) {
throw std::runtime_error("Unexpected number of children on solid");
}
auto face = (taxonomy::face*) s;
const auto& m = ((taxonomy::geom_item*)face->basis)->matrix.ccomponents();
gp_Pln pln(convert_xyz2<gp_Pnt>(m.col(3)), convert_xyz2<gp_Dir>(m.col(2)));
const gp_Pnt pnt = pln.Location().Translated(face->orientation.get_value_or(false) ? pln.Axis().Direction() : -pln.Axis().Direction());
TopoDS_Shape halfspace = BRepPrimAPI_MakeHalfSpace(BRepBuilderAPI_MakeFace(pln), pnt).Solid();
if (!face->children.empty()) {
TopoDS_Wire wire;
gp_GTrsf gtrsf;
if (convert((taxonomy::loop*)face->children[0], wire) && wire.Closed() && convert(&face->matrix, gtrsf)) {
gp_Trsf trsf = gtrsf.Trsf();
TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire), gp_Vec(0, 0, 200));
gp_Trsf down; down.SetTranslation(gp_Vec(0, 0, -100.0));
// `trsf` and `down` both have a unit scale factor
prism.Move(trsf*down);
halfspace = BRepAlgoAPI_Common(halfspace, prism);
}
}
result = halfspace;
return true;
} else {
if (s->kind() != taxonomy::SHELL) {
throw std::runtime_error("Unexpected child in solid");
}
if (S.IsNull()) {
BB.MakeSolid(S);
}
TopoDS_Shell shl;
convert(((taxonomy::shell*)s), shl);
BB.Add(S, shl);
if (solid->instance->declaration().is("IfcHalfSpaceSolid")) {
// halfspace
if (solid->children.size() != 1) {
throw std::runtime_error("Unexpected number of children on solid");
}
auto face = solid->children[0]->children[0];
const auto& m = taxonomy::cast<taxonomy::plane>(face->basis)->matrix->ccomponents();
gp_Pln pln(convert_xyz2<gp_Pnt>(m.col(3)), convert_xyz2<gp_Dir>(m.col(2)));
const gp_Pnt pnt = pln.Location().Translated(face->orientation.get_value_or(false) ? pln.Axis().Direction() : -pln.Axis().Direction());
TopoDS_Shape halfspace = BRepPrimAPI_MakeHalfSpace(BRepBuilderAPI_MakeFace(pln), pnt).Solid();
if (!face->children.empty()) {
TopoDS_Wire wire;
gp_GTrsf gtrsf;
if (convert((taxonomy::loop::ptr)face->children[0], wire) && wire.Closed() && convert(face->matrix, gtrsf)) {
gp_Trsf trsf = gtrsf.Trsf();
TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire), gp_Vec(0, 0, 200));
gp_Trsf down; down.SetTranslation(gp_Vec(0, 0, -100.0));
// `trsf` and `down` both have a unit scale factor
prism.Move(trsf*down);
halfspace = BRepAlgoAPI_Common(halfspace, prism);
}
}
result = halfspace;
return true;
}
for (auto& s : solid->children) {
if (S.IsNull()) {
BB.MakeSolid(S);
}
TopoDS_Shell shl;
convert(((taxonomy::shell::ptr)s), shl);
BB.Add(S, shl);
}
if (!S.IsNull()) {
result = S;
}
}
bool OpenCascadeKernel::convert_impl(const taxonomy::solid* solid , IfcGeom::ConversionResults& results) {
bool OpenCascadeKernel::convert_impl(const taxonomy::solid::ptr solid , IfcGeom::ConversionResults& results) {
TopoDS_Shape shape;
if (!convert(solid, shape)) {
return false;