Bläddra i källkod

missing rhs lhs files

Former-commit-id: bfddf7f7e040f42f0e9a9f7e4bcdc359b59bd372
Alec Jacobson 11 år sedan
förälder
incheckning
c47c2706cd

+ 32 - 0
include/igl/matlab/parse_rhs.cpp

@@ -0,0 +1,32 @@
+#include "parse_rhs.h"
+#include <algorithm>
+
+template <typename DerivedV>
+IGL_INLINE void igl::parse_rhs_double(
+    const mxArray *prhs[], 
+    Eigen::PlainObjectBase<DerivedV> & V)
+{
+  using namespace std;
+  // set number of mesh vertices
+  const int n = mxGetM(prhs[0]);
+  // set vertex position pointers
+  double * Vp = mxGetPr(prhs[0]);
+  const int dim = mxGetN(prhs[0]);
+  V.resize(n,dim);
+  copy(Vp,Vp+n*dim,&V.data()[0]);
+}
+
+template <typename DerivedV>
+IGL_INLINE void igl::parse_rhs_index(
+    const mxArray *prhs[], 
+    Eigen::PlainObjectBase<DerivedV> & V)
+{
+  parse_rhs_double(prhs,V);
+  V.array() -= 1;
+}
+
+#ifndef IGL_HEADER_ONLY
+template void igl::parse_rhs_index<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(mxArray_tag const**, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::parse_rhs_index<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(mxArray_tag const**, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+template void igl::parse_rhs_double<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(mxArray_tag const**, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+#endif

+ 27 - 0
include/igl/matlab/parse_rhs.h

@@ -0,0 +1,27 @@
+#ifndef IGL_PARSE_RHS_H
+#define IGL_PARSE_RHS_H
+#include <igl/igl_inline.h>
+#include <mex.h>
+#include <Eigen/Dense>
+namespace igl
+{
+  // Reads in a matrix as a double
+  //
+  // Inputs:
+  //   prhs  points to rhs argument
+  // Outputs:
+  //   V  M by N matrix 
+  template <typename DerivedV>
+  IGL_INLINE void parse_rhs_double(
+    const mxArray *prhs[], 
+    Eigen::PlainObjectBase<DerivedV> & V);
+  // Reads in a matrix and subtracts 1
+  template <typename DerivedV>
+  IGL_INLINE void parse_rhs_index(
+    const mxArray *prhs[], 
+    Eigen::PlainObjectBase<DerivedV> & V);
+};
+#ifdef IGL_HEADER_ONLY
+#  include "parse_rhs.cpp"
+#endif
+#endif

+ 29 - 0
include/igl/matlab/prepare_lhs.cpp

@@ -0,0 +1,29 @@
+#include "prepare_lhs.h"
+#include <algorithm>
+template <typename DerivedV>
+IGL_INLINE void igl::prepare_lhs_double(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  mxArray *plhs[])
+{
+  using namespace std;
+  plhs[0] = mxCreateDoubleMatrix(V.rows(),V.cols(), mxREAL);
+  double * Vp = mxGetPr(plhs[0]);
+  copy(&V.data()[0],&V.data()[0]+V.size(),Vp);
+}
+
+template <typename DerivedV>
+IGL_INLINE void igl::prepare_lhs_index(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  mxArray *plhs[])
+{
+  // Treat indices as reals
+  
+  const auto Vd = (V.template cast<double>().array()+1).eval();
+  return prepare_lhs_double(Vd,plhs);
+}
+
+#ifndef IGL_HEADER_ONLY
+template void igl::prepare_lhs_index<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
+template void igl::prepare_lhs_index<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
+template void igl::prepare_lhs_double<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, mxArray_tag**);
+#endif

+ 28 - 0
include/igl/matlab/prepare_lhs.h

@@ -0,0 +1,28 @@
+#ifndef IGL_PREPARE_LHS_H
+#define IGL_PREPARE_LHS_H
+#include <igl/igl_inline.h>
+#include <mex.h>
+#include <Eigen/Dense>
+namespace igl
+{
+  // Writes out a matrix as a double
+  //
+  // Inputs:
+  //   prhs  points to rhs argument
+  // Outputs:
+  //   V  M by N matrix 
+  template <typename DerivedV>
+  IGL_INLINE void prepare_lhs_double(
+    const Eigen::PlainObjectBase<DerivedV> & V,
+    mxArray *plhs[]);
+  // Writes out a matrix and adds 1
+  template <typename DerivedV>
+  IGL_INLINE void prepare_lhs_index(
+    const Eigen::PlainObjectBase<DerivedV> & V,
+    mxArray *plhs[]);
+};
+#ifdef IGL_HEADER_ONLY
+#  include "prepare_lhs.cpp"
+#endif
+#endif
+