Visual Computing Library
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 "element.h"
27
28#include <vclib/concepts/mesh/elements/face.h>
29#include <vclib/concepts/ranges/range.h>
30#include <vclib/types/view.h>
31
32namespace vcl {
33
47template<typename MeshType, typename... Comps>
48class Face : public Element<ElemId::FACE, MeshType, Comps...>
49{
50 using Base = Element<ElemId::FACE, MeshType, Comps...>;
51
52 // VertexPointers or VertexIndices component of the Face
53 using VRefs = typename Face::VertexReferences;
54
55 static const int NV = VRefs::VERTEX_NUMBER; // If dynamic, NV will be -1
56
57public:
58 using VertexType = typename VRefs::VertexType;
59
67 Face() = default;
68
84 template<Range Rng>
87 {
88 using F = Face<MeshType, TypeWrapper<Comps...>>;
89
90 VRefs::setVertices(r);
91
92 // if polygonal, I need to resize all the TTVN components
93 if constexpr (NV < 0) {
94 (resizeTTVNComponent<Comps>(std::ranges::size(r)), ...);
95 }
96 }
97
112 template<typename... V>
113 void setVertices(V... args) requires (
114 (std::convertible_to<V, VertexType*> || std::convertible_to<V, uint>) &&
115 ...)
116 {
117 setVertices(std::list({args...}));
118 }
119
136 {
137 VRefs::resizeVertices(n);
138
139 // Now I need to resize all the TTVN components
141 }
142
143 void pushVertex(VertexType* v) requires PolygonFaceConcept<Face>
144 {
145 VRefs::pushVertex(v);
146
147 // Now I need to pushBack in all the TTVN components
149 }
150
151 void pushVertex(uint vi) requires PolygonFaceConcept<Face>
152 {
153 VRefs::pushVertex(vi);
154
155 // Now I need to pushBack in all the TTVN components
156 (pushBackTTVNComponent<Comps>(), ...);
157 }
158
159 void insertVertex(uint i, VertexType* v) requires PolygonFaceConcept<Face>
160 {
161 VRefs::insertVertex(i, v);
162
163 // Now I need to insert in all the TTVN components
164 (insertTTVNComponent<Comps>(i), ...);
165 }
166
167 void insertVertex(uint i, uint vi) requires PolygonFaceConcept<Face>
168 {
169 VRefs::insertVertex(i, vi);
170
171 // Now I need to insert in all the TTVN components
172 (insertTTVNComponent<Comps>(i), ...);
173 }
174
175 void eraseVertex(uint i) requires PolygonFaceConcept<Face>
176 {
177 VRefs::eraseVertex(i);
178
179 // Now I need to erase in all the TTVN components
180 (eraseTTVNComponent<Comps>(i), ...);
181 }
182
183 void clearVertices() requires PolygonFaceConcept<Face>
184 {
185 VRefs::clearVertices();
186
187 // Now I need to clear all the TTVN components
188 (clearTTVNComponent<Comps>(), ...);
189 }
190
191 template<typename ElType>
192 void importFrom(const ElType& v, bool importRefs = true)
193 {
194 if constexpr (comp::HasVertexReferences<ElType> && NV < 0) {
195 VRefs::resizeVertices(v.vertexNumber());
196 // Now I need to resize all the TTVN components
197 (resizeTTVNComponent<Comps>(v.vertexNumber()), ...);
198 }
199
200 Base::importFrom(v, importRefs);
201 }
202
203private:
208 template<typename Comp>
210 {
211 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
212 if (Comp::isAvailable())
213 Comp::resize(n);
214 }
215 }
216
221 template<typename Comp>
223 {
224 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
225 if (Comp::isAvailable())
226 Comp::pushBack();
227 }
228 }
229
234 template<typename Comp>
236 {
237 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
238 if (Comp::isAvailable())
239 Comp::insert(i);
240 }
241 }
242
247 template<typename Comp>
249 {
250 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
251 if (Comp::isAvailable())
252 Comp::erase(i);
253 }
254 }
255
260 template<typename Comp>
262 {
263 if constexpr (comp::IsTiedToVertexNumber<Comp>) {
264 if (Comp::isAvailable())
265 Comp::clear();
266 }
267 }
268};
269
270template<typename MeshType, typename... Comps>
271class Face<MeshType, TypeWrapper<Comps...>> : public Face<MeshType, Comps...>
272{
273};
274
275} // namespace vcl
276
277#endif // VCL_MESH_ELEMENTS_FACE_H
The Element class.
Definition element.h:57
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:49
void eraseTTVNComponent(uint i)
Definition face.h:248
void setVertices(Rng &&r)
Sets all the Vertices to the face.
Definition face.h:85
Face()=default
Empty constructor.
void clearTTVNComponent()
Definition face.h:261
void pushBackTTVNComponent()
Definition face.h:222
void insertTTVNComponent(uint i)
Definition face.h:235
void setVertices(V... args)
Sets a list of Vertices to the face.
Definition face.h:113
void resizeTTVNComponent(uint n)
Definition face.h:209
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:135
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
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
The PolygonFaceConcept describes how a Face element class should be organized to be a polygonal face ...
Definition face.h:149
Evaluates to true if the type T is tied to the number of vertices in the face.
Definition component.h:124
A simple structure that wraps a list of variadic templates, without instantiating anything....
Definition type_wrapper.h:41