Skip to content

Commit a9ca363

Browse files
committed
[space] Add TexCoordIndexed class
1 parent 8616f9b commit a9ca363

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

vclib/core/include/vclib/space/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "core/segment.h"
3838
#include "core/sphere.h"
3939
#include "core/tex_coord.h"
40+
#include "core/tex_coord_indexed.h"
4041
#include "core/texture.h"
4142
#include "core/triangle_wrapper.h"
4243
#include "core/vector.h"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
28+
namespace vcl {
29+
30+
/**
31+
* @brief The TexCoordIndexed class represents a texture coordinate with an
32+
* index.
33+
*
34+
* The TexCoordIndexed class represents a texture coordinate with an index. The
35+
* class is a specialization of the TexCoord class template, where the two
36+
* components of the texture coordinate are named `u` and `v`. The class adds
37+
* an index member variable that represents the index of the texture coordinate.
38+
*
39+
* @tparam Scalar: The scalar type of the texture coordinate components.
40+
*
41+
* @ingroup space_core
42+
*/
43+
template<typename Scalar>
44+
class TexCoordIndexed : public TexCoord<Scalar>
45+
{
46+
using Base = TexCoord<Scalar>;
47+
48+
ushort mIndex = 0;
49+
50+
public:
51+
using Base::Base;
52+
53+
using Base::operator();
54+
using Base::operator[];
55+
56+
TexCoordIndexed() = default;
57+
58+
TexCoordIndexed(const Base& base, ushort index) : Base(base), mIndex(index)
59+
{
60+
}
61+
62+
TexCoordIndexed(const Scalar& s1, const Scalar& s2, ushort index) :
63+
Base(s1, s2), mIndex(index)
64+
{
65+
}
66+
67+
TexCoordIndexed(const Point2<Scalar>& p, ushort index) :
68+
Base(p), mIndex(index)
69+
{
70+
}
71+
72+
template<typename S>
73+
auto cast() const
74+
{
75+
if constexpr (std::is_same<Scalar, S>::value) {
76+
return *this;
77+
}
78+
else {
79+
TexCoordIndexed<S> tmp = Base::template cast<S>();
80+
tmp.mIndex = mIndex;
81+
return tmp;
82+
}
83+
}
84+
85+
ushort index() const { return mIndex; }
86+
87+
ushort& index() { return mIndex; }
88+
89+
void serialize(std::ostream& os) const
90+
{
91+
Base::serialize(os);
92+
vcl::serialize(os, mIndex);
93+
}
94+
95+
void deserialize(std::istream& is)
96+
{
97+
Base::deserialize(is);
98+
vcl::deserialize(is, mIndex);
99+
}
100+
101+
// operators
102+
auto operator<=>(const TexCoordIndexed& t1) const = default;
103+
};
104+
105+
} // namespace vcl
106+
107+
#endif // VCL_SPACE_CORE_TEX_COORD_INDEXED_H

0 commit comments

Comments
 (0)