Geogram Version 1.10.1
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
238 void run_key_func(const std::string& key) {
239 auto it = key_funcs_.find(key);
240 if(it != key_funcs_.end()) {
241 it->second();
242 }
243 }
244
245 protected:
253 const std::string& key, std::function<void()> cb,
254 const char* help = nullptr
255 );
256
264 const std::string& key, bool* p_val,
265 const char* help = nullptr
266 );
267
271 void char_callback(unsigned int c) override;
272
276 void key_callback(int key, int scancode, int action, int mods) override;
277
282 int button, int action, int mods, int source
283 ) override;
284
288 void cursor_pos_callback(double x, double y, int source) override;
289
293 void scroll_callback(double xoffset, double yoffset) override;
294
298 virtual void draw_scene_begin();
299
303 virtual void draw_scene();
304
308 virtual void draw_scene_end();
309
314
319
324
329
330
334 virtual void draw_command_window();
335
339 virtual void draw_console();
340
341
345 virtual void draw_menu_bar();
346
347
351 virtual void draw_load_menu();
352
356 virtual void draw_save_menu();
357
364 virtual void draw_fileops_menu();
365
369 virtual void draw_about();
370
374 virtual void draw_help();
375
379 virtual void draw_windows_menu();
380
386
392
393
398
399
403 void post_draw() override;
404
412 virtual bool can_load(const std::string& filename);
413
422 virtual std::string supported_read_file_extensions();
423
435 virtual std::string supported_write_file_extensions();
436
440 void GL_initialize() override;
441
445 void GL_terminate() override;
446
453 void browse(const std::string& path, bool subdirs=false);
454
458 void geogram_initialize(int argc, char** argv) override;
459
465 void set_default_filename(const std::string& filename) {
466 strcpy(filename_, filename.c_str());
467 }
468
476 void init_colormap(const std::string& name, const char** xpm_data);
477
484
488 void ImGui_initialize() override;
489
490 void set_2d() {
491 three_D_ = false;
492 }
493
494 void set_3d() {
495 three_D_ = true;
496 }
497
498 void set_default_layout();
499
500 void resize(index_t w, index_t h, index_t fb_w, index_t fb_h) override;
501
502 virtual const char* default_layout() const;
503 virtual const char* default_layout_android_vertical() const;
504 virtual const char* default_layout_android_horizontal() const;
505
511 virtual void command_line_arg_changed(const std::string& argname);
512
523
535 virtual void snapshot(
536 Image* image,
537 index_t x0=0, index_t y0=0, index_t width=0, index_t height=0,
538 bool redraw = true
539 );
540
549 virtual void snapshot(std::string filename = "", bool verbose=false);
550
554 void declare_args() override;
555
556 protected:
557 bool locked_; // avoid starting command when command is running
558 bool lighting_;
559 bool edit_light_;
560 bool clipping_;
561 GLUPclipMode clip_mode_;
562 bool edit_clip_;
563 bool fixed_clip_;
564 GLenum effect_;
565 vec4f background_color_;
566
567 bool viewer_properties_visible_;
568 bool object_properties_visible_;
569 bool console_visible_;
570 bool text_editor_visible_;
571 bool use_text_editor_;
572 bool command_line_editor_visible_;
573
574 Box roi_;
575 double roi_radius_;
576 vec3 object_translation_;
577 ArcBall object_rotation_;
578 ArcBall light_rotation_;
579 ArcBall clip_rotation_;
580 vec3 clip_translation_;
581 bool three_D_;
582 double zoom_;
583 double zoom_down_;
585 bool props_pinned_;
586
587 enum MouseOp {
588 MOUSE_NOOP, MOUSE_ROTATE, MOUSE_TRANSLATE, MOUSE_ZOOM
589 } mouse_op_;
590
591 enum MouseTarget {
592 MOUSE_NOTARGET, MOUSE_OBJECT, MOUSE_LIGHT, MOUSE_CLIP
593 } mouse_target_;
594
595 vec2 mouse_down_xy_; // in [-1,1] x [-1,1]
596 vec2 mouse_xy_; // in [-1,1] x [-1,1]
597
598 // Current transform, for picking
599 GLint viewport_[4];
600 mat4 modelview_transpose_;
601 mat4 project_transpose_;
602
603 std::string path_;
604 std::string current_file_;
605 char filename_[geo_imgui_string_length]; // Buffer for file dialog.
606 GLuint geogram_logo_texture_;
607
608 Console_var console_;
609 StatusBar_var status_bar_;
610 TextEditor text_editor_;
611
612 std::map< std::string, std::function<void()> > key_funcs_;
613 std::map< std::string, std::string > key_funcs_help_;
614
616 ColormapInfo() : texture(0) {
617 }
618 GLuint texture;
619 std::string name;
620 };
621
622 vector<ColormapInfo> colormaps_;
623 FullScreenEffectImpl_var full_screen_effect_;
624
625 lua_State* lua_state_;
626 bool lua_error_occured_;
627 };
628
629}
630
631#endif
Base class for all applications.
Controls a 3d rotation from user mouse input.
Base class for all applications.
Definition application.h:74
static Application * instance()
Gets the instance.
Definition application.h:92
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 run_key_func(const std::string &key)
Runs the key func associated with a given key.
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:703
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:340
Implementation of the status bar.
A simple text editor.