33 [&](
const int curve_i) {
34 const IndexRange src_points = src_points_by_curve[curve_i];
41 if (src_points.
size() == 1) {
42 point_counts.
first() = 1;
46 for (
int &count : point_counts) {
48 count = std::max(count, 0) + 1;
50 if (!cyclic[curve_i]) {
52 point_counts.last() = 1;
57 dst_curve_offsets[curve_i] = point_offsets.
last();
67 const float step = 1.0f / dst.
size();
82 [&](
const int curve_i) {
83 const IndexRange src_points = src_points_by_curve[curve_i];
87 const IndexRange dst_points = dst_points_by_curve[curve_i];
92 for (const int i : range) {
93 const IndexRange segment_points = curve_offsets[i];
94 linear_interpolation(curve_src[i], curve_src[i + 1], curve_dst.slice(segment_points));
98 const IndexRange dst_last_segment = dst_points.
slice(curve_offsets[src_points.size() - 1]);
112 if constexpr (!std::is_same_v<T, std::string>) {
113 subdivide_attribute_linear(src_points_by_curve,
132 [&](
const int curve_i) {
133 const IndexRange src_points = src_points_by_curve[curve_i];
136 const IndexRange dst_points = dst_points_by_curve[curve_i];
139 all_point_offsets.
slice(src_segments),
140 dst.
slice(dst_points));
162 const float3 &handle_prev,
163 const float3 &handle_next,
164 const float3 &position_next,
168 const int dst_next_segment_start,
185 dst_positions[segment_points.
first()] = position_prev;
190 float3 segment_start = position_prev;
191 float3 segment_handle_prev = handle_prev;
192 float3 segment_handle_next = handle_next;
193 const float3 segment_end = position_next;
196 const float parameter = 1.0f / (segment_points.
size() - i);
197 const int point_i = segment_points[i];
199 segment_start, segment_handle_prev, segment_handle_next, segment_end, parameter);
213 dst_handles_r[segment_points.
last()] = segment_handle_prev;
214 dst_handles_l[dst_next_segment_start] = segment_handle_next;
240 for (const int segment_i : range) {
241 const IndexRange segment = evaluated_offsets[segment_i];
242 subdivide_bezier_segment(src_positions[segment_i],
243 src_handles_r[segment_i],
244 src_handles_l[segment_i + 1],
245 src_positions[segment_i + 1],
246 HandleType(src_types_r[segment_i]),
247 HandleType(src_types_l[segment_i + 1]),
249 segment.one_after_last(),
259 const int last_index = src_positions.index_range().last();
260 const IndexRange segment = evaluated_offsets[last_index];
261 subdivide_bezier_segment(src_positions.last(),
262 src_handles_r.last(),
263 src_handles_l.first(),
264 src_positions.first(),
276 dst_positions.last() = src_positions.last();
277 dst_types_l.first() = src_types_l.first();
278 dst_types_r.last() = src_types_r.last();
279 dst_handles_l.first() = src_handles_l.first();
280 dst_handles_r.last() = src_handles_r.last();
284 bke::curves::bezier::calculate_auto_handles(
285 cyclic, dst_types_l, dst_types_r, dst_positions, dst_handles_l, dst_handles_r);
321 all_point_offset_data.
fill(-1);
329 all_point_offset_data);
332 const Span<int> all_point_offsets(all_point_offset_data);
343 auto subdivide_catmull_rom = [&](
const IndexMask &selection) {
344 for (
auto &
attribute : attributes_to_transfer) {
355 auto subdivide_poly = [&](
const IndexMask &selection) {
356 for (
auto &
attribute : attributes_to_transfer) {
366 auto subdivide_bezier = [&](
const IndexMask &selection) {
381 [&](
const int curve_i) {
382 const IndexRange src_points = src_points_by_curve[curve_i];
385 const IndexRange dst_points = dst_points_by_curve[curve_i];
387 src_types_l.
slice(src_points),
388 src_types_r.
slice(src_points),
389 src_handles_l.
slice(src_points),
390 src_handles_r.
slice(src_points),
391 all_point_offsets.
slice(src_segments),
393 dst_positions.
slice(dst_points),
394 dst_types_l.
slice(dst_points),
395 dst_types_r.
slice(dst_points),
396 dst_handles_l.
slice(dst_points),
397 dst_handles_r.
slice(dst_points));
403 "position",
"handle_type_left",
"handle_type_right",
"handle_right",
"handle_left"};
404 for (
auto &
attribute : attributes_to_transfer) {
419 auto subdivide_nurbs = subdivide_poly;
424 subdivide_catmull_rom,
429 for (
auto &
attribute : attributes_to_transfer) {
431 src_points_by_curve, dst_points_by_curve, unselected,
attribute.src,
attribute.dst.span);
Low-level operations for curves.
Low-level operations for curves.
__forceinline const float4 insert(const float4 &a, const float b)
#define BLI_assert_unreachable()
void fill(const T &value) const
GMutableSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
GSpan slice(const int64_t start, int64_t size) 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 slice(int64_t start, int64_t size) 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 MutableSpan drop_back(const int64_t n) const
constexpr void fill(const T &value) const
constexpr T & first() const
constexpr IndexRange index_range() 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
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
MutableSpan< int8_t > handle_types_left_for_write()
VArray< int8_t > curve_types() const
MutableSpan< float3 > positions_for_write()
MutableSpan< int8_t > handle_types_right_for_write()
std::optional< Span< float3 > > handle_positions_right() const
void resize(int points_num, int curves_num)
VArray< bool > cyclic() const
AttributeAccessor attributes() const
Span< float3 > positions() const
MutableSpan< float3 > handle_positions_right_for_write()
std::optional< Span< float3 > > handle_positions_left() const
IndexRange curves_range() const
VArray< int8_t > handle_types_left() const
MutableSpan< float3 > handle_positions_left_for_write()
Span< int > offsets() const
MutableSpan< int > offsets_for_write()
const std::array< int, CURVE_TYPES_NUM > & curve_type_counts() const
VArray< int8_t > handle_types_right() const
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
constexpr Span slice(int64_t start, int64_t size) 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 copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
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)
bool segment_is_vector(const HandleType left, const HandleType right)
void interpolate_to_evaluated(GSpan src, bool cyclic, int resolution, GMutableSpan dst)
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)
IndexRange per_curve_point_offsets_range(const IndexRange points, const int curve_index)
void foreach_curve_by_type(const VArray< int8_t > &types, const std::array< int, CURVE_TYPES_NUM > &type_counts, const IndexMask &selection, FunctionRef< void(IndexMask)> catmull_rom_fn, FunctionRef< void(IndexMask)> poly_fn, FunctionRef< void(IndexMask)> bezier_fn, FunctionRef< void(IndexMask)> nurbs_fn)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
constexpr ParallelGrainSize grain_size(int grain_size)
static HandleType aligned_or_free_handle_type(const HandleType type)
static void calculate_result_offsets(const OffsetIndices< int > src_points_by_curve, const IndexMask &selection, const IndexMask &unselected, const VArray< float > &radii, const VArray< int > &counts, const Span< bool > cyclic, MutableSpan< int > dst_curve_offsets, MutableSpan< int > dst_point_offsets)
static void subdivide_bezier_positions(const Span< float3 > src_positions, const Span< int8_t > src_types_l, const Span< int8_t > src_types_r, const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, const OffsetIndices< int > evaluated_offsets, const bool cyclic, MutableSpan< float3 > dst_positions, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r)
static void linear_interpolation(const T &a, const T &b, MutableSpan< T > dst)
bke::CurvesGeometry subdivide_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const VArray< int > &cuts, const bke::AttributeFilter &attribute_filter={})
static void subdivide_attribute_catmull_rom(const OffsetIndices< int > src_points_by_curve, const OffsetIndices< int > dst_points_by_curve, const IndexMask &selection, const Span< int > all_point_offsets, const Span< bool > cyclic, const GSpan src, GMutableSpan dst)
static void subdivide_bezier_segment(const float3 &position_prev, const float3 &handle_prev, const float3 &handle_next, const float3 &position_next, const HandleType type_prev, const HandleType type_next, const IndexRange segment_points, const int dst_next_segment_start, MutableSpan< float3 > dst_positions, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r)
static void subdivide_attribute_linear(const OffsetIndices< int > src_points_by_curve, const OffsetIndices< int > dst_points_by_curve, const IndexMask &selection, const Span< int > all_point_offsets, const Span< T > src, MutableSpan< T > dst)
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)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
VecBase< float, 3 > float3
ListBaseT< struct bDeformGroup > vertex_group_names