ViewerCore.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // ------------------- Drawing functions
  43. // Clear the frame buffers
  44. IGL_INLINE void clear_framebuffers();
  45. // Draw everything
  46. IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl, bool update_matrices = true);
  47. IGL_INLINE void draw_buffer(ViewerData& data,
  48. OpenGL_state& opengl,
  49. bool update_matrices,
  50. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
  51. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
  52. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
  53. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
  54. // ------------------- Properties
  55. // Text rendering helper
  56. TextRenderer textrenderer;
  57. // Shape material
  58. float shininess;
  59. // Colors
  60. Eigen::Vector3f background_color;
  61. Eigen::Vector3f line_color;
  62. // Lighting
  63. Eigen::Vector3f light_position;
  64. float lighting_factor;
  65. // Trackball angle (quaternion)
  66. Eigen::Vector4f trackball_angle;
  67. // Model viewing parameters
  68. float model_zoom;
  69. Eigen::Vector3f model_translation;
  70. // Model viewing paramters (uv coordinates)
  71. float model_zoom_uv;
  72. Eigen::Vector3f model_translation_uv;
  73. // Camera parameters
  74. float camera_zoom;
  75. bool orthographic;
  76. Eigen::Vector3f camera_eye;
  77. Eigen::Vector3f camera_up;
  78. Eigen::Vector3f camera_center;
  79. float camera_view_angle;
  80. float camera_dnear;
  81. float camera_dfar;
  82. // Visualization options
  83. bool show_overlay;
  84. bool show_overlay_depth;
  85. bool show_texture;
  86. bool show_faces;
  87. bool show_lines;
  88. bool show_vertid;
  89. bool show_faceid;
  90. bool invert_normals;
  91. bool depth_test;
  92. // Point size / line width
  93. float point_size;
  94. float line_width;
  95. // Animation
  96. bool is_animating;
  97. double animation_max_fps;
  98. // Caches the two-norm between the min/max point of the bounding box
  99. float object_scale;
  100. // Viewport size
  101. Eigen::Vector4f viewport;
  102. // Save the OpenGL transformation matrices used for the previous rendering pass
  103. Eigen::Matrix4f view;
  104. Eigen::Matrix4f model;
  105. Eigen::Matrix4f proj;
  106. };
  107. }
  108. }
  109. #ifndef IGL_STATIC_LIBRARY
  110. # include "ViewerCore.cpp"
  111. #endif
  112. #endif