28 const bool smooth_ends,
29 const bool keep_shape,
62 if (src.
size() == 1) {
67 const int n_half = keep_shape ? (iterations * iterations) / 8 + iterations :
68 (iterations * iterations) / 4 + 2 * iterations + 12;
69 double w = keep_shape ? 2.0 : 1.0;
70 double w2 = keep_shape ?
71 (1.0 /
M_SQRT3) *
exp((2 * iterations * iterations) /
double(n_half * 3)) :
76 const int64_t last_pt = total_points - 1;
78 auto is_end_and_fixed = [smooth_ends, is_cyclic, last_pt](
int index) {
79 return !smooth_ends && !is_cyclic &&
ELEM(
index, 0, last_pt);
84 for (const int64_t index : range) {
85 if (!is_end_and_fixed(index)) {
95 for (const int64_t index : range) {
97 if (is_end_and_fixed(index)) {
101 double w_before = w - w2;
102 double w_after = w - w2;
105 int64_t before = index - offset;
106 int64_t after = index + offset;
108 before = (before % total_points + total_points) % total_points;
109 after = after % total_points;
112 if (!smooth_ends && (before < 0)) {
113 w_before *= -before / float(index);
115 before = math::max(before, int64_t(0));
117 if (!smooth_ends && (after > last_pt)) {
118 w_after *= (after - (total_points - 1)) / float(total_points - 1 - index);
120 after = math::min(after, last_pt);
124 const T bval = src[before];
125 const T aval = src[after];
126 const T cval = src[index];
128 dst[index] += (bval - cval) * w_before;
129 dst[index] += (aval - cval) * w_after;
132 total_weight[index] += w_before;
133 total_weight[index] += w_after;
137 w *= (n_half + offset) /
double(n_half + 1 - offset);
138 w2 *= (n_half * 3 + offset) /
double(n_half * 3 + 1 - offset);
143 threading::parallel_for(dst.index_range(), 1024, [&](
const IndexRange range) {
144 for (const int64_t index : range) {
145 if (!is_end_and_fixed(index)) {
146 total_weight[index] += w - w2;
147 dst[index] = src[index] + influence_by_point[index] * dst[index] / total_weight[index];
155 const int iterations,
157 const bool smooth_ends,
158 const bool keep_shape,
159 const bool is_cyclic,
165 if constexpr (is_same_any_v<T, float, float2, float3>) {
166 gaussian_blur_1D(src.typed<T>(),
181 const int iterations,
183 const bool smooth_ends,
184 const bool keep_shape,
189 auto smooth_points_range =
194 const GSpan src_data(dst_data.
type(), orig_data.data(), range.
size());
206 [&](
const int curve_i) {
208 const IndexRange points = points_by_curve[curve_i];
216 const std::optional<IndexRange> selection_range = selection_mask.
to_range();
217 if (selection_range && *selection_range == points) {
218 smooth_points_range(points, cyclic[curve_i], orig_data);
223 smooth_points_range(range,
false, orig_data);
234 const int iterations,
235 const float influence,
236 const bool smooth_ends,
237 const bool keep_shape,
254 const int iterations,
256 const bool smooth_ends,
257 const bool keep_shape)
277 const IndexMask bezier_curves_to_smooth =
curves.indices_for_curve_type(
284 curves, bezier_curves_to_smooth);
288 [&](
const int curve) {
290 const IndexRange points = points_by_curve[curve];
301 if (!smooth_ends && !cyclic[curve]) {
312 if (!smooth_ends && !cyclic[curve]) {
315 for (const int index : influences_range) {
318 point_influences[index] = influences.slice(range)[(index + 1) / 3];
324 positions_range.index_range(), 4096, [&](
const IndexRange influences_range) {
325 for (const int index : influences_range) {
326 point_influences[index] = influences.slice(range)[index / 3];
348 curves.curves_range(), memory);
349 if (!other_curves_to_smooth.
is_empty()) {
351 smooth_curve_attribute(other_curves_to_smooth,
363 curves.calculate_bezier_auto_handles();
364 curves.calculate_bezier_aligned_handles();
367 curves.tag_positions_changed();
373 const int iterations,
374 const float influence,
375 const bool smooth_ends,
376 const bool keep_shape)
Low-level operations for curves.
Low-level operations for curves.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
MutableSpan< T > as_mutable_span()
void copy_assign_n(const void *src, void *dst, int64_t n) const
int64_t size_in_bytes() const
GMutableSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
const CPPType & type() const
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
constexpr IndexRange index_range() const
constexpr IndexRange drop_front(int64_t n) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr bool is_empty() const
static VArray from_single(T value, const int64_t size)
static VArray from_span(Span< T > values)
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
GSpanAttributeWriter lookup_for_write_span(StringRef name)
constexpr Span slice(int64_t start, int64_t size) const
void foreach_range(ForeachRangeFn auto &&fn) const
std::optional< IndexRange > to_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void to_static_type(const CPPType &cpp_type, Fn &&fn)
Array< float3 > retrieve_all_positions(const bke::CurvesGeometry &curves, const IndexMask &curves_selection)
void write_all_positions(bke::CurvesGeometry &curves, const IndexMask &curves_selection, Span< float3 > all_positions)
constexpr ParallelGrainSize grain_size(int grain_size)
void smooth_curve_positions(bke::CurvesGeometry &curves, const IndexMask &curves_to_smooth, const VArray< bool > &point_selection, int iterations, const VArray< float > &influence_by_point, bool smooth_ends, bool keep_shape)
void smooth_curve_attribute(const IndexMask &curves_to_smooth, const OffsetIndices< int > points_by_curve, const VArray< bool > &point_selection, const VArray< bool > &cyclic, int iterations, float influence, bool smooth_ends, bool keep_shape, GMutableSpan attribute_data)
void gaussian_blur_1D(const GSpan src, int iterations, const VArray< float > &influence_by_point, const bool smooth_ends, const bool keep_shape, const bool is_cyclic, GMutableSpan dst)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void devirtualize_varray(const VArray< T > &varray, const Func &func, bool enable=true)