Эх сурвалжийг харах

- extracted ViewerData from the viewer

Former-commit-id: 30374f1192b02f79c07c85b4a1bf10fdccdb2e37
Daniele Panozzo 11 жил өмнө
parent
commit
ca5b68b26b

+ 1 - 62
include/igl/viewer/Viewer.cpp

@@ -988,38 +988,6 @@ namespace igl
     return true;
   }
 
-  static GLuint create_shader_helper(GLint type, const std::string &shader_string)
-  {
-    using namespace std;
-    if (shader_string.empty())
-      return (GLuint) 0;
-
-    GLuint id = glCreateShader(type);
-    const char *shader_string_const = shader_string.c_str();
-    glShaderSource(id, 1, &shader_string_const, NULL);
-    glCompileShader(id);
-
-    GLint status;
-    glGetShaderiv(id, GL_COMPILE_STATUS, &status);
-
-    if (status != GL_TRUE)
-    {
-      char buffer[512];
-      if (type == GL_VERTEX_SHADER)
-        cerr << "Vertex shader:" << endl;
-      else if (type == GL_FRAGMENT_SHADER)
-        cerr << "Fragment shader:" << endl;
-      else if (type == GL_GEOMETRY_SHADER)
-        cerr << "Geometry shader:" << endl;
-      cerr << shader_string << endl << endl;
-      glGetShaderInfoLog(id, 512, NULL, buffer);
-      cerr << "Error: " << endl << buffer << endl;
-      return (GLuint) 0;
-    }
-
-    return id;
-  }
-
   void Viewer::OpenGL_state::init()
   {
     // Mesh: Vertex Array Object & Buffer objects
@@ -1074,7 +1042,7 @@ namespace igl
     glDeleteTextures(1, &vbo_tex);
   }
 
-  void Viewer::OpenGL_state::set_data(const Data &data, bool face_based, bool invert_normals)
+  void Viewer::OpenGL_state::set_data(const igl::ViewerData &data, bool face_based, bool invert_normals)
   {
     bool per_corner_uv = (data.F_uv.rows() == data.F.rows());
     bool per_corner_normals = (data.F_normals.rows() == 3 * data.F.rows());
@@ -1860,35 +1828,6 @@ namespace igl
     #endif
   }
 
