Răsfoiți Sursa

robust redrum, mexstream for printing in mex files

Former-commit-id: 954e861d028e40c7f414a3db306665c1c80946a9
Alec Jacobson (jalec 12 ani în urmă
părinte
comite
ad15159ab3

+ 20 - 1
include/igl/REDRUM.h

@@ -8,6 +8,25 @@
 
 // ANSI color codes for formating iostream style output
 
+#ifdef IGL_REDRUM_NOOP
+
+// Bold Red, etc.
+#define REDRUM(X)     X
+#define GREENRUM(X)   X
+#define YELLOWRUM(X)  X
+#define BLUERUM(X)    X
+#define MAGENTARUM(X) X
+#define CYANRUM(X)    X
+// Regular Red, etc.
+#define REDGIN(X)     X
+#define GREENGIN(X)   X
+#define YELLOWGIN(X)  X
+#define BLUEGIN(X)    X
+#define MAGENTAGIN(X) X
+#define CYANGIN(X)    X
+
+#else
+
 // Bold Red, etc.
 #define REDRUM(X)      "\e[1m\e[31m"<<X<<"\e[m"
 #define GREENRUM(X)    "\e[1m\e[32m"<<X<<"\e[m"
@@ -15,7 +34,6 @@
 #define BLUERUM(X)     "\e[1m\e[34m"<<X<<"\e[m"
 #define MAGENTARUM(X)  "\e[1m\e[35m"<<X<<"\e[m"
 #define CYANRUM(X)     "\e[1m\e[36m"<<X<<"\e[m"
-
 // Regular Red, etc.
 #define REDGIN(X)      "\e[31m"<<X<<"\e[m"
 #define GREENGIN(X)    "\e[32m"<<X<<"\e[m"
@@ -23,5 +41,6 @@
 #define BLUEGIN(X)     "\e[34m"<<X<<"\e[m"
 #define MAGENTAGIN(X)  "\e[35m"<<X<<"\e[m"
 #define CYANGIN(X)     "\e[36m"<<X<<"\e[m"
+#endif
 
 #endif 

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

@@ -64,6 +64,7 @@ IGL_INLINE igl::MatlabWorkspace& igl::MatlabWorkspace::save(
   data.push_back(mx_data);
   names.push_back(name);
   // Copy data immediately
+  // Q: Won't this be incorrect for integers?
   copy(M.data(),M.data()+M.size(),mxGetPr(mx_data));
   return *this;
 }

+ 1 - 1
include/igl/matlab/matlabinterface.cpp

@@ -112,7 +112,7 @@ IGL_INLINE void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::Mat
     M = Eigen::MatrixXd(m,n);
     
     double *pM = mxGetPr(ary);
-    
+
     int c = 0;
     for(int j=0; j<M.cols();++j)
       for(int i=0; i<M.rows();++i)

+ 18 - 0
include/igl/matlab/mexStream.cpp

@@ -0,0 +1,18 @@
+#include "mexStream.h"
+#include "mex.h"
+
+std::streamsize igl::mexStream::xsputn(const char *s, std::streamsize n) 
+{
+  mexPrintf("%.*s",n,s);
+  mexEvalString("drawnow;"); // to dump string.
+  return n;
+}
+
+int igl::mexStream::overflow(int c) 
+{
+    if (c != EOF) {
+      mexPrintf("%.1s",&c);
+      mexEvalString("drawnow;"); // to dump string.
+    }
+    return 1;
+}

+ 20 - 0
include/igl/matlab/mexStream.h

@@ -0,0 +1,20 @@
+#include <iostream>
+namespace igl
+{
+  // http://stackoverflow.com/a/249008/148668
+  
+  // Class to implement "cout" for mex files to print to the matlab terminal
+  // window.
+  //
+  // Insert at the beginning of mexFunction():
+  //  mexStream mout;
+  //  std::cout.rdbuf(&mout); 
+  //
+  class mexStream : public std::streambuf
+  {
+    public:
+    protected:
+      virtual std::streamsize xsputn(const char *s, std::streamsize n); 
+      virtual int overflow(int c = EOF);
+  }; 
+}

+ 6 - 0
include/igl/min_quad_with_fixed.cpp

@@ -141,6 +141,12 @@ IGL_INLINE bool igl::min_quad_with_fixed_precompute(
     // Get transpose of Aequ
     Eigen::SparseMatrix<T> AequT = Aequ.transpose();
     // Compute LU decomposition
+    // TODO: This should be using SimplicialLDLT
+    // Q: Does SimplicialLDLT work on "Hermitian indefinite matrices" the way
+    // that matlabs ldl does?
+    // A: Maybe not. The eigen documentation writes, "This class provides a
+    // LDL^T Cholesky factorizations without square root of sparse matrices
+    // that are selfadjoint and positive definite"
     bool lu_success = igl::lu_lagrange(Auu,AequT,data.L,data.U);
     if(!lu_success)
     {