libigl v2.5.0
Loading...
Searching...
No Matches
ViewerCore.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
4//
5// This Source Code Form is subject to the terms of the Mozilla Public License
6// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7// obtain one at http://mozilla.org/MPL/2.0/.
8#ifndef IGL_OPENGL_VIEWERCORE_H
9#define IGL_OPENGL_VIEWERCORE_H
10
11#include "MeshGL.h"
12
13#include "../igl_inline.h"
14#include <Eigen/Geometry>
15#include <Eigen/Core>
16
17namespace igl
18{
19namespace opengl
20{
21
22// Forward declaration
23class ViewerData;
24
27{
28public:
31
34
37
40
45 const Eigen::MatrixXd& V,
46 const Eigen::MatrixXi& F);
49 const Eigen::MatrixXd& V);
50
58 const Eigen::MatrixXd& V,
59 const Eigen::MatrixXi& F,
60 float & zoom,
61 Eigen::Vector3f& shift);
64 const Eigen::MatrixXd& V,
65 float & zoom,
66 Eigen::Vector3f& shift);
67
70
78 IGL_INLINE void draw(ViewerData& data, bool update_matrices = true);
86 IGL_INLINE void draw_shadow_pass(ViewerData& data, bool update_matrices = true);
100 ViewerData& data,
101 bool update_matrices,
102 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
103 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
104 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
105 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
110 ViewerData& data,
111 const igl::opengl::MeshGL::TextGL& labels
112 );
113
130
134 IGL_INLINE void set(unsigned int &property_mask, bool value = true) const;
135
138 IGL_INLINE void unset(unsigned int &property_mask) const;
139
142 IGL_INLINE void toggle(unsigned int &property_mask) const;
143
147 IGL_INLINE bool is_set(unsigned int property_mask) const;
148
153
154 // ------------------- Properties
155
157 unsigned int id = 1u;
158
160 Eigen::Vector4f background_color;
161
163 Eigen::Vector3f light_position;
180
184 Eigen::Quaternionf trackball_angle;
185
193 Eigen::Vector3f camera_base_translation;
195 Eigen::Vector3f camera_translation;
197 Eigen::Vector3f camera_eye;
199 Eigen::Vector3f camera_up;
201 Eigen::Vector3f camera_center;
208
211
216
219
221 Eigen::Vector4f viewport;
222
224 Eigen::Matrix4f view;
226 Eigen::Matrix4f proj;
228 Eigen::Matrix4f norm;
230 Eigen::Matrix4f shadow_view;
232 Eigen::Matrix4f shadow_proj;
233 public:
234 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
235};
236
237}
238}
239
240#include "../serialize.h"
241namespace igl {
242 namespace serialization {
243
244 inline void serialization(bool s, igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
245 {
246
247 SERIALIZE_MEMBER(background_color);
248
249 SERIALIZE_MEMBER(light_position);
250 SERIALIZE_MEMBER(lighting_factor);
251
252 SERIALIZE_MEMBER(trackball_angle);
253 SERIALIZE_MEMBER(rotation_type);
254
255 SERIALIZE_MEMBER(camera_base_zoom);
256 SERIALIZE_MEMBER(camera_zoom);
257 SERIALIZE_MEMBER(orthographic);
258 SERIALIZE_MEMBER(camera_base_translation);
259 SERIALIZE_MEMBER(camera_translation);
260 SERIALIZE_MEMBER(camera_view_angle);
261 SERIALIZE_MEMBER(camera_dnear);
262 SERIALIZE_MEMBER(camera_dfar);
263 SERIALIZE_MEMBER(camera_eye);
264 SERIALIZE_MEMBER(camera_center);
265 SERIALIZE_MEMBER(camera_up);
266
267 SERIALIZE_MEMBER(depth_test);
268 SERIALIZE_MEMBER(is_animating);
269 SERIALIZE_MEMBER(animation_max_fps);
270
271 SERIALIZE_MEMBER(object_scale);
272
273 SERIALIZE_MEMBER(viewport);
274 SERIALIZE_MEMBER(view);
275 SERIALIZE_MEMBER(proj);
276 SERIALIZE_MEMBER(norm);
277 }
278
279 template<>
280 inline void serialize(const igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
281 {
282 serialization(true, const_cast<igl::opengl::ViewerCore&>(obj), buffer);
283 }
284
285 template<>
286 inline void deserialize(igl::opengl::ViewerCore& obj, const std::vector<char>& buffer)
287 {
288 serialization(false, obj, const_cast<std::vector<char>&>(buffer));
289 }
290 }
291}
292
293#ifndef IGL_STATIC_LIBRARY
294# include "ViewerCore.cpp"
295#endif
296
297#endif
unsigned int GLuint
Definition MeshGL.h:26
Basic class of the 3D mesh viewer.
Definition ViewerCore.h:27
Eigen::Matrix4f shadow_proj
OpenGL shadow_proj transformation matrix on last render pass.
Definition ViewerCore.h:232
float object_scale
Caches the two-norm between the min/max point of the bounding box.
Definition ViewerCore.h:218
Eigen::Vector3f light_position
Light position (or direction to light)
Definition ViewerCore.h:163
bool is_animating
Whether "animating" (continuous drawing) is enabled.
Definition ViewerCore.h:213
void draw_labels(ViewerData &data, const igl::opengl::MeshGL::TextGL &labels)
Draw the text lables.
GLuint shadow_width
Width of the shadow map.
Definition ViewerCore.h:169
GLuint shadow_color_rbo
Shadow map color render buffer object.
Definition ViewerCore.h:177
void align_camera_center(const Eigen::MatrixXd &V)
This is an overloaded member function, provided for convenience. It differs from the above function o...
GLuint shadow_depth_tex
Shadow map depth texture.
Definition ViewerCore.h:173
bool depth_test
Whether testing for depth is enabled.
Definition ViewerCore.h:210
float camera_dnear
Near plane of camera.
Definition ViewerCore.h:205
GLuint shadow_height
Height of the shadow map.
Definition ViewerCore.h:171
void get_scale_and_shift_to_fit_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, float &zoom, Eigen::Vector3f &shift)
Determines how much to zoom and shift such that the mesh fills the unit box (centered at the origin)
Eigen::Matrix4f norm
OpenGL norm transformation matrix on last render pass.
Definition ViewerCore.h:228
bool is_set(unsigned int property_mask) const
Check whether a ViewerData visualization option is set for this viewport.
bool is_shadow_mapping
Whether shadow mapping is on.
Definition ViewerCore.h:167
bool orthographic
Whether camera is orthographic (or perspective)
Definition ViewerCore.h:191
Eigen::Matrix4f proj
OpenGL proj transformation matrix on last render pass.
Definition ViewerCore.h:226
float camera_base_zoom
Base zoom of camera.
Definition ViewerCore.h:187
void deinitialize_shadow_pass()
deinitialize shadow pass
void init()
Initialization.
void toggle(unsigned int &property_mask) const
Toggle a ViewerData visualization option for this viewport.
void set_rotation_type(const RotationType &value)
Set the current rotation type.
void draw_buffer(ViewerData &data, bool update_matrices, Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > &R, Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > &G, Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > &B, Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > &A)
Render given ViewerData to a buffer.
bool is_directional_light
Whether to treat light_position as a point or direction.
Definition ViewerCore.h:165
void InitSerialization()
Serialization code.
Eigen::Quaternionf trackball_angle
View rotation as quaternion.
Definition ViewerCore.h:184
void generate_shadow_buffers()
generate the shadow buffers
Eigen::Vector3f camera_eye
Current "eye" / origin position of camera.
Definition ViewerCore.h:197
void delete_shadow_buffers()
delete the shadow buffers
Eigen::Matrix4f view
OpenGL view transformation matrix on last render pass.
Definition ViewerCore.h:224
RotationType
Type of user interface for changing the view rotation based on the mouse draggin.
Definition ViewerCore.h:117
@ ROTATION_TYPE_TRACKBALL
Typical trackball rotation (like Meshlab)
Definition ViewerCore.h:119
@ NUM_ROTATION_TYPES
Total number of rotation types.
Definition ViewerCore.h:125
@ ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP
Fixed up rotation (like Blender, Maya, etc.)
Definition ViewerCore.h:121
@ ROTATION_TYPE_NO_ROTATION
No rotation suitable for 2D.
Definition ViewerCore.h:123
void shut()
Shutdown.
void draw_shadow_pass(ViewerData &data, bool update_matrices=true)
Draw everything to shadow map.
Eigen::Vector3f camera_center
Current "look at" position of camera.
Definition ViewerCore.h:201
float camera_view_angle
Current view angle of camera.
Definition ViewerCore.h:203
void set(unsigned int &property_mask, bool value=true) const
Set a ViewerData visualization option for this viewport.
void get_scale_and_shift_to_fit_mesh(const Eigen::MatrixXd &V, float &zoom, Eigen::Vector3f &shift)
This is an overloaded member function, provided for convenience. It differs from the above function o...
MeshGL::GLuint GLuint
Definition ViewerCore.h:29
Eigen::Vector4f viewport
Viewport size.
Definition ViewerCore.h:221
float lighting_factor
Factor of lighting (0: no lighting, 1: full lighting)
Definition ViewerCore.h:179
Eigen::Vector3f camera_base_translation
Base translation of camera.
Definition ViewerCore.h:193
void initialize_shadow_pass()
initialize shadow pass
Eigen::Vector4f background_color
Background color as RGBA.
Definition ViewerCore.h:160
void draw(ViewerData &data, bool update_matrices=true)
Draw everything.
Eigen::Vector3f camera_up
Current "up" vector of camera.
Definition ViewerCore.h:199
Eigen::Matrix4f shadow_view
OpenGL shadow_view transformation matrix on last render pass.
Definition ViewerCore.h:230
float camera_dfar
Far plane of camera.
Definition ViewerCore.h:207
RotationType rotation_type
Type of rotation interaction.
Definition ViewerCore.h:182
void unset(unsigned int &property_mask) const
Unset a ViewerData visualization option for this viewport.
float camera_zoom
Current zoom of camera.
Definition ViewerCore.h:189
Eigen::Vector3f camera_translation
Current translation of camera.
Definition ViewerCore.h:195
void align_camera_center(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
Adjust the view to see the entire model.
double animation_max_fps
Max fps of animation loop (e.g. 30fps or 60fps)
Definition ViewerCore.h:215
GLuint shadow_depth_fbo
Shadow map depth framebuffer object.
Definition ViewerCore.h:175
void clear_framebuffers()
Clear the frame buffers.
Object being drawn (i.e., mesh and its accessories) by the ViewerCore.
Definition ViewerData.h:39
#define IGL_INLINE
Definition igl_inline.h:15
void serialization(bool s, igl::opengl::ViewerCore &obj, std::vector< char > &buffer)
Definition ViewerCore.h:244
void deserialize(igl::opengl::ViewerCore &obj, const std::vector< char > &buffer)
Definition ViewerCore.h:286
void serialize(const igl::opengl::ViewerCore &obj, std::vector< char > &buffer)
Definition ViewerCore.h:280
Definition AABB.h:17
#define SERIALIZE_MEMBER(Object)
Definition serialize.h:68
Definition MeshGL.h:106