Visual Computing Library  devel
Loading...
Searching...
No Matches
material_index.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_MATERIAL_INDEX_H
24#define VCL_MESH_COMPONENTS_MATERIAL_INDEX_H
25
26#include "base/component.h"
27#include "base/predicates.h"
28
29namespace vcl::comp {
30
31template<typename ParentElemType = void, bool OPT = false>
33 public Component<
34 MaterialIndex<ParentElemType, OPT>,
35 CompId::MATERIAL_INDEX,
36 uint,
37 ParentElemType,
38 !std::is_same_v<ParentElemType, void>,
39 OPT>
40{
41 using Base = Component<
43 CompId::MATERIAL_INDEX,
44 uint,
46 !std::is_same_v<ParentElemType, void>,
47 OPT>;
48
49public:
50 /* Constructors */
51
56 {
57 if constexpr (!Base::IS_VERTICAL) {
58 init();
59 }
60 }
61
73
74 /* Member functions */
75
80 uint& materialIndex() { return Base::data(); }
81
86 uint materialIndex() const { return Base::data(); }
87
95 // uint& textureIndex() { return Base::data(); }
96
104 // uint textureIndex() const { return Base::data(); }
105
106protected:
107 // Component interface function
108 template<typename Element>
109 void importFrom(const Element& e, bool = true);
110
111 void serialize(std::ostream& os) const
112 {
113 vcl::serialize(os, materialIndex());
114 }
115
116 void deserialize(std::istream& is)
117 {
118 vcl::deserialize(is, materialIndex());
119 }
120};
121
122/* concepts */
123
141template<typename T>
142concept HasMaterialIndex = TB::IsDerivedFromSpecializationOfV<T, MaterialIndex>;
143
154template<typename T>
158
159/* importFrom function */
160
161template<typename ParentElemType, bool OPT>
162template<typename Element>
164{
165 if constexpr (HasMaterialIndex<Element>) {
166 if (isMaterialIndexAvailableOn(e)) {
167 materialIndex() = e.materialIndex();
168 }
169 }
170}
171
172/* Detector function to check if a class has MaterialIndex available */
173
185bool isMaterialIndexAvailableOn(const auto& element)
186{
188}
189
190} // namespace vcl::comp
191
192#endif // VCL_MESH_COMPONENTS_MATERIAL_INDEX_H
A class representing a box in N-dimensional space.
Definition box.h:46
The Element class.
Definition element.h:75
Definition material_index.h:40
void importFrom(const Element &e, bool=true)
Returns a reference to the material index.
Definition material_index.h:163
void init()
Initializes the material index to UINT_NULL.
Definition material_index.h:72
MaterialIndex()
Constructor that initializes the material index to UINT_NULL.
Definition material_index.h:55
uint & materialIndex()
Returns a reference to the material index.
Definition material_index.h:80
uint materialIndex() const
Returns the value of the material index.
Definition material_index.h:86
A concept that checks whether a type T (that should be a Element or a Mesh) has the MaterialIndex com...
Definition material_index.h:142
A concept that checks whether a type T (that should be a Element or a Mesh) has the MaterialIndex com...
Definition material_index.h:155
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:48