Cleanup: Rename variables, use shorter names
`src` and `dst` are perfectly clear, and avoid repeating unecessary characters when writing the variables many times, allowing more space for everything else.
This commit is contained in:
@@ -196,7 +196,7 @@ class Spline {
|
|||||||
* exceed the lifetime of the input data.
|
* exceed the lifetime of the input data.
|
||||||
*/
|
*/
|
||||||
virtual blender::fn::GVArrayPtr interpolate_to_evaluated(
|
virtual blender::fn::GVArrayPtr interpolate_to_evaluated(
|
||||||
const blender::fn::GVArray &source_data) const = 0;
|
const blender::fn::GVArray &src) const = 0;
|
||||||
blender::fn::GVArrayPtr interpolate_to_evaluated(blender::fn::GSpan data) const;
|
blender::fn::GVArrayPtr interpolate_to_evaluated(blender::fn::GSpan data) const;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
blender::fn::GVArray_Typed<T> interpolate_to_evaluated(blender::Span<T> data) const
|
blender::fn::GVArray_Typed<T> interpolate_to_evaluated(blender::Span<T> data) const
|
||||||
@@ -332,8 +332,7 @@ class BezierSpline final : public Spline {
|
|||||||
};
|
};
|
||||||
InterpolationData interpolation_data_from_index_factor(const float index_factor) const;
|
InterpolationData interpolation_data_from_index_factor(const float index_factor) const;
|
||||||
|
|
||||||
virtual blender::fn::GVArrayPtr interpolate_to_evaluated(
|
virtual blender::fn::GVArrayPtr interpolate_to_evaluated(const blender::fn::GVArray &src) const;
|
||||||
const blender::fn::GVArray &source_data) const override;
|
|
||||||
|
|
||||||
void evaluate_segment(const int index,
|
void evaluate_segment(const int index,
|
||||||
const int next_index,
|
const int next_index,
|
||||||
@@ -455,13 +454,12 @@ class NURBSpline final : public Spline {
|
|||||||
|
|
||||||
blender::Span<blender::float3> evaluated_positions() const final;
|
blender::Span<blender::float3> evaluated_positions() const final;
|
||||||
|
|
||||||
blender::fn::GVArrayPtr interpolate_to_evaluated(
|
blender::fn::GVArrayPtr interpolate_to_evaluated(const blender::fn::GVArray &src) const final;
|
||||||
const blender::fn::GVArray &source_data) const final;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void correct_end_tangents() const final;
|
void correct_end_tangents() const final;
|
||||||
void calculate_knots() const;
|
void calculate_knots() const;
|
||||||
void calculate_basis_cache() const;
|
blender::Span<BasisCache> calculate_basis_cache() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -505,8 +503,7 @@ class PolySpline final : public Spline {
|
|||||||
|
|
||||||
blender::Span<blender::float3> evaluated_positions() const final;
|
blender::Span<blender::float3> evaluated_positions() const final;
|
||||||
|
|
||||||
blender::fn::GVArrayPtr interpolate_to_evaluated(
|
blender::fn::GVArrayPtr interpolate_to_evaluated(const blender::fn::GVArray &src) const final;
|
||||||
const blender::fn::GVArray &source_data) const final;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void correct_end_tangents() const final;
|
void correct_end_tangents() const final;
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ using blender::float3;
|
|||||||
using blender::IndexRange;
|
using blender::IndexRange;
|
||||||
using blender::MutableSpan;
|
using blender::MutableSpan;
|
||||||
using blender::Span;
|
using blender::Span;
|
||||||
|
using blender::fn::GVArray;
|
||||||
|
using blender::fn::GVArray_For_ArrayContainer;
|
||||||
|
using blender::fn::GVArrayPtr;
|
||||||
|
|
||||||
SplinePtr BezierSpline::copy() const
|
SplinePtr BezierSpline::copy() const
|
||||||
{
|
{
|
||||||
@@ -546,44 +549,44 @@ BezierSpline::InterpolationData BezierSpline::interpolation_data_from_index_fact
|
|||||||
/* Use a spline argument to avoid adding this to the header. */
|
/* Use a spline argument to avoid adding this to the header. */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void interpolate_to_evaluated_impl(const BezierSpline &spline,
|
static void interpolate_to_evaluated_impl(const BezierSpline &spline,
|
||||||
const blender::VArray<T> &source_data,
|
const blender::VArray<T> &src,
|
||||||
MutableSpan<T> result_data)
|
MutableSpan<T> dst)
|
||||||
{
|
{
|
||||||
|
BLI_assert(src.size() == spline.size());
|
||||||
|
BLI_assert(dst.size() == spline.evaluated_points_size());
|
||||||
Span<float> mappings = spline.evaluated_mappings();
|
Span<float> mappings = spline.evaluated_mappings();
|
||||||
|
|
||||||
for (const int i : result_data.index_range()) {
|
for (const int i : dst.index_range()) {
|
||||||
BezierSpline::InterpolationData interp = spline.interpolation_data_from_index_factor(
|
BezierSpline::InterpolationData interp = spline.interpolation_data_from_index_factor(
|
||||||
mappings[i]);
|
mappings[i]);
|
||||||
|
|
||||||
const T &value = source_data[interp.control_point_index];
|
const T &value = src[interp.control_point_index];
|
||||||
const T &next_value = source_data[interp.next_control_point_index];
|
const T &next_value = src[interp.next_control_point_index];
|
||||||
|
|
||||||
result_data[i] = blender::attribute_math::mix2(interp.factor, value, next_value);
|
dst[i] = blender::attribute_math::mix2(interp.factor, value, next_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blender::fn::GVArrayPtr BezierSpline::interpolate_to_evaluated(
|
GVArrayPtr BezierSpline::interpolate_to_evaluated(const GVArray &src) const
|
||||||
const blender::fn::GVArray &source_data) const
|
|
||||||
{
|
{
|
||||||
BLI_assert(source_data.size() == this->size());
|
BLI_assert(src.size() == this->size());
|
||||||
|
|
||||||
if (source_data.is_single()) {
|
if (src.is_single()) {
|
||||||
return source_data.shallow_copy();
|
return src.shallow_copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int eval_size = this->evaluated_points_size();
|
const int eval_size = this->evaluated_points_size();
|
||||||
if (eval_size == 1) {
|
if (eval_size == 1) {
|
||||||
return source_data.shallow_copy();
|
return src.shallow_copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
blender::fn::GVArrayPtr new_varray;
|
GVArrayPtr new_varray;
|
||||||
blender::attribute_math::convert_to_static_type(source_data.type(), [&](auto dummy) {
|
blender::attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
|
||||||
using T = decltype(dummy);
|
using T = decltype(dummy);
|
||||||
if constexpr (!std::is_void_v<blender::attribute_math::DefaultMixer<T>>) {
|
if constexpr (!std::is_void_v<blender::attribute_math::DefaultMixer<T>>) {
|
||||||
Array<T> values(eval_size);
|
Array<T> values(eval_size);
|
||||||
interpolate_to_evaluated_impl<T>(*this, source_data.typed<T>(), values);
|
interpolate_to_evaluated_impl<T>(*this, src.typed<T>(), values);
|
||||||
new_varray = std::make_unique<blender::fn::GVArray_For_ArrayContainer<Array<T>>>(
|
new_varray = std::make_unique<GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
|
||||||
std::move(values));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ using blender::float3;
|
|||||||
using blender::IndexRange;
|
using blender::IndexRange;
|
||||||
using blender::MutableSpan;
|
using blender::MutableSpan;
|
||||||
using blender::Span;
|
using blender::Span;
|
||||||
|
using blender::fn::GVArray;
|
||||||
|
using blender::fn::GVArray_For_ArrayContainer;
|
||||||
using blender::fn::GVArray_Typed;
|
using blender::fn::GVArray_Typed;
|
||||||
|
using blender::fn::GVArrayPtr;
|
||||||
|
|
||||||
SplinePtr NURBSpline::copy() const
|
SplinePtr NURBSpline::copy() const
|
||||||
{
|
{
|
||||||
@@ -326,15 +329,15 @@ static void calculate_basis_for_point(const float parameter,
|
|||||||
basis_cache.start_index = start;
|
basis_cache.start_index = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NURBSpline::calculate_basis_cache() const
|
Span<NURBSpline::BasisCache> NURBSpline::calculate_basis_cache() const
|
||||||
{
|
{
|
||||||
if (!basis_cache_dirty_) {
|
if (!basis_cache_dirty_) {
|
||||||
return;
|
return basis_cache_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard lock{basis_cache_mutex_};
|
std::lock_guard lock{basis_cache_mutex_};
|
||||||
if (!basis_cache_dirty_) {
|
if (!basis_cache_dirty_) {
|
||||||
return;
|
return basis_cache_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int points_len = this->size();
|
const int points_len = this->size();
|
||||||
@@ -371,50 +374,47 @@ void NURBSpline::calculate_basis_cache() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
basis_cache_dirty_ = false;
|
basis_cache_dirty_ = false;
|
||||||
|
return basis_cache_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void interpolate_to_evaluated_impl(Span<NURBSpline::BasisCache> weights,
|
void interpolate_to_evaluated_impl(Span<NURBSpline::BasisCache> weights,
|
||||||
const blender::VArray<T> &source_data,
|
const blender::VArray<T> &src,
|
||||||
MutableSpan<T> result_data)
|
MutableSpan<T> dst)
|
||||||
{
|
{
|
||||||
const int points_len = source_data.size();
|
const int size = src.size();
|
||||||
BLI_assert(result_data.size() == weights.size());
|
BLI_assert(dst.size() == weights.size());
|
||||||
blender::attribute_math::DefaultMixer<T> mixer(result_data);
|
blender::attribute_math::DefaultMixer<T> mixer(dst);
|
||||||
|
|
||||||
for (const int i : result_data.index_range()) {
|
for (const int i : dst.index_range()) {
|
||||||
Span<float> point_weights = weights[i].weights;
|
Span<float> point_weights = weights[i].weights;
|
||||||
const int start_index = weights[i].start_index;
|
const int start_index = weights[i].start_index;
|
||||||
|
|
||||||
for (const int j : point_weights.index_range()) {
|
for (const int j : point_weights.index_range()) {
|
||||||
const int point_index = (start_index + j) % points_len;
|
const int point_index = (start_index + j) % size;
|
||||||
mixer.mix_in(i, source_data[point_index], point_weights[j]);
|
mixer.mix_in(i, src[point_index], point_weights[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mixer.finalize();
|
mixer.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
blender::fn::GVArrayPtr NURBSpline::interpolate_to_evaluated(
|
GVArrayPtr NURBSpline::interpolate_to_evaluated(const GVArray &src) const
|
||||||
const blender::fn::GVArray &source_data) const
|
|
||||||
{
|
{
|
||||||
BLI_assert(source_data.size() == this->size());
|
BLI_assert(src.size() == this->size());
|
||||||
|
|
||||||
if (source_data.is_single()) {
|
if (src.is_single()) {
|
||||||
return source_data.shallow_copy();
|
return src.shallow_copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->calculate_basis_cache();
|
Span<BasisCache> basis_cache = this->calculate_basis_cache();
|
||||||
Span<BasisCache> weights(basis_cache_);
|
|
||||||
|
|
||||||
blender::fn::GVArrayPtr new_varray;
|
GVArrayPtr new_varray;
|
||||||
blender::attribute_math::convert_to_static_type(source_data.type(), [&](auto dummy) {
|
blender::attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
|
||||||
using T = decltype(dummy);
|
using T = decltype(dummy);
|
||||||
if constexpr (!std::is_void_v<blender::attribute_math::DefaultMixer<T>>) {
|
if constexpr (!std::is_void_v<blender::attribute_math::DefaultMixer<T>>) {
|
||||||
Array<T> values(this->evaluated_points_size());
|
Array<T> values(this->evaluated_points_size());
|
||||||
interpolate_to_evaluated_impl<T>(weights, source_data.typed<T>(), values);
|
interpolate_to_evaluated_impl<T>(basis_cache, src.typed<T>(), values);
|
||||||
new_varray = std::make_unique<blender::fn::GVArray_For_ArrayContainer<Array<T>>>(
|
new_varray = std::make_unique<GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
|
||||||
std::move(values));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
using blender::float3;
|
using blender::float3;
|
||||||
using blender::MutableSpan;
|
using blender::MutableSpan;
|
||||||
using blender::Span;
|
using blender::Span;
|
||||||
|
using blender::fn::GVArray;
|
||||||
|
using blender::fn::GVArrayPtr;
|
||||||
|
|
||||||
SplinePtr PolySpline::copy() const
|
SplinePtr PolySpline::copy() const
|
||||||
{
|
{
|
||||||
@@ -115,10 +117,9 @@ Span<float3> PolySpline::evaluated_positions() const
|
|||||||
* the original data. Therefore the lifetime of the returned virtual array must not be longer than
|
* the original data. Therefore the lifetime of the returned virtual array must not be longer than
|
||||||
* the source data.
|
* the source data.
|
||||||
*/
|
*/
|
||||||
blender::fn::GVArrayPtr PolySpline::interpolate_to_evaluated(
|
GVArrayPtr PolySpline::interpolate_to_evaluated(const GVArray &src) const
|
||||||
const blender::fn::GVArray &source_data) const
|
|
||||||
{
|
{
|
||||||
BLI_assert(source_data.size() == this->size());
|
BLI_assert(src.size() == this->size());
|
||||||
|
|
||||||
return source_data.shallow_copy();
|
return src.shallow_copy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,8 +326,6 @@ static void geo_node_curve_to_points_exec(GeoNodeExecParams params)
|
|||||||
|
|
||||||
geometry_set = bke::geometry_set_realize_instances(geometry_set);
|
geometry_set = bke::geometry_set_realize_instances(geometry_set);
|
||||||
|
|
||||||
SCOPED_TIMER(__func__);
|
|
||||||
|
|
||||||
if (!geometry_set.has_curve()) {
|
if (!geometry_set.has_curve()) {
|
||||||
params.set_output("Geometry", GeometrySet());
|
params.set_output("Geometry", GeometrySet());
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user