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
74 friend void swap(Face& a, Face& b) { a.swap(b); }
75
91 template<Range Rng>
94 {
95 VRefs::setVertices(r);
96
97 // if polygonal, I need to resize all the TTVN components
98 if constexpr (NV < 0) {
99 (resizeTTVNComponent<Comps>(std::ranges::size(r)), ...);
100 }
101 }
102
117 template<typename... V>
118 void setVertices(V... args) requires (
119 (std::convertible_to<V, VertexType*> || std::convertible_to<V, uint>) &&
120 ...)
121 {
122 setVertices(std::list({args...}));
123 }
124
140 void resizeVertices(uint n) requires (NV < 0)
141 {
142 VRefs::resizeVertices(n);
143
144 // Now I need to resize all the TTVN components
146 }
147
148 void pushVertex(VertexType* v) requires (NV < 0)
149 {
150 VRefs::pushVertex(v);
151
152 // Now I need to pushBack in all the TTVN components
154 }
155
156 void pushVertex(uint vi) requires (NV < 0)
157 {
158 VRefs::pushVertex(vi);
159
160 // Now I need to pushBack in all the TTVN components
161 (pushBackTTVNComponent<Comps>(), ...);
162 }
163
164 void insertVertex(uint i, VertexType* v) requires (NV < 0)
165 {
166 VRefs::insertVertex(i, v);
167
168 // Now I need to insert in all the TTVN components
169 (insertTTVNComponent<Comps>(i), ...);
170 }
171
172 void insertVertex(uint i, uint vi) requires (NV < 0)
173 {
174 VRefs::insertVertex(i, vi);
175
176 // Now I need to insert in all the TTVN components
177 (insertTTVNComponent<Comps>(i), ...);
178 }
179
180 void eraseVertex(uint i) requires (NV < 0)
181 {
182 VRefs::eraseVertex(i);
183
184 // Now I need to erase in all the TTVN components
185 (eraseTTVNComponent<Comps>(i), ...);
186 }
187
188 void clearVertices() requires (NV < 0)
189 {
190 VRefs::clearVertices();
191
192 // Now I need to clear all the TTVN components
193 (clearTTVNComponent<Comps>(), ...);
194 }
195
196 template<typename ElType>
197 void importFrom(const ElType& v, bool importRefs = true)
198 {
199 if constexpr (comp::HasVertexReferences<ElType> && NV < 0) {
200 VRefs::resizeVertices(v.vertexNumber());
201 // Now I need to resize all the TTVN components
202 (resizeTTVNComponent<Comps>(v.vertexNumber()), ...);
203 }
204
205 Base::importFrom(v, importRefs);
206 }
207
208private:
213 template<typename Comp>
215 {
216 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
217 if (Comp::isAvailable())
218 Comp::resize(n);
219 }
220 }
221
226 template<typename Comp>
228 {
229 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
230 if (Comp::isAvailable())
231 Comp::pushBack();
232 }
233 }
234
239 template<typename Comp>
241 {
242 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
243 if (Comp::isAvailable())
244 Comp::insert(i);
245 }
246 }
247
252 template<typename Comp>
254 {
255 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
256 if (Comp::isAvailable())
257 Comp::erase(i);
258 }
259 }
260
265 template<typename Comp>
267 {
268 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
269 if (Comp::isAvailable())
270 Comp::clear();
271 }
272 }
273};
274
275template<typename MeshType, comp::ComponentConcept... Comps>
276class Face<MeshType, TypeWrapper<Comps...>> : public Face<MeshType, Comps...>
277{
278};
279
280/* Concepts */
281
302template<typename T>
303concept FaceConcept =
304 IsDerivedFromSpecializationOfV<T, Face> &&
305 RemoveRef<T>::ELEMENT_ID == ElemId::FACE && face::HasBitFlags<T> &&
307 (RemoveRef<T>::VERTEX_NUMBER < 0 || RemoveRef<T>::VERTEX_NUMBER >= 3) &&
308 (!face::HasTriangleBitFlags<T> || RemoveRef<T>::VERTEX_NUMBER == 3) &&
311
312template<typename T>
314 RemoveRef<T>::VERTEX_NUMBER == 3 && FaceConcept<T>;
315
325template<typename T>
326concept PolygonFaceConcept = RemoveRef<T>::VERTEX_NUMBER < 0 && FaceConcept<T>;
327
328} // namespace vcl
329
330#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:253
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:140
void setVertices(Rng &&r)
Sets all the Vertices to the face.
Definition face.h:92
Face()=default
Empty constructor.
void clearTTVNComponent()
Definition face.h:266
void pushBackTTVNComponent()
Definition face.h:227
void insertTTVNComponent(uint i)
Definition face.h:240
void setVertices(V... args)
Sets a list of Vertices to the face.
Definition face.h:118
void resizeTTVNComponent(uint n)
Definition face.h:214
friend void swap(Face &a, Face &b)
Swap function that delegates to the base Element swap.
Definition face.h:74
A concept that checks whether a class has (inherits from) an Face class.
Definition face.h:303
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:326
Definition face.h:313
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:417
Definition face_components.h:77
Definition face_components.h:109
Definition face_components.h:111
A simple structure that wraps a list of variadic templates, without instantiating anything....
Definition type_wrapper.h:39