Browse Source

we have the functions `igl::components()` and `igl::facet_components()` for computing connected components on vertices and faces respectively.

The naming here is super confusing (and someone wasted a couple of hours because they didn't know that facet_components existed).

This change improves discoverability in 2 ways:
1 - More consistent naming by changint `components()` to `vertex_components()` which hints that there may exist a `facet_component()` function.
2 - Reference `facet_components()` in the docs for `vertex_components()` and vice versa


Former-commit-id: 43a7d250f53e0bb40ffce1f09d1ceb91610d69c8
Francis Williams 7 years ago
parent
commit
18a1eaf38c

+ 11 - 11
include/igl/components.cpp

@@ -11,7 +11,7 @@
 #include <vector>
 #include <vector>
 
 
 template <typename AScalar, typename DerivedC, typename Derivedcounts>
 template <typename AScalar, typename DerivedC, typename Derivedcounts>
-IGL_INLINE void igl::components(
+IGL_INLINE void igl::vertex_components(
   const Eigen::SparseMatrix<AScalar> & A,
   const Eigen::SparseMatrix<AScalar> & A,
   Eigen::PlainObjectBase<DerivedC> & C,
   Eigen::PlainObjectBase<DerivedC> & C,
   Eigen::PlainObjectBase<Derivedcounts> & counts)
   Eigen::PlainObjectBase<Derivedcounts> & counts)
@@ -68,31 +68,31 @@ IGL_INLINE void igl::components(
 }
 }
 
 
 template <typename AScalar, typename DerivedC>
 template <typename AScalar, typename DerivedC>
-IGL_INLINE void igl::components(
+IGL_INLINE void igl::vertex_components(
   const Eigen::SparseMatrix<AScalar> & A,
   const Eigen::SparseMatrix<AScalar> & A,
   Eigen::PlainObjectBase<DerivedC> & C)
   Eigen::PlainObjectBase<DerivedC> & C)
 {
 {
   Eigen::VectorXi counts;
   Eigen::VectorXi counts;
-  return components(A,C,counts);
+  return vertex_components(A,C,counts);
 }
 }
 
 
 template <typename DerivedF, typename DerivedC>
 template <typename DerivedF, typename DerivedC>
-IGL_INLINE void igl::components(
+IGL_INLINE void igl::vertex_components(
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
   Eigen::PlainObjectBase<DerivedC> & C)
   Eigen::PlainObjectBase<DerivedC> & C)
 {
 {
   Eigen::SparseMatrix<typename DerivedC::Scalar> A;
   Eigen::SparseMatrix<typename DerivedC::Scalar> A;
   adjacency_matrix(F,A);
   adjacency_matrix(F,A);
-  return components(A,C);
+  return vertex_components(A,C);
 }
 }
 
 
 #ifdef IGL_STATIC_LIBRARY
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // Explicit template instantiation
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template void igl::components<bool, Eigen::Array<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<bool, 0, int> const&, Eigen::PlainObjectBase<Eigen::Array<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> >&);
+template void igl::vertex_components<bool, Eigen::Array<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<bool, 0, int> const&, Eigen::PlainObjectBase<Eigen::Array<int, -1, 1, 0, -1, 1> >&);
+template void igl::vertex_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::vertex_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::vertex_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::vertex_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::vertex_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
 #endif

+ 13 - 6
include/igl/components.h

