ViewerCore.h 4.2 KB

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