Visual Computing Library  devel
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 "base/container_component.h"
27#include "base/predicates.h"
28
29#include <vclib/space/core.h>
30#include <vclib/base.h>
31
32namespace vcl::comp {
33
75template<
76 typename Scalar,
77 int N,
78 typename ParentElemType = void,
79 bool OPT = false>
81 public ContainerComponent<
82 WedgeTexCoords<Scalar, N, ParentElemType, OPT>,
83 CompId::WEDGE_TEX_COORDS,
84 vcl::TexCoord<Scalar>,
85 N,
86 ushort,
87 ParentElemType,
88 !std::is_same_v<ParentElemType, void>,
89 OPT,
90 true>
91{
92 using Base = ContainerComponent<
94 CompId::WEDGE_TEX_COORDS,
96 N,
97 ushort,
99 !std::is_same_v<ParentElemType, void>,
100 OPT,
101 true>;
102
103public:
108
109 /* Iterator Types declaration */
110
111 using WedgeTexCoordsIterator = Vector<vcl::TexCoord<Scalar>, N>::Iterator;
112 using ConstWedgeTexCoordsIterator =
113 Vector<vcl::TexCoord<Scalar>, N>::ConstIterator;
114
115 static const int WEDGE_TEX_COORD_NUMBER = N;
116
117 /* Constructors */
118
126 WedgeTexCoords() = default;
127
128 /* Member functions */
129
143 vcl::TexCoord<Scalar>& wedgeTexCoord(uint i) { return texCoords().at(i); }
144
154 {
155 return texCoords().at(i);
156 }
157
175 {
176 return texCoords().atMod(i);
177 }
178
186 {
187 return texCoords().atMod(i);
188 }
189
198 {
199 texCoords().set(i, t);
200 }
201
213 template<Range Rng>
216 {
217 texCoords().set(r);
218 }
219
227
235
236 /* Iterator Member functions */
237
244 WedgeTexCoordsIterator wedgeTexCoordBegin() { return texCoords().begin(); }
245
251 WedgeTexCoordsIterator wedgeTexCoordEnd() { return texCoords().end(); }
252
259 ConstWedgeTexCoordsIterator wedgeTexCoordBegin() const
260 {
261 return texCoords().begin();
262 }
263
270 ConstWedgeTexCoordsIterator wedgeTexCoordEnd() const
271 {
272 return texCoords().end();
273 }
274
295
316
317 // dummy member to discriminate between WedgeTexCoords and
318 // FaceHalfEdgePointers
319 void __wedgeTexCoords() const {}
320
321protected:
322 using WedgeTexCoordScalarType = Scalar;
323
324 // Component interface functions
325 template<typename Element>
326 void importFrom(const Element& e, bool = true);
327
328 void serialize(std::ostream& os) const
329 {
330 texCoords().serialize(os);
331 vcl::serialize(os, textureIndex());
332 }
333
334 void deserialize(std::istream& is)
335 {
336 texCoords().deserialize(is);
337 vcl::deserialize(is, textureIndex());
338 }
339
340 // ContainerComponent interface functions
341 void resize(uint n) requires (N < 0) { texCoords().resize(n); }
342
343 void pushBack(const vcl::TexCoord<Scalar>& t = vcl::TexCoord<Scalar>())
344 requires (N < 0)
345 {
346 texCoords().pushBack(t);
347 }
348
349 void insert(
350 uint i,
352 requires (N < 0)
353 {
354 texCoords().insert(i, t);
355 }
356
357 void erase(uint i) requires (N < 0) { texCoords().erase(i); }
358
359 void clear() requires (N < 0) { texCoords().clear(); }
360
361private:
362 template<typename Element>
363 void importWedgeTexCoordsFrom(const Element& e)
364 {
365 for (uint i = 0; i < e.vertexNumber(); ++i) {
366 wedgeTexCoord(i) = e.wedgeTexCoord(i).template cast<Scalar>();
367 }
368 textureIndex() = e.textureIndex();
369 }
370
371 Vector<vcl::TexCoord<Scalar>, N>& texCoords() { return Base::container(); }
372
373 const Vector<vcl::TexCoord<Scalar>, N>& texCoords() const
374 {
375 return Base::container();
376 }
377};
378
379/* concepts */
380
398template<typename T>
400 TITB::IsDerivedFromSpecializationOfV<T, WedgeTexCoords>;
401
412template<typename T>
416
427template<typename T>
429 RemoveRef<T>::VERTEX_NUMBER == RemoveRef<T>::WEDGE_TEX_COORD_NUMBER;
430
443template<typename T>
446
447/* importFrom function */
448
449template<typename Scalar, int N, typename ParentElemType, bool OPT>
450template<typename Element>
451void WedgeTexCoords<Scalar, N, ParentElemType, OPT>::importFrom(
452 const Element& e,
453 bool)
454{
455 if constexpr (HasWedgeTexCoords<Element>) {
456 if (isWedgeTexCoordsAvailableOn(e)) {
457 if constexpr (N > 0) {
458 // same static size
459 if constexpr (N == Element::WEDGE_TEX_COORD_NUMBER) {
460 importWedgeTexCoordsFrom(e);
461 }
462 // from dynamic to static, but dynamic size == static size
463 else if constexpr (Element::WEDGE_TEX_COORD_NUMBER < 0) {
464 if (e.vertexNumber() == N) {
465 importWedgeTexCoordsFrom(e);
466 }
467 }
468 else {
469 // do not import in this case: cannot import from
470 // dynamic size != static size
471 }
472 }
473 else {
474 // from static/dynamic to dynamic size: need to resize
475 // first, then import
476 resize(e.vertexNumber());
477 importWedgeTexCoordsFrom(e);
478 }
479 }
480 }
481}
482
483/* Detector function to check if a class has WedgeTexCoords available */
484
496bool isWedgeTexCoordsAvailableOn(const auto& element)
497{
499}
500
501} // namespace vcl::comp
502
503#endif // VCL_MESH_COMPONENTS_WEDGE_TEX_COORDS_H
A class representing a box in N-dimensional space.
Definition box.h:46
void deserialize(std::istream &is)
Deserializes the box from the given input stream.
Definition box.h:476
Box()
The Empty constructor of a box, initializes a null box.
Definition box.h:65
void serialize(std::ostream &os) const
Serializes the box to the given output stream.
Definition box.h:466
The Element class.
Definition element.h:75
The View class is a simple class that stores and exposes two iterators begin and end.
Definition view.h:67
The WedgeTexCoords class is a container of texture coordinates associated to the wedges of a Face ele...
Definition wedge_tex_coords.h:91
WedgeTexCoordsIterator wedgeTexCoordEnd()
Returns an iterator to the end of the container of this component.
Definition wedge_tex_coords.h:251
vcl::TexCoord< Scalar > & wedgeTexCoord(uint i)
Returns a reference to the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:143
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:174
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:226
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:234
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:312
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:291
WedgeTexCoordsIterator wedgeTexCoordBegin()
Returns an iterator to the first wedge texcoord in the container of this component.
Definition wedge_tex_coords.h:244
ConstWedgeTexCoordsIterator wedgeTexCoordEnd() const
Returns a const iterator to the end of the container of this component.
Definition wedge_tex_coords.h:270
void setWedgeTexCoords(Rng &&r)
Sets all the wedge texcoords of the element.
Definition wedge_tex_coords.h:214
ConstWedgeTexCoordsIterator wedgeTexCoordBegin() const
Returns a const iterator to the first wedge texcoord in the container of this component.
Definition wedge_tex_coords.h:259
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:153
const vcl::TexCoord< Scalar > & wedgeTexCoordMod(int i) const
Same of wedgeTexCoordMod(int) but returns a const reference.
Definition wedge_tex_coords.h:185
void setWedgeTexCoord(uint i, const vcl::TexCoord< Scalar > &t)
Sets the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:197
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 concept that checks whether a type T (that should be a Element) has the WedgeTexCoords component (i...
Definition wedge_tex_coords.h:413
HasRightNumberOfWedgeTexCoords concept.
Definition wedge_tex_coords.h:428
A concept that checks whether a type T (that should be a Element) has the WedgeTexCoords component (i...
Definition wedge_tex_coords.h:399
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74
SanityCheckWedgeTexCoords concept.
Definition wedge_tex_coords.h:444