Visual Computing Library  devel
Loading...
Searching...
No Matches
face.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_ELEMENTS_FACE_H
24#define VCL_MESH_ELEMENTS_FACE_H
25
26#include "base/element.h"
27#include "face_components.h"
28
29#include <vclib/base.h>
30
31namespace vcl {
32
46template<typename MeshType, comp::ComponentConcept... Comps>
47class Face : public Element<ElemId::FACE, MeshType, Comps...>
48{
49 using Base = Element<ElemId::FACE, MeshType, Comps...>;
50
51 // VertexPointers or VertexIndices component of the Face
52 using VRefs = typename Face::VertexReferences;
53
54 static const int NV = VRefs::VERTEX_NUMBER; // If dynamic, NV will be -1
55
56public:
57 using VertexType = typename VRefs::VertexType;
58
66 Face() = default;
67
83 template<Range Rng>
86 {
87 VRefs::setVertices(r);
88
89 // if polygonal, I need to resize all the TTVN components
90 if constexpr (NV < 0) {
91 (resizeTTVNComponent<Comps>(std::ranges::size(r)), ...);
92 }
93 }
94
109 template<typename... V>
110 void setVertices(V... args) requires (
111 (std::convertible_to<V, VertexType*> || std::convertible_to<V, uint>) &&
112 ...)
113 {
114 setVertices(std::list({args...}));
115 }
116
132 void resizeVertices(uint n) requires (NV < 0)
133 {
134 VRefs::resizeVertices(n);
135
136 // Now I need to resize all the TTVN components
138 }
139
140 void pushVertex(VertexType* v) requires (NV < 0)
141 {
142 VRefs::pushVertex(v);
143
144 // Now I need to pushBack in all the TTVN components
146 }
147
148 void pushVertex(uint vi) requires (NV < 0)
149 {
150 VRefs::pushVertex(vi);
151
152 // Now I need to pushBack in all the TTVN components
153 (pushBackTTVNComponent<Comps>(), ...);
154 }
155
156 void insertVertex(uint i, VertexType* v) requires (NV < 0)
157 {
158 VRefs::insertVertex(i, v);
159
160 // Now I need to insert in all the TTVN components
161 (insertTTVNComponent<Comps>(i), ...);
162 }
163
164 void insertVertex(uint i, uint vi) requires (NV < 0)
165 {
166 VRefs::insertVertex(i, vi);
167
168 // Now I need to insert in all the TTVN components
169 (insertTTVNComponent<Comps>(i), ...);
170 }
171
172 void eraseVertex(uint i) requires (NV < 0)
173 {
174 VRefs::eraseVertex(i);
175
176 // Now I need to erase in all the TTVN components
177 (eraseTTVNComponent<Comps>(i), ...);
178 }
179
180 void clearVertices() requires (NV < 0)
181 {
182 VRefs::clearVertices();
183
184 // Now I need to clear all the TTVN components
185 (clearTTVNComponent<Comps>(), ...);
186 }
187
188 template<typename ElType>
189 void importFrom(const ElType& v, bool importRefs = true)
190 {
191 if constexpr (comp::HasVertexReferences<ElType> && NV < 0) {
192 VRefs::resizeVertices(v.vertexNumber());
193 // Now I need to resize all the TTVN components
194 (resizeTTVNComponent<Comps>(v.vertexNumber()), ...);
195 }
196
197 Base::importFrom(v, importRefs);
198 }
199
200private:
205 template<typename Comp>
207 {
208 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
209 if (Comp::isAvailable())
210 Comp::resize(n);
211 }
212 }
213
218 template<typename Comp>
220 {
221 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
222 if (Comp::isAvailable())
223 Comp::pushBack();
224 }
225 }
226
231 template<typename Comp>
233 {
234 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
235 if (Comp::isAvailable())
236 Comp::insert(i);
237 }
238 }
239
244 template<typename Comp>
246 {
247 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
248 if (Comp::isAvailable())
249 Comp::erase(i);
250 }
251 }
252
257 template<typename Comp>
259 {
260 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
261 if (Comp::isAvailable())
262 Comp::clear();
263 }
264 }
265};
266
267template<typename MeshType, comp::ComponentConcept... Comps>
268class Face<MeshType, TypeWrapper<Comps...>> : public Face<MeshType, Comps...>
269{
270};
271
272/* Concepts */
273
294template<typename T>
295concept FaceConcept =
296 IsDerivedFromSpecializationOfV<T, Face> &&
297 RemoveRef<T>::ELEMENT_ID == ElemId::FACE && face::HasBitFlags<T> &&
299 (RemoveRef<T>::VERTEX_NUMBER < 0 || RemoveRef<T>::VERTEX_NUMBER >= 3) &&
300 (!face::HasTriangleBitFlags<T> || RemoveRef<T>::VERTEX_NUMBER == 3) &&
303
304template<typename T>
306 RemoveRef<T>::VERTEX_NUMBER == 3 && FaceConcept<T>;
307
317template<typename T>
318concept PolygonFaceConcept = RemoveRef<T>::VERTEX_NUMBER < 0 && FaceConcept<T>;
319
320} // namespace vcl
321
322#endif // VCL_MESH_ELEMENTS_FACE_H
A class representing a box in N-dimensional space.
Definition box.h:46
The Element class.
Definition element.h:75
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:48
void eraseTTVNComponent(uint i)
Definition face.h:245
void resizeVertices(uint n)
Resize the number of Vertex Pointers of the Face, taking care of updating also the other components o...
Definition face.h:132
void setVertices(Rng &&r)
Sets all the Vertices to the face.
Definition face.h:84
Face()=default
Empty constructor.
void clearTTVNComponent()
Definition face.h:258
void pushBackTTVNComponent()
Definition face.h:219
void insertTTVNComponent(uint i)
Definition face.h:232
void setVertices(V... args)
Sets a list of Vertices to the face.
Definition face.h:110
void resizeTTVNComponent(uint n)
Definition face.h:206
A concept that checks whether a class has (inherits from) an Face class.
Definition face.h:295
Utility concept that is evaluated true the Range R is an Input Range and has a value_type that is con...
Definition range.h:89
A concpet that checks whether a class has (inherits from) a Face class and that the Face is polygonal...
Definition face.h:318
Definition face.h:305
Evaluates to true if the type T is tied to the number of vertices in the face.
Definition component.h:126
SanityCheckAdjacentEdges concept.
Definition adjacent_edges.h:715
SanityCheckAdjacentFaces concept.
Definition adjacent_faces.h:719
SanityCheckWedgeColors concept.
Definition wedge_colors.h:380
SanityCheckWedgeTexCoords concept.
Definition wedge_tex_coords.h:444
Definition face_components.h:76
Definition face_components.h:104
Definition face_components.h:106
A simple structure that wraps a list of variadic templates, without instantiating anything....
Definition type_wrapper.h:39