Curves: Add method to find indices for curve type in a selection

For example, this can be used to find the indices of all Bezier curves
inside an existing selection. The important part is that it is optimized
for the case when all curves have the same type.
This commit is contained in:
Hans Goudey 2022-05-04 13:55:08 +02:00
parent 16011e34f0
commit 9ee9dd257f
2 changed files with 20 additions and 16 deletions

View File

@ -181,11 +181,18 @@ class CurvesGeometry : public ::CurvesGeometry {
/** Update the cached count of curves of each type, necessary after #curve_types_for_write. */
void update_curve_types();
bool has_curve_with_type(const CurveType type) const;
bool has_curve_with_type(CurveType type) const;
/** Return true if all of the curves have the provided type. */
bool is_single_type(CurveType type) const;
/** Return the number of curves with each type. */
const std::array<int, CURVE_TYPES_NUM> &curve_type_counts() const;
/**
* All of the curve indices for curves with a specific type.
*/
IndexMask indices_for_curve_type(CurveType type, Vector<int64_t> &r_indices) const;
IndexMask indices_for_curve_type(CurveType type,
IndexMask selection,
Vector<int64_t> &r_indices) const;
Span<float3> positions() const;
MutableSpan<float3> positions_for_write();
@ -283,11 +290,6 @@ class CurvesGeometry : public ::CurvesGeometry {
bool bounds_min_max(float3 &min, float3 &max) const;
private:
/**
* All of the curve indices for curves with a specific type.
*/
IndexMask indices_for_curve_type(CurveType type, Vector<int64_t> &r_indices) const;
/* --------------------------------------------------------------------
* Evaluation.
*/

View File

@ -531,19 +531,19 @@ Span<int> CurvesGeometry::evaluated_offsets() const
IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type,
Vector<int64_t> &r_indices) const
{
return this->indices_for_curve_type(type, this->curves_range(), r_indices);
}
VArray<int8_t> types = this->curve_types();
if (types.is_single()) {
if (types.get_internal_single() == type) {
return IndexMask(types.size());
}
return {};
IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type,
const IndexMask selection,
Vector<int64_t> &r_indices) const
{
if (this->curve_type_counts()[type] == this->curves_num()) {
return selection;
}
Span<int8_t> types_span = types.get_internal_span();
Span<int8_t> types_span = this->curve_types().get_internal_span();
return index_mask_ops::find_indices_based_on_predicate(
IndexMask(types.size()), 1024, r_indices, [&](const int index) {
return types_span[index] == type;
});
selection, 1024, r_indices, [&](const int index) { return types_span[index] == type; });
}
void CurvesGeometry::ensure_nurbs_basis_cache() const
@ -1196,6 +1196,8 @@ static CurvesGeometry copy_with_removed_curves(const CurvesGeometry &curves,
}
});
new_curves.update_curve_types();
return new_curves;
}