move scaling to CGAL::Bbox_3

This commit is contained in:
Jane Tournois 2024-03-04 16:08:10 +01:00
parent 124f2b1eff
commit 272beb678a
2 changed files with 35 additions and 10 deletions

View File

@ -77,6 +77,7 @@ public:
Bbox_3& operator+=(const Bbox_3& b); Bbox_3& operator+=(const Bbox_3& b);
void dilate(int dist); void dilate(int dist);
void scale(double factor);
}; };
inline inline
@ -200,6 +201,25 @@ Bbox_3::dilate(int dist)
rep[5] = float_advance(rep[5],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<double, 3> 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 inline
bool bool

View File

@ -58,6 +58,14 @@ namespace CGAL {
* `Construct_bbox_3` must provide the functor `Bbox_3 operator()(Point_3)` * `Construct_bbox_3` must provide the functor `Bbox_3 operator()(Point_3)`
* where `%Point_3` is the value type of the vertex point map.} * where `%Point_3` is the value type of the vertex point map.}
* \cgalParamNEnd * \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 * \cgalNamedParamsEnd
* *
* @see `vertex_bbox()` * @see `vertex_bbox()`
@ -79,6 +87,9 @@ namespace CGAL {
GT gt = choose_parameter<GT>(get_parameter(np, internal_np::geom_traits)); GT gt = choose_parameter<GT>(get_parameter(np, internal_np::geom_traits));
typename GT::Construct_bbox_3 get_bbox = gt.construct_bbox_3_object(); 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<PolygonMesh>::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits<PolygonMesh>::vertex_descriptor vertex_descriptor;
CGAL::Bbox_3 bb; CGAL::Bbox_3 bb;
@ -86,6 +97,9 @@ namespace CGAL {
{ {
bb += get_bbox( get(vpm, v) ); bb += get_bbox( get(vpm, v) );
} }
if (factor != 1.)
bb.scale(factor);
return bb; return bb;
} }
@ -321,19 +335,10 @@ namespace CGAL {
using Iso_cuboid_3 = typename GT::Iso_cuboid_3; using Iso_cuboid_3 = typename GT::Iso_cuboid_3;
using Vector_3 = typename GT::Vector_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( const bool dont_triangulate = choose_parameter(
get_parameter(np, internal_np::do_not_triangulate_faces), false); get_parameter(np, internal_np::do_not_triangulate_faces), false);
const Iso_cuboid_3 bb(CGAL::Polygon_mesh_processing::bbox(pmesh, np)); const Iso_cuboid_3 bbext(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)()));
PolygonMesh bbox_mesh; PolygonMesh bbox_mesh;
CGAL::make_hexahedron(bbext[0], bbext[1], bbext[2], bbext[3], CGAL::make_hexahedron(bbext[0], bbext[1], bbext[2], bbext[3],