Visual Computing Library
Loading...
Searching...
No Matches
wedge_colors.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_WEDGE_COLORS_H
24#define VCL_MESH_COMPONENTS_WEDGE_COLORS_H
25
26#include "bases/container_component.h"
27
28#include <vclib/concepts/mesh/components/color.h>
29#include <vclib/concepts/mesh/components/wedge_colors.h>
30#include <vclib/space/core/color.h>
31#include <vclib/space/core/vector.h>
32#include <vclib/types/view.h>
33
34namespace vcl::comp {
35
73template<int N, typename ParentElemType = void, bool OPT = false>
75 public ContainerComponent<
76 WedgeColors<N, ParentElemType, OPT>,
77 CompId::WEDGE_COLORS,
78 vcl::Color,
79 N,
80 void,
81 ParentElemType,
82 !std::is_same_v<ParentElemType, void>,
83 OPT,
84 true>
85{
88 CompId::WEDGE_COLORS,
90 N,
91 void,
93 !std::is_same_v<ParentElemType, void>,
94 OPT,
95 true>;
96
97public:
102
103 /* Iterator Types declaration */
104
105 using WedgeColorsIterator = Base::Iterator;
106 using ConstWedgeColorsIterator = Base::ConstIterator;
107
108 static const int WEDGE_COLOR_NUMBER = Base::SIZE;
109
110 /* Constructors */
111
119 WedgeColors() = default;
120
121 /* Member functions */
122
136 vcl::Color& wedgeColor(uint i) { return colors().at(i); }
137
145 const vcl::Color& wedgeColor(uint i) const { return colors().at(i); }
146
163 vcl::Color& wedgeColorMod(int i) { return colors().atMod(i); }
164
171 const vcl::Color& wedgeColorMod(int i) const { return colors().atMod(i); }
172
179 void setWedgeColor(uint i, const vcl::Color& c) { colors().set(i, c); }
180
192 template<Range Rng>
194 {
195 colors().set(r);
196 }
197
198 /* Iterator Member functions */
199
206 WedgeColorsIterator wedgeColorBegin() { return colors().begin(); }
207
213 WedgeColorsIterator wedgeColorEnd() { return colors().end(); }
214
221 ConstWedgeColorsIterator wedgeColorBegin() const
222 {
223 return colors().begin();
224 }
225
232 ConstWedgeColorsIterator wedgeColorEnd() const { return colors().end(); }
233
254
275
276 // dummy member to discriminate between WedgeColors and FaceHalfEdgePointers
277 void __wedgeColors() const {}
278
279protected:
280 // Component interface functions
281 template<typename Element>
282 void importFrom(const Element& e, bool = true)
283 {
284 if constexpr (HasWedgeColors<Element>) {
285 if (isWedgeColorsAvailableOn(e)) {
286 if constexpr (N > 0) {
287 // same static size
288 if constexpr (N == Element::WEDGE_COLOR_NUMBER) {
289 importWedgeColorsFrom(e);
290 }
291 // from dynamic to static, but dynamic size == static size
292 else if constexpr (Element::WEDGE_COLOR_NUMBER < 0) {
293 if (e.vertexNumber() == N) {
294 importWedgeColorsFrom(e);
295 }
296 }
297 else {
298 // do not import in this case: cannot import from
299 // dynamic size != static size
300 }
301 }
302 else {
303 // from static/dynamic to dynamic size: need to resize
304 // first, then import
305 resize(e.vertexNumber());
306 importWedgeColorsFrom(e);
307 }
308 }
309 }
310 }
311
312 void serialize(std::ostream& os) const { colors().serialize(os); }
313
314 void deserialize(std::istream& is) { colors().deserialize(is); }
315
316 // ContainerComponent interface functions
317 void resize(uint n) requires (N < 0) { colors().resize(n); }
318
319 void pushBack(const vcl::Color& c = vcl::Color()) requires (N < 0)
320 {
321 colors().pushBack(c);
322 }
323
324 void insert(uint i, const vcl::Color& c = vcl::Color()) requires (N < 0)
325 {
326 colors().insert(i, c);
327 }
328
329 void erase(uint i) requires (N < 0) { colors().erase(i); }
330
331 void clear() requires (N < 0) { colors().clear(); }
332
333private:
334 template<typename Element>
335 void importWedgeColorsFrom(const Element& e)
336 {
337 for (uint i = 0; i < e.vertexNumber(); ++i) {
338 wedgeColor(i) = e.wedgeColor(i);
339 }
340 }
341
342 Vector<vcl::Color, N>& colors() { return Base::container(); }
343
344 const Vector<vcl::Color, N>& colors() const { return Base::container(); }
345};
346
347/* Detector function to check if a class has WedgeColors available */
348
360bool isWedgeColorsAvailableOn(const ElementConcept auto& element)
361{
362 return isComponentAvailableOn<CompId::WEDGE_COLORS>(element);
363}
364
365} // namespace vcl::comp
366
367#endif // VCL_MESH_COMPONENTS_WEDGE_COLORS_H
The Color class represents a 32 bit color.
Definition color.h:48
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 ContainerComponent class is the base class for all the components of VCLib that store a container...
Definition container_component.h:130
The WedgeColors class is a container of colors associated to the wedges of a Face element.
Definition wedge_colors.h:85
View< ConstWedgeColorsIterator > wedgeColors() const
Returns a lightweight const view object that stores the begin and end iterators of the container of w...
Definition wedge_colors.h:271
vcl::Color & wedgeColorMod(int i)
Returns a reference to the i-th wedge color of the element but using as index the module between i an...
Definition wedge_colors.h:163
vcl::Color & wedgeColor(uint i)
Returns a reference to the i-th wedge color of the element.
Definition wedge_colors.h:136
WedgeColors()=default
Empty constructor.
WedgeColorsIterator wedgeColorBegin()
Returns an iterator to the first wedge color in the container of this component.
Definition wedge_colors.h:206
ConstWedgeColorsIterator wedgeColorEnd() const
Returns a const iterator to the end of the container of this component.
Definition wedge_colors.h:232
WedgeColorsIterator wedgeColorEnd()
Returns an iterator to the end of the container of this component.
Definition wedge_colors.h:213
void setWedgeColors(Rng &&r)
Sets all the wedge colors of the element.
Definition wedge_colors.h:193
ConstWedgeColorsIterator wedgeColorBegin() const
Returns a const iterator to the first wedge color in the container of this component.
Definition wedge_colors.h:221
const vcl::Color & wedgeColor(uint i) const
Returns a const reference to the i-th wedge color of the element.
Definition wedge_colors.h:145
const vcl::Color & wedgeColorMod(int i) const
Same of wedgeColorMod(int) but returns a const reference.
Definition wedge_colors.h:171
View< WedgeColorsIterator > wedgeColors()
Returns a lightweight view object that stores the begin and end iterators of the container of wedge c...
Definition wedge_colors.h:250
void setWedgeColor(uint i, const vcl::Color &c)
Sets the i-th wedge color of the element.
Definition wedge_colors.h:179
Utility concept that is evaluated true the Range R is an Input Range and has a value_type that is con...
Definition range.h:89