OGS
MeshLib/CoordinateSystem.cpp
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#include "CoordinateSystem.h"
5
6#include <cmath>
7
8#include "GeoLib/AABB.h"
10#include "MeshLib/Node.h"
11
12namespace
13{
14unsigned char getCoordinateSystem(GeoLib::AABB const& bbox)
15{
16 unsigned char coords = 0;
17
18 auto const [bbox_min, bbox_max] = bbox.getMinMaxPoints();
19 Eigen::Vector3d const pt_diff = bbox_max - bbox_min;
20
21 // The axis aligned bounding box is a from the right half-open interval.
22 // Therefore, the difference between the particular coordinates of the
23 // points is modified by the unit in the last place towards zero.
24 if (std::nexttoward(std::abs(pt_diff[0]), 0.0) > .0)
25 {
27 }
28 if (std::nexttoward(std::abs(pt_diff[1]), 0.0) > .0)
29 {
31 }
32 if (std::nexttoward(std::abs(pt_diff[2]), 0.0) > .0)
33 {
35 }
36
37 return coords;
38}
39} // namespace
40
41namespace MeshLib
42{
44{
45 GeoLib::AABB const aabb(ele.getNodes(),
46 ele.getNodes() + ele.getNumberOfNodes());
47 CoordinateSystem const bboxCoordSys(getCoordinateSystem(aabb));
48 if (bboxCoordSys.getDimension() >= ele.getDimension())
49 {
50 _type = bboxCoordSys.getType();
51 }
52 else
53 { // e.g. zero volume elements
54 if (ele.getDimension() >= 1)
55 {
57 }
58 if (ele.getDimension() >= 2)
59 {
61 }
62 if (ele.getDimension() == 3)
63 {
65 }
66 }
67}
68
70 : _type(getCoordinateSystem(bbox))
71{
72}
73
74} // namespace MeshLib
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:45
MinMaxPoints getMinMaxPoints() const
Definition AABB.h:163
unsigned char getType() const
get this coordinate type
CoordinateSystem(unsigned char coord)
User provided coordinate system.
unsigned getDimension() const
get dimension size
virtual unsigned getNumberOfNodes() const =0
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
virtual Node *const * getNodes() const =0
Get array of element nodes.
unsigned char getCoordinateSystem(GeoLib::AABB const &bbox)