Forráskód Böngészése

read works with vector of vector

Former-commit-id: aa56a2a8ae808659d7a00b0b86c2dbf4ee21a562
jalec 13 éve
szülő
commit
df3470adb9
4 módosított fájl, 71 hozzáadás és 17 törlés
  1. 36 3
      include/igl/read.cpp
  2. 17 2
      include/igl/read.h
  3. 2 0
      include/igl/readOFF.cpp
  4. 16 12
      include/igl/readOFF.h

+ 36 - 3
include/igl/read.cpp

@@ -2,15 +2,46 @@
 
 #include "readOBJ.h"
 #include "readOFF.h"
+#include "pathinfo.h"
 
 #include <cstdio>
+#include <iostream>
 
 
+template <typename Scalar, typename Index>
+IGL_INLINE bool igl::read(
+  const std::string str,
+  std::vector<std::vector<Scalar> > & V,
+  std::vector<std::vector<Index> > & F)
+{
+  using namespace std;
+  using namespace igl;
+  // dirname, basename, extension and filename
+  string d,b,e,f;
+  pathinfo(str,d,b,e,f);
+  // Convert extension to lower case
+  std::transform(e.begin(), e.end(), e.begin(), ::tolower);
+  vector<vector<Scalar> > TC, N;
+  vector<vector<Index> > FTC, FN;
+  if(e == "obj")
+  {
+    return readOBJ(str,V,TC,N,F,FTC,FN);
+  }else if(e == "off")
+  {
+    return readOFF(str,V,F,N);
+  }
+  cerr<<"Error: "<<__FUNCTION__<<": "<<
+    str<<" is not a recognized mesh file format."<<endl;
+  return false;
+}
+
+
+#ifndef IGL_NO_EIGN
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE bool igl::read(
-                     const std::string str,
-                     Eigen::PlainObjectBase<DerivedV>& V,
-                     Eigen::PlainObjectBase<DerivedF>& F)
+  const std::string str,
+  Eigen::PlainObjectBase<DerivedV>& V,
+  Eigen::PlainObjectBase<DerivedF>& F)
 {
     const char* p;
     for (p = str.c_str(); *p != '\0'; p++)
@@ -31,9 +62,11 @@ IGL_INLINE bool igl::read(
       return false;
     }
 }
+#endif
 
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
 template bool igl::read<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::read<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<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
 #endif

+ 17 - 2
include/igl/read.h

@@ -11,22 +11,37 @@
 #define IGL_READ_H
 #include "igl_inline.h"
 
-#include <Eigen/Core>
+#ifndef IGL_NO_EIGEN
+#  include <Eigen/Core>
+#endif
 #include <string>
+#include <vector>
 
 namespace igl 
 {
-    // read mesh from an ascii file with automatic detection of file format. supported: obj, off)
+  // read mesh from an ascii file with automatic detection of file format. supported: obj, off)
+  // Templates:
+  //   Scalar  type for positions and vectors (will be read as double and cast
+  //     to Scalar)
+  //   Index  type for indices (will be read as int and cast to Index)
+  // Inputs:
   // Inputs:
   //   str  path to .obj/.off file
   // Outputs:
   //   V  eigen double matrix #V by 3
   //   F  eigen int matrix #F by 3
+  template <typename Scalar, typename Index>
+  IGL_INLINE bool read(
+    const std::string str,
+    std::vector<std::vector<Scalar> > & V,
+    std::vector<std::vector<Index> > & F);
+#ifndef IGL_NO_EIGEN
   template <typename DerivedV, typename DerivedF>
   IGL_INLINE bool read(
     const std::string str,
     Eigen::PlainObjectBase<DerivedV>& V,
     Eigen::PlainObjectBase<DerivedF>& F);
+#endif
 }
 
 #ifdef IGL_HEADER_ONLY

+ 2 - 0
include/igl/readOFF.cpp

@@ -123,6 +123,7 @@ IGL_INLINE bool igl::readOFF(
 }
 
 
+#ifndef IGL_NO_EIGEN
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE bool igl::readOFF(
                              const std::string str,
@@ -196,6 +197,7 @@ IGL_INLINE bool igl::readOFF(
   }
   return true;
 }
+#endif
 
 
 #ifndef IGL_HEADER_ONLY

+ 16 - 12
include/igl/readOFF.h

@@ -10,7 +10,9 @@
 #define IGL_READOFF_H
 #include "igl_inline.h"
 
-#include <Eigen/Core>
+#ifndef IGL_NO_EIGEN
+#  include <Eigen/Core>
+#endif
 #include <string>
 #include <vector>
 
@@ -36,12 +38,13 @@ 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,
-                          std::vector<std::vector<Scalar > > & N);
+    const std::string off_file_name, 
+    std::vector<std::vector<Scalar > > & V,
+    std::vector<std::vector<Index > > & F,
+    std::vector<std::vector<Scalar > > & N);
   
   
+#ifndef IGL_NO_EIGEN
   // read mesh from a ascii off file
   // Inputs:
   //   str  path to .off file
@@ -50,16 +53,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);
+    const std::string str,
+    Eigen::PlainObjectBase<DerivedV>& V,
+    Eigen::PlainObjectBase<DerivedF>& F,
+    Eigen::PlainObjectBase<DerivedV>& N);
+#endif
 
 }