Easy3D 2.6.1
Loading...
Searching...
No Matches
Drawable Class Referenceabstract

The base class for drawable objects. A drawable represent a set of points, line segments, or triangles. More...

#include <easy3d/renderer/drawable.h>

Inheritance diagram for Drawable:
State LinesDrawable LinesDrawable2D PointsDrawable TrianglesDrawable

Public Types

enum  Type { DT_POINTS = 0x0000 , DT_LINES = 0x0001 , DT_TRIANGLES = 0x0004 }
 The type of the drawable. More...
 
- Public Types inherited from State
enum  Method { UNIFORM_COLOR , COLOR_PROPERTY , SCALAR_FIELD , TEXTURED }
 Available coloring methods. More...
 
enum  Location { VERTEX , FACE , EDGE , HALFEDGE }
 The location of a coloring property. More...
 

Public Member Functions

 Drawable (const std::string &name="unknown", Model *model=nullptr)
 Constructor that initializes the drawable with a name and an optional model.
 
 ~Drawable () override
 Destructor.
 
virtual Type type () const =0
 Returns the type of the drawable.
 
const std::string & name () const
 Returns the name of the drawable.
 
void set_name (const std::string &n)
 Sets the name of the drawable.
 
Modelmodel ()
 Returns the model to which the drawable is attached.
 
const Modelmodel () const
 Returns the model to which the drawable is attached (const version).
 
void set_model (Model *m)
 Sets the model to which the drawable is attached.
 
const Box3bounding_box () const
 Returns the bounding box of the drawable.
 
Statestate ()
 Returns the state of the drawable.
 
const Statestate () const
 Returns the state of the drawable (const version).
 
void set_state (const State &s)
 Sets the state of the drawable.
 
void buffer_stats (std::ostream &output) const
 Prints statistics of the buffers to an output stream.
 
std::size_t num_vertices () const
 Returns the number of vertices.
 
VertexArrayObjectvao ()
 Returns the vertex array object of this drawable.
 
const VertexArrayObjectvao () const
 Returns the vertex array object of this drawable (const version).
 
Buffer access and management
unsigned int vertex_buffer () const
 Returns the vertex buffer ID.
 
unsigned int color_buffer () const
 Returns the color buffer ID.
 
unsigned int normal_buffer () const
 Returns the normal buffer ID.
 
unsigned int texcoord_buffer () const
 Returns the texture coordinate buffer ID.
 
unsigned int element_buffer () const
 Returns the element buffer ID.
 
void update_vertex_buffer (const std::vector< vec3 > &vertices, bool dynamic=false)
 Creates/Updates the vertex buffer.
 
void update_color_buffer (const std::vector< vec3 > &colors, bool dynamic=false)
 Creates/Updates the color buffer.
 
void update_normal_buffer (const std::vector< vec3 > &normals, bool dynamic=false)
 Updates the normal buffer.
 
void update_texcoord_buffer (const std::vector< vec2 > &texcoords, bool dynamic=false)
 Updates the texture coordinate buffer.
 
void update_element_buffer (const std::vector< unsigned int > &elements)
 Updates the element buffer.
 
void update_element_buffer (const std::vector< std::vector< unsigned int > > &elements)
 Updates the element buffer.
 
void disable_element_buffer ()
 Disables the use of the element buffer.
 
Rendering
virtual void draw (const Camera *camera) const =0
 Draws the drawable.
 
void gl_draw () const
 Draws the drawable using OpenGL.
 
void update ()
 Requests an update of the OpenGL buffers.
 
void set_update_func (const std::function< void(Model *, Drawable *)> &func)
 Sets the update function for the drawable.
 
Manipulation
Manipulatormanipulator ()
 Returns the manipulator attached to this drawable.
 
const Manipulatormanipulator () const
 Returns the manipulator attached to this drawable (const version).
 
void set_manipulator (std::shared_ptr< Manipulator > manip)
 Attaches a manipulator to this drawable.
 
mat4 manipulated_matrix () const
 Returns the manipulation matrix.
 
- Public Member Functions inherited from State
 State ()
 Default constructor.
 
 State (const State &s)
 Copy constructor.
 
Stateoperator= (const State &rhs)
 Assignment operator.
 
virtual ~State ()=default
 Virtual destructor.
 
bool is_visible () const
 Checks if the drawable is visible.
 
