Easy3D 2.5.3
Renderer Class Reference

A Renderer manages the drawables (and thus the rendering) of a model. More...

#include <easy3d/renderer/renderer.h>

Public Member Functions

 Renderer (Model *model, bool create_drawables=true)
 Constructor. More...
 
Modelmodel ()
 The model to which this renderer is attached.
 
bool is_visible () const
 Returns whether the model is currently visible.
 
void set_visible (bool b)
 Shows/Hides the model.
 
bool is_selected () const
 Returns whether the model has been selected.
 
void set_selected (bool b)
 Select/Deselect the model. The state of all its drawables will change accordingly.
 
void update ()
 Invalidates the rendering buffers of the model and thus updates the rendering (delayed in rendering). More...
 
PointsDrawableget_points_drawable (const std::string &name) const
 
LinesDrawableget_lines_drawable (const std::string &name) const
 
TrianglesDrawableget_triangles_drawable (const std::string &name) const
 
PointsDrawableadd_points_drawable (const std::string &name)
 
LinesDrawableadd_lines_drawable (const std::string &name)
 
TrianglesDrawableadd_triangles_drawable (const std::string &name)
 
const std::vector< PointsDrawable * > & points_drawables () const
 
const std::vector< LinesDrawable * > & lines_drawables () const
 
const std::vector< TrianglesDrawable * > & triangles_drawables () const
 

Static Public Member Functions

static void create_default_drawables (Model *model)
 Create default drawables for rendering. More...
 
static void set_default_rendering_state (PointCloud *model, PointsDrawable *drawable)
 Set the default rendering state of the "vertices" drawable of a point cloud. More...
 
static void set_default_rendering_state (SurfaceMesh *model, TrianglesDrawable *drawable)
 Set the default rendering state of the "faces" drawable of a surface mesh. More...
 
template<typename FT >
static void color_from_segmentation (SurfaceMesh *mesh, SurfaceMesh::FaceProperty< FT > segments, SurfaceMesh::FaceProperty< vec3 > colors)
 Generates random colors for visualizing face-based segmentation of a SurfaceMesh. More...
 
template<typename FT >
static void color_from_segmentation (SurfaceMesh *mesh, SurfaceMesh::VertexProperty< FT > segments, SurfaceMesh::VertexProperty< vec3 > colors)
 Generates random colors for visualizing vertex-based segmentation of a SurfaceMesh. More...
 
template<typename FT >
static void color_from_segmentation (PointCloud *cloud, PointCloud::VertexProperty< FT > segments, PointCloud::VertexProperty< vec3 > colors)
 Generates random colors for visualizing the segmentation of a PointCloud. More...
 

Detailed Description

A Renderer manages the drawables (and thus the rendering) of a model.

Renderer also allow to create default drawables for most rendering purposes.

See also
Drawable, PointsDrawable, LinesDrawable, TrianglesDrawable

The following code shows how to use renderer:

// create a renderer and attach it to the model
void set_renderer(Renderer *r)
Sets the renderer of this model.
Definition: model.h:92
Model * model()
The model to which this renderer is attached.
Definition: renderer.h:89
Renderer(Model *model, bool create_drawables=true)
Constructor.
Definition: renderer.cpp:40
// don't forget to delete the renderer when the model is deleted
delete model->renderer();
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94

Constructor & Destructor Documentation

◆ Renderer()

Renderer ( Model model,
bool  create_drawables = true 
)
explicit

Constructor.

Parameters
modelThe model to which this renderer is attached.
create_drawablestrue to create default drawables for this model. Skip the creation if false. The supported default drawables are
  • PointCloud: "vertices".
  • SurfaceMesh: "faces", "vertices", "edges", and "borders".
  • Graph: "vertices", and "edges".
  • PolyMesh: "faces:border" and "faces:interior". After the model has been changed or modified (in geometry, texture, color, etc.), client code can call update() for the rendering buffers of its default drawable to be automatically updated during the rendering stage. In case the default drawables don't meet a particular visualization purpose, client code should skip the creation of the default drawables (by passing false to create_drawables). Instead, create a customized drawable and update the buffers accordingly. If the drawable changes or will be modified frequently and its visualization is expected to be automatically updated after each change, provide an update function.
See also
update(),

Member Function Documentation

◆ add_lines_drawable()

LinesDrawable * add_lines_drawable ( const std::string &  name)

Create a new lines drawable and add it to this renderer.

Parameters
nameThe name of the lines drawable to be created.
Returns
The created lines drawable. If a lines drawable with 'name' already exists, the creation will be ignored and the existing drawable is returned.
Examples
Tutorial_302_Imposters.

◆ add_points_drawable()

PointsDrawable * add_points_drawable ( const std::string &  name)

Create a new points drawable and add it to this renderer.

Parameters
nameThe name of the points drawable to be created.
Returns
The created points drawable. If a points drawable with 'name' already exists, the creation will be ignored and the existing drawable is returned.
Examples
Tutorial_302_Imposters.

◆ add_triangles_drawable()

TrianglesDrawable * add_triangles_drawable ( const std::string &  name)

Create a new triangles drawable and add it to this renderer.

Parameters
nameThe name of the triangles drawable to be created.
Returns
The created triangles drawable. If a triangles drawable with 'name' already exists, the creation will be ignored and the existing drawable is returned.
Examples
Tutorial_303_ScalarField.

