ViewerCore.h 3.0 KB

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