Visual Computing Library
Loading...
Searching...
No Matches
tex_coord.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_TEX_COORD_H
24#define VCL_MESH_COMPONENTS_TEX_COORD_H
25
26#include "bases/component.h"
27
28#include <vclib/concepts/mesh/components/tex_coord.h>
29#include <vclib/space/core/tex_coord_indexed.h>
30
31namespace vcl::comp {
32
57template<typename Scalar, typename ParentElemType = void, bool OPT = false>
58class TexCoord :
59 public Component<
60 TexCoord<Scalar, ParentElemType, OPT>,
61 CompId::TEX_COORD,
62 vcl::TexCoordIndexed<Scalar>,
63 ParentElemType,
64 !std::is_same_v<ParentElemType, void>,
65 OPT>
66{
67 using Base = Component<
69 CompId::TEX_COORD,
72 !std::is_same_v<ParentElemType, void>,
73 OPT>;
74
75public:
80
81 /* Constructors */
82
86 TexCoord() = default;
87
88 /* Member functions */
89
94 const TexCoordType& texCoord() const { return Base::data(); }
95
100 TexCoordType& texCoord() { return Base::data(); }
101
102protected:
103 // Component interface functions
104 template<typename Element>
105 void importFrom(const Element& e, bool = true)
106 {
107 if constexpr (HasTexCoord<Element>) {
108 if (isTexCoordAvailableOn(e)) {
109 texCoord() = e.texCoord().template cast<Scalar>();
110 }
111 }
112 }
113
114 void serialize(std::ostream& os) const { texCoord().serialize(os); }
115
116 void deserialize(std::istream& is) { texCoord().deserialize(is); }
117};
118
119/* Detector function to check if a class has TexCoord available */
120
134bool isTexCoordAvailableOn(const ElementConcept auto& element)
135{
136 return isComponentAvailableOn<CompId::TEX_COORD>(element);
137}
138
139/* Specialization Aliases */
140
153template<typename ElementType = void, bool OPT = false>
155
168template<typename ElementType = void, bool OPT = false>
170
171} // namespace vcl::comp
172
173#endif // VCL_MESH_COMPONENTS_TEX_COORD_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 TexCoord class represents a component that stores a texture coordinate.
Definition tex_coord.h:66
TexCoordType & texCoord()
Returns a reference of the tex coord of the element.
Definition tex_coord.h:100
const TexCoordType & texCoord() const
Returns a const reference of the tex coord of the element.
Definition tex_coord.h:94
TexCoord()=default
Initilizes the Texture Coordinate to (0, 0).
HasTexCoord concept is satisfied only if a Element class provides the types and member functions spec...
Definition tex_coord.h:47