Geogram
Version 1.9.1
A programming library of geometric algorithms
|
Draws a mesh using OpenGL. More...
#include <geogram_gfx/mesh/mesh_gfx.h>
Classes | |
struct | Filter |
Filters primitives based on their id and on an attribute. More... | |
Public Member Functions | |
MeshGfx () | |
MeshGfx constructor. | |
~MeshGfx () | |
MeshGfx destructor. | |
MeshGfx (const MeshGfx &rhs)=delete | |
Forbids MeshGfx copy.. | |
MeshGfx & | operator= (const MeshGfx &rhs)=delete |
Forbids MeshGfx copy.. | |
void | draw_vertices () |
Draws the vertices of the mesh. More... | |
void | draw_edges () |
Draws the edges of the mesh. | |
void | draw_surface () |
Draws the surfacic part of the mesh. | |
void | draw_surface_borders () |
Draws the borders of the surfacic part of the mesh. | |
void | draw_volume () |
Draws the volumetric part of the mesh. | |
bool | get_show_mesh () const |
Gets the mesh visibility flag. More... | |
void | set_show_mesh (bool x) |
Sets the mesh visibility flag. More... | |
index_t | get_mesh_width () const |
Gets the mesh width. More... | |
void | set_mesh_width (index_t x) |
Sets the mesh width. More... | |
index_t | get_mesh_border_width () const |
Gets the mesh border width. More... | |
void | set_mesh_border_width (index_t x) |
Sets the mesh border width. More... | |
double | get_shrink () const |
Gets the cells shrink coefficient. More... | |
void | set_shrink (double x) |
Sets the cells shrink coefficient. More... | |
bool | get_animate () const |
Gets the animate flag. More... | |
void | set_animate (bool x) |
Gets the animate flag. More... | |
double | get_time () const |
Gets the time of the animation. More... | |
void | set_time (double x) |
Gets the time of the animation. More... | |
bool | get_draw_cells (MeshCellType type) const |
Gets the cell visibility flag. More... | |
void | set_draw_cells (MeshCellType type, bool x) |
Sets the cell visibility flag. More... | |
void | set_points_color (float r, float g, float b, float a=1.0f) |
Sets the points color. More... | |
void | get_points_color (float &r, float &g, float &b, float &a) const |
Gets the points color. More... | |
void | set_points_size (float x) |
Sets the point size. More... | |
float | get_points_size () const |
Gets the point size. More... | |
void | set_mesh_color (float r, float g, float b, float a=1.0f) |
Sets the mesh color. More... | |
void | get_mesh_color (float &r, float &g, float &b, float &a) const |
Gets the mesh color. More... | |
void | set_surface_color (float r, float g, float b, float a=1.0f) |
Sets the surface color. More... | |
void | get_surface_color (float &r, float &g, float &b, float &a) const |
Gets the surface color. More... | |
void | set_backface_surface_color (float r, float g, float b, float a=1.0f) |
Sets the surface color for backfacing faces. More... | |
void | set_cells_color (float r, float g, float b, float a=1.0f) |
Sets the color used to display mesh cells. More... | |
void | get_cells_color (float &r, float &g, float &b, float &a) const |
Gets the cells color. More... | |
void | set_cells_colors_by_type () |
Sets a different color for each mesh cell type. More... | |
bool | get_lighting () const |
Gets the lighing flag. More... | |
void | set_lighting (bool x) |
Sets the lighting flag. More... | |
void | set_mesh (const Mesh *M) |
Sets the mesh. More... | |
const Mesh * | mesh () const |
Gets the mesh. More... | |
void | set_picking_mode (MeshElementsFlags what) |
Sets picking mode. More... | |
MeshElementsFlags | get_picking_mode () const |
Gets the current picking mode. More... | |
void | set_object_picking_id (index_t id) |
Sets the object-wide picking id. More... | |
index_t | get_object_picking_id () const |
Gets the object-wide picking id. More... | |
void | set_vertices_selection (const std::string &name) |
Sets the vertices selection. More... | |
const std::string & | get_vertices_selection () const |
Gets the vertices selection. More... | |
void | set_scalar_attribute (MeshElementsFlags subelements, const std::string &name, double attr_min, double attr_max, GLuint colormap_texture, index_t repeat=1) |
Sets the parameters for displaying a scalar attribute using texture mapping. More... | |
void | set_texturing (MeshElementsFlags subelements, const std::string &attribute_name, GLuint texture, index_t texture_dim, index_t repeat=1) |
Sets the parameters for texture mapping. More... | |
void | unset_scalar_attribute () |
Unsets scalar attribute display. | |
void | set_filter (MeshElementsFlags subelements, const std::string &name="filter") |
Sets primitive filtering. More... | |
void | unset_filters () |
Unset primitive filtering. | |
void | cleanup () |
Deallocates OpenGL objects. | |
Protected Member Functions | |
void | draw_vertices_array () |
void | draw_vertices_immediate_plain () |
void | draw_vertices_immediate_attrib () |
void | draw_vertices_selection () |
void | draw_edges_array () |
void | draw_edges_immediate_plain () |
void | draw_edges_immediate_attrib () |
void | draw_triangles () |
void | draw_triangles_array () |
void | draw_triangles_immediate_plain () |
void | draw_triangles_immediate_attrib () |
void | draw_quads () |
void | draw_quads_array () |
void | draw_quads_immediate_plain () |
void | draw_quads_immediate_attrib () |
void | draw_triangles_and_quads () |
void | draw_triangles_and_quads_array () |
void | draw_triangles_and_quads_immediate_plain () |
void | draw_triangles_and_quads_immediate_attrib () |
void | draw_polygons () |
void | draw_polygons_plain () |
void | draw_polygons_attrib () |
void | draw_tets () |
void | draw_tets_array () |
void | draw_tets_immediate_plain () |
void | draw_tets_immediate_attrib () |
void | draw_hybrid () |
void | draw_hybrid_array () |
void | draw_hybrid_immediate_plain () |
void | draw_hybrid_immediate_attrib () |
void | set_cells_color (MeshCellType type, float r, float g, float b) |
void | draw_attribute_as_tex_coord (index_t element) |
void | draw_vertex_with_attribute (index_t vertex) |
void | draw_surface_vertex_with_attribute (index_t vertex, index_t facet, index_t corner) |
void | draw_volume_vertex_with_attribute (index_t vertex, index_t cell, index_t cell_corner) |
void | draw_vertex (index_t v) |
void | draw_surface_mesh_with_lines () |
void | set_GLUP_parameters () |
Sets GLUP drawing parameters. | |
void | set_GLUP_picking (MeshElementsFlags what) |
Sets GLUP picking mode for drawing primitives of a given type, or deactivates GLUP picking if MeshGfx picking mode is deactivated. More... | |
void | set_GLUP_vertex_color_from_picking_id (index_t id) |
Encodes an id as the current vertex color. More... | |
void | update_buffer_objects_if_needed () |
Updates the Vertex Buffer Objects and Vertex Array Objects. More... | |
void | update_attribute_buffer_objects_if_needed () |
Updates the buffer objects used to display attributes. More... | |
void | bind_attribute_buffer_object (GLuint VAO) |
Binds the attribute buffer object to a Vertex Array Object. More... | |
void | unbind_attribute_buffer_object (GLuint VAO) |
Unbinds the attribute buffer object from a Vertex Array Object. More... | |
void | bind_vertices_VBO () |
Binds the vertices VBO to the current VAO. | |
void | begin_attributes () |
Setups drawing for attributes. More... | |
void | end_attributes () |
Deactivates drawing for attributes. | |
bool | can_use_array_mode (GLUPprimitive prim) const |
Tests whether array mode can be used to draw a specified GLUP primitive. More... | |
void | update_surface_elements () |
void | update_volume_elements () |
bool | hw_filtering_supported () const |
Tests whether hardware primitive filtering is supported. More... | |
void | draw_sequences (const MeshSubElementsStore &elements, std::function< void(index_t, index_t)> draw) |
Generic function to extract element sequences to draw. More... | |
void | draw_sequences_if (const MeshSubElementsStore &elements, std::function< bool(index_t)> predicate, std::function< void(index_t, index_t)> draw) |
Generic function to extract element sequences to draw. More... | |
Protected Attributes | |
bool | show_mesh_ |
index_t | mesh_width_ |
index_t | mesh_border_width_ |
double | shrink_ |
bool | animate_ |
double | time_ |
bool | draw_cells_ [MESH_NB_CELL_TYPES] |
float | points_size_ |
float | points_color_ [4] |
float | mesh_color_ [4] |
float | surface_color_ [4] |
float | backface_surface_color_ [4] |
float | cells_color_ [MESH_NB_CELL_TYPES][4] |
bool | cells_colors_by_type_ |
bool | lighting_ |
MeshElementsFlags | picking_mode_ |
index_t | object_picking_id_ |
std::string | vertices_selection_ |
bool | do_animation_ |
const Mesh * | mesh_ |
bool | triangles_and_quads_ |
bool | quads_ |
bool | has_cells_ [MESH_NB_CELL_TYPES] |
bool | buffer_objects_dirty_ |
bool | attributes_buffer_objects_dirty_ |
bool | long_vector_attribute_ |
GLuint | vertices_VAO_ |
GLuint | edges_VAO_ |
GLuint | facets_VAO_ |
GLuint | cells_VAO_ |
GLuint | vertices_VBO_ |
GLuint | edge_indices_VBO_ |
GLuint | facet_indices_VBO_ |
GLuint | cell_indices_VBO_ |
GLuint | vertices_attribute_VBO_ |
MeshElementsFlags | attribute_subelements_ |
std::string | attribute_name_ |
index_t | attribute_dim_ |
double | attribute_min_ |
double | attribute_max_ |
GLuint | attribute_texture_ |
index_t | attribute_texture_dim_ |
index_t | attribute_repeat_ |
ReadOnlyScalarAttributeAdapter | scalar_attribute_ |
ReadOnlyScalarAttributeAdapter | tex_coord_attribute_ [3] |
bool | ES_profile_ |
Filter | vertices_filter_ |
Filter | facets_filter_ |
Filter | cells_filter_ |
Draws a mesh using OpenGL.
Definition at line 60 of file mesh_gfx.h.
|
protected |
Setups drawing for attributes.
If no attribute is bound, does nothing.
|
protected |
Binds the attribute buffer object to a Vertex Array Object.
[in] | VAO | one of vertices_VAO_, edges_VAO_, facets_VAO_ or cells_VAO_. If zero, the function does nothing. |
|
protected |
Tests whether array mode can be used to draw a specified GLUP primitive.
[in] | prim | the GLUP primitive |
|
inlineprotected |
Generic function to extract element sequences to draw.
Tests the filter if set, and finds all intervals of primitives to render. For each interval, it calls glupBasePickingId(GLUPuint64(begin)) so that picking Ids are correct.
[in] | elements | the MeshSubElementsStore to render |
[in] | draw | the function to be called for each (begin,end) sequence of elements to be drawn, where begin is the index of the first element, and end one position past the index of the last element. |
Definition at line 1023 of file mesh_gfx.h.
|
inlineprotected |
Generic function to extract element sequences to draw.
Tests the filter if set, and finds all intervals of primitives to render. For each interval, it calls glupBasePickingId(GLUPuint64(begin)) so that picking Ids are correct.
[in] | elements | the MeshSubElementsStore to render |
[in] | predicate | a function that tests which elements should be drawn or not |
[in] | draw | the function to be called for each (begin,end) sequence of elements to be drawn, where begin is the index of the first element, and end one position past the index of the last element. |
Definition at line 1077 of file mesh_gfx.h.
void GEO::MeshGfx::draw_vertices | ( | ) |
Draws the vertices of the mesh.
If a vertices selection is set, only the vertices in the selection are drawn
|
inline |
Gets the animate flag.
When animate mode is activated and the mesh has 6d vertices, then an animation is displayed. The first three coordinates correspond to the vertex position at initial time (t=0). The last three coordinates correspond to the vertex position at final time (t=1).
true | if animation is used |
false | otherwise |
Definition at line 220 of file mesh_gfx.h.
|
inline |
Gets the cells color.
[out] | r,g,b,a | the components of the cells color, in (0.0 .. 1.0) |
Definition at line 434 of file mesh_gfx.h.
|
inline |
Gets the cell visibility flag.
It is possible to specify cell visibility flags for each individual cell type.
[in] | type | one of MESH_TET, MESH_HEX, MESH_PRISM, MESH_PYRAMID |
true | if the cells of type should be displayed |
false | otherwise |
Definition at line 273 of file mesh_gfx.h.
|
inline |
Gets the lighing flag.
true | if lighting should be used |
false | otherwise |
Definition at line 464 of file mesh_gfx.h.
|
inline |
Gets the mesh border width.
The mesh border width is the one used by draw_surface_borders()
Definition at line 165 of file mesh_gfx.h.
|
inline |
Gets the mesh color.
[out] | r,g,b,a | the components of the mesh color, in (0.0 .. 1.0) |
Definition at line 356 of file mesh_gfx.h.
|
inline |
Gets the mesh width.
The mesh width is taken into account when the mesh visibility flag is set (by set_show_mesh()), when drawing facets and cells.
Definition at line 143 of file mesh_gfx.h.
|
inline |
Gets the object-wide picking id.
Definition at line 534 of file mesh_gfx.h.
|
inline |
Gets the current picking mode.
Definition at line 513 of file mesh_gfx.h.
|
inline |
Gets the points color.
[out] | r,g,b,a | the components of the points color, in (0.0 .. 1.0) |
Definition at line 310 of file mesh_gfx.h.
|
inline |
Gets the point size.
Definition at line 331 of file mesh_gfx.h.
|
inline |
Gets the mesh visibility flag.
The mesh visibility flags specifies whether mesh edges should be drawn. The used color can be specified by set_mesh_color()
true | if mesh edges should be displayed |
false | otherwise |
Definition at line 120 of file mesh_gfx.h.
|
inline |
Gets the cells shrink coefficient.
The cells shrink coefficient is used to display cells slighly smaller than what they are. Cells shrinking is only supported in GLSL mode.
Definition at line 187 of file mesh_gfx.h.
|
inline |
Gets the surface color.
[out] | r,g,b,a | the components of the surface color, in (0.0 .. 1.0) |
Definition at line 389 of file mesh_gfx.h.
|
inline |
Gets the time of the animation.
Used if animate mode is set.
Definition at line 245 of file mesh_gfx.h.
|
inline |
Gets the vertices selection.
Definition at line 555 of file mesh_gfx.h.
|
protected |
Tests whether hardware primitive filtering is supported.
On some higher profiles (GLUP150, GLUP440), it is possible to filter primitives in the shaders. It reduces GPU transfers by making it possible to reuse the same VBOs even when the list of objects to display changes.
|
inline |
Gets the mesh.
Definition at line 488 of file mesh_gfx.h.
|
inline |
Gets the animate flag.
When animate mode is activated and the mesh has 6d vertices, then an animation is displayed. The first three coordinates correspond to the vertex position at initial time (t=0). The last three coordinates correspond to the vertex position at final time (t=1).
[in] | x | true if animation should be used, false otherwise |
Definition at line 234 of file mesh_gfx.h.
|
inline |
Sets the surface color for backfacing faces.
Specifies the color used to display the backfaces of the surfacic part of the mesh.
[in] | r,g,b,a | the components of the surface color, in (0.0 .. 1.0) |
Definition at line 404 of file mesh_gfx.h.
|
inline |
Sets the color used to display mesh cells.
[in] | r,g,b,a | the components of the cells color, in (0.0 .. 1.0) |
Definition at line 419 of file mesh_gfx.h.
|
inline |
Sets a different color for each mesh cell type.
it uses the following colors:
Definition at line 450 of file mesh_gfx.h.
|
inline |
Sets the cell visibility flag.
It is possible to specify cell visibility flags for each individual cell type.
[in] | type | one of MESH_TET, MESH_HEX, MESH_PRISM, MESH_PYRAMID |
[in] | x | true if mesh cells of type type should be displayed, false otherwise. |
Definition at line 286 of file mesh_gfx.h.
void GEO::MeshGfx::set_filter | ( | MeshElementsFlags | subelements, |
const std::string & | name = "filter" |
||
) |
Sets primitive filtering.
Primitive filtering deactivates display of some primitives based on their id and an attribute. The attribute is of type Numeric::uint8. If the attribute value is zero, then the corresponding primitive is not displayed.
[in] | subelements | one of MESH_VERTICES, MESH_FACETS, MESH_CELLS, MESH_ALL_ELEMENTS |
[in] | name | the name of the attribute with the filter. Default is "filter" |
|
protected |
Sets GLUP picking mode for drawing primitives of a given type, or deactivates GLUP picking if MeshGfx picking mode is deactivated.
[in] | what | one of MESH_VERTICES, MESH_EDGES, MESH_FACETS, MESH_CELLS. |
|
protected |
Encodes an id as the current vertex color.
This is required for drawing polygons, that cannot use standard GLUP primitives and picking.
|
inline |
Sets the lighting flag.
[in] | x | true if lighting should be used, false otherwise. |
Definition at line 473 of file mesh_gfx.h.
void GEO::MeshGfx::set_mesh | ( | const Mesh * | M | ) |
Sets the mesh.
[in] | M | a pointer to the mesh that should be displayed. |
|
inline |
Sets the mesh border width.
The mesh border width is the one used by draw_surface_borders()
[in] | x | the mesh width (minimum is 1) |
Definition at line 175 of file mesh_gfx.h.
|
inline |
Sets the mesh color.
Specifies the mesh color to be used if mesh edges should be displayed.
[in] | r,g,b,a | the components of the mesh color, in (0.0 .. 1.0) |
Definition at line 343 of file mesh_gfx.h.
|
inline |
Sets the mesh width.
The mesh width is taken into account when the mesh visibility flag is set (by set_show_mesh()), when drawing facets and cells.
[in] | x | the mesh width (minimum is 1) |
Definition at line 155 of file mesh_gfx.h.
|
inline |
Sets the object-wide picking id.
When the object-wide picking id is set, it is used to draw all primitives in the picking buffer.
[in] | id | the object-wide picking id, or index_t(-1) if normal per-primitive picking should be used. |
Definition at line 525 of file mesh_gfx.h.
|
inline |
Sets picking mode.
If picking mode is MESH_NONE, then normal drawing is activated, else the color is replaced with the index of the elements.
[in] | what | a bitwise or ('|') combination of MESH_VERTICES, MESH_EDGES, MESH_FACETS, MESH_CELLS, or MESH_NONE if picking mode should be deactivated |
Definition at line 503 of file mesh_gfx.h.
|
inline |
Sets the points color.
Specifies the color used to display points
[in] | r,g,b,a | the components of the points color, in (0.0 .. 1.0) |
Definition at line 297 of file mesh_gfx.h.
|
inline |
Sets the point size.
[in] | x | the point size (minimum 1) |
Definition at line 322 of file mesh_gfx.h.
void GEO::MeshGfx::set_scalar_attribute | ( | MeshElementsFlags | subelements, |
const std::string & | name, | ||
double | attr_min, | ||
double | attr_max, | ||
GLuint | colormap_texture, | ||
index_t | repeat = 1 |
||
) |
Sets the parameters for displaying a scalar attribute using texture mapping.
[in] | subelements | one of MESH_VERTICES, MESH_FACETS, MESH_FACET_CORNERS, MESH_CELLS, MESH_CELL_CORNERS, MESH_CELL_FACETS |
[in] | name | name of the attribute with an optional index, for instance, "foobar[5]" refers to the 5th coordinate of the "foobar" vector attribute. |
[in] | attr_min | value of the attribute that is bound to the leftmost color in the colormap |
[in] | attr_max | value of the attribute that is bound to the rightmost color in the colormap |
[in] | colormap_texture | the texture to be used to display the attribute colors |
[in] | repeat | the number of times the colorramp should be repeated within the specified range. |
|
inline |
Sets the mesh visibility flag.
[in] | x | the new value of the mesh visibility flag. |
The mesh visibility flags specifies whether mesh edges should be drawn. The used color can be specified by set_mesh_color()
Definition at line 131 of file mesh_gfx.h.
|
inline |
Sets the cells shrink coefficient.
The cells shrink coefficient is used to display cells slighly smaller than what they are. Cells shrinking is only supported in GLSL mode.
[in] | x | the cells shrink coefficient, betwe 0.0 (no shrink) and 1.0 (full shrink) |
Definition at line 199 of file mesh_gfx.h.
|
inline |
Sets the surface color.
Specifies the color used to display the surfacic part of the mesh. It specifies the color of both frontfacing and backfacing faces.
[in] | r,g,b,a | the components of the surface color, in (0.0 .. 1.0) |
Definition at line 372 of file mesh_gfx.h.
void GEO::MeshGfx::set_texturing | ( | MeshElementsFlags | subelements, |
const std::string & | attribute_name, | ||
GLuint | texture, | ||
index_t | texture_dim, | ||
index_t | repeat = 1 |
||
) |
Sets the parameters for texture mapping.
[in] | subelements | the subelements that have texture coordinates. |
[in] | attribute_name | the name of the attribute that has the texture coordinates. Can be a 2d or 3d vector attribute. |
[in] | texture | the texture. |
[in] | repeat | the number of times the texture should be repeated in the unit square in texture space. |
|
inline |
Gets the time of the animation.
Used if animate mode is set.
[in] | x | the time of the animation, betwe 0.0 (initial) and 1.0 (final) |
Definition at line 256 of file mesh_gfx.h.
|
inline |
Sets the vertices selection.
If set, the vertices selection is used to determine which vertices should be drawn by draw_vertices().
[in] | name | the name of a Property<bool> bound to the vertices of the mesh. |
Definition at line 546 of file mesh_gfx.h.
|
protected |
Unbinds the attribute buffer object from a Vertex Array Object.
[in] | VAO | one of vertices_VAO_, edges_VAO_, facets_VAO_ or cells_VAO_. If zero, the function does nothing. |
|
protected |
Updates the buffer objects used to display attributes.
The buffer objects are updated if attribute_buffer_objects_dirty_ is set, then attribute_buffer_objects_dirty_ is reset. If attribute_buffer_objects_dirty_ is not set, it checks whether the sizes of the buffer objects match the size of the mesh arrays.
|
protected |
Updates the Vertex Buffer Objects and Vertex Array Objects.
The buffer objects are updated if buffer_objects_dirty_ is set, then buffer_objects_dirty_ is reset. If buffer_objects_dirty_ is not set, it checks whether the sizes of the buffer objects match the size of the mesh arrays.