-  void Viewer::Data::InitSerialization()
-  {
-    #ifdef ENABLE_XML_SERIALIZATION
-    xmlSerializer->Add(V,"V");
-    xmlSerializer->Add(F,"F");
-    xmlSerializer->Add(F_normals,"F_normals");
-
-    xmlSerializer->Add(F_material_ambient,"F_material_ambient");
-    xmlSerializer->Add(F_material_diffuse,"F_material_diffuse");
-    xmlSerializer->Add(F_material_specular,"F_material_specular");
-
-    xmlSerializer->Add(V_normals,"V_normals");
-    xmlSerializer->Add(V_material_ambient,"V_material_ambient");
-    xmlSerializer->Add(V_material_diffuse,"V_material_diffuse");
-    xmlSerializer->Add(V_material_specular,"V_material_specular");
-
-    xmlSerializer->Add(V_uv,"V_uv");
-    xmlSerializer->Add(F_uv,"F_uv");
-    xmlSerializer->Add(texture_R,"texture_R");
-    xmlSerializer->Add(texture_G,"texture_G");
-    xmlSerializer->Add(texture_B,"texture_B");
-    xmlSerializer->Add(lines,"lines");
-    xmlSerializer->Add(points,"points");
-
-    xmlSerializer->Add(labels_positions,"labels_positions");
-    xmlSerializer->Add(labels_strings,"labels_strings");
-    #endif
-  }
-
   void Viewer::set_face_based(bool newvalue)
   {
     if (options.face_based != newvalue)

+ 4 - 69
include/igl/viewer/Viewer.h

@@ -21,6 +21,7 @@
 
 #include <Eigen/Core>
 #include <igl/viewer/OpenGL_shader.h>
+#include <igl/viewer/ViewerData.h>
 
 namespace igl
 {
@@ -118,72 +119,6 @@ namespace igl
       DIRTY_ALL            = 0x03FF
     };
 
-    class Data
-    #ifdef ENABLE_XML_SERIALIZATION
-    : public ::igl::XMLSerialization
-    #endif
-    {
-    public:
-      Data()
-      #ifdef ENABLE_XML_SERIALIZATION
-      : XMLSerialization("Data"), dirty(DIRTY_ALL)
-      #endif
-      {};
-
-      void InitSerialization();
-
-      Eigen::MatrixXd V; // Vertices of the current mesh (#V x 3)
-      Eigen::MatrixXi F; // Faces of the mesh (#F x 3)
-
-      // Per face attributes
-      Eigen::MatrixXd F_normals; // One normal per face
-
-      Eigen::MatrixXd F_material_ambient; // Per face ambient color
-      Eigen::MatrixXd F_material_diffuse; // Per face diffuse color
-      Eigen::MatrixXd F_material_specular; // Per face specular color
-
-      // Per vertex attributes
-      Eigen::MatrixXd V_normals; // One normal per vertex
-
-      Eigen::MatrixXd V_material_ambient; // Per vertex ambient color
-      Eigen::MatrixXd V_material_diffuse; // Per vertex diffuse color
-      Eigen::MatrixXd V_material_specular; // Per vertex specular color
-
-      // UV parametrization
-      Eigen::MatrixXd V_uv; // UV vertices
-      Eigen::MatrixXi F_uv; // optional faces for UVs
-
-      // Texture
-      Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_R;
-      Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_G;
-      Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_B;
-
-      // Overlays
-
-      // Lines plotted over the scene
-      // (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),
-      // 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
-      Eigen::MatrixXd lines;
-
-      // Points plotted over the scene
-      // (Every row contains 6 doubles in the following format P_x, P_y, P_z, C_r, C_g, C_b),
-      // with P the position in global coordinates of the center of the point, and C the color in floating point rgb format
-      Eigen::MatrixXd points;
-
-      // Text labels plotted over the scene
-      // Textp contains, in the i-th row, the position in global coordinates where the i-th label should be anchored
-      // Texts contains in the i-th position the text of the i-th label
-      Eigen::MatrixXd           labels_positions;
-      std::vector<std::string > labels_strings;
-
-      // Marks dirty buffers that need to be uploaded to OpenGL
-      uint32_t dirty;
-
-      // Caches the two-norm between the min/max point of the bounding box
-      float object_scale;
-      /*********************************/
-    };
-
     class OpenGL_state
     {
     public:
@@ -240,7 +175,7 @@ namespace igl
       void init();
 
       // Update contents from a 'Data' instance
-      void set_data(const Data &data, bool face_based, bool invert_normals);
+      void set_data(const igl::ViewerData &data, bool face_based, bool invert_normals);
 
       // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
       void bind_mesh();
@@ -268,12 +203,12 @@ namespace igl
     Options options;
 
     // Stores all the data that should be visualized
-    Data data;
+    igl::ViewerData data;
 
     // Stores the vbos indices and opengl related settings
     OpenGL_state opengl;
 
-    // Pointer to the plugin_manager (usually it will be a global variable)
+    // List of registered plugins
     std::vector<Viewer_plugin*> plugins;
     void init_plugins();
     void shutdown_plugins();

+ 30 - 0
include/igl/viewer/ViewerData.cpp

@@ -0,0 +1,30 @@
+#include "ViewerData.h"
+
+void igl::ViewerData::InitSerialization()
+{
+  #ifdef ENABLE_XML_SERIALIZATION
+  xmlSerializer->Add(V,"V");
+  xmlSerializer->Add(F,"F");
+  xmlSerializer->Add(F_normals,"F_normals");
+
+  xmlSerializer->Add(F_material_ambient,"F_material_ambient");
+  xmlSerializer->Add(F_material_diffuse,"F_material_diffuse");
+  xmlSerializer->Add(F_material_specular,"F_material_specular");
+
+  xmlSerializer->Add(V_normals,"V_normals");
+  xmlSerializer->Add(V_material_ambient,"V_material_ambient");
+  xmlSerializer->Add(V_material_diffuse,"V_material_diffuse");
+  xmlSerializer->Add(V_material_specular,"V_material_specular");
+
+  xmlSerializer->Add(V_uv,"V_uv");
+  xmlSerializer->Add(F_uv,"F_uv");
+  xmlSerializer->Add(texture_R,"texture_R");
+  xmlSerializer->Add(texture_G,"texture_G");
+  xmlSerializer->Add(texture_B,"texture_B");
+  xmlSerializer->Add(lines,"lines");
+  xmlSerializer->Add(points,"points");
+
+  xmlSerializer->Add(labels_positions,"labels_positions");
+  xmlSerializer->Add(labels_strings,"labels_strings");
+  #endif
+}

+ 82 - 0
include/igl/viewer/ViewerData.h

@@ -0,0 +1,82 @@
+#ifndef IGL_VIEWER_DATA_H
+#define IGL_VIEWER_DATA_H
+
+#include <igl/igl_inline.h>
+
+namespace igl
+{
+
+class ViewerData
+#ifdef ENABLE_XML_SERIALIZATION
+: public ::igl::XMLSerialization
+#endif
+{
+public:
+  ViewerData()
+  #ifdef ENABLE_XML_SERIALIZATION
+  : XMLSerialization("Data"), dirty(DIRTY_ALL)
+  #endif
+  {};
+
+  void InitSerialization();
+
+  Eigen::MatrixXd V; // Vertices of the current mesh (#V x 3)
+  Eigen::MatrixXi F; // Faces of the mesh (#F x 3)
+
+  // Per face attributes
+  Eigen::MatrixXd F_normals; // One normal per face
+
+  Eigen::MatrixXd F_material_ambient; // Per face ambient color
+  Eigen::MatrixXd F_material_diffuse; // Per face diffuse color
+  Eigen::MatrixXd F_material_specular; // Per face specular color
+
+  // Per vertex attributes
+  Eigen::MatrixXd V_normals; // One normal per vertex
+
+  Eigen::MatrixXd V_material_ambient; // Per vertex ambient color
+  Eigen::MatrixXd V_material_diffuse; // Per vertex diffuse color
+  Eigen::MatrixXd V_material_specular; // Per vertex specular color
+
+  // UV parametrization
+  Eigen::MatrixXd V_uv; // UV vertices
+  Eigen::MatrixXi F_uv; // optional faces for UVs
+
+  // Texture
+  Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_R;
+  Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_G;
+  Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_B;
+
+  // Overlays
+
+  // Lines plotted over the scene
+  // (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),
+  // 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
+  Eigen::MatrixXd lines;
+
+  // Points plotted over the scene
+  // (Every row contains 6 doubles in the following format P_x, P_y, P_z, C_r, C_g, C_b),
+  // with P the position in global coordinates of the center of the point, and C the color in floating point rgb format
+  Eigen::MatrixXd points;
+
+  // Text labels plotted over the scene
+  // Textp contains, in the i-th row, the position in global coordinates where the i-th label should be anchored
+  // Texts contains in the i-th position the text of the i-th label
+  Eigen::MatrixXd           labels_positions;
+  std::vector<std::string > labels_strings;
+
+  // Marks dirty buffers that need to be uploaded to OpenGL
+  uint32_t dirty;
+
+  // Caches the two-norm between the min/max point of the bounding box
+  float object_scale;
+  /*********************************/
+};
+
+
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "ViewerData.cpp"
+#endif
+
+#endif