40#ifndef GEOGRAM_GFX_MESH_GFX
41#define GEOGRAM_GFX_MESH_GFX
166 return mesh_border_width_;
176 mesh_border_width_ = x;
203 }
else if(shrink_ > 1.0) {
260 }
else if(time_ > 1.0) {
274 return draw_cells_[type];
287 draw_cells_[type] = x;
298 points_color_[0] = r;
299 points_color_[1] = g;
300 points_color_[2] = b;
301 points_color_[3] = a;
311 r = points_color_[0];
312 g = points_color_[1];
313 b = points_color_[2];
314 a = points_color_[3];
373 surface_color_[0] = r;
374 surface_color_[1] = g;
375 surface_color_[2] = b;
376 surface_color_[3] = a;
377 backface_surface_color_[0] = r;
378 backface_surface_color_[1] = g;
379 backface_surface_color_[2] = b;
380 backface_surface_color_[3] = a;
390 r = surface_color_[0];
391 g = surface_color_[1];
392 b = surface_color_[2];
393 a = surface_color_[3];
405 float r,
float g,
float b,
float a=1.0f
407 backface_surface_color_[0] = r;
408 backface_surface_color_[1] = g;
409 backface_surface_color_[2] = b;
410 backface_surface_color_[3] = a;
420 for(
index_t i=0; i<MESH_NB_CELL_TYPES; ++i) {
421 cells_color_[i][0] = r;
422 cells_color_[i][1] = g;
423 cells_color_[i][2] = b;
424 cells_color_[i][3] = a;
435 r = cells_color_[0][0];
436 g = cells_color_[0][1];
437 b = cells_color_[0][2];
438 a = cells_color_[0][3];
451 cells_colors_by_type_ =
true;
452 set_cells_color(MESH_TET, 1.0f, 0.0f, 0.0f);
453 set_cells_color(MESH_HEX, 0.9f, 0.9f, 0.9f);
454 set_cells_color(MESH_PRISM, 0.0f, 1.0f, 0.0f);
455 set_cells_color(MESH_PYRAMID, 0.0f, 0.0f, 1.0f);
456 set_cells_color(MESH_CONNECTOR, 1.0f, 0.8f, 0.0f);
504 picking_mode_ = what;
514 return picking_mode_;
526 object_picking_id_ = id;
535 return object_picking_id_;
547 if(vertices_selection_ != name) {
548 vertices_selection_ = name;
549 vertices_selection_filter_.attribute_name = name;
550 vertices_selection_filter_.dirty =
true;
560 return vertices_selection_;
582 MeshElementsFlags subelements,
583 const std::string& name,
584 double attr_min,
double attr_max,
585 GLuint colormap_texture,
600 MeshElementsFlags subelements,
601 const std::string& attribute_name,
612 attribute_subelements_ = MESH_NONE;
613 attribute_min_ = 0.0;
614 attribute_max_ = 0.0;
615 attribute_texture_ = 0;
616 attribute_repeat_ = 1;
632 MeshElementsFlags subelements,
633 const std::string& name =
"filter"
649 void draw_vertices_array();
650 void draw_vertices_immediate_plain();
651 void draw_vertices_immediate_attrib();
652 void draw_vertices_selection();
654 void draw_edges_array();
655 void draw_edges_immediate_plain();
656 void draw_edges_immediate_attrib();
657 void draw_edges_picking_filter();
659 void draw_triangles();
660 void draw_triangles_array();
661 void draw_triangles_immediate_plain();
662 void draw_triangles_immediate_attrib();
665 void draw_quads_array();
666 void draw_quads_immediate_plain();
667 void draw_quads_immediate_attrib();
669 void draw_triangles_and_quads();
670 void draw_triangles_and_quads_array();
671 void draw_triangles_and_quads_immediate_plain();
672 void draw_triangles_and_quads_immediate_attrib();
674 void draw_polygons();
675 void draw_polygons_plain();
676 void draw_polygons_attrib();
679 void draw_tets_array();
680 void draw_tets_immediate_plain();
681 void draw_tets_immediate_attrib();
684 void draw_hybrid_array();
685 void draw_hybrid_immediate_plain();
686 void draw_hybrid_immediate_attrib();
688 void set_cells_color(MeshCellType type,
float r,
float g,
float b) {
689 cells_color_[type][0] = r;
690 cells_color_[type][1] = g;
691 cells_color_[type][2] = b;
694 void draw_attribute_as_tex_coord(
index_t element) {
695 if(picking_mode_ == MESH_NONE) {
696 switch(attribute_dim_) {
698 glupPrivateTexCoord1d(scalar_attribute_[element]);
701 glupPrivateTexCoord2d(
702 tex_coord_attribute_[0][element],
703 tex_coord_attribute_[1][element]
707 glupPrivateTexCoord3d(
708 tex_coord_attribute_[0][element],
709 tex_coord_attribute_[1][element],
710 tex_coord_attribute_[2][element]
717 void draw_vertex_with_attribute(index_t vertex) {
718 if(attribute_subelements_ == MESH_VERTICES) {
719 draw_attribute_as_tex_coord(vertex);
724 void draw_surface_vertex_with_attribute(
725 index_t vertex, index_t facet, index_t corner
727 if(attribute_subelements_ == MESH_VERTICES) {
728 draw_attribute_as_tex_coord(vertex);
729 }
else if(attribute_subelements_ == MESH_FACETS) {
730 draw_attribute_as_tex_coord(facet);
731 }
else if(attribute_subelements_ == MESH_FACET_CORNERS) {
732 draw_attribute_as_tex_coord(corner);
737 void draw_volume_vertex_with_attribute(
738 index_t vertex, index_t cell, index_t cell_corner
740 if(attribute_subelements_ == MESH_VERTICES) {
741 draw_attribute_as_tex_coord(vertex);
742 }
else if(attribute_subelements_ == MESH_CELLS) {
743 draw_attribute_as_tex_coord(cell);
744 }
else if(attribute_subelements_ == MESH_CELL_CORNERS) {
745 draw_attribute_as_tex_coord(cell_corner);
750 void draw_vertex(index_t v) {
752 if(mesh_->vertices.single_precision()) {
754 mesh_->vertices.single_precision_point_ptr(v);
755 float t = float(time_);
756 float s = 1.0f - float(time_);
763 const GLUPdouble* p = mesh_->vertices.point_ptr(v);
764 double s = 1.0 - time_;
772 if(mesh_->vertices.single_precision()) {
773 if(mesh_->vertices.dimension() < 3) {
774 glupPrivateVertex2fv(
775 mesh_->vertices.single_precision_point_ptr(v)
778 glupPrivateVertex3fv(
779 mesh_->vertices.single_precision_point_ptr(v)
783 if(mesh_->vertices.dimension() < 3) {
784 glupPrivateVertex2dv(
785 mesh_->vertices.point_ptr(v)
788 glupPrivateVertex3dv(
789 mesh_->vertices.point_ptr(v)
796 void draw_surface_mesh_with_lines();
885 void update_surface_elements();
887 void update_volume_elements();
896 bool draw_cells_[MESH_NB_CELL_TYPES];
899 float points_color_[4];
900 float mesh_color_[4];
901 float surface_color_[4];
902 float backface_surface_color_[4];
903 float cells_color_[MESH_NB_CELL_TYPES][4];
904 bool cells_colors_by_type_;
908 MeshElementsFlags picking_mode_;
911 std::string vertices_selection_;
916 bool triangles_and_quads_;
918 bool has_cells_[MESH_NB_CELL_TYPES];
920 bool buffer_objects_dirty_;
921 bool attributes_buffer_objects_dirty_;
922 bool long_vector_attribute_;
924 GLuint vertices_VAO_;
929 GLuint vertices_VBO_;
930 GLuint edge_indices_VBO_;
931 GLuint facet_indices_VBO_;
932 GLuint cell_indices_VBO_;
933 GLuint vertices_attribute_VBO_;
935 MeshElementsFlags attribute_subelements_;
936 std::string attribute_name_;
938 double attribute_min_;
939 double attribute_max_;
940 GLuint attribute_texture_;
941 index_t attribute_texture_dim_;
970 bool hw_primitive_filtering=
true
991 !attribute.is_bound() ||
992 attribute[primitive_id] != 0
996 std::string attribute_name;
1003 Filter vertices_filter_;
1004 Filter edges_filter_;
1005 Filter facets_filter_;
1006 Filter cells_filter_;
1007 Filter vertices_selection_filter_;
1038 const bool hw_filtering = hw_filtering_supported();
1040 Filter* filter =
nullptr;
1041 if(&elements == &mesh_->vertices) {
1042 filter = &vertices_filter_;
1043 }
else if(&elements == &mesh_->edges) {
1044 filter = &edges_filter_;
1045 }
else if(&elements == &mesh_->facets) {
1046 filter = &facets_filter_;
1047 }
else if(&elements == &mesh_->cells) {
1048 filter = &cells_filter_;
1054 while(e < elements.
nb()) {
1055 while(e<elements.
nb() && !(hw_filtering||filter->
test(e))) {
1058 if(e<elements.
nb()) {
1060 while(e<elements.
nb() && (hw_filtering||filter->
test(e))) {
1064 glupBasePickingId(GLUPuint64(begin));
1069 glupBasePickingId(0);
1088 std::function<
bool(
index_t)> predicate,
1095 const bool hw_filtering = hw_filtering_supported();
1097 Filter* filter =
nullptr;
1098 if(&elements == &mesh_->vertices) {
1099 filter = &vertices_filter_;
1100 }
else if(&elements == &mesh_->edges) {
1101 filter = &edges_filter_;
1102 }
else if(&elements == &mesh_->facets) {
1103 filter = &facets_filter_;
1104 }
else if(&elements == &mesh_->cells) {
1105 filter = &cells_filter_;
1111 while(e < elements.
nb()) {
1113 e<elements.
nb() && (
1114 !(hw_filtering || filter->
test(e)) || !predicate(e))
1118 if(e<elements.
nb()) {
1122 (hw_filtering || filter->
test(e)) &&
1128 glupBasePickingId(GLUPuint64(begin));
1133 glupBasePickingId(0);
GLUP: GL Useful Primitives.
GLUPprimitive
Symbolic values corresponding to GLUP primitive types.
Slightly faster GLUP functions, not part of the API (do not use in client code).
#define geo_assert(x)
Verifies that a condition is met.
Manages an attribute attached to a set of object.
Manages a set of attributes attached to an object.
Draws a mesh using OpenGL.
void draw_surface()
Draws the surfacic part of the mesh.
void get_mesh_color(float &r, float &g, float &b, float &a) const
Gets the mesh color.
void get_points_color(float &r, float &g, float &b, float &a) const
Gets the points color.
void bind_attribute_buffer_object(GLuint VAO)
Binds the attribute buffer object to a Vertex Array Object.
void cleanup()
Deallocates OpenGL objects.
const std::string & get_vertices_selection() const
Gets the vertices selection.
void set_GLUP_parameters()
Sets GLUP drawing parameters.
void set_lighting(bool x)
Sets the lighting flag.
void set_shrink(double x)
Sets the cells shrink coefficient.
void update_attribute_buffer_objects_if_needed()
Updates the buffer objects used to display attributes.
void set_cells_colors_by_type()
Sets a different color for each mesh cell type.
void end_attributes()
Deactivates drawing for attributes.
void begin_attributes()
Setups drawing for attributes.
void set_draw_cells(MeshCellType type, bool x)
Sets the cell visibility flag.
void set_cells_color(float r, float g, float b, float a=1.0f)
Sets the color used to display mesh cells.
double get_shrink() const
Gets the cells shrink coefficient.
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.
void set_points_size(float x)
Sets the point size.
void draw_volume()
Draws the volumetric part of the mesh.
void get_cells_color(float &r, float &g, float &b, float &a) const
Gets the cells color.
index_t get_object_picking_id() const
Gets the object-wide picking id.
MeshGfx()
MeshGfx constructor.
void set_picking_mode(MeshElementsFlags what)
Sets picking mode.
bool get_draw_cells(MeshCellType type) const
Gets the cell visibility flag.
void set_object_picking_id(index_t id)
Sets the object-wide picking id.
float get_points_size() const
Gets the point size.
bool get_lighting() const
Gets the lighing flag.
bool can_use_array_mode(GLUPprimitive prim) const
Tests whether array mode can be used to draw a specified GLUP primitive.
void set_GLUP_vertex_color_from_picking_id(index_t id)
Encodes an id as the current vertex color.
void set_GLUP_picking(MeshElementsFlags what)
Sets GLUP picking mode for drawing primitives of a given type, or deactivates GLUP picking if MeshGfx...
void set_surface_color(float r, float g, float b, float a=1.0f)
Sets the surface color.
void set_points_color(float r, float g, float b, float a=1.0f)
Sets the points color.
void draw_edges()
Draws the edges of the mesh.
void set_mesh(const Mesh *M)
Sets the mesh.
void set_mesh_width(index_t x)
Sets the mesh width.
void set_time(double x)
Gets the time of the animation.
void set_vertices_selection(const std::string &name)
Sets the vertices selection.
~MeshGfx()
MeshGfx destructor.
index_t get_mesh_width() const
Gets the mesh width.
bool get_show_mesh() const
Gets the mesh visibility flag.
const Mesh * mesh() const
Gets the mesh.
void set_backface_surface_color(float r, float g, float b, float a=1.0f)
Sets the surface color for backfacing faces.
bool get_animate() const
Gets the animate flag.
void set_mesh_border_width(index_t x)
Sets the mesh border width.
void unset_filters()
Unset primitive filtering.
index_t get_mesh_border_width() const
Gets the mesh border width.
void set_show_mesh(bool x)
Sets the mesh visibility flag.
void get_surface_color(float &r, float &g, float &b, float &a) const
Gets the surface color.
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.
void draw_vertices()
Draws the vertices of the mesh.
void update_buffer_objects_if_needed()
Updates the Vertex Buffer Objects and Vertex Array Objects.
MeshGfx(const MeshGfx &rhs)=delete
Forbids MeshGfx copy..
void draw_surface_borders()
Draws the borders of the surfacic part of the mesh.
double get_time() const
Gets the time of the animation.
void set_animate(bool x)
Gets the animate flag.
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.
void bind_vertices_VBO()
Binds the vertices VBO to the current VAO.
void set_filter(MeshElementsFlags subelements, const std::string &name="filter")
Sets primitive filtering.
MeshGfx & operator=(const MeshGfx &rhs)=delete
Forbids MeshGfx copy..
void unset_scalar_attribute()
Unsets scalar attribute display.
MeshElementsFlags get_picking_mode() const
Gets the current picking mode.
bool hw_filtering_supported() const
Tests whether hardware primitive filtering is supported.
void set_mesh_color(float r, float g, float b, float a=1.0f)
Sets the mesh color.
void draw_sequences(const MeshSubElementsStore &elements, std::function< void(index_t, index_t)> draw)
Generic function to extract element sequences to draw.
void unbind_attribute_buffer_object(GLuint VAO)
Unbinds the attribute buffer object from a Vertex Array Object.
Base class for mesh sub-element storage.
AttributesManager & attributes() const
Gets the attributes manager.
index_t nb() const
Gets the number of (sub-)elements.
Readonly access to an attribute as a double regardless its type.
Common include file, providing basic definitions. Should be included before anything else by all head...
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
The class that represents a mesh.
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.
Filters primitives based on their id and on an attribute.
bool begin(AttributesManager &attributes_manager, bool hw_primitive_filtering=true)
Begins rendering with primitive filtering.
void end()
Needs to be called after rendering.
bool test(index_t primitive_id) const
Tests an individual primitive.
void deallocate()
Deallocates GPU objects.