Browse Source

templates

Former-commit-id: 0bed00f810d2e32b61925631b4447fd11857b917
Alec Jacobson 9 years ago
parent
commit
2dfdea1a3b

+ 1 - 0
include/igl/components.cpp

@@ -89,4 +89,5 @@ IGL_INLINE void igl::components(
 // Explicit template specialization
 template void igl::components<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> >&);
 template void igl::components<int, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<int, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::components<int, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::SparseMatrix<int, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif

+ 11 - 1
include/igl/orientable_patches.cpp

@@ -84,12 +84,22 @@ IGL_INLINE void igl::orientable_patches(
   //% Connected components are patches
   //%C = components(A); % alternative to graphconncomp from matlab_bgl
   //[~,C] = graphconncomp(A);
-  // graph connected components using boost
+  // graph connected components 
   components(A,C);
 
 }
 
+template <typename DerivedF, typename DerivedC>
+IGL_INLINE void igl::orientable_patches(
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedC> & C)
+{
+  Eigen::SparseMatrix<typename DerivedF::Scalar> A;
+  return orientable_patches(F,C,A);
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 template void igl::orientable_patches<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::SparseMatrix<int, 0, int>&);
+template void igl::orientable_patches<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> >&);
 #endif

+ 4 - 0
include/igl/orientable_patches.h

@@ -30,6 +30,10 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedF> & F,
     Eigen::PlainObjectBase<DerivedC> & C,
     Eigen::SparseMatrix<AScalar> & A);
+  template <typename DerivedF, typename DerivedC>
+  IGL_INLINE void orientable_patches(
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedC> & C);
 };
 #ifndef IGL_STATIC_LIBRARY
 #  include "orientable_patches.cpp"

+ 1 - 0
include/igl/randperm.cpp

@@ -31,5 +31,6 @@ IGL_INLINE void igl::randperm(
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 template void igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::randperm<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 //template Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int);
 #endif

+ 1 - 0
include/igl/slice.cpp

@@ -272,4 +272,5 @@ template void igl::slice<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0,
 template void igl::slice<Eigen::PlainObjectBase<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> > >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::slice<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::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::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 template void igl::slice<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
+template Eigen::Matrix<int, -1, -1, 0, -1, -1> igl::slice<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&);
 #endif

+ 16 - 0
include/igl/snap_points.cpp

@@ -67,7 +67,23 @@ IGL_INLINE void igl::snap_points(
   }
 }
 
+template <
+  typename DerivedC, 
+  typename DerivedV, 
+  typename DerivedI>
+IGL_INLINE void igl::snap_points(
+  const Eigen::PlainObjectBase<DerivedC > & C,
+  const Eigen::PlainObjectBase<DerivedV > & V,
+  Eigen::PlainObjectBase<DerivedI > & I)
+{
+  Eigen::Matrix<typename DerivedC::Scalar,DerivedC::RowsAtCompileTime,1> minD;
+  return igl::snap_points(C,V,I,minD);
+}
+
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 template void igl::snap_points<Eigen::Matrix<double, 1, 3, 1, 1, 3>, 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::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
+template void igl::snap_points<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 #endif
+

+ 8 - 0
include/igl/snap_points.h

@@ -46,6 +46,14 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedV > & V,
     Eigen::PlainObjectBase<DerivedI > & I,
     Eigen::PlainObjectBase<DerivedminD > & minD);
+  template <
+    typename DerivedC, 
+    typename DerivedV, 
+    typename DerivedI >
+  IGL_INLINE void snap_points(
+    const Eigen::PlainObjectBase<DerivedC > & C,
+    const Eigen::PlainObjectBase<DerivedV > & V,
+    Eigen::PlainObjectBase<DerivedI > & I);
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 28 - 11
include/igl/unproject.cpp

@@ -23,20 +23,35 @@ IGL_INLINE void igl::unproject(
   const Eigen::PlainObjectBase<Derivedviewport>&  viewport,
   Eigen::PlainObjectBase<Derivedscene> & scene)
 {
-  typedef typename Derivedscene::Scalar Scalar;
-  Eigen::Matrix<Scalar,4,4> Inverse = 
-    (proj.template cast<Scalar>() * model.template cast<Scalar>()).inverse();
+  if(win.cols() != 3)
+  {
+    assert(win.rows() == 3);
+    // needless transposes
+    Eigen::Matrix<typename Derivedscene::Scalar,1,3> sceneT;
+    unproject(win.transpose().eval(),model,proj,viewport,sceneT);
+    scene = sceneT.head(3);
+    return;
+  }
+  assert(win.cols() == 3);
+  const int n = win.rows();
+  scene.resize(n,3);
+  for(int i = 0;i<n;i++)
+  {
+    typedef typename Derivedscene::Scalar Scalar;
+    Eigen::Matrix<Scalar,4,4> Inverse = 
+      (proj.template cast<Scalar>() * model.template cast<Scalar>()).inverse();
 
-  Eigen::Matrix<Scalar,4,1> tmp;
-  tmp << win, 1;
-  tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
-  tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
-  tmp = tmp.array() * 2.0f - 1.0f;
+    Eigen::Matrix<Scalar,4,1> tmp;
+    tmp << win.row(i).head(3).transpose(), 1;
+    tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
+    tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
+    tmp = tmp.array() * 2.0f - 1.0f;
 
-  Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
-  obj /= obj(3);
+    Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
+    obj /= obj(3);
 
-  scene = obj.head(3);
+    scene.row(i).head(3) = obj.head(3);
+  }
 }
 
 template <typename Scalar>
@@ -54,4 +69,6 @@ IGL_INLINE Eigen::Matrix<Scalar,3,1> igl::unproject(
 #ifdef IGL_STATIC_LIBRARY
 template Eigen::Matrix<float, 3, 1, 0, 3, 1> igl::unproject<float>(Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&);
 template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::unproject<double>(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 1, 0, 4, 1> const&);
+template void igl::unproject<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
 #endif

+ 2 - 3
include/igl/unproject.h

@@ -14,12 +14,12 @@ namespace igl
   // Eigen reimplementation of gluUnproject
   //
   // Inputs:
-  //   win  screen space x, y, and z coordinates
+  //   win  #P by 3 or 3-vector (#P=1) of screen space x, y, and z coordinates
   //   model  4x4 model-view matrix
   //   proj  4x4 projection matrix
   //   viewport  4-long viewport vector
   // Outputs:
-  //   scene  the unprojected x, y, and z coordinates
+  //   scene  #P by 3 or 3-vector (#P=1) the unprojected x, y, and z coordinates
   template <
     typename Derivedwin,
     typename Derivedmodel,
@@ -40,7 +40,6 @@ namespace igl
     const Eigen::Matrix<Scalar,4,1>&  viewport);
 }
 
-
 #ifndef IGL_STATIC_LIBRARY
 #  include "unproject.cpp"
 #endif