ViewerCore.h 3.1 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_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. #ifdef ENABLE_XML_SERIALIZATION
  15. #include <igl/xml/serialize_xml.h>
  16. #else
  17. #include <igl/serialize.h>
  18. #endif
  19. namespace igl
  20. {
  21. // Basic class of the 3D mesh viewer
  22. // TODO: write documentation
  23. class ViewerCore
  24. #ifdef ENABLE_XML_SERIALIZATION
  25. : public igl::XMLSerializable
  26. #else
  27. : public igl::Serializable
  28. #endif
  29. {
  30. public:
  31. IGL_INLINE ViewerCore();
  32. // Initialization
  33. IGL_INLINE void init();
  34. // Shutdown
  35. IGL_INLINE void shut();
  36. // Serialization code
  37. IGL_INLINE void InitSerialization();
  38. // ------------------- Camera control functions
  39. // Adjust the view to see the entire model
  40. IGL_INLINE void align_camera_center(
  41. const Eigen::MatrixXd& V,
  42. const Eigen::MatrixXi& F);
  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. const Eigen::MatrixXi& F,
  48. float & zoom,
  49. Eigen::Vector3f& shift);
  50. // ------------------- Drawing functions
  51. // Clear the frame buffers
  52. IGL_INLINE void clear_framebuffers();
  53. // Draw everything
  54. IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl);
  55. // ------------------- Properties
  56. // Text rendering helper
  57. TextRenderer textrenderer;
  58. // Shape material
  59. float shininess;
  60. // Colors
  61. Eigen::Vector3f background_color;
  62. Eigen::Vector3f line_color;
  63. // Lighting
  64. Eigen::Vector3f light_position;
  65. float lighting_factor;
  66. // Trackball angle (quaternion)
  67. Eigen::Vector4f trackball_angle;
  68. // Model viewing parameters
  69. float model_zoom;
  70. Eigen::Vector3f model_translation;
  71. // Model viewing paramters (uv coordinates)
  72. float model_zoom_uv;
  73. Eigen::Vector3f model_translation_uv;
  74. // Camera parameters
  75. float camera_zoom;
  76. bool orthographic;
  77. Eigen::Vector3f camera_eye;
  78. Eigen::Vector3f camera_up;
  79. Eigen::Vector3f camera_center;
  80. float camera_view_angle;
  81. float camera_dnear;
  82. float camera_dfar;
  83. // Visualization options
  84. bool show_overlay;
  85. bool show_overlay_depth;
  86. bool show_texture;
  87. bool show_faces;
  88. bool show_lines;
  89. bool show_vertid;
  90. bool show_faceid;
  91. bool invert_normals;
  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. #ifndef IGL_STATIC_LIBRARY
  109. # include "ViewerCore.cpp"
  110. #endif
  111. #endif