Easy3D 2.6.1
|
The built-in Easy3D viewer. More...
#include <easy3d/viewer/viewer.h>
Public Member Functions | |
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. | |
virtual | ~Viewer () |
The destructor. | |
int | run (bool see_all=true) |
Run the viewer. | |
virtual void | exit () |
Terminate the viewer. | |
Viewer properties | |
void | set_title (const std::string &title) |
Set the window title of the viewer. | |
const std::string & | title () const |
Query the window title of the viewer. | |
void | resize (int w, int h) |
Set/Change the viewer size. | |
int | width () const |
Returns the width of the viewer/window. | |
int | height () const |
Returns the height of the viewer/window. | |
void | viewer_size (int &w, int &h) const |
Queries the size of the viewer/window. | |
int | framebuffer_width () const |
Returns the width of the framebuffer, which is identical to: width() * dpi_scaling(). | |
int | framebuffer_height () const |
Returns the height of the framebuffer, which is identical to: height() * dpi_scaling(). | |
void | framebuffer_size (int &w, int &h) const |
Queries the size of the framebuffer. | |
void | set_position (int xpos, int ypos) |
Sets the position of the content area of the viewer. | |
int | samples () const |
Query the actual samples of the viewer. | |
float | dpi_scaling () const |
Query the scaling factor for high DPI devices (e.g., MackBook pro). | |
void | set_background_color (const vec4 &color) |
Set the background color of the viewer. | |
const vec4 & | background_color () const |
Query the background color of the viewer. | |
Camera * | camera () |
Returns the camera used by the viewer. See Camera . | |
const Camera * | camera () const |
Returns the camera used by the viewer. See Camera . | |
File IO | |
virtual bool | open () |
Open a model (PointCloud/SurfaceMesh/Graph) from a file into the viewer. On success, the viewer will be in charge of the memory management of the model. | |
virtual bool | save () const |
Save the active model (if exists) to a file. | |
Drawable management | |
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 management of the drawable. | |
Drawable * | add_drawable (Drawable *drawable) |
Add a drawable to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the drawable. | |
bool | delete_drawable (Drawable *drawable) |
const std::vector< std::shared_ptr< Drawable > > & | drawables () const |
Query the drawables managed by this viewer. | |
void | clear_scene () |
Delete all visual contents of the viewer (all models and drawables). | |
UI-related functions | |
void | update () const |
Update the display (i.e., repaint). | |
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 scale. | |
virtual bool | snapshot () const |
Take a snapshot of the screen and save it to a file. | |
bool | snapshot (const std::string &file_name, float scaling=1.0f, int samples=4, int back_ground=1, bool expand=true) const |
Take a snapshot of the screen and save it to an image file. Supported image format: png, jpg, bmp, and tga. | |
virtual vec3 | point_under_pixel (int x, int y, bool &found) const |
Query the XYZ coordinates of the surface point under the cursor. | |
void | set_usage (const std::string &manual="default", const std::string &screen_hint="") |
The usage information of the viewer. | |
Algorithm execution | |
enum | Key { KEY_UNKNOWN = -1 , KEY_0 = 48 , KEY_1 = 49 , KEY_2 = 50 , KEY_3 = 51 , KEY_4 = 52 , KEY_5 = 53 , KEY_6 = 54 , KEY_7 = 55 , KEY_8 = 56 , KEY_9 = 57 , KEY_A = 65 , KEY_B = 66 , KEY_C = 67 , KEY_D = 68 , KEY_E = 69 , KEY_F = 70 , KEY_G = 71 , KEY_H = 72 , KEY_I = 73 , KEY_J = 74 , KEY_K = 75 , KEY_L = 76 , KEY_M = 77 , KEY_N = 78 , KEY_O = 79 , KEY_P = 80 , KEY_Q = 81 , KEY_R = 82 , KEY_S = 83 , KEY_T = 84 , KEY_U = 85 , KEY_V = 86 , KEY_W = 87 , KEY_X = 88 , KEY_Y = 89 , KEY_Z = 90 , KEY_RIGHT = 262 , KEY_LEFT = 263 , KEY_DOWN = 264 , KEY_UP = 265 , KEY_F1 = 290 , KEY_F2 = 291 , KEY_F3 = 292 , KEY_F4 = 293 , KEY_F5 = 294 , KEY_F6 = 295 , KEY_F7 = 296 , KEY_F8 = 297 , KEY_F9 = 298 , KEY_SPACE = 32 , KEY_COMMA = 44 , KEY_MINUS = 45 , KEY_PERIOD = 46 , KEY_SLASH = 47 , KEY_SEMICOLON = 59 , KEY_EQUAL = 61 , KEY_LEFT_BRACKET = 91 , KEY_BACKSLASH = 92 , KEY_RIGHT_BRACKET = 93 } |
The keys. Currently only a limited number of commonly used keys are supported. | |
enum | Modifier { MODIF_NONE = 0x0000 , MODIF_SHIFT = 0x0001 , MODIF_CTRL = 0x0002 , MODIF_ALT = 0x0004 } |
The key modifiers. Currently only Shift, Ctrl, and Alt are supported. | |
enum | Button { BUTTON_LEFT = 0 , BUTTON_RIGHT = 1 , BUTTON_MIDDLE = 2 } |
Mouse buttons. | |
using | Function = std::function<bool(Viewer* viewer, Model* model)> |
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'. | |
Animation | |
std::function< bool(Viewer *viewer)> | animation_func_ |
Function called at an equal interval for animation. | |
void | set_animation (bool b) |
Enable/Disable animation. | |
bool | is_animating () const |
Is animation currently being performed. | |
Model management | |
Model * | add_model (Model *model, bool create_default_drawables=true) |
Add an existing model to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the model. | |
virtual bool | delete_model (Model *model) |
Delete a model. The memory of the model will be released and its existing drawables also be deleted. | |
const std::vector< std::shared_ptr< Model > > & | models () const |
Query the models managed by this viewer. | |
Model * | current_model () const |
Query the active model. | |
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 the memory management of the model. The loaded model can be accessed by the 'current_model()' method. | |
Model * | add_model (std::shared_ptr< Model > model, bool create_default_drawables=true) |
Add an existing model to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the model. | |
The built-in Easy3D viewer.
Easy3D is really easy to use. That's why it has such a name. To use the viewer, simply create an instance of Viewer, and call the run() method, e.g.,
The default Easy3D viewer can be easily extended by deriving your enhanced viewer from it by re-implementing some of its functions (see the documentation of Viewer).
A function type, which applies the user's algorithm(s)/operation(s) on the given model.
viewer | A pointer to this viewer. |
model | The model to be operated on. Example of defining such a function: auto mesh = surface_reconstruction(cloud);
if (!mesh)
return false;
viewer->add_model(mesh);
viewer->update();
return true;
}
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 |
|
explicit |
Constructor.
title | The window title of the viewer, which can be changed by calling set_title() after construction. |
samples | The number of samples for multisample antialiasing |
gl_major | The OpenGL major version to request. Must be >= 3. The minimal version of OpenGL required to use the Core Profile is OpenGL 3.2. |
gl_minor | The OpenGL minor version to request. Must be >= 2. The minimal version of OpenGL required to use the Core Profile is OpenGL 3.2. |
full_screen | Do you want the viewer to be fullscreen? |
resizable | Whether the viewer will be resizable by the user. |
depth_bits | The desired bit depths of the depth component of the default framebuffer. |
stencil_bits | The desired bit depths of the stencil component of the default framebuffer. |
width | The width of the viewer, which can be changed by calling resize() after construction. |
height | The height of the viewer, which can be changed by calling resize() after construction. |
Add a drawable to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the drawable.
The use of drawables for visualization is quite flexible. Drawables are typically created for rendering 3D models (e.g., point clouds, meshes, graphs) and a 3D model is usually loaded from a file or generated by an algorithm. This method allows the user to visualize drawables without defining a 3D model.
drawable | The pointer to the drawable. |
Add a drawable to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the drawable.
The use of drawables for visualization is quite flexible. Drawables are typically created for rendering 3D models (e.g., point clouds, meshes, graphs) and a 3D model is usually loaded from a file or generated by an algorithm. This method allows the user to visualize drawables without defining a 3D model.
drawable | The pointer to the drawable. |
Add an existing model to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the model.
This method adds a model into the viewer. It allows the user to control if default drawables will be created. The default drawables are
model | The pointer to the model. |
create_default_drawables | If true, the default drawables will be created. |
|
inline |
Query the background color of the viewer.
Bind a function that will be triggered by the shortcut 'modifier + key'.
This operation will overwrite the previous function (if exist) bound to the same key-modifier shortcut.
func | The function to be executed, which will be triggered by the shortcut. |
model | The model to be processed. |
key | The shortcut key. |
modifier | The shortcut key modifier (e.g., Ctrl, Shift, Alt). This can be MODIF_NONE. |
Model * current_model | ( | ) | const |
Query the active model.
The viewer can manage/visualize/process multiple models. The default behavior of the Easy3D viewer is, when a command is triggerred (e.g., the Save menu was clicked), only the active model is processed. This method is used to identify the active model.
bool delete_drawable | ( | Drawable * | drawable | ) |
Delete the drawable from the viewer. The related drawables will also be deleted.
drawable | The pointer to the drawable. |
|
virtual |
Delete a model. The memory of the model will be released and its existing drawables also be deleted.
model | The pointer to the model. |
Reimplemented in OffScreen.
|
inline |
Query the scaling factor for high DPI devices (e.g., MackBook pro).
|
inline |
Query the drawables managed by this viewer.
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 scale.
model | The pointer to the model to be centered on the screen. If nullptr, the entire scene (i.e., all models) will be centered on the screen at a proper scale. |
|
inline |
Query the models managed by this viewer.
|
virtual |
Open a model (PointCloud/SurfaceMesh/Graph) from a file into the viewer. On success, the viewer will be in charge of the memory management of the model.
This method loads a model into the viewer. Internally, it will pop up a file dialog for the user to navigate to the file. After loading the model, the necessary drawables (e.g., "vertices" for point clouds, "faces" for surface meshes, and "edges" and "vertices" for graphs) will be created for visualization.
|
virtual |
Query the XYZ coordinates of the surface point under the cursor.
x | The cursor x-coordinate, relative to the left edge of the content area. |
y | The cursor y-coordinate, relative to the top edge of the content area. |
found | indicates whether the point was found or not. |
Reimplemented in MultiViewer.
void resize | ( | int | w, |
int | h ) |
Set/Change the viewer size.
w/h | The requested width/height (in pixels) of the viewer. |
int run | ( | bool | see_all = true | ) |
Run the viewer.
see_all | See all contents within the screen? If true, the entire scene (i.e., all models) will be centered on the screen at a proper scale. |
|
inline |
Query the actual samples of the viewer.
|
virtual |
Save the active model (if exists) to a file.
This method saves the active model to a file. Internally, it will pop up a file dialog for specifying the file name.
void set_animation | ( | bool | b | ) |
Enable/Disable animation.
animation_func_
must be provided to specify how scene geometry is modified.
|
inline |
Set the background color of the viewer.
color | The background color. |
void set_position | ( | int | xpos, |
int | ypos ) |
Sets the position of the content area of the viewer.
This function sets the position, in screen coordinates, of the upper-left corner of the content area of the viewer. If the viewer is a full screen window, this function does nothing.
xpos | The x-coordinate of the upper-left corner of the content area. |
ypos | The y-coordinate of the upper-left corner of the content area. |
void set_title | ( | const std::string & | title | ) |
Set the window title of the viewer.
title | The string of the title. |
void set_usage | ( | const std::string & | manual = "default", |
const std::string & | screen_hint = "" ) |
The usage information of the viewer.
manual | The manual of the viewer, to be shown in the console window. Using "default" will show the default shortcuts of the viewer. |
screen_hint | The hint to the user, which will be sown in the top-left corner of the viewer. |
|
virtual |
Take a snapshot of the screen and save it to a file.
This method takes a snapshot of the screen and saves the snapshot into an image file. Internally, it will pop up a file dialog for specifying the file name.
Reimplemented in MultiViewer.
bool snapshot | ( | const std::string & | file_name, |
float | scaling = 1.0f, | ||
int | samples = 4, | ||
int | back_ground = 1, | ||
bool | expand = true ) const |
Take a snapshot of the screen and save it to an image file. Supported image format: png, jpg, bmp, and tga.
This function renders the scene into a framebuffer and takes a snapshot of the framebuffer. It allows the snapshot image to have a dimension different from the viewer, and it has no limit on the image size (if memory allows).
file_name | The image file name. |
scaling | The scaling factor that determines the size of the image (default to 1.0, using the viewer size), i.e., image_width = viewer_width * scaling; image_height = viewer_height * scaling; |
samples | The required number of samples for antialiased rendering (which can be different from that of the default framebuffer). The default value is 4. |
back_ground | Determines the background color. 0: current color; 1: white; 2: transparent. |
expand | Expand the frustum to ensure the image aspect ratio. |
|
inline |
Query the window title of the viewer.
void update | ( | ) | const |
Update the display (i.e., repaint).
This method is used to update the display of the rendering. Client should call it when your data/view is changed.
|
Add a model from a file to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the model. The loaded model can be accessed by the 'current_model()' method.
This method loads a model into the viewer. It allows the user to control if default drawables will be created. The default drawables are
file_name | The string of the file name. |
create_default_drawables | If true, the default drawables will be created. |
Reimplemented in OffScreen.
Add an existing model to the viewer to be visualized. On success, the viewer will be in charge of the memory management of the model.
This method adds a model into the viewer. It allows the user to control if default drawables will be created. The default drawables are
model | The pointer to the model. |
create_default_drawables | If true, the default drawables will be created. |