浏览代码

[REFACTOR]: use common combine routine

Former-commit-id: 6422b08fe1cfa0a10d71cafef1f049f301d4380a
Alec Jacobson 7 年之前
父节点
当前提交
0e9c419ac2
共有 3 个文件被更改,包括 55 次插入29 次删除
  1. 32 2
      include/igl/combine.cpp
  2. 17 0
      include/igl/combine.h
  3. 6 27
      include/igl/copyleft/cgal/mesh_boolean.cpp

+ 32 - 2
include/igl/combine.cpp

@@ -7,19 +7,26 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "combine.h"
 #include <cassert>
+
 template <
   typename DerivedVV, 
   typename DerivedFF, 
   typename DerivedV, 
-  typename DerivedF>
+  typename DerivedF,
+  typename DerivedVsizes,
+  typename DerivedFsizes>
 IGL_INLINE void igl::combine(
   const std::vector<DerivedVV> & VV,
   const std::vector<DerivedFF> & FF,
   Eigen::PlainObjectBase<DerivedV> & V,
-  Eigen::PlainObjectBase<DerivedF> & F)
+  Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedVsizes> & Vsizes,
+  Eigen::PlainObjectBase<DerivedFsizes> & Fsizes)
 {
   assert(VV.size() == FF.size() && 
     "Lists of verex lists and face lists should be same size");
+  Vsizes.resize(VV.size());
+  Fsizes.resize(FF.size());
   // Dimension of vertex positions
   const int dim = VV.size() > 0 ? VV[0].cols() : 0;
   // Simplex/element size
@@ -30,8 +37,10 @@ IGL_INLINE void igl::combine(
   {
     const auto & Vi = VV[i];
     const auto & Fi = FF[i];
+    Vsizes(i) = Vi.rows();
     n+=Vi.rows();
     assert(dim == Vi.cols() && "All vertex lists should have same #columns");
+    Fsizes(i) = Fi.rows();
     m+=Fi.rows();
     assert(ss == Fi.cols() && "All face lists should have same #columns");
   }
@@ -55,3 +64,24 @@ IGL_INLINE void igl::combine(
     assert(kf == F.rows());
   }
 }
+
+template <
+  typename DerivedVV, 
+  typename DerivedFF, 
+  typename DerivedV, 
+  typename DerivedF>
+IGL_INLINE void igl::combine(
+  const std::vector<DerivedVV> & VV,
+  const std::vector<DerivedFF> & FF,
+  Eigen::PlainObjectBase<DerivedV> & V,
+  Eigen::PlainObjectBase<DerivedF> & F)
+{
+  Eigen::VectorXi Vsizes,Fsizes;
+  return igl::combine(VV,FF,V,F,Vsizes,Fsizes);
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template instantiation
+// generated by autoexplicit.sh
+template void igl::combine<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::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1>, Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1> >(std::vector<Eigen::Matrix<double, -1, -1, 0, -1, -1>, std::allocator<Eigen::Matrix<double, -1, -1, 0, -1, -1> > > const&, std::vector<Eigen::Matrix<int, -1, -1, 0, -1, -1>, std::allocator<Eigen::Matrix<int, -1, -1, 0, -1, -1> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1> >&);
+#endif

+ 17 - 0
include/igl/combine.h

@@ -26,10 +26,27 @@ namespace igl
   //     vertex positions
   //   F   FF[0].rows()+...+FF[k-1].rows() by FF[0].cols() list of mesh faces
   //     indices into V
+  //   Vsizes  k list so that Vsizes(i) is the #vertices in the ith input
+  //   Fsizes  k list so that Fsizes(i) is the #faces in the ith input
   // Example:
   //   // Suppose you have mesh A (VA,FA) and mesh B (VB,FB)
   //   igl::combine<Eigen::MatrixXd,Eigen::MatrixXi>({VA,VB},{FA,FB},V,F);
   //
+  //
+  template <
+    typename DerivedVV, 
+    typename DerivedFF, 
+    typename DerivedV, 
+    typename DerivedF,
+    typename DerivedVsizes,
+    typename DerivedFsizes>
+  IGL_INLINE void combine(
+    const std::vector<DerivedVV> & VV,
+    const std::vector<DerivedFF> & FF,
+    Eigen::PlainObjectBase<DerivedV> & V,
+    Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedVsizes> & Vsizes,
+    Eigen::PlainObjectBase<DerivedFsizes> & Fsizes);
   template <
     typename DerivedVV, 
     typename DerivedFF, 

+ 6 - 27
include/igl/copyleft/cgal/mesh_boolean.cpp

@@ -15,6 +15,7 @@
 #include "relabel_small_immersed_cells.h"
 #include "remesh_self_intersections.h"
 #include "string_to_mesh_boolean_type.h"
+#include "../../combine.h"
 #include "../../cumsum.h"
 #include "../../extract_manifold_patches.h"
 #include "../../get_seconds.h"
@@ -137,33 +138,11 @@ IGL_INLINE bool igl::copyleft::cgal::mesh_boolean(
     Eigen::PlainObjectBase<DerivedFC > & FC,
     Eigen::PlainObjectBase<DerivedJ > & J)
 {
-  assert(Flist.size() == Vlist.size() && "#Vlist and #Flist should match");
-  const size_t num_inputs = Vlist.size();
-  // Gather sizes
-  Eigen::Matrix<size_t,Eigen::Dynamic,1> sizes(num_inputs);
-  int numf = 0;
-  int numv = 0;
-  for(int i = 0;i<num_inputs;i++)
-  {
-    sizes(i) = Flist[i].rows();
-    numf += Flist[i].rows();
-    numv += Vlist[i].rows();
-  }
-  // Combined mesh
-  DerivedV VV(numv,3);
-  DerivedF FF(numf,3);
-  {
-    int fk = 0;
-    int vk = 0;
-    for(int i = 0;i<num_inputs;i++)
-    {
-      FF.block(fk,0,Flist[i].rows(),3) = Flist[i].array() + vk;
-      fk += Flist[i].rows();
-      VV.block(vk,0,Vlist[i].rows(),3) = Vlist[i];
-      vk += Vlist[i].rows();
-    }
-  }
-  return mesh_boolean(VV,FF,sizes,wind_num_op,keep,VC,FC,J);
+  DerivedV VV;
+  DerivedF FF;
+  Eigen::Matrix<size_t,Eigen::Dynamic,1> Vsizes,Fsizes;
+  igl::combine(Vlist,Flist,VV,FF,Vsizes,Fsizes);
+  return mesh_boolean(VV,FF,Fsizes,wind_num_op,keep,VC,FC,J);
 }
 
 template <