27#ifndef EASY3D_VIEWER_VIEWER_H
28#define EASY3D_VIEWER_VIEWER_H
34#include <easy3d/core/types.h>
44 class TrianglesDrawable;
46 class KeyFrameInterpolator;
77 const std::string&
title =
"Easy3D Viewer",
81 bool full_screen =
false,
82 bool resizable =
true,
99 int run(
bool see_all =
true);
119 const std::string&
title()
const {
return title_; }
125 void resize(
int w,
int h);
128 int width()
const {
return width_; }
132 void viewer_size(
int& w,
int& h)
const { w = width_; h = height_; }
202 virtual bool save()
const;
228 virtual Model*
add_model(
const std::string& file_name,
bool create_default_drawables =
true);
263 const std::vector<Model*>&
models()
const {
return models_; }
302 const std::vector<Drawable*>&
drawables()
const {
return drawables_; }
351 bool snapshot(
const std::string& file_name,
float scaling = 1.0f,
int samples = 0,
int back_ground = 1,
bool expand =
true)
const;
377 const std::string&
usage()
const {
return usage_string_; }
378 void set_usage(
const std::string& usg) { usage_string_ = usg; }
391 KEY_0 = 48, KEY_1 = 49, KEY_2 = 50, KEY_3 = 51, KEY_4 = 52, KEY_5 = 53, KEY_6 = 54, KEY_7 = 55,
392 KEY_8 = 56, KEY_9 = 57,
394 KEY_A = 65, KEY_B = 66, KEY_C = 67, KEY_D = 68, KEY_E = 69, KEY_F = 70, KEY_G = 71, KEY_H = 72,
395 KEY_I = 73, KEY_J = 74, KEY_K = 75, KEY_L = 76, KEY_M = 77, KEY_N = 78, KEY_O = 79, KEY_P = 80,
396 KEY_Q = 81, KEY_R = 82, KEY_S = 83, KEY_T = 84, KEY_U = 85, KEY_V = 86, KEY_W = 87, KEY_X = 88,
397 KEY_Y = 89, KEY_Z = 90,
399 KEY_RIGHT = 262, KEY_LEFT = 263, KEY_DOWN = 264, KEY_UP = 265,
400 KEY_F1 = 290, KEY_F2 = 291, KEY_F3 = 292, KEY_F4 = 293, KEY_F5 = 294,
401 KEY_F6 = 295, KEY_F7 = 296, KEY_F8 = 297, KEY_F9 = 298,
404 KEY_COMMA = 44, KEY_MINUS = 45, KEY_PERIOD = 46,
405 KEY_SLASH = 47, KEY_SEMICOLON = 59, KEY_EQUAL = 61,
406 KEY_LEFT_BRACKET = 91, KEY_BACKSLASH = 92, KEY_RIGHT_BRACKET = 93
414 MODIF_SHIFT = 0x0001,
461 commands_[key][modifier] = std::make_pair(func, model);
481 virtual void draw()
const;
501 virtual void pre_draw();
505 virtual void post_draw();
510 virtual void post_resize(
int w,
int h) { (void)w, (
void)h; }
513 virtual bool mouse_press_event(
int x,
int y,
int button,
int modifiers);
515 virtual bool mouse_release_event(
int x,
int y,
int button,
int modifiers);
517 virtual bool mouse_drag_event(
int x,
int y,
int dx,
int dy,
int button,
int modifiers);
519 virtual bool mouse_free_move_event(
int x,
int y,
int dx,
int dy,
int modifiers);
521 virtual bool mouse_scroll_event(
int x,
int y,
int dx,
int dy);
525 virtual bool char_input_event(
unsigned int codepoint);
528 virtual bool key_press_event(
int key,
int modifiers);
529 virtual bool key_release_event(
int key,
int modifiers);
532 virtual bool drop_event(
const std::vector<std::string> & filenames);
535 virtual bool focus_event(
bool focused);
538 GLFWwindow *create_window(
const std::string &
title,
549 void setup_callbacks(GLFWwindow*);
552 virtual bool callback_event_cursor_pos(
double x,
double y);
553 virtual bool callback_event_mouse_button(
int button,
int action,
int modifiers);
554 virtual bool callback_event_keyboard(
int key,
int action,
int mods);
555 virtual bool callback_event_character(
unsigned int codepoint);
556 virtual bool callback_event_drop(
int count,
const char **filenames);
557 virtual bool callback_event_scroll(
double dx,
double dy);
558 virtual void callback_event_resize(
int w,
int h);
560 void draw_corner_axes()
const;
581 std::string usage_string_;
586 vec4 background_color_;
589 bool process_events_;
598 int mouse_current_x_;
599 int mouse_current_y_;
600 int mouse_pressed_x_;
601 int mouse_pressed_y_;
604 bool show_pivot_point_;
605 bool show_frame_rate_;
613 bool show_camera_path_;
615 std::vector<Model*> models_;
619 std::vector<Drawable*> drawables_;
621 typedef std::pair<Function, Model*> FunctionModel;
622 std::map<Key, std::map<Modifier, FunctionModel> > commands_;
A perspective or orthographic camera.
Definition: camera.h:116
The base class for drawable objects. A drawable represent a set of points, line segments,...
Definition: drawable.h:56
A keyframe interpolator for animation generation.
Definition: key_frame_interpolator.h:104
The base class of renderable 3D models.
Definition: model.h:49
TextRenderer enables quick and easy string rendering in OpenGL applications.
Definition: text_renderer.h:53
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition: drawable_triangles.h:46
The built-in Easy3D viewer.
Definition: viewer.h:61
void bind(const Function &func, Model *model, Key key, Modifier modifier=MODIF_NONE)
Bind a function that will be triggered by the shortcut 'modifier + key'.
Definition: viewer.h:460
Button
Mouse buttons.
Definition: viewer.h:426
virtual ~Viewer()
The destructor.
Definition: viewer.cpp:551
const easy3d::vec4 & background_color() const
Query the background color of the viewer.
Definition: viewer.h:174
bool is_animating() const
Is animation currently being performed.
Definition: viewer.cpp:1199
void framebuffer_size(int &w, int &h) const
Queries the size of the framebuffer.
Definition: viewer.cpp:626
void clear_scene()
Delete all visual contents of the viewer (all models and drawables).
Definition: viewer.cpp:556
virtual void exit()
Terminate the viewer.
Definition: viewer.cpp:1159
const std::string & usage() const
The usage information of the viewer. For the time being, it is the manual of this default viewer.
Definition: viewer.h:377
const std::string & title() const
Query the window title of the viewer.
Definition: viewer.h:119
void set_title(const std::string &title)
Set the window title of the viewer.
Definition: viewer.cpp:590
void viewer_size(int &w, int &h) const
Queries the size of the viewer/window.
Definition: viewer.h:132
const Camera * camera() const
Returns the camera used by the viewer. See Camera.
Definition: viewer.h:179
bool delete_drawable(Drawable *drawable)
Definition: viewer.cpp:1319
Model * current_model() const
Query the active model.
Definition: viewer.cpp:746
virtual bool save() const
Save the active model (if exists) to a file.
Definition: viewer.cpp:1395
void resize(int w, int h)
Set/Change the viewer size.
Definition: viewer.cpp:603
bool add_drawable(Drawable *drawable)
Add a drawable to the viewer to be visualized. After a drawable being added to the viewer,...
Definition: viewer.cpp:1302
Modifier
The key modifiers. Currently only Shift, Ctrl, and Alt are supported.
Definition: viewer.h:412
virtual vec3 point_under_pixel(int x, int y, bool &found) const
Query the XYZ coordinates of the surface point under the cursor.
Definition: viewer.cpp:1064
int samples() const
Query the actual samples of the viewer.
Definition: viewer.h:156
Viewer(const std::string &title="Easy3D Viewer", int samples=4, int gl_major=3, int gl_minor=2, bool full_screen=false, bool resizable=true, int depth_bits=24, int stencil_bits=8, int width=800, int height=600)
Constructor.
Definition: viewer.cpp:74
bool delete_model(Model *model)
Delete a model. The memory of the model will be released and its existing drawables also be deleted.
Definition: viewer.cpp:1273
Key
The keys. Currently only a limited number of commonly used keys are supported.
Definition: viewer.h:387
const std::vector< Model * > & models() const
Query the models managed by this viewer.
Definition: viewer.h:263
const std::vector< Drawable * > & drawables() const
Query the drawables managed by this viewer.
Definition: viewer.h:302
virtual Model * add_model(const std::string &file_name, bool create_default_drawables=true)
Add a model from a file to the viewer to be visualized. On success, the viewer will be in charge of t...
Definition: viewer.cpp:1204
int framebuffer_width() const
Returns the width of the framebuffer, which is identical to: width() * dpi_scaling().
Definition: viewer.cpp:612
void fit_screen(const easy3d::Model *model=nullptr)
Moves the camera so that the entire scene or the active model is centered on the screen at a proper s...
Definition: viewer.cpp:1337
Camera * camera()
Returns the camera used by the viewer. See Camera.
Definition: viewer.h:177
int height() const
Returns the height of the viewer/window.
Definition: viewer.h:130
int width() const
Returns the width of the viewer/window.
Definition: viewer.h:128
std::function< bool(Viewer *viewer)> animation_func_
Function called at an equal interval for animation.
Definition: viewer.h:468
void set_animation(bool b)
Enable/Disable animation.
Definition: viewer.cpp:1193
virtual bool open()
Open a model (PointCloud/SurfaceMesh/Graph) from a file into the viewer. On success,...
Definition: viewer.cpp:1369
int run(bool see_all=true)
Run the viewer.
Definition: viewer.cpp:1090
void update() const
Update the display (i.e., repaint).
Definition: viewer.cpp:631
void set_background_color(const easy3d::vec4 &c)
Set the background color of the viewer.
Definition: viewer.h:168
bool snapshot() const
Take a snapshot of the screen and save it to a file.
Definition: viewer.cpp:1436
float dpi_scaling() const
Query the scaling factor for high DPI devices (e.g., MackBook pro).
Definition: viewer.h:162
void set_position(int xpos, int ypos)
Sets the position of the content area of the viewer.
Definition: viewer.cpp:598
std::function< bool(Viewer *viewer, Model *model)> Function
Definition: viewer.h:449
int framebuffer_height() const
Returns the height of the framebuffer, which is identical to: height() * dpi_scaling().
Definition: viewer.cpp:619
Definition: collider.cpp:182