Polygon Mesh Processing Library
Loading...
Searching...
No Matches
MeshViewer Class Reference

Simple viewer for a SurfaceMesh. More...

#include <pmp/visualization/mesh_viewer.h>

Inherits TrackballViewer.

Public Member Functions

 MeshViewer (const char *title, int width, int height, bool showgui=true)
 constructor
 
 ~MeshViewer () override=default
 destructor
 
virtual void load_mesh (const char *filename)
 load a mesh from file filename
 
void load_matcap (const char *filename)
 load a matcap texture from file filename
 
void load_texture (const char *filename, GLint format=GL_RGB, GLint min_filter=GL_LINEAR_MIPMAP_LINEAR, GLint mag_filter=GL_LINEAR, GLint wrap=GL_CLAMP_TO_EDGE)
 load a texture from file filename
 
virtual void update_mesh ()
 update mesh normals and all buffers for OpenGL rendering.
 
void draw (const std::string &draw_mode) override
 draw the scene in different draw modes
 
void process_imgui () override
 handle ImGUI interface
 
void keyboard (int key, int code, int action, int mod) override
 this function handles keyboard events
 
void drop (int count, const char **paths) override
 load mesh by dropping file onto the window
 
Vertex pick_vertex (int x, int y)
 get vertex closest to 3D position under the mouse cursor
 
- Public Member Functions inherited from TrackballViewer
 TrackballViewer (const char *title, int width, int height, bool showgui=true)
 constructor
 
 ~TrackballViewer () override
 destructor
 
void set_scene (const vec3 &center, float radius)
 define the center and radius of the scene/ used for trackball rotation
 
void view_all ()
 adjust camera such that the whole scene (defined by set_scene()) is visible
 
- Public Member Functions inherited from Window
 Window (const char *title, int width, int height, bool showgui=true)
 constructor
 
virtual ~Window ()
 destructor
 
int run ()
 main window loop
 

Protected Attributes

std::string filename_
 the current file
 
- Protected Attributes inherited from TrackballViewer
unsigned int draw_mode_
 draw modes
 
vec3 center_
 scene position and dimension
 
float near_
 projection parameters
 
mat4 projection_matrix_
 OpenGL matrices.
 
ivec2 last_point_2d_
 trackball helpers
 

Additional Inherited Members

- Protected Member Functions inherited from TrackballViewer
void display () override
 this function is called when the scene has to be rendered.
 
void keyboard (int key, int code, int action, int mods) override
 this function handles keyboard events
 
void mouse (int button, int action, int mods) override
 this function handles mouse button events
 
void motion (double xpos, double ypos) override
 this function handles mouse motion (passive/active position)
 
void scroll (double xoffset, double yoffset) override
 this function handles mouse scroll events
 
void clear_draw_modes ()
 reset the list of draw modes
 
unsigned int add_draw_mode (const std::string &drawMode)
 add a draw mode
 
void set_draw_mode (const std::string &drawMode)
 activate a draw mode
 
virtual void init ()
 initialize all OpenGL states
 
virtual void draw (const std::string &drawMode)=0
 this function is responsible for rendering the scene
 
void rotation (int x, int y)
 turn a mouse event into a rotation around the scene center. calls rotate().
 
void translation (int x, int y)
 turn a mouse event into a translation in the view plane. calls translate().
 
void zoom (int x, int y)
 turn a mouse event into a zoom, i.e., translation in z-direction. calls translate().
 
bool pick (vec3 &result)
 get 3D position under the mouse cursor
 
bool pick (int x, int y, vec3 &result)
 get 3D position of 2D position (x,y)
 
void fly_to (int x, int y)
 fly toward the position Distributed under the mouse cursor and set rotation center to it
 
void translate (const vec3 &trans)
 translate the scene and update modelview matrix
 
void rotate (const vec3 &axis, float angle)
 rotate the scene (around its center) and update modelview matrix
 
bool map_to_sphere (const ivec2 &point, vec3 &result)
 virtual trackball: map 2D screen point to unit sphere. used by rotate().
 
- Protected Member Functions inherited from Window
virtual void display ()=0
 this function is called when the scene has to be rendered.
 
virtual void keyboard (int, int, int, int)
 this function handles keyboard events
 
virtual void character (unsigned int)
 this function handles unicode character events
 
virtual void mouse (int, int, int)
 this function handles mouse button events
 
virtual void motion (double, double)
 this function handles mouse motion (passive/active position)
 
virtual void scroll (double, double)
 this function handles mouse scroll events
 
virtual void resize (int, int)
 this function is called if the window is resized
 
virtual void drop (int, const char **)
 this function is called if a file is dropped onto the window
 
virtual void process_imgui ()
 this function renders the ImGUI elements and handles their events
 
virtual void do_processing ()
 this function is called just before rendering
 
void init_imgui ()
 setup ImGUI user interface
 
void scale_imgui (float scale)
 scale ImGUI elements and font
 
bool show_imgui () const
 is ImGUI visible or hidden?
 
void show_imgui (bool b)
 show or hide ImGUI
 
void clear_help_items ()
 clear help items
 
void add_help_item (std::string key, std::string description, int position=-1)
 add key binding (or general action description)
 
void show_help ()
 show ImGUI help dialog
 
void screenshot ()
 take a screenshot, save it to title-n.png using the window title and an incremented number n.
 
int width () const
 width of window
 
int height () const
 height of window
 
float high_dpi_scaling () const
 highDPI scaling
 
float imgui_scaling () const
 imgui scaling
 
void cursor_pos (double &x, double &y) const
 get position of mouse cursor
 
bool left_mouse_pressed () const
 is left mouse button pressed down?
 
bool right_mouse_pressed () const
 is right mouse button pressed down?
 
bool middle_mouse_pressed () const
 is middle mouse button pressed down?
 
bool ctrl_pressed () const
 is CTRL modifier key pressed down?
 
bool alt_pressed () const
 is ALT modifier key pressed down?
 
bool shift_pressed () const
 is SHIFT modifier key pressed down?
 

Detailed Description

Simple viewer for a SurfaceMesh.

Member Function Documentation

◆ update_mesh()

void update_mesh ( )
virtual

update mesh normals and all buffers for OpenGL rendering.

call this function whenever you change either the vertex positions or the triangulation of the mesh