◆ color_from_segmentation() [1/3]

void color_from_segmentation ( PointCloud cloud,
PointCloud::VertexProperty< FT >  segments,
PointCloud::VertexProperty< vec3 colors 
)
inlinestatic

Generates random colors for visualizing the segmentation of a PointCloud.

Parameters
cloudThe point cloud.
segmentsThe vertex property storing the segmentation of the point cloud.
Attention
The face property segments must have a type of int, {unsigned int}, std::size_t, bool, or {unsigned char}. Besides, any negative values are treated as out of range.
Parameters
colorsThe vertex property to store the colors. Must be allocated before hand.

◆ color_from_segmentation() [2/3]

void color_from_segmentation ( SurfaceMesh mesh,
SurfaceMesh::FaceProperty< FT >  segments,
SurfaceMesh::FaceProperty< vec3 colors 
)
inlinestatic

Generates random colors for visualizing face-based segmentation of a SurfaceMesh.

Parameters
meshThe surface mesh.
segmentsThe face property storing the segmentation of the surface mesh.
colorsThe face property to store the colors. Must be allocated before hand.
Attention
The face property segments must have a type of int, {unsigned int}, std::size_t, bool, or {unsigned char}. Besides, any negative values are treated as out of range.

◆ color_from_segmentation() [3/3]

void color_from_segmentation ( SurfaceMesh mesh,
SurfaceMesh::VertexProperty< FT >  segments,
SurfaceMesh::VertexProperty< vec3 colors 
)
inlinestatic

Generates random colors for visualizing vertex-based segmentation of a SurfaceMesh.

Parameters
meshThe surface mesh.
segmentsThe vertex property storing the segmentation of the surface mesh.
colorsThe vertex property to store the colors. Must be allocated before hand.
Attention
The face property segments must have a type of int, {unsigned int}, std::size_t, bool, or {unsigned char}. Besides, any negative values are treated as out of range.

◆ create_default_drawables()

void create_default_drawables ( Model model)
static

Create default drawables for rendering.

This method creates defaults drawables for rendering a model. The supported default drawables are

  • PointCloud: "vertices".
  • SurfaceMesh: "faces", "vertices", "edges", "borders".
  • Graph: "vertices", "edges". These drawables are usually sufficient for basic rendering of the model. In case the default drawables don't meet the particular visualization purpose, you can override this function or set 'create_default_drawables' to false and create the drawables by calling Model::add_[type]_drawable().

◆ get_lines_drawable()

LinesDrawable * get_lines_drawable ( const std::string &  name) const

Get the lines drawable with a given name. Return nullptr if the drawable does not exist.

Examples
Tutorial_203_Viewer_wxWidgets, Tutorial_402_FacePicker, and Tutorial_602_ConvexPartition.

◆ get_points_drawable()

◆ get_triangles_drawable()

TrianglesDrawable * get_triangles_drawable ( const std::string &  name) const

Get the triangles drawable with a given name. Return nullptr if the drawable does not exist.

Examples
Tutorial_205_MultiView, Tutorial_305_Texture, Tutorial_501_AmbientOcclusion, Tutorial_502_HardShadow, and Tutorial_503_SoftShadow.

◆ lines_drawables()

const std::vector< LinesDrawable * > & lines_drawables ( ) const
inline

All available lines drawables managed by this renderer.

◆ points_drawables()

const std::vector< PointsDrawable * > & points_drawables ( ) const
inline

All available points drawables managed by this renderer.

◆ set_default_rendering_state() [1/2]

void set_default_rendering_state ( PointCloud model,
PointsDrawable drawable 
)
static

Set the default rendering state of the "vertices" drawable of a point cloud.

The default rendering state is determined by the availability of the vertex properties. The motivation is that the most appealing rendering is demonstrated by default. The following priority applies:

  1. per-vertex color: in "v:color";
  2. per-vertex texture coordinates: in "v:texcoord";
  3. segmentation: in "v:primitive_index";
  4. scalar field; 5: uniform color.

◆ set_default_rendering_state() [2/2]

void set_default_rendering_state ( SurfaceMesh model,
TrianglesDrawable drawable 
)
static

Set the default rendering state of the "faces" drawable of a surface mesh.

The default rendering state is determined by the availability of the vertex/face properties. The motivation is that the most appealing rendering is demonstrated by default. The following priority applies: 1: per-face color: in "f:color"; 2: per-vertex color: in "v:color";

  1. per-halfedge texture coordinates: in "h:texcoord";
  2. per-vertex texture coordinates: in "v:texcoord";
  3. segmentation: in "f:chart";
  4. scalar field; 7 uniform color

◆ triangles_drawables()

const std::vector< TrianglesDrawable * > & triangles_drawables ( ) const
inline

All available triangles drawables managed by this renderer.

Examples
Tutorial_203_Viewer_wxWidgets.

◆ update()

void update ( )

Invalidates the rendering buffers of the model and thus updates the rendering (delayed in rendering).

This method triggers an update of the rendering buffers of all the drawables of the model to which this renderer is attached. The effect is equivalent to calling Drawable::update() functions for all the drawables of this model. todo: for better performance, it is wise to update only the affected drawables and buffers.

See also
Drawable::update()
Examples
Tutorial_312_MultiThread.

The documentation for this class was generated from the following files: