[Bf-blender-cvs] [ae63b010161] temp-T97352-3d-texturing-seam-bleeding-b2: Removed debug code as it slowed down the algorithm.

Jeroen Bakker noreply at git.blender.org
Mon Jun 20 08:35:08 CEST 2022


Commit: ae63b0101616139c6f42f101e6f9c0733600e6ae
Author: Jeroen Bakker
Date:   Mon Jun 20 08:23:49 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rBae63b0101616139c6f42f101e6f9c0733600e6ae

Removed debug code as it slowed down the algorithm.

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

M	source/blender/blenkernel/BKE_uv_islands.hh
M	source/blender/blenkernel/intern/pbvh_pixels.cc
M	source/blender/blenkernel/intern/uv_islands.cc

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

diff --git a/source/blender/blenkernel/BKE_uv_islands.hh b/source/blender/blenkernel/BKE_uv_islands.hh
index 2530dfa4d3b..4e1d5965876 100644
--- a/source/blender/blenkernel/BKE_uv_islands.hh
+++ b/source/blender/blenkernel/BKE_uv_islands.hh
@@ -25,7 +25,8 @@ namespace blender::bke::uv_islands {
  * When enabled various parts of the code would generate an SVG file to visual see how the
  * algorithm makes decisions.
  */
-#define DEBUG_SVG
+//#define DEBUG_SVG
+// #define VALIDATE
 
 struct UVIslands;
 struct UVIslandsMask;
@@ -137,6 +138,7 @@ struct MeshData {
     init_primitives();
     init_edges();
 
+#ifdef VALIDATE
     for (const MeshVertex &v : vertices) {
       printf("Vert {v%lld}\n", v.v);
       for (const MeshEdge *e : v.edges) {
@@ -150,6 +152,7 @@ struct MeshData {
         }
       }
     }
+#endif
   }
   void init_vertices()
   {
@@ -541,7 +544,9 @@ struct UVBorder {
 
   static std::optional<UVBorder> extract_from_edges(Vector<UVBorderEdge> &edges);
 
+#ifdef VALIDATE
   void validate() const;
+#endif
 
   /** Remove edge from the border. updates the indexes. */
   void remove(int64_t index)
@@ -620,9 +625,7 @@ struct UVIsland {
   /** Initialize the border attribute. */
   void extract_borders();
   /** Iterative extend border to fit the mask. */
-  void extend_border(const UVIslandsMask &mask,
-                     const short island_index,
-                     const MeshData &mesh_data);
+  void extend_border(const UVIslandsMask &mask, const short island_index);
 
  private:
   void append(const UVPrimitive &primitive)
@@ -683,6 +686,7 @@ struct UVIsland {
     }
   }
 
+#ifdef VALIDATE
   void validate_primitives() const
   {
     /* Each UVPrimitive that points to the same mesh primitive should contain the same mesh
@@ -727,6 +731,7 @@ struct UVIsland {
       border.validate();
     }
   }
+#endif
 };
 
 /* Debug functions to export to a SVG file. */
@@ -787,15 +792,19 @@ struct UVIslands {
 #endif
   }
 
-  void extend_borders(const UVIslandsMask &islands_mask, const MeshData &mesh_data)
+  void extend_borders(const UVIslandsMask &islands_mask)
   {
+#ifdef VALIDATE
     printf("Extending borders\n");
     printf("=================\n");
+#endif
     ushort index = 0;
     for (UVIsland &island : islands) {
+#ifdef VALIDATE
       printf("Island %d\n", index);
       printf("---------\n");
-      island.extend_border(islands_mask, index++, mesh_data);
+#endif
+      island.extend_border(islands_mask, index++);
     }
 
 #ifdef DEBUG_SVG
@@ -852,6 +861,7 @@ struct UVIslands {
     return &islands.last();
   }
 
+#ifdef VALIDATE
   bool validate() const
   {
     /* After operations it is not allowed that islands share any edges. In that case it should
@@ -867,6 +877,7 @@ struct UVIslands {
     }
     return true;
   }
+#endif
 };
 
 /* Bitmask containing the num of the nearest Island. */
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index f613f962522..a13e87544e6 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -337,13 +337,15 @@ static void update_pixels(PBVH *pbvh, Mesh *mesh, Image *image, ImageUser *image
       pbvh->looptri, pbvh->totprim, pbvh->totvert, pbvh->mloop, ldata_uv);
   uv_islands::UVIslands islands(mesh_data);
 
-  // TODO: Currenly uv_masks only supports a single udim tile. We should create one for each tile.
+  // TODO: Currently uv_masks only supports a single udim tile. We should create one for each tile.
+  // TODO: mask resolution should be based on the actual resolution of the image buffer (or a
+  // factor of it).
   uv_islands::UVIslandsMask uv_masks(float2(0.0, 0.0), ushort2(256, 256));
   uv_masks.add(islands);
   uv_masks.dilate(image->seamfix_iter);
 
   islands.extract_borders();
-  islands.extend_borders(uv_masks, mesh_data);
+  islands.extend_borders(uv_masks);
   update_geom_primitives(*pbvh, mesh_data);
 
   EncodePixelsUserData user_data;
diff --git a/source/blender/blenkernel/intern/uv_islands.cc b/source/blender/blenkernel/intern/uv_islands.cc
index 18419e0e57e..731ad75c713 100644
--- a/source/blender/blenkernel/intern/uv_islands.cc
+++ b/source/blender/blenkernel/intern/uv_islands.cc
@@ -145,7 +145,9 @@ struct Fan {
         }
       }
       if (stop == false) {
+#ifdef VALIDATE
         printf("unknown how to create the fan for vert %lld\n", vertex.v);
+#endif
         flags.full = false;
         break;
       }
@@ -212,6 +214,7 @@ struct Fan {
   }
 };
 
+#ifdef VALIDATE
 static void print(const Fan &fan)
 {
   for (const InnerEdge &fan_edge : fan.inner_edges) {
@@ -225,6 +228,7 @@ static void print(const Fan &fan)
     printf(" %d\n", fan_edge.flags.found);
   }
 }
+#endif
 
 static void add_uv_primitive_shared_uv_edge(UVIsland &island,
                                             UVVertex *connected_vert_1,
@@ -264,28 +268,38 @@ static void add_uv_primitive_shared_uv_edge(UVIsland &island,
   prim1.append_to_uv_edges();
   prim1.append_to_uv_vertices();
   island.uv_primitives.append(prim1);
+#ifdef VALIDATE
   island.validate_primitive(island.uv_primitives.last());
+#endif
 }
 
 static MeshPrimitive *find_fill_border(const MeshVertex &v1,
                                        const MeshVertex &v2,
                                        const MeshVertex &v3)
 {
+#ifdef VALIDATE
   printf("find primitive containing (%lld,%lld,%lld)\n", v1.v, v2.v, v3.v);
+#endif
   for (MeshEdge *edge : v1.edges) {
     for (MeshPrimitive *primitive : edge->primitives) {
+#ifdef VALIDATE
       printf("- try primitive %lld containing (%lld,%lld,%lld)\n",
              primitive->index,
              primitive->vertices[0].vertex->v,
              primitive->vertices[1].vertex->v,
              primitive->vertices[2].vertex->v);
+#endif
       if (primitive->has_vertex(v1) && primitive->has_vertex(v2) && primitive->has_vertex(v3)) {
+#ifdef VALIDATE
         printf("- found primitive\n");
+#endif
         return primitive;
       }
     }
   }
+#ifdef VALIDATE
   printf("- No primitive found\n");
+#endif
   return nullptr;
 }
 /**
@@ -334,10 +348,9 @@ static void add_uv_primitive_fill(UVIsland &island,
   uv_primitive.append_to_uv_edges();
   uv_primitive.append_to_uv_vertices();
   island.uv_primitives.append(uv_primitive);
-  // island.validate_primitive(island.uv_primitives.last());
 }
 
-static void extend_at_vert(UVIsland &island, UVBorderCorner &corner, const MeshData &mesh_data)
+static void extend_at_vert(UVIsland &island, UVBorderCorner &corner)
 {
   int border_index = corner.first->border_index;
   UVBorder &border = island.borders[border_index];
@@ -350,13 +363,14 @@ static void extend_at_vert(UVIsland &island, UVBorderCorner &corner, const MeshD
   }
   fan.init_uv_coordinates(*uv_vertex, island);
   fan.mark_already_added_segments(*uv_vertex);
+#ifdef VALIDATE
   print(fan);
+#endif
 
   // tag them as being 'not fixed in uv space'. count them and determine a position in uv space.
   // add UV primitives for them.
   // recalc the border.
   int num_to_add = fan.count_num_to_add();
-  printf("Found %d new edges to add\n", num_to_add);
 
   if (num_to_add == 0) {
     MeshPrimitive *fill_primitive_1 = corner.second->uv_primitive->primitive;
@@ -372,13 +386,11 @@ static void extend_at_vert(UVIsland &island, UVBorderCorner &corner, const MeshD
     }
 
     float2 center_uv = corner.uv(0.5f);
-    printf(" - add new projection for {%lld}\n", fill_primitive_1->index);
     add_uv_primitive_shared_uv_edge(island,
                                     corner.first->get_uv_vertex(1),
                                     corner.first->get_uv_vertex(0),
                                     center_uv,
                                     fill_primitive_1);
-    printf(" - add new projection for {%lld}\n", fill_primitive_2->index);
     add_uv_primitive_shared_uv_edge(island,
                                     corner.second->get_uv_vertex(0),
                                     corner.second->get_uv_vertex(1),
@@ -508,9 +520,7 @@ static void extend_at_vert(UVIsland &island, UVBorderCorner &corner, const MeshD
   border.update_extendability();
 }
 
-void UVIsland::extend_border(const UVIslandsMask &mask,
-                             const short island_index,
-                             const MeshData &mesh_data)
+void UVIsland::extend_border(const UVIslandsMask &mask, const short island_index)
 {
   // Find sharpest corner that still inside the island mask and can be extended.
   // exit when no corner could be found.
@@ -534,12 +544,9 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
   // cases have been implemented.
   int num_iterations = 99999;
   while (num_iterations) {
-    printf("**iterations left %d**\n", num_iterations);
-    if (step == 366) {
-      printf("Debug iteration\n");
-      // break;
-    }
+#ifdef VALIDATE
     validate_border();
+#endif
     std::optional<UVBorderCorner> extension_corner = sharpest_border_corner(*this);
     if (!extension_corner.has_value()) {
       break;
@@ -551,9 +558,10 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
       continue;
     }
 
-    // TODO: extend
-    extend_at_vert(*this, *extension_corner, mesh_data);
+    extend_at_vert(*this, *extension_corner);
+#ifdef VALIDATE
     validate_border();
+#endif
 
     /* Mark that the vert is extended. Unable to extend twice. */
     extension_corner->second->flags.extendable = false;
@@ -671,7 +679,7 @@ void UVBorder::update_extendability()
     }
   }
 }
-
+#ifdef VALIDATE
 void UVBorder::validate() const
 {
   for (const UVBorderEdge &edge : edges) {
@@ -687,6 +695,7 @@ void UVBorder::validate() const
     BLI_assert(edge.get_uv_vertex(1)->uv == edges[edge.next_index].get_uv_vertex(0)->uv);
   }
 }
+#endif
 
 /** \} */
 
@@ -832,7 +841,7 @@ void svg_footer(std::ostream &ss)
 {
   ss << "</svg>\n";
 }
-void svg(std::ostream &ss, const UVEdge &edge)
+static void svg(std::ostream &ss, const UVEdge &edge)
 {
   ss << "       <line x1=\"" << svg_x(*edge.vertices[0]) << "\" y1=\"" << svg_y(*edge.vertices[0])
      << "\" x2=\"" << svg_x(*edge.vertices[1]) << "\" y2=\"" << svg_y(*edge.vertices[1])
@@ -975,7 +984,7 @@ void svg(std::

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list