Просмотр исходного кода

Merge branch 'master' of github.com:libigl/libigl

Former-commit-id: f587481763fa4a5bb526e4eef13742cf45ec34fe
Alec Jacobson 10 лет назад
Родитель
Сommit
eb1511831f

+ 59 - 51
include/igl/serialize.cpp

@@ -51,19 +51,12 @@ namespace igl
 
   template <typename T>
   IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer)
-  {
-    std::map<std::uintptr_t,IndexedPointerBase*> handler;
-    return serialize(obj,objectName,buffer,0,handler);
-  }
-
-  template <typename T>
-  IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer,size_t offset,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
   {
     // serialize object data
     size_t size = serialization::getByteSize(obj);
     std::vector<char> tmp(size);
     auto it = tmp.begin();
-    serialization::serialize(obj,tmp,it,memoryMap);
+    serialization::serialize(obj,tmp,it);
 
     std::string objectType(typeid(obj).name());
     size_t newObjectSize = tmp.size();
@@ -76,9 +69,9 @@ namespace igl
     std::vector<char>::iterator iter = buffer.begin()+curSize;
 
     // serialize object header (name/type/size)
-    serialization::serialize(objectName,buffer,iter,memoryMap);
-    serialization::serialize(objectType,buffer,iter,memoryMap);
-    serialization::serialize(newObjectSize,buffer,iter,memoryMap);
+    serialization::serialize(objectName,buffer,iter);
+    serialization::serialize(objectType,buffer,iter);
+    serialization::serialize(newObjectSize,buffer,iter);
 
     // copy serialized data to buffer
     iter = std::copy(tmp.begin(),tmp.end(),iter);
@@ -288,7 +281,7 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       // data
       std::vector<char> tmp;
@@ -296,7 +289,7 @@ namespace igl
 
       // size
       size_t size = buffer.size();
-      serialization::serialize(tmp.size(),buffer,iter,memoryMap);
+      serialization::serialize(tmp.size(),buffer,iter);
       size_t cur = iter - buffer.begin();
 
       buffer.resize(size+tmp.size());
@@ -327,9 +320,9 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      //serialization::updateMemoryMap(obj,sizeof(T),memoryMap);
+      //serialization::updateMemoryMap(obj,sizeof(T));
       const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&obj);
       iter = std::copy(ptr,ptr+sizeof(T),iter);
     }
@@ -349,12 +342,12 @@ namespace igl
       return getByteSize(obj.length())+obj.length()*sizeof(uint8_t);
     }
 
-    IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj.length(),buffer,iter,memoryMap);
+      serialization::serialize(obj.length(),buffer,iter);
       for(const auto& cur : obj)
       {
-        serialization::serialize(cur,buffer,iter,memoryMap);
+        serialization::serialize(cur,buffer,iter);
       }
     }
 
@@ -381,7 +374,7 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       // data
       std::vector<char> tmp;
@@ -389,7 +382,7 @@ namespace igl
 
       // size
       size_t size = buffer.size();
-      serialization::serialize(tmp.size(),buffer,iter,memoryMap);
+      serialization::serialize(tmp.size(),buffer,iter);
       size_t cur = iter - buffer.begin();
 
       buffer.resize(size+tmp.size());
@@ -422,10 +415,10 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj.first,buffer,iter,memoryMap);
-      serialization::serialize(obj.second,buffer,iter,memoryMap);
+      serialization::serialize(obj.first,buffer,iter);
+      serialization::serialize(obj.second,buffer,iter);
     }
 
     template <typename T1,typename T2>
@@ -444,13 +437,13 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
       size_t size = obj.size();
-      serialization::serialize(size,buffer,iter,memoryMap);
-      for(const auto& cur : obj)
+      serialization::serialize(size,buffer,iter);
+      for(const T1& cur : obj)
       {
-        serialization::serialize(cur,buffer,iter,memoryMap);
+        serialization::serialize(cur,buffer,iter);
       }
     }
 
@@ -461,12 +454,27 @@ namespace igl
       serialization::deserialize(size,iter);
 
       obj.resize(size);
-      for(auto& v : obj)
+      for(T1& v : obj)
       {
         serialization::deserialize(v,iter);
       }
     }
 
