39 const float sample_length,
40 const bool keep_last_segment)
44 if (sample_length == 0.0f) [[unlikely]] {
47 const int count = int(curve_length / sample_length) + 1;
48 return std::max(keep_last_segment ? 2 : 1, count);
52 const bool keep_last_segment)
54 static auto get_count_fn = mf::build::SI3_SO<float, float, bool, int>(
55 "Length Input to Count",
57 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
73 const std::array<int, CURVE_TYPES_NUM> &type_counts)
78 if (
ELEM(name,
"handle_type_left",
"handle_type_right",
"handle_left",
"handle_right")) {
81 if (
ELEM(name,
"nurbs_weight")) {
99 return !no_interpolation.
contains(name);
125 src_arrays.
append(std::move(src_attribute));
130 dst_writers.
append(std::move(dst_attribute));
190 result.src_no_interpolation,
191 result.dst_no_interpolation,
200 result.dst_attributes.append(std::move(dst_attribute));
207 result.dst_attributes.append(std::move(dst_attribute));
224 for (
const int i : attributes.
src.index_range()) {
251 for (
const int i :
data.index_range()) {
260 for (
const int i_curve : curve_selection) {
278 const int64_t size_in_bytes =
sizeof(
T) * size;
282 this->heap_allocated.
resize(size_in_bytes);
330 for (
const int i_curve : selection_segment) {
331 const bool cyclic = curves_cyclic[i_curve];
332 const IndexRange dst_points = dst_points_by_curve[i_curve];
342 !curves_cyclic[i_curve],
350 for (
const int i_attribute : attributes.
dst.index_range()) {
351 const CPPType &type = attributes.
src[i_attribute].type();
353 if constexpr (!std::is_same_v<T, std::string>) {
354 Span<T> src = attributes.
src[i_attribute].typed<
T>();
357 for (
const int i_curve : selection_segment) {
358 const IndexRange src_points = src_points_by_curve[i_curve];
359 const IndexRange dst_points = dst_points_by_curve[i_curve];
363 sample_indices.
as_span().slice(dst_points),
364 sample_factors.
as_span().slice(dst_points),
365 dst.slice(dst_points));
369 evaluated_points_by_curve[i_curve].
size());
373 sample_indices.
as_span().slice(dst_points),
374 sample_factors.
as_span().slice(dst_points),
375 dst.slice(dst_points));
383 for (
const int i_curve : selection_segment) {
384 const IndexRange src_points = evaluated_points_by_curve[i_curve];
385 const IndexRange dst_points = dst_points_by_curve[i_curve];
387 sample_indices.
as_span().slice(dst_points),
388 sample_factors.
as_span().slice(dst_points),
389 dst.slice(dst_points));
394 interpolate_evaluated_data(evaluated_positions, dst_positions);
399 selection_segment, dst_points_by_curve, attributes.
dst_tangents);
404 selection_segment, dst_points_by_curve, attributes.
dst_normals);
409 for (
const int i_curve : selection_segment) {
410 const IndexRange dst_points = dst_points_by_curve[i_curve];
488 [&](
const int count) { return count > 0; }));
515 const bool keep_last_segment)
530 [&](
const int curve_i) {
532 curve_i, curves_cyclic[curve_i]);
534 curve_length, sample_lengths[curve_i], keep_last_segment);
557 const bool keep_last_segment)
601 for (
const int i_attribute : attributes.
dst.index_range()) {
602 for (
const int i_curve : selection_segment) {
603 const IndexRange src_points = src_points_by_curve[i_curve];
604 const IndexRange dst_points = dst_points_by_curve[i_curve];
606 attributes.
src[i_attribute].slice(src_points),
607 attributes.
dst[i_attribute].slice(dst_points));
612 for (
const int i_curve : selection_segment) {
613 const IndexRange src_points = src_evaluated_points_by_curve[i_curve];
614 const IndexRange dst_points = dst_points_by_curve[i_curve];
615 dst.
slice(dst_points).copy_from(src.
slice(src_points));
620 copy_evaluated_data(evaluated_positions, dst_positions);
625 selection_segment, dst_points_by_curve, attributes.
dst_tangents);
630 selection_segment, dst_points_by_curve, attributes.
dst_normals);
635 for (
const int i_curve : selection_segment) {
636 const IndexRange dst_points = dst_points_by_curve[i_curve];
Low-level operations for curves.
Low-level operations for curves.
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
void value_initialize_n(void *ptr, int64_t n) const
GMutableSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
MutableSpan< T > typed() const
CommonVArrayInfo common_info() const
const CPPType & type() const
static constexpr size_t min_alignment
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr MutableSpan< NewT > cast() const
constexpr MutableSpan drop_back(const int64_t n) const
constexpr Span< T > as_span() const
constexpr T * end() const
constexpr T * begin() const
constexpr T & last(const int64_t n=0) const
bool contains(const Key &key) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void add_new(const Key &key)
void remove_contained(const Key &key)
void append(const T &value)
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader lookup(const StringRef name) const
Span< float3 > evaluated_tangents() const
VArray< int8_t > curve_types() const
void ensure_can_interpolate_to_evaluated() const
MutableSpan< float3 > positions_for_write()
void resize(int points_num, int curves_num)
VArray< bool > cyclic() const
AttributeAccessor attributes() const
Span< float3 > positions() const
void interpolate_to_evaluated(int curve_index, GSpan src, GMutableSpan dst) const
IndexRange curves_range() const
Span< float > evaluated_lengths_for_curve(int curve_index, bool cyclic) const
void ensure_evaluated_lengths() const
OffsetIndices< int > evaluated_points_by_curve() const
MutableSpan< int > offsets_for_write()
void fill_curve_types(CurveType type)
const std::array< int, CURVE_TYPES_NUM > & curve_type_counts() const
Span< float3 > evaluated_positions() const
float evaluated_length_total_for_curve(int curve_index, bool cyclic) const
OffsetIndices< int > points_by_curve() const
Span< float3 > evaluated_normals() const
MutableAttributeAccessor attributes_for_write()
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
void set_selection(Field< bool > selection)
IndexMask get_evaluated_selection_as_mask() const
int add_with_destination(GField field, GVMutableArray dst)
static FieldOperationPtr from(std::shared_ptr< const mf::MultiFunction > fn, Vector< GField > inputs)
static Field from_input(Args &&...args)
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
OffsetIndices slice(const IndexRange range) const
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void to_static_type(const CPPType &cpp_type, Fn &&fn)
void copy_custom_knots(const bke::CurvesGeometry &src_curves, const IndexMask &exclude_curves, bke::CurvesGeometry &dst_curves)
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
void fill_points(OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, GPointer value, GMutableSpan dst)
bool attribute_name_is_anonymous(const StringRef name)
AttrType cpp_type_to_attribute_type(const CPPType &type)
constexpr ParallelGrainSize grain_size(int grain_size)
const MultiFunction & lookup(UString id)
static AttributesForInterpolation retrieve_attribute_spans(const Span< StringRef > names, const CurvesGeometry &src_from_curves, const CurvesGeometry &src_to_curves, const bke::AttrDomain domain, CurvesGeometry &dst_curves)
static fn::Field< int > get_count_input_max_one(const fn::Field< int > &count_field)
static void normalize_span(MutableSpan< float3 > data)
static void copy_or_defaults_for_unselected_curves(const CurvesGeometry &src_curves, const IndexMask &unselected_curves, const AttributesForResample &attributes, CurvesGeometry &dst_curves)
CurvesGeometry resample_to_count(const CurvesGeometry &src_curves, const IndexMask &selection, const VArray< int > &counts, const ResampleCurvesOutputAttributeIDs &output_ids={})
CurvesGeometry resample_to_evaluated(const CurvesGeometry &src_curves, const IndexMask &selection, const ResampleCurvesOutputAttributeIDs &output_ids={})
static int get_count_from_length(const float curve_length, const float sample_length, const bool keep_last_segment)
CurvesGeometry resample_to_length(const CurvesGeometry &src_curves, const IndexMask &selection, const VArray< float > &sample_lengths, const ResampleCurvesOutputAttributeIDs &output_ids={}, bool keep_last_segment=false)
static bool interpolate_attribute_to_curves(const StringRef name, const std::array< int, CURVE_TYPES_NUM > &type_counts)
static void resample_to_uniform(const CurvesGeometry &src_curves, const IndexMask &selection, const ResampleCurvesOutputAttributeIDs &output_ids, CurvesGeometry &dst_curves)
static AttributesForInterpolation gather_point_attributes_to_interpolate(const CurvesGeometry &from_curves, const CurvesGeometry &to_curves, CurvesGeometry &dst_curves)
static bool interpolate_attribute_to_poly_curve(const StringRef name)
static fn::Field< int > get_count_input_from_length(const fn::Field< float > &length_field, const bool keep_last_segment)
static void normalize_curve_point_data(const IndexMaskSegment curve_selection, const OffsetIndices< int > points_by_curve, MutableSpan< float3 > data)
void interpolate(const Span< T > src, const Span< int > indices, const Span< float > factors, MutableSpan< T > dst)
void sample_uniform(Span< float > accumulated_segment_lengths, bool include_last_point, MutableSpan< int > r_segment_indices, MutableSpan< float > r_factors)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void copy_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask, MutableSpan< int > sizes)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
std::optional< OffsetIndices< int > > accumulate_counts_to_offsets_with_overflow_check(MutableSpan< int > counts_to_offsets, int start_offset=0)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMesh const char void * data
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
VecBase< float, 3 > float3
ListBaseT< struct bDeformGroup > vertex_group_names
Span< float3 > src_evaluated_tangents
MutableSpan< float3 > dst_normals
Vector< bke::GSpanAttributeWriter > dst_attributes
Vector< GMutableSpan > dst_no_interpolation
Vector< GVArraySpan > src
Vector< GVArraySpan > src_no_interpolation
MutableSpan< float3 > dst_tangents
Span< float3 > src_evaluated_normals
Vector< GMutableSpan > dst
GuardedAlignedAllocator<> AllocatorType
MutableSpan< T > resize(const int64_t size)
std::array< std::byte, 1024 > inline_buffer
Vector< std::byte, 0, AllocatorType > heap_allocated
std::optional< std::string > tangent_id
std::optional< std::string > normal_id