diff --git a/src/ifcgeom/ConversionSettings.h b/src/ifcgeom/ConversionSettings.h index 2a8e8115c5..7928c29748 100644 --- a/src/ifcgeom/ConversionSettings.h +++ b/src/ifcgeom/ConversionSettings.h @@ -300,6 +300,12 @@ namespace ifcopenshell { static constexpr const char* const description = "Overrides transparency of spaces in geometry output."; }; + struct CircleSegments : public SettingBase { + static constexpr const char* const name = "circle-segments"; + static constexpr const char* const description = "Number of segments to approximate full circles in CGAL kernel."; + static constexpr int defaultvalue = 16; + }; + enum PiecewiseStepMethod { MAXSTEPSIZE, MINSTEPS }; @@ -402,7 +408,7 @@ namespace ifcopenshell { }; class IFC_GEOM_API Settings : public SettingsContainer< - std::tuple + std::tuple > {}; } diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.cpp b/src/ifcgeom/kernels/cgal/CgalKernel.cpp index 13b35606ad..18d71f1a1d 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.cpp +++ b/src/ifcgeom/kernels/cgal/CgalKernel.cpp @@ -364,13 +364,13 @@ namespace { }; struct cgal_curve_creation_visitor { - static const int FULL_CIRCLE_NUM_SEGMENTS = 32; + Settings& settings_; parameter_range param; std::vector points; - cgal_curve_creation_visitor() : param(unbounded) {} - cgal_curve_creation_visitor(const parameter_range& p) : param(p) {} + cgal_curve_creation_visitor(Settings& s) : settings_(s), param(unbounded) {} + cgal_curve_creation_visitor(Settings& s, const parameter_range& p) : settings_(s), param(p) {} void operator()(const taxonomy::line::ptr& l) { if (param == unbounded) { @@ -397,7 +397,7 @@ namespace { if (b <= a) { b += 2 * M_PI; } - int num_segments = (int)std::ceil(std::fabs(a - b) / (2 * M_PI) * FULL_CIRCLE_NUM_SEGMENTS); + int num_segments = (int)std::ceil(std::fabs(a - b) / (2 * M_PI) * settings_.get().get()); double du = (b - a) / num_segments; taxonomy::point3 P; // @nb for loop is not inclusive of the both end points @@ -429,7 +429,7 @@ namespace { std::swap(v1.u, v2.u); } - cgal_curve_creation_visitor v({ v1.u, v2.u }); + cgal_curve_creation_visitor v(settings_, { v1.u, v2.u }); dispatch_curve_creation::dispatch(e->basis, v); this->points = v.points; @@ -448,8 +448,8 @@ namespace { } }; - void convert_curve(taxonomy::ptr i, std::vector& points) { - cgal_curve_creation_visitor v; + void convert_curve(Settings& s, taxonomy::ptr i, std::vector& points) { + cgal_curve_creation_visitor v(s); dispatch_curve_creation::dispatch(i, v); points = v.points; } @@ -647,7 +647,7 @@ bool CgalKernel::convert(const taxonomy::loop::ptr loop, cgal_wire_t& result) { for (auto& e : loop->children) { std::vector edge; if (e->basis) { - convert_curve(e, edge); + convert_curve(settings_, e, edge); if (!e->orientation_2.get_value_or(true)) { std::reverse(edge.begin(), edge.end()); } diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.h b/src/ifcgeom/kernels/cgal/CgalKernel.h index 37f65c675a..c5a25104bd 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.h +++ b/src/ifcgeom/kernels/cgal/CgalKernel.h @@ -70,8 +70,6 @@ namespace ifcopenshell { class IFC_GEOM_API CgalKernel : public AbstractKernel { private: - size_t circle_segments_; - #ifndef IFOPSH_SIMPLE_KERNEL enum boolean_operand_preprocess { PP_MINKOWSKY_DILATE, @@ -94,7 +92,6 @@ namespace ifcopenshell { CgalKernel(const Settings& settings) : AbstractKernel("cgal", settings) - , circle_segments_(32) {} void remove_duplicate_points_from_loop(cgal_wire_t& polygon);