+    template <typename T2>
+    IGL_INLINE void deserialize(std::vector<bool,T2>& obj,std::vector<char>::const_iterator& iter)
+    {
+      size_t size;
+      serialization::deserialize(size,iter);
+
+      obj.resize(size);
+      for(int i=0;i<obj.size();i++)
+      {
+        bool val;
+        serialization::deserialize(val,iter);
+        obj[i] = val;
+      }
+    }
+
     //std::set
 
     template <typename T>
@@ -476,12 +484,12 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj.size(),buffer,iter,memoryMap);
-      for(const auto& cur : obj)
+      serialization::serialize(obj.size(),buffer,iter);
+      for(const T& cur : obj)
       {
-        serialization::serialize(cur,buffer,iter,memoryMap);
+        serialization::serialize(cur,buffer,iter);
       }
     }
 
@@ -509,12 +517,12 @@ namespace igl
     }
 
     template <typename T1,typename T2>
-    IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj.size(),buffer,iter,memoryMap);
+      serialization::serialize(obj.size(),buffer,iter);
       for(const auto& cur : obj)
       {
-        serialization::serialize(cur,buffer,iter,memoryMap);
+        serialization::serialize(cur,buffer,iter);
       }
     }
 
@@ -542,10 +550,10 @@ namespace igl
     }
 
     template<typename T,int R,int C,int P,int MR,int MC>
-    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj.rows(),buffer,iter,memoryMap);
-      serialization::serialize(obj.cols(),buffer,iter,memoryMap);
+      serialization::serialize(obj.rows(),buffer,iter);
+      serialization::serialize(obj.cols(),buffer,iter);
       size_t size = sizeof(T)*obj.rows()*obj.cols();
       auto ptr = reinterpret_cast<const uint8_t*>(obj.data());
       iter = std::copy(ptr,ptr+size,iter);
@@ -573,19 +581,19 @@ namespace igl
     }
 
     template<typename T,int P,typename I>
-    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj.rows(),buffer,iter,memoryMap);
-      serialization::serialize(obj.cols(),buffer,iter,memoryMap);
-      serialization::serialize(obj.nonZeros(),buffer,iter,memoryMap);
+      serialization::serialize(obj.rows(),buffer,iter);
+      serialization::serialize(obj.cols(),buffer,iter);
+      serialization::serialize(obj.nonZeros(),buffer,iter);
 
       for(int k=0;k<obj.outerSize();++k)
       {
         for(typename Eigen::SparseMatrix<T,P,I>::InnerIterator it(obj,k);it;++it)
         {
-          serialization::serialize(it.row(),buffer,iter,memoryMap);
-          serialization::serialize(it.col(),buffer,iter,memoryMap);
-          serialization::serialize(it.value(),buffer,iter,memoryMap);
+          serialization::serialize(it.row(),buffer,iter);
+          serialization::serialize(it.col(),buffer,iter);
+          serialization::serialize(it.value(),buffer,iter);
         }
       }
     }
@@ -628,12 +636,12 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialization::serialize(obj == nullptr,buffer,iter,memoryMap);
+      serialization::serialize(obj == nullptr,buffer,iter);
 
       if(obj)
-        serialization::serialize(*obj,buffer,iter,memoryMap);
+        serialization::serialize(*obj,buffer,iter);
     }
 
     template <typename T>
@@ -673,9 +681,9 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
-      serialize(obj.get(),buffer,iter,memoryMap);
+      serialize(obj.get(),buffer,iter);
     }
 
     template <template<typename> class T0,typename T1>
@@ -704,7 +712,7 @@ namespace igl
     }
 
     template <typename T>
-    IGL_INLINE void serialize(const std::weak_ptr<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
+    IGL_INLINE void serialize(const std::weak_ptr<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
     {
 
     }

+ 17 - 15
include/igl/serialize.h

@@ -75,7 +75,7 @@ namespace igl
   template <typename T>
   IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer);
   template <typename T>
-  IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer,size_t offset,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+  IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer);
 
   // Deserializes the given data from a file or buffer back to the provided object
   //
@@ -247,7 +247,7 @@ namespace igl
     template <typename T>
     IGL_INLINE typename std::enable_if<!is_serializable<T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
     IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
 
@@ -255,20 +255,20 @@ namespace igl
     template <typename T>
     IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
     IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
 
     // std::string
     IGL_INLINE size_t getByteSize(const std::string& obj);
-    IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     IGL_INLINE void deserialize(std::string& obj,std::vector<char>::const_iterator& iter);
 
     // SerializableBase
     template <typename T>
     IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
     IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);    
 
