Forráskód Böngészése

merge

Former-commit-id: 4e74f2a229ea5999bc798bd07245021af63df535
Kenshi Takayama (kenshi 11 éve
szülő
commit
80e3801ad2
4 módosított fájl, 104 hozzáadás és 51 törlés
  1. 35 5
      include/igl/adjacency_list.cpp
  2. 11 4
      include/igl/adjacency_list.h
  3. 20 22
      include/igl/tt.cpp
  4. 38 20
      include/igl/tt.h

+ 35 - 5
include/igl/adjacency_list.cpp

@@ -3,10 +3,10 @@
 #include "verbose.h"
 #include <algorithm>
 
-template <typename T, typename M>
+template <typename Index, typename IndexVector>
 IGL_INLINE void igl::adjacency_list(
-    const M & F, 
-    std::vector<std::vector<T> >& A,
+    const Eigen::PlainObjectBase<Index>  & F,
+    std::vector<std::vector<IndexVector> >& A,
     bool sorted)
 {
   A.clear(); 
@@ -62,7 +62,7 @@ IGL_INLINE void igl::adjacency_list(
     
     for(int v=0; v<(int)SR.size();++v)
     {
-      std::vector<T>& vv = A.at(v);
+      std::vector<IndexVector>& vv = A.at(v);
       std::vector<std::vector<int> >& sr = SR[v];
       
       std::vector<std::vector<int> > pn = sr;
@@ -120,7 +120,37 @@ IGL_INLINE void igl::adjacency_list(
   }
 }
 
+template <typename Index>
+IGL_INLINE void igl::adjacency_list(
+  const std::vector<std::vector<Index> > & F,
+  std::vector<std::vector<Index> >& A)
+{
+  A.clear(); 
+  A.resize(F.maxCoeff()+1);
+  
+  // Loop over faces
+  for(int i = 0;i<F.size();i++)
+  {
+    // Loop over this face
+    for(int j = 0;j<F[i].size();j++)
+    {
+      // Get indices of edge: s --> d
+      int s = F(i,j);
+      int d = F(i,(j+1)%F[i].size());
+      A.at(s).push_back(d);
+      A.at(d).push_back(s);
+    }
+  }
+  
+  // Remove duplicates
+  for(int i=0; i<(int)A.size();++i)
+  {
+    std::sort(A[i].begin(), A[i].end());
+    A[i].erase(std::unique(A[i].begin(), A[i].end()), A[i].end());
+  }
+  
+}
+
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
-template void igl::adjacency_list<unsigned int, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> const&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >&, bool);
 #endif

+ 11 - 4
include/igl/adjacency_list.h

@@ -2,7 +2,6 @@
 #define IGL_ADJACENCY_LIST_H
 #include "igl_inline.h"
 
-#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
 #include <Eigen/Dense>
 #include <Eigen/Sparse>
 #include <vector>
@@ -23,11 +22,19 @@ namespace igl
   //   adjacency_list(F,A);
   //
   // See also: edges, cotmatrix, diag
-  template <typename T, typename M>
+  template <typename Index, typename IndexVector>
   IGL_INLINE void adjacency_list(
-    const M & F, 
-    std::vector<std::vector<T> >& A,
+    const Eigen::PlainObjectBase<Index> & F, 
+    std::vector<std::vector<IndexVector> >& A,
     bool sorted = false);
+
+  // Variant that accepts polygonal faces. 
+  // Each element of F is a set of indices of a polygonal face.
+  template <typename Index>
+  IGL_INLINE void adjacency_list(
+    const std::vector<std::vector<Index> > & F,
+    std::vector<std::vector<Index> >& A);
+
 }
 
 #ifdef IGL_HEADER_ONLY

+ 20 - 22
include/igl/tt.cpp

@@ -3,9 +3,9 @@
 #include "is_manifold.h"
 #include <algorithm>
 
-template <typename DerivedV, typename DerivedF>
-IGL_INLINE void igl::tt_preprocess(const Eigen::PlainObjectBase<DerivedV>& /*V*/,
-                                   const Eigen::PlainObjectBase<DerivedF>& F,
+template <typename Scalar, typename Index>
+IGL_INLINE void igl::tt_preprocess(const Eigen::PlainObjectBase<Scalar>& /*V*/,
+                                   const Eigen::PlainObjectBase<Index>& F,
                                    std::vector<std::vector<int> >& TTT)
 {
   for(int f=0;f<F.rows();++f)
@@ -24,12 +24,12 @@ IGL_INLINE void igl::tt_preprocess(const Eigen::PlainObjectBase<DerivedV>& /*V*/
 }
 
 // Extract the face adjacencies
-template <typename DerivedF, typename DerivedTT>
-IGL_INLINE void igl::tt_extractTT(const Eigen::PlainObjectBase<DerivedF>& F,
+template <typename Index>
+IGL_INLINE void igl::tt_extractTT(const Eigen::PlainObjectBase<Index>& F,
                                   std::vector<std::vector<int> >& TTT,
-                                  Eigen::PlainObjectBase<DerivedTT>& TT)
+                                  Eigen::PlainObjectBase<Index>& TT)
 {
-  TT = Eigen::PlainObjectBase<DerivedTT>::Constant((int)(F.rows()),F.cols(),-1);
+  TT = Eigen::PlainObjectBase<Index>::Constant((int)(F.rows()),F.cols(),-1);
   
   for(int i=1;i<(int)TTT.size();++i)
   {
@@ -44,12 +44,12 @@ IGL_INLINE void igl::tt_extractTT(const Eigen::PlainObjectBase<DerivedF>& F,
 }
 
 // Extract the face adjacencies indices (needed for fast traversal)
-template <typename DerivedF, typename DerivedTT>
-IGL_INLINE void igl::tt_extractTTi(const Eigen::PlainObjectBase<DerivedF>& F,
+template <typename Index>
+IGL_INLINE void igl::tt_extractTTi(const Eigen::PlainObjectBase<Index>& F,
                                    std::vector<std::vector<int> >& TTT,
-                                   Eigen::PlainObjectBase<DerivedTT>& TTi)
+                                   Eigen::PlainObjectBase<Index>& TTi)
 {
-  TTi = Eigen::PlainObjectBase<DerivedTT>::Constant((int)(F.rows()),F.cols(),-1);
+  TTi = Eigen::PlainObjectBase<Index>::Constant((int)(F.rows()),F.cols(),-1);
   
   for(int i=1;i<(int)TTT.size();++i)
   {
@@ -64,10 +64,10 @@ IGL_INLINE void igl::tt_extractTTi(const Eigen::PlainObjectBase<DerivedF>& F,
 }
 
 // Compute triangle-triangle adjacency
-template <typename DerivedV, typename DerivedF, typename DerivedTT>
-IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<DerivedV>& V,
-                        const Eigen::PlainObjectBase<DerivedF>& F,
-                        Eigen::PlainObjectBase<DerivedTT>& TT)
+template <typename Scalar, typename Index>
+IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<Scalar>& V,
+                        const Eigen::PlainObjectBase<Index>& F,
+                        Eigen::PlainObjectBase<Index>& TT)
 {
   assert(igl::is_manifold(V,F));
   std::vector<std::vector<int> > TTT;
@@ -77,11 +77,11 @@ IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<DerivedV>& V,
 }
 
 // Compute triangle-triangle adjacency with indices
-template <typename DerivedV, typename DerivedF, typename DerivedTT>
-IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<DerivedV>& V,
-                        const Eigen::PlainObjectBase<DerivedF>& F,
-                        Eigen::PlainObjectBase<DerivedTT>& TT,
-                        Eigen::PlainObjectBase<DerivedTT>& TTi)
+template <typename Scalar, typename Index>
+IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<Scalar>& V,
+                        const Eigen::PlainObjectBase<Index>& F,
+                        Eigen::PlainObjectBase<Index>& TT,
+                        Eigen::PlainObjectBase<Index>& TTi)
 {
   assert(igl::is_manifold(V,F));
   std::vector<std::vector<int> > TTT;
@@ -94,6 +94,4 @@ IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<DerivedV>& V,
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
-template void igl::tt<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::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::tt<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::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> >&);
 #endif

+ 38 - 20
include/igl/tt.h

@@ -13,32 +13,50 @@
 
 namespace igl 
 {
+  // Constructs the triangle adjacency matrix for a given
+  // mesh (V,F).
+  //
+  // Templates:
+  //   Scalar derived type of eigen matrix for V (e.g. derived from
+  //     MatirxXd)
+  //   Index  derived type of eigen matrix for F (e.g. derived from
+  //     MatrixXi)
+  // Inputs:
+  //   V  #V by dim list of mesh vertex positions
+  //   F  #F by simplex_size list of mesh faces (must be triangles)
+  // Outputs:
+  //   TT   #F by #3 adjacent matrix, the element i,j is the id of the triangle adjacent to the j edge of triangle i
+  //   TTi  #F by #3 adjacent matrix, the element i,j is the id of edge of the triangle TT(i,j) that is adjacent with triangle i
+  // NOTE: the first edge of a triangle is [0,1] the second [1,2] and the third [2,3].
+  //       this convention is DIFFERENT from cotangent.h
+
+  template <typename Scalar, typename Index>
+  IGL_INLINE void tt(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 tt(const Eigen::PlainObjectBase<Scalar>& V,
+                     const Eigen::PlainObjectBase<Index>& F,
+                     Eigen::PlainObjectBase<Index>& TT,
+                     Eigen::PlainObjectBase<Index>& TTi);
+
+  
   // Preprocessing
-  template <typename DerivedV, typename DerivedF>
-  IGL_INLINE void tt_preprocess(const Eigen::PlainObjectBase<DerivedV>& V,
-                                const Eigen::PlainObjectBase<DerivedF>& F,
+  template <typename Scalar, typename Index>
+  IGL_INLINE void tt_preprocess(const Eigen::PlainObjectBase<Scalar>& V,
+                                const Eigen::PlainObjectBase<Index>& F,
                                 std::vector<std::vector<int> >& TTT);
   // Extract the face adjacencies
-  template <typename DerivedF, typename DerivedTT>
-  IGL_INLINE void tt_extractTT(const Eigen::PlainObjectBase<DerivedF>& F,
+  template <typename Index>
+  IGL_INLINE void tt_extractTT(const Eigen::PlainObjectBase<Index>& F,
                                std::vector<std::vector<int> >& TTT,
-                               Eigen::PlainObjectBase<DerivedTT>& TT);
+                               Eigen::PlainObjectBase<Index>& TT);
   // Extract the face adjacencies indices (needed for fast traversal)
-  template <typename DerivedF, typename DerivedTT>
-  IGL_INLINE void tt_extractTTi(const Eigen::PlainObjectBase<DerivedF>& F,
+  template <typename Index>
+  IGL_INLINE void tt_extractTTi(const Eigen::PlainObjectBase<Index>& F,
                                 std::vector<std::vector<int> >& TTT,
-                                Eigen::PlainObjectBase<DerivedTT>& TTi);
-  // Compute triangle-triangle adjacency
-  template <typename DerivedV, typename DerivedF, typename DerivedTT>
-  IGL_INLINE void tt(const Eigen::PlainObjectBase<DerivedV>& V,
-                     const Eigen::PlainObjectBase<DerivedF>& F,
-                     Eigen::PlainObjectBase<DerivedTT>& TT);
-  // Compute triangle-triangle adjacency with indices
-  template <typename DerivedV, typename DerivedF, typename DerivedTT>
-  IGL_INLINE void tt(const Eigen::PlainObjectBase<DerivedV>& V,
-                     const Eigen::PlainObjectBase<DerivedF>& F,
-                     Eigen::PlainObjectBase<DerivedTT>& TT,
-                     Eigen::PlainObjectBase<DerivedTT>& TTi);
+                                Eigen::PlainObjectBase<Index>& TTi);
 }
 
 #ifdef IGL_HEADER_ONLY