-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathMeshInformation.h
75 lines (66 loc) · 2.07 KB
/
MeshInformation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* \file
* \author Karsten Rink
* \date 2013-10-28
* \brief Definition of the MeshInformation class
*
* \copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <array>
#include <limits>
#include <string>
#include "GeoLib/AABB.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
#include "MeshLib/Properties.h"
namespace MeshLib
{
/**
* \brief A set of tools for extracting information from a mesh
*/
class MeshInformation
{
public:
/// Returns the smallest and largest value of a scalar array with the given
/// name.
template <typename T>
static boost::optional<std::pair<T, T>> const getValueBounds(
MeshLib::Mesh const& mesh, std::string const& name)
{
if (!mesh.getProperties().existsPropertyVector<T>(name))
{
return {};
}
auto const* const data_vec =
mesh.getProperties().getPropertyVector<T>(name);
if (data_vec->empty())
{
INFO("Mesh does not contain values for the property '%s'.",
name.c_str());
return {};
}
auto const [min, max] =
std::minmax_element(begin(*data_vec), end(*data_vec));
return {{*min, *max}};
}
/// Returns the bounding box of the mesh.
static const GeoLib::AABB getBoundingBox(const MeshLib::Mesh& mesh);
/**
* Returns an array with the number of elements of each type in the given
* mesh. On completion, n_element_types array contains the number of
* elements of each of the seven supported types. The index to element type
* conversion is this: 0: \#lines 1: \#triangles 2: \#quads 3: \#tetrahedra
* 4: \#hexahedra
* 5: \#pyramids
* 6: \#prisms
*/
static const std::array<unsigned, 7> getNumberOfElementTypes(
const MeshLib::Mesh& mesh);
};
} // namespace MeshLib