ViewerData.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_DATA_H
  9. #define IGL_VIEWER_VIEWER_DATA_H
  10. #include <cstdint>
  11. #include <vector>
  12. #include <Eigen/Core>
  13. #include <igl/igl_inline.h>
  14. namespace igl
  15. {
  16. namespace viewer
  17. {
  18. // TODO: write documentation
  19. class ViewerData
  20. {
  21. public:
  22. ViewerData();
  23. enum DirtyFlags
  24. {
  25. DIRTY_NONE = 0x0000,
  26. DIRTY_POSITION = 0x0001,
  27. DIRTY_UV = 0x0002,
  28. DIRTY_NORMAL = 0x0004,
  29. DIRTY_AMBIENT = 0x0008,
  30. DIRTY_DIFFUSE = 0x0010,
  31. DIRTY_SPECULAR = 0x0020,
  32. DIRTY_TEXTURE = 0x0040,
  33. DIRTY_FACE = 0x0080,
  34. DIRTY_MESH = 0x00FF,
  35. DIRTY_OVERLAY_LINES = 0x0100,
  36. DIRTY_OVERLAY_POINTS = 0x0200,
  37. DIRTY_ALL = 0x03FF
  38. };
  39. // Empy all fields
  40. IGL_INLINE void clear();
  41. // Change the visualization mode, invalidating the cache if necessary
  42. IGL_INLINE void set_face_based(bool newvalue);
  43. // Helpers that can draw the most common meshes
  44. IGL_INLINE void set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
  45. IGL_INLINE void set_vertices(const Eigen::MatrixXd& V);
  46. IGL_INLINE void set_normals(const Eigen::MatrixXd& N);
  47. // Set the color of the mesh
  48. //
  49. // Inputs:
  50. // C #V|#F|1 by 3 list of colors
  51. IGL_INLINE void set_colors(const Eigen::MatrixXd &C);
  52. // Set per-vertex UV coordinates
  53. //
  54. // Inputs:
  55. // UV #V by 2 list of UV coordinates (indexed by F)
  56. IGL_INLINE void set_uv(const Eigen::MatrixXd& UV);
  57. // Set per-corner UV coordinates
  58. //
  59. // Inputs:
  60. // UV_V #UV by 2 list of UV coordinates
  61. // UV_F #F by 3 list of UV indices into UV_V
  62. IGL_INLINE void set_uv(const Eigen::MatrixXd& UV_V, const Eigen::MatrixXi& UV_F);
  63. // Set the texture associated with the mesh.
  64. //
  65. // Inputs:
  66. // R width by height image matrix of red channel
  67. // G width by height image matrix of green channel
  68. // B width by height image matrix of blue channel
  69. //
  70. IGL_INLINE void set_texture(
  71. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
  72. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
  73. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B);
  74. // Sets points given a list of point vertices. In constrast to `set_points`
  75. // this will (purposefully) clober existing points.
  76. //
  77. // Inputs:
  78. // P #P by 3 list of vertex positions
  79. // C #P|1 by 3 color(s)
  80. IGL_INLINE void set_points(
  81. const Eigen::MatrixXd& P,
  82. const Eigen::MatrixXd& C);
  83. IGL_INLINE void add_points(const Eigen::MatrixXd& P, const Eigen::MatrixXd& C);
  84. // Sets edges given a list of edge vertices and edge indices. In constrast
  85. // to `add_edges` this will (purposefully) clober existing edges.
  86. //
  87. // Inputs:
  88. // P #P by 3 list of vertex positions
  89. // E #E by 2 list of edge indices into P
  90. // C #E|1 by 3 color(s)
  91. IGL_INLINE void set_edges (const Eigen::MatrixXd& P, const Eigen::MatrixXi& E, const Eigen::MatrixXd& C);
  92. IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C);
  93. IGL_INLINE void add_label (const Eigen::VectorXd& P, const std::string& str);
  94. // Computes the normals of the mesh
  95. IGL_INLINE void compute_normals();
  96. // Assigns uniform colors to all faces/vertices
  97. IGL_INLINE void uniform_colors(Eigen::Vector3d ambient, Eigen::Vector3d diffuse, Eigen::Vector3d specular);
  98. // Generates a default grid texture
  99. IGL_INLINE void grid_texture();
  100. Eigen::MatrixXd V; // Vertices of the current mesh (#V x 3)
  101. Eigen::MatrixXi F; // Faces of the mesh (#F x 3)
  102. // Per face attributes
  103. Eigen::MatrixXd F_normals; // One normal per face
  104. Eigen::MatrixXd F_material_ambient; // Per face ambient color
  105. Eigen::MatrixXd F_material_diffuse; // Per face diffuse color
  106. Eigen::MatrixXd F_material_specular; // Per face specular color
  107. // Per vertex attributes
  108. Eigen::MatrixXd V_normals; // One normal per vertex
  109. Eigen::MatrixXd V_material_ambient; // Per vertex ambient color
  110. Eigen::MatrixXd V_material_diffuse; // Per vertex diffuse color
  111. Eigen::MatrixXd V_material_specular; // Per vertex specular color
  112. // UV parametrization
  113. Eigen::MatrixXd V_uv; // UV vertices
  114. Eigen::MatrixXi F_uv; // optional faces for UVs
  115. // Texture
  116. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_R;
  117. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_G;
  118. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_B;
  119. // Overlays
  120. // Lines plotted over the scene
  121. // (Every row contains 9 doubles in the following format S_x, S_y, S_z, T_x, T_y, T_z, C_r, C_g, C_b),
  122. // with S and T the coordinates of the two vertices of the line in global coordinates, and C the color in floating point rgb format
  123. Eigen::MatrixXd lines;
  124. // Points plotted over the scene
  125. // (Every row contains 6 doubles in the following format P_x, P_y, P_z, C_r, C_g, C_b),
  126. // with P the position in global coordinates of the center of the point, and C the color in floating point rgb format
  127. Eigen::MatrixXd points;
  128. // Text labels plotted over the scene
  129. // Textp contains, in the i-th row, the position in global coordinates where the i-th label should be anchored
  130. // Texts contains in the i-th position the text of the i-th label
  131. Eigen::MatrixXd labels_positions;
  132. std::vector<std::string> labels_strings;
  133. // Marks dirty buffers that need to be uploaded to OpenGL
  134. uint32_t dirty;
  135. // Enable per-face or per-vertex properties
  136. bool face_based;
  137. /*********************************/
  138. };
  139. }
  140. }
  141. #ifndef IGL_STATIC_LIBRARY
  142. # include "ViewerData.cpp"
  143. #endif
  144. #endif