Cleanup: Small changes to GP smooth operator
- Avoid calling `.finish()` twice, only pass span - Fix "opcities" typo - Remove unnecessary "is_empty()" check - Group creation of "src_data" in one block - Remove periods after doxygen titles - Remove unnecessary "curves" argument - Order mutable argument last Pull Request: https://projects.blender.org/blender/blender/pulls/110428
This commit is contained in:
@@ -93,7 +93,7 @@ static void keymap_grease_pencil_painting(wmKeyConfig *keyconf)
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Smooth Stroke Operator.
|
||||
/** \name Smooth Stroke Operator
|
||||
* \{ */
|
||||
|
||||
template<typename T>
|
||||
@@ -246,21 +246,16 @@ void gaussian_blur_1D(const GSpan src,
|
||||
});
|
||||
}
|
||||
|
||||
static void smooth_curve_attribute(bke::CurvesGeometry &curves,
|
||||
bke::GSpanAttributeWriter &attribute,
|
||||
const OffsetIndices<int> points_by_curve,
|
||||
const VArray<bool> selection,
|
||||
const VArray<bool> cyclic,
|
||||
static void smooth_curve_attribute(const OffsetIndices<int> points_by_curve,
|
||||
const VArray<bool> &selection,
|
||||
const VArray<bool> &cyclic,
|
||||
const int64_t iterations,
|
||||
const float influence,
|
||||
const bool smooth_ends,
|
||||
const bool keep_shape)
|
||||
const bool keep_shape,
|
||||
GMutableSpan data)
|
||||
{
|
||||
GMutableSpan data = attribute.span;
|
||||
if (data.is_empty()) {
|
||||
return;
|
||||
}
|
||||
threading::parallel_for(curves.curves_range(), 512, [&](const IndexRange range) {
|
||||
threading::parallel_for(points_by_curve.index_range(), 512, [&](const IndexRange range) {
|
||||
Vector<std::byte> orig_data;
|
||||
for (const int curve_i : range) {
|
||||
const IndexRange points = points_by_curve[curve_i];
|
||||
@@ -273,17 +268,16 @@ static void smooth_curve_attribute(bke::CurvesGeometry &curves,
|
||||
Vector<IndexRange> selection_ranges = selection_mask.to_ranges();
|
||||
for (const IndexRange range : selection_ranges) {
|
||||
GMutableSpan dst_data = data.slice(range);
|
||||
|
||||
orig_data.resize(dst_data.size_in_bytes());
|
||||
dst_data.type().copy_assign_n(dst_data.data(), orig_data.data(), range.size());
|
||||
const GSpan src_data(dst_data.type(), orig_data.data(), range.size());
|
||||
|
||||
GSpan src_data(dst_data.type(), orig_data.data(), range.size());
|
||||
gaussian_blur_1D(
|
||||
src_data, iterations, influence, smooth_ends, keep_shape, cyclic[curve_i], dst_data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
attribute.finish();
|
||||
}
|
||||
|
||||
static int grease_pencil_stroke_smooth_exec(bContext *C, wmOperator *op)
|
||||
@@ -322,41 +316,38 @@ static int grease_pencil_stroke_smooth_exec(bContext *C, wmOperator *op)
|
||||
|
||||
if (smooth_position) {
|
||||
bke::GSpanAttributeWriter positions = attributes.lookup_for_write_span("position");
|
||||
smooth_curve_attribute(curves,
|
||||
positions,
|
||||
points_by_curve,
|
||||
smooth_curve_attribute(points_by_curve,
|
||||
selection,
|
||||
cyclic,
|
||||
iterations,
|
||||
influence,
|
||||
smooth_ends,
|
||||
keep_shape);
|
||||
keep_shape,
|
||||
positions.span);
|
||||
positions.finish();
|
||||
}
|
||||
if (smooth_opacity && drawing.opacities().is_span()) {
|
||||
bke::GSpanAttributeWriter opcities = attributes.lookup_for_write_span("opacity");
|
||||
smooth_curve_attribute(curves,
|
||||
opcities,
|
||||
points_by_curve,
|
||||
bke::GSpanAttributeWriter opacities = attributes.lookup_for_write_span("opacity");
|
||||
smooth_curve_attribute(points_by_curve,
|
||||
selection,
|
||||
cyclic,
|
||||
iterations,
|
||||
influence,
|
||||
smooth_ends,
|
||||
false);
|
||||
opcities.finish();
|
||||
false,
|
||||
opacities.span);
|
||||
opacities.finish();
|
||||
}
|
||||
if (smooth_radius && drawing.radii().is_span()) {
|
||||
bke::GSpanAttributeWriter radii = attributes.lookup_for_write_span("radius");
|
||||
smooth_curve_attribute(curves,
|
||||
radii,
|
||||
points_by_curve,
|
||||
smooth_curve_attribute(points_by_curve,
|
||||
selection,
|
||||
cyclic,
|
||||
iterations,
|
||||
influence,
|
||||
smooth_ends,
|
||||
false);
|
||||
false,
|
||||
radii.span);
|
||||
radii.finish();
|
||||
}
|
||||
});
|
||||
@@ -397,7 +388,7 @@ static void GREASE_PENCIL_OT_stroke_smooth(wmOperatorType *ot)
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Simplify Stroke Operator.
|
||||
/** \name Simplify Stroke Operator
|
||||
* \{ */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user