@@ -13,7 +13,9 @@
 namespace igl
 namespace igl
 {
 {
   // Compute connected components of a graph represented by an adjacency
   // Compute connected components of a graph represented by an adjacency
-  // matrix. This version is faster than the previous version using boost.
+  // matrix.
+  //
+  // Returns a component ID per vertex of the graph where connectivity is established by edges.
   //
   //
   // Inputs:
   // Inputs:
   //   A  n by n adjacency matrix
   //   A  n by n adjacency matrix
@@ -22,23 +24,28 @@ namespace igl
   //   counts  #components list of counts for each component
   //   counts  #components list of counts for each component
   //
   //
   template <typename AScalar, typename DerivedC, typename Derivedcounts>
   template <typename AScalar, typename DerivedC, typename Derivedcounts>
-  IGL_INLINE void components(
+  IGL_INLINE void vertex_components(
     const Eigen::SparseMatrix<AScalar> & A,
     const Eigen::SparseMatrix<AScalar> & A,
     Eigen::PlainObjectBase<DerivedC> & C,
     Eigen::PlainObjectBase<DerivedC> & C,
     Eigen::PlainObjectBase<Derivedcounts> & counts);
     Eigen::PlainObjectBase<Derivedcounts> & counts);
+
   template <typename AScalar, typename DerivedC>
   template <typename AScalar, typename DerivedC>
-  IGL_INLINE void components(
+  IGL_INLINE void vertex_components(
     const Eigen::SparseMatrix<AScalar> & A,
     const Eigen::SparseMatrix<AScalar> & A,
     Eigen::PlainObjectBase<DerivedC> & C);
     Eigen::PlainObjectBase<DerivedC> & C);
-  // Ditto but for mesh faces as input. This computes connected components of
-  // **vertices** where **edges** establish connectivity.
+
+  // Compute the connected components for a mesh given its faces.
+  // Returns a component ID per vertex of the mesh where connectivity is established by edges.
+  //
+  // For computing connected components per face see igl::facet_components
+  //
   //
   //
   // Inputs:
   // Inputs:
   //   F  n by 3 list of triangle indices
   //   F  n by 3 list of triangle indices
   // Outputs:
   // Outputs:
   //   C  max(F) list of component ids
   //   C  max(F) list of component ids
   template <typename DerivedF, typename DerivedC>
   template <typename DerivedF, typename DerivedC>
-  IGL_INLINE void components(
+  IGL_INLINE void vertex_components(
     const Eigen::MatrixBase<DerivedF> & F,
     const Eigen::MatrixBase<DerivedF> & F,
     Eigen::PlainObjectBase<DerivedC> & C);
     Eigen::PlainObjectBase<DerivedC> & C);
 
 

+ 7 - 0
include/igl/facet_components.h

@@ -14,6 +14,8 @@ namespace igl
 {
 {
   // Compute connected components of facets based on edge-edge adjacency.
   // Compute connected components of facets based on edge-edge adjacency.
   //
   //
+  // For connected components on vertices see igl::vertex_components
+  //
   // Inputs:
   // Inputs:
   //   F  #F by 3 list of triangle indices
   //   F  #F by 3 list of triangle indices
   // Outputs:
   // Outputs:
@@ -22,6 +24,11 @@ namespace igl
   IGL_INLINE void facet_components(
   IGL_INLINE void facet_components(
     const Eigen::PlainObjectBase<DerivedF> & F,
     const Eigen::PlainObjectBase<DerivedF> & F,
     Eigen::PlainObjectBase<DerivedC> & C);
     Eigen::PlainObjectBase<DerivedC> & C);
+
+  // Compute connected components of facets based on edge-edge adjacency.
+  //
+  // For connected components on vertices see igl::vertex_components
+  //
   // Inputs:
   // Inputs:
   //   TT  #TT by 3 list of list of adjacency triangles (see
   //   TT  #TT by 3 list of list of adjacency triangles (see
   //   triangle_triangle_adjacency.h)
   //   triangle_triangle_adjacency.h)

+ 2 - 2
include/igl/orientable_patches.cpp

@@ -82,10 +82,10 @@ IGL_INLINE void igl::orientable_patches(
     }
     }
   }
   }
   //% Connected components are patches
   //% Connected components are patches
-  //%C = components(A); % alternative to graphconncomp from matlab_bgl
+  //%C = vertex_components(A); % alternative to graphconncomp from matlab_bgl
   //[~,C] = graphconncomp(A);
   //[~,C] = graphconncomp(A);
   // graph connected components 
   // graph connected components 
-  components(A,C);
+  vertex_components(A,C);
 
 
 }
 }
 
 

+ 1 - 1
include/igl/straighten_seams.cpp

@@ -199,7 +199,7 @@ IGL_INLINE void igl::straighten_seams(
     // Doesn't Compile on older Eigen:
     // Doesn't Compile on older Eigen:
     //SparseMatrix<bool> A = OTVT * (!SV).matrix().asDiagonal() * VTOT;
     //SparseMatrix<bool> A = OTVT * (!SV).matrix().asDiagonal() * VTOT;
     SparseMatrix<bool> A = OTVT * (SV!=true).matrix().asDiagonal() * VTOT;
     SparseMatrix<bool> A = OTVT * (SV!=true).matrix().asDiagonal() * VTOT;
-    components(A,C);
+    vertex_components(A,C);
     nc = C.maxCoeff()+1;
     nc = C.maxCoeff()+1;
   }
   }
   //std::cout<<"nc: "<<nc<<std::endl;
   //std::cout<<"nc: "<<nc<<std::endl;

+ 1 - 1
tutorial/710_SLIM/main.cpp

@@ -255,7 +255,7 @@ void check_mesh_for_issues(Eigen::MatrixXd& V, Eigen::MatrixXi& F) {
   igl::adjacency_matrix(F,A);
   igl::adjacency_matrix(F,A);
 
 
   Eigen::MatrixXi C, Ci;
   Eigen::MatrixXi C, Ci;
-  igl::components(A, C, Ci);
+  igl::vertex_components(A, C, Ci);
 
 
   int connected_components = Ci.rows();
   int connected_components = Ci.rows();
   if (connected_components!=1) {
   if (connected_components!=1) {