[Bf-blender-cvs] [4e154c59a2b] soc-2021-adaptive-cloth: modifier: adaptive_remesh: dump file pre and post edge operation

ishbosamiya noreply at git.blender.org
Wed Aug 4 11:29:32 CEST 2021


Commit: 4e154c59a2b3fdd6279f6e3fce1540de3eff61f1
Author: ishbosamiya
Date:   Sun Aug 1 11:35:34 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB4e154c59a2b3fdd6279f6e3fce1540de3eff61f1

modifier: adaptive_remesh: dump file pre and post edge operation

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

M	source/blender/blenkernel/BKE_cloth_remesh.hh
M	source/blender/blenkernel/intern/cloth_remesh.cc
M	source/blender/modifiers/intern/MOD_adaptive_remesh.cc

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

diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index d8e693f7c8e..44530f9b0f0 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -176,6 +176,53 @@ using EdgeVerts = std::tuple<VertIndex, VertIndex>;
 
 using usize = uint64_t;
 
+class FilenameGen {
+  usize number;
+  std::string prefix;
+  std::string suffix;
+
+ public:
+  FilenameGen(const std::string prefix, const std::string suffix)
+      : number(0), prefix(prefix), suffix(suffix)
+  {
+  }
+
+  std::string gen_next()
+  {
+    this->number += 1;
+    return this->get_curr();
+  }
+
+  std::string gen_next(const std::string pre_suffix)
+  {
+    this->number += 1;
+    return this->get_curr(pre_suffix);
+  }
+
+  std::string get_curr()
+  {
+    return this->prefix + "_" + std::to_string(this->number) + this->suffix;
+  }
+
+  std::string get_curr(const std::string pre_suffix)
+  {
+    return this->prefix + "_" + std::to_string(this->number) + "_" + pre_suffix + this->suffix;
+  }
+};
+
+inline void dump_file(const fs::path &filepath, const std::string &info)
+{
+  std::fstream fout;
+  fout.open(filepath, std::ios::out);
+  if (fout.is_open()) {
+    fout << info;
+    fout.close();
+  }
+  else {
+    std::cerr << "Couldn't open file " << filepath.c_str() << std::endl;
+  }
+}
+
 inline void copy_v2_float2(float *res, const float2 &v2)
 {
   res[0] = v2[0];
diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index 2eac85428e2..c643f07b387 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -716,13 +716,7 @@ Mesh *adaptive_remesh(const AdaptiveRemeshParams<END, ExtraData> &params,
   adaptive_mesh.read(meshio_input);
   {
     const auto serialized = adaptive_mesh.serialize();
-    const auto *filepath = "/tmp/test.msgpack";
-    std::fstream fout;
-    fout.open(filepath, std::ios::out);
-    if (fout.is_open()) {
-      fout << serialized;
-      fout.close();
-    }
+    internal::dump_file("/tmp/test.mesh", serialized);
   }
 
   /* Load up the `NodeData`'s extra_data */
diff --git a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
index d47720d8814..4266b349104 100644
--- a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
+++ b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
@@ -41,6 +41,10 @@
 
 using namespace blender::bke;
 
+static internal::FilenameGen split_edge_name_gen("/tmp/adaptive_cloth/split_edge", ".mesh");
+static internal::FilenameGen collapse_edge_name_gen("/tmp/adaptive_cloth/collapse_edge", ".mesh");
+static internal::FilenameGen flip_edge_name_gen("/tmp/adaptive_cloth/flip_edge", ".mesh");
+
 static void initData(ModifierData *md)
 {
   AdaptiveRemeshModifierData *armd = reinterpret_cast<AdaptiveRemeshModifierData *>(md);
@@ -88,14 +92,46 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
     auto flippable = internal_mesh.is_edge_flippable(edge_index, across_seams);
     std::cout << "flippable: " << flippable << std::endl;
     if (mode == ADAPTIVE_REMESH_SPLIT_EDGE) {
+      auto pre_split_msgpack = internal_mesh.serialize();
+      auto pre_split_filename = split_edge_name_gen.get_curr(std::to_string(edge_i) + "_pre");
+
       internal_mesh.split_edge_triangulate(edge_index, across_seams);
+
+      auto post_split_msgpack = internal_mesh.serialize();
+      auto post_split_filename = split_edge_name_gen.get_curr(std::to_string(edge_i) + "_post");
+      /* split_edge_name_gen.gen_next(); */
+
+      internal::dump_file(pre_split_filename, pre_split_msgpack);
+      internal::dump_file(post_split_filename, post_split_msgpack);
     }
     else if (mode == ADAPTIVE_REMESH_COLLAPSE_EDGE) {
+      auto pre_collapse_msgpack = internal_mesh.serialize();
+      auto pre_collapse_filename = collapse_edge_name_gen.get_curr(std::to_string(edge_i) +
+                                                                   "_pre");
+
       internal_mesh.collapse_edge_triangulate(edge_index, verts_swapped, across_seams);
+
+      auto post_collapse_msgpack = internal_mesh.serialize();
+      auto post_collapse_filename = collapse_edge_name_gen.get_curr(std::to_string(edge_i) +
+                                                                    "_post");
+      /* collapse_edge_name_gen.gen_next(); */
+
+      internal::dump_file(pre_collapse_filename, pre_collapse_msgpack);
+      internal::dump_file(post_collapse_filename, post_collapse_msgpack);
     }
     else if (mode == ADAPTIVE_REMESH_FLIP_EDGE) {
       if (flippable) {
+        auto pre_flip_msgpack = internal_mesh.serialize();
+        auto pre_flip_filename = flip_edge_name_gen.get_curr(std::to_string(edge_i) + "_pre");
+
         internal_mesh.flip_edge_triangulate(edge_index, across_seams);
+
+        auto post_flip_msgpack = internal_mesh.serialize();
+        auto post_flip_filename = flip_edge_name_gen.get_curr(std::to_string(edge_i) + "_post");
+        /* flip_edge_name_gen.gen_next(); */
+
+        internal::dump_file(pre_flip_filename, pre_flip_msgpack);
+        internal::dump_file(post_flip_filename, post_flip_msgpack);
       }
     }
   }



More information about the Bf-blender-cvs mailing list