|
@@ -0,0 +1,64 @@
|
|
|
+#include "read_eigen_from_CSV.h"
|
|
|
+
|
|
|
+#include <sstream>
|
|
|
+#include <string>
|
|
|
+#include <fstream>
|
|
|
+
|
|
|
+#include <vector>
|
|
|
+
|
|
|
+namespace igl
|
|
|
+{
|
|
|
+
|
|
|
+template <typename Scalar>
|
|
|
+IGL_INLINE bool read_eigen_from_CSV(const std::string str, Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic>& M)
|
|
|
+{
|
|
|
+ using namespace std;
|
|
|
+ using namespace igl;
|
|
|
+
|
|
|
+ std::vector<std::vector<Scalar> > Mt;
|
|
|
+
|
|
|
+ std::ifstream infile(str.c_str());
|
|
|
+ std::string line;
|
|
|
+ while (std::getline(infile, line))
|
|
|
+ {
|
|
|
+ std::istringstream iss(line);
|
|
|
+ vector<Scalar> temp;
|
|
|
+ Scalar a;
|
|
|
+ while (iss >> a)
|
|
|
+ temp.push_back(a);
|
|
|
+
|
|
|
+ if (temp.size() != 0) // skip empty lines
|
|
|
+ Mt.push_back(temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Mt.size() != 0)
|
|
|
+ {
|
|
|
+ // Verify that it is indeed a matrix
|
|
|
+ for (unsigned i = 0; i<Mt.size(); ++i)
|
|
|
+ {
|
|
|
+ if (Mt[i].size() != Mt[0].size())
|
|
|
+ {
|
|
|
+ infile.close();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ M.resize(Mt.size(),Mt[0].size());
|
|
|
+ for (unsigned i = 0; i<Mt.size(); ++i)
|
|
|
+ for (unsigned j = 0; j<Mt[i].size(); ++j)
|
|
|
+ M(i,j) = Mt[i][j];
|
|
|
+
|
|
|
+// cerr << "TRUE!" << endl;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ infile.close();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#ifndef IGL_HEADER_ONLY
|
|
|
+// Explicit template specialization
|
|
|
+// generated by autoexplicit.sh
|
|
|
+#endif
|