[Bf-blender-cvs] [1709bc51643] master: Add performance timing to mesh_boolean.cc.

Howard Trickey noreply at git.blender.org
Fri Nov 27 00:29:26 CET 2020


Commit: 1709bc51643d57278063562389519705f331a2c0
Author: Howard Trickey
Date:   Thu Nov 26 18:29:11 2020 -0500
Branches: master
https://developer.blender.org/rB1709bc51643d57278063562389519705f331a2c0

Add performance timing to mesh_boolean.cc.

You can uncomment the PERFDEBUG define to get timings.

===================================================================

M	source/blender/blenlib/intern/mesh_boolean.cc

===================================================================

diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc
index bac1b0665c8..403fe089ecb 100644
--- a/source/blender/blenlib/intern/mesh_boolean.cc
+++ b/source/blender/blenlib/intern/mesh_boolean.cc
@@ -40,8 +40,11 @@
 #  include "BLI_vector.hh"
 #  include "BLI_vector_set.hh"
 
+#  include "PIL_time.h"
+
 #  include "BLI_mesh_boolean.hh"
 
+// #  define PERFDEBUG
 namespace blender::meshintersect {
 
 /**
@@ -3268,31 +3271,69 @@ IMesh boolean_trimesh(IMesh &tm_in,
   if (tm_in.face_size() == 0) {
     return IMesh(tm_in);
   }
+#  ifdef PERFDEBUG
+  double start_time = PIL_check_seconds_timer();
+  std::cout << "  boolean_trimesh, timing begins\n";
+#  endif
+
   IMesh tm_si = trimesh_nary_intersect(tm_in, nshapes, shape_fn, use_self, arena);
   if (dbg_level > 1) {
     write_obj_mesh(tm_si, "boolean_tm_si");
     std::cout << "\nboolean_tm_input after intersection:\n" << tm_si;
   }
+#  ifdef PERFDEBUG
+  double intersect_time = PIL_check_seconds_timer();
+  std::cout << "  intersected, time = " << intersect_time - start_time << "\n";
+#  endif
+
   /* It is possible for tm_si to be empty if all the input triangles are bogus/degenerate. */
   if (tm_si.face_size() == 0 || op == BoolOpType::None) {
     return tm_si;
   }
   auto si_shape_fn = [shape_fn, tm_si](int t) { return shape_fn(tm_si.face(t)->orig); };
   TriMeshTopology tm_si_topo(tm_si);
+#  ifdef PERFDEBUG
+  double topo_time = PIL_check_seconds_timer();
+  std::cout << "  topology built, time = " << topo_time - intersect_time << "\n";
+#  endif
   PatchesInfo pinfo = find_patches(tm_si, tm_si_topo);
+#  ifdef PERFDEBUG
+  double patch_time = PIL_check_seconds_timer();
+  std::cout << "  patches found, time = " << patch_time - topo_time << "\n";
+#  endif
   IMesh tm_out;
   if (!is_pwn(tm_si, tm_si_topo)) {
+#  ifdef PERFDEBUG
+    double pwn_check_time = PIL_check_seconds_timer();
+    std::cout << "  pwn checked (not pwn), time = " << pwn_check_time - patch_time << "\n";
+#  endif
     if (dbg_level > 0) {
       std::cout << "Input is not PWN, using gwn method\n";
     }
     tm_out = gwn_boolean(tm_si, op, nshapes, shape_fn, pinfo, arena);
+#  ifdef PERFDEBUG
+    double gwn_time = PIL_check_seconds_timer();
+    std::cout << "  gwn, time = " << gwn_time - pwn_check_time << "\n";
+#  endif
   }
   else {
+#  ifdef PERFDEBUG
+    double pwn_time = PIL_check_seconds_timer();
+    std::cout << "  pwn checked (ok), time = " << pwn_time - patch_time << "\n";
+#  endif
     CellsInfo cinfo = find_cells(tm_si, tm_si_topo, pinfo);
     if (dbg_level > 0) {
       std::cout << "Input is PWN\n";
     }
+#  ifdef PERFDEBUG
+    double cell_time = PIL_check_seconds_timer();
+    std::cout << "  cells found, time = " << cell_time - pwn_time << "\n";
+#  endif
     finish_patch_cell_graph(tm_si, cinfo, pinfo, tm_si_topo, arena);
+#  ifdef PERFDEBUG
+    double finish_pc_time = PIL_check_seconds_timer();
+    std::cout << "  finished patch-cell graph, time = " << finish_pc_time - cell_time << "\n";
+#  endif
     bool pc_ok = patch_cell_graph_ok(cinfo, pinfo);
     if (!pc_ok) {
       /* TODO: if bad input can lead to this, diagnose the problem. */
@@ -3301,13 +3342,25 @@ IMesh boolean_trimesh(IMesh &tm_in,
     }
     cinfo.init_windings(nshapes);
     int c_ambient = find_ambient_cell(tm_si, nullptr, tm_si_topo, pinfo, arena);
+#  ifdef PERFDEBUG
+    double amb_time = PIL_check_seconds_timer();
+    std::cout << "  ambient cell found, time = " << amb_time - finish_pc_time << "\n";
+#  endif
     if (c_ambient == NO_INDEX) {
       /* TODO: find a way to propagate this error to user properly. */
       std::cout << "Could not find an ambient cell; input not valid?\n";
       return IMesh(tm_si);
     }
     propagate_windings_and_in_output_volume(pinfo, cinfo, c_ambient, op, nshapes, si_shape_fn);
+#  ifdef PERFDEBUG
+    double propagate_time = PIL_check_seconds_timer();
+    std::cout << "  windings propagated, time = " << propagate_time - amb_time << "\n";
+#  endif
     tm_out = extract_from_in_output_volume_diffs(tm_si, pinfo, cinfo, arena);
+#  ifdef PERFDEBUG
+    double extract_time = PIL_check_seconds_timer();
+    std::cout << "  extracted, time = " << extract_time - propagate_time << "\n";
+#  endif
     if (dbg_level > 0) {
       /* Check if output is PWN. */
       TriMeshTopology tm_out_topo(tm_out);
@@ -3320,6 +3373,10 @@ IMesh boolean_trimesh(IMesh &tm_in,
     write_obj_mesh(tm_out, "boolean_tm_output");
     std::cout << "boolean tm output:\n" << tm_out;
   }
+#  ifdef PERFDEBUG
+  double end_time = PIL_check_seconds_timer();
+  std::cout << "  boolean_trimesh done, total time = " << end_time - start_time << "\n";
+#  endif
   return tm_out;
 }
 
@@ -3365,19 +3422,35 @@ IMesh boolean_mesh(IMesh &imesh,
   }
   IMesh *tm_in = imesh_triangulated;
   IMesh our_triangulation;
+#  ifdef PERFDEBUG
+  double start_time = PIL_check_seconds_timer();
+  std::cout << "boolean_mesh, timing begins\n";
+#  endif
   if (tm_in == nullptr) {
     our_triangulation = triangulate_polymesh(imesh, arena);
     tm_in = &our_triangulation;
   }
+#  ifdef PERFDEBUG
+  double tri_time = PIL_check_seconds_timer();
+  std::cout << "triangulated, time = " << tri_time - start_time << "\n";
+#  endif
   if (dbg_level > 1) {
     write_obj_mesh(*tm_in, "boolean_tm_in");
   }
   IMesh tm_out = boolean_trimesh(*tm_in, op, nshapes, shape_fn, use_self, arena);
+#  ifdef PERFDEBUG
+  double bool_tri_time = PIL_check_seconds_timer();
+  std::cout << "boolean_trimesh done, time = " << bool_tri_time - tri_time << "\n";
+#  endif
   if (dbg_level > 1) {
     std::cout << "bool_trimesh_output:\n" << tm_out;
     write_obj_mesh(tm_out, "bool_trimesh_output");
   }
   IMesh ans = polymesh_from_trimesh_with_dissolve(tm_out, imesh, arena);
+#  ifdef PERFDEBUG
+  double dissolve_time = PIL_check_seconds_timer();
+  std::cout << "polymesh from dissolving, time = " << dissolve_time - bool_tri_time << "\n";
+#  endif
   if (dbg_level > 0) {
     std::cout << "boolean_mesh output:\n" << ans;
     if (dbg_level > 2) {
@@ -3385,6 +3458,10 @@ IMesh boolean_mesh(IMesh &imesh,
       dump_test_spec(ans);
     }
   }
+#  ifdef PERFDEBUG
+  double end_time = PIL_check_seconds_timer();
+  std::cout << "boolean_mesh done, total time = " << end_time - start_time << "\n";
+#  endif
   return ans;
 }



More information about the Bf-blender-cvs mailing list