Bläddra i källkod

fixed template madness in tri_tri

Former-commit-id: 4d754128268c21277d2a7d5111b4f8189f6f5460
Alec Jacobson 10 år sedan
förälder
incheckning
3b3eddd9a0

+ 2 - 1
include/igl/false_barycentric_subdivision.h

@@ -19,7 +19,8 @@ namespace igl
   //   F       #F by 3 list of mesh faces (must be triangles)
   // Outputs:
   //   VD      #V + #F by 3 coordinate of the vertices of the dual mesh
-  //           The added vertices are added at the end of VD
+  //           The added vertices are added at the end of VD (should not be
+  //           same references as (V,F)
   //   FD      #F*3 by 3 faces of the dual mesh
   //
   template <typename Scalar, typename Index>

+ 43 - 33
include/igl/triangle_triangle_adjacency.cpp

@@ -14,9 +14,18 @@
 #include <iostream>
 
 template <typename Scalar, typename Index>
-IGL_INLINE void igl::triangle_triangle_adjacency_preprocess(const Eigen::PlainObjectBase<Scalar>& /*V*/,
-                                   const Eigen::PlainObjectBase<Index>& F,
-                                   std::vector<std::vector<int> >& TTT)
+IGL_INLINE void igl::triangle_triangle_adjacency_preprocess(
+    const Eigen::PlainObjectBase<Scalar>& /*V*/,
+    const Eigen::PlainObjectBase<Index>& F,
+    std::vector<std::vector<int> >& TTT)
+{
+  return triangle_triangle_adjacency_preprocess(F,TTT);
+}
+
+template <typename Index>
+IGL_INLINE void igl::triangle_triangle_adjacency_preprocess(
+    const Eigen::PlainObjectBase<Index>& F,
+    std::vector<std::vector<int> >& TTT)
 {
   for(int f=0;f<F.rows();++f)
     for (int i=0;i<F.cols();++i)
@@ -34,12 +43,13 @@ IGL_INLINE void igl::triangle_triangle_adjacency_preprocess(const Eigen::PlainOb
 }
 
 // Extract the face adjacencies
-template <typename Index>
-IGL_INLINE void igl::triangle_triangle_adjacency_extractTT(const Eigen::PlainObjectBase<Index>& F,
-                                  std::vector<std::vector<int> >& TTT,
-                                  Eigen::PlainObjectBase<Index>& TT)
+template <typename DerivedF, typename DerivedTT>
+IGL_INLINE void igl::triangle_triangle_adjacency_extractTT(
+  const Eigen::PlainObjectBase<DerivedF>& F,
+  std::vector<std::vector<int> >& TTT,
+  Eigen::PlainObjectBase<DerivedTT>& TT)
 {
-  TT = Eigen::PlainObjectBase<Index>::Constant((int)(F.rows()),F.cols(),-1);
+  TT.setConstant((int)(F.rows()),F.cols(),-1);
 
   for(int i=1;i<(int)TTT.size();++i)
   {
@@ -54,12 +64,13 @@ IGL_INLINE void igl::triangle_triangle_adjacency_extractTT(const Eigen::PlainObj
 }
 
 // Extract the face adjacencies indices (needed for fast traversal)
-template <typename Index>
-IGL_INLINE void igl::triangle_triangle_adjacency_extractTTi(const Eigen::PlainObjectBase<Index>& F,
-                                   std::vector<std::vector<int> >& TTT,
-                                   Eigen::PlainObjectBase<Index>& TTi)
+template <typename DerivedF, typename DerivedTTi>
+IGL_INLINE void igl::triangle_triangle_adjacency_extractTTi(
+  const Eigen::PlainObjectBase<DerivedF>& F,
+  std::vector<std::vector<int> >& TTT,
+  Eigen::PlainObjectBase<DerivedTTi>& TTi)
 {
-  TTi = Eigen::PlainObjectBase<Index>::Constant((int)(F.rows()),F.cols(),-1);
+  TTi.setConstant((int)(F.rows()),F.cols(),-1);
 
   for(int i=1;i<(int)TTT.size();++i)
   {
@@ -88,15 +99,29 @@ IGL_INLINE void igl::triangle_triangle_adjacency(const Eigen::PlainObjectBase<Sc
 
 // Compute triangle-triangle adjacency with indices
 template <typename Scalar, typename Index>
-IGL_INLINE void igl::triangle_triangle_adjacency(const Eigen::PlainObjectBase<Scalar>& V,
-                        const Eigen::PlainObjectBase<Index>& F,
-                        Eigen::PlainObjectBase<Index>& TT,
-                        Eigen::PlainObjectBase<Index>& TTi)
+IGL_INLINE void igl::triangle_triangle_adjacency(
+  const Eigen::PlainObjectBase<Scalar>& /*V*/,
+  const Eigen::PlainObjectBase<Index>& F,
+  Eigen::PlainObjectBase<Index>& TT,
+  Eigen::PlainObjectBase<Index>& TTi)
 {
   //assert(igl::is_edge_manifold(V,F));
   std::vector<std::vector<int> > TTT;
+  triangle_triangle_adjacency_preprocess(F,TTT);
+  triangle_triangle_adjacency_extractTT(F,TTT,TT);
+  triangle_triangle_adjacency_extractTTi(F,TTT,TTi);
+}
 
-  triangle_triangle_adjacency_preprocess(V,F,TTT);
+// Compute triangle-triangle adjacency with indices
+template <typename DerivedF, typename DerivedTT, typename DerivedTTi>
+IGL_INLINE void igl::triangle_triangle_adjacency(
+  const Eigen::PlainObjectBase<DerivedF>& F,
+  Eigen::PlainObjectBase<DerivedTT>& TT,
+  Eigen::PlainObjectBase<DerivedTTi>& TTi)
+{
+  //assert(igl::is_edge_manifold(V,F));
+  std::vector<std::vector<int> > TTT;
+  triangle_triangle_adjacency_preprocess(F,TTT);
   triangle_triangle_adjacency_extractTT(F,TTT,TT);
   triangle_triangle_adjacency_extractTTi(F,TTT,TTi);
 }
@@ -210,19 +235,4 @@ template <
 
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<long, -1, 1, 0, -1, 1>, long, long, long>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> > const&, std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > const&, bool, std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > >&, std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > >&);
-template void igl::triangle_triangle_adjacency<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&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<int, -1, -1, 0, -1, -1>, long, long>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > >&, std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > >&);
-template void igl::triangle_triangle_adjacency<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&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<double, -1, -1, 0, -1, -1>, long, long>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > >&, std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > >&);
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<int, -1, -1, 0, -1, -1>, int, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >&, std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >&);
-template void igl::triangle_triangle_adjacency<Eigen::Matrix<int, -1, 3, 0, -1,
-         3>, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >
-             const&, std::vector<std::vector<std::vector<int,
-             std::allocator<int> >, std::allocator<std::vector<int,
-             std::allocator<int> > > >,
-             std::allocator<std::vector<std::vector<int, std::allocator<int> >,
-             std::allocator<std::vector<int, std::allocator<int> > > > > >&);
 #endif

+ 33 - 18
include/igl/triangle_triangle_adjacency.h

@@ -32,32 +32,47 @@ namespace igl
   // Known bug: this should not need to take V as input.
 
   template <typename Scalar, typename Index>
-  IGL_INLINE void triangle_triangle_adjacency(const Eigen::PlainObjectBase<Scalar>& V,
-                     const Eigen::PlainObjectBase<Index>& F,
-                     Eigen::PlainObjectBase<Index>& TT);
+  IGL_INLINE void triangle_triangle_adjacency(
+    const Eigen::PlainObjectBase<Scalar>& V,
+    const Eigen::PlainObjectBase<Index>& F,
+    Eigen::PlainObjectBase<Index>& TT);
   // Compute triangle-triangle adjacency with indices
   template <typename Scalar, typename Index>
-  IGL_INLINE void triangle_triangle_adjacency(const Eigen::PlainObjectBase<Scalar>& V,
-                     const Eigen::PlainObjectBase<Index>& F,
-                     Eigen::PlainObjectBase<Index>& TT,
-                     Eigen::PlainObjectBase<Index>& TTi);
+  IGL_INLINE void triangle_triangle_adjacency(
+    const Eigen::PlainObjectBase<Scalar>& V,
+    const Eigen::PlainObjectBase<Index>& F,
+    Eigen::PlainObjectBase<Index>& TT,
+    Eigen::PlainObjectBase<Index>& TTi);
+
+  template <typename DerivedF, typename DerivedTT, typename DerivedTTi>
+  IGL_INLINE void triangle_triangle_adjacency(
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    Eigen::PlainObjectBase<DerivedTT>& TT,
+    Eigen::PlainObjectBase<DerivedTTi>& TTi);
 
 
   // Preprocessing
   template <typename Scalar, typename Index>
-  IGL_INLINE void triangle_triangle_adjacency_preprocess(const Eigen::PlainObjectBase<Scalar>& V,
-                                const Eigen::PlainObjectBase<Index>& F,
-                                std::vector<std::vector<int> >& TTT);
+  IGL_INLINE void triangle_triangle_adjacency_preprocess(
+    const Eigen::PlainObjectBase<Scalar>& V,
+    const Eigen::PlainObjectBase<Index>& F,
+    std::vector<std::vector<int> >& TTT);
+  template <typename DerivedF>
+  IGL_INLINE void triangle_triangle_adjacency_preprocess(
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    std::vector<std::vector<int> >& TTT);
   // Extract the face adjacencies
-  template <typename Index>
-  IGL_INLINE void triangle_triangle_adjacency_extractTT(const Eigen::PlainObjectBase<Index>& F,
-                               std::vector<std::vector<int> >& TTT,
-                               Eigen::PlainObjectBase<Index>& TT);
+  template <typename DerivedF, typename DerivedTT>
+  IGL_INLINE void triangle_triangle_adjacency_extractTT(
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    std::vector<std::vector<int> >& TTT,
+    Eigen::PlainObjectBase<DerivedTT>& TT);
   // Extract the face adjacencies indices (needed for fast traversal)
-  template <typename Index>
-  IGL_INLINE void triangle_triangle_adjacency_extractTTi(const Eigen::PlainObjectBase<Index>& F,
-                                std::vector<std::vector<int> >& TTT,
-                                Eigen::PlainObjectBase<Index>& TTi);
+  template <typename DerivedF, typename DerivedTTi>
+  IGL_INLINE void triangle_triangle_adjacency_extractTTi(
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    std::vector<std::vector<int> >& TTT,
+    Eigen::PlainObjectBase<DerivedTTi>& TTi);
   // Adjacency list version, which works with non-manifold meshes
   //
   // Inputs:

+ 4 - 3
include/igl/upsample.cpp

@@ -9,7 +9,6 @@
 
 #include "triangle_triangle_adjacency.h"
 
-#include <Eigen/Dense>
 
 template <
   typename DerivedV,
@@ -28,8 +27,10 @@ IGL_INLINE void igl::upsample(
   using namespace std;
   using namespace Eigen;
 
-  Eigen::MatrixXi FF,FFi;
-  triangle_triangle_adjacency(V,F,FF,FFi);
+  Eigen::Matrix<
+    typename DerivedF::Scalar,Eigen::Dynamic,Eigen::Dynamic>
+    FF,FFi;
+  triangle_triangle_adjacency(F,FF,FFi);
 
   // TODO: Cache optimization missing from here, it is a mess