Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
boundingbox.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef BOUNDINGBOX_HH
5#define BOUNDINGBOX_HH
6
7#include <vector>
8
9#include "box.hh"
11
19template<class CoordType, int dim>
21: public Box<CoordType, dim>
22{
23
24 public:
25
28 BoundingBox(const CoordType& lower, const CoordType& upper):
29 Box<CoordType,dim>(lower, upper)
30 {}
31
34 BoundingBox(const CoordType& point):
35 Box<CoordType,dim>(point, point)
36 {}
37
41 {
42 /* if point set is empty throw an exception otherwise set lower/upper to the first point in the container */
43 if (points.size() == 0)
44 DUNE_THROW(Dune::RangeError,"Point set is empty in Constructor BoundingBox::BoundingBox(const std::vector<CoordType>& points)");
45 else
46 {
47 this->upper_ = points[0];
48 this->lower_ = points[0];
49 }
50
51 /* lower = (min(p) p_1, min(p) p_2, ...); upper = (max(p) p_1, ... */
52 for (size_t i=1; i<points.size(); i++)
53 {
54 for (int j=0; j<dim; j++)
55 {
56 if (points[i][j] < this->lower_[j])
57 this->lower_[j] = points[i][j];
58 if (points[i][j] > this->upper_[j])
59 this->upper_[j] = points[i][j];
60 }
61 }
62
63 /* set the center */
64 setCenter();
65 }
66
74 void expandToInclude(const CoordType& point, bool resetCenter=true)
75 {
76 for (int j=0; j<dim; j++)
77 {
78 if (point[j] < this->lower_[j])
79 this->lower_[j] = point[j];
80 if (point[j] > this->upper_[j])
81 this->upper_[j] = point[j];
82 }
83
84 if (resetCenter)
85 setCenter();
86 }
87
90 void setCenter()
91 {
92 for (int i = 0; i < dim; ++i)
93 this->center_[i] = 0.5*(this->upper_[i]+this->lower_[i]);
94
95 }
96
97 /* more or less reimplementation of Box::contains, therefore commented out */
98 // /** Checks whether a point is inside of the box
99 // */
100 // bool inside(const CoordType& point) {
101 // for (int i=0; i<dim; i++) {
102 // if (point[i] > this.upper_[i])
103 // return false;
104 // if (point[i] < this.lower_[i])
105 // return false;
106 // }
107 // return true;
108 // }
109
115 bool insideNeighborhood(const CoordType& point, const double epsilon)
116 {
117 for (int i=0; i<dim; i++)
118 {
119 if (point[i] > this->upper_[i] + epsilon)
120 return false;
121 if (point[i] < this->lower_[i] - epsilon)
122 return false;
123 }
124 return true;
125 }
126
127};
128
129template<class CoordType, int dim>
131{
132 s << "[ (" << box.lower()[0];
133 for (int i=1; i<dim; ++i)
134 s << ", " << box.lower()[i];
135 s << ") ,(" << box.upper()[0];
136 for (int i=1; i<dim; ++i)
137 s << ", " << box.upper()[i];
138 s << ")]" << std::endl;
139 return s;
140}
141
142#endif
std::ostream & operator<<(std::ostream &s, const Box< CoordType, dim > &box)
Definition boundingbox.hh:130
size_type dim() const
#define DUNE_THROW(E,...)
Class for bounding boxes of point clouds.
Definition boundingbox.hh:22
BoundingBox(const CoordType &point)
Create "box" from one given point.
Definition boundingbox.hh:34
BoundingBox(const std::vector< const CoordType > &points)
Create bounding box of a set of points.
Definition boundingbox.hh:40
void setCenter()
calculates and sets the coordinates of the center of the box
Definition boundingbox.hh:90
bool insideNeighborhood(const CoordType &point, const double epsilon)
checks whether a point is inside an epsilon neighborhood of the bounding box
Definition boundingbox.hh:115
BoundingBox(const CoordType &lower, const CoordType &upper)
Create box from two given points.
Definition boundingbox.hh:28
void expandToInclude(const CoordType &point, bool resetCenter=true)
expands box to include a new point
Definition boundingbox.hh:74
Simple Box class.
Definition box.hh:11
CoordType lower_
Definition box.hh:67
CoordType center_
Definition box.hh:69
CoordType upper_
Definition box.hh:68
const CoordType & lower() const
Definition box.hh:56
const CoordType & upper() const
Definition box.hh:61
T endl(T... args)
T size(T... args)