Răsfoiți Sursa

added a few specializations
readOFF supports vertex normals


Former-commit-id: 7847832f5d0ee31e6090f424fb070a916abe0e30

dolga 13 ani în urmă
părinte
comite
21f9758feb

+ 1 - 1
examples/MatlabWorkspace/Makefile

@@ -4,7 +4,7 @@ IGL=../../
 IGL_LIB=-L$(IGL)/lib -ligl
 IGL_INC=-I$(IGL)/include
 
-EIGEN3_INC=-I/usr/local/include/eigen3 -I/usr/local/include/eigen3/unsupported
+EIGEN3_INC=-I/usr/local/include/eigen3 -I/usr/local/include/eigen3/unsupported -I/opt/local/include/eigen3 -I/opt/local/include/eigen3/unsupported
 
 MATLAB_INC=-I$(MATLAB)/extern/include/
 MATLAB_LIB=-L$(MATLAB)/bin/maci64 -lmx -lmat

+ 1 - 0
include/igl/adjacency_list.cpp

@@ -122,4 +122,5 @@ IGL_INLINE void igl::adjacency_list(
 
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
+template void igl::adjacency_list<unsigned int, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> const&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >&, bool);
 #endif

+ 3 - 0
include/igl/list_to_matrix.cpp

@@ -86,4 +86,7 @@ template bool igl::list_to_matrix<bool, Eigen::PlainObjectBase<Eigen::Matrix<int
 template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(std::vector<int, std::allocator<int> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template bool igl::list_to_matrix<int, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
 template bool igl::list_to_matrix<int, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::vector<int, std::allocator<int> > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
+template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
+template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 1, -1, 2> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 1, -1, 2> >&);
+template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&);
 #endif

+ 1 - 0
include/igl/normalize_rows.cpp

