Visual Computing Library
Loading...
Searching...
No Matches
mesh_elements.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_TYPES_MESH_ELEMENTS_H
24#define VCL_TYPES_MESH_ELEMENTS_H
25
26#include "base.h"
27
28#include <string>
29
30namespace vcl {
31
53struct ElemId
54{
55 enum Enum : uint {
56 VERTEX = 0,
57 FACE,
58 EDGE,
59 ELEMENTS_NUMBER,
60 };
61};
62
69constexpr const char* ELEMENT_ENUM_STRINGS[ElemId::ELEMENTS_NUMBER] = {
70 "Vertex",
71 "Face",
72 "Edge",
73};
74
86template<uint ELEM_ID>
88{
92 const char* str = ELEM_ID < ElemId::ELEMENTS_NUMBER ?
93 ELEMENT_ENUM_STRINGS[ELEM_ID] :
94 nullptr;
95};
96
105template<uint ELEM_ID>
106constexpr const char* elementEnumCString()
107{
108 static_assert(
109 ElementString<ELEM_ID>().str != nullptr,
110 "Invalid ElementIDEnum. You should specialize 'the ElementString' "
111 "struct with your ELEM_ID value.");
112
113 return ElementString<ELEM_ID>().str;
114}
115
124// Todo: make this function constexpr when upgrading to C++23.
125template<uint ELEM_ID>
126const std::string& elementEnumString()
127{
128 static const std::string str = elementEnumCString<ELEM_ID>();
129
130 return str;
131}
132
133} // namespace vcl
134
135#endif // VCL_TYPES_MESH_ELEMENTS_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
constexpr const char * elementEnumCString()
Returns the string associated to the ELEM_ID value.
Definition mesh_elements.h:106
const std::string & elementEnumString()
Returns the string associated to the ELEM_ID value.
Definition mesh_elements.h:126
constexpr const char * ELEMENT_ENUM_STRINGS[ElemId::ELEMENTS_NUMBER]
The ELEMENT_ENUM_STRINGS array contains the string representation of the elements that can compose a ...
Definition mesh_elements.h:69
The ElemId struct enumerates the elements that can compose a mesh.
Definition mesh_elements.h:54
The ElementString class is used to retrieve the string associated to a ELEM_ID value,...
Definition mesh_elements.h:88
const char * str
The string associated to the ELEM_ID.
Definition mesh_elements.h:92