Commit: 6c4e3a9e517840bb69260f2ad46748e1dc655e32 Author: Hans Goudey Date: Wed Jan 18 16:41:10 2023 -0600 Branches: master https://developer.blender.org/rB6c4e3a9e517840bb69260f2ad46748e1dc655e32
Curves: Deduplicate and parallelize point to curve map creation There is a utility method on `CurvesGeometry` to build a map of the curve for each point. Use that in two more places and make sure its implementation is multithreaded, which gives a slight speedup in a simple test file. =================================================================== M source/blender/blenkernel/intern/curves_geometry.cc M source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc =================================================================== diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index b2cd7cf5cae..0f24d9ea640 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -536,9 +536,11 @@ Array<int> CurvesGeometry::point_to_curve_map() const { const OffsetIndices points_by_curve = this->points_by_curve(); Array<int> map(this->points_num()); - for (const int i : this->curves_range()) { - map.as_mutable_span().slice(points_by_curve[i]).fill(i); - } + threading::parallel_for(this->curves_range(), 1024, [&](const IndexRange range) { + for (const int i_curve : range) { + map.as_mutable_span().slice(points_by_curve[i_curve]).fill(i_curve); + } + }); return map; } @@ -1075,28 +1077,13 @@ static void copy_with_map(const GSpan src, const Span<int> map, GMutableSpan dst }); } -/** - * Builds an array that for every point, contains the corresponding curve index. - */ -static Array<int> build_point_to_curve_map(const CurvesGeometry &curves) -{ - const OffsetIndices points_by_curve = curves.points_by_curve(); - Array<int> point_to_curve_map(curves.points_num()); - threading::parallel_for(curves.curves_range(), 1024, [&](const IndexRange curves_range) { - for (const int i_curve : curves_range) { - point_to_curve_map.as_mutable_span().slice(points_by_curve[i_curve]).fill(i_curve); - } - }); - return point_to_curve_map; -} - static CurvesGeometry copy_with_removed_points( const CurvesGeometry &curves, const IndexMask points_to_delete, const AnonymousAttributePropagationInfo &propagation_info) { /* Use a map from points to curves to facilitate using an #IndexMask input. */ - const Array<int> point_to_curve_map = build_point_to_curve_map(curves); + const Array<int> point_to_curve_map = curves.point_to_curve_map(); const Vector<IndexRange> copy_point_ranges = points_to_delete.extract_ranges_invert( curves.points_range()); diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc index b3017a569eb..480fd516360 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc @@ -821,14 +821,7 @@ static void duplicate_points_curve(GeometrySet &geometry_set, Array<int> offsets = accumulate_counts_to_offsets(selection, counts); const int dst_num = offsets.last(); - const OffsetIndices src_points_by_curve = src_curves.points_by_curve(); - Array<int> point_to_curve_map(src_curves.points_num()); - threading::parallel_for(src_curves.curves_range(), 1024, [&](const IndexRange range) { - for (const int i_curve : range) { - const IndexRange points = src_points_by_curve[i_curve]; - point_to_curve_map.as_mutable_span().slice(points).fill(i_curve); - } - }); + const Array<int> point_to_curve_map = src_curves.point_to_curve_map(); Curves *new_curves_id = bke::curves_new_nomain(dst_num, dst_num); bke::curves_copy_parameters(src_curves_id, *new_curves_id); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs