Visual Computing Library
Loading...
Searching...
No Matches
mesh_render_info.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_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
25
26#include "mesh_render_info_macros.h"
27
28#include <vclib/space/core/bit_set.h>
29#include <vclib/types.h>
30
31#include <array>
32
33namespace vcl {
34
35namespace detail {
36
37template<typename Enum>
38auto constexpr makeExclusiveReangesArray(auto... args)
39{
40 std::array<Enum, sizeof...(args)> array;
41
42 std::size_t i = 0;
43 ((array[i++] = args), ...);
44
45 return array;
46};
47
48} // namespace detail
49
61{
62public:
63 enum class Buffers : uint {
64 VERTICES,
65 VERT_NORMALS,
66 VERT_COLORS,
67 VERT_TEXCOORDS,
68
69 TRIANGLES,
70 TRI_NORMALS,
71 TRI_COLORS,
72 WEDGE_TEXCOORDS,
73
74 WIREFRAME,
75
76 EDGES,
77 EDGE_COLORS,
78 EDGE_NORMALS,
79
80 TEXTURES,
81
82 MESH_UNIFORMS,
83
84 COUNT,
85 };
86
90 enum class Primitive {
91 POINTS = 0,
92 SURFACE,
93 WIREFRAME,
94 EDGES,
95
96 COUNT
97 };
98
99private:
100 using BuffersBitSetUnderlyingType = ushort;
101
102 static_assert(
103 sizeof(BuffersBitSetUnderlyingType) < (uint) Buffers::COUNT,
104 "BuffersBitSet is not able to store all enum Buffers values");
105
106 bool mVisible;
107
108 // settings for each primitive
109 std::array<BitSet16, toUnderlying(Primitive::COUNT)> mSettings;
110
111public:
112 using BuffersBitSet = vcl::BitSet<BuffersBitSetUnderlyingType>;
113
114private:
115 static BuffersBitSet buffersAll()
116 {
117 BuffersBitSet all;
118 all.set();
119 return all;
120 }
121
122public:
123 static const inline BuffersBitSet BUFFERS_NONE = BuffersBitSet();
124
125 static const inline BuffersBitSet BUFFERS_ALL = buffersAll();
126
130 enum class Points {
131 VISIBLE = VCL_MRS_DRAW_POINTS,
132 SHAPE_PIXEL = VCL_MRS_POINTS_PIXEL,
133 SHAPE_CIRCLE = VCL_MRS_POINTS_CIRCLE,
134 SHADING_NONE = VCL_MRS_POINTS_SHADING_NONE,
135 SHADING_VERT = VCL_MRS_POINTS_SHADING_VERT,
136 COLOR_VERTEX = VCL_MRS_POINTS_COLOR_VERTEX,
137 COLOR_MESH = VCL_MRS_POINTS_COLOR_MESH,
138 COLOR_USER = VCL_MRS_POINTS_COLOR_USER,
139
140 COUNT
141 };
142
146 enum class Surface {
147 VISIBLE = VCL_MRS_DRAW_SURF,
148 SHADING_NONE = VCL_MRS_SURF_SHADING_NONE,
149 SHADING_FLAT = VCL_MRS_SURF_SHADING_FLAT,
150 SHADING_SMOOTH = VCL_MRS_SURF_SHADING_SMOOTH,
151 COLOR_VERTEX = VCL_MRS_SURF_COLOR_VERTEX,
152 COLOR_FACE = VCL_MRS_SURF_COLOR_FACE,
153 COLOR_VERTEX_TEX = VCL_MRS_SURF_TEX_VERTEX,
154 COLOR_WEDGE_TEX = VCL_MRS_SURF_TEX_WEDGE,
155 COLOR_MESH = VCL_MRS_SURF_COLOR_MESH,
156 COLOR_USER = VCL_MRS_SURF_COLOR_USER,
157
158 COUNT
159 };
160
164 enum class Wireframe {
165 VISIBLE = VCL_MRS_DRAW_WIREFRAME,
166 SHADING_NONE = VCL_MRS_WIREFRAME_SHADING_NONE,
167 SHADING_VERT = VCL_MRS_WIREFRAME_SHADING_VERT,
168 COLOR_VERTEX = VCL_MRS_WIREFRAME_COLOR_VERT,
169 COLOR_MESH = VCL_MRS_WIREFRAME_COLOR_MESH,
170 COLOR_USER = VCL_MRS_WIREFRAME_COLOR_USER,
171
172 COUNT
173 };
174
178 enum class Edges {
179 VISIBLE = VCL_MRS_DRAW_EDGES,
180 SHADING_NONE = VCL_MRS_EDGES_SHADING_NONE,
181 SHADING_FLAT = VCL_MRS_EDGES_SHADING_FLAT,
182 SHADING_SMOOTH = VCL_MRS_EDGES_SHADING_SMOOTH,
183 COLOR_VERTEX = VCL_MRS_EDGES_COLOR_VERTEX,
184 COLOR_EDGE = VCL_MRS_EDGES_COLOR_EDGE,
185 COLOR_MESH = VCL_MRS_EDGES_COLOR_MESH,
186 COLOR_USER = VCL_MRS_EDGES_COLOR_USER,
187
188 COUNT
189 };
190
195 bool visible() const { return mVisible; }
196
201 bool& visible() { return mVisible; }
202
208 template<Primitive PRIMITIVE>
210 {
211 return mSettings[toUnderlying(PRIMITIVE)];
212 }
213
219 template<Primitive PRIMITIVE>
221 {
222 return mSettings[toUnderlying(PRIMITIVE)];
223 }
224
230
236
242
248
254
260
266
272
276 void reset()
277 {
278 mVisible = false;
279 for (auto& s : mSettings)
280 s.reset();
281 }
282
283 bool operator==(const MeshRenderInfo& o) const
284 {
285 return mVisible == o.mVisible && mSettings == o.mSettings;
286 }
287
288 MeshRenderInfo& operator&=(const MeshRenderInfo& o)
289 {
290 mVisible &= o.mVisible;
291 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
292 s &= os;
293 }
294 return *this;
295 }
296
297 MeshRenderInfo& operator|=(const MeshRenderInfo& o)
298 {
299 mVisible |= o.mVisible;
300 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
301 s |= os;
302 }
303 return *this;
304 }
305
306 MeshRenderInfo& operator^=(const MeshRenderInfo& o)
307 {
308 mVisible ^= o.mVisible;
309 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
310 s ^= os;
311 }
312 return *this;
313 }
314
334 template<Primitive PRIMITIVE>
335 constexpr static auto exclusiveRange(auto value)
336 {
337 const auto& ranges = exclusiveRanges<PRIMITIVE>();
338 return getExclusiveRange(value, ranges);
339 }
340
357 constexpr static auto pointsExclusiveRange(auto value)
358 {
360 }
361
378 constexpr static auto surfaceExclusiveRange(auto value)
379 {
381 }
382
399 constexpr static auto wireframeExclusiveRange(auto value)
400 {
402 }
403
420 constexpr static auto edgesExclusiveRange(auto value)
421 {
423 }
424
425private:
426 inline static constexpr const auto POINTS_EXCLUSIVE_RANGES =
427 detail::makeExclusiveReangesArray<Points>(
428 Points::SHAPE_PIXEL, // first
429 Points::SHAPE_CIRCLE, // last
430 Points::SHADING_NONE, // first
431 Points::SHADING_VERT, // last
432 Points::COLOR_VERTEX, // first
433 Points::COLOR_USER); // last
434
435 inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
436 detail::makeExclusiveReangesArray<Surface>(
437 Surface::SHADING_NONE, // first
438 Surface::SHADING_SMOOTH, // last
439 Surface::COLOR_VERTEX, // first
440 Surface::COLOR_USER); // last
441
442 inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
443 detail::makeExclusiveReangesArray<Wireframe>(
444 Wireframe::SHADING_NONE, // first
445 Wireframe::SHADING_VERT, // last
446 Wireframe::COLOR_VERTEX, // first
447 Wireframe::COLOR_USER); // last
448
449 inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
450 detail::makeExclusiveReangesArray<Edges>(
451 Edges::SHADING_NONE, // first
452 Edges::SHADING_SMOOTH, // last
453 Edges::COLOR_VERTEX, // first
454 Edges::COLOR_USER); // last
455
456 template<Primitive PRIMITIVE>
457 inline static constexpr auto& exclusiveRanges()
458 {
459 if constexpr (PRIMITIVE == Primitive::POINTS) {
460 return POINTS_EXCLUSIVE_RANGES;
461 }
462 else if constexpr (PRIMITIVE == Primitive::SURFACE) {
463 return SURFACE_EXCLUSIVE_RANGES;
464 }
465 else if constexpr (PRIMITIVE == Primitive::WIREFRAME) {
466 return WIREFRAME_EXCLUSIVE_RANGES;
467 }
468 else if constexpr (PRIMITIVE == Primitive::EDGES) {
469 return EDGES_EXCLUSIVE_RANGES;
470 }
471 else {
472 static_assert(PRIMITIVE, "Unknown Primitive");
473 }
474 }
475
476 constexpr static auto getExclusiveRange(auto value, const auto& array)
477 {
478 for (uint i = 0; i < array.size(); i += 2) {
479 if (toUnderlying(value) >= toUnderlying(array[i]) &&
480 toUnderlying(value) <= toUnderlying(array[i + 1])) {
481 return std::pair(
482 toUnderlying(array[i]), toUnderlying(array[i + 1]));
483 }
484 }
485 return std::pair(toUnderlying(value), toUnderlying(value));
486 }
487};
488
489} // namespace vcl
490
491#endif // VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
bool & visible()
Sets the visibility status of the mesh.
Definition mesh_render_info.h:201
Primitive
List of primitives for which settings can be stored.
Definition mesh_render_info.h:90
Wireframe
List of possible settings for the wireframe primitive.
Definition mesh_render_info.h:164
BitSet16 edges() const
Returns the settings for the edges primitive.
Definition mesh_render_info.h:265
BitSet16 & wireframe()
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:259
BitSet16 surface() const
Returns the settings for the surface primitive.
Definition mesh_render_info.h:241
BitSet16 settings() const
Returns the settings for a given primitive.
Definition mesh_render_info.h:209
BitSet16 points() const
Returns the settings for the points primitive.
Definition mesh_render_info.h:229
static constexpr auto surfaceExclusiveRange(auto value)
Returns pair representing the range in the Surface enumeration of the mutual exclusive settings for t...
Definition mesh_render_info.h:378
Surface
List of possible settings for the surface primitive.
Definition mesh_render_info.h:146
bool visible() const
Returns the visibility status of the mesh.
Definition mesh_render_info.h:195
BitSet16 & edges()
Returns the settings for the edges primitive.
Definition mesh_render_info.h:271
static constexpr auto edgesExclusiveRange(auto value)
Returns pair representing the range in the Edges enumeration of the mutual exclusive settings for the...
Definition mesh_render_info.h:420
BitSet16 & points()
Returns the settings for the points primitive.
Definition mesh_render_info.h:235
BitSet16 wireframe() const
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:253
static constexpr auto pointsExclusiveRange(auto value)
Returns pair representing the range in the Points enumeration of the mutual exclusive settings for th...
Definition mesh_render_info.h:357
BitSet16 & surface()
Returns the settings for the surface primitive.
Definition mesh_render_info.h:247
BitSet16 & settings()
Returns the settings for a given primitive.
Definition mesh_render_info.h:220
void reset()
Resets all the settings of the mesh.
Definition mesh_render_info.h:276
Edges
List of possible settings for the edges primitive.
Definition mesh_render_info.h:178
static constexpr auto wireframeExclusiveRange(auto value)
Returns pair representing the range in the Wireframe enumeration of the mutual exclusive settings for...
Definition mesh_render_info.h:399
static constexpr auto exclusiveRange(auto value)
Given a primitive and a setting, returns pair representing the range in the primitive enumeration of ...
Definition mesh_render_info.h:335
Points
List of possible settings for the points primitive.
Definition mesh_render_info.h:130
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
BitSet< short > BitSet16
BitSet16 is a BitSet of 16 bits.
Definition bit_set.h:393