ViewerData.h 5.0 KB

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