3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
boundingsphere.hh
Go to the documentation of this file.
1/*****************************************************************************
2 * See the file COPYING for full copying permissions. *
3 * *
4 * This program is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 *****************************************************************************/
22#ifndef DUMUX_GEOMETRY_BOUNDINGSPHERE_HH
23#define DUMUX_GEOMETRY_BOUNDINGSPHERE_HH
24
25#include <algorithm>
26#include <vector>
27
29
30namespace Dumux {
31
38template<class ConvexGeometry>
39static inline Sphere<typename ConvexGeometry::ctype, ConvexGeometry::coorddimension>
40boundingSphere(const ConvexGeometry& geometry)
41{
42 constexpr int dimWorld = ConvexGeometry::coorddimension;
43 assert(geometry.corners() >= 1);
44
45 auto corner = geometry.corner(0);
46 auto xMin = corner, xMax = corner;
47 using std::max; using std::min;
48
49 // Compute the min and max over the remaining vertices
50 for (std::size_t i = 1; i < geometry.corners(); ++i)
51 {
52 corner = geometry.corner(i);
53 for (std::size_t dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
54 {
55 xMin[dimIdx] = min(xMin[dimIdx], corner[dimIdx]);
56 xMax[dimIdx] = max(xMax[dimIdx], corner[dimIdx]);
57 }
58 }
59
60 auto center = 0.5*xMax + xMin;
61 auto radius = (center-xMax).two_norm();
62 return { std::move(center), std::move(radius) };
63}
64
65namespace Detail {
66template<class Scalar, int dim>
68{
69 const std::vector<Dune::FieldVector<Scalar, dim>>& points_;
70 PointsToGeometryWrapper(const std::vector<Dune::FieldVector<Scalar, dim>>& points)
71 : points_(points) {}
72
73 static constexpr int coorddimension = dim;
74 using ctype = Scalar;
75
76 auto corners() const { return points_.size(); }
77 const auto& corner(std::size_t i) const { return points_[i]; }
78};
79} // end namespace Detail
80
87template<class Scalar, int dim>
88static inline Sphere<Scalar, dim>
89boundingSphere(const std::vector<Dune::FieldVector<Scalar, dim>>& points)
90{
92 return boundingSphere(geometry);
93}
94
95} // end namespace Dumux
96
97#endif
A function to compute bounding spheres of points clouds or convex polytopes.
static Sphere< typename ConvexGeometry::ctype, ConvexGeometry::coorddimension > boundingSphere(const ConvexGeometry &geometry)
Computes a bounding sphere of a convex polytope geometry (Dune::Geometry interface)
Definition: boundingsphere.hh:40
Definition: adapt.hh:29
Definition: boundingsphere.hh:68
static constexpr int coorddimension
Definition: boundingsphere.hh:73
const std::vector< Dune::FieldVector< Scalar, dim > > & points_
Definition: boundingsphere.hh:69
const auto & corner(std::size_t i) const
Definition: boundingsphere.hh:77
Scalar ctype
Definition: boundingsphere.hh:74
auto corners() const
Definition: boundingsphere.hh:76
PointsToGeometryWrapper(const std::vector< Dune::FieldVector< Scalar, dim > > &points)
Definition: boundingsphere.hh:70