ViewerCore.h 3.8 KB

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