27#ifndef EASY3D_VIEWER_VIEWER_H
28#define EASY3D_VIEWER_VIEWER_H
35#include <easy3d/core/types.h>
81 const std::string&
title =
"Easy3D Viewer",
85 bool full_screen =
false,
86 bool resizable =
true,
103 int run(
bool see_all =
true);
123 const std::string&
title()
const {
return title_; }
129 void resize(
int w,
int h);
132 int width()
const {
return width_; }
136 void viewer_size(
int& w,
int& h)
const { w = width_; h = height_; }
206 virtual bool save()
const;
232 virtual Model*
add_model(
const std::string& file_name,
bool create_default_drawables =
true);
253 Model*
add_model(std::shared_ptr<Model> model,
bool create_default_drawables =
true);
287 const std::vector< std::shared_ptr<Model> >&
models()
const {
return models_; }
337 const std::vector< std::shared_ptr<Drawable> >&
drawables()
const {
return drawables_; }
386 bool snapshot(
const std::string& file_name,
float scaling = 1.0f,
int samples = 4,
int back_ground = 1,
bool expand =
true)
const;
416 void set_usage(
const std::string& manual =
"default",
const std::string& screen_hint =
"");
429 KEY_0 = 48, KEY_1 = 49, KEY_2 = 50, KEY_3 = 51, KEY_4 = 52, KEY_5 = 53, KEY_6 = 54, KEY_7 = 55,
430 KEY_8 = 56, KEY_9 = 57,
432 KEY_A = 65, KEY_B = 66, KEY_C = 67, KEY_D = 68, KEY_E = 69, KEY_F = 70, KEY_G = 71, KEY_H = 72,
433 KEY_I = 73, KEY_J = 74, KEY_K = 75, KEY_L = 76, KEY_M = 77, KEY_N = 78, KEY_O = 79, KEY_P = 80,
434 KEY_Q = 81, KEY_R = 82, KEY_S = 83, KEY_T = 84, KEY_U = 85, KEY_V = 86, KEY_W = 87, KEY_X = 88,
435 KEY_Y = 89, KEY_Z = 90,
437 KEY_RIGHT = 262, KEY_LEFT = 263, KEY_DOWN = 264, KEY_UP = 265,
438 KEY_F1 = 290, KEY_F2 = 291, KEY_F3 = 292, KEY_F4 = 293, KEY_F5 = 294,
439 KEY_F6 = 295, KEY_F7 = 296, KEY_F8 = 297, KEY_F9 = 298,
442 KEY_COMMA = 44, KEY_MINUS = 45, KEY_PERIOD = 46,
443 KEY_SLASH = 47, KEY_SEMICOLON = 59, KEY_EQUAL = 61,
444 KEY_LEFT_BRACKET = 91, KEY_BACKSLASH = 92, KEY_RIGHT_BRACKET = 93
452 MODIF_SHIFT = 0x0001,
499 commands_[key][modifier] = std::make_pair(func, model);
519 virtual void draw()
const;
539 virtual void pre_draw();
543 virtual void post_draw();
548 virtual void post_resize(
int w,
int h) { (void)w, (
void)h; }
551 virtual bool mouse_press_event(
int x,
int y,
int button,
int modifiers);
553 virtual bool mouse_release_event(
int x,
int y,
int button,
int modifiers);
555 virtual bool mouse_drag_event(
int x,
int y,
int dx,
int dy,
int button,
int modifiers);
557 virtual bool mouse_free_move_event(
int x,
int y,
int dx,
int dy,
int modifiers);
559 virtual bool mouse_scroll_event(
int x,
int y,
int dx,
int dy);
563 virtual bool char_input_event(
unsigned int codepoint);
566 virtual bool key_press_event(
int key,
int modifiers);
567 virtual bool key_release_event(
int key,
int modifiers);
570 virtual bool drop_event(
const std::vector<std::string> & filenames);
573 virtual bool focus_event(
bool focused);
576 GLFWwindow *create_window(
const std::string &
title,
587 void setup_callbacks(GLFWwindow*);
590 virtual bool callback_event_cursor_pos(
double x,
double y);
591 virtual bool callback_event_mouse_button(
int button,
int action,
int modifiers);
592 virtual bool callback_event_keyboard(
int key,
int action,
int mods);
593 virtual bool callback_event_character(
unsigned int codepoint);
594 virtual bool callback_event_drop(
int count,
const char **filenames);
595 virtual bool callback_event_scroll(
double dx,
double dy);
596 virtual void callback_event_resize(
int w,
int h);
598 void draw_corner_axes()
const;
614 std::unique_ptr<Camera> camera_;
616 std::unique_ptr<KeyFrameInterpolator> kfi_;
625 vec4 background_color_;
628 bool process_events_;
631 std::unique_ptr<TextRenderer> texter_;
632 bool show_easy3d_logo_;
638 int mouse_current_x_;
639 int mouse_current_y_;
640 int mouse_pressed_x_;
641 int mouse_pressed_y_;
644 bool show_pivot_point_;
645 bool show_frame_rate_;
650 std::unique_ptr<TrianglesDrawable> drawable_axes_;
653 std::unique_ptr<LinesDrawable2D> drawable_pivot_;
656 bool show_camera_path_;
658 std::vector< std::shared_ptr<Model> > models_;
662 std::vector< std::shared_ptr<Drawable> > drawables_;
664 typedef std::pair<Function, Model*> FunctionModel;
665 std::map<Key, std::map<Modifier, FunctionModel> > commands_;
A perspective or orthographic camera.
Definition camera.h:113
The base class for drawable objects. A drawable represent a set of points, line segments,...
Definition drawable.h:58
A keyframe interpolator for animation generation.
Definition key_frame_interpolator.h:104
The drawable for rendering a set of line segments in the screen space.
Definition drawable_lines_2D.h:43
The base class of renderable 3D models.
Definition model.h:50
TextRenderer enables quick and easy string rendering in OpenGL applications.
Definition text_renderer.h:52
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition drawable_triangles.h:46
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:498
Button
Mouse buttons.
Definition viewer.h:464
virtual ~Viewer()
The destructor.
Definition viewer.cpp:553
bool is_animating() const
Is animation currently being performed.
Definition viewer.cpp:1237
void framebuffer_size(int &w, int &h) const
Queries the size of the framebuffer.
Definition viewer.cpp:625
void clear_scene()
Delete all visual contents of the viewer (all models and drawables).
Definition viewer.cpp:562
virtual void exit()
Terminate the viewer.
Definition viewer.cpp:1196
const std::string & title() const
Query the window title of the viewer.
Definition viewer.h:123
void set_title(const std::string &title)
Set the window title of the viewer.
Definition viewer.cpp:589
void viewer_size(int &w, int &h) const
Queries the size of the viewer/window.
Definition viewer.h:136
const Camera * camera() const
Returns the camera used by the viewer. See Camera.
Definition viewer.h:183
bool delete_drawable(Drawable *drawable)
Definition viewer.cpp:1368
Model * current_model() const
Query the active model.
Definition viewer.cpp:767
const vec4 & background_color() const
Query the background color of the viewer.
Definition viewer.h:178
virtual bool save() const
Save the active model (if exists) to a file.
Definition viewer.cpp:1446
const std::vector< std::shared_ptr< Drawable > > & drawables() const
Query the drawables managed by this viewer.
Definition viewer.h:337
const std::vector< std::shared_ptr< Model > > & models() const
Query the models managed by this viewer.
Definition viewer.h:287
void resize(int w, int h)
Set/Change the viewer size.
Definition viewer.cpp:602
Modifier
The key modifiers. Currently only Shift, Ctrl, and Alt are supported.
Definition viewer.h:450
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:1093
void set_background_color(const vec4 &color)
Set the background color of the viewer.
Definition viewer.h:172
int samples() const
Query the actual samples of the viewer.
Definition viewer.h:160
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:75
virtual 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:1318
void fit_screen(const 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:1387
Key
The keys. Currently only a limited number of commonly used keys are supported.
Definition viewer.h:425
void set_usage(const std::string &manual="default", const std::string &screen_hint="")
The usage information of the viewer.
Definition viewer.cpp:1119
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:1242
int framebuffer_width() const
Returns the width of the framebuffer, which is identical to: width() * dpi_scaling().
Definition viewer.cpp:611
Camera * camera()
Returns the camera used by the viewer. See Camera.
Definition viewer.h:181
int height() const
Returns the height of the viewer/window.
Definition viewer.h:134
int width() const
Returns the width of the viewer/window.
Definition viewer.h:132
std::function< bool(Viewer *viewer)> animation_func_
Function called at an equal interval for animation.
Definition viewer.h:506
void set_animation(bool b)
Enable/Disable animation.
Definition viewer.cpp:1231
virtual bool open()
Open a model (PointCloud/SurfaceMesh/Graph) from a file into the viewer. On success,...
Definition viewer.cpp:1420
int run(bool see_all=true)
Run the viewer.
Definition viewer.cpp:1127
void update() const
Update the display (i.e., repaint).
Definition viewer.cpp:630
Drawable * add_drawable(std::shared_ptr< Drawable > drawable)
Add a drawable to the viewer to be visualized. On success, the viewer will be in charge of the memory...
Definition viewer.cpp:1346
virtual bool snapshot() const
Take a snapshot of the screen and save it to a file.
Definition viewer.cpp:1487
float dpi_scaling() const
Query the scaling factor for high DPI devices (e.g., MackBook pro).
Definition viewer.h:166
void set_position(int xpos, int ypos)
Sets the position of the content area of the viewer.
Definition viewer.cpp:597
std::function< bool(Viewer *viewer, Model *model)> Function
Definition viewer.h:487
int framebuffer_height() const
Returns the height of the framebuffer, which is identical to: height() * dpi_scaling().
Definition viewer.cpp:618
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46