Geogram Version 1.9.6-rc
A programming library of geometric algorithms
Loading...
Searching...
No Matches
simple_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_APPLICATION_H
41#define H_GEOGRAM_GFX_GUI_SIMPLE_APPLICATION_H
42
51#include <geogram_gfx/imgui_ext/imgui_ext.h>
52#include <geogram_gfx/imgui_ext/icon_font.h>
53
54#include <map>
55#include <functional>
56
57struct lua_State;
58
59namespace GEO {
60
67 public:
68
73 SimpleApplication(const std::string& name);
74
79
83 void draw_gui() override;
84
88 void draw_graphics() override;
89
97 virtual bool save(const std::string& filename);
98
106 virtual bool load(const std::string& filename);
107
113 return text_editor_;
114 }
115
120 text_editor_visible_ = true;
121 }
122
127 text_editor_visible_ = false;
128 }
129
134 console_visible_ = true;
135 }
136
141 console_visible_ = false;
142 }
143
147 void home();
148
152 void set_style(const std::string& style) override;
153
161 double xmin, double ymin, double zmin,
162 double xmax, double ymax, double zmax
163 );
164
172 double& xmin, double& ymin, double& zmin,
173 double& xmax, double& ymax, double& zmax
174 ) const;
175
176 void zoom_in() {
177 zoom_ *= 1.1;
178 }
179
180 void zoom_out() {
181 zoom_ /= 1.1;
182 }
183
184 void set_clipping(bool x) {
185 clipping_ = x;
186 }
187
188 void set_lighting(bool x) {
189 lighting_ = x;
190 }
191
192 void set_background_color(const vec4f& color) {
193 background_color_ = color;
194 }
195
196 virtual bool exec_command(const char* command);
197
198 static SimpleApplication* instance() {
199 return dynamic_cast<SimpleApplication*>(
201 );
202 }
203
210 vec3 project(const vec3& p);
211
218 vec3 unproject(const vec3& p);
219
226
227
231 void drop_callback(int nb, const char** f) override;
232
233 protected:
241 const std::string& key, std::function<void()> cb,
242 const char* help = nullptr
243 );
244
252 const std::string& key, bool* p_val,
253 const char* help = nullptr
254 );
255
259 void char_callback(unsigned int c) override;
260
264 void key_callback(int key, int scancode, int action, int mods) override;
265
270 int button, int action, int mods, int source
271 ) override;
272
276 void cursor_pos_callback(double x, double y, int source) override;
277
281 void scroll_callback(double xoffset, double yoffset) override;
282
286 virtual void draw_scene_begin();
287
291 virtual void draw_scene();
292
296 virtual void draw_scene_end();
297
302
307
312
317
318
322 virtual void draw_command_window();
323
327 virtual void draw_console();
328
329
333 virtual void draw_menu_bar();
334
335
339 virtual void draw_load_menu();
340
344 virtual void draw_save_menu();
345
352 virtual void draw_fileops_menu();
353
357 virtual void draw_about();
358
362 virtual void draw_help();
363
367 virtual void draw_windows_menu();
368
374
380
381
386
387
391 void post_draw() override;
392
400 virtual bool can_load(const std::string& filename);
401
410 virtual std::string supported_read_file_extensions();
411
423 virtual std::string supported_write_file_extensions();
424
428 void GL_initialize() override;
429
433 void GL_terminate() override;
434
441 void browse(const std::string& path, bool subdirs=false);
442
446 void geogram_initialize(int argc, char** argv) override;
447
453 void set_default_filename(const std::string& filename) {
454 strcpy(filename_, filename.c_str());
455 }
456
464 void init_colormap(const std::string& name, const char** xpm_data);
465
472
476 void ImGui_initialize() override;
477
478 void set_2d() {
479 three_D_ = false;
480 }
481
482 void set_3d() {
483 three_D_ = true;
484 }
485
486 void set_default_layout();
487
488 void resize(index_t w, index_t h, index_t fb_w, index_t fb_h) override;
489
490 virtual const char* default_layout() const;
491 virtual const char* default_layout_android_vertical() const;
492 virtual const char* default_layout_android_horizontal() const;
493
499 virtual void command_line_arg_changed(const std::string& argname);
500
511
523 virtual void snapshot(
524 Image* image,
525 index_t x0=0, index_t y0=0, index_t width=0, index_t height=0,
526 bool redraw = true
527 );
528
537 virtual void snapshot(std::string filename = "", bool verbose=false);
538
542 void declare_args() override;
543
544 protected:
545 bool locked_; // avoid starting command when command is running
546 bool lighting_;
547 bool edit_light_;
548 bool clipping_;
549 GLUPclipMode clip_mode_;
550 bool edit_clip_;
551 bool fixed_clip_;
552 GLenum effect_;
553 vec4f background_color_;
554
555 bool viewer_properties_visible_;
556 bool object_properties_visible_;
557 bool console_visible_;
558 bool text_editor_visible_;
559 bool use_text_editor_;
560 bool command_line_editor_visible_;
561
562 Box roi_;
563 double roi_radius_;
564 vec3 object_translation_;
565 ArcBall object_rotation_;
566 ArcBall light_rotation_;
567 ArcBall clip_rotation_;
568 vec3 clip_translation_;
569 bool three_D_;
570 double zoom_;
571 double zoom_down_;
573 bool props_pinned_;
574
575 enum MouseOp {
576 MOUSE_NOOP, MOUSE_ROTATE, MOUSE_TRANSLATE, MOUSE_ZOOM
577 } mouse_op_;
578
579 enum MouseTarget {
580 MOUSE_NOTARGET, MOUSE_OBJECT, MOUSE_LIGHT, MOUSE_CLIP
581 } mouse_target_;
582
583 vec2 mouse_down_xy_; // in [-1,1] x [-1,1]
584 vec2 mouse_xy_; // in [-1,1] x [-1,1]
585
586 // Current transform, for picking
587 GLint viewport_[4];
588 mat4 modelview_transpose_;
589 mat4 project_transpose_;
590
591 std::string path_;
592 std::string current_file_;
593 char filename_[geo_imgui_string_length]; // Buffer for file dialog.
594 GLuint geogram_logo_texture_;
595
596 Console_var console_;
597 StatusBar_var status_bar_;
598 TextEditor text_editor_;
599
600 std::map< std::string, std::function<void()> > key_funcs_;
601 std::map< std::string, std::string > key_funcs_help_;
602
604 ColormapInfo() : texture(0) {
605 }
606 GLuint texture;
607 std::string name;
608 };
609
610 vector<ColormapInfo> colormaps_;
611 FullScreenEffectImpl_var full_screen_effect_;
612
613 lua_State* lua_state_;
614 bool lua_error_occured_;
615 };
616
617}
618
619#endif
Base class for all applications.
Controls a 3d rotation from user mouse input.
Base class for all applications.
Definition application.h:67
static Application * instance()
Gets the instance.
Definition application.h:85
Enables to interactively define a rotation.
Definition arc_ball.h:66
Axis-aligned bounding box.
Definition geometry.h:689
An image.
Definition image.h:59
SimpleApplication is an Application with pre-created and customizable menus, commands,...
virtual void draw_fileops_menu()
Draws other file operation menu.
virtual void draw_console()
Draws the console.
void cursor_pos_callback(double x, double y, int source) override
Callback called whenever the mouse cursor is moved.
virtual void draw_scene_begin()
Setups OpenGL for scene drawing.
virtual void draw_application_menus()
Draws the application menus.
virtual void draw_load_menu()
Draws the load menu and browser.
void drop_callback(int nb, const char **f) override
Callback called whenever files are dropped in the window.
virtual bool save(const std::string &filename)
Saves the current content to a file.
virtual bool can_load(const std::string &filename)
Tests whether a file can be loaded.
TextEditor & text_editor()
Gets the text editor.
virtual void command_line_arg_changed(const std::string &argname)
This function is changed each time the user changed the value of a command line argument in the comma...
virtual void draw_viewer_properties()
Draws the contents of viewer properties window.
virtual void draw_about()
Draws the about box in the file menu.
virtual void draw_application_icons()
Draws the application icons on the menubar.
void char_callback(unsigned int c) override
Callback called whenever a key is pushed (high level version)
virtual void draw_help()
Draws help info (accelarators)
void declare_args() override
Called by geogram_initialize(), right before parsing command line arguments.
void set_style(const std::string &style) override
Sets the style of the application.
virtual void draw_scene_end()
Cleanups OpenGL after scene drawing.
virtual void snapshot(Image *image, index_t x0=0, index_t y0=0, index_t width=0, index_t height=0, bool redraw=true)
Copies a rectangular zone of the framebuffer to an image.
void mouse_button_callback(int button, int action, int mods, int source) override
Callback called whenenver a mouse button changed.
void hide_text_editor()
Hides the text editor.
vec3 project(const vec3 &p)
Projects a point from model space to window coordinates.
vec3 unproject(const vec3 &p)
Unprojects a 3d point from window coordinates to model space.
void resize(index_t w, index_t h, index_t fb_w, index_t fb_h) override
Called whenever window size changes.
void init_colormap(const std::string &name, const char **xpm_data)
Initializes a new colormap from name and xpm data.
virtual void draw_menu_bar()
Draws the menu bar.
vec2 unproject_2d(const vec2 &p)
Unprojects a 2d point from window coordinates to model space.
virtual void draw_windows_menu()
Draws the windows menu.
virtual void draw_viewer_properties_window()
Draws the viewer properties window frame and contents.
void show_console()
Shows the console.
void show_text_editor()
Shows the text editor.
void GL_initialize() override
Initializes OpenGL and GLUP objects.
void key_callback(int key, int scancode, int action, int mods) override
Callback called whenever a key is pushed (low level version)
SimpleApplication(const std::string &name)
SimpleApplication constructor.
void scroll_callback(double xoffset, double yoffset) override
Callback called whenenver the mouse wheel is moved.
void browse(const std::string &path, bool subdirs=false)
Recursively browses a directory and generates menu items.
void draw_gui() override
This function is called when the GUI should be redisplayed.
virtual void draw_command_window()
Draws the active command window if any.
void get_region_of_interest(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Gets the region of interest.
virtual void draw_object_properties()
Draws the contents of the object properties window.
void draw_graphics() override
This function is called when the 3d content should be redisplayed.
void set_default_filename(const std::string &filename)
Sets the default filename used to save the current file.
virtual std::string supported_read_file_extensions()
Gets the list of supported file extensions for reading.
void post_draw() override
This function is called after all drawing operations.
void home()
Restores default viewing parameters.
void ImGui_initialize() override
Initializes the ImGui library.
~SimpleApplication() override
SimpleApplication destructor.
virtual bool load(const std::string &filename)
Loads a file.
static void replay_latest_command()
Executes once again the latest issued command.
void GL_terminate() override
Deallocates OpenGL and GLUP objects.
void hide_console()
Hides the console.
virtual void draw_scene()
Draws the scene.
virtual std::string supported_write_file_extensions()
Gets the list of supported file extensions for writing.
void add_key_func(const std::string &key, std::function< void()> cb, const char *help=nullptr)
Declares a function to be triggered when a key is pressed.
void init_colormaps()
Initializes all the default colormaps.
void geogram_initialize(int argc, char **argv) override
void add_key_toggle(const std::string &key, bool *p_val, const char *help=nullptr)
Declares a boolean to be toggled when a key is pressed.
virtual void draw_command_line_editor()
Draws a window to edit all command line arguments.
virtual void snapshot(std::string filename="", bool verbose=false)
Saves the framebuffer to an image.
virtual void draw_save_menu()
Draws the save menu.
void set_region_of_interest(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Sets the region of interest.
virtual void draw_object_properties_window()
Draw the object properties window frame and contents.
A minimalistic text editor.
Definition text_editor.h:58
Vector with aligned memory allocation.
Definition memory.h:660
A simple system to interface C++ functions with a ImGui interface. Used mainly by geobox.
A console.
Low-level base class for full screen effects.
#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...
Global Vorpaline namespace.
Definition basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329
Implementation of the status bar.
A simple text editor.