void set_visible (bool v)
 Sets the visibility of the drawable.
 
bool is_selected () const
 Checks if the drawable is selected.
 
void set_selected (bool b)
 Sets the selection state of the drawable.
 
void set_uniform_coloring (const vec4 &color)
 Constructs a uniform coloring scheme.
 
void set_property_coloring (Location color_location, const std::string &color_name="")
 Constructs a scheme for rendering a drawable with per-element color.
 
void set_texture_coloring (Location texcoord_location, const std::string &texcoord_name, const Texture *texture=nullptr, float repeat=1.0f, float repeat_fraction=0.0f)
 Constructs a scheme for textured rendering.
 
void set_scalar_coloring (Location scalar_location, const std::string &scalar_name, const Texture *texture=nullptr, float clamp_lower=0.05f, float clamp_upper=0.05f)
 Constructs a scheme for rendering scalar fields.
 
void set_coloring (Method method, Location location, const std::string &name)
 Sets the coloring.
 
void set_coloring_method (Method method)
 Sets the coloring method.
 
Method coloring_method () const
 Returns the coloring method being used for rendering.
 
const vec4color () const
 Returns the color, which is effective only when the coloring method was set to UNIFORM_COLOR.
 
void set_color (const vec4 &c)
 Sets the color.
 
Location property_location () const
 Returns the location of the color property.
 
const std::string & property_name () const
 Returns the name of the color attribute.
 
bool lighting () const
 Checks if lighting is enabled.
 
void set_lighting (bool l)
 Enables or disables lighting.
 
bool lighting_two_sides () const
 Checks if double-sided lighting is enabled.
 
void set_lighting_two_sides (bool b)
 Enables or disables double-sided lighting.
 
bool distinct_back_color () const
 Checks if a different color is used for rendering the backside of a drawable.
 
void set_distinct_back_color (bool b)
 Enables or disables different backside color.
 
const vec4back_color () const
 Returns the backside color.
 
void set_back_color (const vec4 &c)
 Sets the backside color.
 
const Texturetexture () const
 Returns the texture.
 
void set_texture (const Texture *tex)
 Sets the texture.
 
float texture_repeat () const
 Returns the repeat factor of the texture.
 
void set_texture_repeat (float r)
 Sets the repeat factor of the texture.
 
float texture_fractional_repeat () const
 Returns the fractional repeat factor of the texture.
 
void set_texture_fractional_repeat (float fr)
 Sets the fractional repeat factor of the texture.
 
bool is_ssao_enabled () const
 Checks if SSAO is enabled.
 
void enable_ssao (bool b)
 Enables or disables SSAO.
 
void set_ssao_texture (unsigned int tex)
 Sets the SSAO texture.
 
bool clamp_range () const
 Checks if the value range of a scalar field is clamped.
 
void set_clamp_range (bool b)
 Sets the clamping of the value range of a scalar field.
 
float clamp_lower () const
 Returns the percentage of values clamped at the lower side of the range.
 
void set_clamp_lower (float v)
 Sets the percentage of values clamped at the lower side of the range.
 
float clamp_upper () const
 Returns the percentage of values clamped at the upper side of the range.
 
void set_clamp_upper (float v)
 Sets the percentage of values clamped at the upper side of the range.
 
Materialmaterial ()
 Returns the material.
 
const Materialmaterial () const
 Returns the material (const version).
 
void set_material (const Material &m)
 Sets the material.
 
bool plane_clip_discard_primitive () const
 Controls the behavior for vertex clipping.
 
void set_plane_clip_discard_primitive (bool b)
 Sets the behavior for vertex clipping.
 
bool highlight () const
 Checks if a subset of primitives of this drawable is highlighted.
 
void set_highlight (bool b)
 Sets the highlight state of a subset of primitives of this drawable.
 
void set_highlight_range (const std::pair< int, int > &range)
 Sets the range of primitives to be highlighted.
 
const std::pair< int, int > & highlight_range () const
 Returns the range of primitives to be highlighted.
 

Detailed Description

The base class for drawable objects. A drawable represent a set of points, line segments, or triangles.

A Drawable is an abstraction for "something that can be drawn", e.g., a point cloud, the surface of a mesh, the wireframe of a surface mesh, the vertices of a graph, the border of a polyhedral mesh. A drawable manages its rendering status and controls the upload of the data to the GPU. A drawable can live independently or be associated with a Model. A drawable is considered standalone if its associated Model is null. The rendering states of a drawable can be accessed/modified through the functions provided in its parent class State.

