Visual Computing Library
Loading...
Searching...
No Matches
wedge_tex_coords.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_WEDGE_TEX_COORDS_H
24#define VCL_MESH_COMPONENTS_WEDGE_TEX_COORDS_H
25
26#include "bases/container_component.h"
27
28#include <vclib/concepts/mesh/components/tex_coord.h>
29#include <vclib/concepts/mesh/components/wedge_tex_coords.h>
30#include <vclib/space/core/tex_coord.h>
31#include <vclib/space/core/vector.h>
32#include <vclib/types/view.h>
33
34namespace vcl::comp {
35
77template<
78 typename Scalar,
79 int N,
80 typename ParentElemType = void,
81 bool OPT = false>
83 public ContainerComponent<
84 WedgeTexCoords<Scalar, N, ParentElemType, OPT>,
85 CompId::WEDGE_TEX_COORDS,
86 vcl::TexCoord<Scalar>,
87 N,
88 ushort,
89 ParentElemType,
90 !std::is_same_v<ParentElemType, void>,
91 OPT,
92 true>
93{
96 CompId::WEDGE_TEX_COORDS,
98 N,
99 ushort,
101 !std::is_same_v<ParentElemType, void>,
102 OPT,
103 true>;
104
105public:
110
111 /* Iterator Types declaration */
112
113 using WedgeTexCoordsIterator = Vector<vcl::TexCoord<Scalar>, N>::Iterator;
114 using ConstWedgeTexCoordsIterator =
115 Vector<vcl::TexCoord<Scalar>, N>::ConstIterator;
116
117 static const int WEDGE_TEX_COORD_NUMBER = N;
118
119 /* Constructors */
120
128 WedgeTexCoords() = default;
129
130 /* Member functions */
131
145 vcl::TexCoord<Scalar>& wedgeTexCoord(uint i) { return texCoords().at(i); }
146
156 {
157 return texCoords().at(i);
158 }
159
177 {
178 return texCoords().atMod(i);
179 }
180
188 {
189 return texCoords().atMod(i);
190 }
191
200 {
201 texCoords().set(i, t);
202 }
203
215 template<Range Rng>
218 {
219 texCoords().set(r);
220 }
221
228 ushort& textureIndex() { return Base::additionalData(); }
229
236 ushort textureIndex() const { return Base::additionalData(); }
237
238 /* Iterator Member functions */
239
246 WedgeTexCoordsIterator wedgeTexCoordBegin() { return texCoords().begin(); }
247
253 WedgeTexCoordsIterator wedgeTexCoordEnd() { return texCoords().end(); }
254
261 ConstWedgeTexCoordsIterator wedgeTexCoordBegin() const
262 {
263 return texCoords().begin();
264 }
265
272 ConstWedgeTexCoordsIterator wedgeTexCoordEnd() const
273 {
274 return texCoords().end();
275 }
276
297
318
319 // dummy member to discriminate between WedgeTexCoords and
320 // FaceHalfEdgePointers
321 void __wedgeTexCoords() const {}
322
323protected:
324 using WedgeTexCoordScalarType = Scalar;
325
326 // Component interface functions
327 template<typename Element>
328 void importFrom(const Element& e, bool = true)
329 {
330 if constexpr (HasWedgeTexCoords<Element>) {
331 if (isWedgeTexCoordsAvailableOn(e)) {
332 if constexpr (N > 0) {
333 // same static size
334 if constexpr (N == Element::WEDGE_TEX_COORD_NUMBER) {
335 importWedgeTexCoordsFrom(e);
336 }
337 // from dynamic to static, but dynamic size == static size
338 else if constexpr (Element::WEDGE_TEX_COORD_NUMBER < 0) {
339 if (e.vertexNumber() == N) {
340 importWedgeTexCoordsFrom(e);
341 }
342 }
343 else {
344 // do not import in this case: cannot import from
345 // dynamic size != static size
346 }
347 }
348 else {
349 // from static/dynamic to dynamic size: need to resize
350 // first, then import
351 resize(e.vertexNumber());
352 importWedgeTexCoordsFrom(e);
353 }
354 }
355 }
356 }
357
358 void serialize(std::ostream& os) const
359 {
360 texCoords().serialize(os);
361 vcl::serialize(os, textureIndex());
362 }
363
364 void deserialize(std::istream& is)
365 {
366 texCoords().deserialize(is);
367 vcl::deserialize(is, textureIndex());
368 }
369
370 // ContainerComponent interface functions
371 void resize(uint n) requires (N < 0) { texCoords().resize(n); }
372
373 void pushBack(const vcl::TexCoord<Scalar>& t = vcl::TexCoord<Scalar>())
374 requires (N < 0)
375 {
376 texCoords().pushBack(t);
377 }
378
379 void insert(
380 uint i,
382 requires (N < 0)
383 {
384 texCoords().insert(i, t);
385 }
386
387 void erase(uint i) requires (N < 0) { texCoords().erase(i); }
388
389 void clear() requires (N < 0) { texCoords().clear(); }
390
391private:
392 template<typename Element>
393 void importWedgeTexCoordsFrom(const Element& e)
394 {
395 for (uint i = 0; i < e.vertexNumber(); ++i) {
396 wedgeTexCoord(i) = e.wedgeTexCoord(i).template cast<Scalar>();
397 }
398 textureIndex() = e.textureIndex();
399 }
400
401 Vector<vcl::TexCoord<Scalar>, N>& texCoords() { return Base::container(); }
402
403 const Vector<vcl::TexCoord<Scalar>, N>& texCoords() const
404 {
405 return Base::container();
406 }
407};
408
409/* Detector function to check if a class has WedgeTexCoords available */
410
423bool isWedgeTexCoordsAvailableOn(const ElementConcept auto& element)
424{
425 return isComponentAvailableOn<CompId::WEDGE_TEX_COORDS>(element);
426}
427
428} // namespace vcl::comp
429
430#endif // VCL_MESH_COMPONENTS_WEDGE_TEX_COORDS_H
The Element class.
Definition element.h:57
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The View class is a simple class that stores and exposes two iterators begin and end.
Definition view.h:67
The ContainerComponent class is the base class for all the components of VCLib that store a container...
Definition container_component.h:130
The WedgeTexCoords class is a container of texture coordinates associated to the wedges of a Face ele...
Definition wedge_tex_coords.h:93
WedgeTexCoordsIterator wedgeTexCoordEnd()
Returns an iterator to the end of the container of this component.
Definition wedge_tex_coords.h:253
vcl::TexCoord< Scalar > & wedgeTexCoord(uint i)
Returns a reference to the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:145
vcl::TexCoord< Scalar > & wedgeTexCoordMod(int i)
Returns a reference to the i-th wedge texcoord of the element but using as index the module between i...
Definition wedge_tex_coords.h:176
ushort & textureIndex()
Returns a reference to the texture index used to identify the texture on which the wedge texture coor...
Definition wedge_tex_coords.h:228
WedgeTexCoords()=default
Empty constructor.
ushort textureIndex() const
Returns the texture index used to identify the texture on which the wedge texture coordinates are map...
Definition wedge_tex_coords.h:236
View< ConstWedgeTexCoordsIterator > wedgeTexCoords() const
Returns a lightweight const view object that stores the begin and end iterators of the container of w...
Definition wedge_tex_coords.h:314
View< WedgeTexCoordsIterator > wedgeTexCoords()
Returns a lightweight view object that stores the begin and end iterators of the container of wedge t...
Definition wedge_tex_coords.h:293
WedgeTexCoordsIterator wedgeTexCoordBegin()
Returns an iterator to the first wedge texcoord in the container of this component.
Definition wedge_tex_coords.h:246
ConstWedgeTexCoordsIterator wedgeTexCoordEnd() const
Returns a const iterator to the end of the container of this component.
Definition wedge_tex_coords.h:272
void setWedgeTexCoords(Rng &&r)
Sets all the wedge texcoords of the element.
Definition wedge_tex_coords.h:216
ConstWedgeTexCoordsIterator wedgeTexCoordBegin() const
Returns a const iterator to the first wedge texcoord in the container of this component.
Definition wedge_tex_coords.h:261
const vcl::TexCoord< Scalar > & wedgeTexCoord(uint i) const
Returns a const reference to the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:155
const vcl::TexCoord< Scalar > & wedgeTexCoordMod(int i) const
Same of wedgeTexCoordMod(int) but returns a const reference.
Definition wedge_tex_coords.h:187
void setWedgeTexCoord(uint i, const vcl::TexCoord< Scalar > &t)
Sets the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:199
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