Visual Computing Library  devel
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 "base/container_component.h"
27#include "base/predicates.h"
28
29#include <vclib/space/core.h>
30#include <vclib/base.h>
31
32namespace vcl::comp {
33
71template<int N, typename ParentElemType = void, bool OPT = false>
73 public ContainerComponent<
74 WedgeColors<N, ParentElemType, OPT>,
75 CompId::WEDGE_COLORS,
76 vcl::Color,
77 N,
78 void,
79 ParentElemType,
80 !std::is_same_v<ParentElemType, void>,
81 OPT,
82 true>
83{
84 using Base = ContainerComponent<
86 CompId::WEDGE_COLORS,
88 N,
89 void,
91 !std::is_same_v<ParentElemType, void>,
92 OPT,
93 true>;
94
95public:
100
101 /* Iterator Types declaration */
102
103 using WedgeColorsIterator = Base::Iterator;
104 using ConstWedgeColorsIterator = Base::ConstIterator;
105
106 static const int WEDGE_COLOR_NUMBER = Base::SIZE;
107
108 /* Constructors */
109
117 WedgeColors() = default;
118
119 /* Member functions */
120
134 vcl::Color& wedgeColor(uint i) { return colors().at(i); }
135
143 const vcl::Color& wedgeColor(uint i) const { return colors().at(i); }
144
161 vcl::Color& wedgeColorMod(int i) { return colors().atMod(i); }
162
169 const vcl::Color& wedgeColorMod(int i) const { return colors().atMod(i); }
170
177 void setWedgeColor(uint i, const vcl::Color& c) { colors().set(i, c); }
178
190 template<Range Rng>
192 {
193 colors().set(r);
194 }
195
196 /* Iterator Member functions */
197
204 WedgeColorsIterator wedgeColorBegin() { return colors().begin(); }
205
211 WedgeColorsIterator wedgeColorEnd() { return colors().end(); }
212
219 ConstWedgeColorsIterator wedgeColorBegin() const
220 {
221 return colors().begin();
222 }
223
230 ConstWedgeColorsIterator wedgeColorEnd() const { return colors().end(); }
231
252
273
274 // dummy member to discriminate between WedgeColors and FaceHalfEdgePointers
275 void __wedgeColors() const {}
276
277protected:
278 // Component interface functions
279 template<typename Element>
280 void importFrom(const Element& e, bool = true);
281
282 void serialize(std::ostream& os) const { colors().serialize(os); }
283
284 void deserialize(std::istream& is) { colors().deserialize(is); }
285
286 // ContainerComponent interface functions
287 void resize(uint n) requires (N < 0) { colors().resize(n); }
288
289 void pushBack(const vcl::Color& c = vcl::Color()) requires (N < 0)
290 {
291 colors().pushBack(c);
292 }
293
294 void insert(uint i, const vcl::Color& c = vcl::Color()) requires (N < 0)
295 {
296 colors().insert(i, c);
297 }
298
299 void erase(uint i) requires (N < 0) { colors().erase(i); }
300
301 void clear() requires (N < 0) { colors().clear(); }
302
303private:
304 template<typename Element>
305 void importWedgeColorsFrom(const Element& e)
306 {
307 for (uint i = 0; i < e.vertexNumber(); ++i) {
308 wedgeColor(i) = e.wedgeColor(i);
309 }
310 }
311
312 Vector<vcl::Color, N>& colors() { return Base::container(); }
313
314 const Vector<vcl::Color, N>& colors() const { return Base::container(); }
315};
316
317/* concepts */
318
336template<typename T>
337concept HasWedgeColors = ITB::IsDerivedFromSpecializationOfV<T, WedgeColors>;
338
349template<typename T>
353
364template<typename T>
365concept HasRightNumberOfWedgeColors = T::VERTEX_NUMBER == T::WEDGE_COLOR_NUMBER;
366
379template<typename T>
382
383/* importFrom function */
384
385template<int N, typename ParentElemType, bool OPT>
386template<typename Element>
387void WedgeColors<N, ParentElemType, OPT>::importFrom(const Element& e, bool)
388{
389 if constexpr (HasWedgeColors<Element>) {
390 if (isWedgeColorsAvailableOn(e)) {
391 if constexpr (N > 0) {
392 // same static size
393 if constexpr (N == Element::WEDGE_COLOR_NUMBER) {
394 importWedgeColorsFrom(e);
395 }
396 // from dynamic to static, but dynamic size == static size
397 else if constexpr (Element::WEDGE_COLOR_NUMBER < 0) {
398 if (e.vertexNumber() == N) {
399 importWedgeColorsFrom(e);
400 }
401 }
402 else {
403 // do not import in this case: cannot import from
404 // dynamic size != static size
405 }
406 }
407 else {
408 // from static/dynamic to dynamic size: need to resize
409 // first, then import
410 resize(e.vertexNumber());
411 importWedgeColorsFrom(e);
412 }
413 }
414 }
415}
416
417/* Detector function to check if a class has WedgeColors available */
418
429bool isWedgeColorsAvailableOn(const auto& element)
430{
432}
433
434} // namespace vcl::comp
435
436#endif // VCL_MESH_COMPONENTS_WEDGE_COLORS_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
Box()
The Empty constructor of a box, initializes a null box.
Definition box.h:65
void serialize(std::ostream &os) const
Serializes the box to the given output stream.
Definition box.h:466
The Color class represents a 32 bit color.
Definition color.h:48
The Element class.
Definition element.h:75
The View class is a simple class that stores and exposes two iterators begin and end.
Definition view.h:67
The WedgeColors class is a container of colors associated to the wedges of a Face element.
Definition wedge_colors.h:83
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:269
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:161
vcl::Color & wedgeColor(uint i)
Returns a reference to the i-th wedge color of the element.
Definition wedge_colors.h:134
WedgeColors()=default
Empty constructor.
WedgeColorsIterator wedgeColorBegin()
Returns an iterator to the first wedge color in the container of this component.
Definition wedge_colors.h:204
ConstWedgeColorsIterator wedgeColorEnd() const
Returns a const iterator to the end of the container of this component.
Definition wedge_colors.h:230
WedgeColorsIterator wedgeColorEnd()
Returns an iterator to the end of the container of this component.
Definition wedge_colors.h:211
void setWedgeColors(Rng &&r)
Sets all the wedge colors of the element.
Definition wedge_colors.h:191
ConstWedgeColorsIterator wedgeColorBegin() const
Returns a const iterator to the first wedge color in the container of this component.
Definition wedge_colors.h:219
const vcl::Color & wedgeColor(uint i) const
Returns a const reference to the i-th wedge color of the element.
Definition wedge_colors.h:143
const vcl::Color & wedgeColorMod(int i) const
Same of wedgeColorMod(int) but returns a const reference.
Definition wedge_colors.h:169
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:248
void setWedgeColor(uint i, const vcl::Color &c)
Sets the i-th wedge color of the element.
Definition wedge_colors.h:177
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
A concept that checks whether a type T (that should be a Element) has the WedgeColors component (inhe...
Definition wedge_colors.h:350
HasRightNumberOfWedgeColors concept.
Definition wedge_colors.h:365
A concept that checks whether a type T (that should be a Element) has the WedgeColors component (inhe...
Definition wedge_colors.h:337
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74
SanityCheckWedgeColors concept.
Definition wedge_colors.h:380