ViewerCore.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. Eigen::Vector4f trackball_angle;
  76. // Model viewing parameters
  77. float model_zoom;
  78. Eigen::Vector3f model_translation;
  79. // Model viewing paramters (uv coordinates)
  80. float model_zoom_uv;
  81. Eigen::Vector3f model_translation_uv;
  82. // Camera parameters
  83. float camera_zoom;
  84. bool orthographic;
  85. Eigen::Vector3f camera_eye;
  86. Eigen::Vector3f camera_up;
  87. Eigen::Vector3f camera_center;
  88. float camera_view_angle;
  89. float camera_dnear;
  90. float camera_dfar;
  91. // Visualization options
  92. bool show_overlay;
  93. bool show_overlay_depth;
  94. bool show_texture;
  95. bool show_faces;
  96. bool show_lines;
  97. bool show_vertid;
  98. bool show_faceid;
  99. bool invert_normals;
  100. bool depth_test;
  101. // Point size / line width
  102. float point_size;
  103. float line_width;
  104. // Animation
  105. bool is_animating;
  106. double animation_max_fps;
  107. // Caches the two-norm between the min/max point of the bounding box
  108. float object_scale;
  109. // Viewport size
  110. Eigen::Vector4f viewport;
  111. // Save the OpenGL transformation matrices used for the previous rendering pass
  112. Eigen::Matrix4f view;
  113. Eigen::Matrix4f model;
  114. Eigen::Matrix4f proj;
  115. };
  116. }
  117. }
  118. #ifndef IGL_STATIC_LIBRARY
  119. # include "ViewerCore.cpp"
  120. #endif
  121. #endif