Visual Computing Library
Loading...
Searching...
No Matches
texture_paths.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_TEXTURE_PATHS_H
24#define VCL_MESH_COMPONENTS_TEXTURE_PATHS_H
25
26#include "bases/component.h"
27
28#include <vclib/concepts/mesh/components/texture_images.h>
29#include <vclib/concepts/mesh/components/texture_paths.h>
30#include <vclib/io/serialization.h>
31#include <vclib/types/view.h>
32
33#include <string>
34#include <vector>
35
36namespace vcl::comp {
37
38namespace detail {
39
40struct TPData
41{
42 std::vector<std::string> texPaths;
43 std::string meshPath;
44};
45
46} // namespace detail
47
74 public Component<
75 TexturePaths,
76 CompId::TEXTURE_PATHS,
77 detail::TPData,
78 void,
79 false,
80 false>
81{
82 using Base = Component<
84 CompId::TEXTURE_PATHS,
85 detail::TPData,
86 void,
87 false,
88 false>;
89
90public:
91 // iterators
92 using TexFileNamesIterator = std::vector<std::string>::iterator;
93 using ConstTexFileNamesIterator = std::vector<std::string>::const_iterator;
94
95 /* Constructors */
96
101 TexturePaths() = default;
102
103 /* Member functions */
104
108 uint textureNumber() const { return texPaths().size(); }
109
115 const std::string& texturePath(uint i) const { return texPaths()[i]; }
116
122 std::string& texturePath(uint i) { return texPaths()[i]; }
123
127 const std::string& meshBasePath() const { return Base::data().meshPath; }
128
132 std::string& meshBasePath() { return Base::data().meshPath; }
133
137 void clearTexturePaths() { texPaths().clear(); }
138
143 void pushTexturePath(const std::string& textName)
144 {
145 texPaths().push_back(textName);
146 }
147
153 TexFileNamesIterator texturePathBegin() { return texPaths().begin(); }
154
159 TexFileNamesIterator texturePathEnd() { return texPaths().end(); }
160
166 ConstTexFileNamesIterator texturePathBegin() const
167 {
168 return texPaths().begin();
169 }
170
176 ConstTexFileNamesIterator texturePathEnd() const
177 {
178 return texPaths().end();
179 }
180
201
221
222protected:
223 // Component interface functions
224 template<typename Element>
225 void importFrom(const Element& e, bool = true)
226 {
227 if constexpr (HasTexturePaths<Element>) {
228 texPaths().clear();
229 for (const auto& tex : e.textures()) {
230 texPaths().push_back(tex.path());
231 }
232 meshBasePath() = e.meshBasePath();
233 }
234 }
235
236 void serialize(std::ostream& os) const
237 {
238 vcl::serialize(os, texPaths());
239 vcl::serialize(os, meshBasePath());
240 }
241
242 void deserialize(std::istream& is)
243 {
244 vcl::deserialize(is, texPaths());
245 vcl::deserialize(is, meshBasePath());
246 }
247
248private:
249 // members that allow to access the data
250 std::vector<std::string>& texPaths() { return Base::data().texPaths; }
251
252 const std::vector<std::string>& texPaths() const
253 {
254 return Base::data().texPaths;
255 }
256};
257
258} // namespace vcl::comp
259
260#endif // VCL_MESH_COMPONENTS_TEXTURE_PATHS_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 View class is a simple class that stores and exposes two iterators begin and end.
Definition view.h:67
The TexturePaths class represents a component that stores the paths of the textures used by a mesh....
Definition texture_paths.h:81
uint textureNumber() const
Returns the number of texture paths of the mesh.
Definition texture_paths.h:108
TexFileNamesIterator texturePathBegin()
Returns an iterator to the beginning of the vector of texture paths.
Definition texture_paths.h:153
void clearTexturePaths()
Clears the vector of texture paths.
Definition texture_paths.h:137
TexFileNamesIterator texturePathEnd()
Returns an iterator to the end of the vector of texture paths.
Definition texture_paths.h:159
TexturePaths()=default
Initializes the component with an empty vector of texture paths, and an empty string as mesh base pat...
std::string & meshBasePath()
Returns a reference to the mesh base path.
Definition texture_paths.h:132
View< ConstTexFileNamesIterator > texturePaths() const
Returns a lightweigth const view object that stores the begin and end iterators of the vector of text...
Definition texture_paths.h:217
std::string & texturePath(uint i)
Returns a reference to the path of the i-th texture of the mesh. The path is relative to the mesh bas...
Definition texture_paths.h:122
ConstTexFileNamesIterator texturePathEnd() const
Returns a const iterator to the end of the vector of texture paths.
Definition texture_paths.h:176
const std::string & meshBasePath() const
Returns the mesh base path.
Definition texture_paths.h:127
View< TexFileNamesIterator > texturePaths()
Returns a lightweigth view object that stores the begin and end iterators of the vector of texture pa...
Definition texture_paths.h:197
ConstTexFileNamesIterator texturePathBegin() const
Returns a const iterator to the beginning of the vector of texture paths.
Definition texture_paths.h:166
void pushTexturePath(const std::string &textName)
Adds a texture path to the vector of texture paths.
Definition texture_paths.h:143
const std::string & texturePath(uint i) const
Returns the path of the i-th texture of the mesh. The path is relative to the mesh base path.
Definition texture_paths.h:115
HasTexturePaths concept is satisfied only if a Mesh class provides the member functions specified in ...
Definition texture_paths.h:47