From e38e0401f4b812e142ea2392ad3c34767e92d83c Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Fri, 10 May 2019 10:55:58 +0200 Subject: [PATCH] Add the possibility to build bounding boxes with containers of points. --- include/deal.II/base/bounding_box.h | 34 ++++++++++++++++--- include/deal.II/boost_adaptors/bounding_box.h | 1 + source/base/bounding_box.cc | 8 +++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index 8922fa6b36..b6962409b1 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -67,7 +67,7 @@ enum class NeighborType * * Objects of this class are used to represent bounding boxes. They are, * among other uses, useful in parallel distributed meshes to give a general - * description the owners of each portion of the mesh. + * description of the owners of each portion of the mesh. * * Bounding boxes are represented by two vertices (bottom left and top right). * Geometrically, a bounding box is: @@ -89,7 +89,7 @@ enum class NeighborType * | |/ * V------. * @endcode - * Notice the sides are always parallel to the respective axis. + * Notice that the sides are always parallel to the respective axis. * * @author Giovanni Alzetta, 2017. */ @@ -112,10 +112,20 @@ public: &boundary_points); /** - * Return the boundary_points + * Construct the bounding box that encloses all the points in the given + * container. + * + * The constructor supports any Container that provides begin() and end() + * iterators to Point elements. + */ + template + BoundingBox(const Container &points); + + /** + * Return a reference to the boundary_points */ - const std::pair, Point> & - get_boundary_points() const; + std::pair, Point> & + get_boundary_points(); /** * Check if the current object and @p other_bbox are neighbors, i.e. if the boxes @@ -189,6 +199,20 @@ inline BoundingBox::BoundingBox( this->boundary_points = boundary_points; } + + +template +template +inline BoundingBox::BoundingBox(const Container &points) +{ + boost::geometry::envelope( + boost::geometry::model::multi_point>(points.begin(), + points.end()), + *this); +} + + + template inline void BoundingBox::extend(const Number &amount) diff --git a/include/deal.II/boost_adaptors/bounding_box.h b/include/deal.II/boost_adaptors/bounding_box.h index a85f573aa9..63f4be6865 100644 --- a/include/deal.II/boost_adaptors/bounding_box.h +++ b/include/deal.II/boost_adaptors/bounding_box.h @@ -21,6 +21,7 @@ #include #include +#include namespace boost { diff --git a/source/base/bounding_box.cc b/source/base/bounding_box.cc index 410d610d35..006721f78c 100644 --- a/source/base/bounding_box.cc +++ b/source/base/bounding_box.cc @@ -142,13 +142,17 @@ BoundingBox::get_neighbor_type( } } + + template -const std::pair, Point> & -BoundingBox::get_boundary_points() const +std::pair, Point> & +BoundingBox::get_boundary_points() { return this->boundary_points; } + + template double BoundingBox::volume() const -- 2.39.5