ViewerData.h 7.1 KB

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