From 272beb678a007f4cd8fdf5c57ab7a26db77bb528 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Mon, 4 Mar 2024 16:08:10 +0100 Subject: [PATCH] move scaling to CGAL::Bbox_3 --- Kernel_23/include/CGAL/Bbox_3.h | 20 +++++++++++++++ .../CGAL/Polygon_mesh_processing/bbox.h | 25 +++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Kernel_23/include/CGAL/Bbox_3.h b/Kernel_23/include/CGAL/Bbox_3.h index b5bb3640800..7e8a86eec73 100644 --- a/Kernel_23/include/CGAL/Bbox_3.h +++ b/Kernel_23/include/CGAL/Bbox_3.h @@ -77,6 +77,7 @@ public: Bbox_3& operator+=(const Bbox_3& b); void dilate(int dist); + void scale(double factor); }; inline @@ -200,6 +201,25 @@ Bbox_3::dilate(int dist) rep[5] = float_advance(rep[5],dist); } +inline +void +Bbox_3::scale(double factor) +{ + CGAL_precondition(factor > 0); + + if (factor == 1.) + return; + + std::array center = { (xmin() + xmax()) * 0.5, + (ymin() + ymax()) * 0.5, + (zmin() + zmax()) * 0.5 }; + rep[0] = center[0] + factor * (xmin() - center[0]); + rep[1] = center[1] + factor * (ymin() - center[1]); + rep[2] = center[2] + factor * (zmin() - center[2]); + rep[3] = center[0] + factor * (xmax() - center[0]); + rep[4] = center[1] + factor * (ymax() - center[1]); + rep[5] = center[2] + factor * (zmax() - center[2]); +} inline bool diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/bbox.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/bbox.h index b8c2680b26b..5660a7cfdd5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/bbox.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/bbox.h @@ -58,6 +58,14 @@ namespace CGAL { * `Construct_bbox_3` must provide the functor `Bbox_3 operator()(Point_3)` * where `%Point_3` is the value type of the vertex point map.} * \cgalParamNEnd + * + * \cgalParamNBegin{bbox_scaling} + * \cgalParamDescription{a double used to scale the bounding box. + * The default value is 1 and the bounding box is the smallest possible + * axis-aligned bounding box.} + * \cgalParamDefault{1.} + * \cgalParamPrecondition{`bbox_scaling > 0`} + * \cgalParamNEnd * \cgalNamedParamsEnd * * @see `vertex_bbox()` @@ -79,6 +87,9 @@ namespace CGAL { GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); typename GT::Construct_bbox_3 get_bbox = gt.construct_bbox_3_object(); + const double factor = choose_parameter(get_parameter(np, internal_np::bbox_scaling), 1.); + CGAL_precondition(factor > 0); + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; CGAL::Bbox_3 bb; @@ -86,6 +97,9 @@ namespace CGAL { { bb += get_bbox( get(vpm, v) ); } + if (factor != 1.) + bb.scale(factor); + return bb; } @@ -321,19 +335,10 @@ namespace CGAL { using Iso_cuboid_3 = typename GT::Iso_cuboid_3; using Vector_3 = typename GT::Vector_3; - const double factor = choose_parameter(get_parameter(np, internal_np::bbox_scaling), 1.); - CGAL_precondition(factor > 0); const bool dont_triangulate = choose_parameter( get_parameter(np, internal_np::do_not_triangulate_faces), false); - const Iso_cuboid_3 bb(CGAL::Polygon_mesh_processing::bbox(pmesh, np)); - - auto midpoint = gt.construct_midpoint_3_object(); - const Point_3 bb_center = midpoint((bb.min)(), (bb.max)()); - const Iso_cuboid_3 bbext = (factor == 1.) - ? bb - : Iso_cuboid_3(bb_center + factor * Vector_3(bb_center, (bb.min)()), - bb_center + factor * Vector_3(bb_center, (bb.max)())); + const Iso_cuboid_3 bbext(CGAL::Polygon_mesh_processing::bbox(pmesh, np)); PolygonMesh bbox_mesh; CGAL::make_hexahedron(bbext[0], bbext[1], bbext[2], bbext[3],