2026-03-31 15:32:36 +02:00
|
|
|
/********************************************************************************
|
2017-01-16 11:53:11 +01:00
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef CGAL_KERNEL_H
|
|
|
|
|
#define CGAL_KERNEL_H
|
|
|
|
|
|
2026-06-10 18:30:54 +02:00
|
|
|
#include "../../../ifcparse/IfcLogger.h"
|
|
|
|
|
|
2017-01-16 11:53:11 +01:00
|
|
|
/*
|
|
|
|
|
#ifdef NO_CACHE
|
|
|
|
|
|
|
|
|
|
#define IN_CACHE(T,E,t,e)
|
|
|
|
|
#define CACHE(T,E,e)
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#define IN_CACHE(T,E,t,e) std::map<int,t>::const_iterator it = cache.T.find(E->entity->id());\
|
|
|
|
|
if ( it != cache.T.end() ) { e = it->second; return true; }
|
|
|
|
|
#define CACHE(T,E,e) cache.T[E->entity->id()] = e;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
*/
|
|
|
|
|
|
2023-04-03 13:34:35 +02:00
|
|
|
#ifdef IFOPSH_SIMPLE_KERNEL
|
|
|
|
|
#define CgalKernel SimpleCgalKernel
|
|
|
|
|
#define create_cube create_cube_simple
|
|
|
|
|
#define create_polyhedron create_polyhedron_simple
|
|
|
|
|
#endif
|
2019-01-23 17:27:13 +01:00
|
|
|
|
2019-01-18 16:43:38 +01:00
|
|
|
#include "../../../ifcparse/macros.h"
|
2019-01-20 13:16:42 +01:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
#include "../../../ifcgeom/AbstractKernel.h"
|
2019-01-20 13:16:42 +01:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
#include "../../../ifcgeom/IfcGeomElement.h"
|
2019-09-01 16:29:00 +02:00
|
|
|
#include "../../../ifcgeom/kernels/cgal/CgalConversionResult.h"
|
2025-09-26 14:24:49 +02:00
|
|
|
#include "../../../ifcgeom/kernels/ifc_geomlibrary_api.h"
|
2019-01-18 16:43:38 +01:00
|
|
|
|
2023-04-03 13:34:35 +02:00
|
|
|
#include <CGAL/Polygon_2.h>
|
|
|
|
|
|
|
|
|
|
#include <cmath>
|
2017-02-02 14:29:26 -06:00
|
|
|
|
2019-09-01 16:29:00 +02:00
|
|
|
namespace ifcopenshell {
|
2023-03-21 20:15:01 +01:00
|
|
|
namespace geometry {
|
|
|
|
|
namespace utils {
|
2025-09-26 14:24:49 +02:00
|
|
|
IFC_GEOMLIBRARY_API CGAL::Polyhedron_3<Kernel_> create_cube(double d);
|
|
|
|
|
IFC_GEOMLIBRARY_API CGAL::Polyhedron_3<Kernel_> create_cube(const Kernel_::Point_3& lower, const Kernel_::Point_3& upper);
|
2026-06-10 18:30:54 +02:00
|
|
|
IFC_GEOMLIBRARY_API CGAL::Polyhedron_3<Kernel_> create_polyhedron(std::list<cgal_face_t> &face_list, bool stitch_borders = false, Logger& logger = Logger::Root());
|
2023-04-03 13:34:35 +02:00
|
|
|
|
|
|
|
|
#ifndef IFOPSH_SIMPLE_KERNEL
|
2026-06-10 18:30:54 +02:00
|
|
|
IFC_GEOMLIBRARY_API CGAL::Polyhedron_3<Kernel_> create_polyhedron(const CGAL::Nef_polyhedron_3<Kernel_> &nef_polyhedron, Logger& logger = Logger::Root());
|
|
|
|
|
IFC_GEOMLIBRARY_API CGAL::Nef_polyhedron_3<Kernel_> create_nef_polyhedron(std::list<cgal_face_t> &face_list, Logger& logger = Logger::Root());
|
|
|
|
|
IFC_GEOMLIBRARY_API CGAL::Nef_polyhedron_3<Kernel_> create_nef_polyhedron(CGAL::Polyhedron_3<Kernel_> &polyhedron, Logger& logger = Logger::Root());
|
2023-04-03 13:34:35 +02:00
|
|
|
#endif
|
2019-09-25 15:30:11 +02:00
|
|
|
}
|
2019-01-18 16:43:38 +01:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
namespace kernels {
|
2017-01-16 11:53:11 +01:00
|
|
|
|
2025-09-26 14:24:49 +02:00
|
|
|
class IFC_GEOMLIBRARY_API CgalKernel : public AbstractKernel {
|
2023-03-21 20:15:01 +01:00
|
|
|
private:
|
2023-04-03 13:34:35 +02:00
|
|
|
#ifndef IFOPSH_SIMPLE_KERNEL
|
2023-09-13 22:04:58 +02:00
|
|
|
enum boolean_operand_preprocess {
|
|
|
|
|
PP_MINKOWSKY_DILATE,
|
|
|
|
|
PP_SNAP_POINTS_TO_FIRST_OPERAND,
|
|
|
|
|
PP_SNAP_PLANES_TO_FIRST_OPERAND,
|
|
|
|
|
PP_UNIFY_PLANES_INTERNALLY,
|
|
|
|
|
PP_NONE
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
bool preprocess_boolean_operand(const express::Base& log_reference, const std::list<cgal_shape_t>& first_operands, const std::list<CGAL::Nef_polyhedron_3<Kernel_>>& first_operands_nef, const std::list<Kernel_::Plane_3>& all_operand_planes, const cgal_shape_t& shape_const, CGAL::Nef_polyhedron_3<Kernel_>& result, boolean_operand_preprocess proc);
|
2023-04-03 13:34:35 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
bool thin_solid(const CGAL::Nef_polyhedron_3<Kernel_>& a, CGAL::Nef_polyhedron_3<Kernel_>& result);
|
2017-01-16 11:53:11 +01:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
CGAL::Nef_polyhedron_3<Kernel_> create_precision_cube_() const {
|
2023-11-15 10:32:20 +01:00
|
|
|
auto cc = utils::create_cube(settings_.get<settings::Precision>().get());
|
2023-03-21 20:15:01 +01:00
|
|
|
return CGAL::Nef_polyhedron_3<Kernel_>(cc);
|
|
|
|
|
}
|
2023-04-03 13:34:35 +02:00
|
|
|
#endif
|
2023-03-21 20:15:01 +01:00
|
|
|
public:
|
|
|
|
|
|
2026-06-10 18:30:54 +02:00
|
|
|
CgalKernel(const Settings& settings, Logger& logger = Logger::Root())
|
|
|
|
|
: AbstractKernel("cgal", settings, logger)
|
2023-03-21 20:15:01 +01:00
|
|
|
{}
|
|
|
|
|
|
2026-06-11 21:04:44 +02:00
|
|
|
virtual AbstractKernel* clone(Logger& logger) const {
|
|
|
|
|
return new CgalKernel(settings(), logger);
|
2025-09-26 14:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool supports_boolean_operations() const {
|
|
|
|
|
#ifndef IFOPSH_SIMPLE_KERNEL
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
bool convert(const taxonomy::extrusion::ptr, cgal_shape_t&);
|
2023-09-14 21:57:49 +02:00
|
|
|
bool convert(const taxonomy::face::ptr, std::list<cgal_face_t>&);
|
2023-07-27 16:42:06 +08:00
|
|
|
bool convert(const taxonomy::loop::ptr, cgal_wire_t&);
|
|
|
|
|
// bool convert(const taxonomy::matrix4::ptr, cgal_placement_t&);
|
|
|
|
|
bool convert(const taxonomy::shell::ptr, cgal_shape_t&);
|
|
|
|
|
|
|
|
|
|
bool process_extrusion(const cgal_face_t& bottom_face, taxonomy::direction3::ptr direction, double height, cgal_shape_t& shape);
|
|
|
|
|
bool process_as_2d_polygon(const taxonomy::boolean_result::ptr br, std::list<CGAL::Polygon_2<Kernel_>>& loops, double& z0, double& z1);
|
2026-01-04 10:40:02 +01:00
|
|
|
bool process_as_2d_polygon(const std::list<std::list<std::pair<express::Base, cgal_shape_t>>>& operands, std::list<CGAL::Polygon_2<Kernel_>>& loops, double& z0, double& z1);
|
2023-03-21 20:15:01 +01:00
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
virtual bool convert_impl(const taxonomy::shell::ptr, IfcGeom::ConversionResults&);
|
|
|
|
|
virtual bool convert_impl(const taxonomy::extrusion::ptr, IfcGeom::ConversionResults&);
|
|
|
|
|
virtual bool convert_impl(const taxonomy::boolean_result::ptr, IfcGeom::ConversionResults&);
|
|
|
|
|
virtual bool convert_impl(const taxonomy::solid::ptr, IfcGeom::ConversionResults&);
|
2023-03-21 20:15:01 +01:00
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
virtual bool convert_openings(const express::Base& entity, const std::vector<std::pair<taxonomy::ptr, ifcopenshell::geometry::taxonomy::matrix4>>& openings,
|
2023-03-21 20:15:01 +01:00
|
|
|
const IfcGeom::ConversionResults& entity_shapes, const ifcopenshell::geometry::taxonomy::matrix4& entity_trsf, IfcGeom::ConversionResults& cut_shapes);
|
|
|
|
|
|
2023-04-03 13:34:35 +02:00
|
|
|
#ifndef IFOPSH_SIMPLE_KERNEL
|
2023-03-21 20:15:01 +01:00
|
|
|
CGAL::Nef_polyhedron_3<Kernel_> precision_cube() const { return create_precision_cube_(); }
|
2023-04-03 13:34:35 +02:00
|
|
|
#endif
|
2023-03-21 20:15:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-01 16:29:00 +02:00
|
|
|
}
|
2026-06-10 18:30:54 +02:00
|
|
|
#endif
|