From 9e393fc2f12583d32dddf00bad8174d2bb06b61d Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 8 Jun 2022 15:37:46 +0200 Subject: Curves: Port set type node to new data-block This commit ports the "Set Spline Type" node to the new curves type. Performance should be improved in similar ways to the other refactors from the conversion task (T95443). Converting to and from Catmull Rom curves is now supported. There are a few cases where a lot of work can be skipped: when the number of points doesn't change, and when the types already match the goal type. The refactor has a few other explicit goals as well: - Don't count on initialization of attribute arrays when they are first allocated. - Avoid copying the entire data-block when possible. - Make decisions about which attributes to copy when changing curves more obvious. - Use higher-level methods to copy data between curve points. - Optimize for the common cases of single types and full selections. - Process selected curves of the same types in the same loop. The Bezier to NURBS conversion is written by Piotr Makal (@pmakal). Differential Revision: https://developer.blender.org/D14769 --- source/blender/geometry/intern/resample_curves.cc | 62 ++++++----------------- 1 file changed, 16 insertions(+), 46 deletions(-) (limited to 'source/blender/geometry') diff --git a/source/blender/geometry/intern/resample_curves.cc b/source/blender/geometry/intern/resample_curves.cc index 9eaab327e01..36525e1bdf0 100644 --- a/source/blender/geometry/intern/resample_curves.cc +++ b/source/blender/geometry/intern/resample_curves.cc @@ -165,38 +165,6 @@ static void gather_point_attributes_to_interpolate(const CurveComponent &src_com dst_curves.update_customdata_pointers(); } -/** - * Copy the provided point attribute values between all curves in the #curve_ranges index - * ranges, assuming that all curves are the same size in #src_curves and #dst_curves. - */ -template -static void copy_between_curves(const bke::CurvesGeometry &src_curves, - const bke::CurvesGeometry &dst_curves, - const Span curve_ranges, - const Span src, - const MutableSpan dst) -{ - threading::parallel_for(curve_ranges.index_range(), 512, [&](IndexRange range) { - for (const IndexRange range : curve_ranges.slice(range)) { - const IndexRange src_points = src_curves.points_for_curves(range); - const IndexRange dst_points = dst_curves.points_for_curves(range); - /* The arrays might be large, so a threaded copy might make sense here too. */ - dst.slice(dst_points).copy_from(src.slice(src_points)); - } - }); -} -static void copy_between_curves(const bke::CurvesGeometry &src_curves, - const bke::CurvesGeometry &dst_curves, - const Span unselected_ranges, - const GSpan src, - const GMutableSpan dst) -{ - attribute_math::convert_to_static_type(src.type(), [&](auto dummy) { - using T = decltype(dummy); - copy_between_curves(src_curves, dst_curves, unselected_ranges, src.typed(), dst.typed()); - }); -} - static Curves *resample_to_uniform(const CurveComponent &src_component, const fn::Field &selection_field, const fn::Field &count_field) @@ -328,20 +296,21 @@ static Curves *resample_to_uniform(const CurveComponent &src_component, /* Any attribute data from unselected curve points can be directly copied. */ for (const int i : attributes.src.index_range()) { - copy_between_curves( + bke::curves::copy_point_data( src_curves, dst_curves, unselected_ranges, attributes.src[i], attributes.dst[i]); } for (const int i : attributes.src_no_interpolation.index_range()) { - copy_between_curves(src_curves, - dst_curves, - unselected_ranges, - attributes.src_no_interpolation[i], - attributes.dst_no_interpolation[i]); + bke::curves::copy_point_data(src_curves, + dst_curves, + unselected_ranges, + attributes.src_no_interpolation[i], + attributes.dst_no_interpolation[i]); } /* Copy positions for unselected curves. */ Span src_positions = src_curves.positions(); - copy_between_curves(src_curves, dst_curves, unselected_ranges, src_positions, dst_positions); + bke::curves::copy_point_data( + src_curves, dst_curves, unselected_ranges, src_positions, dst_positions); for (bke::OutputAttribute &attribute : attributes.dst_attributes) { attribute.save(); @@ -449,20 +418,21 @@ Curves *resample_to_evaluated(const CurveComponent &src_component, /* Any attribute data from unselected curve points can be directly copied. */ for (const int i : attributes.src.index_range()) { - copy_between_curves( + bke::curves::copy_point_data( src_curves, dst_curves, unselected_ranges, attributes.src[i], attributes.dst[i]); } for (const int i : attributes.src_no_interpolation.index_range()) { - copy_between_curves(src_curves, - dst_curves, - unselected_ranges, - attributes.src_no_interpolation[i], - attributes.dst_no_interpolation[i]); + bke::curves::copy_point_data(src_curves, + dst_curves, + unselected_ranges, + attributes.src_no_interpolation[i], + attributes.dst_no_interpolation[i]); } /* Copy positions for unselected curves. */ Span src_positions = src_curves.positions(); - copy_between_curves(src_curves, dst_curves, unselected_ranges, src_positions, dst_positions); + bke::curves::copy_point_data( + src_curves, dst_curves, unselected_ranges, src_positions, dst_positions); for (bke::OutputAttribute &attribute : attributes.dst_attributes) { attribute.save(); -- cgit v1.2.3