@@ -277,7 +277,7 @@ namespace igl
     template <typename T1,typename T2>
     IGL_INLINE size_t getByteSize(const std::pair<T1,T2>& obj);
     template <typename T1,typename T2>
-    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T1,typename T2>
     IGL_INLINE void deserialize(std::pair<T1,T2>& obj,std::vector<char>::const_iterator& iter);
 
@@ -285,15 +285,17 @@ namespace igl
     template <typename T1,typename T2>
     IGL_INLINE size_t getByteSize(const std::vector<T1,T2>& obj);
     template <typename T1,typename T2>
-    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T1,typename T2>
     IGL_INLINE void deserialize(std::vector<T1,T2>& obj,std::vector<char>::const_iterator& iter);
+    template <typename T2>
+    IGL_INLINE void deserialize(std::vector<bool,T2>& obj,std::vector<char>::const_iterator& iter);
 
     // std::set
     template <typename T>
     IGL_INLINE size_t getByteSize(const std::set<T>& obj);
     template <typename T>
-    IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
     IGL_INLINE void deserialize(std::set<T>& obj,std::vector<char>::const_iterator& iter);
 
@@ -301,7 +303,7 @@ namespace igl
     template <typename T1,typename T2>
     IGL_INLINE size_t getByteSize(const std::map<T1,T2>& obj);
     template <typename T1,typename T2>
-    IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T1,typename T2>
     IGL_INLINE void deserialize(std::map<T1,T2>& obj,std::vector<char>::const_iterator& iter);
 
@@ -309,14 +311,14 @@ namespace igl
     template<typename T,int R,int C,int P,int MR,int MC>
     IGL_INLINE size_t getByteSize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj);
     template<typename T,int R,int C,int P,int MR,int MC>
-    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template<typename T,int R,int C,int P,int MR,int MC>
     IGL_INLINE void deserialize(Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>::const_iterator& iter);
 
     template<typename T,int P,typename I>
     IGL_INLINE size_t getByteSize(const Eigen::SparseMatrix<T,P,I>& obj);
     template<typename T,int P,typename I>
-    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template<typename T,int P,typename I>
     IGL_INLINE void deserialize(Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>::const_iterator& iter);
 
@@ -324,7 +326,7 @@ namespace igl
     template <typename T>
     IGL_INLINE typename std::enable_if<std::is_pointer<T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
     IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type deserialize(T& obj,std::vector<char>::const_iterator& iter);
 
@@ -332,7 +334,7 @@ namespace igl
     template <typename T>
     IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value,size_t>::type getByteSize(const T& obj);
     template <typename T>
-    IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <template<typename> class T0, typename T1>
     IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T0<T1> >::value>::type deserialize(T0<T1>& obj,std::vector<char>::const_iterator& iter);
 
@@ -340,7 +342,7 @@ namespace igl
     template <typename T>
     IGL_INLINE size_t getByteSize(const std::weak_ptr<T>& obj);
     template <typename T>
-    IGL_INLINE void serialize(const std::weak_ptr<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void serialize(const std::weak_ptr<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter);
     template <typename T>
     IGL_INLINE void deserialize(std::weak_ptr<T>& obj,std::vector<char>::const_iterator& iter);
 
@@ -352,7 +354,7 @@ namespace igl
 
     // helper functions
     template <typename T>
-    IGL_INLINE void updateMemoryMap(T& obj,size_t size,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap);
+    IGL_INLINE void updateMemoryMap(T& obj,size_t size);
   }
 }
 

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

