浏览代码

Output timing.

Former-commit-id: ae9e01560384d0044c8682743acaa32bf1c7e9cb
Qingnan Zhou 9 年之前
父节点
当前提交
4aae2f9ea0

+ 32 - 0
include/igl/copyleft/boolean/mesh_boolean.cpp

@@ -20,6 +20,8 @@
 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
 #include <algorithm>
 #include <algorithm>
 
 
+#define MESH_BOOLEAN_TIMING
+
 template <
 template <
   typename DerivedVA,
   typename DerivedVA,
   typename DerivedFA,
   typename DerivedFA,
@@ -43,6 +45,21 @@ IGL_INLINE void igl::copyleft::boolean::mesh_boolean(
     Eigen::PlainObjectBase<DerivedFC > & FC,
     Eigen::PlainObjectBase<DerivedFC > & FC,
     Eigen::PlainObjectBase<DerivedJ > & J) {
     Eigen::PlainObjectBase<DerivedJ > & J) {
 
 
+#ifdef MESH_BOOLEAN_TIMING
+  const auto & tictoc = []()
+  {
+    static double t_start = igl::get_seconds();
+    double diff = igl::get_seconds()-t_start;
+    t_start += diff;
+    return diff;
+  };
+  const auto log_time = [&](const std::string& label) {
+    std::cout << "mesh_boolean." << label << ": "
+      << tictoc() << std::endl;
+  };
+  tictoc();
+#endif
+
   typedef typename DerivedVC::Scalar Scalar;
   typedef typename DerivedVC::Scalar Scalar;
   //typedef typename DerivedFC::Scalar Index;
   //typedef typename DerivedFC::Scalar Index;
   typedef CGAL::Epeck Kernel;
   typedef CGAL::Epeck Kernel;
@@ -84,6 +101,9 @@ IGL_INLINE void igl::copyleft::boolean::mesh_boolean(
       //}
       //}
       resolve_fun(VV, FF, V, F, CJ);
       resolve_fun(VV, FF, V, F, CJ);
   }
   }
+#ifdef MESH_BOOLEAN_TIMING
+  log_time("resolve_self_intersection");
+#endif
 
 
   // Compute winding numbers on each side of each facet.
   // Compute winding numbers on each side of each facet.
   const size_t num_faces = F.rows();
   const size_t num_faces = F.rows();
@@ -101,6 +121,9 @@ IGL_INLINE void igl::copyleft::boolean::mesh_boolean(
   } else {
   } else {
     assert(W.cols() == 4);
     assert(W.cols() == 4);
   }
   }
+#ifdef MESH_BOOLEAN_TIMING
+  log_time("propergate_input_winding_number");
+#endif
 
 
   // Compute resulting winding number.
   // Compute resulting winding number.
   Eigen::MatrixXi Wr(num_faces, 2);
   Eigen::MatrixXi Wr(num_faces, 2);
@@ -111,6 +134,9 @@ IGL_INLINE void igl::copyleft::boolean::mesh_boolean(
     Wr(i,0) = wind_num_op(w_out);
     Wr(i,0) = wind_num_op(w_out);
     Wr(i,1) = wind_num_op(w_in);
     Wr(i,1) = wind_num_op(w_in);
   }
   }
+#ifdef MESH_BOOLEAN_TIMING
+  log_time("compute_output_winding_number");
+#endif
 
 
   // Extract boundary separating inside from outside.
   // Extract boundary separating inside from outside.
   auto index_to_signed_index = [&](size_t i, bool ori) -> int{
   auto index_to_signed_index = [&](size_t i, bool ori) -> int{
@@ -141,6 +167,9 @@ IGL_INLINE void igl::copyleft::boolean::mesh_boolean(
     }
     }
     kept_face_indices(i, 0) = CJ[idx];
     kept_face_indices(i, 0) = CJ[idx];
   }
   }
