Visual Computing Library  devel
Loading...
Searching...
No Matches
face.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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_COUNT; // 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
90 template<Range Rng>
93 {
94 VRefs::setVertices(r);
95
96 // if polygonal, I need to resize all the TTVC components
97 if constexpr (NV < 0) {
98 (resizeTTVCComponent<Comps>(std::ranges::size(r)), ...);
99 }
100 }
101
116 template<typename... V>
117 void setVertices(V... args) requires (
118 (std::convertible_to<V, VertexType*> || std::convertible_to<V, uint>) &&
119 ...)
120 {
121 setVertices(std::list({args...}));
122 }
123
139 void resizeVertices(uint n) requires (NV < 0)
140 {
141 VRefs::resizeVertices(n);
142
143 // Now I need to resize all the TTVC components
145 }
146
147 void pushVertex(VertexType* v) requires (NV < 0)
148 {
149 VRefs::pushVertex(v);
150
151 // Now I need to pushBack in all the TTVC components
153 }
154
155 void pushVertex(uint vi) requires (NV < 0)
156 {
157 VRefs::pushVertex(vi);
158
159 // Now I need to pushBack in all the TTVC components
160 (pushBackTTVCComponent<Comps>(), ...);
161 }
162
163 void insertVertex(uint i, VertexType* v) requires (NV < 0)
164 {
165 VRefs::insertVertex(i, v);
166
167 // Now I need to insert in all the TTVC components
168 (insertTTVCComponent<Comps>(i), ...);
169 }
170
171 void insertVertex(uint i, uint vi) requires (NV < 0)
172 {
173 VRefs::insertVertex(i, vi);
174
175 // Now I need to insert in all the TTVC components
176 (insertTTVCComponent<Comps>(i), ...);
177 }
178
179 void eraseVertex(uint i) requires (NV < 0)
180 {
181 VRefs::eraseVertex(i);
182
183 // Now I need to erase in all the TTVC components
184 (eraseTTVCComponent<Comps>(i), ...);
185 }
186
187 void clearVertices() requires (NV < 0)
188 {
189 VRefs::clearVertices();
190
191 // Now I need to clear all the TTVC components
192 (clearTTVCComponent<Comps>(), ...);
193 }
194
195 template<typename ElType>
196 void importFrom(const ElType& v, bool importRefs = true)
197 {
198 if constexpr (comp::HasVertexReferences<ElType> && NV < 0) {
199 VRefs::resizeVertices(v.vertexCount());
200 // Now I need to resize all the TTVC components
201 (resizeTTVCComponent<Comps>(v.vertexCount()), ...);
202 }
203
204 Base::importFrom(v, importRefs);
205 }
206
207private:
212 template<typename Comp>
214 {
215 if constexpr (comp::IsTiedToVertexCount<Comp>) {
216 if (Comp::isAvailable())
217 Comp::resize(n);
218 }
219 }
220
225 template<typename Comp>
227 {
228 if constexpr (comp::IsTiedToVertexCount<Comp>) {
229 if (Comp::isAvailable())
230 Comp::pushBack();
231 }
232 }
233
238 template<typename Comp>
240 {
241 if constexpr (comp::IsTiedToVertexCount<Comp>) {
242 if (Comp::isAvailable())
243 Comp::insert(i);
244 }
245 }
246
251 template<typename Comp>
253 {
254 if constexpr (comp::IsTiedToVertexCount<Comp>) {
255 if (Comp::isAvailable())
256 Comp::erase(i);
257 }
258 }
259
264 template<typename Comp>
266 {
267 if constexpr (comp::IsTiedToVertexCount<Comp>) {
268 if (Comp::isAvailable())
269 Comp::clear();
270 }
271 }
272};
273
274template<typename MeshType, comp::ComponentConcept... Comps>
275class Face<MeshType, TypeWrapper<Comps...>> : public Face<MeshType, Comps...>
276{
277};
278
279/* Concepts */
280
301template<typename T>
302concept FaceConcept =
303 IsDerivedFromSpecializationOfV<T, Face> &&
304 RemoveRef<T>::ELEMENT_ID == ElemId::FACE && face::HasBitFlags<T> &&
306 (RemoveRef<T>::VERTEX_COUNT < 0 || RemoveRef<T>::VERTEX_COUNT >= 3) &&
307 (!face::HasTriangleBitFlags<T> || RemoveRef<T>::VERTEX_COUNT == 3) &&
310
311template<typename T>
312concept TriangleFaceConcept = RemoveRef<T>::VERTEX_COUNT == 3 && FaceConcept<T>;
313
323template<typename T>
324concept PolygonFaceConcept = RemoveRef<T>::VERTEX_COUNT < 0 && FaceConcept<T>;
325
326} // namespace vcl
327
328#endif // VCL_MESH_ELEMENTS_FACE_H
The Element class.
Definition element.h:75
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:48
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:139
void eraseTTVCComponent(uint i)
Definition face.h:252
void setVertices(Rng &&r)
Sets all the Vertices to the face.
Definition face.h:91
Face()=default
Empty constructor.
void resizeTTVCComponent(uint n)
Definition face.h:213
void pushBackTTVCComponent()
Definition face.h:226
void insertTTVCComponent(uint i)
Definition face.h:239
void setVertices(V... args)
Sets a list of Vertices to the face.
Definition face.h:117
void clearTTVCComponent()
Definition face.h:265
friend void swap(Face &a, Face &b)
Swap function that delegates to the base Element swap.
Definition face.h:74
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
A concept that checks whether a class has (inherits from) an Face class.
Definition face.h:302
Utility concept that is evaluated true the Range R is an Input Range and has a value_type that is con...
Definition range.h:99
A concpet that checks whether a class has (inherits from) a Face class and that the Face is polygonal...
Definition face.h:324
Definition face.h:312
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:714
SanityCheckAdjacentFaces concept.
Definition adjacent_faces.h:716
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