[Bf-blender-cvs] [07aa2779734] soc-2021-porting-modifiers-to-nodes-merge-by-distance: working stage

Fabian Schempp noreply at git.blender.org
Sat Oct 2 00:17:39 CEST 2021


Commit: 07aa2779734aab72a7952906673c4884bd298d28
Author: Fabian Schempp
Date:   Fri Oct 1 21:44:44 2021 +0200
Branches: soc-2021-porting-modifiers-to-nodes-merge-by-distance
https://developer.blender.org/rB07aa2779734aab72a7952906673c4884bd298d28

working stage

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

M	source/blender/geometry/intern/pointcloud_merge_by_distance.cc

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

diff --git a/source/blender/geometry/intern/pointcloud_merge_by_distance.cc b/source/blender/geometry/intern/pointcloud_merge_by_distance.cc
index 377d43c3898..be9cb9bf9ee 100644
--- a/source/blender/geometry/intern/pointcloud_merge_by_distance.cc
+++ b/source/blender/geometry/intern/pointcloud_merge_by_distance.cc
@@ -16,6 +16,7 @@
 
 #include "BKE_geometry_set.hh"
 #include "BKE_pointcloud.h"
+#include <BKE_attribute_math.hh>
 
 #include "BLI_array.hh"
 #include "BLI_float3.hh"
@@ -50,7 +51,7 @@ static KDTree_3d *build_kdtree(Span<float3> positions, Span<bool> selection)
 }
 
 static void build_merge_map(Span<float3> positions,
-                            MutableSpan<bool> merge_map,
+                            MutableSpan<int> merge_map,
                             const float merge_threshold,
                             Span<bool> selection)
 {
@@ -59,7 +60,7 @@ static void build_merge_map(Span<float3> positions,
   for (int i : positions.index_range()) {
     struct CallbackData {
       int index;
-      MutableSpan<bool> merge_map;
+      MutableSpan<int> merge_map;
       Span<bool> selection;
     } callback_data = {i, merge_map, selection};
 
@@ -74,11 +75,11 @@ static void build_merge_map(Span<float3> positions,
           CallbackData &callback_data = *static_cast<CallbackData *>(user_data);
           int target_point_index = callback_data.index;
           if (source_point_index != target_point_index &&
-              !callback_data.merge_map[source_point_index] &&
-              !callback_data.merge_map[target_point_index] &&
+              callback_data.merge_map[source_point_index] == -1 &&
+              callback_data.merge_map[target_point_index] == -1 &&
               callback_data.selection[source_point_index] &&
               callback_data.selection[target_point_index]) {
-            callback_data.merge_map[source_point_index] = true;
+            callback_data.merge_map[source_point_index] = target_point_index;
           }
           return true;
         },
@@ -93,14 +94,14 @@ PointCloud *pointcloud_merge_by_distance(PointCloudComponent &pointcloud_compone
                                          Span<bool> selection)
 {
   const PointCloud &src_pointcloud = *pointcloud_component.get_for_read();
-  Array<bool> merge_map(src_pointcloud.totpoint, false);
+  Array<int> merge_map(src_pointcloud.totpoint, -1);
   Span<float3> positions((const float3 *)src_pointcloud.co, src_pointcloud.totpoint);
 
   build_merge_map(positions, merge_map, merge_threshold, selection);
 
   Vector<int64_t> copy_mask_vector;
   for (const int i : positions.index_range()) {
-    if (!merge_map[i]) {
+    if (merge_map[i] == -1) {
       copy_mask_vector.append(i);
     }
   }
@@ -126,14 +127,33 @@ PointCloud *pointcloud_merge_by_distance(PointCloudComponent &pointcloud_compone
           bke::OutputAttribute target_attribute = dst_component.attribute_try_get_for_output_only(
               attribute_id, meta_data.domain, meta_data.data_type);
 
-          fn::GMutableSpan dst_span = target_attribute.as_span();
-          fn::GSpan src_span = read_attribute->get_internal_span();
-          for (const int i : copy_mask.index_range()) {
-            const fn::CPPType *type = bke::custom_data_type_to_cpp_type(meta_data.data_type);
-            type->copy_assign(src_span[copy_mask[i]], dst_span[i]);
-          }
+          blender::attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) {
+            using T = decltype(dummy);
+            // fn::GVMutableArray_Typed<T> dst_span = target_attribute->typed<T>();
+            // const fn::GVArray_Typed<T> src_span = read_attribute->typed<T>();
+            // target_attribute.template as_span<>()
+            // dst_span->materialize_to_uninitialized(buffer);
+            attribute_math::DefaultMixer<T> mixer(target_attribute.as_span<T>());
+
+            // for (const int j : merge_map.index_range()) {
+            //   if (merge_map[j] == src_index) {
+            //     mixer.mix_in(src_span[j], 0.1f);
+            //    }
+            // }
+            mixer.finalize();
+          });
 
           target_attribute.save();
+
+          //          fn::GMutableSpan dst_span = target_attribute.as_span();
+          //          const fn::GSpan src_span = read_attribute->get_internal_span();
+          //          for (const int i : copy_mask.index_range()) {
+          //            const int src_index = copy_mask[i];
+          //            const fn::CPPType *type =
+          //            bke::custom_data_type_to_cpp_type(meta_data.data_type);
+          //            type->copy_assign(src_span[src_index], dst_span[i]);
+          //            target_attribute.save();
+          //          }
         }
         return true;
       });



More information about the Bf-blender-cvs mailing list