ViewerCore.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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(ViewerData& data,
  61. OpenGL_state& opengl,
  62. bool update_matrices,
  63. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
  64. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
  65. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
  66. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
  67. // ------------------- Properties
  68. #ifdef IGL_VIEWER_WITH_NANOGUI
  69. // Text rendering helper
  70. TextRenderer textrenderer;
  71. #endif
  72. // Shape material
  73. float shininess;
  74. // Colors
  75. Eigen::Vector4f background_color;
  76. Eigen::Vector4f line_color;
  77. // Lighting
  78. Eigen::Vector3f light_position;
  79. float lighting_factor;
  80. // Trackball angle (quaternion)
  81. enum RotationType
  82. {
  83. ROTATION_TYPE_TRACKBALL = 0,
  84. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  85. NUM_ROTATION_TYPES = 2
  86. } rotation_type;
  87. Eigen::Quaternionf trackball_angle;
  88. // Model viewing parameters
  89. float model_zoom;
  90. Eigen::Vector3f model_translation;
  91. // Model viewing paramters (uv coordinates)
  92. float model_zoom_uv;
  93. Eigen::Vector3f model_translation_uv;
  94. // Camera parameters
  95. float camera_zoom;
  96. bool orthographic;
  97. Eigen::Vector3f camera_eye;
  98. Eigen::Vector3f camera_up;
  99. Eigen::Vector3f camera_center;
  100. float camera_view_angle;
  101. float camera_dnear;
  102. float camera_dfar;
  103. // Visualization options
  104. bool show_overlay;
  105. bool show_overlay_depth;
  106. bool show_texture;
  107. bool show_faces;
  108. bool show_lines;
  109. bool show_vertid;
  110. bool show_faceid;
  111. bool invert_normals;
  112. bool depth_test;
  113. // Point size / line width
  114. float point_size;
  115. float line_width;
  116. // Animation
  117. bool is_animating;
  118. double animation_max_fps;
  119. // Caches the two-norm between the min/max point of the bounding box
  120. float object_scale;
  121. // Viewport size
  122. Eigen::Vector4f viewport;
  123. // Save the OpenGL transformation matrices used for the previous rendering pass
  124. Eigen::Matrix4f view;
  125. Eigen::Matrix4f model;
  126. Eigen::Matrix4f proj;
  127. public:
  128. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  129. };
  130. }
  131. }
  132. #ifndef IGL_STATIC_LIBRARY
  133. # include "ViewerCore.cpp"
  134. #endif
  135. #endif