version 3.10-dev
boundingsphere.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_GEOMETRY_BOUNDINGSPHERE_HH
13#define DUMUX_GEOMETRY_BOUNDINGSPHERE_HH
14
15#include <algorithm>
16#include <vector>
17
19
20namespace Dumux {
21
28template<class ConvexGeometry>
29static inline Sphere<typename ConvexGeometry::ctype, ConvexGeometry::coorddimension>
30boundingSphere(const ConvexGeometry& geometry)
31{
32 constexpr int dimWorld = ConvexGeometry::coorddimension;
33 assert(geometry.corners() >= 1);
34
35 auto corner = geometry.corner(0);
36 auto xMin = corner, xMax = corner;
37 using std::max; using std::min;
38
39 // Compute the min and max over the remaining vertices
40 for (std::size_t i = 1; i < geometry.corners(); ++i)
41 {
42 corner = geometry.corner(i);
43 for (std::size_t dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
44 {
45 xMin[dimIdx] = min(xMin[dimIdx], corner[dimIdx]);
46 xMax[dimIdx] = max(xMax[dimIdx], corner[dimIdx]);
47 }
48 }
49
50 auto center = 0.5*xMax + xMin;
51 auto radius = (center-xMax).two_norm();
52 return { std::move(center), std::move(radius) };
53}
54
55namespace Detail {
56template<class Scalar, int dim>
58{
59 const std::vector<Dune::FieldVector<Scalar, dim>>& points_;
60 PointsToGeometryWrapper(const std::vector<Dune::FieldVector<Scalar, dim>>& points)
61 : points_(points) {}
62
63 static constexpr int coorddimension = dim;
64 using ctype = Scalar;
65
66 auto corners() const { return points_.size(); }
67 const auto& corner(std::size_t i) const { return points_[i]; }
68};
69} // end namespace Detail
70
77template<class Scalar, int dim>
78static inline Sphere<Scalar, dim>
79boundingSphere(const std::vector<Dune::FieldVector<Scalar, dim>>& points)
80{
82 return boundingSphere(geometry);
83}
84
85} // end namespace Dumux
86
87#endif
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:30
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition: center.hh:24
Definition: adapt.hh:17
A function to compute bounding spheres of points clouds or convex polytopes.
Definition: boundingsphere.hh:58
static constexpr int coorddimension
Definition: boundingsphere.hh:63
const std::vector< Dune::FieldVector< Scalar, dim > > & points_
Definition: boundingsphere.hh:59
const auto & corner(std::size_t i) const
Definition: boundingsphere.hh:67
Scalar ctype
Definition: boundingsphere.hh:64
auto corners() const
Definition: boundingsphere.hh:66
PointsToGeometryWrapper(const std::vector< Dune::FieldVector< Scalar, dim > > &points)
Definition: boundingsphere.hh:60