Visual Computing Library
Loading...
Searching...
No Matches
tex_coord_indexed.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_SPACE_CORE_TEX_COORD_INDEXED_H
24#define VCL_SPACE_CORE_TEX_COORD_INDEXED_H
25
26#include "tex_coord.h"
27
28namespace vcl {
29
43template<typename Scalar>
44class TexCoordIndexed : public TexCoord<Scalar>
45{
46 template<typename S>
47 friend class TexCoordIndexed;
48
49 using Base = TexCoord<Scalar>;
50
51 ushort mIndex = 0;
52
53public:
54 using Base::Base;
55 using Base::set;
56
57 using Base::operator();
58 using Base::operator[];
59
60 TexCoordIndexed() = default;
61
62 TexCoordIndexed(const Base& base, ushort index) : Base(base), mIndex(index)
63 {
64 }
65
66 TexCoordIndexed(const Scalar& s1, const Scalar& s2, ushort index) :
67 Base(s1, s2), mIndex(index)
68 {
69 }
70
71 TexCoordIndexed(const Point2<Scalar>& p, ushort index) :
72 Base(p), mIndex(index)
73 {
74 }
75
76 template<typename S>
77 auto cast() const
78 {
79 if constexpr (std::is_same<Scalar, S>::value) {
80 return *this;
81 }
82 else {
83 TexCoordIndexed<S> tmp(Base::template cast<S>(), mIndex);
84 return tmp;
85 }
86 }
87
88 ushort index() const { return mIndex; }
89
90 ushort& index() { return mIndex; }
91
92 void set(const Scalar& s1, const Scalar& s2, ushort index)
93 {
94 Base::set(s1, s2);
95 mIndex = index;
96 }
97
98 void serialize(std::ostream& os) const
99 {
100 Base::serialize(os);
101 vcl::serialize(os, mIndex);
102 }
103
104 void deserialize(std::istream& is)
105 {
106 Base::deserialize(is);
107 vcl::deserialize(is, mIndex);
108 }
109
110 // operators
111 auto operator<=>(const TexCoordIndexed& t1) const = default;
112};
113
114/* Specialization Aliases */
115
119
120} // namespace vcl
121
122#endif // VCL_SPACE_CORE_TEX_COORD_INDEXED_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The TexCoordIndexed class represents a texture coordinate with an index.
Definition tex_coord_indexed.h:45
The TexCoord class represents a 2-dimensional texture coordinate containing two scalar values.
Definition tex_coord.h:51