ViewerCore.h 4.1 KB

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