OGS
MeshElementGrid.h
Go to the documentation of this file.
1/*
2 * \file
3 * \brief Declaration of the MeshElementGrid class.
4 *
6 * Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
8 * See accompanying file LICENSE.txt or
10 */
11
12#pragma once
13
14#include <array>
15#include <limits>
16#include <vector>
17
18#include "GeoLib/AABB.h"
19#include "MathLib/Point3d.h"
20
21namespace MeshLib {
22
23// forward declarations
24class Mesh;
25class Element;
26
32class MeshElementGrid final {
33public:
36 explicit MeshElementGrid(MeshLib::Mesh const& mesh);
37
43 template <typename POINT>
44 std::vector<MeshLib::Element const*> getElementsInVolume(
45 POINT const& min, POINT const& max) const
46 {
47 auto const min_coords(getGridCellCoordinates(min));
48 auto const max_coords(getGridCellCoordinates(max));
49
50 std::vector<MeshLib::Element const*> elements_vec;
51
52 const std::size_t n_plane(_n_steps[0]*_n_steps[1]);
53 for (std::size_t i(min_coords.second[0]); i<=max_coords.second[0]; i++) {
54 for (std::size_t j(min_coords.second[1]); j<=max_coords.second[1]; j++) {
55 for (std::size_t k(min_coords.second[2]); k<=max_coords.second[2]; k++) {
56 std::size_t idx(i+j*_n_steps[0]+k*n_plane);
57 elements_vec.insert(end(elements_vec),
58 begin(_elements_in_grid_box[idx]),
59 end(_elements_in_grid_box[idx]));
60 }
61 }
62 }
63 return elements_vec;
64 }
65
68 Eigen::Vector3d const& getMinPoint() const;
71 Eigen::Vector3d const& getMaxPoint() const;
72
73private:
74 void sortElementsInGridCells(MeshLib::Mesh const& mesh);
75 bool sortElementInGridCells(MeshLib::Element const& element);
76
81 std::pair<bool, std::array<std::size_t,3>>
83 std::array<double,3> _step_sizes{};
84 std::array<double,3> _inverse_step_sizes{};
85 std::array<std::size_t,3> _n_steps;
86 std::vector<std::vector<MeshLib::Element const*>> _elements_in_grid_box;
87};
88} // namespace MeshLib
Definition of the AABB class.
Definition of the Point3d class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
void sortElementsInGridCells(MeshLib::Mesh const &mesh)
std::vector< std::vector< MeshLib::Element const * > > _elements_in_grid_box
MeshElementGrid(MeshLib::Mesh const &mesh)
std::pair< bool, std::array< std::size_t, 3 > > getGridCellCoordinates(MathLib::Point3d const &p) const
bool sortElementInGridCells(MeshLib::Element const &element)
Eigen::Vector3d const & getMinPoint() const
std::vector< MeshLib::Element const * > getElementsInVolume(POINT const &min, POINT const &max) const
std::array< double, 3 > _inverse_step_sizes
std::array< std::size_t, 3 > _n_steps
std::array< double, 3 > _step_sizes
Eigen::Vector3d const & getMaxPoint() const