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/base.h>
30#include <vclib/space/core.h>
31
32namespace vcl::comp {
33
73template<
74 typename Scalar,
75 int N,
76 typename ParentElemType = void,
77 bool OPT = false>
79 public ContainerComponent<
80 WedgeTexCoords<Scalar, N, ParentElemType, OPT>,
81 CompId::WEDGE_TEX_COORDS,
82 vcl::TexCoord<Scalar>,
83 N,
84 void,
85 ParentElemType,
86 !std::is_same_v<ParentElemType, void>,
87 OPT,
88 true>
89{
90 using Base = ContainerComponent<
92 CompId::WEDGE_TEX_COORDS,
94 N,
95 void,
97 !std::is_same_v<ParentElemType, void>,
98 OPT,
99 true>;
100
101public:
106
107 /* Iterator Types declaration */
108
109 using WedgeTexCoordsIterator = Vector<vcl::TexCoord<Scalar>, N>::Iterator;
110 using ConstWedgeTexCoordsIterator =
111 Vector<vcl::TexCoord<Scalar>, N>::ConstIterator;
112
113 static const int WEDGE_TEX_COORD_NUMBER = N;
114
115 /* Constructors */
116
124 WedgeTexCoords() = default;
125
126 /* Member functions */
127
141 vcl::TexCoord<Scalar>& wedgeTexCoord(uint i) { return texCoords().at(i); }
142
152 {
153 return texCoords().at(i);
154 }
155
173 {
174 return texCoords().atMod(i);
175 }
176
184 {
185 return texCoords().atMod(i);
186 }
187
196 {
197 texCoords().set(i, t);
198 }
199
211 template<Range Rng>
214 {
215 texCoords().set(r);
216 }
217
218 /* Iterator Member functions */
219
226 WedgeTexCoordsIterator wedgeTexCoordBegin() { return texCoords().begin(); }
227
233 WedgeTexCoordsIterator wedgeTexCoordEnd() { return texCoords().end(); }
234
241 ConstWedgeTexCoordsIterator wedgeTexCoordBegin() const
242 {
243 return texCoords().begin();
244 }
245
252 ConstWedgeTexCoordsIterator wedgeTexCoordEnd() const
253 {
254 return texCoords().end();
255 }
256
277
298
299 // dummy member to discriminate between WedgeTexCoords and
300 // FaceHalfEdgePointers
301 void __wedgeTexCoords() const {}
302
303protected:
304 using WedgeTexCoordScalarType = Scalar;
305
306 // Component interface functions
307 template<typename Element>
308 void importFrom(const Element& e, bool = true);
309
310 void serialize(std::ostream& os) const { texCoords().serialize(os); }
311
312 void deserialize(std::istream& is) { texCoords().deserialize(is); }
313
314 // ContainerComponent interface functions
315 void resize(uint n) requires (N < 0) { texCoords().resize(n); }
316
317 void pushBack(const vcl::TexCoord<Scalar>& t = vcl::TexCoord<Scalar>())
318 requires (N < 0)
319 {
320 texCoords().pushBack(t);
321 }
322
323 void insert(
324 uint i,
326 requires (N < 0)
327 {
328 texCoords().insert(i, t);
329 }
330
331 void erase(uint i) requires (N < 0) { texCoords().erase(i); }
332
333 void clear() requires (N < 0) { texCoords().clear(); }
334
335private:
336 template<typename Element>
337 void importWedgeTexCoordsFrom(const Element& e)
338 {
339 for (uint i = 0; i < e.vertexNumber(); ++i) {
340 wedgeTexCoord(i) = e.wedgeTexCoord(i).template cast<Scalar>();
341 }
342 }
343
344 Vector<vcl::TexCoord<Scalar>, N>& texCoords() { return Base::container(); }
345
346 const Vector<vcl::TexCoord<Scalar>, N>& texCoords() const
347 {
348 return Base::container();
349 }
350};
351
352/* concepts */
353
371template<typename T>
373 TITB::IsDerivedFromSpecializationOfV<T, WedgeTexCoords>;
374
385template<typename T>
389
400template<typename T>
402 RemoveRef<T>::VERTEX_NUMBER == RemoveRef<T>::WEDGE_TEX_COORD_NUMBER;
403
416template<typename T>
419
420/* importFrom function */
421
422template<typename Scalar, int N, typename ParentElemType, bool OPT>
423template<typename Element>
424void WedgeTexCoords<Scalar, N, ParentElemType, OPT>::importFrom(
425 const Element& e,
426 bool)
427{
428 if constexpr (HasWedgeTexCoords<Element>) {
429 if (isWedgeTexCoordsAvailableOn(e)) {
430 if constexpr (N > 0) {
431 // same static size
432 if constexpr (N == Element::WEDGE_TEX_COORD_NUMBER) {
433 importWedgeTexCoordsFrom(e);
434 }
435 // from dynamic to static, but dynamic size == static size
436 else if constexpr (Element::WEDGE_TEX_COORD_NUMBER < 0) {
437 if (e.vertexNumber() == N) {
438 importWedgeTexCoordsFrom(e);
439 }
440 }
441 else {
442 // do not import in this case: cannot import from
443 // dynamic size != static size
444 }
445 }
446 else {
447 // from static/dynamic to dynamic size: need to resize
448 // first, then import
449 resize(e.vertexNumber());
450 importWedgeTexCoordsFrom(e);
451 }
452 }
453 }
454}
455
456/* Detector function to check if a class has WedgeTexCoords available */
457
469bool isWedgeTexCoordsAvailableOn(const auto& element)
470{
472}
473
474} // namespace vcl::comp
475
476#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:89
WedgeTexCoordsIterator wedgeTexCoordEnd()
Returns an iterator to the end of the container of this component.
Definition wedge_tex_coords.h:233
vcl::TexCoord< Scalar > & wedgeTexCoord(uint i)
Returns a reference to the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:141
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:172
WedgeTexCoords()=default
Empty constructor.
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:294
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:273
WedgeTexCoordsIterator wedgeTexCoordBegin()
Returns an iterator to the first wedge texcoord in the container of this component.
Definition wedge_tex_coords.h:226
ConstWedgeTexCoordsIterator wedgeTexCoordEnd() const
Returns a const iterator to the end of the container of this component.
Definition wedge_tex_coords.h:252
void setWedgeTexCoords(Rng &&r)
Sets all the wedge texcoords of the element.
Definition wedge_tex_coords.h:212
ConstWedgeTexCoordsIterator wedgeTexCoordBegin() const
Returns a const iterator to the first wedge texcoord in the container of this component.
Definition wedge_tex_coords.h:241
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:151
const vcl::TexCoord< Scalar > & wedgeTexCoordMod(int i) const
Same of wedgeTexCoordMod(int) but returns a const reference.
Definition wedge_tex_coords.h:183
void setWedgeTexCoord(uint i, const vcl::TexCoord< Scalar > &t)
Sets the i-th wedge texcoord of the element.
Definition wedge_tex_coords.h:195
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:386
HasRightNumberOfWedgeTexCoords concept.
Definition wedge_tex_coords.h:401
A concept that checks whether a type T (that should be a Element) has the WedgeTexCoords component (i...
Definition wedge_tex_coords.h:372
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:417