#include <deal.II/base/config.h>
+#include <deal.II/base/bounding_box.h>
#include <deal.II/base/geometry_info.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/fe/mapping.h>
template <int dim, typename T>
double cell_measure (const T &, ...);
+ /**
+ * Compute the smallest box containing the entire triangulation.
+ *
+ * If the input triangulation is a `parallel::distributed::Triangulation`,
+ * then each processor will compute a bounding box enclosing all locally
+ * owned, ghost, and artificial cells. In the case of a domain without curved
+ * boundaries, these bounding boxes will all agree between processors because
+ * the union of the areas occupied by artificial and ghost cells equals the
+ * union of the areas occupied by the cells that other processors own.
+ * However, if the domain has curved boundaries, this is no longer the case.
+ * The bounding box returned may be appropriate for the current processor,
+ * but different from the bounding boxes computed on other processors.
+ */
+ template <int dim, int spacedim>
+ BoundingBox<spacedim> compute_bounding_box(const Triangulation<dim, spacedim> &triangulation);
+
/*@}*/
/**
* @name Functions supporting the creation of meshes
#define dealii_tria_accessor_h
+#include <deal.II/base/bounding_box.h>
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/geometry_info.h>
*/
std::pair<Point<spacedim>,double> enclosing_ball () const;
+ /**
+ * Return the smallest bounding box that encloses the object.
+ */
+ BoundingBox<spacedim> bounding_box () const;
+
/**
* Length of an object in the direction of the given axis, specified in the
* local coordinate system. See the documentation of GeometryInfo for the
}
+
+ template <int dim, int spacedim>
+ BoundingBox<spacedim>
+ compute_bounding_box(const Triangulation<dim, spacedim> &tria)
+ {
+ using iterator = typename Triangulation<dim, spacedim>::active_cell_iterator;
+ const auto predicate = [](const iterator &)
+ {
+ return true;
+ };
+
+ return compute_bounding_box(tria, std::function<bool(const iterator &)>(predicate));
+ }
+
+
+
template <int dim, int spacedim>
void
delete_unused_vertices (std::vector<Point<spacedim> > &vertices,
(const Triangulation<deal_II_dimension, deal_II_space_dimension> &,
const Mapping<deal_II_dimension, deal_II_space_dimension> &);
+ template
+ BoundingBox<deal_II_space_dimension>
+ compute_bounding_box
+ (const Triangulation<deal_II_dimension, deal_II_space_dimension> &);
+
template
void delete_unused_vertices (std::vector<Point<deal_II_space_dimension> > &,
std::vector<CellData<deal_II_dimension> > &,
+template <int structdim, int dim, int spacedim>
+BoundingBox<spacedim>
+TriaAccessor<structdim, dim, spacedim>::
+bounding_box () const
+{
+ std::pair<Point<spacedim>, Point<spacedim> > boundary_points =
+ std::make_pair(this->vertex(0), this->vertex(0));
+
+ for (unsigned int v=1; v<GeometryInfo<structdim>::vertices_per_cell; ++v)
+ {
+ const Point<spacedim> &x = this->vertex(v);
+ for (unsigned int k=0; k<spacedim; ++k)
+ {
+ boundary_points.first[k] = std::min(boundary_points.first[k], x[k]);
+ boundary_points.second[k] = std::max(boundary_points.second[k], x[k]);
+ }
+ }
+
+ return BoundingBox<spacedim>(boundary_points);
+}
+
+
+
template <>
double TriaAccessor<1,1,1>::extent_in_direction(const unsigned int axis) const
{
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Check computing bounding boxes of entire triangulations and individual cells
+
+#include "../tests.h"
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+template <int dim, int spacedim>
+void test_tria_bounding_box()
+{
+ dealii::Point<dim> p1, p2;
+ for (unsigned int k = 0; k < dim; ++k)
+ {
+ p1[k] = k;
+ p2[k] = 2 * k + 1;
+ }
+
+ Triangulation<dim, spacedim> tria;
+ GridGenerator::hyper_rectangle(tria, p1, p2);
+ tria.refine_global(1);
+ const BoundingBox<spacedim> bounding_box = GridTools::compute_bounding_box(tria);
+ const std::pair<Point<spacedim>, Point<spacedim> > &boundary_points =
+ bounding_box.get_boundary_points();
+
+ deallog << boundary_points.first << ", " << boundary_points.second << std::endl;
+}
+
+int main(void)
+{
+ initlog();
+
+ test_tria_bounding_box<1, 1>();
+ test_tria_bounding_box<1, 2>();
+ test_tria_bounding_box<2, 2>();
+ test_tria_bounding_box<1, 3>();
+ test_tria_bounding_box<2, 3>();
+ test_tria_bounding_box<3, 3>();
+
+ return 0;
+}
+
--- /dev/null
+
+DEAL::0.00000, 1.00000
+DEAL::0.00000 0.00000, 1.00000 0.00000
+DEAL::0.00000 1.00000, 1.00000 3.00000
+DEAL::0.00000 0.00000 0.00000, 1.00000 0.00000 0.00000
+DEAL::0.00000 1.00000 0.00000, 1.00000 3.00000 0.00000
+DEAL::0.00000 1.00000 2.00000, 1.00000 3.00000 5.00000
<< tria.begin_active()->extent_in_direction(0) << std::endl;
deallog << "dim" << dim << ":case" << case_no << ":minimum_vertex_distance="
<< tria.begin_active()->minimum_vertex_distance() << std::endl;
+
+ const BoundingBox<dim> box = tria.begin_active()->bounding_box();
+ const std::pair<Point<dim>, Point<dim> > &pts = box.get_boundary_points();
+ deallog << "dim" << dim << ":case" << case_no << ":bounding_box="
+ << pts.first << ", " << pts.second << std::endl;
tria.clear();
}
}
DEAL::dim2:case0:diameter=2.8284
DEAL::dim2:case0:extent_in_direction=2.0000
DEAL::dim2:case0:minimum_vertex_distance=2.0000
+DEAL::dim2:case0:bounding_box=1.0000 1.0000, 3.0000 3.0000
DEAL::dim2:case1:diameter=3.6056
DEAL::dim2:case1:extent_in_direction=3.0000
DEAL::dim2:case1:minimum_vertex_distance=2.0000
+DEAL::dim2:case1:bounding_box=0.0000 1.0000, 3.0000 3.0000
DEAL::dim2:case2:diameter=4.4721
DEAL::dim2:case2:extent_in_direction=3.0000
DEAL::dim2:case2:minimum_vertex_distance=2.2361
+DEAL::dim2:case2:bounding_box=0.0000 1.0000, 4.0000 3.0000
DEAL::dim3:case0:diameter=3.4641
DEAL::dim3:case0:extent_in_direction=2.0000
DEAL::dim3:case0:minimum_vertex_distance=2.0000
+DEAL::dim3:case0:bounding_box=1.0000 1.0000 1.0000, 3.0000 3.0000 3.0000
DEAL::dim3:case1:diameter=4.1231
DEAL::dim3:case1:extent_in_direction=3.0000
DEAL::dim3:case1:minimum_vertex_distance=2.0000
+DEAL::dim3:case1:bounding_box=0.0000 1.0000 1.0000, 3.0000 3.0000 3.0000
DEAL::dim3:case2:diameter=4.1231
DEAL::dim3:case2:extent_in_direction=3.0000
DEAL::dim3:case2:minimum_vertex_distance=2.0000
+DEAL::dim3:case2:bounding_box=0.0000 1.0000 1.0000, 3.0000 3.0000 3.0000