From 7395062480a6b6c623516eaad7e489451e16bcaf Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 9 Nov 2022 12:13:59 -0600 Subject: Cleanup: Miscellaneous cleanups to trim curves node - Fix braces initialization warning - Fixed missing static specifier - Removed two unused functions --- source/blender/blenkernel/BKE_curves_utils.hh | 15 -- source/blender/blenkernel/intern/curves_utils.cc | 29 ---- source/blender/geometry/intern/trim_curves.cc | 204 +++++++++++------------ 3 files changed, 101 insertions(+), 147 deletions(-) diff --git a/source/blender/blenkernel/BKE_curves_utils.hh b/source/blender/blenkernel/BKE_curves_utils.hh index 670b25bf80f..c8ca24b756a 100644 --- a/source/blender/blenkernel/BKE_curves_utils.hh +++ b/source/blender/blenkernel/BKE_curves_utils.hh @@ -543,12 +543,6 @@ IndexMask indices_for_type(const VArray &types, const IndexMask selection, Vector &r_indices); -void indices_for_each_type(const VArray &types, - const std::array &counts, - const IndexMask selection, - std::array &r_type_masks, - std::array, CURVE_TYPES_NUM> &r_type_indices); - void foreach_curve_by_type(const VArray &types, const std::array &type_counts, IndexMask selection, @@ -557,15 +551,6 @@ void foreach_curve_by_type(const VArray &types, FunctionRef bezier_fn, FunctionRef nurbs_fn); -/** - * Same as 'by_type' but index mask for each curve type is pre-computed. - */ -void foreach_curve_by_type_mask(const std::array &curve_type_mask, - FunctionRef catmull_rom_fn, - FunctionRef poly_fn, - FunctionRef bezier_fn, - FunctionRef nurbs_fn); - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenkernel/intern/curves_utils.cc b/source/blender/blenkernel/intern/curves_utils.cc index 2b13a7d3c8a..f5a69a995a3 100644 --- a/source/blender/blenkernel/intern/curves_utils.cc +++ b/source/blender/blenkernel/intern/curves_utils.cc @@ -128,18 +128,6 @@ IndexMask indices_for_type(const VArray &types, selection, 4096, r_indices, [&](const int index) { return types_span[index] == type; }); } -void indices_for_each_type(const VArray &types, - const std::array &counts, - const IndexMask selection, - std::array &r_type_masks, - std::array, CURVE_TYPES_NUM> &r_type_indices) -{ - for (const int64_t curve_type : IndexRange(CURVE_TYPES_NUM)) { - r_type_masks[curve_type] = indices_for_type( - types, counts, CurveType(curve_type), selection, r_type_indices[curve_type]); - } -} - void foreach_curve_by_type(const VArray &types, const std::array &counts, const IndexMask selection, @@ -162,21 +150,4 @@ void foreach_curve_by_type(const VArray &types, call_if_not_empty(CURVE_TYPE_NURBS, nurbs_fn); } -void foreach_curve_by_type_mask(const std::array &curve_type_mask, - FunctionRef catmull_rom_fn, - FunctionRef poly_fn, - FunctionRef bezier_fn, - FunctionRef nurbs_fn) -{ - auto call_if_not_empty = [&](const IndexMask curve_type_mask, FunctionRef fn) { - if (!curve_type_mask.is_empty()) { - fn(curve_type_mask); - } - }; - call_if_not_empty(curve_type_mask[0], catmull_rom_fn); - call_if_not_empty(curve_type_mask[1], poly_fn); - call_if_not_empty(curve_type_mask[2], bezier_fn); - call_if_not_empty(curve_type_mask[3], nurbs_fn); -} - } // namespace blender::bke::curves diff --git a/source/blender/geometry/intern/trim_curves.cc b/source/blender/geometry/intern/trim_curves.cc index 0e23a3d53f0..192c47b0d43 100644 --- a/source/blender/geometry/intern/trim_curves.cc +++ b/source/blender/geometry/intern/trim_curves.cc @@ -752,116 +752,114 @@ static float trim_sample_length(const Span accumulated_lengths, * Compute the selection for the given curve type. Tracks indices for splitting the selection if * there are curves reduced to a single point. */ -void compute_curve_trim_parameters(const bke::CurvesGeometry &curves, - const IndexMask selection, - const VArray &starts, - const VArray &ends, - const GeometryNodeCurveSampleMode mode, - MutableSpan dst_curve_size, - MutableSpan dst_curve_types, - MutableSpan start_points, - MutableSpan end_points, - MutableSpan src_ranges) +static void compute_curve_trim_parameters(const bke::CurvesGeometry &curves, + const IndexMask selection, + const VArray &starts, + const VArray &ends, + const GeometryNodeCurveSampleMode mode, + MutableSpan dst_curve_size, + MutableSpan dst_curve_types, + MutableSpan start_points, + MutableSpan end_points, + MutableSpan src_ranges) { const VArray src_cyclic = curves.cyclic(); const VArray resolution = curves.resolution(); const VArray curve_types = curves.curve_types(); /* Compute. */ - threading::parallel_for( - selection.index_range(), 128, [&](const IndexRange selection_range) { - for (const int64_t curve_i : selection.slice(selection_range)) { - CurveType curve_type = CurveType(curve_types[curve_i]); - - int point_count; - if (curve_type == CURVE_TYPE_NURBS) { - dst_curve_types[curve_i] = CURVE_TYPE_POLY; - point_count = curves.evaluated_points_for_curve(curve_i).size(); - } - else { - dst_curve_types[curve_i] = curve_type; - point_count = curves.points_num_for_curve(curve_i); - } - if (point_count == 1) { - /* Single point. */ - dst_curve_size[curve_i] = 1; - src_ranges[curve_i] = bke::curves::IndexRangeCyclic(0, 0, 1, 1); - start_points[curve_i] = {0, 0, 0.0f}; - end_points[curve_i] = {0, 0, 0.0f}; - continue; - } - - const bool cyclic = src_cyclic[curve_i]; - const Span lengths = curves.evaluated_lengths_for_curve(curve_i, cyclic); - BLI_assert(lengths.size() > 0); - - const float start_length = trim_sample_length(lengths, starts[curve_i], mode); - float end_length; - - bool equal_sample_point; - if (cyclic) { - end_length = trim_sample_length(lengths, ends[curve_i], mode); - const float cyclic_start = start_length == lengths.last() ? 0.0f : start_length; - const float cyclic_end = end_length == lengths.last() ? 0.0f : end_length; - equal_sample_point = cyclic_start == cyclic_end; - } - else { - end_length = ends[curve_i] <= starts[curve_i] ? - start_length : - trim_sample_length(lengths, ends[curve_i], mode); - equal_sample_point = start_length == end_length; - } - - start_points[curve_i] = lookup_curve_point(curves, - curve_type, - curve_i, - lengths, - start_length, - cyclic, - resolution[curve_i], - point_count); - if (equal_sample_point) { - end_points[curve_i] = start_points[curve_i]; - if (end_length <= start_length) { - /* Single point. */ - dst_curve_size[curve_i] = 1; - src_ranges[curve_i] = bke::curves::IndexRangeCyclic::get_range_from_size( - start_points[curve_i].index, - start_points[curve_i].is_controlpoint(), /* Only iterate if control point. */ - point_count); - } - else { - /* Split. */ - src_ranges[curve_i] = bke::curves::IndexRangeCyclic::get_range_between_endpoints( - start_points[curve_i], end_points[curve_i], point_count) - .push_loop(); - const int count = 1 + !start_points[curve_i].is_controlpoint() + point_count; - BLI_assert(count > 1); - dst_curve_size[curve_i] = count; - } - } - else { - /* General case. */ - end_points[curve_i] = lookup_curve_point(curves, - curve_type, - curve_i, - lengths, - end_length, - cyclic, - resolution[curve_i], - point_count); - - src_ranges[curve_i] = bke::curves::IndexRangeCyclic::get_range_between_endpoints( - start_points[curve_i], end_points[curve_i], point_count); - const int count = src_ranges[curve_i].size() + - !start_points[curve_i].is_controlpoint() + - !end_points[curve_i].is_controlpoint(); - BLI_assert(count > 1); - dst_curve_size[curve_i] = count; - } - BLI_assert(dst_curve_size[curve_i] > 0); + threading::parallel_for(selection.index_range(), 128, [&](const IndexRange selection_range) { + for (const int64_t curve_i : selection.slice(selection_range)) { + CurveType curve_type = CurveType(curve_types[curve_i]); + + int point_count; + if (curve_type == CURVE_TYPE_NURBS) { + dst_curve_types[curve_i] = CURVE_TYPE_POLY; + point_count = curves.evaluated_points_for_curve(curve_i).size(); + } + else { + dst_curve_types[curve_i] = curve_type; + point_count = curves.points_num_for_curve(curve_i); + } + if (point_count == 1) { + /* Single point. */ + dst_curve_size[curve_i] = 1; + src_ranges[curve_i] = bke::curves::IndexRangeCyclic(0, 0, 1, 1); + start_points[curve_i] = {{0, 0}, 0.0f}; + end_points[curve_i] = {{0, 0}, 0.0f}; + continue; + } + + const bool cyclic = src_cyclic[curve_i]; + const Span lengths = curves.evaluated_lengths_for_curve(curve_i, cyclic); + BLI_assert(lengths.size() > 0); + + const float start_length = trim_sample_length(lengths, starts[curve_i], mode); + float end_length; + + bool equal_sample_point; + if (cyclic) { + end_length = trim_sample_length(lengths, ends[curve_i], mode); + const float cyclic_start = start_length == lengths.last() ? 0.0f : start_length; + const float cyclic_end = end_length == lengths.last() ? 0.0f : end_length; + equal_sample_point = cyclic_start == cyclic_end; + } + else { + end_length = ends[curve_i] <= starts[curve_i] ? + start_length : + trim_sample_length(lengths, ends[curve_i], mode); + equal_sample_point = start_length == end_length; + } + + start_points[curve_i] = lookup_curve_point(curves, + curve_type, + curve_i, + lengths, + start_length, + cyclic, + resolution[curve_i], + point_count); + if (equal_sample_point) { + end_points[curve_i] = start_points[curve_i]; + if (end_length <= start_length) { + /* Single point. */ + dst_curve_size[curve_i] = 1; + src_ranges[curve_i] = bke::curves::IndexRangeCyclic::get_range_from_size( + start_points[curve_i].index, + start_points[curve_i].is_controlpoint(), /* Only iterate if control point. */ + point_count); } - }); + else { + /* Split. */ + src_ranges[curve_i] = bke::curves::IndexRangeCyclic::get_range_between_endpoints( + start_points[curve_i], end_points[curve_i], point_count) + .push_loop(); + const int count = 1 + !start_points[curve_i].is_controlpoint() + point_count; + BLI_assert(count > 1); + dst_curve_size[curve_i] = count; + } + } + else { + /* General case. */ + end_points[curve_i] = lookup_curve_point(curves, + curve_type, + curve_i, + lengths, + end_length, + cyclic, + resolution[curve_i], + point_count); + + src_ranges[curve_i] = bke::curves::IndexRangeCyclic::get_range_between_endpoints( + start_points[curve_i], end_points[curve_i], point_count); + const int count = src_ranges[curve_i].size() + !start_points[curve_i].is_controlpoint() + + !end_points[curve_i].is_controlpoint(); + BLI_assert(count > 1); + dst_curve_size[curve_i] = count; + } + BLI_assert(dst_curve_size[curve_i] > 0); + } + }); } /** \} */ -- cgit v1.2.3