[Bf-blender-cvs] [b056ed5146f] temp-geometry-nodes-distribute-points-cleanup: Fix another typo/error in progressive sampling reorder
Dalai Felinto
noreply at git.blender.org
Tue Dec 15 19:16:18 CET 2020
Commit: b056ed5146f3ad89377e81f472ab846781af6a49
Author: Dalai Felinto
Date: Tue Dec 15 18:34:17 2020 +0100
Branches: temp-geometry-nodes-distribute-points-cleanup
https://developer.blender.org/rBb056ed5146f3ad89377e81f472ab846781af6a49
Fix another typo/error in progressive sampling reorder
===================================================================
M source/blender/nodes/geometry/nodes/cySampleElim.hh
M source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc
===================================================================
diff --git a/source/blender/nodes/geometry/nodes/cySampleElim.hh b/source/blender/nodes/geometry/nodes/cySampleElim.hh
index 94cdff456ac..04a806513c5 100644
--- a/source/blender/nodes/geometry/nodes/cySampleElim.hh
+++ b/source/blender/nodes/geometry/nodes/cySampleElim.hh
@@ -116,6 +116,8 @@ void PointCloud<blender::float3, float, 3, size_t>::GetPoints(
int neighbors = BLI_kdtree_3d_range_search((KDTree_3d *)kd_tree, position, &ptn, radius);
float unused_radius = 0.0f;
+ printf("neighbors=%d\n", neighbors);
+
for (int i = 0; i < neighbors; i++) {
blender::float3 co(ptn[i].co);
float dist_sq = ptn[i].dist * ptn[i].dist;
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 e6af4e894d3..e5b6744368a 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,15 +21,13 @@
* 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 "BKE_global.h"
+
+#include "cyHeap.h"
#include "node_geometry_util.hh"
@@ -108,13 +106,9 @@ static void points_distance_weight_calculate(Vector<float> *weights,
const void *kd_tree,
const float minimum_distance,
const float maximum_distance,
-#ifndef CYHEAP
Heap *heap,
- Vector<HeapNode *> *nodes)
-#else
- cy::Heap *heap,
- void *UNUSED(nodes))
-#endif
+ Vector<HeapNode *> *nodes,
+ cy::Heap *cy_heap)
{
KDTreeNearest_3d *nearest_point = nullptr;
int neighbors = BLI_kdtree_3d_range_search(
@@ -136,20 +130,21 @@ static void points_distance_weight_calculate(Vector<float> *weights,
maximum_distance, minimum_distance, nearest_point[i].dist);
/* In the first pass we just the weights. */
- if (heap == nullptr) {
+ if ((heap == nullptr) && (cy_heap == nullptr)) {
(*weights)[point_id] += weight_influence;
}
/* When we run again we need to update the weights and the heap. */
else {
(*weights)[neighbor_point_id] -= weight_influence;
-#ifndef CYHEAP
- HeapNode *node = (*nodes)[neighbor_point_id];
- if (node != nullptr) {
- BLI_heap_node_value_update(heap, node, -((*weights)[neighbor_point_id]));
+ if (nodes != NULL) {
+ HeapNode *node = (*nodes)[neighbor_point_id];
+ if (node != nullptr) {
+ BLI_heap_node_value_update(heap, node, -((*weights)[neighbor_point_id]));
+ }
+ }
+ else {
+ cy_heap->MoveItemDown(neighbor_point_id);
}
-#else
- heap->MoveItemDown(neighbor_point_id);
-#endif
}
}
@@ -211,7 +206,15 @@ static void weighted_sample_elimination(const float3 *input_points,
weight_limit_fraction_get(input_size, output_size);
void *kd_tree = nullptr;
+#if 1
points_tiling(input_points, input_size, &kd_tree, maximum_distance, boundbox);
+#else
+ kd_tree = BLI_kdtree_3d_new(input_size);
+ for (size_t i = 0; i < input_size; i++) {
+ BLI_kdtree_3d_insert((KDTree_3d *)kd_tree, i, input_points[i]);
+ }
+ BLI_kdtree_3d_balance((KDTree_3d *)kd_tree);
+#endif
/* Assign weights to each sample. */
Vector<float> weights(input_size, 0.0f);
@@ -223,76 +226,80 @@ static void weighted_sample_elimination(const float3 *input_points,
minimum_distance,
maximum_distance,
nullptr,
+ nullptr,
nullptr);
}
/* Remove the points based on their weight. */
-#ifndef CYHEAP
Heap *heap = BLI_heap_new_ex(weights.size());
Vector<HeapNode *> nodes(input_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_size);
- heap.Build();
-#endif
+
+ cy::Heap cy_heap;
+ cy_heap.SetDataPointer(weights.data(), input_size);
+ cy_heap.Build();
size_t sample_size = input_size;
while (sample_size > output_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;
-
- points_distance_weight_calculate(&weights,
- point_id,
- input_points,
- kd_tree,
- minimum_distance,
- 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
-
+ if (G.debug_value == 0) {
+ size_t point_id = POINTER_AS_INT(BLI_heap_pop_min(heap));
+ nodes[point_id] = nullptr;
+ points_distance_weight_calculate(&weights,
+ point_id,
+ input_points,
+ kd_tree,
+ minimum_distance,
+ maximum_distance,
+ heap,
+ &nodes,
+ nullptr);
+ }
+ else {
+ size_t point_id = cy_heap.GetTopItemID();
+ cy_heap.Pop();
+ points_distance_weight_calculate(&weights,
+ point_id,
+ input_points,
+ kd_tree,
+ minimum_distance,
+ maximum_distance,
+ nullptr,
+ nullptr,
+ &cy_heap);
+ }
sample_size--;
}
/* Copy the samples to the output array. */
size_t target_size = do_copy_eliminated ? input_size : output_size;
-#ifndef CYHEAP
/* We need to traverse in the reverted order because we want
* to first have the points that are more isolated (lower weight). */
- for (int i = target_size - 1; i >= 0; i--) {
- size_t index = POINTER_AS_INT(BLI_heap_pop_min(heap));
- output_points[i] = input_points[index];
+ if (G.debug_value == 0) {
+ for (int i = target_size - 1; i >= 0; i--) {
+ printf("i=%d, target_size=%lu\n", i, target_size);
+ if (BLI_heap_is_empty(heap)) {
+ break;
+ }
+ size_t index = POINTER_AS_INT(BLI_heap_pop_min(heap));
+ output_points[i] = input_points[index];
+ printf("index=%lu\n", index);
+ }
}
-#else
- for (size_t i = 0; i < target_size; i++) {
- size_t index = heap.GetIDFromHeap(i);
- output_points[i] = input_points[index];
+ else {
+ for (size_t i = 0; i < target_size; i++) {
+ size_t index = cy_heap.GetIDFromHeap(i);
+ output_points[i] = input_points[index];
+ }
}
-#endif
/* Cleanup. */
BLI_kdtree_3d_free((KDTree_3d *)kd_tree);
-#ifndef CYHEAP
BLI_heap_free(heap, NULL);
-#endif
}
static void progressive_sampling_reorder(Vector<float3> *output_points,
@@ -328,7 +335,7 @@ static void progressive_sampling_reorder(Vector<float3> *output_points,
source_size = dest_size;
}
if (source_points != output_points->data()) {
- memcpy(dest_points, source_points, dest_size * sizeof(float3));
+ memcpy(output_points->data(), source_points, dest_size * sizeof(float3));
}
}
More information about the Bf-blender-cvs
mailing list