Convex tag on cgal shape

This commit is contained in:
Thomas Krijnen
2024-02-18 12:04:48 +01:00
parent d04357933b
commit 8af6903505
2 changed files with 26 additions and 13 deletions
@@ -19,8 +19,9 @@ using ifcopenshell::geometry::NumberEpeck;
#define NumberType NumberEpeck #define NumberType NumberEpeck
#endif #endif
ifcopenshell::geometry::CgalShape::CgalShape(const cgal_shape_t & shape) { ifcopenshell::geometry::CgalShape::CgalShape(const cgal_shape_t & shape, bool convex) {
shape_ = shape; shape_ = shape;
convex_tag_ = convex;
if (shape.size_of_facets() != 1) { if (shape.size_of_facets() != 1) {
// this is for handling the specical case of storing a single point in a polyhedron, // this is for handling the specical case of storing a single point in a polyhedron,
// @todo come up with a proper variant for storing lower dimensional entities // @todo come up with a proper variant for storing lower dimensional entities
@@ -35,8 +36,10 @@ void ifcopenshell::geometry::CgalShape::to_poly() const {
shape_.emplace(); shape_.emplace();
convert_to_polyhedron(*nef_, *shape_); convert_to_polyhedron(*nef_, *shape_);
// @todo why is this necessary? we have the mark of the volumes? if (shape_->size_of_vertices() > 0) {
CGAL::Polygon_mesh_processing::orient_to_bound_a_volume(*shape_); // @todo why is this necessary? we have the mark of the volumes?
CGAL::Polygon_mesh_processing::orient_to_bound_a_volume(*shape_);
}
// nef_->convert_to_polyhedron(*shape_); // nef_->convert_to_polyhedron(*shape_);
} }
@@ -44,8 +47,10 @@ void ifcopenshell::geometry::CgalShape::to_poly() const {
void ifcopenshell::geometry::CgalShape::to_nef() const { void ifcopenshell::geometry::CgalShape::to_nef() const {
if (!nef_) { if (!nef_) {
if (CGAL::Polygon_mesh_processing::does_self_intersect(*shape_)) { if (!convex_tag_) {
throw std::runtime_error("Self-intersections detected, unable to proceed"); if (CGAL::Polygon_mesh_processing::does_self_intersect(*shape_)) {
throw std::runtime_error("Self-intersections detected, unable to proceed");
}
} }
nef_ = utils::create_nef_polyhedron(*shape_); nef_ = utils::create_nef_polyhedron(*shape_);
} }
@@ -382,7 +387,7 @@ std::vector<ConversionResultShape*> ifcopenshell::geometry::CgalShape::convex_de
// directly, so for now we need to isolate the individual volumes. // directly, so for now we need to isolate the individual volumes.
CGAL::Polyhedron_3<Kernel_> P; CGAL::Polyhedron_3<Kernel_> P;
copy.convert_inner_shell_to_polyhedron(ci->shells_begin(), P); copy.convert_inner_shell_to_polyhedron(ci->shells_begin(), P);
result.push_back(new CgalShape(P)); result.push_back(new CgalShape(P, /*convex=*/ true));
} }
} }
return result; return result;
@@ -394,7 +399,7 @@ ConversionResultShape* ifcopenshell::geometry::CgalShape::halfspaces()
#ifdef IFOPSH_SIMPLE_KERNEL #ifdef IFOPSH_SIMPLE_KERNEL
throw std::runtime_error("Not implemented"); throw std::runtime_error("Not implemented");
#else #else
return new CgalShapeHalfSpaceDecomposition(nef()); return new CgalShapeHalfSpaceDecomposition(nef(), convex_tag_);
#endif #endif
} }
@@ -529,7 +534,7 @@ ConversionResultShape* ifcopenshell::geometry::CgalShape::moved(ifcopenshell::ge
} }
} }
return new CgalShape(s); return new CgalShape(s, convex_tag_);
} }
void ifcopenshell::geometry::CgalShape::map(OpaqueCoordinate<4>& from, OpaqueCoordinate<4>& to) { void ifcopenshell::geometry::CgalShape::map(OpaqueCoordinate<4>& from, OpaqueCoordinate<4>& to) {
@@ -177,16 +177,18 @@ namespace ifcopenshell { namespace geometry {
class CgalShape : public IfcGeom::ConversionResultShape { class CgalShape : public IfcGeom::ConversionResultShape {
private: private:
bool convex_tag_ = false;
mutable boost::optional<cgal_shape_t> shape_; mutable boost::optional<cgal_shape_t> shape_;
#ifndef IFOPSH_SIMPLE_KERNEL #ifndef IFOPSH_SIMPLE_KERNEL
mutable boost::optional<CGAL::Nef_polyhedron_3<Kernel_>> nef_; mutable boost::optional<CGAL::Nef_polyhedron_3<Kernel_>> nef_;
#endif #endif
public: public:
CgalShape(const cgal_shape_t& shape); CgalShape(const cgal_shape_t& shape, bool convex = false);
#ifndef IFOPSH_SIMPLE_KERNEL #ifndef IFOPSH_SIMPLE_KERNEL
CgalShape(const CGAL::Nef_polyhedron_3<Kernel_>& shape) { CgalShape(const CGAL::Nef_polyhedron_3<Kernel_>& shape, bool convex = false) {
nef_ = shape; nef_ = shape;
convex_tag_ = convex;
} }
#endif #endif
@@ -252,6 +254,9 @@ namespace ifcopenshell { namespace geometry {
virtual void map(OpaqueCoordinate<4>& from, OpaqueCoordinate<4>& to); virtual void map(OpaqueCoordinate<4>& from, OpaqueCoordinate<4>& to);
virtual void map(const std::vector<OpaqueCoordinate<4>>& from, const std::vector<OpaqueCoordinate<4>>& to); virtual void map(const std::vector<OpaqueCoordinate<4>>& from, const std::vector<OpaqueCoordinate<4>>& to);
virtual ConversionResultShape* moved(ifcopenshell::geometry::taxonomy::matrix4::ptr) const; virtual ConversionResultShape* moved(ifcopenshell::geometry::taxonomy::matrix4::ptr) const;
bool convex_tag() const { return convex_tag_; }
bool& convex_tag() { return convex_tag_; }
}; };
#ifndef IFOPSH_SIMPLE_KERNEL #ifndef IFOPSH_SIMPLE_KERNEL
@@ -261,9 +266,12 @@ namespace ifcopenshell { namespace geometry {
std::list<CGAL::Plane_3<Kernel_>> planes_; std::list<CGAL::Plane_3<Kernel_>> planes_;
public: public:
CgalShapeHalfSpaceDecomposition(const CGAL::Nef_polyhedron_3<Kernel_>& shape) { CgalShapeHalfSpaceDecomposition(const CGAL::Nef_polyhedron_3<Kernel_>& shape, bool is_convex) {
auto shape_copy = shape; if (is_convex) {
shape_ = std::move(build_halfspace_tree_decomposed(shape_copy, planes_)); shape_ = std::move(build_halfspace_tree_is_decomposed(shape, planes_));
} else {
shape_ = std::move(build_halfspace_tree_decomposed(shape, planes_));
}
} }
CgalShapeHalfSpaceDecomposition(const CGAL::Plane_3<Kernel_>& shape) { CgalShapeHalfSpaceDecomposition(const CGAL::Plane_3<Kernel_>& shape) {