Geogram  Version 1.9.1
A programming library of geometric algorithms
simple_mesh_application.h
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef H_GEOGRAM_GFX_GUI_SIMPLE_MESH_APPLICATION_H
41 #define H_GEOGRAM_GFX_GUI_SIMPLE_MESH_APPLICATION_H
42 
44 #include <geogram_gfx/gui/simple_application.h>
46 
47 namespace GEO {
48 
53  public:
57  SimpleMeshApplication(const std::string& name);
58 
65 
66  protected:
67 
71  void geogram_initialize(int argc, char** argv) override;
72 
76  std::string supported_read_file_extensions() override;
77 
81  std::string supported_write_file_extensions() override;
82 
86  void draw_object_properties() override;
87 
91  void draw_scene() override;
92 
96  void GL_initialize() override;
97 
101  void GL_terminate() override;
102 
106  bool load(const std::string& filename) override;
107 
111  bool save(const std::string& filename) override;
112 
118  SimpleMeshApplication* result =
119  dynamic_cast<SimpleMeshApplication*>(
120  SimpleApplication::instance()
121  );
122  geo_assert(result != nullptr);
123  return result;
124  }
125 
126 
127  protected:
128 
134  virtual void draw_points();
135  virtual void draw_edges();
136  virtual void draw_surface();
137  virtual void draw_volume();
138 
149  void get_bbox(
150  const Mesh& M_in, double* xyzmin, double* xyzmax, bool animate
151  );
152 
158 
164 
170 
176 
177 
182  static void next_file();
183 
188  static void prev_file();
189 
193  static void first_file();
194 
198  static void last_file();
199 
200 
201  void jump_to_file(int relative_index);
202 
203  protected:
204 
209  Mesh* mesh() {
210  return &mesh_;
211  }
212 
218  return &mesh_gfx_;
219  }
220 
224  void show_vertices() {
225  show_vertices_ = true;
226  }
227 
231  void hide_vertices() {
232  show_vertices_ = false;
233  }
234 
238  void show_surface() {
239  show_surface_ = true;
240  }
241 
245  void hide_surface() {
246  show_surface_ = false;
247  }
248 
252  void show_volume() {
253  show_volume_ = true;
254  }
255 
259  void hide_volume() {
260  show_volume_ = false;
261  }
262 
266  virtual void show_attributes();
267 
271  virtual void hide_attributes();
272 
277  void autorange();
278 
283  std::string attribute_names();
284 
290  void set_attribute(const std::string& attribute);
291 
292  protected:
293  Mesh mesh_;
294  MeshGfx mesh_gfx_;
295 
296  float anim_speed_;
297  float anim_time_;
298 
299  bool show_vertices_;
300  bool show_vertices_selection_;
301  float vertices_size_;
302  vec4f vertices_color_;
303  float vertices_transparency_;
304 
305  bool show_surface_;
306  bool show_surface_sides_;
307  bool show_mesh_;
308  float mesh_width_;
309  vec4f mesh_color_;
310 
311  bool show_surface_borders_;
312  vec4f surface_color_;
313  vec4f surface_color_2_;
314 
315  bool show_volume_;
316  float cells_shrink_;
317  vec4f volume_color_;
318  bool show_colored_cells_;
319  bool show_hexes_;
320  bool show_connectors_;
321 
322  bool show_attributes_;
323  index_t current_colormap_index_;
324  std::string attribute_;
325  MeshElementsFlags attribute_subelements_;
326  std::string attribute_name_;
327  float attribute_min_;
328  float attribute_max_;
329  };
330 
331  /*****************************************************************/
332 }
333 
334 #endif
#define geo_assert(x)
Verifies that a condition is met.
Definition: assert.h:149
Draws a mesh using OpenGL.
Definition: mesh_gfx.h:60
Represents a mesh.
Definition: mesh.h:2701
An Application that manipulates a single Mesh.
void hide_surface()
Makes the surface facets invisible.
void get_bbox(const Mesh &M_in, double *xyzmin, double *xyzmax, bool animate)
Gets the bounding box of a mesh animation.
void GL_terminate() override
Deallocates OpenGL and GLUP objects.
void GL_initialize() override
Initializes OpenGL and GLUP objects.
virtual void show_attributes()
Makes the attributes visible.
void autorange()
Adjusts the current minimum and maximum attribute value to the currently bound attribute if any.
std::string supported_write_file_extensions() override
Gets the list of supported file extensions for writing.
static void increment_cells_shrink_callback()
increments the cells shrinkage.
void hide_vertices()
Makes the vertices invisible.
SimpleMeshApplication(const std::string &name)
Application constructor.
static SimpleMeshApplication * instance()
Gets the instance.
bool save(const std::string &filename) override
Saves the current content to a file.
virtual void draw_points()
Called at the beginning of draw_scene().
std::string attribute_names()
Gets the list of attribute names.
static void decrement_cells_shrink_callback()
decrements the cells shrinkage.
void show_volume()
Makes the volume cells visible.
static void last_file()
Loads the last file in the current directory.
static void decrement_anim_time_callback()
derements the animation time in the current instance.
void show_vertices()
Makes the vertices visible.
static void first_file()
Loads the first file in the current directory.
void geogram_initialize(int argc, char **argv) override
std::string supported_read_file_extensions() override
Gets the list of supported file extensions for reading.
void hide_volume()
Makes the volume cells invisible.
void draw_object_properties() override
Draws the contents of the object properties window.
static void next_file()
Loads the next file.
bool load(const std::string &filename) override
Loads a file.
MeshGfx * mesh_gfx()
Gets the mesh graphics.
static void prev_file()
Loads the previous file.
void show_surface()
Makes the surface facets visible.
void set_attribute(const std::string &attribute)
Sets the currently displayed attribute.
void install_key_file_navigation()
Installs key navigation callbacks.
void draw_scene() override
Draws the scene.
virtual void hide_attributes()
Makes the attributes invisible.
static void increment_anim_time_callback()
increments the animation time in the current instance.
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition: defs.h:55
Common include file, providing basic definitions. Should be included before anything else by all head...
A class to display a mesh using OpenGL/GLUP.
Global Vorpaline namespace.
Definition: basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329