+#ifdef MESH_BOOLEAN_TIMING
+  log_time("extract_output");
+#endif
 
 
   // Finally, remove duplicated faces and unreferenced vertices.
   // Finally, remove duplicated faces and unreferenced vertices.
   {
   {
@@ -160,6 +189,9 @@ IGL_INLINE void igl::copyleft::boolean::mesh_boolean(
     Eigen::VectorXi newIM;
     Eigen::VectorXi newIM;
     igl::remove_unreferenced(Vs,G,VC,FC,newIM);
     igl::remove_unreferenced(Vs,G,VC,FC,newIM);
   }
   }
+#ifdef MESH_BOOLEAN_TIMING
+  log_time("clean_up");
+#endif
 }
 }
 
 
 template <
 template <

+ 10 - 6
include/igl/copyleft/cgal/SelfIntersectMesh.h

@@ -16,7 +16,7 @@
 #include <map>
 #include <map>
 #include <vector>
 #include <vector>
 
 
-//#define IGL_SELFINTERSECTMESH_DEBUG
+#define IGL_SELFINTERSECTMESH_DEBUG
 #ifndef IGL_FIRST_HIT_EXCEPTION
 #ifndef IGL_FIRST_HIT_EXCEPTION
 #define IGL_FIRST_HIT_EXCEPTION 10
 #define IGL_FIRST_HIT_EXCEPTION 10
 #endif
 #endif
@@ -337,13 +337,17 @@ inline igl::copyleft::cgal::SelfIntersectMesh<
     t_start += diff;
     t_start += diff;
     return diff;
     return diff;
   };
   };
+  const auto log_time = [&](const std::string& label) {
+    std::cout << "SelfIntersectMesh." << label << ": "
+      << tictoc() << std::endl;
+  };
   tictoc();
   tictoc();
 #endif
 #endif
 
 
   // Compute and process self intersections
   // Compute and process self intersections
   mesh_to_cgal_triangle_list(V,F,T);
   mesh_to_cgal_triangle_list(V,F,T);
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
-  cout<<"mesh_to_cgal_triangle_list: "<<tictoc()<<endl;
+  log_time("convert_to_triangle_list");
 #endif
 #endif
   // http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Box_intersection_d/Chapter_main.html#Section_63.5 
   // http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Box_intersection_d/Chapter_main.html#Section_63.5 
   // Create the corresponding vector of bounding boxes
   // Create the corresponding vector of bounding boxes
@@ -367,7 +371,7 @@ inline igl::copyleft::cgal::SelfIntersectMesh<
       std::placeholders::_1,
       std::placeholders::_1,
       std::placeholders::_2);
       std::placeholders::_2);
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
-  cout<<"boxes and bind: "<<tictoc()<<endl;
+  log_time("box_and_bind");
 #endif
 #endif
   // Run the self intersection algorithm with all defaults
   // Run the self intersection algorithm with all defaults
   try{
   try{
@@ -382,7 +386,7 @@ inline igl::copyleft::cgal::SelfIntersectMesh<
     // Otherwise just fall through
     // Otherwise just fall through
   }
   }
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
-  cout<<"box_self_intersection_d: "<<tictoc()<<endl;
+  log_time("box_intersection_d");
 #endif
 #endif
 
 
   // Convert lIF to Eigen matrix
   // Convert lIF to Eigen matrix
@@ -403,7 +407,7 @@ inline igl::copyleft::cgal::SelfIntersectMesh<
     }
     }
   }
   }
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
-  cout<<"IF: "<<tictoc()<<endl;
+  log_time("store_intersecting_face_pairs");
 #endif
 #endif
 
 
   if(params.detect_only)
   if(params.detect_only)
@@ -414,7 +418,7 @@ inline igl::copyleft::cgal::SelfIntersectMesh<
   remesh_intersections(V,F,T,offending,edge2faces,VV,FF,J,IM);
   remesh_intersections(V,F,T,offending,edge2faces,VV,FF,J,IM);
 
 
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
 #ifdef IGL_SELFINTERSECTMESH_DEBUG
-  cout<<"remesh intersection: "<<tictoc()<<endl;
+  log_time("remesh_intersection");
 #endif
 #endif
 
 
   // Q: Does this give the same result as TETGEN?
   // Q: Does this give the same result as TETGEN?

+ 11 - 7
include/igl/copyleft/cgal/extract_cells.cpp

@@ -19,7 +19,7 @@
 #include <vector>
 #include <vector>
 #include <queue>
 #include <queue>
 
 
