فهرست منبع

moved model data from ViewerCore to ViewerData

Former-commit-id: a82cd5e2ea6b274e16bc07f86ece9c0eaf121371
Alec Jacobson 7 سال پیش
والد
کامیت
ee5613e4e3
6فایلهای تغییر یافته به همراه173 افزوده شده و 185 حذف شده
  1. 13 1
      include/igl/ViewerData.cpp
  2. 16 56
      include/igl/ViewerData.h
  3. 16 30
      include/igl/opengl/ViewerCore.cpp
  4. 53 81
      include/igl/opengl/ViewerCore.h
  5. 18 16
      include/igl/opengl/glfw/Viewer.cpp
  6. 57 1
      include/igl/serialize.h

+ 13 - 1
include/igl/ViewerData.cpp

@@ -17,7 +17,19 @@
 
 
 IGL_INLINE igl::ViewerData::ViewerData()
-: dirty(DIRTY_ALL)
+: dirty(DIRTY_ALL),
+  show_faces(true),
+  show_lines(true),
+  invert_normals(false),
+  show_overlay(true),
+  show_overlay_depth(true),
+  show_vertid(false),
+  show_faceid(false),
+  show_texture(false),
+  point_size(30),
+  line_width(0.5f),
+  line_color(0,0,0,1),
+  shininess(35.0f)
 {
   clear();
 };

+ 16 - 56
include/igl/ViewerData.h

@@ -185,64 +185,24 @@ public:
 
   // Enable per-face or per-vertex properties
   bool face_based;
-  /*********************************/
-};
 
-}
+  // Visualization options
+  bool show_overlay;
+  bool show_overlay_depth;
+  bool show_texture;
+  bool show_faces;
+  bool show_lines;
+  bool show_vertid;
+  bool show_faceid;
+  bool invert_normals;
+  // Point size / line width
+  float point_size;
+  float line_width;
+  Eigen::Vector4f line_color;
+  // Shape material
+  float shininess;
+};
 
