deal.II version 9.7.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
bounding_box.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_base_bounding_box_h
16#define dealii_base_bounding_box_h
17
18
19#include <deal.II/base/config.h>
20
22#include <deal.II/base/point.h>
23
24#include <limits>
25
27
69
134template <int spacedim, typename Number = double>
136{
137public:
142 static constexpr unsigned int dimension = spacedim;
143
148 BoundingBox() = default;
149
154
160
165
173
181 template <class Container>
182 BoundingBox(const Container &points);
183
187 std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
189
193 const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
195
199 bool
201
205 bool
207
212 bool
214 const BoundingBox<spacedim, Number> &other_bbox,
215 const double tolerance = std::numeric_limits<Number>::epsilon()) const;
216
222 const BoundingBox<spacedim, Number> &other_bbox,
223 const double tolerance = std::numeric_limits<Number>::epsilon()) const;
224
230 void
231 merge_with(const BoundingBox<spacedim, Number> &other_bbox);
232
239 bool
242 const double tolerance = std::numeric_limits<Number>::epsilon()) const;
243
254 void
255 extend(const Number amount);
256
262 create_extended(const Number amount) const;
263
278 create_extended_relative(const Number relative_amount) const;
279
283 double
284 volume() const;
285
290 center() const;
291
295 Number
296 side_length(const unsigned int direction) const;
297
301 Number
302 lower_bound(const unsigned int direction) const;
303
307 Number
308 upper_bound(const unsigned int direction) const;
309
314 bounds(const unsigned int direction) const;
315
321 vertex(const unsigned int index) const;
322
328 child(const unsigned int index) const;
329
337 BoundingBox<spacedim - 1, Number>
338 cross_section(const unsigned int direction) const;
339
349 real_to_unit(const Point<spacedim, Number> &point) const;
350
360 unit_to_real(const Point<spacedim, Number> &point) const;
368 Number
370 const unsigned int direction) const;
371
377 Number
378 signed_distance(const Point<spacedim, Number> &point) const;
379
385 template <class Archive>
386 void
387 serialize(Archive &ar, const unsigned int version);
388
389private:
390 std::pair<Point<spacedim, Number>, Point<spacedim, Number>> boundary_points;
391};
392
398template <typename Number>
399class BoundingBox<0, Number>
400{
401public:
406
411
415 template <class Container>
416 BoundingBox(const Container &);
417};
418
419
425template <int dim, typename Number = double>
428
429
430namespace internal
431{
464 template <int dim>
465 inline int
466 coordinate_to_one_dim_higher(const int locked_coordinate,
467 const int coordinate_in_dim)
468 {
469 AssertIndexRange(locked_coordinate, dim + 1);
470 AssertIndexRange(coordinate_in_dim, dim);
471 return (locked_coordinate + coordinate_in_dim + 1) % (dim + 1);
472 }
473
474} // namespace internal
475
476/*------------------------ Inline functions: BoundingBox --------------------*/
477
478#ifndef DOXYGEN
479
480
481template <int spacedim, typename Number>
484 : BoundingBox({p, p})
485{}
486
487
488
489template <int spacedim, typename Number>
492 &boundary_points)
493{
494 // We check the Bounding Box is not degenerate
495 for (unsigned int i = 0; i < spacedim; ++i)
496 Assert(boundary_points.first[i] <= boundary_points.second[i],
497 ExcMessage("Bounding Box can't be created: the points' "
498 "order should be bottom left, top right!"));
499
500 this->boundary_points = boundary_points;
501}
502
503
504
505template <int spacedim, typename Number>
506template <class Container>
507inline BoundingBox<spacedim, Number>::BoundingBox(const Container &points)
508{
509 // Use the default constructor in case points is empty instead of setting
510 // things to +oo and -oo
511 if (points.size() > 0)
512 {
513 auto &min = boundary_points.first;
514 auto &max = boundary_points.second;
515 for (unsigned int d = 0; d < spacedim; ++d)
516 {
517 min[d] = std::numeric_limits<Number>::infinity();
518 max[d] = -std::numeric_limits<Number>::infinity();
519 }
520
521 for (const Point<spacedim, Number> &point : points)
522 for (unsigned int d = 0; d < spacedim; ++d)
523 {
524 min[d] = std::min(min[d], point[d]);
525 max[d] = std::max(max[d], point[d]);
526 }
527 }
528}
529
530
531
532template <int spacedim, typename Number>
533inline std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
535{
536 return this->boundary_points;
537}
538
539
540
541template <int spacedim, typename Number>
542inline const std::pair<Point<spacedim, Number>, Point<spacedim, Number>> &
544{
545 return this->boundary_points;
546}
547
548
549
550template <int spacedim, typename Number>
551inline bool
553 const BoundingBox<spacedim, Number> &box) const
554{
555 return boundary_points == box.boundary_points;
556}
557
558
559
560template <int spacedim, typename Number>
561inline bool
563 const BoundingBox<spacedim, Number> &box) const
564{
565 return boundary_points != box.boundary_points;
566}
567
568
569
570template <int spacedim, typename Number>
571inline void
572BoundingBox<spacedim, Number>::extend(const Number amount)
573{
574 for (unsigned int d = 0; d < spacedim; ++d)
575 {
576 boundary_points.first[d] -= amount;
577 boundary_points.second[d] += amount;
578 Assert(boundary_points.first[d] <= boundary_points.second[d],
579 ExcMessage("Bounding Box can't be shrunk this much: the points' "
580 "order should remain bottom left, top right."));
581 }
582}
583
584
585
586template <int spacedim, typename Number>
588BoundingBox<spacedim, Number>::create_extended(const Number amount) const
589{
590 // create and modify copy
591 auto bb = *this;
592 bb.extend(amount);
593
594 return bb;
595}
596
597
598
599template <int spacedim, typename Number>
602 const Number relative_amount) const
603{
604 // create and modify copy
605 auto bb = *this;
606
607 for (unsigned int d = 0; d < spacedim; ++d)
608 {
609 bb.boundary_points.first[d] -= relative_amount * side_length(d);
610 bb.boundary_points.second[d] += relative_amount * side_length(d);
611 Assert(bb.boundary_points.first[d] <= bb.boundary_points.second[d],
612 ExcMessage("Bounding Box can't be shrunk this much: the points' "
613 "order should remain bottom left, top right."));
614 }
615
616 return bb;
617}
618
619
620
621template <int spacedim, typename Number>
622template <class Archive>
623void
625 const unsigned int /*version*/)
626{
627 // Avoid including boost/serialization/utility.hpp by unpacking the pair
628 // ourselves
629 ar &boundary_points.first;
630 ar &boundary_points.second;
631}
632
633
634
635template <typename Number>
637{
639}
640
641
642
643template <typename Number>
645 const std::pair<Point<0, Number>, Point<0, Number>> &)
646{
648}
649
650
651
652template <typename Number>
653template <class Container>
654inline BoundingBox<0, Number>::BoundingBox(const Container &)
655{
657}
658
659
660
661#endif // DOXYGEN
663
664#endif
NeighborType
BoundingBox< dim, Number > create_unit_bounding_box()
BoundingBox(const std::pair< Point< 0, Number >, Point< 0, Number > > &)
BoundingBox(const Container &)
int coordinate_to_one_dim_higher(const int locked_coordinate, const int coordinate_in_dim)
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > boundary_points
BoundingBox< 1, Number > bounds(const unsigned int direction) const
bool has_overlap_with(const BoundingBox< spacedim, Number > &other_bbox, const double tolerance=std::numeric_limits< Number >::epsilon()) const
BoundingBox(const std::pair< Point< spacedim, Number >, Point< spacedim, Number > > &boundary_points)
Point< spacedim, Number > center() const
BoundingBox()=default
Number lower_bound(const unsigned int direction) const
Number signed_distance(const Point< spacedim, Number > &point, const unsigned int direction) const
bool operator==(const BoundingBox< spacedim, Number > &box) const
void serialize(Archive &ar, const unsigned int version)
void merge_with(const BoundingBox< spacedim, Number > &other_bbox)
std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points()
bool point_inside(const Point< spacedim, Number > &p, const double tolerance=std::numeric_limits< Number >::epsilon()) const
double volume() const
void extend(const Number amount)
BoundingBox< spacedim, Number > create_extended_relative(const Number relative_amount) const
BoundingBox(const Container &points)
Point< spacedim, Number > real_to_unit(const Point< spacedim, Number > &point) const
const std::pair< Point< spacedim, Number >, Point< spacedim, Number > > & get_boundary_points() const
static constexpr unsigned int dimension
Number side_length(const unsigned int direction) const
BoundingBox< spacedim, Number > child(const unsigned int index) const
bool operator!=(const BoundingBox< spacedim, Number > &box) const
BoundingBox< spacedim, Number > & operator=(const BoundingBox< spacedim, Number > &t)=default
NeighborType get_neighbor_type(const BoundingBox< spacedim, Number > &other_bbox, const double tolerance=std::numeric_limits< Number >::epsilon()) const
BoundingBox< spacedim, Number > create_extended(const Number amount) const
Point< spacedim, Number > vertex(const unsigned int index) const
BoundingBox(const Point< spacedim, Number > &point)
BoundingBox< spacedim - 1, Number > cross_section(const unsigned int direction) const
BoundingBox(const BoundingBox< spacedim, Number > &box)=default
Number upper_bound(const unsigned int direction) const
Point< spacedim, Number > unit_to_real(const Point< spacedim, Number > &point) const
Definition point.h:113
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)