20 const int segment_index)
24 handle_types_left[segment_index + 1]);
39 const int size = handle_types_left.
size();
42 evaluated_offsets.
first() = 0;
44 evaluated_offsets.
last() = 1;
48 const int points_per_segment = std::max(1, resolution);
52 evaluated_offsets[i] = offset;
53 offset +=
segment_is_vector(handle_types_left, handle_types_right, i) ? 1 : points_per_segment;
56 evaluated_offsets.
last(1) = offset;
66 evaluated_offsets.
last() = offset;
76 BLI_assert(parameter <= 1.0f && parameter >= 0.0f);
90 const float3 &other_handle,
91 const float3 &aligned_handle)
100 return aligned_handle;
108 const float3 &left_handle,
109 const float3 &right_handle)
118 if (left_length == 0.0f && right_length == 0.0f) {
120 return {left_handle, right_handle};
123 if (left_length == 0.0f) {
124 return {
position - right_dir, right_handle};
126 if (right_length == 0.0f) {
127 return {left_handle,
position - left_dir};
134 if (align_length <= 0.0001f * (left_length + right_length)) {
136 return {left_handle, right_handle};
140 align_dir = align_dir / align_length;
143 const float3 new_left_dir = left_dir -
math::dot(left_dir, align_dir) * align_dir;
144 const float3 new_right_dir = right_dir -
math::dot(right_dir, align_dir) * align_dir;
154 const float3 prev_position,
155 const float3 next_position,
164 if (prev_len == 0.0f) {
167 if (next_len == 0.0f) {
170 const float3 dir = next_diff / next_len + prev_diff / prev_len;
190 const float prev_len_clamped = std::min(prev_len, next_len * 5.0f);
194 const float next_len_clamped = std::min(next_len, prev_len * 5.0f);
244 [&](
const int point) {
246 positions[point], align_with[point], align_handles[point]);
259 [&](
const int point) {
261 positions[point], handles_left[point], handles_right[point]);
262 align_handles_left[point] = new_left;
263 align_handles_right[point] = new_right;
275 const int points_num = positions.
size();
276 if (points_num == 1) {
283 cyclic ? positions.
last() : 2.0f * positions.
first() - positions[1],
285 positions_left.
first(),
286 positions_right.
first());
289 for (
const int i : range) {
304 cyclic ? positions.
first() : 2.0f * positions.
last() - positions.
last(1),
305 positions_left.
last(),
306 positions_right.
last());
315 const float inv_len_squared = inv_len * inv_len;
316 const float inv_len_cubed = inv_len_squared * inv_len;
318 const T rt1 = 3.0f * (point_1 - point_0) * inv_len;
319 const T rt2 = 3.0f * (point_0 - 2.0f * point_1 + point_2) * inv_len_squared;
320 const T rt3 = (point_3 - point_0 + 3.0f * (point_1 - point_2)) * inv_len_cubed;
323 T q1 = rt1 + rt2 + rt3;
324 T q2 = 2.0f * rt2 + 6.0f * rt3;
326 for (
const int i :
result.index_range()) {
360 evaluated_positions.
first() = positions.
first();
366 handles_right.
first(),
369 evaluated_positions.
slice(evaluated_offsets[0]));
372 const int grain_size = std::max<int>(evaluated_positions.
size() / positions.
size() * 32, 1);
375 for (
const int i : range) {
376 const IndexRange evaluated_range = evaluated_offsets[i];
377 if (evaluated_range.
size() == 1) {
378 evaluated_positions[evaluated_range.
first()] = positions[i];
385 evaluated_positions.
slice(evaluated_range));
392 if (last_segment_points.size() == 1) {
393 evaluated_positions.
last() = positions.
last();
397 handles_right.
last(),
398 handles_left.
first(),
400 evaluated_positions.
slice(last_segment_points));
408 const float step = 1.0f / dst.
size();
421 if (src.
size() == 1) {
431 for (const int i : range) {
432 const IndexRange segment = evaluated_offsets[i];
433 linear_interpolation(src[i], src[i + 1], dst.slice(segment));
437 const IndexRange last_segment = evaluated_offsets[src.index_range().last()];
446 if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
447 interpolate_to_evaluated(src.typed<T>(), evaluated_offsets, dst.typed<T>());
Low-level operations for curves.
const CPPType & type() const
constexpr int64_t first() const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr bool contains(int64_t value) const
constexpr IndexRange drop_front(int64_t n) const
constexpr int64_t size() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr T & first() const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
void to_static_type(const CPPType &cpp_type, Fn &&fn)
T mix2(float factor, const T &a, const T &b)
Insertion insert(const float3 &point_prev, const float3 &handle_prev, const float3 &handle_next, const float3 &point_next, float parameter)
void calculate_aligned_handles(const IndexMask &selection, Span< float3 > positions, Span< float3 > handles_left, Span< float3 > handles_right, MutableSpan< float3 > align_handles_left, MutableSpan< float3 > align_handles_right)
bool segment_is_vector(const HandleType left, const HandleType right)
void calculate_auto_handles(bool cyclic, Span< int8_t > types_left, Span< int8_t > types_right, Span< float3 > positions, MutableSpan< float3 > positions_left, MutableSpan< float3 > positions_right)
void calculate_evaluated_offsets(Span< int8_t > handle_types_left, Span< int8_t > handle_types_right, bool cyclic, int resolution, MutableSpan< int > evaluated_offsets)
static std::pair< float3, float3 > calculate_align_both_handles(const float3 &position, const float3 &left_handle, const float3 &right_handle)
float3 calculate_vector_handle(const float3 &point, const float3 &next_point)
static void calculate_point_handles(const HandleType type_left, const HandleType type_right, const float3 position, const float3 prev_position, const float3 next_position, float3 &left, float3 &right)
bool last_cyclic_segment_is_vector(Span< int8_t > handle_types_left, Span< int8_t > handle_types_right)
static float3 calculate_aligned_handle(const float3 &position, const float3 &other_handle, const float3 &aligned_handle)
void evaluate_segment(const T &point_0, const T &point_1, const T &point_2, const T &point_3, MutableSpan< T > result)
void calculate_single_aligned_handles(const IndexMask &selection, Span< float3 > positions, Span< float3 > align_with, MutableSpan< float3 > align_handles)
void calculate_evaluated_positions(Span< float3 > positions, Span< float3 > handles_left, Span< float3 > handles_right, OffsetIndices< int > evaluated_offsets, MutableSpan< float3 > evaluated_positions)
void interpolate_to_evaluated(GSpan src, OffsetIndices< int > evaluated_offsets, GMutableSpan dst)
void evaluate_segment_ex(const T &point_0, const T &point_1, const T &point_2, const T &point_3, MutableSpan< T > result)
void set_handle_position(const float3 &position, HandleType type, HandleType type_other, const float3 &new_handle, float3 &handle, float3 &handle_other)
static void linear_interpolation(const T &a, const T &b, MutableSpan< T > dst)
constexpr ParallelGrainSize grain_size(int grain_size)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T interpolate(const T &a, const T &b, const FactorT &t)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
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)
VecBase< float, 2 > float2
VecBase< float, 3 > float3
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float