-//#define EXTRACT_CELLS_DEBUG
+#define EXTRACT_CELLS_DEBUG
 
 
 template<
 template<
 typename DerivedV,
 typename DerivedV,
@@ -184,6 +184,10 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
     t_start += diff;
     t_start += diff;
     return diff;
     return diff;
   };
   };
+  const auto log_time = [&](const std::string& label) {
+    std::cout << "extract_cells." << label << ": "
+      << tictoc() << std::endl;
+  };
   tictoc();
   tictoc();
 #endif
 #endif
     const size_t num_faces = F.rows();
     const size_t num_faces = F.rows();
@@ -195,19 +199,19 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
         igl::copyleft::cgal::extract_cells_single_component(
         igl::copyleft::cgal::extract_cells_single_component(
                 V, F, P, uE, uE2E, EMAP, raw_cells);
                 V, F, P, uE, uE2E, EMAP, raw_cells);
 #ifdef EXTRACT_CELLS_DEBUG
 #ifdef EXTRACT_CELLS_DEBUG
-    std::cout << "Extract single component cells: " << tictoc() << std::endl;
+    log_time("extract_single_component_cells");
 #endif
 #endif
 
 
     std::vector<std::vector<std::vector<Index > > > TT,_1;
     std::vector<std::vector<std::vector<Index > > > TT,_1;
     igl::triangle_triangle_adjacency(E, EMAP, uE2E, false, TT, _1);
     igl::triangle_triangle_adjacency(E, EMAP, uE2E, false, TT, _1);
 #ifdef EXTRACT_CELLS_DEBUG
 #ifdef EXTRACT_CELLS_DEBUG
-    std::cout << "face adj: " << tictoc() << std::endl;
+    log_time("compute_face_adjacency");
 #endif
 #endif
 
 
     Eigen::VectorXi C, counts;
     Eigen::VectorXi C, counts;
     igl::facet_components(TT, C, counts);
     igl::facet_components(TT, C, counts);
 #ifdef EXTRACT_CELLS_DEBUG
 #ifdef EXTRACT_CELLS_DEBUG
-    std::cout << "face comp: " << tictoc() << std::endl;
+    log_time("form_components");
 #endif
 #endif
 
 
     const size_t num_components = counts.size();
     const size_t num_components = counts.size();
@@ -232,7 +236,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
         outer_cells[i] = raw_cells(P[outer_facets[i]], outer_facet_orientation[i]);
         outer_cells[i] = raw_cells(P[outer_facets[i]], outer_facet_orientation[i]);
     }
     }
 #ifdef EXTRACT_CELLS_DEBUG
 #ifdef EXTRACT_CELLS_DEBUG
-    std::cout << "Per comp outer facet: " << tictoc() << std::endl;
+    log_time("outer_facet_per_component");
 #endif
 #endif
 
 
     auto get_triangle_center = [&](const size_t fid) {
     auto get_triangle_center = [&](const size_t fid) {
@@ -307,7 +311,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
         }
         }
     }
     }
 #ifdef EXTRACT_CELLS_DEBUG
 #ifdef EXTRACT_CELLS_DEBUG
-    std::cout << "Determine nested relaitonship: " << tictoc() << std::endl;
+    log_time("nested_relationship");
 #endif
 #endif
 
 
     const size_t INVALID = std::numeric_limits<size_t>::max();
     const size_t INVALID = std::numeric_limits<size_t>::max();
@@ -371,7 +375,7 @@ IGL_INLINE size_t igl::copyleft::cgal::extract_cells(
     }
     }
     cells = raw_cells;
     cells = raw_cells;
 #ifdef EXTRACT_CELLS_DEBUG
 #ifdef EXTRACT_CELLS_DEBUG
-    std::cout << "Finalize and output: " << tictoc() << std::endl;
+    log_time("finalize");
 #endif
 #endif
     return count;
     return count;
 }
 }

+ 13 - 9
include/igl/copyleft/cgal/propagate_winding_numbers.cpp

@@ -26,7 +26,7 @@
 #include <tuple>
 #include <tuple>
 #include <queue>
 #include <queue>
 
 
-//#define PROPAGATE_WINDING_NUMBER_TIMING
+#define PROPAGATE_WINDING_NUMBER_TIMING
 
 
 namespace propagate_winding_numbers_helper {
 namespace propagate_winding_numbers_helper {
   template<
   template<
@@ -87,6 +87,10 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
     t_start += diff;
     t_start += diff;
     return diff;
     return diff;
   };
   };
