Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curves_utils.cc
| Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | IndexMask indices_for_type(const VArray<int8_t> &types, | ||||
| if (types.is_single()) { | if (types.is_single()) { | ||||
| return types.get_internal_single() == type ? IndexMask(types.size()) : IndexMask(0); | return types.get_internal_single() == type ? IndexMask(types.size()) : IndexMask(0); | ||||
| } | } | ||||
| Span<int8_t> types_span = types.get_internal_span(); | Span<int8_t> types_span = types.get_internal_span(); | ||||
| return index_mask_ops::find_indices_based_on_predicate( | return index_mask_ops::find_indices_based_on_predicate( | ||||
| selection, 4096, r_indices, [&](const int index) { return types_span[index] == type; }); | selection, 4096, r_indices, [&](const int index) { return types_span[index] == type; }); | ||||
| } | } | ||||
| void indices_for_each_type(const VArray<int8_t> &types, | |||||
| const std::array<int, CURVE_TYPES_NUM> &counts, | |||||
| const IndexMask selection, | |||||
| std::array<IndexMask, CURVE_TYPES_NUM> &r_type_masks, | |||||
| std::array<Vector<int64_t>, 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<int8_t> &types, | void foreach_curve_by_type(const VArray<int8_t> &types, | ||||
| const std::array<int, CURVE_TYPES_NUM> &counts, | const std::array<int, CURVE_TYPES_NUM> &counts, | ||||
| const IndexMask selection, | const IndexMask selection, | ||||
| FunctionRef<void(IndexMask)> catmull_rom_fn, | FunctionRef<void(IndexMask)> catmull_rom_fn, | ||||
| FunctionRef<void(IndexMask)> poly_fn, | FunctionRef<void(IndexMask)> poly_fn, | ||||
| FunctionRef<void(IndexMask)> bezier_fn, | FunctionRef<void(IndexMask)> bezier_fn, | ||||
| FunctionRef<void(IndexMask)> nurbs_fn) | FunctionRef<void(IndexMask)> nurbs_fn) | ||||
| { | { | ||||
| Vector<int64_t> indices; | Vector<int64_t> indices; | ||||
| auto call_if_not_empty = [&](const CurveType type, FunctionRef<void(IndexMask)> fn) { | auto call_if_not_empty = [&](const CurveType type, FunctionRef<void(IndexMask)> fn) { | ||||
| indices.clear(); | indices.clear(); | ||||
| const IndexMask mask = indices_for_type(types, counts, type, selection, indices); | const IndexMask mask = indices_for_type(types, counts, type, selection, indices); | ||||
| if (!mask.is_empty()) { | if (!mask.is_empty()) { | ||||
| fn(mask); | fn(mask); | ||||
| } | } | ||||
| }; | }; | ||||
| call_if_not_empty(CURVE_TYPE_CATMULL_ROM, catmull_rom_fn); | call_if_not_empty(CURVE_TYPE_CATMULL_ROM, catmull_rom_fn); | ||||
| call_if_not_empty(CURVE_TYPE_POLY, poly_fn); | call_if_not_empty(CURVE_TYPE_POLY, poly_fn); | ||||
| call_if_not_empty(CURVE_TYPE_BEZIER, bezier_fn); | call_if_not_empty(CURVE_TYPE_BEZIER, bezier_fn); | ||||
| call_if_not_empty(CURVE_TYPE_NURBS, nurbs_fn); | call_if_not_empty(CURVE_TYPE_NURBS, nurbs_fn); | ||||
| } | } | ||||
| void foreach_curve_by_type_mask(const std::array<IndexMask, CURVE_TYPES_NUM> &curve_type_mask, | |||||
| FunctionRef<void(IndexMask)> catmull_rom_fn, | |||||
| FunctionRef<void(IndexMask)> poly_fn, | |||||
| FunctionRef<void(IndexMask)> bezier_fn, | |||||
| FunctionRef<void(IndexMask)> nurbs_fn) | |||||
| { | |||||
| auto call_if_not_empty = [&](const IndexMask curve_type_mask, FunctionRef<void(IndexMask)> 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 | } // namespace blender::bke::curves | ||||