Cleanup: Rename spline interpolation functions
The names were slightly longer than they needed to be clear, and when they are shorter they tend to fit on one line better.
This commit is contained in:
parent
a1c3e45100
commit
feb6fd632f
|
@ -49,7 +49,7 @@ using SplinePtr = std::unique_ptr<Spline>;
|
|||
* evaluation happens in a layer on top of the evaluated points generated by the derived types.
|
||||
*
|
||||
* There are a few methods to evaluate a spline:
|
||||
* 1. #evaluated_positions and #interpolate_to_evaluated_points give data for the initial
|
||||
* 1. #evaluated_positions and #interpolate_to_evaluated give data for the initial
|
||||
* evaluated points, depending on the resolution.
|
||||
* 2. #lookup_evaluated_factor and #lookup_evaluated_factor are meant for one-off lookups
|
||||
* along the length of a curve.
|
||||
|
@ -171,23 +171,23 @@ class Spline {
|
|||
blender::Array<float> sample_uniform_index_factors(const int samples_size) const;
|
||||
LookupResult lookup_data_from_index_factor(const float index_factor) const;
|
||||
|
||||
void sample_based_on_index_factors(const blender::fn::GVArray &src,
|
||||
blender::Span<float> index_factors,
|
||||
blender::fn::GMutableSpan dst) const;
|
||||
void sample_with_index_factors(const blender::fn::GVArray &src,
|
||||
blender::Span<float> index_factors,
|
||||
blender::fn::GMutableSpan dst) const;
|
||||
template<typename T>
|
||||
void sample_based_on_index_factors(const blender::VArray<T> &src,
|
||||
blender::Span<float> index_factors,
|
||||
blender::MutableSpan<T> dst) const
|
||||
void sample_with_index_factors(const blender::VArray<T> &src,
|
||||
blender::Span<float> index_factors,
|
||||
blender::MutableSpan<T> dst) const
|
||||
{
|
||||
this->sample_based_on_index_factors(
|
||||
this->sample_with_index_factors(
|
||||
blender::fn::GVArray_For_VArray(src), index_factors, blender::fn::GMutableSpan(dst));
|
||||
}
|
||||
template<typename T>
|
||||
void sample_based_on_index_factors(blender::Span<T> src,
|
||||
blender::Span<float> index_factors,
|
||||
blender::MutableSpan<T> dst) const
|
||||
void sample_with_index_factors(blender::Span<T> src,
|
||||
blender::Span<float> index_factors,
|
||||
blender::MutableSpan<T> dst) const
|
||||
{
|
||||
this->sample_based_on_index_factors(blender::VArray_For_Span(src), index_factors, dst);
|
||||
this->sample_with_index_factors(blender::VArray_For_Span(src), index_factors, dst);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,14 +195,13 @@ class Spline {
|
|||
* evaluated points. For poly splines, the lifetime of the returned virtual array must not
|
||||
* exceed the lifetime of the input data.
|
||||
*/
|
||||
virtual blender::fn::GVArrayPtr interpolate_to_evaluated_points(
|
||||
virtual blender::fn::GVArrayPtr interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const = 0;
|
||||
blender::fn::GVArrayPtr interpolate_to_evaluated_points(blender::fn::GSpan data) const;
|
||||
blender::fn::GVArrayPtr interpolate_to_evaluated(blender::fn::GSpan data) const;
|
||||
template<typename T>
|
||||
blender::fn::GVArray_Typed<T> interpolate_to_evaluated_points(blender::Span<T> data) const
|
||||
blender::fn::GVArray_Typed<T> interpolate_to_evaluated(blender::Span<T> data) const
|
||||
{
|
||||
return blender::fn::GVArray_Typed<T>(
|
||||
this->interpolate_to_evaluated_points(blender::fn::GSpan(data)));
|
||||
return blender::fn::GVArray_Typed<T>(this->interpolate_to_evaluated(blender::fn::GSpan(data)));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -333,7 +332,7 @@ class BezierSpline final : public Spline {
|
|||
};
|
||||
InterpolationData interpolation_data_from_index_factor(const float index_factor) const;
|
||||
|
||||
virtual blender::fn::GVArrayPtr interpolate_to_evaluated_points(
|
||||
virtual blender::fn::GVArrayPtr interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const override;
|
||||
|
||||
void evaluate_segment(const int index,
|
||||
|
@ -456,7 +455,7 @@ class NURBSpline final : public Spline {
|
|||
|
||||
blender::Span<blender::float3> evaluated_positions() const final;
|
||||
|
||||
blender::fn::GVArrayPtr interpolate_to_evaluated_points(
|
||||
blender::fn::GVArrayPtr interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const final;
|
||||
|
||||
protected:
|
||||
|
@ -506,7 +505,7 @@ class PolySpline final : public Spline {
|
|||
|
||||
blender::Span<blender::float3> evaluated_positions() const final;
|
||||
|
||||
blender::fn::GVArrayPtr interpolate_to_evaluated_points(
|
||||
blender::fn::GVArrayPtr interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const final;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -331,7 +331,7 @@ Span<float3> Spline::evaluated_normals() const
|
|||
}
|
||||
|
||||
/* Rotate the generated normals with the interpolated tilt data. */
|
||||
GVArray_Typed<float> tilts = this->interpolate_to_evaluated_points(this->tilts());
|
||||
GVArray_Typed<float> tilts = this->interpolate_to_evaluated(this->tilts());
|
||||
for (const int i : normals.index_range()) {
|
||||
normals[i] = rotate_direction_around_axis(normals[i], tangents[i], tilts[i]);
|
||||
}
|
||||
|
@ -438,9 +438,9 @@ void Spline::bounds_min_max(float3 &min, float3 &max, const bool use_evaluated)
|
|||
}
|
||||
}
|
||||
|
||||
GVArrayPtr Spline::interpolate_to_evaluated_points(GSpan data) const
|
||||
GVArrayPtr Spline::interpolate_to_evaluated(GSpan data) const
|
||||
{
|
||||
return this->interpolate_to_evaluated_points(GVArray_For_GSpan(data));
|
||||
return this->interpolate_to_evaluated(GVArray_For_GSpan(data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -448,9 +448,9 @@ GVArrayPtr Spline::interpolate_to_evaluated_points(GSpan data) const
|
|||
* points) to arbitrary parameters in between the evaluated points. The interpolation is quite
|
||||
* simple, but this handles the cyclic and end point special cases.
|
||||
*/
|
||||
void Spline::sample_based_on_index_factors(const GVArray &src,
|
||||
Span<float> index_factors,
|
||||
GMutableSpan dst) const
|
||||
void Spline::sample_with_index_factors(const GVArray &src,
|
||||
Span<float> index_factors,
|
||||
GMutableSpan dst) const
|
||||
{
|
||||
BLI_assert(src.size() == this->evaluated_points_size());
|
||||
|
||||
|
|
|
@ -545,9 +545,9 @@ BezierSpline::InterpolationData BezierSpline::interpolation_data_from_index_fact
|
|||
|
||||
/* Use a spline argument to avoid adding this to the header. */
|
||||
template<typename T>
|
||||
static void interpolate_to_evaluated_points_impl(const BezierSpline &spline,
|
||||
const blender::VArray<T> &source_data,
|
||||
MutableSpan<T> result_data)
|
||||
static void interpolate_to_evaluated_impl(const BezierSpline &spline,
|
||||
const blender::VArray<T> &source_data,
|
||||
MutableSpan<T> result_data)
|
||||
{
|
||||
Span<float> mappings = spline.evaluated_mappings();
|
||||
|
||||
|
@ -562,7 +562,7 @@ static void interpolate_to_evaluated_points_impl(const BezierSpline &spline,
|
|||
}
|
||||
}
|
||||
|
||||
blender::fn::GVArrayPtr BezierSpline::interpolate_to_evaluated_points(
|
||||
blender::fn::GVArrayPtr BezierSpline::interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const
|
||||
{
|
||||
BLI_assert(source_data.size() == this->size());
|
||||
|
@ -581,7 +581,7 @@ blender::fn::GVArrayPtr BezierSpline::interpolate_to_evaluated_points(
|
|||
using T = decltype(dummy);
|
||||
if constexpr (!std::is_void_v<blender::attribute_math::DefaultMixer<T>>) {
|
||||
Array<T> values(eval_size);
|
||||
interpolate_to_evaluated_points_impl<T>(*this, source_data.typed<T>(), values);
|
||||
interpolate_to_evaluated_impl<T>(*this, source_data.typed<T>(), values);
|
||||
new_varray = std::make_unique<blender::fn::GVArray_For_ArrayContainer<Array<T>>>(
|
||||
std::move(values));
|
||||
}
|
||||
|
|
|
@ -374,9 +374,9 @@ void NURBSpline::calculate_basis_cache() const
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void interpolate_to_evaluated_points_impl(Span<NURBSpline::BasisCache> weights,
|
||||
const blender::VArray<T> &source_data,
|
||||
MutableSpan<T> result_data)
|
||||
void interpolate_to_evaluated_impl(Span<NURBSpline::BasisCache> weights,
|
||||
const blender::VArray<T> &source_data,
|
||||
MutableSpan<T> result_data)
|
||||
{
|
||||
const int points_len = source_data.size();
|
||||
BLI_assert(result_data.size() == weights.size());
|
||||
|
@ -395,7 +395,7 @@ void interpolate_to_evaluated_points_impl(Span<NURBSpline::BasisCache> weights,
|
|||
mixer.finalize();
|
||||
}
|
||||
|
||||
blender::fn::GVArrayPtr NURBSpline::interpolate_to_evaluated_points(
|
||||
blender::fn::GVArrayPtr NURBSpline::interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const
|
||||
{
|
||||
BLI_assert(source_data.size() == this->size());
|
||||
|
@ -412,7 +412,7 @@ blender::fn::GVArrayPtr NURBSpline::interpolate_to_evaluated_points(
|
|||
using T = decltype(dummy);
|
||||
if constexpr (!std::is_void_v<blender::attribute_math::DefaultMixer<T>>) {
|
||||
Array<T> values(this->evaluated_points_size());
|
||||
interpolate_to_evaluated_points_impl<T>(weights, source_data.typed<T>(), values);
|
||||
interpolate_to_evaluated_impl<T>(weights, source_data.typed<T>(), values);
|
||||
new_varray = std::make_unique<blender::fn::GVArray_For_ArrayContainer<Array<T>>>(
|
||||
std::move(values));
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ Span<float3> NURBSpline::evaluated_positions() const
|
|||
evaluated_position_cache_.resize(eval_size);
|
||||
|
||||
/* TODO: Avoid copying the evaluated data from the temporary array. */
|
||||
GVArray_Typed<float3> evaluated = Spline::interpolate_to_evaluated_points(positions_.as_span());
|
||||
GVArray_Typed<float3> evaluated = Spline::interpolate_to_evaluated(positions_.as_span());
|
||||
evaluated->materialize(evaluated_position_cache_);
|
||||
|
||||
position_cache_dirty_ = false;
|
||||
|
|
|
@ -115,7 +115,7 @@ Span<float3> PolySpline::evaluated_positions() const
|
|||
* the original data. Therefore the lifetime of the returned virtual array must not be longer than
|
||||
* the source data.
|
||||
*/
|
||||
blender::fn::GVArrayPtr PolySpline::interpolate_to_evaluated_points(
|
||||
blender::fn::GVArrayPtr PolySpline::interpolate_to_evaluated(
|
||||
const blender::fn::GVArray &source_data) const
|
||||
{
|
||||
BLI_assert(source_data.size() == this->size());
|
||||
|
|
|
@ -94,16 +94,16 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count)
|
|||
|
||||
Array<float> uniform_samples = input_spline.sample_uniform_index_factors(count);
|
||||
|
||||
input_spline.sample_based_on_index_factors<float3>(
|
||||
input_spline.sample_with_index_factors<float3>(
|
||||
input_spline.evaluated_positions(), uniform_samples, output_spline->positions());
|
||||
|
||||
input_spline.sample_based_on_index_factors<float>(
|
||||
input_spline.interpolate_to_evaluated_points(input_spline.radii()),
|
||||
input_spline.sample_with_index_factors<float>(
|
||||
input_spline.interpolate_to_evaluated(input_spline.radii()),
|
||||
uniform_samples,
|
||||
output_spline->radii());
|
||||
|
||||
input_spline.sample_based_on_index_factors<float>(
|
||||
input_spline.interpolate_to_evaluated_points(input_spline.tilts()),
|
||||
input_spline.sample_with_index_factors<float>(
|
||||
input_spline.interpolate_to_evaluated(input_spline.tilts()),
|
||||
uniform_samples,
|
||||
output_spline->tilts());
|
||||
|
||||
|
@ -123,8 +123,8 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count)
|
|||
return false;
|
||||
}
|
||||
|
||||
input_spline.sample_based_on_index_factors(
|
||||
*input_spline.interpolate_to_evaluated_points(*input_attribute),
|
||||
input_spline.sample_with_index_factors(
|
||||
*input_spline.interpolate_to_evaluated(*input_attribute),
|
||||
uniform_samples,
|
||||
*output_attribute);
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ static void spline_extrude_to_mesh_data(const Spline &spline,
|
|||
Span<float3> normals = spline.evaluated_normals();
|
||||
Span<float3> profile_positions = profile_spline.evaluated_positions();
|
||||
|
||||
GVArray_Typed<float> radii = spline.interpolate_to_evaluated_points(spline.radii());
|
||||
GVArray_Typed<float> radii = spline.interpolate_to_evaluated(spline.radii());
|
||||
for (const int i_ring : IndexRange(spline_vert_len)) {
|
||||
float4x4 point_matrix = float4x4::from_normalized_axis_data(
|
||||
positions[i_ring], normals[i_ring], tangents[i_ring]);
|
||||
|
|
|
@ -186,7 +186,7 @@ static ResultAttributes create_point_attributes(PointCloudComponent &points,
|
|||
|
||||
/**
|
||||
* TODO: For non-poly splines, this has double copies that could be avoided as part
|
||||
* of a general look at optimizing uses of #interpolate_to_evaluated_points.
|
||||
* of a general look at optimizing uses of #Spline::interpolate_to_evaluated.
|
||||
*/
|
||||
static void copy_evaluated_point_attributes(Span<SplinePtr> splines,
|
||||
Span<int> offsets,
|
||||
|
@ -199,10 +199,8 @@ static void copy_evaluated_point_attributes(Span<SplinePtr> splines,
|
|||
const int size = offsets[i + 1] - offsets[i];
|
||||
|
||||
data.positions.slice(offset, size).copy_from(spline.evaluated_positions());
|
||||
spline.interpolate_to_evaluated_points(spline.radii())
|
||||
->materialize(data.radii.slice(offset, size));
|
||||
spline.interpolate_to_evaluated_points(spline.tilts())
|
||||
->materialize(data.tilts.slice(offset, size));
|
||||
spline.interpolate_to_evaluated(spline.radii())->materialize(data.radii.slice(offset, size));
|
||||
spline.interpolate_to_evaluated(spline.tilts())->materialize(data.tilts.slice(offset, size));
|
||||
|
||||
for (const Map<std::string, GMutableSpan>::Item &item : data.point_attributes.items()) {
|
||||
const StringRef name = item.key;
|
||||
|
@ -211,7 +209,7 @@ static void copy_evaluated_point_attributes(Span<SplinePtr> splines,
|
|||
BLI_assert(spline.attributes.get_for_read(name));
|
||||
GSpan spline_span = *spline.attributes.get_for_read(name);
|
||||
|
||||
spline.interpolate_to_evaluated_points(spline_span)
|
||||
spline.interpolate_to_evaluated(spline_span)
|
||||
->materialize(point_span.slice(offset, size).data());
|
||||
}
|
||||
|
||||
|
@ -236,18 +234,16 @@ static void copy_uniform_sample_point_attributes(Span<SplinePtr> splines,
|
|||
|
||||
const Array<float> uniform_samples = spline.sample_uniform_index_factors(size);
|
||||
|
||||
spline.sample_based_on_index_factors<float3>(
|
||||
spline.sample_with_index_factors<float3>(
|
||||
spline.evaluated_positions(), uniform_samples, data.positions.slice(offset, size));
|
||||
|
||||
spline.sample_based_on_index_factors<float>(
|
||||
spline.interpolate_to_evaluated_points(spline.radii()),
|
||||
uniform_samples,
|
||||
data.radii.slice(offset, size));
|
||||
spline.sample_with_index_factors<float>(spline.interpolate_to_evaluated(spline.radii()),
|
||||
uniform_samples,
|
||||
data.radii.slice(offset, size));
|
||||
|
||||
spline.sample_based_on_index_factors<float>(
|
||||
spline.interpolate_to_evaluated_points(spline.tilts()),
|
||||
uniform_samples,
|
||||
data.tilts.slice(offset, size));
|
||||
spline.sample_with_index_factors<float>(spline.interpolate_to_evaluated(spline.tilts()),
|
||||
uniform_samples,
|
||||
data.tilts.slice(offset, size));
|
||||
|
||||
for (const Map<std::string, GMutableSpan>::Item &item : data.point_attributes.items()) {
|
||||
const StringRef name = item.key;
|
||||
|
@ -256,18 +252,18 @@ static void copy_uniform_sample_point_attributes(Span<SplinePtr> splines,
|
|||
BLI_assert(spline.attributes.get_for_read(name));
|
||||
GSpan spline_span = *spline.attributes.get_for_read(name);
|
||||
|
||||
spline.sample_based_on_index_factors(*spline.interpolate_to_evaluated_points(spline_span),
|
||||
uniform_samples,
|
||||
point_span.slice(offset, size));
|
||||
spline.sample_with_index_factors(*spline.interpolate_to_evaluated(spline_span),
|
||||
uniform_samples,
|
||||
point_span.slice(offset, size));
|
||||
}
|
||||
|
||||
spline.sample_based_on_index_factors<float3>(
|
||||
spline.sample_with_index_factors<float3>(
|
||||
spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size));
|
||||
for (float3 &tangent : data.tangents) {
|
||||
tangent.normalize();
|
||||
}
|
||||
|
||||
spline.sample_based_on_index_factors<float3>(
|
||||
spline.sample_with_index_factors<float3>(
|
||||
spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size));
|
||||
for (float3 &normals : data.normals) {
|
||||
normals.normalize();
|
||||
|
@ -330,6 +326,8 @@ static void geo_node_curve_to_points_exec(GeoNodeExecParams params)
|
|||
|
||||
geometry_set = bke::geometry_set_realize_instances(geometry_set);
|
||||
|
||||
SCOPED_TIMER(__func__);
|
||||
|
||||
if (!geometry_set.has_curve()) {
|
||||
params.set_output("Geometry", GeometrySet());
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue