Procházet zdrojové kódy

better templating

Former-commit-id: 258c8e193a6e9062e01336114f9cee49c603c3f3
Alec Jacobson před 8 roky
rodič
revize
680d9ff712
4 změnil soubory, kde provedl 49 přidání a 39 odebrání
  1. 13 11
      include/igl/readOBJ.cpp
  2. 11 7
      include/igl/readOBJ.h
  3. 11 16
      include/igl/writeOBJ.cpp
  4. 14 5
      include/igl/writeOBJ.h

+ 13 - 11
include/igl/readOBJ.cpp

@@ -242,15 +242,21 @@ IGL_INLINE bool igl::readOBJ(
   return readOBJ(obj_file_name,V,TC,N,F,FTC,FN);
 }
 
-template <typename DerivedV, typename DerivedF, typename DerivedT>
+template <
+  typename DerivedV, 
+  typename DerivedTC, 
+  typename DerivedCN, 
+  typename DerivedF,
+  typename DerivedFTC,
+  typename DerivedFN>
 IGL_INLINE bool igl::readOBJ(
   const std::string str,
-    Eigen::PlainObjectBase<DerivedV>& V,
-    Eigen::PlainObjectBase<DerivedT>& TC,
-    Eigen::PlainObjectBase<DerivedV>& CN,
-    Eigen::PlainObjectBase<DerivedF>& F,
-    Eigen::PlainObjectBase<DerivedF>& FTC,
-    Eigen::PlainObjectBase<DerivedF>& FN)
+  Eigen::PlainObjectBase<DerivedV>& V,
+  Eigen::PlainObjectBase<DerivedTC>& TC,
+  Eigen::PlainObjectBase<DerivedCN>& CN,
+  Eigen::PlainObjectBase<DerivedF>& F,
+  Eigen::PlainObjectBase<DerivedFTC>& FTC,
+  Eigen::PlainObjectBase<DerivedFN>& FN)
 {
   std::vector<std::vector<double> > vV,vTC,vN;
   std::vector<std::vector<int> > vF,vFTC,vFN;
@@ -351,8 +357,4 @@ IGL_INLINE bool igl::readOBJ(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template bool igl::readOBJ<double, int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, 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> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
-// 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, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::string, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
-template bool igl::readOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -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<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif

+ 11 - 7
include/igl/readOBJ.h

@@ -68,25 +68,29 @@ namespace igl
     const std::string obj_file_name, 
     std::vector<std::vector<Scalar > > & V,
     std::vector<std::vector<Index > > & F);
-#ifndef IGL_NO_EIGEN
   // Eigen Wrappers. These will return true only if the data is perfectly
   // "rectangular": All faces are the same degree, all have the same number of
   // textures/normals etc.
-  template <typename DerivedV, typename DerivedF, typename DerivedT>
+  template <
+    typename DerivedV, 
+    typename DerivedTC, 
+    typename DerivedCN, 
+    typename DerivedF,
+    typename DerivedFTC,
+    typename DerivedFN>
   IGL_INLINE bool readOBJ(
     const std::string str,
     Eigen::PlainObjectBase<DerivedV>& V,
-    Eigen::PlainObjectBase<DerivedT>& TC,
-    Eigen::PlainObjectBase<DerivedV>& CN,
+    Eigen::PlainObjectBase<DerivedTC>& TC,
+    Eigen::PlainObjectBase<DerivedCN>& CN,
     Eigen::PlainObjectBase<DerivedF>& F,
-    Eigen::PlainObjectBase<DerivedF>& FTC,
-    Eigen::PlainObjectBase<DerivedF>& FN);
+    Eigen::PlainObjectBase<DerivedFTC>& FTC,
+    Eigen::PlainObjectBase<DerivedFN>& FN);
   template <typename DerivedV, typename DerivedF>
   IGL_INLINE bool readOBJ(
     const std::string str,
     Eigen::PlainObjectBase<DerivedV>& V,
     Eigen::PlainObjectBase<DerivedF>& F);
-#endif
 
 }
 

+ 11 - 16
include/igl/writeOBJ.cpp

@@ -14,15 +14,21 @@
 #include <cstdio>
 #include <cassert>
 
-template <typename DerivedV, typename DerivedF, typename DerivedT>
+template <
+  typename DerivedV, 
+  typename DerivedF,
+  typename DerivedCN, 
+  typename DerivedFN,
+  typename DerivedTC, 
+  typename DerivedFTC>
 IGL_INLINE bool igl::writeOBJ(
   const std::string str,
   const Eigen::PlainObjectBase<DerivedV>& V,
   const Eigen::PlainObjectBase<DerivedF>& F,
-  const Eigen::PlainObjectBase<DerivedV>& CN,
-  const Eigen::PlainObjectBase<DerivedF>& FN,
-  const Eigen::PlainObjectBase<DerivedT>& TC,
-  const Eigen::PlainObjectBase<DerivedF>& FTC)
+  const Eigen::PlainObjectBase<DerivedCN>& CN,
+  const Eigen::PlainObjectBase<DerivedFN>& FN,
+  const Eigen::PlainObjectBase<DerivedTC>& TC,
+  const Eigen::PlainObjectBase<DerivedFTC>& FTC)
 {
   FILE * obj_file = fopen(str.c_str(),"w");
   if(NULL==obj_file)
@@ -113,15 +119,4 @@ IGL_INLINE bool igl::writeOBJ(
 
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
-// generated by autoexplicit.sh
-template bool igl::writeOBJ<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&);
-// 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&);
-template bool igl::writeOBJ<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<float, -1, 2, 1, -1, 2> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 2, 1, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
-template bool igl::writeOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -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&, 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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
-template bool igl::writeOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 2, 0, -1, 2> >(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&, 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, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
-template bool igl::writeOBJ<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
-template bool igl::writeOBJ<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
-template bool igl::writeOBJ<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(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<int, -1, 3, 1, -1, 3> > const&);
 #endif

+ 14 - 5
include/igl/writeOBJ.h

@@ -26,15 +26,24 @@ namespace igl
   //   TC  #TC by 2|3 texture coordinates
   //   FTC #F by 3|4 corner texture coord indices into TC
   // Returns true on success, false on error
-  template <typename DerivedV, typename DerivedF, typename DerivedT>
+  //
+  // Known issues: Horrifyingly, this does not have the same order of
+  // parameters as readOBJ.
+  template <
+    typename DerivedV, 
+    typename DerivedF,
+    typename DerivedCN, 
+    typename DerivedFN,
+    typename DerivedTC, 
+    typename DerivedFTC>
   IGL_INLINE bool writeOBJ(
     const std::string str,
     const Eigen::PlainObjectBase<DerivedV>& V,
     const Eigen::PlainObjectBase<DerivedF>& F,
-    const Eigen::PlainObjectBase<DerivedV>& CN,
-    const Eigen::PlainObjectBase<DerivedF>& FN,
-    const Eigen::PlainObjectBase<DerivedT>& TC,
-    const Eigen::PlainObjectBase<DerivedF>& FTC);
+    const Eigen::PlainObjectBase<DerivedCN>& CN,
+    const Eigen::PlainObjectBase<DerivedFN>& FN,
+    const Eigen::PlainObjectBase<DerivedTC>& TC,
+    const Eigen::PlainObjectBase<DerivedFTC>& FTC);
   template <typename DerivedV, typename DerivedF>
   IGL_INLINE bool writeOBJ(
     const std::string str,