+  const auto log_time = [&](const std::string& label) {
+    std::cout << "propagate_winding_num." << label << ": "
+      << tictoc() << std::endl;
+  };
   tictoc();
   tictoc();
 #endif
 #endif
   const size_t num_faces = F.rows();
   const size_t num_faces = F.rows();
@@ -97,13 +101,13 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
   std::vector<std::vector<size_t> > uE2E;
   std::vector<std::vector<size_t> > uE2E;
   igl::unique_edge_map(F, E, uE, EMAP, uE2E);
   igl::unique_edge_map(F, E, uE, EMAP, uE2E);
   if (!propagate_winding_numbers_helper::is_orientable(F, uE, uE2E)) {
   if (!propagate_winding_numbers_helper::is_orientable(F, uE, uE2E)) {
-      std::cerr << "Input mesh is not orientable!" << std::endl;
+    std::cerr << "Input mesh is not orientable!" << std::endl;
   }
   }
 
 
   Eigen::VectorXi P;
   Eigen::VectorXi P;
   const size_t num_patches = igl::extract_manifold_patches(F, EMAP, uE2E, P);
   const size_t num_patches = igl::extract_manifold_patches(F, EMAP, uE2E, P);
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-  std::cout << "extract manifold patches: " << tictoc() << std::endl;
+  log_time("patch_extraction");
 #endif
 #endif
 
 
   DerivedW per_patch_cells;
   DerivedW per_patch_cells;
@@ -111,7 +115,7 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
     igl::copyleft::cgal::extract_cells(
     igl::copyleft::cgal::extract_cells(
         V, F, P, E, uE, uE2E, EMAP, per_patch_cells);
         V, F, P, E, uE, uE2E, EMAP, per_patch_cells);
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-  std::cout << "extract cells: " << tictoc() << std::endl;;
+  log_time("cell_extraction");
 #endif
 #endif
 
 
   typedef std::tuple<size_t, bool, size_t> CellConnection;
   typedef std::tuple<size_t, bool, size_t> CellConnection;
@@ -123,7 +127,7 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
     cell_adjacency[negative_cell].emplace(positive_cell, true, i);
     cell_adjacency[negative_cell].emplace(positive_cell, true, i);
   }
   }
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-  std::cout << "cell connection: " << tictoc() << std::endl;
+  log_time("cell_connectivity");
 #endif
 #endif
 
 
   auto save_cell = [&](const std::string& filename, size_t cell_id) {
   auto save_cell = [&](const std::string& filename, size_t cell_id) {
@@ -208,7 +212,7 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
       }
       }
     }
     }
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-    std::cout << "check for odd cycle: " << tictoc() << std::endl;
+    log_time("odd_cycle_check");
 #endif
 #endif
   }
   }
 #endif
 #endif
@@ -219,7 +223,7 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
   I.setLinSpaced(num_faces, 0, num_faces-1);
   I.setLinSpaced(num_faces, 0, num_faces-1);
   igl::copyleft::cgal::outer_facet(V, F, I, outer_facet, flipped);
   igl::copyleft::cgal::outer_facet(V, F, I, outer_facet, flipped);
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-  std::cout << "outer facet: " << tictoc() << std::endl;
+  log_time("outer_facet");
 #endif
 #endif
 
 
   const size_t outer_patch = P[outer_facet];
   const size_t outer_patch = P[outer_facet];
@@ -283,7 +287,7 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
     }
     }
   }
   }
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-  std::cout << "propagate winding number: " << tictoc() << std::endl;
+  log_time("propagate_winding_number");
 #endif
 #endif
 
 
   W.resize(num_faces, num_labels*2);
   W.resize(num_faces, num_labels*2);
@@ -297,7 +301,7 @@ IGL_INLINE void igl::copyleft::cgal::propagate_winding_numbers(
     }
     }
   }
   }
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
 #ifdef PROPAGATE_WINDING_NUMBER_TIMING
-  std::cout << "save result: " << tictoc() << std::endl;
+  log_time("store_result");
 #endif
 #endif
 }
 }