[Bf-blender-cvs] [2f9dbdb8c68] temp-geometry-nodes-distribute-points-cleanup: Using cyHeap for own solution
Dalai Felinto
noreply at git.blender.org
Fri Dec 11 12:45:22 CET 2020
Commit: 2f9dbdb8c688da701ba321343d8ee90d16df49ae
Author: Dalai Felinto
Date: Fri Dec 11 12:41:45 2020 +0100
Branches: temp-geometry-nodes-distribute-points-cleanup
https://developer.blender.org/rB2f9dbdb8c688da701ba321343d8ee90d16df49ae
Using cyHeap for own solution
This is a temporary solution to isolate the difference between
cyHeap and BLI_heap
===================================================================
M source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc
===================================================================
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc
index 1c48ec60984..3e4a8a751f1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc
@@ -21,10 +21,16 @@
* Copyright (c) 2016, Cem Yuksel <cem at cemyuksel.com>
* All rights reserved.
*/
+#define CYHEAP 1
-#include "BLI_heap.h"
#include "BLI_kdtree.h"
+#ifndef CYHEAP
+# include "BLI_heap.h"
+#else
+# include "cyHeap.h"
+#endif
+
#include "node_geometry_util.hh"
#include <iostream>
@@ -90,8 +96,13 @@ static void points_distance_weight_calculate(std::vector<float> *weights,
const void *kd_tree,
const float minimum_distance,
const float maximum_distance,
+#ifndef CYHEAP
Heap *heap,
std::vector<HeapNode *> *nodes)
+#else
+ cy::Heap *heap,
+ void *UNUSED(nodes))
+#endif
{
KDTreeNearest_3d *nearest_point = nullptr;
int neighbors = BLI_kdtree_3d_range_search(
@@ -119,10 +130,14 @@ static void points_distance_weight_calculate(std::vector<float> *weights,
/* When we run again we need to update the weights and the heap. */
else {
weights->data()[neighbor_point_id] -= weight_influence;
+#ifndef CYHEAP
HeapNode *node = nodes->data()[neighbor_point_id];
if (node != nullptr) {
BLI_heap_node_value_update(heap, node, weights->data()[neighbor_point_id]);
}
+#else
+ heap->MoveItemDown(neighbor_point_id);
+#endif
}
}
@@ -205,16 +220,24 @@ static void weighted_sample_elimination(Vector<float3> const *input_points,
}
/* Remove the points based on their weight. */
+#ifndef CYHEAP
Heap *heap = BLI_heap_new_ex(weights.size());
std::vector<HeapNode *> nodes(input_points->size(), nullptr);
for (size_t i = 0; i < weights.size(); i++) {
nodes[i] = BLI_heap_insert(heap, weights[i], POINTER_FROM_INT(i));
}
+#else
+ cy::Heap heap;
+ heap.SetDataPointer(weights.data(), input_points->size());
+ heap.Build();
+#endif
size_t sample_size = input_points->size();
while (sample_size > output_points->size()) {
/* For each sample around it, remove its weight contribution and update the heap. */
+
+#ifndef CYHEAP
size_t point_id = POINTER_AS_INT(BLI_heap_pop_min(heap));
nodes[point_id] = nullptr;
@@ -226,6 +249,18 @@ static void weighted_sample_elimination(Vector<float3> const *input_points,
maximum_distance,
heap,
&nodes);
+#else
+ size_t point_id = heap.GetTopItemID();
+ heap.Pop();
+ points_distance_weight_calculate(&weights,
+ point_id,
+ input_points,
+ kd_tree,
+ minimum_distance,
+ maximum_distance,
+ &heap,
+ nullptr);
+#endif
sample_size--;
}
@@ -233,13 +268,19 @@ static void weighted_sample_elimination(Vector<float3> const *input_points,
/* Copy the samples to the output array. */
size_t target_size = do_copy_eliminated ? input_points->size() : output_points->size();
for (size_t i = 0; i < target_size; i++) {
+#ifndef CYHEAP
size_t index = POINTER_AS_INT(BLI_heap_pop_min(heap));
+#else
+ size_t index = heap.GetIDFromHeap(i);
+#endif
output_points->data()[i] = input_points->data()[index];
}
/* Cleanup. */
BLI_kdtree_3d_free((KDTree_3d *)kd_tree);
+#ifndef CYHEAP
BLI_heap_free(heap, NULL);
+#endif
}
void poisson_disk_point_elimination(Vector<float3> const *input_points,
More information about the Bf-blender-cvs
mailing list