Browse Source

unsplit tetgen and better matlab workspace

Former-commit-id: 43443354ff9ec051f8180716bd56374d676b4c99
Alec Jacobson (jalec 11 years ago
parent
commit
fc22b86360

+ 1 - 0
include/igl/cotangent.cpp

@@ -135,4 +135,5 @@ IGL_INLINE void igl::cotangent(const MatV & V, const MatF & F, MatC & C)
 template void igl::cotangent<Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
 // generated by autoexplicit.sh
 template void igl::cotangent<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
+template void igl::cotangent<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, Eigen::Matrix<double, -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::Matrix<double, -1, -1, 0, -1, -1>&);
 #endif

+ 38 - 1
include/igl/matlab/MatlabWorkspace.cpp

@@ -59,7 +59,6 @@ IGL_INLINE igl::MatlabWorkspace& igl::MatlabWorkspace::save(
   using namespace std;
   const int m = M.rows();
   const int n = M.cols();
-
   mxArray * mx_data = mxCreateDoubleMatrix(m,n,mxREAL);
   data.push_back(mx_data);
   names.push_back(name);
@@ -69,6 +68,44 @@ IGL_INLINE igl::MatlabWorkspace& igl::MatlabWorkspace::save(
   return *this;
 }
 
+// Treat everything as a double
+template <typename MT>
+IGL_INLINE igl::MatlabWorkspace& igl::MatlabWorkspace::save(
+  const Eigen::SparseMatrix<MT>& M,
+  const std::string & name)
+{
+  using namespace std;
+  const int m = M.rows();
+  const int n = M.cols();
+  // THIS WILL NOT WORK FOR ROW-MAJOR
+  assert(n==M.outerSize());
+  const int nzmax = M.nonZeros();
+  mxArray * mx_data = mxCreateSparse(m, n, nzmax, mxREAL);
+  data.push_back(mx_data);
+  names.push_back(name);
+  // Copy data immediately
+  double * pr = mxGetPr(mx_data);
+  mwIndex * ir = mxGetIr(mx_data);
+  mwIndex * jc = mxGetJc(mx_data);
+
+  // Iterate over outside
+  int k = 0;
+  for(int j=0; j<M.outerSize();j++)
+  {
+    jc[j] = k;
+    // Iterate over inside
+    for(typename Eigen::SparseMatrix<MT>::InnerIterator it (M,j); it; ++it)
+    {
+      pr[k] = it.value();
+      ir[k] = it.row();
+      k++;
+    }
+  }
+  jc[M.outerSize()] = k;
+
+  return *this;
+}
+
 template <typename ScalarM>
 IGL_INLINE igl::MatlabWorkspace& igl::MatlabWorkspace::save(
   const std::vector<std::vector<ScalarM> > & vM,

+ 7 - 0
include/igl/matlab/MatlabWorkspace.h

@@ -5,6 +5,7 @@
 #include <string>
 #include <vector>
 #include <Eigen/Dense>
+#include <Eigen/Sparse>
 
 #include "mat.h"
 
@@ -52,6 +53,12 @@ namespace igl
       IGL_INLINE MatlabWorkspace& save(
         const Eigen::PlainObjectBase<DerivedM>& M,
         const std::string & name);
+      // Template:
+      //   MT  sparse matrix type (e.g. double)
+      template <typename MT>
+      IGL_INLINE MatlabWorkspace& save(
+        const Eigen::SparseMatrix<MT>& M,
+        const std::string & name);
       // Templates:
       //   ScalarM  scalar type, e.g. double
       template <typename ScalarM>

+ 2 - 0
include/igl/matlab_format.cpp

@@ -90,4 +90,6 @@ IGL_INLINE Eigen::IOFormat igl::matlab_format()
 // Explicit template instanciations
 template std::basic_string<char, std::char_traits<char>, std::allocator<char> > const igl::matlab_format<double>(Eigen::SparseMatrix<double, 0, int> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >);
 template Eigen::WithFormat<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const igl::matlab_format<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::string);
+template Eigen::WithFormat<Eigen::Array<int, -1, -1, 0, -1, -1> > const igl::matlab_format<Eigen::Array<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Array<int, -1, -1, 0, -1, -1> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >);
+template Eigen::WithFormat<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const igl::matlab_format<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >);
 #endif

+ 1 - 0
include/igl/unique.cpp

@@ -96,4 +96,5 @@ IGL_INLINE void igl::unique_rows(
 template void igl::unique<int>(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&, std::vector<size_t, std::allocator<size_t> >&, std::vector<size_t, std::allocator<size_t> >&);
 template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, 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> >&);
 template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<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> >&);
+template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, 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