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.h>
29#include <vclib/space/core.h>
76 float mPointWidth = 3;
77 float mPointUserColor[4] = {1, 1, 0, 1};
78 uint mSurfUserColor = 0xFF808080;
80 float mWrfUserColor[4] = {0, 0, 0, 1};
82 uint mEdgesUserColor = 0xFF000000;
104 template<MeshConcept MeshType>
107 setRenderCapabilityFrom(
m);
108 setDefaultSettingsFromCapability();
140 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
212 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
230 float pointWidth()
const {
return mPointWidth; }
242 const float* pointUserColorData()
const {
return mPointUserColor; }
258 c.setAbgr(mSurfUserColor);
262 const uint* surfaceUserColorData()
const {
return &mSurfUserColor; }
275 int wireframeWidth()
const {
return mWrfWidth; }
287 const float* wireframeUserColorData()
const {
return mWrfUserColor; }
300 int edgesWidth()
const {
return mEdgesWidth; }
305 c.setAbgr(mEdgesUserColor);
309 const uint* edgesUserColorData()
const {
return &mEdgesUserColor; }
354 template<MeshRenderInfo::Primitive PRIMITIVE,
typename Enum>
359 auto rng = MRI::exclusiveRange<PRIMITIVE>(
val);
361 if (
rng.first ==
rng.second) {
369 for (
auto i =
rng.first;
i <=
rng.second; ++
i) {
402 bool setPointsWidth(
float width)
413 bool setPointsUserColor(
float r,
float g,
float b,
float a = 1)
416 mPointUserColor[0] = r;
417 mPointUserColor[1] = g;
418 mPointUserColor[2] = b;
419 mPointUserColor[3] = a;
430 mPointUserColor[0] = c.
redF();
431 mPointUserColor[1] = c.
greenF();
432 mPointUserColor[2] = c.
blueF();
433 mPointUserColor[3] = c.
alphaF();
463 bool setSurfaceUserColor(
float r,
float g,
float b,
float a = 1)
471 mSurfUserColor = c.abgr();
482 mSurfUserColor = c.abgr();
512 bool setWireframeUserColor(
float r,
float g,
float b,
float a = 1)
515 mWrfUserColor[0] =
r;
516 mWrfUserColor[1] =
g;
517 mWrfUserColor[2] =
b;
518 mWrfUserColor[3] =
a;
526 bool setWireframeUserColor(
const vcl::Color& c)
529 mWrfUserColor[0] = c.
redF();
530 mWrfUserColor[1] = c.
greenF();
531 mWrfUserColor[2] = c.
blueF();
532 mWrfUserColor[3] = c.
alphaF();
540 bool setWireframeWidth(
int width)
573 bool setEdgesUserColor(
float r,
float g,
float b,
float a = 1)
575 if (
canEdges(MRI::Edges::VISIBLE)) {
581 mEdgesUserColor = c.abgr();
591 if (
canEdges(MRI::Edges::VISIBLE)) {
592 mEdgesUserColor = c.abgr();
600 bool setEdgesWidth(
int width)
602 if (
canEdges(MRI::Edges::VISIBLE)) {
611 template<MeshConcept MeshType>
612 void setRenderCapabilityFrom(
const MeshType& m)
616 if (m.vertexNumber() > 0) {
620 setPointsCapability(MRI::Points::VISIBLE);
621 setPointsCapability(MRI::Points::SHAPE_PIXEL);
622 setPointsCapability(MRI::Points::SHAPE_CIRCLE);
623 setPointsCapability(MRI::Points::SHAPE_SPHERE);
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();
809 void setDefaultSurfaceSettingsFromCapability()
848 void setDefaultWireframeSettingsFromCapability()
866 void setDefaultEdgeSettingsFromCapability()
870 mDrawMode.
edges().reset();
A class representing a box in N-dimensional space.
Definition box.h:46
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:210
float blueF() const
Returns the float blue component of this color [0-1].
Definition color.h:216
float alphaF() const
Returns the float alpha component of this color [0-1].
Definition color.h:222
void setRedF(float red)
Sets the red of this color [0-1].
Definition color.h:534
float redF() const
Returns the float red component of this color [0-1].
Definition color.h:204
void setAlphaF(float alpha)
Sets the alpha of this color [0-1].
Definition color.h:528
void setBlueF(float blue)
Sets the blue of this color [0-1].
Definition color.h:546
void setGreenF(float green)
Sets the green of this color [0-1].
Definition color.h:540
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:165
BitSet16 edges() const
Returns the settings for the edges primitive.
Definition mesh_render_info.h:266
BitSet16 surface() const
Returns the settings for the surface primitive.
Definition mesh_render_info.h:242
BitSet16 settings() const
Returns the settings for a given primitive.
Definition mesh_render_info.h:210
BitSet16 points() const
Returns the settings for the points primitive.
Definition mesh_render_info.h:230
Surface
List of possible settings for the surface primitive.
Definition mesh_render_info.h:147
bool visible() const
Returns the visibility status of the mesh.
Definition mesh_render_info.h:196
BitSet16 wireframe() const
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:254
void reset()
Resets all the settings of the mesh.
Definition mesh_render_info.h:277
Edges
List of possible settings for the edges primitive.
Definition mesh_render_info.h:179
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:70
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:225
bool can(Enum val) const
Returns the capability of a given option for the given primitive.
Definition mesh_render_settings.h:141
bool canWireframe(MeshRenderInfo::Wireframe w) const
Returns the capability of a given option for the wireframe primitive.
Definition mesh_render_settings.h:177
MeshRenderSettings(const MeshType &m)
Construct a new MeshRenderSettings object from a Mesh.
Definition mesh_render_settings.h:105
MeshRenderInfo drawMode() const
Returns the current draw mode as a MeshRenderInfo object.
Definition mesh_render_settings.h:115
bool isVisible() const
Returns whether the mesh is visible.
Definition mesh_render_settings.h:199
bool setSurface(MeshRenderInfo::Surface s, bool b=true)
Sets the given shading option of the surface.
Definition mesh_render_settings.h:458
bool setEdges(MeshRenderInfo::Edges e, bool b=true)
Sets the given shading option of the edges.
Definition mesh_render_settings.h:568
bool is(Enum val) const
Returns whether the given option for the given primitive is set.
Definition mesh_render_settings.h:213
bool set(Enum val, bool b=true)
Sets given the shading option of the given primitive.
Definition mesh_render_settings.h:355
bool setPoints(MeshRenderInfo::Points p, bool b=true)
Sets the given shading option of the points.
Definition mesh_render_settings.h:397
bool canSurface(MeshRenderInfo::Surface s) const
Returns the capability of a given option for the surface primitive.
Definition mesh_render_settings.h:165
bool setVisibility(bool b)
Sets the visibility of the mesh.
Definition mesh_render_settings.h:321
bool canPoints(MeshRenderInfo::Points p) const
Returns the capability of a given option for the points primitive.
Definition mesh_render_settings.h:153
bool canBeVisible() const
Returns whether the mesh can be visible.
Definition mesh_render_settings.h:127
bool canEdges(MeshRenderInfo::Edges e) const
Returns the capability of a given option for the edges primitive.
Definition mesh_render_settings.h:188
bool isSurface(MeshRenderInfo::Surface s) const
Returns whether the given surface option is set.
Definition mesh_render_settings.h:250
bool isWireframe(MeshRenderInfo::Wireframe w) const
Returns whether the given wireframe option is set.
Definition mesh_render_settings.h:270
bool setWireframe(MeshRenderInfo::Wireframe w, bool b=true)
Sets the given shading option of the wireframe.
Definition mesh_render_settings.h:507
bool isEdges(MeshRenderInfo::Edges e) const
Returns whether the given edges option is set.
Definition mesh_render_settings.h:295
Concept that is evaluated true if a Mesh has the Color component.
Definition mesh_requirements.h:62
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:1064
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:1389
Concept that checks if a Mesh has the per Edge Color component.
Definition edge_requirements.h:118
Concept that checks if a Mesh has the per Edge Normal component.
Definition edge_requirements.h:163
Concept that checks if a Mesh has the per Face Color component.
Definition face_requirements.h:141
Concept that checks if a Mesh has the per Face Normal component.
Definition face_requirements.h:188
Concept that checks if a Mesh has the per Face WedgeTexCoords component.
Definition face_requirements.h:300
Concept that checks if a Mesh has the per Vertex Color component.
Definition vertex_requirements.h:110
Concept that checks if a Mesh has the per Vertex Normal component.
Definition vertex_requirements.h:140
Concept that checks if a Mesh has the per Vertex TexCoord component.
Definition vertex_requirements.h:186
Concept that checks if a Mesh has the TexturePaths component.
Definition mesh_requirements.h:105
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:370
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:486
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:833
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:592
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:476