See also
State, Renderer, PointsDrawable, LinesDrawable, TrianglesDrawable, and LinesDrawable2D.
Examples
Tutorial_301_Drawables/main.cpp.

Member Enumeration Documentation

◆ Type

enum Type

The type of the drawable.

Enumerator
DT_POINTS 

Points drawable (GL_POINTS).

DT_LINES 

Lines drawable (GL_LINES).

DT_TRIANGLES 

Triangles drawable (GL_TRIANGLES).

Constructor & Destructor Documentation

◆ Drawable()

Drawable ( const std::string & name = "unknown",
Model * model = nullptr )
explicit

Constructor that initializes the drawable with a name and an optional model.

Parameters
nameThe name of the drawable.
modelThe model to which the drawable is attached (can be nullptr).

Member Function Documentation

◆ bounding_box()

const Box3 & bounding_box ( ) const

Returns the bounding box of the drawable.

Returns
The bounding box of the drawable.

◆ buffer_stats()

void buffer_stats ( std::ostream & output) const

Prints statistics of the buffers to an output stream.

Parameters
outputThe output stream (e.g., std::cout).

◆ color_buffer()

unsigned int color_buffer ( ) const
inline

Returns the color buffer ID.

Returns
The color buffer ID.

◆ disable_element_buffer()

void disable_element_buffer ( )

Disables the use of the element buffer.

This method should be used if existing vertex data is sufficient for rendering (may require duplicating vertex data). This method also releases the element buffer.

◆ draw()

virtual void draw ( const Camera * camera) const
pure virtual

Draws the drawable.

Parameters
cameraThe camera used for rendering.

Implemented in LinesDrawable2D, LinesDrawable, PointsDrawable, and TrianglesDrawable.

◆ element_buffer()

unsigned int element_buffer ( ) const
inline

Returns the element buffer ID.

Returns
The element buffer ID.

◆ gl_draw()

void gl_draw ( ) const

Draws the drawable using OpenGL.

This function should be called when your shader program is in use, i.e., between glUseProgram(id) and glUseProgram(0).

◆ manipulated_matrix()

mat4 manipulated_matrix ( ) const

Returns the manipulation matrix.

Returns
The manipulation matrix.

◆ manipulator() [1/2]

Manipulator * manipulator ( )

Returns the manipulator attached to this drawable.

If the drawable is part of a model, it returns the model's manipulator. Returns nullptr if the drawable cannot be manipulated.

Returns
The manipulator attached to this drawable.

◆ manipulator() [2/2]

const Manipulator * manipulator ( ) const

Returns the manipulator attached to this drawable (const version).

If the drawable is part of a model, it returns the model's manipulator. Returns nullptr if the drawable cannot be manipulated.

Returns
The manipulator attached to this drawable.

◆ model() [1/2]

Model * model ( )
inline

Returns the model to which the drawable is attached.

Returns
The model to which the drawable is attached (can be nullptr).

◆ model() [2/2]

const Model * model ( ) const
inline

Returns the model to which the drawable is attached (const version).

Returns
The model to which the drawable is attached (can be nullptr).

◆ name()

const std::string & name ( ) const
inline

Returns the name of the drawable.

Returns
The name of the drawable.

◆ normal_buffer()

unsigned int normal_buffer ( ) const
inline

Returns the normal buffer ID.

Returns
The normal buffer ID.

◆ num_vertices()

std::size_t num_vertices ( ) const
inline

Returns the number of vertices.

Returns
The number of vertices.

◆ set_manipulator()

void set_manipulator ( std::shared_ptr< Manipulator > manip)
inline

Attaches a manipulator to this drawable.

This is used to manipulate a drawable that is not part of a model.

Parameters
manipThe manipulator to attach.

◆ set_model()

void set_model ( Model * m)
inline

Sets the model to which the drawable is attached.

Parameters
mThe model to which the drawable is attached.

◆ set_name()

void set_name ( const std::string & n)
inline

Sets the name of the drawable.

Parameters
nThe new name of the drawable.

◆ set_state()

void set_state ( const State & s)
inline

Sets the state of the drawable.

Parameters
sThe new state of the drawable.

◆ set_update_func()

