diff options
author | Hans Goudey <h.goudey@me.com> | 2021-08-25 05:57:45 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-08-25 05:57:45 +0300 |
commit | a2e0f714f28559c85082ef039d9f7d829c5afdf3 (patch) | |
tree | 2bf3be401e33adfbb778da65c198829caa4b5e0e /source/blender/nodes | |
parent | 5ef3afd87c54b47614254d95c9b2e9a17c60f76e (diff) |
Cleanup: Remove unecessary variables
Instead of passing separate booleans for whether to store the locations
and distances, check if the spans are empty. And instead of passing a
separate boolean for whether there is valid tree data, pass a pointer
to the data.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc index d71cb09f1bd..ad017ce7cf3 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc @@ -63,15 +63,10 @@ namespace blender::nodes { static void proximity_calc(MutableSpan<float> distance_span, MutableSpan<float3> location_span, const VArray<float3> &positions, - BVHTreeFromMesh &tree_data_mesh, - BVHTreeFromPointCloud &tree_data_pointcloud, - const bool bvh_mesh_success, - const bool bvh_pointcloud_success, - const bool store_distances, - const bool store_locations) + BVHTreeFromMesh *tree_data_mesh, + BVHTreeFromPointCloud *tree_data_pointcloud) { - IndexRange range = positions.index_range(); - threading::parallel_for(range, 512, [&](IndexRange range) { + threading::parallel_for(positions.index_range(), 512, [&](IndexRange range) { BVHTreeNearest nearest_from_mesh; BVHTreeNearest nearest_from_pointcloud; @@ -85,12 +80,12 @@ static void proximity_calc(MutableSpan<float> distance_span, /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ nearest_from_mesh.dist_sq = len_squared_v3v3(nearest_from_mesh.co, positions[i]); - if (bvh_mesh_success) { - BLI_bvhtree_find_nearest(tree_data_mesh.tree, + if (tree_data_mesh != nullptr) { + BLI_bvhtree_find_nearest(tree_data_mesh->tree, positions[i], &nearest_from_mesh, - tree_data_mesh.nearest_callback, - &tree_data_mesh); + tree_data_mesh->nearest_callback, + tree_data_mesh); } /* Use the distance to the closest point in the mesh to speedup the pointcloud bvh lookup. @@ -98,27 +93,27 @@ static void proximity_calc(MutableSpan<float> distance_span, * than the mesh. */ nearest_from_pointcloud.dist_sq = nearest_from_mesh.dist_sq; - if (bvh_pointcloud_success) { - BLI_bvhtree_find_nearest(tree_data_pointcloud.tree, + if (tree_data_pointcloud != nullptr) { + BLI_bvhtree_find_nearest(tree_data_pointcloud->tree, positions[i], &nearest_from_pointcloud, - tree_data_pointcloud.nearest_callback, - &tree_data_pointcloud); + tree_data_pointcloud->nearest_callback, + tree_data_pointcloud); } if (nearest_from_pointcloud.dist_sq < nearest_from_mesh.dist_sq) { - if (store_distances) { + if (!distance_span.is_empty()) { distance_span[i] = sqrtf(nearest_from_pointcloud.dist_sq); } - if (store_locations) { + if (!location_span.is_empty()) { location_span[i] = nearest_from_pointcloud.co; } } else { - if (store_distances) { + if (!distance_span.is_empty()) { distance_span[i] = sqrtf(nearest_from_mesh.dist_sq); } - if (store_locations) { + if (!location_span.is_empty()) { location_span[i] = nearest_from_mesh.co; } } @@ -181,20 +176,18 @@ static void attribute_calc_proximity(GeometryComponent &component, } BLI_assert(position_attribute.varray->type().is<float3>()); - const bNode &node = params.node(); - const NodeGeometryAttributeProximity &storage = *(const NodeGeometryAttributeProximity *) - node.storage; + const NodeGeometryAttributeProximity &storage = + *(const NodeGeometryAttributeProximity *)params.node().storage; - BVHTreeFromMesh tree_data_mesh; - BVHTreeFromPointCloud tree_data_pointcloud; bool bvh_mesh_success = false; - bool bvh_pointcloud_success = false; - + BVHTreeFromMesh tree_data_mesh; if (geometry_set_target.has_mesh()) { bvh_mesh_success = bvh_from_mesh( geometry_set_target.get_mesh_for_read(), storage.target_geometry_element, tree_data_mesh); } + bool bvh_pointcloud_success = false; + BVHTreeFromPointCloud tree_data_pointcloud; if (geometry_set_target.has_pointcloud() && storage.target_geometry_element == GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS) { @@ -211,12 +204,8 @@ static void attribute_calc_proximity(GeometryComponent &component, proximity_calc(distance_span, location_span, positions, - tree_data_mesh, - tree_data_pointcloud, - bvh_mesh_success, - bvh_pointcloud_success, - distance_attribute, /* Boolean. */ - location_attribute); /* Boolean. */ + bvh_mesh_success ? &tree_data_mesh : nullptr, + bvh_pointcloud_success ? &tree_data_pointcloud : nullptr); if (bvh_mesh_success) { free_bvhtree_from_mesh(&tree_data_mesh); |