Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
mesh_grob_shader.h
Go to the documentation of this file.
1/*
2 * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3 * Copyright (C) 2000-2009 INRIA - Project ALICE
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * If you modify this software, you should include a notice giving the
20 * name of the person performing the modification, the date of modification,
21 * and the reason for such modification.
22 *
23 * Contact: Bruno Levy - levy@loria.fr
24 *
25 * Project ALICE
26 * LORIA, INRIA Lorraine,
27 * Campus Scientifique, BP 239
28 * 54506 VANDOEUVRE LES NANCY CEDEX
29 * FRANCE
30 *
31 * Note that the GNU General Public License does not permit incorporating
32 * the Software into proprietary programs.
33 *
34 * As an exception to the GPL, Graphite can be linked with
35 * the following (non-GPL) libraries:
36 * Qt, SuperLU, WildMagic and CGAL
37 */
38
39
40#ifndef H_OGF_MESH_GFX_SHADERS_MESH_GROB_SHADER_H
41#define H_OGF_MESH_GFX_SHADERS_MESH_GROB_SHADER_H
42
43#include <OGF/mesh_gfx/common/common.h>
47
49
50
56namespace GEO {
57 class Image;
58}
59
60
61namespace OGF {
62
63 /**********************************************************/
64
65 class Builder;
66 class Texture;
67
68 enum CullingMode {NO_CULL, CULL_FRONT, CULL_BACK};
69
70 enum PaintingMode {SOLID_COLOR, ATTRIBUTE, COLOR, TEXTURE};
71
75 gom_attribute(abstract, "true")
76 gom_class MESH_GFX_API MeshGrobShader : public Shader {
77 public:
83
87 ~MeshGrobShader() override;
88
92 void draw() override;
93
100 virtual void pick(MeshElementsFlags what);
101
106 void pick_object(index_t object_id) override;
107
111 void blink() override;
112
116 virtual void show_vertices();
117
121 virtual void hide_vertices();
122
127
133
137 virtual void show_mesh();
138
142 virtual void hide_mesh();
143
147 virtual void show_borders();
148
152 virtual void hide_borders();
153
154 gom_properties:
155
163 bool get_has_edges() const {
164 return
165 mesh_grob() != nullptr &&
166 mesh_grob()->edges.nb() != 0;
167 }
168
176 bool get_has_facets() const {
177 return
178 mesh_grob() != nullptr &&
179 mesh_grob()->facets.nb() != 0;
180 }
181
189 bool get_has_cells() const {
190 return
191 mesh_grob() != nullptr &&
192 mesh_grob()->cells.nb() != 0;
193 }
194
203 bool get_is_hybrid() const {
204 return
205 mesh_grob() != nullptr &&
206 mesh_grob()->cells.nb() != 0 &&
207 !mesh_grob()->cells.are_simplices();
208 }
209
220 bool get_has_time() const {
221 return
222 mesh_grob() != nullptr &&
223 mesh_grob()->vertices.dimension() >= 6;
224 }
225
226 bool get_has_vertices_selection() const {
227 return mesh_grob() != nullptr &&
228 mesh_grob()->vertices.attributes().is_defined("selection");
229 }
230
231
232 bool get_has_weird_cells() const {
233 return mesh_grob() != nullptr &&
234 mesh_grob()->cells.attributes().is_defined("weird");
235 }
236
237 std::string get_scalar_attributes() const {
238 std::string result;
239 if(mesh_grob() != nullptr) {
240 result = mesh_grob()->get_scalar_attributes();
241 }
242 return result;
243 }
244
245 std::string get_vector_attributes() const {
246 std::string result;
247 if(mesh_grob() != nullptr) {
248 result = mesh_grob()->get_vector_attributes(3);
249 }
250 return result;
251 }
252
253 bool get_has_vertices_filter() const {
254 return
255 mesh_grob()->vertices.nb() != 0 &&
256 mesh_grob()->vertices.attributes().is_defined("filter") ;
257 }
258
259 bool get_has_facets_filter() const {
260 return
261 mesh_grob()->facets.nb() != 0 &&
262 mesh_grob()->facets.attributes().is_defined("filter") ;
263 }
264
265 bool get_has_cells_filter() const {
266 return
267 mesh_grob()->cells.nb() != 0 &&
268 mesh_grob()->cells.attributes().is_defined("filter") ;
269 }
270
271 protected:
277 return static_cast<MeshGrob*>(grob());
278 }
279 };
280
281 /****************************************************************/
282
286 gom_class MESH_GFX_API PlainMeshGrobShader : public MeshGrobShader {
287 public:
293
298
302 void draw() override;
303
307 void pick(MeshElementsFlags what) override;
308
312 void pick_object(index_t object_id) override;
313
317 void blink() override;
318
322 void show_vertices() override;
323
327 void hide_vertices() override;
328
332 void show_vertices_selection() override;
333
337 void hide_vertices_selection() override;
338
342 void show_mesh() override;
343
347 void hide_mesh() override;
348
352 void show_borders() override;
353
357 void hide_borders() override;
358
359 gom_properties:
360
366 bool get_attributes() const {
367 return (painting_mode_ == ATTRIBUTE);
368 }
369
370 gom_slots:
371
375 gom_attribute(visible_if, "attributes")
376 void autorange();
377
378
385 void set_time_smooth(double x) {
386 time_ = x;
387 update();
388 }
389
396 double get_time_smooth() const {
397 return time_;
398 }
399
400 gom_properties:
401
406 void set_painting(PaintingMode value);
407
412 PaintingMode get_painting() const {
413 return painting_mode_;
414 }
415
421 gom_attribute(visible_if, "attributes")
422 void set_attribute_min(double value) {
423 attribute_min_ = value;
424 update();
425 }
426
432 double get_attribute_min() const {
433 return attribute_min_;
434 }
435
441 gom_attribute(visible_if, "attributes")
442 void set_attribute_max(double value) {
443 attribute_max_ = value;
444 update();
445 }
446
452 double get_attribute_max() const {
453 return attribute_max_;
454 }
455
456
461 gom_attribute(visible_if, "attributes")
462 gom_attribute(handler, "combo_box")
463 gom_attribute(values, "$scalar_attributes")
464 void set_attribute(const std::string& value);
465
470 const std::string& get_attribute() const {
471 return attribute_;
472 }
473
478 gom_attribute(visible_if, "attributes")
479 void set_colormap(const ColormapStyle& value) {
480 colormap_style_ = value;
481 colormap_texture_.reset();
482 update();
483 }
484
485 const ColormapStyle& get_colormap() const {
486 return colormap_style_;
487 }
488
494 bool get_texturing() const {
495 return (painting_mode_ == TEXTURE);
496 }
497
503 bool get_coloring() const {
504 return (painting_mode_ == COLOR);
505 }
506
507
513 gom_attribute(visible_if, "texturing")
514 void set_tex_image(const ImageFileName& value) {
515 texture_filename_ = value;
516 texture_.reset();
517 update();
518 }
519
526 return texture_filename_;
527 }
528
533 gom_attribute(visible_if, "texturing")
534 gom_attribute(handler, "combo_box")
535 gom_attribute(values, "$vector_attributes")
536 void set_tex_coords(const std::string& value);
537
542 const std::string& get_tex_coords() const {
543 return tex_coord_attribute_;
544 }
545
546
551 gom_attribute(visible_if, "coloring")
552 gom_attribute(handler, "combo_box")
553 gom_attribute(values, "$vector_attributes")
554 void set_colors(const std::string& value) {
555 // It is an alias of tex_coord, because we use
556 // 3D texturing internally to display colors
557 // (it is stupid, but makes code simpler for now.
558 set_tex_coords(value);
559 }
560
565 const std::string& get_colors() const {
566 // It is an alias of tex_coord, because we use
567 // 3D texturing internally to display colors
568 // (it is stupid, but makes code simpler for now.
569 return get_tex_coords();
570 }
571
577 gom_attribute(visible_if, "texturing")
578 void set_tex_repeat(index_t value) {
579 tex_coord_repeat_ = value;
580 update();
581 }
582
589 return tex_coord_repeat_;
590 }
591
592
593
599 gom_attribute(visible_if, "texturing")
600 void set_normal_map(bool value) {
601 tex_normal_mapping_ = value;
602 update();
603 }
604
610 bool get_normal_map() const {
611 return tex_normal_mapping_;
612 }
613
619 void set_lighting(bool value) {
620 gfx_.set_lighting(value);
621 update();
622 }
623
629 bool get_lighting() const {
630 return gfx_.get_lighting();
631 }
632
633
640 void set_clipping(bool value) {
641 clipping_ = value;
642 update();
643 }
644
651 bool get_clipping() const {
652 return clipping_;
653 }
654
655
660 gom_attribute(visible_if, "has_facets")
661 void set_surface_style(const SurfaceStyle& value) {
662 surface_style_ = value;
663 update();
664 }
665
671 return surface_style_;
672 }
673
678 gom_attribute(visible_if, "has_facets_filter")
679 void set_facets_filter(bool value) {
680 facets_filter_ = value;
681 gfx_.set_filter(
682 MESH_FACETS, value ? "filter" : ""
683 );
684 update();
685 }
686
687 bool get_facets_filter() const {
688 return facets_filter_;
689 }
690
695 gom_attribute(visible_if, "has_facets")
696 void set_culling_mode(const CullingMode value) {
697 culling_mode_ = value;
698 update();
699 }
700
705 CullingMode get_culling_mode() const {
706 return culling_mode_;
707 }
708
714 gom_attribute(visible_if, "has_facets or has_cells")
715 void set_specular(index_t x) {
716 specular_ = x;
717 update();
718 }
719
725 return specular_;
726 }
727
739 gom_attribute(visible_if, "has_facets")
740 void set_two_sided(bool value) {
741 two_sided_ = value;
742 update();
743 }
744
750 bool get_two_sided() const {
751 return two_sided_;
752 }
753
759 gom_attribute(visible_if, "has_cells")
760 void set_volume_style(const SurfaceStyle& value) {
761 volume_style_ = value;
762 update();
763 }
764
772 return volume_style_;
773 }
774
775
780 gom_attribute(visible_if, "has_cells_filter")
781 void set_cells_filter(bool value) {
782 gfx_.set_filter(
783 MESH_CELLS, value ? "filter" : ""
784 );
785 cells_filter_ = value;
786 update();
787 }
788
789 bool get_cells_filter() const {
790 return cells_filter_;
791 }
792
793
800 gom_attribute(visible_if, "is_hybrid")
801 void set_colored_cells(bool value) {
802 colored_cells_ = value;
803 update();
804 }
805
811 bool get_colored_cells() const {
812 return colored_cells_;
813 }
814
815
821 gom_attribute(visible_if, "is_hybrid")
822 void set_tets(bool value) {
823 tets_ = value;
824 update();
825 }
826
832 bool get_tets() const {
833 return tets_;
834 }
835
841 gom_attribute(visible_if, "is_hybrid")
842 void set_hexes(bool value) {
843 hexes_ = value;
844 update();
845 }
846
852 bool get_hexes() const {
853 return hexes_;
854 }
855
856
862 gom_attribute(visible_if, "is_hybrid")
863 void set_prisms(bool value) {
864 prisms_ = value;
865 update();
866 }
867
873 bool get_prisms() const {
874 return prisms_;
875 }
876
877
883 gom_attribute(visible_if, "is_hybrid")
884 void set_pyramids(bool value) {
885 pyramids_ = value;
886 update();
887 }
888
894 bool get_pyramids() const {
895 return pyramids_;
896 }
897
898
904 gom_attribute(visible_if, "is_hybrid")
905 void set_connectors(bool value) {
906 connectors_ = value;
907 update();
908 }
909
915 bool get_connectors() const {
916 return connectors_;
917 }
918
924 gom_attribute(visible_if, "has_edges")
925 void set_edges_style(const EdgeStyle& value) {
926 edges_style_ = value;
927 update();
928 }
929
935 const EdgeStyle& get_edges_style() const {
936 return edges_style_;
937 }
938
939
947 gom_attribute(visible_if, "has_facets or has_cells")
948 void set_mesh_style(const EdgeStyle& value) {
949 mesh_style_ = value;
950 update();
951 }
952
960 const EdgeStyle& get_mesh_style() const {
961 return mesh_style_;
962 }
963
964
971 gom_attribute(visible_if, "has_facets")
972 void set_border_style(const EdgeStyle& value) {
973 border_style_ = value;
974 update();
975 }
976
984 return border_style_;
985 }
986
992 void set_vertices_style(const PointStyle& value) {
993 vertices_style_ = value;
994 update();
995 }
996
1003 return vertices_style_;
1004 }
1005
1006
1011 gom_attribute(visible_if, "has_vertices_filter")
1012 void set_vertices_filter(bool value) {
1013 gfx_.set_filter(
1014 MESH_VERTICES, value ? "filter" : ""
1015 );
1016 vertices_filter_ = value;
1017 update();
1018 }
1019
1020 bool get_vertices_filter() const {
1021 return vertices_filter_;
1022 }
1023
1024 gom_properties:
1025
1031 gom_attribute(visible_if, "has_vertices_selection")
1032 void set_vert_select_style(const PointStyle& value) {
1033 vertices_selection_style_ = value;
1035 }
1036
1042 return vertices_selection_style_;
1043 }
1044
1051 gom_attribute(visible_if, "has_cells")
1052 void set_shrink(index_t value) {
1053 gfx_.set_shrink(double(value)/10.0);
1054 update();
1055 }
1056
1064 return index_t(gfx_.get_shrink()*10.0);
1065 }
1066
1067
1078 gom_attribute(visible_if, "has_time")
1079 void set_animate(bool value) {
1080 animate_ = value;
1081 update();
1082 }
1083
1094 bool get_animate() const {
1095 return animate_;
1096 }
1097
1103 gom_attribute(visible_if, "has_time and animate")
1104 gom_attribute(handler, "slider_int")
1105 gom_attribute(min, "0")
1106 gom_attribute(max, "20")
1107 void set_time(index_t value) {
1108 time_ = double(value) / 20.0;
1109 update();
1110 }
1111
1117 return index_t(time_ * 20.0);
1118 }
1119
1120
1121 gom_attribute(visible_if, "has_cells")
1122 void set_slivers(double value) {
1123 slivers_ = value;
1124 update();
1125 }
1126
1127 double get_slivers() const {
1128 return slivers_;
1129 }
1130
1131 gom_attribute(visible_if, "has_weird_cells")
1132 void set_weird_cells(bool x) {
1133 weird_cells_ = x;
1134 update();
1135 }
1136
1137 bool get_weird_cells() const {
1138 return weird_cells_;
1139 }
1140
1141 bool get_glsl_source_visible() const {
1142 return false;
1143 }
1144
1145 gom_attribute(visible_if, "glsl_source_visible")
1146 void set_glsl_source(const std::string& value) {
1147 glsl_source_ = value;
1148 update_glsl_program();
1149 }
1150
1151 const std::string& get_glsl_source() const {
1152 return glsl_source_;
1153 }
1154
1155 public:
1156 void set_transparency(Transparency x) override;
1157
1158
1159 protected:
1160 void draw_slivers();
1161 void draw_weird_cells();
1162 void draw_surface_with_glsl_shader();
1163 void update_glsl_program();
1164
1165 protected:
1166 GEO::MeshGfx gfx_;
1167
1168 PaintingMode painting_mode_;
1169
1170 std::string attribute_;
1171 MeshElementsFlags attribute_subelements_;
1172 std::string attribute_name_;
1173 double attribute_min_;
1174 double attribute_max_;
1175 ColormapStyle colormap_style_;
1176 Texture_var colormap_texture_;
1177
1178 MeshElementsFlags tex_coord_subelements_;
1179 std::string tex_coord_attribute_;
1180 std::string tex_coord_name_;
1181 index_t tex_coord_repeat_;
1182 bool tex_normal_mapping_;
1183 Texture_var texture_;
1184 ImageFileName texture_filename_;
1185
1186 SurfaceStyle surface_style_;
1187 bool facets_filter_;
1188 CullingMode culling_mode_;
1189
1190 index_t specular_;
1191 bool two_sided_;
1192 SurfaceStyle volume_style_;
1193 bool cells_filter_;
1194 bool colored_cells_;
1195 bool tets_;
1196 bool hexes_;
1197 bool prisms_;
1198 bool pyramids_;
1199 bool connectors_;
1200 index_t shrink_;
1201 EdgeStyle edges_style_;
1202 EdgeStyle mesh_style_;
1203 EdgeStyle border_style_;
1204 PointStyle vertices_style_;
1205 bool vertices_filter_;
1206 PointStyle vertices_selection_style_;
1207 bool animate_;
1208 double time_;
1209 bool picking_;
1210 double slivers_;
1211 bool weird_cells_;
1212 bool clipping_;
1213
1214 bool glsl_program_changed_;
1215 double glsl_start_time_;
1216 index_t glsl_frame_;
1217 std::string glsl_source_;
1218 GLuint glsl_program_;
1219 };
1220
1221 /**********************************************************/
1222
1226 gom_class MESH_GFX_API ExplodedViewMeshGrobShader :
1227 public PlainMeshGrobShader {
1228 public:
1234
1239
1240 gom_properties:
1241
1242 gom_attribute(handler, "combo_box")
1243 gom_attribute(values, "$scalar_attributes")
1244 void set_region(const std::string& value) {
1245 region_ = value;
1246 dirty_ = true;
1247 update();
1248 }
1249
1250 const std::string& get_region() const {
1251 return region_;
1252 }
1253
1254 void set_amount(index_t value) {
1255 amount_ = value;
1256 update();
1257 }
1258
1259 index_t get_amount() const {
1260 return amount_;
1261 }
1262
1263 public:
1264 void draw() override;
1265
1266 protected:
1267 bool dirty_;
1268 std::string region_;
1269 index_t amount_;
1270 int rgn_min_;
1271 int rgn_max_;
1272 vec3 bary_;
1273 vector<vec3> region_bary_;
1274 };
1275
1276 /**********************************************************/
1277
1278}
1279
1280#endif
Draws a mesh using OpenGL.
Definition mesh_gfx.h:60
Vector with aligned memory allocation.
Definition memory.h:710
Exploded view, moves regions apart.
void draw() override
Draws the Grob.
~ExplodedViewMeshGrobShader() override
PlainMeshGrobShader destructor.
ExplodedViewMeshGrobShader(MeshGrob *grob)
PlainMeshGrobShader constructor.
Base class for drawing and picking MeshGrob.
virtual void hide_borders()
Makes surface borders invisible and triggers a drawing event.
virtual void hide_vertices()
Makes vertices invisible and triggers a drawing event.
virtual void show_borders()
Makes surface borders visible and triggers a drawing event.
void pick_object(index_t object_id) override
Draws the Grob in picking mode.
MeshGrobShader(MeshGrob *grob)
MeshGrobShader constructor.
bool get_has_cells() const
Tests whether the MeshGrob attached to this shader has cells.
virtual void hide_mesh()
Makes the mesh invisible and triggers a drawing event.
virtual void show_mesh()
Makes the mesh visible and triggers a drawing event.
virtual void show_vertices()
Makes vertices visible and triggers a drawing event.
virtual void show_vertices_selection()
Makes vertices selection visible and triggers a drawing event.
virtual void pick(MeshElementsFlags what)
Picks an element of a mesh.
void blink() override
Draws the current object several times, while chaning the value of one graphic attribute (e....
bool get_has_time() const
Tests whether the MeshGrob attached to this shader stores a time evolution.
MeshGrob * mesh_grob() const
Gets the MeshGrob.
virtual void hide_vertices_selection()
Makes vertices selection invisible and triggers a drawing event.
bool get_is_hybrid() const
Tests whether the MeshGrob attached to this shader is a volumetric hybrid mesh.
void draw() override
Draws the Grob.
~MeshGrobShader() override
MeshGrobShader destructor.
bool get_has_facets() const
Tests whether the MeshGrob attached to this shader has facets.
A Grob wrapper around Geogram's Mesh class.
Definition mesh_grob.h:56
The default implementation of MeshGrobShader.
const SurfaceStyle & get_volume_style() const
Gets the style used to draw the volumetric cells.
~PlainMeshGrobShader() override
PlainMeshGrobShader destructor.
const EdgeStyle & get_mesh_style() const
Gets the style used to draw the mesh in the facets and in the cells.
void blink() override
Draws the current object several times, while chaning the value of one graphic attribute (e....
bool get_clipping() const
Gets whether clipping should be used.
index_t get_specular() const
Gets the current surface specular factor.
void hide_mesh() override
Makes the mesh invisible and triggers a drawing event.
bool get_tets() const
Tests whether tetrahedra are displayed.
void hide_borders() override
Makes surface borders invisible and triggers a drawing event.
bool get_texturing() const
Tests whether texturing is active.
void show_mesh() override
Makes the mesh visible and triggers a drawing event.
bool get_coloring() const
Tests whether coloring is active.
bool get_hexes() const
Tests whether hexahedra are displayed.
PlainMeshGrobShader(MeshGrob *grob)
PlainMeshGrobShader constructor.
PaintingMode get_painting() const
Gets painting mode.
void hide_vertices() override
Makes vertices invisible and triggers a drawing event.
index_t get_time() const
Gets the time parameter used for time interpolation.
const ImageFileName & get_tex_image() const
Gets the image used for texturing.
bool get_colored_cells() const
Tests whether volumetric cells are colored by type.
void show_borders() override
Makes surface borders visible and triggers a drawing event.
double get_attribute_min() const
Gets the minimum of the displayed range for attribute values.
void set_lighting(bool value)
Sets whether lighting should be used.
const EdgeStyle & get_edges_style() const
Gets the style used to draw the edges.
void show_vertices() override
Makes vertices visible and triggers a drawing event.
void draw() override
Draws the Grob.
const SurfaceStyle & get_surface_style() const
Gets the current surface drawing style.
bool get_lighting() const
Gets whether lighting is used.
index_t get_shrink() const
Gets the shrinking coefficient of the volumetric cells.
bool get_normal_map() const
Gets normal mapping mode.
void show_vertices_selection() override
Makes vertices selection visible and triggers a drawing event.
bool get_two_sided() const
Tests whether different colors are used for inside/outside.
void pick(MeshElementsFlags what) override
Picks an element of a mesh.
bool get_animate() const
Tests whether time interpolation should be used.
bool get_pyramids() const
Tests whether pyramids are displayed.
double get_attribute_max() const
Gets the maximum of the displayed range for attribute values.
const PointStyle & get_vert_select_style() const
Gets the vertices selection style.
void pick_object(index_t object_id) override
Draws the Grob in picking mode.
bool get_prisms() const
Tests whether prisms are displayed.
CullingMode get_culling_mode() const
Gets the current culling mode.
const std::string & get_colors() const
Gets the name of the displayed attribute.
bool get_connectors() const
Tests whether connectors are displayed.
double get_time_smooth() const
Gets the time as floating point parameter.
const PointStyle & get_vertices_style() const
Gets the style used to draw the vertices.
const EdgeStyle & get_border_style() const
Gets the style used to draw the border of the surface.
index_t get_tex_repeat() const
Gets the texture repeat factor.
void set_vertices_style(const PointStyle &value)
Sets the style used to draw the vertices.
void hide_vertices_selection() override
Makes vertices selection invisible and triggers a drawing event.
void set_transparency(Transparency x) override
Transparent rendering mode.
update()
Redraws the scene.
void set_clipping(bool value)
Sets whether clipping should be active.
Base class for Grob shader.
Definition shader.h:64
A class to display a mesh using OpenGL/GLUP.
the MeshGrob class.
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:330
Global Graphite namespace.
Definition common.h:76
The base class for all object shaders.
The style used to display colormapped colors.
Definition properties.h:433
Drawing style for mesh edges.
Definition properties.h:95
Drawing style for points.
Definition properties.h:64
Drawing style for polygons.
Definition properties.h:127