Bläddra i källkod

better templating

Former-commit-id: 54f119c55eb74bc324bdbc61efb998cfd441503c
Alec Jacobson 8 år sedan
förälder
incheckning
992eeb587a

+ 3 - 2
include/igl/components.cpp

@@ -78,7 +78,7 @@ IGL_INLINE void igl::components(
 
 template <typename DerivedF, typename DerivedC>
 IGL_INLINE void igl::components(
-  const Eigen::PlainObjectBase<DerivedF> & F,
+  const Eigen::MatrixBase<DerivedF> & F,
   Eigen::PlainObjectBase<DerivedC> & C)
 {
   Eigen::SparseMatrix<typename DerivedC::Scalar> A;
@@ -88,8 +88,9 @@ IGL_INLINE void igl::components(
 
 #ifdef IGL_STATIC_LIBRARY
 // 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<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<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> >&);
 template void igl::components<double, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+template void igl::components<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif

+ 1 - 1
include/igl/components.h

@@ -39,7 +39,7 @@ namespace igl
   //   C  max(F) list of component ids
   template <typename DerivedF, typename DerivedC>
   IGL_INLINE void components(
-    const Eigen::PlainObjectBase<DerivedF> & F,
+    const Eigen::MatrixBase<DerivedF> & F,
     Eigen::PlainObjectBase<DerivedC> & C);
 
 }

+ 6 - 1
include/igl/edges.cpp

@@ -10,7 +10,7 @@
 
 template <typename DerivedF, typename DerivedE>
 IGL_INLINE void igl::edges(
-  const Eigen::PlainObjectBase<DerivedF> & F, 
+  const Eigen::MatrixBase<DerivedF> & F, 
   Eigen::PlainObjectBase<DerivedE> & E)
 {
   // build adjacency matrix
@@ -38,3 +38,8 @@ IGL_INLINE void igl::edges(
     }
   }
 }
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template specialization
+template void igl::edges<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 2, 0, -1, 2> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&);
+#endif

+ 1 - 1
include/igl/edges.h

@@ -26,7 +26,7 @@ namespace igl
   // See also: adjacency_matrix
   template <typename DerivedF, typename DerivedE>
   IGL_INLINE void edges(
-    const Eigen::PlainObjectBase<DerivedF> & F, 
+    const Eigen::MatrixBase<DerivedF> & F, 
     Eigen::PlainObjectBase<DerivedE> & E);
 }
 

+ 15 - 2
include/igl/euler_characteristic.cpp

@@ -7,7 +7,8 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "euler_characteristic.h"
 
-#include <igl/edge_topology.h>
+#include "edge_topology.h"
+#include "edges.h"
 
 template <typename Scalar, typename Index>
 IGL_INLINE int igl::euler_characteristic(
@@ -26,8 +27,20 @@ IGL_INLINE int igl::euler_characteristic(
 
 }
 
+template <typename DerivedF>
+IGL_INLINE int igl::euler_characteristic(
+  const Eigen::MatrixBase<DerivedF> & F)
+{
+  const int nf = F.rows();
+  const int nv = F.maxCoeff()+1;
+  Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,2> E;
+  edges(F,E);
+  const int ne = E.rows();
+  return nv - ne + nf;
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
-// generated by autoexplicit.sh
 template int igl::euler_characteristic<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<int, -1, -1, 0, -1, -1> > const&);
+template int igl::euler_characteristic<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
 #endif

+ 11 - 2
include/igl/euler_characteristic.h

@@ -1,6 +1,7 @@
 // This file is part of libigl, a simple c++ geometry processing library.
 //
 // Copyright (C) 2016 Michael Rabinovich <michaelrabinovich27@gmail.com>
+// Copyright (C) 2017 Alec Jacobson <alecjacobson@gmail.com>
 //
 // This Source Code Form is subject to the terms of the Mozilla Public License
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
@@ -14,6 +15,15 @@
 #include <vector>
 namespace igl
 {
+  // Computes the Euler characteristic of a given mesh (V,F)
+  //
+  // Inputs:
+  //   F #F by dim list of mesh faces (must be triangles)
+  // Returns An int containing the Euler characteristic
+  template <typename DerivedF>
+  IGL_INLINE int euler_characteristic(
+    const Eigen::MatrixBase<DerivedF> & F);
+
   // Computes the Euler characteristic of a given mesh (V,F)
   // Templates:
   //   Scalar  should be a floating point number type
@@ -21,8 +31,7 @@ namespace igl
   // Inputs:
   //   V       #V by dim list of mesh vertex positions
   //   F       #F by dim list of mesh faces (must be triangles)
-  // Outputs:
-  //   An int containing the Euler characteristic
+  // Returns An int containing the Euler characteristic
   template <typename Scalar, typename Index>
   IGL_INLINE int euler_characteristic(
     const Eigen::PlainObjectBase<Scalar> & V,