23#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_SETTINGS_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_SETTINGS_H
26#include "mesh_render_info.h"
28#include <vclib/mesh/requirements.h>
29#include <vclib/space/core/bit_set.h>
30#include <vclib/space/core/color.h>
77 float mPointWidth = 3;
78 float mPointUserColor[4] = {1, 1, 0, 1};
79 uint mSurfUserColor = 0xFF808080;
81 float mWrfUserColor[4] = {0, 0, 0, 1};
83 uint mEdgesUserColor = 0xFF000000;
105 template<MeshConcept MeshType>
108 setRenderCapabilityFrom(
m);
109 setDefaultSettingsFromCapability();
141 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
213 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
231 float pointWidth()
const {
return mPointWidth; }
243 const float* pointUserColorData()
const {
return mPointUserColor; }
259 c.setAbgr(mSurfUserColor);
263 const uint* surfaceUserColorData()
const {
return &mSurfUserColor; }
276 int wireframeWidth()
const {
return mWrfWidth; }
288 const float* wireframeUserColorData()
const {
return mWrfUserColor; }
301 int edgesWidth()
const {
return mEdgesWidth; }
306 c.setAbgr(mEdgesUserColor);
310 const uint* edgesUserColorData()
const {
return &mEdgesUserColor; }
355 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
360 auto rng = MRI::exclusiveRange<PRIMITIVE>(
val);
362 if (
rng.first ==
rng.second) {
370 for (
auto i =
rng.first;
i <=
rng.second; ++
i) {
403 bool setPointsWidth(
float width)
414 bool setPointsUserColor(
float r,
float g,
float b,
float a = 1)
417 mPointUserColor[0] = r;
418 mPointUserColor[1] = g;
419 mPointUserColor[2] = b;
420 mPointUserColor[3] = a;
431 mPointUserColor[0] = c.
redF();
432 mPointUserColor[1] = c.
greenF();
433 mPointUserColor[2] = c.
blueF();
434 mPointUserColor[3] = c.
alphaF();
464 bool setSurfaceUserColor(
float r,
float g,
float b,
float a = 1)
472 mSurfUserColor = c.abgr();
483 mSurfUserColor = c.abgr();
513 bool setWireframeUserColor(
float r,
float g,
float b,
float a = 1)
516 mWrfUserColor[0] =
r;
517 mWrfUserColor[1] =
g;
518 mWrfUserColor[2] =
b;
519 mWrfUserColor[3] =
a;
527 bool setWireframeUserColor(
const vcl::Color& c)
530 mWrfUserColor[0] = c.
redF();
531 mWrfUserColor[1] = c.
greenF();
532 mWrfUserColor[2] = c.
blueF();
533 mWrfUserColor[3] = c.
alphaF();
541 bool setWireframeWidth(
int width)
574 bool setEdgesUserColor(
float r,
float g,
float b,
float a = 1)
576 if (
canEdges(MRI::Edges::VISIBLE)) {
582 mEdgesUserColor = c.abgr();
592 if (
canEdges(MRI::Edges::VISIBLE)) {
593 mEdgesUserColor = c.abgr();
601 bool setEdgesWidth(
int width)
603 if (
canEdges(MRI::Edges::VISIBLE)) {
612 template<MeshConcept MeshType>
613 void setRenderCapabilityFrom(
const MeshType& m)
617 if (m.vertexNumber() > 0) {
621 setPointsCapability(MRI::Points::VISIBLE);
622 setPointsCapability(MRI::Points::SHAPE_PIXEL);
623 setPointsCapability(MRI::Points::SHAPE_CIRCLE);
624 setPointsCapability(MRI::Points::SHADING_NONE);
625 setPointsCapability(MRI::Points::COLOR_USER);
628 if (vcl::isPerVertexNormalAvailable(m)) {
629 setPointsCapability(MRI::Points::SHADING_VERT);
634 if (vcl::isPerVertexColorAvailable(m)) {
635 setPointsCapability(MRI::Points::COLOR_VERTEX);
640 setPointsCapability(MRI::Points::COLOR_MESH);
645 if (m.faceNumber() > 0) {
646 setSurfaceCapability(MRI::Surface::VISIBLE);
647 setSurfaceCapability(MRI::Surface::SHADING_NONE);
648 setSurfaceCapability(MRI::Surface::COLOR_USER);
649 setWireframeCapability(MRI::Wireframe::VISIBLE);
650 setWireframeCapability(MRI::Wireframe::SHADING_NONE);
651 setWireframeCapability(MRI::Wireframe::COLOR_USER);
654 setSurfaceCapability(MRI::Surface::COLOR_MESH);
655 setWireframeCapability(MRI::Wireframe::COLOR_MESH);
660 setSurfaceCapability(MRI::Surface::SHADING_FLAT);
665 if (vcl::isPerVertexNormalAvailable(m)) {
666 setSurfaceCapability(MRI::Surface::SHADING_SMOOTH);
667 setWireframeCapability(
668 MRI::Wireframe::SHADING_VERT);
674 setSurfaceCapability(MRI::Surface::COLOR_FACE);
678 if (vcl::isPerVertexColorAvailable(m)) {
679 setSurfaceCapability(MRI::Surface::COLOR_VERTEX);
680 setWireframeCapability(
681 MRI::Wireframe::COLOR_VERTEX);
687 if (vcl::isPerVertexTexCoordAvailable(m) &&
688 m.textureNumber() > 0)
689 setSurfaceCapability(
690 MRI::Surface::COLOR_VERTEX_TEX);
695 m.textureNumber() > 0)
696 setSurfaceCapability(
697 MRI::Surface::COLOR_WEDGE_TEX);
705 if (m.edgeNumber() > 0) {
706 setEdgesCapability(MRI::Edges::VISIBLE);
707 setEdgesCapability(MRI::Edges::SHADING_NONE);
708 setEdgesCapability(MRI::Edges::COLOR_USER);
711 setEdgesCapability(MRI::Edges::COLOR_MESH);
715 if (vcl::isPerVertexNormalAvailable(m)) {
716 setEdgesCapability(MRI::Edges::SHADING_SMOOTH);
722 setEdgesCapability(MRI::Edges::SHADING_FLAT);
728 setEdgesCapability(MRI::Edges::COLOR_EDGE);
732 if (vcl::isPerVertexColorAvailable(m)) {
733 setEdgesCapability(MRI::Edges::COLOR_VERTEX);
741 mDrawMode &= mCapability;
744 void setDefaultSettingsFromCapability()
751 setDefaultSurfaceSettingsFromCapability();
752 setDefaultWireframeSettingsFromCapability();
753 setDefaultPointSettingsFromCapability();
754 setDefaultEdgeSettingsFromCapability();
759 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
760 void setCapability(Enum val,
bool b =
true)
762 assert(val < Enum::COUNT);
763 mCapability.
settings<PRIMITIVE>()[toUnderlying(val)] = b;
768 setCapability<MRI::Primitive::POINTS>(p, b);
773 setCapability<MRI::Primitive::SURFACE>(s, b);
778 setCapability<MRI::Primitive::WIREFRAME>(w, b);
783 setCapability<MRI::Primitive::EDGES>(e, b);
786 void setDefaultPointSettingsFromCapability()
790 mDrawMode.
points().reset();
808 void setDefaultSurfaceSettingsFromCapability()
847 void setDefaultWireframeSettingsFromCapability()
865 void setDefaultEdgeSettingsFromCapability()
869 mDrawMode.
edges().reset();
The Color class represents a 32 bit color.
Definition color.h:48
float greenF() const
Returns the float green component of this color [0-1].
Definition color.h:207
float blueF() const
Returns the float blue component of this color [0-1].
Definition color.h:213
float alphaF() const
Returns the float alpha component of this color [0-1].
Definition color.h:219
void setRedF(float red)
Sets the red of this color [0-1].
Definition color.h:531
float redF() const
Returns the float red component of this color [0-1].
Definition color.h:201
void setAlphaF(float alpha)
Sets the alpha of this color [0-1].
Definition color.h:525
void setBlueF(float blue)
Sets the blue of this color [0-1].
Definition color.h:543
void setGreenF(float green)
Sets the green of this color [0-1].
Definition color.h:537
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
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 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
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 wireframe() const
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:253
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
Points
List of possible settings for the points primitive.
Definition mesh_render_info.h:130
The MeshRenderSettings class allows an easy management of render settings of a Mesh....
Definition mesh_render_settings.h:71
MeshRenderSettings()=default
Construct a new MeshRenderSettings object with capabilities set to false.
bool isPoints(MeshRenderInfo::Points p) const
Returns whether the given points option is set.
Definition mesh_render_settings.h:226
bool can(Enum val) const
Returns the capability of a given option for the given primitive.
Definition mesh_render_settings.h:142
bool canWireframe(MeshRenderInfo::Wireframe w) const
Returns the capability of a given option for the wireframe primitive.
Definition mesh_render_settings.h:178
MeshRenderSettings(const MeshType &m)
Construct a new MeshRenderSettings object from a Mesh.
Definition mesh_render_settings.h:106
MeshRenderInfo drawMode() const
Returns the current draw mode as a MeshRenderInfo object.
Definition mesh_render_settings.h:116
bool isVisible() const
Returns whether the mesh is visible.
Definition mesh_render_settings.h:200
bool setSurface(MeshRenderInfo::Surface s, bool b=true)
Sets the given shading option of the surface.
Definition mesh_render_settings.h:459
bool setEdges(MeshRenderInfo::Edges e, bool b=true)
Sets the given shading option of the edges.
Definition mesh_render_settings.h:569
bool is(Enum val) const
Returns whether the given option for the given primitive is set.
Definition mesh_render_settings.h:214
bool set(Enum val, bool b=true)
Sets given the shading option of the given primitive.
Definition mesh_render_settings.h:356
bool setPoints(MeshRenderInfo::Points p, bool b=true)
Sets the given shading option of the points.
Definition mesh_render_settings.h:398
bool canSurface(MeshRenderInfo::Surface s) const
Returns the capability of a given option for the surface primitive.
Definition mesh_render_settings.h:166
bool setVisibility(bool b)
Sets the visibility of the mesh.
Definition mesh_render_settings.h:322
bool canPoints(MeshRenderInfo::Points p) const
Returns the capability of a given option for the points primitive.
Definition mesh_render_settings.h:154
bool canBeVisible() const
Returns whether the mesh can be visible.
Definition mesh_render_settings.h:128
bool canEdges(MeshRenderInfo::Edges e) const
Returns the capability of a given option for the edges primitive.
Definition mesh_render_settings.h:189
bool isSurface(MeshRenderInfo::Surface s) const
Returns whether the given surface option is set.
Definition mesh_render_settings.h:251
bool isWireframe(MeshRenderInfo::Wireframe w) const
Returns whether the given wireframe option is set.
Definition mesh_render_settings.h:271
bool setWireframe(MeshRenderInfo::Wireframe w, bool b=true)
Sets the given shading option of the wireframe.
Definition mesh_render_settings.h:508
bool isEdges(MeshRenderInfo::Edges e) const
Returns whether the given edges option is set.
Definition mesh_render_settings.h:296
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Concept that is evaluated true if a Mesh has the Color component.
Definition per_mesh.h:69
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:131
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:133
Concept that checks if a Mesh has the per Edge Color component.
Definition per_edge.h:97
Concept that checks if a Mesh has the per Edge Normal component.
Definition per_edge.h:142
Concept that checks if a Mesh has the per Face Color component.
Definition per_face.h:111
Concept that checks if a Mesh has the per Face Normal component.
Definition per_face.h:158
Concept that checks if a Mesh has the per Face WedgeTexCoords component.
Definition per_face.h:270
Concept that checks if a Mesh has the per Vertex Color component.
Definition per_vertex.h:98
Concept that checks if a Mesh has the per Vertex Normal component.
Definition per_vertex.h:128
Concept that checks if a Mesh has the per Vertex TexCoord component.
Definition per_vertex.h:174
Concept that checks if a Mesh has the TexturePaths component.
Definition per_mesh.h:112
bool isPerEdgeColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Edge element of the input mesh m.
Definition edge_requirements.h:214
bool isPerEdgeNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Edge element of the input mesh m.
Definition edge_requirements.h:330
bool isPerFaceWedgeTexCoordsAvailable(const MeshType &m)
Returns true if the WedgeTexCoords component is available (enabled) in the Face element of the input ...
Definition face_requirements.h:571
bool isPerFaceNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:330
bool isPerFaceColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:214