@@ -18,4 +18,5 @@ IGL_INLINE void igl::normalize_rows(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::normalize_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::normalize_rows<Eigen::Matrix<double, -1, 3, 1, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
 #endif

+ 1 - 0
include/igl/per_corner_normals.cpp

@@ -76,4 +76,5 @@ IGL_INLINE void igl::per_corner_normals(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::per_corner_normals<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::per_corner_normals<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, unsigned int>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > > const&, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
 #endif

+ 1 - 0
include/igl/per_face_normals.cpp

@@ -20,4 +20,5 @@ IGL_INLINE void igl::per_face_normals(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::per_face_normals<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::per_face_normals<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
 #endif

+ 1 - 0
include/igl/per_vertex_normals.cpp

@@ -54,4 +54,5 @@ IGL_INLINE void igl::per_vertex_normals(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::per_vertex_normals<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::per_vertex_normals<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
 #endif

+ 1 - 0
include/igl/readOBJ.cpp

@@ -325,4 +325,5 @@ IGL_INLINE bool igl::readOBJ(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template bool igl::readOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+template bool igl::readOBJ<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<double, -1, 2, 1, -1, 2> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 1, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&);
 #endif

+ 66 - 5
include/igl/readOFF.cpp

@@ -4,7 +4,8 @@ template <typename Scalar, typename Index>
 IGL_INLINE bool igl::readOFF(
                              const std::string off_file_name, 
                              std::vector<std::vector<Scalar > > & V,
-                             std::vector<std::vector<Index > > & F)
+                             std::vector<std::vector<Index > > & F,
+                             std::vector<std::vector<Scalar > > & N)
 {
   FILE * off_file = fopen(off_file_name.c_str(),"r");                                       
   if(NULL==off_file)
@@ -14,6 +15,7 @@ IGL_INLINE bool igl::readOFF(
   }
   V.clear();
   F.clear();
+  N.clear();
   // First line is always OFF
   char header[1000];
   const std::string OFF("OFF");
@@ -40,6 +42,8 @@ IGL_INLINE bool igl::readOFF(
   }
   sscanf(line,"%d %d %d",&number_of_vertices,&number_of_faces,&number_of_edges);
   V.resize(number_of_vertices);
+  if (has_normals)
+    N.resize(number_of_vertices);
   F.resize(number_of_faces);
   //printf("%s %d %d %d\n",(has_normals ? "NOFF" : "OFF"),number_of_vertices,number_of_faces,number_of_edges);
   // Read vertices
@@ -55,6 +59,16 @@ IGL_INLINE bool igl::readOFF(
       vertex[1] = y;
       vertex[2] = z;
       V[i] = vertex;
+
+      if (has_normals)
+      {
+        std::vector<Scalar > normal;
+        normal.resize(3);
+        normal[0] = nx;
+        normal[1] = ny;
+        normal[2] = nz;
+        N[i] = normal;
+      }
       i++;
     }else if(
              fscanf(off_file,"%[#]",&tic_tac_toe)==1)
@@ -109,13 +123,14 @@ IGL_INLINE bool igl::readOFF(
 
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE bool igl::readOFF(
-                        const std::string str,
-                        Eigen::PlainObjectBase<DerivedV>& V,
-                        Eigen::PlainObjectBase<DerivedF>& F)
+                             const std::string str,
+                             Eigen::PlainObjectBase<DerivedV>& V,
+                             Eigen::PlainObjectBase<DerivedF>& F)
 {
   std::vector<std::vector<double> > vV;
+  std::vector<std::vector<double> > vN;  
   std::vector<std::vector<int> > vF;
-  bool success = igl::readOFF(str,vV,vF);
+  bool success = igl::readOFF(str,vV,vF,vN);
   if(!success)
   {
     // readOFF(str,vV,vF) should have already printed an error
@@ -136,8 +151,54 @@ IGL_INLINE bool igl::readOFF(
   }
   return true;
 }
+
+
+template <typename DerivedV, typename DerivedF>
+IGL_INLINE bool igl::readOFF(
+                             const std::string str,
+                             Eigen::PlainObjectBase<DerivedV>& V,
+                             Eigen::PlainObjectBase<DerivedF>& F,
+                             Eigen::PlainObjectBase<DerivedV>& N)
+{
+  std::vector<std::vector<double> > vV;
+  std::vector<std::vector<double> > vN;  
+  std::vector<std::vector<int> > vF;
+  bool success = igl::readOFF(str,vV,vF,vN);
+  if(!success)
+  {
+    // readOFF(str,vV,vF) should have already printed an error
+    // message to stderr
+    return false;
+  }
+  bool V_rect = igl::list_to_matrix(vV,V);
+  if(!V_rect)
+  {
+    // igl::list_to_matrix(vV,V) already printed error message to std err
+    return false;
+  }
+  bool F_rect = igl::list_to_matrix(vF,F);
+  if(!F_rect)
+  {
+    // igl::list_to_matrix(vF,F) already printed error message to std err
+    return false;
+  }
+  
+  if (vN.size())
+  {
+    bool N_rect = igl::list_to_matrix(vN,N);
+    if(!N_rect)
+    {
+      // igl::list_to_matrix(vN,N) already printed error message to std err
+      return false;
+    }
+  }
+  return true;
+}
+
+
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
 template bool igl::readOFF<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+template bool igl::readOFF<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&);
 #endif

+ 15 - 6
include/igl/readOFF.h

@@ -36,9 +36,10 @@ namespace igl
   // Returns true on success, false on errors
   template <typename Scalar, typename Index>
   IGL_INLINE bool readOFF(
-    const std::string off_file_name, 
-    std::vector<std::vector<Scalar > > & V,
-    std::vector<std::vector<Index > > & F);
+                          const std::string off_file_name, 
+                          std::vector<std::vector<Scalar > > & V,
+                          std::vector<std::vector<Index > > & F,
+                          std::vector<std::vector<Scalar > > & N);
   
   
   // read mesh from a ascii off file
@@ -49,9 +50,17 @@ namespace igl
   //   F  eigen int matrix #F by 3
   template <typename DerivedV, typename DerivedF>
   IGL_INLINE bool readOFF(
-    const std::string str,
-    Eigen::PlainObjectBase<DerivedV>& V,
-    Eigen::PlainObjectBase<DerivedF>& F);
+                          const std::string str,
+                          Eigen::PlainObjectBase<DerivedV>& V,
+                          Eigen::PlainObjectBase<DerivedF>& F);
+
+  template <typename DerivedV, typename DerivedF>
+  IGL_INLINE bool readOFF(
+                          const std::string str,
+                          Eigen::PlainObjectBase<DerivedV>& V,
+                          Eigen::PlainObjectBase<DerivedF>& F,
+                          Eigen::PlainObjectBase<DerivedV>& N);
+
 }
 
 #ifdef IGL_HEADER_ONLY

+ 1 - 0
include/igl/vf.cpp

@@ -29,4 +29,5 @@ IGL_INLINE void igl::vf(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::vf<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, int>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
+template void igl::vf<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, unsigned int>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >&);
 #endif

+ 1 - 0
include/igl/writeOBJ.cpp

@@ -106,4 +106,5 @@ IGL_INLINE bool igl::writeOBJ(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template bool igl::writeOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
+template bool igl::writeOBJ<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<double, -1, 2, 1, -1, 2> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 1, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
 #endif

+ 1 - 0
include/igl/writeOFF.cpp

@@ -31,4 +31,5 @@ IGL_INLINE bool igl::writeOFF(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template bool igl::writeOFF<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
+template bool igl::writeOFF<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
 #endif