ViewerCore.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_VIEWER_VIEWER_CORE_H
  9. #define IGL_VIEWER_VIEWER_CORE_H
  10. #ifdef IGL_VIEWER_WITH_NANOGUI
  11. #include <igl/viewer/TextRenderer.h>
  12. #endif
  13. #include <igl/viewer/ViewerData.h>
  14. #include <igl/viewer/OpenGL_state.h>
  15. #include <igl/igl_inline.h>
  16. #include <Eigen/Geometry>
  17. #include <Eigen/Core>
  18. namespace igl
  19. {
  20. namespace viewer
  21. {
  22. // Basic class of the 3D mesh viewer
  23. // TODO: write documentation
  24. class ViewerCore
  25. {
  26. public:
  27. IGL_INLINE ViewerCore();
  28. // Initialization
  29. IGL_INLINE void init();
  30. // Shutdown
  31. IGL_INLINE void shut();
  32. // Serialization code
  33. IGL_INLINE void InitSerialization();
  34. // ------------------- Camera control functions
  35. // Adjust the view to see the entire model
  36. IGL_INLINE void align_camera_center(
  37. const Eigen::MatrixXd& V,
  38. const Eigen::MatrixXi& F);
  39. // Determines how much to zoom and shift such that the mesh fills the unit
  40. // box (centered at the origin)
  41. IGL_INLINE void get_scale_and_shift_to_fit_mesh(
  42. const Eigen::MatrixXd& V,
  43. const Eigen::MatrixXi& F,
  44. float & zoom,
  45. Eigen::Vector3f& shift);
  46. // Adjust the view to see the entire model
  47. IGL_INLINE void align_camera_center(
  48. const Eigen::MatrixXd& V);
  49. // Determines how much to zoom and shift such that the mesh fills the unit
  50. // box (centered at the origin)
  51. IGL_INLINE void get_scale_and_shift_to_fit_mesh(
  52. const Eigen::MatrixXd& V,
  53. float & zoom,
  54. Eigen::Vector3f& shift);
  55. // ------------------- Drawing functions
  56. // Clear the frame buffers
  57. IGL_INLINE void clear_framebuffers();
  58. // Draw everything
  59. IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl, bool update_matrices = true);
  60. IGL_INLINE void draw_buffer(
  61. ViewerData& data,
  62. OpenGL_state& opengl,
  63. bool update_matrices,
  64. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
  65. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
  66. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
  67. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
  68. // Trackball angle (quaternion)
  69. enum RotationType
  70. {
  71. ROTATION_TYPE_TRACKBALL = 0,
  72. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  73. NUM_ROTATION_TYPES = 2
  74. };
  75. IGL_INLINE void set_rotation_type(const RotationType & value);
  76. // ------------------- Properties
  77. #ifdef IGL_VIEWER_WITH_NANOGUI
  78. // Text rendering helper
  79. TextRenderer textrenderer;
  80. #endif
  81. // Shape material
  82. float shininess;
  83. // Colors
  84. Eigen::Vector4f background_color;
  85. Eigen::Vector4f line_color;
  86. // Lighting
  87. Eigen::Vector3f light_position;
  88. float lighting_factor;
  89. RotationType rotation_type;
  90. Eigen::Quaternionf trackball_angle;
  91. // Model viewing parameters
  92. float model_zoom;
  93. Eigen::Vector3f model_translation;
  94. // Model viewing paramters (uv coordinates)
  95. float model_zoom_uv;
  96. Eigen::Vector3f model_translation_uv;
  97. // Camera parameters
  98. float camera_zoom;
  99. bool orthographic;
  100. Eigen::Vector3f camera_eye;
  101. Eigen::Vector3f camera_up;
  102. Eigen::Vector3f camera_center;
  103. float camera_view_angle;
  104. float camera_dnear;
  105. float camera_dfar;
  106. // Visualization options
  107. bool show_overlay;
  108. bool show_overlay_depth;
  109. bool show_texture;
  110. bool show_faces;
  111. bool show_lines;
  112. bool show_vertid;
  113. bool show_faceid;
  114. bool invert_normals;
  115. bool depth_test;
  116. // Point size / line width
  117. float point_size;
  118. float line_width;
  119. // Animation
  120. bool is_animating;
  121. double animation_max_fps;
  122. // Caches the two-norm between the min/max point of the bounding box
  123. float object_scale;
  124. // Viewport size
  125. Eigen::Vector4f viewport;
  126. // Save the OpenGL transformation matrices used for the previous rendering pass
  127. Eigen::Matrix4f view;
  128. Eigen::Matrix4f model;
  129. Eigen::Matrix4f proj;
  130. public:
  131. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  132. };
  133. }
  134. }
  135. #ifndef IGL_STATIC_LIBRARY
  136. # include "ViewerCore.cpp"
  137. #endif
  138. #endif