瀏覽代碼

Viewer: finished a first cleaning pass on the viewer

Former-commit-id: a24fe2d0bba76d8ee8e88fbd6b187c1483028542
Daniele Panozzo 11 年之前
父節點
當前提交
dc36eb7ab2

+ 8 - 0
include/igl/viewer/OpenGL_shader.cpp

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #include "OpenGL_shader.h"
 
 #ifdef __APPLE__

+ 11 - 0
include/igl/viewer/OpenGL_shader.h

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #ifndef IGL_OPENGL_SHADER_H
 #define IGL_OPENGL_SHADER_H
 
@@ -18,6 +26,9 @@
 namespace igl
 {
 
+// This class wraps an OpenGL program composed of three shaders
+// TODO: write documentation
+
 class OpenGL_shader
 {
 public:

+ 8 - 0
include/igl/viewer/OpenGL_state.cpp

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #include "OpenGL_state.h"
 
 IGL_INLINE void igl::OpenGL_state::init_buffers()

+ 8 - 0
include/igl/viewer/OpenGL_state.h

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #ifndef IGL_OPENGL_STATE_H
 #define IGL_OPENGL_STATE_H
 

+ 7 - 0
include/igl/viewer/TextRenderer.cpp

@@ -1,3 +1,10 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
 #include "TextRenderer.h"
 #include <igl/project.h>
 

+ 8 - 0
include/igl/viewer/TextRenderer.h

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 /* This class extends the font rendering code in AntTweakBar
    so that it can be used to render text at arbitrary 3D positions */
 

+ 8 - 0
include/igl/viewer/Viewer.cpp

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #include "Viewer.h"
 #include <igl/get_seconds.h>
 

+ 12 - 11
include/igl/viewer/Viewer.h

@@ -1,4 +1,10 @@
-// Main class of the Viewer
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
 
 #ifndef IGL_VIEWER_H
 #define IGL_VIEWER_H
@@ -28,7 +34,7 @@
 
 namespace igl
 {
-
+  // GLFW-based mesh viewer
   class Viewer
   {
   public:
@@ -67,17 +73,14 @@ namespace igl
     // Keep track of the global position of the scrollwheel
     float scroll_position;
 
-    // Wrapper for ViewerData::compute_normals()
-    void compute_normals();
-
+    // Wrappers for ViewerCore functions
     void align_camera_center();
 
-    void clear();      // Clear the mesh data
+    // Wrappers for ViewerData functions
 
-    // Change the visualization mode, invalidating the cache if necessary
+    void clear();
+    void compute_normals();
     void set_face_based(bool newvalue);
-
-    // Helpers that can draw the most common meshes
     void set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
     void set_vertices(const Eigen::MatrixXd& V);
     void set_normals(const Eigen::MatrixXd& N);
@@ -95,8 +98,6 @@ namespace igl
     void add_label (const Eigen::VectorXd& P,  const std::string& str);
 
 
-//    Eigen::Vector4f viewport;
-
     // UI Enumerations
     enum MouseButton {IGL_LEFT, IGL_MIDDLE, IGL_RIGHT};
     enum MouseMode { NOTHING, ROTATION, ZOOM, PAN, TRANSLATE} mouse_mode;

+ 8 - 0
include/igl/viewer/ViewerCore.cpp

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #include "ViewerCore.h"
 #include <igl/quat_to_mat.h>
 

+ 27 - 3
include/igl/viewer/ViewerCore.h

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #ifndef IGL_VIEWER_CORE_H
 #define IGL_VIEWER_CORE_H
 
@@ -9,6 +17,9 @@
 namespace igl
 {
 
+// Basic class of the 3D mesh viewer
+// TODO: write documentation
+
 class ViewerCore
 #ifdef ENABLE_XML_SERIALIZATION
 : public ::igl::XMLSerialization
@@ -17,13 +28,20 @@ class ViewerCore
 public:
   IGL_INLINE ViewerCore();
 
+  // Initialization
   IGL_INLINE void init();
-  IGL_INLINE void shut();
 
+  // Shutdown
+  IGL_INLINE void shut();
 
+  // Serialization code
   IGL_INLINE void InitSerialization();
 
-  IGL_INLINE void align_camera_center(const Eigen::MatrixXd& V); // Adjust the view to see the entire model
+
+  // ------------------- Camera control functions
+
+  // Adjust the view to see the entire model
+  IGL_INLINE void align_camera_center(const Eigen::MatrixXd& V);
 
   // Determines how much to zoom and shift such that the mesh fills the unit
   // box (centered at the origin)
@@ -32,11 +50,17 @@ public:
     float & zoom,
     Eigen::Vector3f& shift);
 
+  // ------------------- Drawing functions
+
+  // Clear the frame buffers
   IGL_INLINE void clear_framebuffers();
 
   // Draw everything
   IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl);
 
+  // ------------------- Properties
+
+  // Text rendering helper
   TextRenderer textrenderer;
 
   // Shape material
@@ -92,7 +116,7 @@ public:
   // Caches the two-norm between the min/max point of the bounding box
   float object_scale;
 
-  // Window size
+  // Viewport size
   Eigen::Vector4f viewport;
 
   // Save the OpenGL transformation matrices used for the previous rendering pass

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

@@ -1,9 +1,25 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #include "ViewerData.h"
 
 #include <igl/per_face_normals.h>
 #include <igl/per_vertex_normals.h>
 #include <iostream>
 
+IGL_INLINE igl::ViewerData::ViewerData()
+#ifdef ENABLE_XML_SERIALIZATION
+: XMLSerialization("Data"), dirty(DIRTY_ALL)
+#endif
+{
+  clear();
+};
+
 IGL_INLINE void igl::ViewerData::InitSerialization()
 {
   #ifdef ENABLE_XML_SERIALIZATION

+ 20 - 12
include/igl/viewer/ViewerData.h

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #ifndef IGL_VIEWER_DATA_H
 #define IGL_VIEWER_DATA_H
 
@@ -7,17 +15,16 @@
 namespace igl
 {
 
+// Store the data visualized by ViewerCore
+// TODO: write documentation
+
 class ViewerData
 #ifdef ENABLE_XML_SERIALIZATION
 : public ::igl::XMLSerialization
 #endif
 {
 public:
-  ViewerData()
-  #ifdef ENABLE_XML_SERIALIZATION
-  : XMLSerialization("Data"), dirty(DIRTY_ALL)
-  #endif
-  {clear();};
+  ViewerData();
 
   enum DirtyFlags
   {
@@ -36,8 +43,6 @@ public:
     DIRTY_ALL            = 0x03FF
   };
 
-  // Helpers functions to fill the fields
-
   // Empy all fields
   IGL_INLINE void clear();
 
@@ -48,6 +53,7 @@ public:
   IGL_INLINE void set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
   IGL_INLINE void set_vertices(const Eigen::MatrixXd& V);
   IGL_INLINE void set_normals(const Eigen::MatrixXd& N);
+
   // Set the color of the mesh
   //
   // Inputs:
@@ -72,14 +78,16 @@ public:
   IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C);
   IGL_INLINE void add_label (const Eigen::VectorXd& P,  const std::string& str);
 
-  // More helpers
-
-  IGL_INLINE void compute_normals(); // Computes the normals of the mesh
-  IGL_INLINE void uniform_colors(Eigen::Vector3d ambient, Eigen::Vector3d diffuse, Eigen::Vector3d specular); // assign uniform colors to all faces/vertices
-  IGL_INLINE void grid_texture(); // Generate a default grid texture
+  // Computes the normals of the mesh
+  IGL_INLINE void compute_normals();
 
+  // Assigns uniform colors to all faces/vertices
+  IGL_INLINE void uniform_colors(Eigen::Vector3d ambient, Eigen::Vector3d diffuse, Eigen::Vector3d specular);
 
+  // Generates a default grid texture
+  IGL_INLINE void grid_texture();
 
+  // Serialization code
   IGL_INLINE void InitSerialization();
 
   Eigen::MatrixXd V; // Vertices of the current mesh (#V x 3)

+ 8 - 0
include/igl/viewer/ViewerPlugin.h

@@ -1,3 +1,11 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
 #ifndef IGL_VIEWER_PLUGIN_H
 #define IGL_VIEWER_PLUGIN_H