@@ -7,6 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 #include "OpenGL_state.h"
+#include "ViewerData.h"
 
 IGL_INLINE void igl::OpenGL_state::init_buffers()
 {

+ 3 - 5
include/igl/viewer/Viewer.cpp

@@ -9,7 +9,6 @@
 // TODO: save_scene()/load_scene()
 
 #include "Viewer.h"
-#include <igl/get_seconds.h>
 
 #ifdef _WIN32
 #  include <windows.h>
@@ -43,13 +42,12 @@
 #include <iomanip>
 #include <iostream>
 #include <fstream>
-
 #include <algorithm>
-#include <igl/project.h>
-
 #include <limits>
 #include <cassert>
 
+#include <igl/project.h>
+#include <igl/get_seconds.h>
 #include <igl/readOBJ.h>
 #include <igl/readOFF.h>
 #include <igl/adjacency_list.h>
@@ -63,6 +61,7 @@
 #include <igl/trackball.h>
 #include <igl/snap_to_canonical_view_quat.h>
 #include <igl/unproject.h>
+
 #include <igl/viewer/TextRenderer.h>
 
 #ifdef ENABLE_SERIALIZATION
@@ -418,7 +417,6 @@ namespace igl
 
   IGL_INLINE Viewer::Viewer()
   {
-
     // Temporary variables initialization
     down = false;
     hack_never_moved = true;

+ 13 - 10
include/igl/viewer/Viewer.h

@@ -12,25 +12,28 @@
 #define IGL_OPENGL_4
 #endif
 
-#include <AntTweakBar.h>
-
 #include <vector>
 #include <string>
 #include <cstdint>
 
+#include <Eigen/Core>
+#include <Eigen/Geometry>
+
+#include <AntTweakBar.h>
+
+#include <igl/igl_inline.h>
+
+#include "OpenGL_shader.h"
+#include "OpenGL_state.h"
+#include "ViewerCore.h"
+#include "ViewerData.h"
+#include "ViewerPlugin.h"
+
 #define IGL_MOD_SHIFT           0x0001
 #define IGL_MOD_CONTROL         0x0002
 #define IGL_MOD_ALT             0x0004
 #define IGL_MOD_SUPER           0x0008
 
-#include <Eigen/Core>
-#include <Eigen/Geometry>
-#include <igl/viewer/OpenGL_shader.h>
-#include <igl/viewer/OpenGL_state.h>
-#include <igl/viewer/ViewerCore.h>
-#include <igl/viewer/ViewerData.h>
-#include <igl/viewer/ViewerPlugin.h>
-
 namespace igl
 {
   // GLFW-based mesh viewer

+ 43 - 39
include/igl/viewer/ViewerCore.cpp

@@ -134,7 +134,7 @@ IGL_INLINE void igl::ViewerCore::clear_framebuffers()
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 }
 
-IGL_INLINE void igl::ViewerCore::draw(ViewerData& data, OpenGL_state& opengl)
+IGL_INLINE void igl::ViewerCore::draw(ViewerData& data, OpenGL_state& opengl, bool update_matrices)
 {
   using namespace std;
   using namespace Eigen;
@@ -155,44 +155,47 @@ IGL_INLINE void igl::ViewerCore::draw(ViewerData& data, OpenGL_state& opengl)
   // Initialize uniform
   glViewport(viewport(0), viewport(1), viewport(2), viewport(3));
 
-  model = Eigen::Matrix4f::Identity();
-  view  = Eigen::Matrix4f::Identity();
-  proj  = Eigen::Matrix4f::Identity();
-
-  // Set view
-  look_at( camera_eye, camera_center, camera_up, view);
-
-  float width  = viewport(2);
-  float height = viewport(3);
-
-  // Set projection
-  if (orthographic)
-  {
-    float length = (camera_eye - camera_center).norm();
-    float h = tan(camera_view_angle/360.0 * M_PI) * (length);
-    ortho(-h*width/height, h*width/height, -h, h, camera_dnear, camera_dfar,proj);
-  }
-  else
+  if(update_matrices)
   {
-    float fH = tan(camera_view_angle / 360.0 * M_PI) * camera_dnear;
-    float fW = fH * (double)width/(double)height;
-    frustum(-fW, fW, -fH, fH, camera_dnear, camera_dfar,proj);
+    model = Eigen::Matrix4f::Identity();
+    view  = Eigen::Matrix4f::Identity();
+    proj  = Eigen::Matrix4f::Identity();
+    
+    // Set view
+    look_at( camera_eye, camera_center, camera_up, view);
+    
+    float width  = viewport(2);
+    float height = viewport(3);
+    
+    // Set projection
+    if (orthographic)
+    {
+      float length = (camera_eye - camera_center).norm();
+      float h = tan(camera_view_angle/360.0 * M_PI) * (length);
+      ortho(-h*width/height, h*width/height, -h, h, camera_dnear, camera_dfar,proj);
+    }
+    else
+    {
+      float fH = tan(camera_view_angle / 360.0 * M_PI) * camera_dnear;
+      float fW = fH * (double)width/(double)height;
+      frustum(-fW, fW, -fH, fH, camera_dnear, camera_dfar,proj);
+    }
+    // end projection
+    
+    // Set model transformation
+    float mat[16];
+    igl::quat_to_mat(trackball_angle.data(), mat);
+    
+    for (unsigned i=0;i<4;++i)
+      for (unsigned j=0;j<4;++j)
+        model(i,j) = mat[i+4*j];
+    
+    // Why not just use Eigen::Transform<double,3,Projective> for model...?
+    model.topLeftCorner(3,3)*=camera_zoom;
+    model.topLeftCorner(3,3)*=model_zoom;
+    model.col(3).head(3) += model.topLeftCorner(3,3)*model_translation;
   }
-  // end projection
-
-  // Set model transformation
-  float mat[16];
-  igl::quat_to_mat(trackball_angle.data(), mat);
-
-  for (unsigned i=0;i<4;++i)
-    for (unsigned j=0;j<4;++j)
-      model(i,j) = mat[i+4*j];
-
-  // Why not just use Eigen::Transform<double,3,Projective> for model...?
-  model.topLeftCorner(3,3)*=camera_zoom;
-  model.topLeftCorner(3,3)*=model_zoom;
-  model.col(3).head(3) += model.topLeftCorner(3,3)*model_translation;
-
+  
   // Send transformations to the GPU
   GLint modeli = opengl.shader_mesh.uniform("model");
   GLint viewi  = opengl.shader_mesh.uniform("view");
@@ -200,7 +203,7 @@ IGL_INLINE void igl::ViewerCore::draw(ViewerData& data, OpenGL_state& opengl)
   glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
   glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
   glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
-
+  
   // Light parameters
   GLint specular_exponenti    = opengl.shader_mesh.uniform("specular_exponent");
   GLint light_position_worldi = opengl.shader_mesh.uniform("light_position_world");
@@ -315,6 +318,7 @@ IGL_INLINE void igl::ViewerCore::draw(ViewerData& data, OpenGL_state& opengl)
 
 IGL_INLINE void igl::ViewerCore::draw_buffer(ViewerData& data,
                             OpenGL_state& opengl,
+                            bool update_matrices,
                             Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic>& R,
                             Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic>& G,
                             Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic>& B,
@@ -363,7 +367,7 @@ IGL_INLINE void igl::ViewerCore::draw_buffer(ViewerData& data,
   viewport << 0,0,x,y;
   
   // Draw
-  draw(data,opengl);
+  draw(data,opengl,update_matrices);
   
   // Restore viewport
   viewport = viewport_ori;

+ 4 - 2
include/igl/viewer/ViewerCore.h

@@ -9,11 +9,12 @@
 #ifndef IGL_VIEWER_CORE_H
 #define IGL_VIEWER_CORE_H
 
-#include <igl/igl_inline.h>
 #include <igl/viewer/TextRenderer.h>
 #include <igl/viewer/ViewerData.h>
 #include <igl/viewer/OpenGL_state.h>
 
+#include <igl/igl_inline.h>
+
 namespace igl
 {
 
@@ -56,9 +57,10 @@ public:
   IGL_INLINE void clear_framebuffers();
 
   // Draw everything
-  IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl);
+  IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl, bool update_matrices = true);
   IGL_INLINE void draw_buffer(ViewerData& data,
                               OpenGL_state& opengl,
+                              bool update_matrices,
                               Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic>& R,
                               Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic>& G,
                               Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic>& B,

+ 2 - 1
include/igl/viewer/ViewerData.cpp

@@ -8,9 +8,10 @@
 
 #include "ViewerData.h"
 
+#include <iostream>
+
 #include <igl/per_face_normals.h>
 #include <igl/per_vertex_normals.h>
-#include <iostream>
 
 #ifdef ENABLE_SERIALIZATION
 #include <igl/serialize.h>

+ 6 - 2
include/igl/viewer/ViewerData.h

@@ -9,9 +9,13 @@
 #ifndef IGL_VIEWER_DATA_H
 #define IGL_VIEWER_DATA_H
 
-#include <igl/igl_inline.h>
+#include <cstdint>
+#include <vector>
+
 #include <Eigen/Core>
 
+#include <igl/igl_inline.h>
+
 namespace igl
 {
 
@@ -134,7 +138,7 @@ public:
   // 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;
+  std::vector<std::string>  labels_strings;
 
   // Marks dirty buffers that need to be uploaded to OpenGL
   uint32_t dirty;