OGS
MeshElementGrid.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <array>
7#include <limits>
8#include <vector>
9
10#include "GeoLib/AABB.h"
11#include "MathLib/Point3d.h"
12
13namespace MeshLib {
14
15// forward declarations
16class Mesh;
17class Element;
18
24class MeshElementGrid final {
25public:
28 explicit MeshElementGrid(MeshLib::Mesh const& mesh);
29
35 template <typename POINT>
36 std::vector<MeshLib::Element const*> getElementsInVolume(
37 POINT const& min, POINT const& max) const
38 {
39 auto const min_coords(getGridCellCoordinates(min));
40 auto const max_coords(getGridCellCoordinates(max));
41
42 std::vector<MeshLib::Element const*> elements_vec;
43
44 const std::size_t n_plane(_n_steps[0]*_n_steps[1]);
45 for (std::size_t i(min_coords.second[0]); i<=max_coords.second[0]; i++) {
46 for (std::size_t j(min_coords.second[1]); j<=max_coords.second[1]; j++) {
47 for (std::size_t k(min_coords.second[2]); k<=max_coords.second[2]; k++) {
48 std::size_t idx(i+j*_n_steps[0]+k*n_plane);
49 elements_vec.insert(end(elements_vec),
50 begin(_elements_in_grid_box[idx]),
51 end(_elements_in_grid_box[idx]));
52 }
53 }
54 }
55 return elements_vec;
56 }
57
60 Eigen::Vector3d const& getMinPoint() const;
63 Eigen::Vector3d const& getMaxPoint() const;
64
65private:
66 void sortElementsInGridCells(MeshLib::Mesh const& mesh);
67 bool sortElementInGridCells(MeshLib::Element const& element);
68
73 std::pair<bool, std::array<std::size_t,3>>
75 std::array<double,3> _step_sizes{};
76 std::array<double,3> _inverse_step_sizes{};
77 std::array<std::size_t,3> _n_steps;
78 std::vector<std::vector<MeshLib::Element const*>> _elements_in_grid_box;
79};
80} // namespace MeshLib
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:45
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