23#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
26#include "mesh_render_info_macros.h"
28#include <vclib/space/core/bit_set.h>
29#include <vclib/types.h>
37template<
typename Enum>
38auto constexpr makeExclusiveReangesArray(
auto... args)
40 std::array<Enum,
sizeof...(args)> array;
43 ((array[i++] = args), ...);
63 enum class Buffers :
uint {
100 using BuffersBitSetUnderlyingType =
ushort;
103 sizeof(BuffersBitSetUnderlyingType) < (uint) Buffers::COUNT,
104 "BuffersBitSet is not able to store all enum Buffers values");
109 std::array<
BitSet16, toUnderlying(Primitive::COUNT)> mSettings;
115 static BuffersBitSet buffersAll()
123 static const inline BuffersBitSet BUFFERS_NONE = BuffersBitSet();
125 static const inline BuffersBitSet BUFFERS_ALL = buffersAll();
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,
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,
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,
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,
208 template<Primitive PRIMITIVE>
211 return mSettings[toUnderlying(
PRIMITIVE)];
219 template<Primitive PRIMITIVE>
222 return mSettings[toUnderlying(
PRIMITIVE)];
279 for (
auto& s : mSettings)
285 return mVisible ==
o.mVisible && mSettings ==
o.mSettings;
288 MeshRenderInfo& operator&=(
const MeshRenderInfo& o)
290 mVisible &= o.mVisible;
291 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
297 MeshRenderInfo& operator|=(
const MeshRenderInfo& o)
299 mVisible |= o.mVisible;
300 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
306 MeshRenderInfo& operator^=(
const MeshRenderInfo& o)
308 mVisible ^= o.mVisible;
309 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
334 template<Primitive PRIMITIVE>
338 return getExclusiveRange(value, ranges);
426 inline static constexpr const auto POINTS_EXCLUSIVE_RANGES =
427 detail::makeExclusiveReangesArray<Points>(
429 Points::SHAPE_CIRCLE,
430 Points::SHADING_NONE,
431 Points::SHADING_VERT,
432 Points::COLOR_VERTEX,
435 inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
436 detail::makeExclusiveReangesArray<Surface>(
437 Surface::SHADING_NONE,
438 Surface::SHADING_SMOOTH,
439 Surface::COLOR_VERTEX,
440 Surface::COLOR_USER);
442 inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
443 detail::makeExclusiveReangesArray<Wireframe>(
444 Wireframe::SHADING_NONE,
445 Wireframe::SHADING_VERT,
446 Wireframe::COLOR_VERTEX,
447 Wireframe::COLOR_USER);
449 inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
450 detail::makeExclusiveReangesArray<Edges>(
452 Edges::SHADING_SMOOTH,
456 template<Primitive PRIMITIVE>
457 inline static constexpr auto& exclusiveRanges()
459 if constexpr (
PRIMITIVE == Primitive::POINTS) {
460 return POINTS_EXCLUSIVE_RANGES;
462 else if constexpr (PRIMITIVE == Primitive::SURFACE) {
463 return SURFACE_EXCLUSIVE_RANGES;
465 else if constexpr (PRIMITIVE == Primitive::WIREFRAME) {
466 return WIREFRAME_EXCLUSIVE_RANGES;
468 else if constexpr (PRIMITIVE == Primitive::EDGES) {
469 return EDGES_EXCLUSIVE_RANGES;
472 static_assert(PRIMITIVE,
"Unknown Primitive");
476 constexpr static auto getExclusiveRange(
auto value,
const auto& array)
478 for (uint i = 0; i < array.size(); i += 2) {
479 if (toUnderlying(value) >= toUnderlying(array[i]) &&
480 toUnderlying(value) <= toUnderlying(array[i + 1])) {
482 toUnderlying(array[i]), toUnderlying(array[i + 1]));
485 return std::pair(toUnderlying(value), toUnderlying(value));
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