[Bf-blender-cvs] [8d34b73df2b] temp-point-distribution-refactor-experiment: remove poisson distribution code

Jacques Lucke noreply at git.blender.org
Tue Jan 12 21:27:32 CET 2021


Commit: 8d34b73df2b5f05916a47e54627fabad8a3c10ed
Author: Jacques Lucke
Date:   Tue Jan 12 16:54:43 2021 +0100
Branches: temp-point-distribution-refactor-experiment
https://developer.blender.org/rB8d34b73df2b5f05916a47e54627fabad8a3c10ed

remove poisson distribution code

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

M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/geometry/node_geometry_util.hh
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
D	source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc

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

diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 64667faa735..d72189636e4 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -154,7 +154,6 @@ set(SRC
   geometry/nodes/node_geo_join_geometry.cc
   geometry/nodes/node_geo_object_info.cc
   geometry/nodes/node_geo_point_distribute.cc
-  geometry/nodes/node_geo_point_distribute_poisson_disk.cc
   geometry/nodes/node_geo_point_instance.cc
   geometry/nodes/node_geo_point_separate.cc
   geometry/nodes/node_geo_rotate_points.cc
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index 7c4963b1f3f..12ede8b6ee0 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -46,11 +46,6 @@ void update_attribute_input_socket_availabilities(bNode &node,
 
 CustomDataType attribute_domain_highest_complexity(Span<CustomDataType>);
 
-void poisson_disk_point_elimination(Vector<float3> const *input_points,
-                                    Vector<float3> *output_points,
-                                    float maximum_distance,
-                                    float3 boundbox);
-
 Array<uint32_t> get_geometry_element_ids_as_uints(const GeometryComponent &component,
                                                   const AttributeDomain domain);
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index f5f9c9f8830..76f1bf30c85 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -122,160 +122,6 @@ static Vector<float3> random_scatter_points_from_mesh(const Mesh *mesh,
   return points;
 }
 
-struct RayCastAll_Data {
-  void *bvhdata;
-
-  BVHTree_RayCastCallback raycast_callback;
-
-  /** The original coordinate the result point was projected from. */
-  float2 raystart;
-
-  const Mesh *mesh;
-  float base_weight;
-  FloatReadAttribute *density_factors;
-  Vector<float3> *projected_points;
-  Vector<float3> *normals;
-  Vector<int> *stable_ids;
-  float cur_point_weight;
-};
-
-static void project_2d_bvh_callback(void *userdata,
-                                    int index,
-                                    const BVHTreeRay *ray,
-                                    BVHTreeRayHit *hit)
-{
-  struct RayCastAll_Data *data = (RayCastAll_Data *)userdata;
-  data->raycast_callback(data->bvhdata, index, ray, hit);
-  if (hit->index != -1) {
-    /* This only updates a cache and can be considered to be logically const. */
-    const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(const_cast<Mesh *>(data->mesh));
-    const MVert *mvert = data->mesh->mvert;
-
-    const MLoopTri &looptri = looptris[index];
-    const FloatReadAttribute &density_factors = data->density_factors[0];
-
-    const int v0_index = data->mesh->mloop[looptri.tri[0]].v;
-    const int v1_index = data->mesh->mloop[looptri.tri[1]].v;
-    const int v2_index = data->mesh->mloop[looptri.tri[2]].v;
-
-    const float v0_density_factor = std::max(0.0f, density_factors[v0_index]);
-    const float v1_density_factor = std::max(0.0f, density_factors[v1_index]);
-    const float v2_density_factor = std::max(0.0f, density_factors[v2_index]);
-
-    /* Calculate barycentric weights for hit point. */
-    float3 weights;
-    interp_weights_tri_v3(
-        weights, mvert[v0_index].co, mvert[v1_index].co, mvert[v2_index].co, hit->co);
-
-    float point_weight = weights[0] * v0_density_factor + weights[1] * v1_density_factor +
-                         weights[2] * v2_density_factor;
-
-    point_weight *= data->base_weight;
-
-    if (point_weight >= FLT_EPSILON && data->cur_point_weight <= point_weight) {
-      data->projected_points->append(hit->co);
-
-      /* Build a hash stable even when the mesh is deformed. */
-      data->stable_ids->append((int)data->raystart.hash());
-
-      data->normals->append(hit->no);
-    }
-  }
-}
-
-static Vector<float3> poisson_scatter_points_from_mesh(const Mesh *mesh,
-                                                       const float density,
-                                                       const float minimum_distance,
-                                                       const FloatReadAttribute &density_factors,
-                                                       Vector<float3> &r_normals,
-                                                       Vector<int> &r_ids,
-                                                       const int seed)
-{
-  Vector<float3> points;
-
-  if (minimum_distance <= FLT_EPSILON || density <= FLT_EPSILON) {
-    return points;
-  }
-
-  /* Scatter points randomly on the mesh with higher density (5-7) times higher than desired for
-   * good quality possion disk distributions. */
-  int quality = 5;
-  const int output_points_target = 1000;
-  points.resize(output_points_target * quality);
-
-  const float required_area = output_points_target *
-                              (2.0f * sqrtf(3.0f) * minimum_distance * minimum_distance);
-  const float point_scale_multiplier = sqrtf(required_area);
-
-  {
-    const int rnd_seed = BLI_hash_int(seed);
-    RandomNumberGenerator point_rng(rnd_seed);
-
-    for (int i = 0; i < points.size(); i++) {
-      points[i].x = point_rng.get_float() * point_scale_multiplier;
-      points[i].y = point_rng.get_float() * point_scale_multiplier;
-      points[i].z = 0.0f;
-    }
-  }
-
-  /* Eliminate the scattered points until we get a possion distribution. */
-  Vector<float3> output_points(output_points_target);
-
-  const float3 bounds_max = float3(point_scale_multiplier, point_scale_multiplier, 0);
-  poisson_disk_point_elimination(&points, &output_points, 2.0f * minimum_distance, bounds_max);
-  Vector<float3> final_points;
-  r_ids.reserve(output_points_target);
-  final_points.reserve(output_points_target);
-
-  /* Check if we have any points we should remove from the final possion distribition. */
-  BVHTreeFromMesh treedata;
-  BKE_bvhtree_from_mesh_get(&treedata, const_cast<Mesh *>(mesh), BVHTREE_FROM_LOOPTRI, 2);
-
-  float3 bb_min, bb_max;
-  BLI_bvhtree_get_bounding_box(treedata.tree, bb_min, bb_max);
-
-  struct RayCastAll_Data data;
-  data.bvhdata = &treedata;
-  data.raycast_callback = treedata.raycast_callback;
-  data.mesh = mesh;
-  data.projected_points = &final_points;
-  data.stable_ids = &r_ids;
-  data.normals = &r_normals;
-  data.density_factors = const_cast<FloatReadAttribute *>(&density_factors);
-  data.base_weight = std::min(
-      1.0f, density / (output_points.size() / (point_scale_multiplier * point_scale_multiplier)));
-
-  const float max_dist = bb_max[2] - bb_min[2] + 2.0f;
-  const float3 dir = float3(0, 0, -1);
-  float3 raystart;
-  raystart.z = bb_max[2] + 1.0f;
-
-  float tile_start_x_coord = bb_min[0];
-  int tile_repeat_x = ceilf((bb_max[0] - bb_min[0]) / point_scale_multiplier);
-
-  float tile_start_y_coord = bb_min[1];
-  int tile_repeat_y = ceilf((bb_max[1] - bb_min[1]) / point_scale_multiplier);
-
-  for (int x = 0; x < tile_repeat_x; x++) {
-    float tile_curr_x_coord = x * point_scale_multiplier + tile_start_x_coord;
-    for (int y = 0; y < tile_repeat_y; y++) {
-      float tile_curr_y_coord = y * point_scale_multiplier + tile_start_y_coord;
-      for (int idx = 0; idx < output_points.size(); idx++) {
-        raystart.x = output_points[idx].x + tile_curr_x_coord;
-        raystart.y = output_points[idx].y + tile_curr_y_coord;
-
-        data.cur_point_weight = (float)idx / (float)output_points.size();
-        data.raystart = raystart;
-
-        BLI_bvhtree_ray_cast_all(
-            treedata.tree, raystart, dir, 0.0f, max_dist, project_2d_bvh_callback, &data);
-      }
-    }
-  }
-
-  return final_points;
-}
-
 static void geo_node_point_distribute_exec(GeoNodeExecParams params)
 {
   GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
@@ -319,8 +165,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
       break;
     case GEO_NODE_POINT_DISTRIBUTE_POISSON:
       const float min_dist = params.extract_input<float>("Distance Min");
-      points = poisson_scatter_points_from_mesh(
-          mesh_in, density, min_dist, density_factors, normals, stable_ids, seed);
+      UNUSED_VARS(min_dist);
       break;
   }
 
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
deleted file mode 100644
index 005fec71f86..00000000000
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute_poisson_disk.cc
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/*
- * Based on Cem Yuksel. 2015. Sample Elimination for Generating Poisson Disk Sample
- * ! Sets. Computer Graphics Forum 34, 2 (May 2015), 25-32.
- * ! http://www.cemyuksel.com/research/sampleelimination/
- * Copyright (c) 2016, Cem Yuksel <cem at cemyuksel.com>
- * All rights reserved.
- */
-
-#include "BLI_inplace_priority_queue.hh"
-#include "BLI_kdtree.h"
-
-#include "node_geometry_util.hh"
-
-#include <cstring>
-#include <iostream>
-
-namespace blender::nodes {
-
-static void tile_point(Vector<float3> *tiled_points,
-                       Vector<size_t> *indices,
-                       const float maximum_distance,
-                    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list