Files
IfcOpenShell/src/ifcgeom/kernels/cgal/cgal_kernel.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
6.4 KiB
C++
Raw Normal View History

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-07-09 13:30:48 +02:00
#include "../../../ifcparse/logger.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
*/
#ifdef IFOPSH_SIMPLE_KERNEL
2026-08-08 07:42:45 +02:00
#define cgal_kernel 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
2026-08-08 14:19:57 +02:00
#include "../../../ifcgeom/abstract_kernel.h"
2019-01-20 13:16:42 +01:00
2026-08-08 14:19:57 +02:00
#include "../../../ifcgeom/element.h"
#include "../../../ifcgeom/kernels/cgal/cgal_conversion_result.h"
2025-09-26 14:24:49 +02:00
#include "../../../ifcgeom/kernels/ifc_geomlibrary_api.h"
2019-01-18 16:43:38 +01:00
#include <CGAL/Polygon_2.h>
#include <cmath>
2019-09-01 16:29:00 +02:00
namespace ifcopenshell {
2026-08-08 07:42:45 +02:00
namespace geom {
2023-03-21 20:15:01 +01:00
namespace utils {
2026-08-08 07:42:45 +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-08-08 14:58:15 +02:00
IFC_GEOMLIBRARY_API CGAL::Polyhedron_3<kernel_> create_polyhedron(std::list<cgal_face> &face_list, bool stitch_borders = false, logger& logger = ifcopenshell::logger::root());
#ifndef IFOPSH_SIMPLE_KERNEL
IFC_GEOMLIBRARY_API CGAL::Polyhedron_3<kernel_> create_polyhedron(const CGAL::Nef_polyhedron_3<kernel_> &nef_polyhedron, logger& logger = ifcopenshell::logger::root());
2026-08-08 14:58:15 +02:00
IFC_GEOMLIBRARY_API CGAL::Nef_polyhedron_3<kernel_> create_nef_polyhedron(std::list<cgal_face> &face_list, logger& logger = ifcopenshell::logger::root());
IFC_GEOMLIBRARY_API CGAL::Nef_polyhedron_3<kernel_> create_nef_polyhedron(CGAL::Polyhedron_3<kernel_> &polyhedron, logger& logger = ifcopenshell::logger::root());
#endif
}
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
2026-08-08 07:42:45 +02:00
class IFC_GEOMLIBRARY_API cgal_kernel : public abstract_kernel {
2023-03-21 20:15:01 +01:00
private:
#ifndef IFOPSH_SIMPLE_KERNEL
2026-08-19 18:16:59 +05: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-08-08 14:58:15 +02:00
bool preprocess_boolean_operand(const express::base& log_reference, const std::list<cgal_polyhedron>& first_operands, const std::list<CGAL::Nef_polyhedron_3<kernel_>>& first_operands_nef, const std::list<kernel_::Plane_3>& all_operand_planes, const cgal_polyhedron& shape_const, CGAL::Nef_polyhedron_3<kernel_>& result, boolean_operand_preprocess proc);
2026-08-08 07:42:45 +02: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
2026-08-08 07:42:45 +02: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());
2026-08-08 07:42:45 +02:00
return CGAL::Nef_polyhedron_3<kernel_>(cc);
2023-03-21 20:15:01 +01:00
}
#endif
2023-03-21 20:15:01 +01:00
public:
cgal_kernel(const ifcopenshell::geom::settings& settings, ifcopenshell::logger& logger = ifcopenshell::logger::root())
2026-08-08 07:42:45 +02:00
: abstract_kernel("cgal", settings, logger)
2023-03-21 20:15:01 +01:00
{}
virtual abstract_kernel* clone(ifcopenshell::logger& logger) const {
2026-08-08 07:42:45 +02:00
return new cgal_kernel(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
}
2026-08-08 14:58:15 +02:00
bool convert(const taxonomy::extrusion::ptr, cgal_polyhedron&);
bool convert(const taxonomy::face::ptr, std::list<cgal_face>&);
bool convert(const taxonomy::loop::ptr, cgal_wire&);
// bool convert(const taxonomy::matrix4::ptr, cgal_placement&);
bool convert(const taxonomy::shell::ptr, cgal_polyhedron&);
2026-08-08 14:58:15 +02:00
bool process_extrusion(const cgal_face& bottom_face, taxonomy::direction3::ptr direction, double height, cgal_polyhedron& shape);
2026-08-08 07:42:45 +02:00
bool process_as_2d_polygon(const taxonomy::boolean_result::ptr br, std::list<CGAL::Polygon_2<kernel_>>& loops, double& z0, double& z1);
2026-08-08 14:58:15 +02:00
bool process_as_2d_polygon(const std::list<std::list<std::pair<express::base, cgal_polyhedron>>>& operands, std::list<CGAL::Polygon_2<kernel_>>& loops, double& z0, double& z1);
2023-03-21 20:15:01 +01:00
2026-08-08 15:45:04 +02:00
virtual bool convert_impl(const taxonomy::shell::ptr, std::vector<ifcopenshell::geom::conversion_result>&);
virtual bool convert_impl(const taxonomy::extrusion::ptr, std::vector<ifcopenshell::geom::conversion_result>&);
virtual bool convert_impl(const taxonomy::boolean_result::ptr, std::vector<ifcopenshell::geom::conversion_result>&);
virtual bool convert_impl(const taxonomy::solid::ptr, std::vector<ifcopenshell::geom::conversion_result>&);
2023-03-21 20:15:01 +01:00
2026-08-08 07:42:45 +02:00
virtual bool convert_openings(const express::base& entity, const std::vector<std::pair<taxonomy::ptr, ifcopenshell::geom::taxonomy::matrix4>>& openings,
2026-08-08 15:45:04 +02:00
const std::vector<ifcopenshell::geom::conversion_result>& entity_shapes, const ifcopenshell::geom::taxonomy::matrix4& entity_trsf, std::vector<ifcopenshell::geom::conversion_result>& cut_shapes);
2023-03-21 20:15:01 +01:00
#ifndef IFOPSH_SIMPLE_KERNEL
2026-08-08 07:42:45 +02:00
CGAL::Nef_polyhedron_3<kernel_> precision_cube() const { return create_precision_cube_(); }
#endif
2023-03-21 20:15:01 +01:00
};
}
}
2019-09-01 16:29:00 +02:00
}
#endif