Visual Computing Library  devel
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 "base/component.h"
27#include "base/predicates.h"
28
29#include <vclib/space/core.h>
30
31namespace vcl::comp {
32
56template<typename Scalar, typename ParentElemType = void, bool OPT = false>
57class TexCoord :
58 public Component<
59 TexCoord<Scalar, ParentElemType, OPT>,
60 CompId::TEX_COORD,
61 vcl::TexCoord<Scalar>,
62 ParentElemType,
63 !std::is_same_v<ParentElemType, void>,
64 OPT>
65{
66 using Base = Component<
68 CompId::TEX_COORD,
71 !std::is_same_v<ParentElemType, void>,
72 OPT>;
73
74public:
79
80 /* Constructors */
81
85 TexCoord() = default;
86
87 /* Member functions */
88
93 const TexCoordType& texCoord() const { return Base::data(); }
94
99 TexCoordType& texCoord() { return Base::data(); }
100
101protected:
102 // Component interface functions
103 template<typename Element>
104 void importFrom(const Element& e, bool = true);
105
106 void serialize(std::ostream& os) const { texCoord().serialize(os); }
107
108 void deserialize(std::istream& is) { texCoord().deserialize(is); }
109};
110
111/* concepts */
112
130template<typename T>
131concept HasTexCoord = TTB::IsDerivedFromSpecializationOfV<T, TexCoord>;
132
143template<typename T>
146
147/* importFrom function */
148
149template<typename Scalar, typename ParentElemType, bool OPT>
150template<typename Element>
151void TexCoord<Scalar, ParentElemType, OPT>::importFrom(const Element& e, bool)
152{
153 if constexpr (HasTexCoord<Element>) {
154 if (isTexCoordAvailableOn(e)) {
155 texCoord() = e.texCoord().template cast<Scalar>();
156 }
157 }
158}
159
160/* Detector function to check if a class has TexCoord available */
161
174bool isTexCoordAvailableOn(const auto& element)
175{
177}
178
179/* Specialization Aliases */
180
193template<typename ElementType = void, bool OPT = false>
195
208template<typename ElementType = void, bool OPT = false>
210
211} // namespace vcl::comp
212
213#endif // VCL_MESH_COMPONENTS_TEX_COORD_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
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 TexCoord class represents a component that stores a texture coordinate.
Definition tex_coord.h:65
TexCoordType & texCoord()
Returns a reference of the tex coord of the element.
Definition tex_coord.h:99
const TexCoordType & texCoord() const
Returns a const reference of the tex coord of the element.
Definition tex_coord.h:93
TexCoord()=default
Initilizes the Texture Coordinate to (0, 0).
A concept that checks whether a type T (that should be a Element) has the TexCoord component (inherit...
Definition tex_coord.h:144
A concept that checks whether a type T (that should be a Element) has the TexCoord component (inherit...
Definition tex_coord.h:131
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74