Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-06-08 16:37:46 +0300
committerHans Goudey <h.goudey@me.com>2022-06-08 16:37:46 +0300
commit9e393fc2f12583d32dddf00bad8174d2bb06b61d (patch)
treeb73ae3921fba6d76060ad484d2de87e010f91c9b /source/blender/blenkernel/intern/curves_utils.cc
parent520be607e8baf4dacfadc1897013c84e77b81b27 (diff)
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
Diffstat (limited to 'source/blender/blenkernel/intern/curves_utils.cc')
-rw-r--r--source/blender/blenkernel/intern/curves_utils.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/curves_utils.cc b/source/blender/blenkernel/intern/curves_utils.cc
index 78c2382b62f..802469399ab 100644
--- a/source/blender/blenkernel/intern/curves_utils.cc
+++ b/source/blender/blenkernel/intern/curves_utils.cc
@@ -4,6 +4,8 @@
* \ingroup bke
*/
+#include "BLI_index_mask_ops.hh"
+
#include "BKE_curves_utils.hh"
namespace blender::bke::curves {
@@ -35,4 +37,86 @@ void accumulate_counts_to_offsets(MutableSpan<int> counts_to_offsets, const int
counts_to_offsets.last() = offset;
}
+void copy_point_data(const CurvesGeometry &src_curves,
+ const CurvesGeometry &dst_curves,
+ const Span<IndexRange> curve_ranges,
+ const GSpan src,
+ GMutableSpan 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));
+ }
+ });
+}
+
+void copy_point_data(const CurvesGeometry &src_curves,
+ const CurvesGeometry &dst_curves,
+ const IndexMask src_curve_selection,
+ const GSpan src,
+ GMutableSpan dst)
+{
+ threading::parallel_for(src_curve_selection.index_range(), 512, [&](IndexRange range) {
+ for (const int i : src_curve_selection.slice(range)) {
+ const IndexRange src_points = src_curves.points_for_curve(i);
+ const IndexRange dst_points = dst_curves.points_for_curve(i);
+ /* The arrays might be large, so a threaded copy might make sense here too. */
+ dst.slice(dst_points).copy_from(src.slice(src_points));
+ }
+ });
+}
+
+void fill_points(const CurvesGeometry &curves,
+ const IndexMask curve_selection,
+ const GPointer value,
+ GMutableSpan dst)
+{
+ BLI_assert(*value.type() == dst.type());
+ const CPPType &type = dst.type();
+ threading::parallel_for(curve_selection.index_range(), 512, [&](IndexRange range) {
+ for (const int i : curve_selection.slice(range)) {
+ const IndexRange points = curves.points_for_curve(i);
+ type.fill_assign_n(value.get(), dst.slice(curves.points_for_curve(i)).data(), points.size());
+ }
+ });
+}
+
+IndexMask indices_for_type(const VArray<int8_t> &types,
+ const std::array<int, CURVE_TYPES_NUM> &type_counts,
+ const CurveType type,
+ const IndexMask selection,
+ Vector<int64_t> &r_indices)
+{
+ if (type_counts[type] == types.size()) {
+ return selection;
+ }
+ if (types.is_single()) {
+ return types.get_internal_single() == type ? IndexMask(types.size()) : IndexMask(0);
+ }
+ Span<int8_t> types_span = types.get_internal_span();
+ return index_mask_ops::find_indices_based_on_predicate(
+ selection, 4096, r_indices, [&](const int index) { return types_span[index] == type; });
+}
+
+void foreach_curve_by_type(const VArray<int8_t> &types,
+ const std::array<int, CURVE_TYPES_NUM> &counts,
+ const IndexMask selection,
+ FunctionRef<void(IndexMask)> catmull_rom_fn,
+ FunctionRef<void(IndexMask)> poly_fn,
+ FunctionRef<void(IndexMask)> bezier_fn,
+ FunctionRef<void(IndexMask)> nurbs_fn)
+{
+ Vector<int64_t> catmull_rom;
+ Vector<int64_t> poly;
+ Vector<int64_t> bezier;
+ Vector<int64_t> nurbs;
+ catmull_rom_fn(indices_for_type(types, counts, CURVE_TYPE_CATMULL_ROM, selection, catmull_rom));
+ poly_fn(indices_for_type(types, counts, CURVE_TYPE_POLY, selection, poly));
+ bezier_fn(indices_for_type(types, counts, CURVE_TYPE_BEZIER, selection, bezier));
+ nurbs_fn(indices_for_type(types, counts, CURVE_TYPE_NURBS, selection, nurbs));
+}
+
} // namespace blender::bke::curves