-// Alec: This seems like the wrong place for this...  Should this just go in
-// serialize.h ?
-#include <igl/serialize.h>
-namespace igl {
-	namespace serialization {
-
-		inline void serialization(bool s, igl::ViewerData& obj, std::vector<char>& buffer)
-		{
-			SERIALIZE_MEMBER(V);
-			SERIALIZE_MEMBER(F);
-
-			SERIALIZE_MEMBER(F_normals);
-			SERIALIZE_MEMBER(F_material_ambient);
-			SERIALIZE_MEMBER(F_material_diffuse);
-			SERIALIZE_MEMBER(F_material_specular);
-
-			SERIALIZE_MEMBER(V_normals);
-			SERIALIZE_MEMBER(V_material_ambient);
-			SERIALIZE_MEMBER(V_material_diffuse);
-			SERIALIZE_MEMBER(V_material_specular);
-
-			SERIALIZE_MEMBER(V_uv);
-			SERIALIZE_MEMBER(F_uv);
-
-			SERIALIZE_MEMBER(texture_R);
-			SERIALIZE_MEMBER(texture_G);
-			SERIALIZE_MEMBER(texture_B);
-      SERIALIZE_MEMBER(texture_A);
-
-			SERIALIZE_MEMBER(lines);
-			SERIALIZE_MEMBER(points);
-
-			SERIALIZE_MEMBER(labels_positions);
-			SERIALIZE_MEMBER(labels_strings);
-
-			SERIALIZE_MEMBER(dirty);
-
-			SERIALIZE_MEMBER(face_based);
-		}
-
-		template<>
-		inline void serialize(const igl::ViewerData& obj, std::vector<char>& buffer)
-		{
-			serialization(true, const_cast<igl::ViewerData&>(obj), buffer);
-		}
-
-		template<>
-		inline void deserialize(igl::ViewerData& obj, const std::vector<char>& buffer)
-		{
-			serialization(false, obj, const_cast<std::vector<char>&>(buffer));
-			obj.dirty = igl::ViewerData::DIRTY_ALL;
-		}
-	}
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 16 - 30
include/igl/opengl/ViewerCore.cpp

@@ -113,7 +113,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
   /* Bind and potentially refresh mesh/line/point data */
   if (data.dirty)
   {
-    opengl.set_data(data, invert_normals);
+    opengl.set_data(data, data.invert_normals);
     data.dirty = ViewerData::DIRTY_NONE;
   }
   opengl.bind_mesh();
@@ -177,7 +177,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
   GLint fixed_colori          = glGetUniformLocation(opengl.shader_mesh,"fixed_color");
   GLint texture_factori       = glGetUniformLocation(opengl.shader_mesh,"texture_factor");
 
-  glUniform1f(specular_exponenti, shininess);
+  glUniform1f(specular_exponenti, data.shininess);
   Vector3f rev_light = -1.*light_position;
   glUniform3fv(light_position_worldi, 1, rev_light.data());
   glUniform1f(lighting_factori, lighting_factor); // enables lighting
@@ -186,26 +186,28 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
   if (data.V.rows()>0)
   {
     // Render fill
-    if (show_faces)
+    if (data.show_faces)
     {
       // Texture
-      glUniform1f(texture_factori, show_texture ? 1.0f : 0.0f);
+      glUniform1f(texture_factori, data.show_texture ? 1.0f : 0.0f);
       opengl.draw_mesh(true);
       glUniform1f(texture_factori, 0.0f);
     }
 
     // Render wireframe
-    if (show_lines)
+    if (data.show_lines)
     {
-      glLineWidth(line_width);
-      glUniform4f(fixed_colori, line_color[0], line_color[1],
-        line_color[2], 1.0f);
+      glLineWidth(data.line_width);
+      glUniform4f(fixed_colori, 
+        data.line_color[0], 
+        data.line_color[1],
+        data.line_color[2], 1.0f);
       opengl.draw_mesh(false);
       glUniform4f(fixed_colori, 0.0f, 0.0f, 0.0f, 0.0f);
     }
 
 #ifdef IGL_VIEWER_WITH_NANOGUI
-    if (show_vertid)
+    if (data.show_vertid)
     {
       textrenderer.BeginDraw(view*model, proj, viewport, object_scale);
       for (int i=0; i<data.V.rows(); ++i)
@@ -213,7 +215,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
       textrenderer.EndDraw();
     }
 
-    if (show_faceid)
+    if (data.show_faceid)
     {
       textrenderer.BeginDraw(view*model, proj, viewport, object_scale);
 
@@ -231,9 +233,9 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
 #endif
   }
 
-  if (show_overlay)
+  if (data.show_overlay)
   {
-    if (show_overlay_depth)
+    if (data.show_overlay_depth)
       glEnable(GL_DEPTH_TEST);
     else
       glDisable(GL_DEPTH_TEST);
@@ -250,7 +252,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
       glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
       // This must be enabled, otherwise glLineWidth has no effect
       glEnable(GL_LINE_SMOOTH);
-      glLineWidth(line_width);
+      glLineWidth(data.line_width);
 
       opengl.draw_overlay_lines();
     }
@@ -265,7 +267,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
       glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
       glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
       glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
-      glPointSize(point_size);
+      glPointSize(data.point_size);
 
       opengl.draw_overlay_points();
     }
@@ -389,12 +391,8 @@ IGL_INLINE void igl::opengl::ViewerCore::set_rotation_type(
 
 IGL_INLINE igl::opengl::ViewerCore::ViewerCore()
 {
-  // Default shininess
-  shininess = 35.0f;
-
   // Default colors
   background_color << 0.3f, 0.3f, 0.5f, 1.0f;
-  line_color << 0.0f, 0.0f, 0.0f, 1.0f;
 
   // Default lights settings
   light_position << 0.0f, -0.30f, -5.0f;
@@ -418,20 +416,8 @@ IGL_INLINE igl::opengl::ViewerCore::ViewerCore()
   camera_center << 0, 0, 0;
   camera_up << 0, 1, 0;
 
-  // Default visualization options
-  show_faces = true;
-  show_lines = true;
-  invert_normals = false;
-  show_overlay = true;
-  show_overlay_depth = true;
-  show_vertid = false;
-  show_faceid = false;
-  show_texture = false;
   depth_test = true;
 
-  // Default point size / line width
-  point_size = 30;
-  line_width = 0.5f;
   is_animating = false;
   animation_max_fps = 30.;
 

+ 53 - 81
include/igl/opengl/ViewerCore.h

@@ -103,12 +103,9 @@ public:
   TextRenderer textrenderer;
 #endif
 
-  // Shape material
-  float shininess;
 
   // Colors
   Eigen::Vector4f background_color;
-  Eigen::Vector4f line_color;
 
   // Lighting
   Eigen::Vector3f light_position;
@@ -136,21 +133,8 @@ public:
   float camera_dnear;
   float camera_dfar;
 
-  // Visualization options
-  bool show_overlay;
-  bool show_overlay_depth;
-  bool show_texture;
-  bool show_faces;
-  bool show_lines;
-  bool show_vertid;
-  bool show_faceid;
-  bool invert_normals;
   bool depth_test;
 
-  // Point size / line width
-  float point_size;
-  float line_width;
-
   // Animation
   bool is_animating;
   double animation_max_fps;
@@ -161,7 +145,8 @@ public:
   // Viewport size
   Eigen::Vector4f viewport;
 
-  // Save the OpenGL transformation matrices used for the previous rendering pass
+  // Save the OpenGL transformation matrices used for the previous rendering
+  // pass
   Eigen::Matrix4f view;
   Eigen::Matrix4f model;
   Eigen::Matrix4f proj;
@@ -176,70 +161,57 @@ public:
 #ifdef ENABLE_SERIALIZATION
 #include <igl/serialize.h>
 namespace igl {
-	namespace serialization {
-
-		inline void serialization(bool s, igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
-		{
-			SERIALIZE_MEMBER(shininess);
-
-			SERIALIZE_MEMBER(background_color);
-			SERIALIZE_MEMBER(line_color);
-
-			SERIALIZE_MEMBER(light_position);
-			SERIALIZE_MEMBER(lighting_factor);
-
-			SERIALIZE_MEMBER(trackball_angle);
-			SERIALIZE_MEMBER(rotation_type);
-
-			SERIALIZE_MEMBER(model_zoom);
-			SERIALIZE_MEMBER(model_translation);
-
-			SERIALIZE_MEMBER(model_zoom_uv);
-			SERIALIZE_MEMBER(model_translation_uv);
-
-			SERIALIZE_MEMBER(camera_zoom);
-			SERIALIZE_MEMBER(orthographic);
-			SERIALIZE_MEMBER(camera_view_angle);
-			SERIALIZE_MEMBER(camera_dnear);
-			SERIALIZE_MEMBER(camera_dfar);
-			SERIALIZE_MEMBER(camera_eye);
-			SERIALIZE_MEMBER(camera_center);
-			SERIALIZE_MEMBER(camera_up);
-
-			SERIALIZE_MEMBER(show_faces);
-			SERIALIZE_MEMBER(show_lines);
-			SERIALIZE_MEMBER(invert_normals);
-			SERIALIZE_MEMBER(show_overlay);
-			SERIALIZE_MEMBER(show_overlay_depth);
-			SERIALIZE_MEMBER(show_vertid);
-			SERIALIZE_MEMBER(show_faceid);
-			SERIALIZE_MEMBER(show_texture);
-			SERIALIZE_MEMBER(depth_test);
-
-			SERIALIZE_MEMBER(point_size);
-			SERIALIZE_MEMBER(line_width);
-			SERIALIZE_MEMBER(is_animating);
-			SERIALIZE_MEMBER(animation_max_fps);
-
-			SERIALIZE_MEMBER(object_scale);
-
-			SERIALIZE_MEMBER(viewport);
-			SERIALIZE_MEMBER(view);
-			SERIALIZE_MEMBER(model);
-			SERIALIZE_MEMBER(proj);
-		}
-
-		template<>
-		inline void serialize(const igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
-		{
-			serialization(true, const_cast<igl::opengl::ViewerCore&>(obj), buffer);
-		}
-
-		template<>
-		inline void deserialize(igl::opengl::ViewerCore& obj, const std::vector<char>& buffer)
-		{
-			serialization(false, obj, const_cast<std::vector<char>&>(buffer));
-		}
+  namespace serialization {
+
+    inline void serialization(bool s, igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
+    {
+
+      SERIALIZE_MEMBER(background_color);
+
+      SERIALIZE_MEMBER(light_position);
+      SERIALIZE_MEMBER(lighting_factor);
+
+      SERIALIZE_MEMBER(trackball_angle);
+      SERIALIZE_MEMBER(rotation_type);
+
+      SERIALIZE_MEMBER(model_zoom);
+      SERIALIZE_MEMBER(model_translation);
+
+      SERIALIZE_MEMBER(model_zoom_uv);
+      SERIALIZE_MEMBER(model_translation_uv);
+
+      SERIALIZE_MEMBER(camera_zoom);
+      SERIALIZE_MEMBER(orthographic);
+      SERIALIZE_MEMBER(camera_view_angle);
+      SERIALIZE_MEMBER(camera_dnear);
+      SERIALIZE_MEMBER(camera_dfar);
+      SERIALIZE_MEMBER(camera_eye);
+      SERIALIZE_MEMBER(camera_center);
+      SERIALIZE_MEMBER(camera_up);
+
+      SERIALIZE_MEMBER(depth_test);
+      SERIALIZE_MEMBER(is_animating);
+      SERIALIZE_MEMBER(animation_max_fps);
+
+      SERIALIZE_MEMBER(object_scale);
+
+      SERIALIZE_MEMBER(viewport);
+      SERIALIZE_MEMBER(view);
+      SERIALIZE_MEMBER(model);
+      SERIALIZE_MEMBER(proj);
+    }
+
+    template<>
+    inline void serialize(const igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
+    {
+      serialization(true, const_cast<igl::opengl::ViewerCore&>(obj), buffer);
+    }
+
+    template<>
+    inline void deserialize(igl::opengl::ViewerCore& obj, const std::vector<char>& buffer)
+    {
+      serialization(false, obj, const_cast<std::vector<char>&>(buffer));
+    }
   }
 }
 #endif

+ 18 - 16
include/igl/opengl/glfw/Viewer.cpp

@@ -387,28 +387,30 @@ namespace glfw
       return this->selected_data().face_based;
     });
 
-    ngui->addVariable("Show texture",core.show_texture);
+    ngui->addVariable("Show texture",this->selected_data().show_texture);
 
     ngui->addVariable<bool>("Invert normals",[&](bool checked)
     {
       this->selected_data().dirty |= ViewerData::DIRTY_NORMAL;
-      this->core.invert_normals = checked;
+      this->selected_data().invert_normals = checked;
     },[&]()
     {
-      return this->core.invert_normals;
+      return this->selected_data().invert_normals;
     });
 
-    ngui->addVariable("Show overlay", core.show_overlay);
-    ngui->addVariable("Show overlay depth", core.show_overlay_depth);
+    // Alec: This will probably just attach to the selected_data() at the time
+    // that addVariable is called. We probably need to use a callback here.
+    ngui->addVariable("Show overlay", selected_data().show_overlay);
+    ngui->addVariable("Show overlay depth", selected_data().show_overlay_depth);
+    ngui->addVariable("Line color", (nanogui::Color &) selected_data().line_color);
     ngui->addVariable("Background", (nanogui::Color &) core.background_color);
-    ngui->addVariable("Line color", (nanogui::Color &) core.line_color);
-    ngui->addVariable("Shininess", core.shininess);
+    ngui->addVariable("Shininess", selected_data().shininess);
 
     ngui->addGroup("Overlays");
-    ngui->addVariable("Wireframe", core.show_lines);
-    ngui->addVariable("Fill", core.show_faces);
-    ngui->addVariable("Show vertex labels", core.show_vertid);
-    ngui->addVariable("Show faces labels", core.show_faceid);
+    ngui->addVariable("Wireframe", selected_data().show_lines);
+    ngui->addVariable("Fill", selected_data().show_faces);
+    ngui->addVariable("Show vertex labels", selected_data().show_vertid);
+    ngui->addVariable("Show faces labels", selected_data().show_faceid);
 
     screen->setVisible(true);
     screen->performLayout();
@@ -671,13 +673,13 @@ namespace glfw
       case 'i':
       {
         selected_data().dirty |= ViewerData::DIRTY_NORMAL;
-        core.invert_normals = !core.invert_normals;
+        selected_data().invert_normals = !selected_data().invert_normals;
         return true;
       }
       case 'L':
       case 'l':
       {
-        core.show_lines = !core.show_lines;
+        selected_data().show_lines = !selected_data().show_lines;
         return true;
       }
       case 'O':
@@ -689,7 +691,7 @@ namespace glfw
       case 'T':
       case 't':
       {
-        core.show_faces = !core.show_faces;
+        selected_data().show_faces = !selected_data().show_faces;
         return true;
       }
       case 'Z':
@@ -716,10 +718,10 @@ namespace glfw
       }
 #ifdef IGL_VIEWER_WITH_NANOGUI
       case ';':
-        core.show_vertid = !core.show_vertid;
+        selected_data().show_vertid = !selected_data().show_vertid;
         return true;
       case ':':
-        core.show_faceid = !core.show_faceid;
+        selected_data().show_faceid = !selected_data().show_faceid;
         return true;
 #endif
       default: break;//do nothing

+ 57 - 1
include/igl/serialize.h

@@ -1254,5 +1254,61 @@ namespace igl
     }
   }
 }
- 
+
+#include "ViewerData.h"
+namespace igl 
+{
+  namespace serialization
+  {
+    inline void serialization(bool s, igl::ViewerData& obj, std::vector<char>& buffer)
+    {
+      SERIALIZE_MEMBER(V);
+      SERIALIZE_MEMBER(F);
+      SERIALIZE_MEMBER(F_normals);
+      SERIALIZE_MEMBER(F_material_ambient);
+      SERIALIZE_MEMBER(F_material_diffuse);
+      SERIALIZE_MEMBER(F_material_specular);
+      SERIALIZE_MEMBER(V_normals);
+      SERIALIZE_MEMBER(V_material_ambient);
+      SERIALIZE_MEMBER(V_material_diffuse);
+      SERIALIZE_MEMBER(V_material_specular);
+      SERIALIZE_MEMBER(V_uv);
+      SERIALIZE_MEMBER(F_uv);
+      SERIALIZE_MEMBER(texture_R);
+      SERIALIZE_MEMBER(texture_G);
+      SERIALIZE_MEMBER(texture_B);
+      SERIALIZE_MEMBER(texture_A);
+      SERIALIZE_MEMBER(lines);
+      SERIALIZE_MEMBER(points);
+      SERIALIZE_MEMBER(labels_positions);
+      SERIALIZE_MEMBER(labels_strings);
+      SERIALIZE_MEMBER(dirty);
+      SERIALIZE_MEMBER(face_based);
+      SERIALIZE_MEMBER(show_faces);
+      SERIALIZE_MEMBER(show_lines);
+      SERIALIZE_MEMBER(invert_normals);
+      SERIALIZE_MEMBER(show_overlay);
+      SERIALIZE_MEMBER(show_overlay_depth);
+      SERIALIZE_MEMBER(show_vertid);
+      SERIALIZE_MEMBER(show_faceid);
+      SERIALIZE_MEMBER(show_texture);
+      SERIALIZE_MEMBER(point_size);
+      SERIALIZE_MEMBER(line_width);
+      SERIALIZE_MEMBER(line_color);
+      SERIALIZE_MEMBER(shininess);
+    }
+    template<>
+    inline void serialize(const igl::ViewerData& obj, std::vector<char>& buffer)
+    {
+      serialization(true, const_cast<igl::ViewerData&>(obj), buffer);
+    }
+    template<>
+    inline void deserialize(igl::ViewerData& obj, const std::vector<char>& buffer)
+    {
+      serialization(false, obj, const_cast<std::vector<char>&>(buffer));
+      obj.dirty = igl::ViewerData::DIRTY_ALL;
+    }
+  }
+}
+
 #endif