Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curves_geometry.cc
| Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | static void copy_curves_geometry(CurvesGeometry &dst, const CurvesGeometry &src) | ||||
| CustomData_copy(&src.curve_data, &dst.curve_data, CD_MASK_ALL, CD_DUPLICATE, dst.curve_size); | CustomData_copy(&src.curve_data, &dst.curve_data, CD_MASK_ALL, CD_DUPLICATE, dst.curve_size); | ||||
| MEM_SAFE_FREE(dst.curve_offsets); | MEM_SAFE_FREE(dst.curve_offsets); | ||||
| dst.curve_offsets = (int *)MEM_calloc_arrayN(dst.point_size + 1, sizeof(int), __func__); | dst.curve_offsets = (int *)MEM_calloc_arrayN(dst.point_size + 1, sizeof(int), __func__); | ||||
| dst.offsets_for_write().copy_from(src.offsets()); | dst.offsets_for_write().copy_from(src.offsets()); | ||||
| dst.tag_topology_changed(); | dst.tag_topology_changed(); | ||||
| /* Though type counts are a cache, they must be copied because they are calculated eagerly. */ | |||||
| dst.runtime->type_counts = src.runtime->type_counts; | |||||
| dst.update_customdata_pointers(); | dst.update_customdata_pointers(); | ||||
| } | } | ||||
| CurvesGeometry::CurvesGeometry(const CurvesGeometry &other) | CurvesGeometry::CurvesGeometry(const CurvesGeometry &other) | ||||
| : CurvesGeometry(other.point_size, other.curve_size) | : CurvesGeometry(other.point_size, other.curve_size) | ||||
| { | { | ||||
| copy_curves_geometry(*this, other); | copy_curves_geometry(*this, other); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | return get_varray_attribute<int8_t>( | ||||
| *this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE, CURVE_TYPE_CATMULL_ROM); | *this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE, CURVE_TYPE_CATMULL_ROM); | ||||
| } | } | ||||
| MutableSpan<int8_t> CurvesGeometry::curve_types_for_write() | MutableSpan<int8_t> CurvesGeometry::curve_types_for_write() | ||||
| { | { | ||||
| return get_mutable_attribute<int8_t>(*this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE); | return get_mutable_attribute<int8_t>(*this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE); | ||||
| } | } | ||||
| bool CurvesGeometry::has_curve_with_type(const CurveType type) const | void CurvesGeometry::fill_curve_types(const CurveType type) | ||||
| { | { | ||||
| const VArray<int8_t> curve_types = this->curve_types(); | this->curve_types_for_write().fill(type); | ||||
| if (curve_types.is_single()) { | this->runtime->type_counts.fill(0); | ||||
| return curve_types.get_internal_single() == type; | this->runtime->type_counts[type] = this->curves_num(); | ||||
| } | |||||
| if (curve_types.is_span()) { | |||||
| return curve_types.get_internal_span().contains(type); | |||||
| } | } | ||||
| /* The curves types array should be a single value or a span. */ | |||||
| BLI_assert_unreachable(); | void CurvesGeometry::fill_curve_types(const IndexMask selection, const CurveType type) | ||||
| return false; | { | ||||
| /* A potential performance optimization is only counting the changed indices. */ | |||||
| this->curve_types_for_write().fill_indices(selection, type); | |||||
| this->update_curve_types(); | |||||
| this->runtime->type_counts.fill(0); | |||||
JacquesLucke: This looks wrong, because it removes info about all other curves. | |||||
HooglyBooglyAuthorUnsubmitted Done Inline ActionsOops, good catch. Yeah, copy and paste error. HooglyBoogly: Oops, good catch. Yeah, copy and paste error. | |||||
| this->runtime->type_counts[type] = this->curves_num(); | |||||
| } | } | ||||
| std::array<int, CURVE_TYPES_NUM> CurvesGeometry::count_curve_types() const | std::array<int, CURVE_TYPES_NUM> calculate_type_counts(const VArray<int8_t> &types) | ||||
| { | { | ||||
| using CountsType = std::array<int, CURVE_TYPES_NUM>; | using CountsType = std::array<int, CURVE_TYPES_NUM>; | ||||
| CountsType counts; | |||||
| counts.fill(0); | |||||
| CountsType identity; | |||||
| identity.fill(0); | |||||
| const VArray<int8_t> types = this->curve_types(); | |||||
| if (types.is_single()) { | if (types.is_single()) { | ||||
| identity[types.get_internal_single()] = this->curves_num(); | counts[types.get_internal_single()] = types.size(); | ||||
| return identity; | return counts; | ||||
| } | } | ||||
| Span<int8_t> types_span = types.get_internal_span(); | Span<int8_t> types_span = types.get_internal_span(); | ||||
| return threading::parallel_reduce( | return threading::parallel_reduce( | ||||
| this->curves_range(), | types.index_range(), | ||||
| 2048, | 2048, | ||||
| identity, | counts, | ||||
| [&](const IndexRange curves_range, const CountsType &init) { | [&](const IndexRange curves_range, const CountsType &init) { | ||||
| CountsType result = init; | CountsType result = init; | ||||
| for (const int curve_index : curves_range) { | for (const int curve_index : curves_range) { | ||||
| result[types_span[curve_index]]++; | result[types_span[curve_index]]++; | ||||
| } | } | ||||
| return result; | return result; | ||||
| }, | }, | ||||
| [](const CountsType &a, const CountsType &b) { | [](const CountsType &a, const CountsType &b) { | ||||
| CountsType result = a; | CountsType result = a; | ||||
| for (const int i : IndexRange(CURVE_TYPES_NUM)) { | for (const int i : IndexRange(CURVE_TYPES_NUM)) { | ||||
| result[i] += b[i]; | result[i] += b[i]; | ||||
| } | } | ||||
| return result; | return result; | ||||
| }); | }); | ||||
| } | } | ||||
| void CurvesGeometry::update_curve_types() | |||||
| { | |||||
| this->runtime->type_counts = calculate_type_counts(this->curve_types()); | |||||
| } | |||||
| Span<float3> CurvesGeometry::positions() const | Span<float3> CurvesGeometry::positions() const | ||||
| { | { | ||||
| return {(const float3 *)this->position, this->point_size}; | return {(const float3 *)this->position, this->point_size}; | ||||
| } | } | ||||
| MutableSpan<float3> CurvesGeometry::positions_for_write() | MutableSpan<float3> CurvesGeometry::positions_for_write() | ||||
| { | { | ||||
| this->position = (float(*)[3])CustomData_duplicate_referenced_layer_named( | this->position = (float(*)[3])CustomData_duplicate_referenced_layer_named( | ||||
| &this->point_data, CD_PROP_FLOAT3, ATTR_POSITION.c_str(), this->point_size); | &this->point_data, CD_PROP_FLOAT3, ATTR_POSITION.c_str(), this->point_size); | ||||
| ▲ Show 20 Lines • Show All 983 Lines • ▼ Show 20 Lines | attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | ||||
| reverse_curve_point_data<T>( | reverse_curve_point_data<T>( | ||||
| *this, curves_to_reverse, {static_cast<T *>(layer.data), this->points_num()}); | *this, curves_to_reverse, {static_cast<T *>(layer.data), this->points_num()}); | ||||
| }); | }); | ||||
| } | } | ||||
| /* In order to maintain the shape of Bezier curves, handle attributes must reverse, but also the | /* In order to maintain the shape of Bezier curves, handle attributes must reverse, but also the | ||||
| * values for the left and right must swap. Use a utility to swap and reverse at the same time, | * values for the left and right must swap. Use a utility to swap and reverse at the same time, | ||||
| * to avoid loading the attribute twice. Generally we can expect the right layer to exist when | * to avoid loading the attribute twice. Generally we can expect the right layer to exist when | ||||
| * the left does, but there's no need to count on it, so check for both attributes. */ | * the left does, but there's no need to count on it, so check for both attributes. */ | ||||
Done Inline Actions/home/jacques/blender/blender/source/blender/blenkernel/intern/curves_geometry.cc:1425:6: error: no declaration matches ‘void blender::bke::CurvesGeometry::remove_attributes_based_on_curve_types()’
1425 | void CurvesGeometry::remove_attributes_based_on_curve_types()
| ^~~~~~~~~~~~~~
/home/jacques/blender/blender/source/blender/blenkernel/intern/curves_geometry.cc:1425:6: note: no functions named ‘void blender::bke::CurvesGeometry::remove_attributes_based_on_curve_types()’
In file included from /home/jacques/blender/blender/source/blender/blenkernel/intern/curves_geometry.cc:20:
/home/jacques/blender/blender/source/blender/blenkernel/BKE_curves.hh:116:7: note: ‘class blender::bke::CurvesGeometry’ defined here
116 | class CurvesGeometry : public ::CurvesGeometry {
| ^~~~~~~~~~~~~~JacquesLucke: ```
/home/jacques/blender/blender/source/blender/blenkernel/intern/curves_geometry.cc:1425:6… | |||||
Done Inline ActionsOops, WIP code somehow made it into this patch, sorry. HooglyBoogly: Oops, WIP code somehow made it into this patch, sorry. | |||||
This looks wrong, because it removes info about all other curves.