Browse Source

pure k-gon to corners

Alec Jacobson 5 năm trước cách đây
mục cha
commit
babf491b69
2 tập tin đã thay đổi với 43 bổ sung0 xóa
  1. 29 0
      include/igl/polygon_corners.cpp
  2. 14 0
      include/igl/polygon_corners.h

+ 29 - 0
include/igl/polygon_corners.cpp

@@ -34,8 +34,37 @@ IGL_INLINE void igl::polygon_corners(
   I = Eigen::Map<DerivedI>(vI.data(),vI.size());
 }
 
+template <
+  typename DerivedQ, 
+  typename DerivedI,
+  typename DerivedC>
+IGL_INLINE void igl::polygon_corners(
+  const Eigen::MatrixBase<DerivedQ> & Q,
+  Eigen::PlainObjectBase<DerivedI> & I,
+  Eigen::PlainObjectBase<DerivedC> & C)
+{
+  I.resize(Q.size());
+  C.resize(Q.rows()+1);
+  int c = 0;
+  C(0) = 0;
+  for(int p = 0;p<Q.rows();p++)
+  {
+    int np = 0;
+    for(int i = 0;i<Q.cols();i++)
+    {
+      if(Q(p,i) == -1){ break;}
+      I(c++) = Q(p,i);
+      np++;
+    }
+    C(p+1) = C(p)+np;
+  }
+  I.conservativeResize(c);
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // generated by autoexplicit.sh
+template void igl::polygon_corners<Eigen::Matrix<int, -1, -1, 0, -1, -1>, 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> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+// generated by autoexplicit.sh
 template void igl::polygon_corners<int, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 #endif

+ 14 - 0
include/igl/polygon_corners.h

@@ -32,6 +32,20 @@ namespace igl
     const std::vector<std::vector<PType> > & P,
     Eigen::PlainObjectBase<DerivedI> & I,
     Eigen::PlainObjectBase<DerivedC> & C);
+  // Convert a pure k-gon list of polygon mesh indices to list of polygon corners
+  // and sizes
+  //
+  // Inputs:
+  //   Q  #Q by k list of k-gon indices (Q(i,j) = -1 means that face i is a
+  //     j-gon)
+  template <
+    typename DerivedQ, 
+    typename DerivedI,
+    typename DerivedC>
+  IGL_INLINE void polygon_corners(
+    const Eigen::MatrixBase<DerivedQ> & Q,
+    Eigen::PlainObjectBase<DerivedI> & I,
+    Eigen::PlainObjectBase<DerivedC> & C);
 }
 
 #ifndef IGL_STATIC_LIBRARY