void set_update_func ( const std::function< void(Model *, Drawable *)> & func)
inline

Sets the update function for the drawable.

The update function defines how a drawable updates its rendering buffers. It is required by only non-standard drawables for a special visualization purpose. Rendering buffers of standard drawables attached to a model can be automatically updated and do not require this function. For a subclassed drawable, you can also reimplement update_buffers_internal() for the same purpose.

Parameters
funcThe update function.
See also
update(), Renderer::update().

◆ state() [1/2]

State & state ( )
inline

Returns the state of the drawable.

Returns
The state of the drawable.

◆ state() [2/2]

const State & state ( ) const
inline

Returns the state of the drawable (const version).

Returns
The state of the drawable.

◆ texcoord_buffer()

unsigned int texcoord_buffer ( ) const
inline

Returns the texture coordinate buffer ID.

Returns
The texture coordinate buffer ID.

◆ type()

virtual Type type ( ) const
pure virtual

Returns the type of the drawable.

Returns
The type of the drawable.

Implemented in LinesDrawable2D, LinesDrawable, PointsDrawable, and TrianglesDrawable.

◆ update()

void update ( )

Requests an update of the OpenGL buffers.

This function sets the status to trigger an update of the OpenGL buffers. The actual update does not occur immediately but is deferred to the rendering phase.

Note
This method works for both standard drawables (no update function required) and non-standard drawable (update function required). Standard drawables include:
  • SurfaceMesh: "faces", "edges", "vertices", "borders", and "locks";
  • PointCloud: "vertices";
  • Graph: "edges", and "vertices",
  • PolyMesh: "faces:border" and "faces:interior".
See also
set_update_func(), Renderer::update()

◆ update_color_buffer()

void update_color_buffer ( const std::vector< vec3 > & colors,
bool dynamic = false )

Creates/Updates the color buffer.

Parameters
colorsThe new color data.
dynamicWhether the buffer is dynamic.
Examples
Tutorial_310_TextMesher/main.cpp.

◆ update_element_buffer() [1/2]

void update_element_buffer ( const std::vector< std::vector< unsigned int > > & elements)

Updates the element buffer.

This is an overload of the above update_element_buffer() method.

Parameters
elementsThe new element data.
Note
Each entry must have 2 (for LinesDrawable) or 3 elements (for TrianglesDrawable).

◆ update_element_buffer() [2/2]

void update_element_buffer ( const std::vector< unsigned int > & elements)

Updates the element buffer.

Primitives like lines and triangles can be drawn with or without the element buffer.

  • With an element buffer: this can reduce the GPU memory consumption.
  • Without an element buffer: easier data transfer, but uses more GPU memory. In this case, vertices need to be in a correct order, like f1_v1, f1_v2, f1_v3, f2_v1, f2_v2, f2_v3... This requires the shared vertices be duplicated in the vertex buffer.
    Parameters
    elementsThe new element data.
Examples
Tutorial_301_Drawables/main.cpp, and Tutorial_310_TextMesher/main.cpp.

◆ update_normal_buffer()

void update_normal_buffer ( const std::vector< vec3 > & normals,
bool dynamic = false )

Updates the normal buffer.

Parameters
normalsThe new normal data.
dynamicWhether the buffer is dynamic.

◆ update_texcoord_buffer()

void update_texcoord_buffer ( const std::vector< vec2 > & texcoords,
bool dynamic = false )

Updates the texture coordinate buffer.

Parameters
texcoordsThe new texture coordinate data.
dynamicWhether the buffer is dynamic.

◆ update_vertex_buffer()

void update_vertex_buffer ( const std::vector< vec3 > & vertices,
bool dynamic = false )

Creates/Updates the vertex buffer.

Parameters
verticesThe new vertex data.
dynamicWhether the buffer is dynamic.
Examples
Tutorial_301_Drawables/main.cpp, and Tutorial_310_TextMesher/main.cpp.

◆ vao() [1/2]

VertexArrayObject * vao ( )
inline

Returns the vertex array object of this drawable.

Returns
The vertex array object.

◆ vao() [2/2]

const VertexArrayObject * vao ( ) const
inline

Returns the vertex array object of this drawable (const version).

Returns
The vertex array object.

◆ vertex_buffer()

unsigned int vertex_buffer ( ) const
inline

Returns the vertex buffer ID.

Returns
The vertex buffer ID.

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