Visual Computing Library  devel
Loading...
Searching...
No Matches
base.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_MESH_COMPONENTS_BASE_BASE_H
24#define VCL_MESH_COMPONENTS_BASE_BASE_H
25
26#include <vclib/base.h>
27
28namespace vcl {
29
47struct CompId
48{
49 enum Enum {
50 BIT_FLAGS = 0,
51 POSITION,
52 NORMAL,
53 COLOR,
54 QUALITY,
55 MARK,
56 MATERIAL_INDEX,
57 PRINCIPAL_CURVATURE,
58 TANGENT,
59 TEX_COORD,
60 VERTEX_REFERENCES,
61 ADJACENT_EDGES,
62 ADJACENT_FACES,
63 ADJACENT_VERTICES,
64 WEDGE_COLORS,
65 WEDGE_TEX_COORDS,
66 BOUNDING_BOX,
67 NAME,
68 MATERIALS,
69 TRANSFORM_MATRIX,
70 CUSTOM_COMPONENTS,
71 // Additional components here
72
73 COMPONENTS_NUMBER,
74 };
75};
76
83constexpr const char* COMPONENT_ENUM_STRINGS[CompId::COMPONENTS_NUMBER] = {
84 "BitFlags", "Position",
85 "Normal", "Color",
86 "Quality", "Mark",
87 "MaterialIndex", "PrincipalCurvature",
88 "Tangent", "TexCoord",
89 "VertexPointers", "AdjacentEdges",
90 "AdjacentFaces", "AdjacentVertices",
91 "WedgeColors", "WedgeTexCoords",
92 "BoundingBox", "Name",
93 "Materials", "TransformMatrix",
94 "CustomComponents",
95};
96
108template<uint COMP_ID>
110{
114 const char* str = COMP_ID < CompId::COMPONENTS_NUMBER ?
116 nullptr;
117};
118
127template<uint COMP_ID>
128constexpr const char* componentEnumString()
129{
130 static_assert(
131 ComponentString<COMP_ID>().str != nullptr,
132 "Invalid ComponentIDEnum. You should specialize the 'ComponentString' "
133 "struct with your COMP_ID value.");
134
135 return ComponentString<COMP_ID>().str;
136}
137
138namespace comp {
139
140namespace detail {
141
151template<uint COMP_ID, typename... Components>
152struct ComponentOfTypePred
153{
154private:
155 template<typename Comp>
156 struct SameCompPred
157 {
158 static constexpr bool value = Comp::COMPONENT_ID == COMP_ID;
159 };
160
161public:
162 // TypeWrapper of the found container, if any
163 using type =
164 typename FilterTypesByCondition<SameCompPred, Components...>::type;
165 static constexpr bool value = NumberOfTypes<type>::value == 1;
166};
167
168// TypeWrapper specialization
169template<uint COMP_ID, typename... Components>
170struct ComponentOfTypePred<COMP_ID, TypeWrapper<Components...>> :
171 public ComponentOfTypePred<COMP_ID, Components...>
172{
173};
174
175} // namespace detail
176
184template<uint COMP_ID, typename... Components>
186 typename detail::ComponentOfTypePred<COMP_ID, Components...>::type>;
187
188template<typename T>
192
193} // namespace comp
194
195} // namespace vcl
196
197#endif // VCL_MESH_COMPONENTS_BASE_BASE_H
A class representing a box in N-dimensional space.
Definition box.h:46
typename FirstType< Args... >::type FirstTypeT
Alias for the type of the first type in a pack of types.
Definition variadic_templates.h:63
constexpr const char * COMPONENT_ENUM_STRINGS[CompId::COMPONENTS_NUMBER]
The COMPONENT_ENUM_STRINGS array contains the string representation of the CompId::Enum values.
Definition base.h:83
constexpr const char * componentEnumString()
Returns the string associated to the COMP_ID value.
Definition base.h:128
The CompId struct enumerates the components that can compose a element or a mesh.
Definition base.h:48
The ComponentString class is used to retrieve the string associated to a COMP_ID value,...
Definition base.h:110
const char * str
The string associated to the COMPONENT_ID.
Definition base.h:114