Blender  V3.3
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Spline Class Referenceabstract

#include <BKE_spline.hh>

Inheritance diagram for Spline:
BezierSpline NURBSpline PolySpline

Classes

struct  LookupResult
 

Public Member Functions

virtual ~Spline ()=default
 
 Spline (const CurveType type)
 
 Spline (Spline &other)
 
SplinePtr copy () const
 
SplinePtr copy_only_settings () const
 
SplinePtr copy_without_attributes () const
 
CurveType type () const
 
virtual int size () const =0
 
int segments_num () const
 
bool is_cyclic () const
 
void set_cyclic (bool value)
 
virtual void resize (int size)=0
 
virtual blender::MutableSpan< blender::float3positions ()=0
 
virtual blender::Span< blender::float3positions () const =0
 
virtual blender::MutableSpan< floatradii ()=0
 
virtual blender::Span< floatradii () const =0
 
virtual blender::MutableSpan< floattilts ()=0
 
virtual blender::Span< floattilts () const =0
 
virtual void translate (const blender::float3 &translation)
 
virtual void transform (const blender::float4x4 &matrix)
 
void reverse ()
 
virtual void mark_cache_invalid ()=0
 
virtual int evaluated_points_num () const =0
 
int evaluated_edges_num () const
 
float length () const
 
virtual blender::Span< blender::float3evaluated_positions () const =0
 
blender::Span< floatevaluated_lengths () const
 
blender::Span< blender::float3evaluated_tangents () const
 
blender::Span< blender::float3evaluated_normals () const
 
void bounds_min_max (blender::float3 &min, blender::float3 &max, bool use_evaluated) const
 
LookupResult lookup_evaluated_factor (float factor) const
 
LookupResult lookup_evaluated_length (float length) const
 
blender::Array< floatsample_uniform_index_factors (int samples_num) const
 
LookupResult lookup_data_from_index_factor (float index_factor) const
 
void sample_with_index_factors (const blender::GVArray &src, blender::Span< float > index_factors, blender::GMutableSpan dst) const
 
template<typename T >
void sample_with_index_factors (const blender::VArray< T > &src, blender::Span< float > index_factors, blender::MutableSpan< T > dst) const
 
template<typename T >
void sample_with_index_factors (blender::Span< T > src, blender::Span< float > index_factors, blender::MutableSpan< T > dst) const
 
virtual blender::GVArray interpolate_to_evaluated (const blender::GVArray &src) const =0
 
blender::GVArray interpolate_to_evaluated (blender::GSpan data) const
 
template<typename T >
blender::VArray< Tinterpolate_to_evaluated (blender::Span< T > data) const
 

Static Public Member Functions

static void copy_base_settings (const Spline &src, Spline &dst)
 

Public Attributes

NormalMode normal_mode = NORMAL_MODE_MINIMUM_TWIST
 
blender::bke::CustomDataAttributes attributes
 

Protected Member Functions

virtual void correct_end_tangents () const =0
 
virtual void copy_settings (Spline &dst) const =0
 
virtual void copy_data (Spline &dst) const =0
 
virtual void reverse_impl ()=0
 

Protected Attributes

CurveType type_
 
bool is_cyclic_ = false
 
blender::Vector< blender::float3evaluated_tangents_cache_
 
std::mutex tangent_cache_mutex_
 
bool tangent_cache_dirty_ = true
 
blender::Vector< blender::float3evaluated_normals_cache_
 
std::mutex normal_cache_mutex_
 
bool normal_cache_dirty_ = true
 
blender::Vector< floatevaluated_lengths_cache_
 
std::mutex length_cache_mutex_
 
bool length_cache_dirty_ = true
 

Detailed Description

A spline is an abstraction of a single branch-less curve section, its evaluation methods, and data. The spline data itself is just control points and a set of attributes by the set of "evaluated" data is often used instead. Conceptually, the derived vs. original data is an essential distinction. Derived data is usually calculated lazily and cached on the spline.

Any derived class of Spline has to manage two things:

  1. Interpolating arbitrary attribute data from the control points to evaluated points.
  2. Evaluating the positions based on the stored control point data.

Beyond that, everything is the base class's responsibility, with minor exceptions. Further 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 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.
  3. sample_uniform_index_factors returns an array that stores uniform-length samples along the spline which can be used to interpolate data from method 1.

Commonly used evaluated data is stored in caches on the spline itself so that operations on splines don't need to worry about taking ownership of evaluated data when they don't need to.

Definition at line 52 of file BKE_spline.hh.

Constructor & Destructor Documentation

◆ ~Spline()

virtual Spline::~Spline ( )
virtualdefault

◆ Spline() [1/2]

Spline::Spline ( const CurveType  type)
inline

Definition at line 79 of file BKE_spline.hh.

◆ Spline() [2/2]

Spline::Spline ( Spline other)
inline

Definition at line 82 of file BKE_spline.hh.

References copy_base_settings().

Member Function Documentation

◆ bounds_min_max()

void Spline::bounds_min_max ( blender::float3 min,
blender::float3 max,
bool  use_evaluated 
) const

Definition at line 490 of file spline_base.cc.

References evaluated_positions(), max, min, minmax_v3v3_v3(), and positions().

◆ copy()

SplinePtr Spline::copy ( ) const

Return a new spline with the same data, settings, and attributes.

Definition at line 53 of file spline_base.cc.

References attributes, and copy_without_attributes().

◆ copy_base_settings()

void Spline::copy_base_settings ( const Spline src,
Spline dst 
)
static

Definition at line 30 of file spline_base.cc.

References is_cyclic_, normal_mode, and src.

Referenced by copy_only_settings(), and Spline().

◆ copy_data()

virtual void Spline::copy_data ( Spline dst) const
protectedpure virtual

Implemented in PolySpline, and NURBSpline.

Referenced by copy_without_attributes().

◆ copy_only_settings()

SplinePtr Spline::copy_only_settings ( ) const

Return a new spline with the same type and settings like "cyclic", but without any data.

Definition at line 60 of file spline_base.cc.

References copy_base_settings(), copy_settings(), create_spline(), and type_.

Referenced by copy_without_attributes().

◆ copy_settings()

virtual void Spline::copy_settings ( Spline dst) const
protectedpure virtual

Implemented in PolySpline, and NURBSpline.

Referenced by copy_only_settings().

◆ copy_without_attributes()

SplinePtr Spline::copy_without_attributes ( ) const

The same as copy, but skips copying dynamic attributes to the new spline.

Definition at line 68 of file spline_base.cc.

References copy_data(), and copy_only_settings().

Referenced by copy().

◆ correct_end_tangents()

virtual void Spline::correct_end_tangents ( ) const
protectedpure virtual

Implemented in PolySpline, and NURBSpline.

Referenced by evaluated_tangents().

◆ evaluated_edges_num()

int Spline::evaluated_edges_num ( ) const

◆ evaluated_lengths()

Span< float > Spline::evaluated_lengths ( ) const

Return non-owning access to the cache of accumulated lengths along the spline. Each item is the length of the subsequent segment, i.e. the first value is the length of the first segment rather than 0. This calculation is rather trivial, and only depends on the evaluated positions. However, the results are used often, and it is necessarily single threaded, so it is cached.

Definition at line 169 of file spline_base.cc.

References accumulate_lengths(), evaluated_edges_num(), evaluated_lengths_cache_, evaluated_positions(), is_cyclic_, length_cache_dirty_, length_cache_mutex_, lock, positions(), and blender::Vector< T, InlineBufferCapacity, Allocator >::resize().

Referenced by length(), lookup_evaluated_length(), and sample_uniform_index_factors().

◆ evaluated_normals()

Span< float3 > Spline::evaluated_normals ( ) const

Return non-owning access to the direction vectors perpendicular to the tangents at every evaluated point. The method used to generate the normal vectors depends on Spline.normal_mode.

Definition at line 361 of file spline_base.cc.

References calculate_normals_minimum(), calculate_normals_z_up(), evaluated_normals_cache_, evaluated_points_num(), evaluated_tangents(), interpolate_to_evaluated(), is_cyclic_, lock, normal_cache_dirty_, normal_cache_mutex_, normal_mode, NORMAL_MODE_MINIMUM_TWIST, NORMAL_MODE_Z_UP, normals, rotate_direction_around_axis(), tangents, and tilts().

◆ evaluated_points_num()

virtual int Spline::evaluated_points_num ( ) const
pure virtual

◆ evaluated_positions()

virtual blender::Span<blender::float3> Spline::evaluated_positions ( ) const
pure virtual

◆ evaluated_tangents()

Span< float3 > Spline::evaluated_tangents ( ) const

Return non-owning access to the direction of the curve at each evaluated point.

Definition at line 234 of file spline_base.cc.

References calculate_tangents(), correct_end_tangents(), evaluated_points_num(), evaluated_positions(), evaluated_tangents_cache_, is_cyclic_, lock, positions(), tangent_cache_dirty_, and tangent_cache_mutex_.

Referenced by evaluated_normals().

◆ interpolate_to_evaluated() [1/3]

GVArray Spline::interpolate_to_evaluated ( blender::GSpan  data) const

Definition at line 498 of file spline_base.cc.

References data, and interpolate_to_evaluated().

◆ interpolate_to_evaluated() [2/3]

template<typename T >
blender::VArray<T> Spline::interpolate_to_evaluated ( blender::Span< T data) const
inline

Definition at line 228 of file BKE_spline.hh.

References data, interpolate_to_evaluated(), T, and blender::GVArray::typed().

◆ interpolate_to_evaluated() [3/3]

virtual blender::GVArray Spline::interpolate_to_evaluated ( const blender::GVArray src) const
pure virtual

Interpolate a virtual array of data with the size of the number of control points to the evaluated points. For poly splines, the lifetime of the returned virtual array must not exceed the lifetime of the input data.

Implemented in BezierSpline, PolySpline, and NURBSpline.

Referenced by evaluated_normals(), NURBSpline::evaluated_positions(), interpolate_to_evaluated(), blender::nodes::node_geo_curve_trim_cc::to_single_point_nurbs(), and blender::nodes::node_geo_curve_trim_cc::trim_nurbs_spline().

◆ is_cyclic()

bool Spline::is_cyclic ( ) const

Definition at line 143 of file spline_base.cc.

References is_cyclic_.

Referenced by calculate_mappings_linear_resolution().

◆ length()

float Spline::length ( ) const

◆ lookup_data_from_index_factor()

Spline::LookupResult Spline::lookup_data_from_index_factor ( float  index_factor) const

Definition at line 469 of file spline_base.cc.

References evaluated_points_num(), blender::math::floor(), and is_cyclic_.

◆ lookup_evaluated_factor()

Spline::LookupResult Spline::lookup_evaluated_factor ( float  factor) const

Find the position on the evaluated spline at the given portion of the total length. The return value is the indices of the two neighboring points at that location and the factor between them, which can be used to look up any attribute on the evaluated points.

Note
This does not support extrapolation.

Definition at line 400 of file spline_base.cc.

References length(), and lookup_evaluated_length().

◆ lookup_evaluated_length()

Spline::LookupResult Spline::lookup_evaluated_length ( float  length) const

The same as lookup_evaluated_factor, but looks up a length directly instead of a portion of the total.

Definition at line 405 of file spline_base.cc.

References blender::Span< T >::begin(), BLI_assert, blender::Span< T >::end(), evaluated_lengths(), evaluated_points_num(), length(), and offset.

Referenced by lookup_evaluated_factor().

◆ mark_cache_invalid()

virtual void Spline::mark_cache_invalid ( )
pure virtual

Mark all caches for re-computation. This must be called after any operation that would change the generated positions, tangents, normals, mapping, etc. of the evaluated points.

Implemented in PolySpline, NURBSpline, and BezierSpline.

Referenced by blender::bke::create_attribute_providers_for_curve(), reverse(), transform(), and translate().

◆ positions() [1/2]

virtual blender::Span<blender::float3> Spline::positions ( ) const
pure virtual

Implemented in PolySpline, NURBSpline, and BezierSpline.

◆ positions() [2/2]

virtual blender::MutableSpan<blender::float3> Spline::positions ( )
pure virtual

◆ radii() [1/2]

virtual blender::Span<float> Spline::radii ( ) const
pure virtual

Implemented in PolySpline, NURBSpline, and BezierSpline.

◆ radii() [2/2]

virtual blender::MutableSpan<float> Spline::radii ( )
pure virtual

◆ resize()

virtual void Spline::resize ( int  size)
pure virtual

◆ reverse()

void Spline::reverse ( )

◆ reverse_impl()

virtual void Spline::reverse_impl ( )
protectedpure virtual

Implemented in PolySpline, NURBSpline, and BezierSpline.

Referenced by reverse().

◆ sample_uniform_index_factors()

Array< float > Spline::sample_uniform_index_factors ( int  samples_num) const

Return an array of evenly spaced samples along the length of the spline. The samples are indices and factors to the next index encoded in floats. The logic for converting from the float values to interpolation data is in lookup_data_from_index_factor.

Definition at line 423 of file spline_base.cc.

References BLI_assert, evaluated_edges_num(), evaluated_lengths(), float(), is_cyclic_, blender::Array< T, InlineBufferCapacity, Allocator >::last(), length(), and blender::Span< T >::size().

◆ sample_with_index_factors() [1/3]

template<typename T >
void Spline::sample_with_index_factors ( blender::Span< T src,
blender::Span< float index_factors,
blender::MutableSpan< T dst 
) const
inline

Definition at line 214 of file BKE_spline.hh.

References sample_with_index_factors(), and src.

◆ sample_with_index_factors() [2/3]

void Spline::sample_with_index_factors ( const blender::GVArray src,
blender::Span< float index_factors,
blender::GMutableSpan  dst 
) const

Sample any input data with a value for each evaluated point (already interpolated to evaluated points) to arbitrary parameters in between the evaluated points. The interpolation is quite simple, but this handles the cyclic and end point special cases.

Definition at line 503 of file spline_base.cc.

References BLI_assert, blender::attribute_math::convert_to_static_type(), blender::threading::parallel_for(), and src.

Referenced by sample_with_index_factors().

◆ sample_with_index_factors() [3/3]

template<typename T >
void Spline::sample_with_index_factors ( const blender::VArray< T > &  src,
blender::Span< float index_factors,
blender::MutableSpan< T dst 
) const
inline

Definition at line 206 of file BKE_spline.hh.

References sample_with_index_factors(), and src.

◆ segments_num()

int Spline::segments_num ( ) const

Definition at line 136 of file spline_base.cc.

References is_cyclic_, and size().

Referenced by NURBSpline::evaluated_points_num().

◆ set_cyclic()

void Spline::set_cyclic ( bool  value)

Definition at line 148 of file spline_base.cc.

References is_cyclic_.

◆ size()

virtual int Spline::size ( ) const
pure virtual

Return the number of control points.

Implemented in PolySpline, NURBSpline, and BezierSpline.

Referenced by segments_num().

◆ tilts() [1/2]

virtual blender::Span<float> Spline::tilts ( ) const
pure virtual

Implemented in PolySpline, NURBSpline, and BezierSpline.

◆ tilts() [2/2]

virtual blender::MutableSpan<float> Spline::tilts ( )
pure virtual

◆ transform()

void Spline::transform ( const blender::float4x4 matrix)
virtual

Reimplemented in BezierSpline.

Definition at line 86 of file spline_base.cc.

References mark_cache_invalid(), and positions().

◆ translate()

void Spline::translate ( const blender::float3 translation)
virtual

Reimplemented in BezierSpline.

Definition at line 78 of file spline_base.cc.

References mark_cache_invalid(), and positions().

◆ type()

CurveType Spline::type ( ) const

Member Data Documentation

◆ attributes

◆ evaluated_lengths_cache_

blender::Vector<float> Spline::evaluated_lengths_cache_
mutableprotected

Accumulated lengths along the evaluated points.

Definition at line 73 of file BKE_spline.hh.

Referenced by evaluated_lengths().

◆ evaluated_normals_cache_

blender::Vector<blender::float3> Spline::evaluated_normals_cache_
mutableprotected

Normal direction vectors for each evaluated point.

Definition at line 68 of file BKE_spline.hh.

Referenced by evaluated_normals().

◆ evaluated_tangents_cache_

blender::Vector<blender::float3> Spline::evaluated_tangents_cache_
mutableprotected

Direction of the spline at each evaluated point.

Definition at line 63 of file BKE_spline.hh.

Referenced by evaluated_tangents().

◆ is_cyclic_

bool Spline::is_cyclic_ = false
protected

◆ length_cache_dirty_

bool Spline::length_cache_dirty_ = true
mutableprotected

◆ length_cache_mutex_

std::mutex Spline::length_cache_mutex_
mutableprotected

Definition at line 74 of file BKE_spline.hh.

Referenced by evaluated_lengths().

◆ normal_cache_dirty_

bool Spline::normal_cache_dirty_ = true
mutableprotected

◆ normal_cache_mutex_

std::mutex Spline::normal_cache_mutex_
mutableprotected

Definition at line 69 of file BKE_spline.hh.

Referenced by evaluated_normals().

◆ normal_mode

NormalMode Spline::normal_mode = NORMAL_MODE_MINIMUM_TWIST

Definition at line 54 of file BKE_spline.hh.

Referenced by copy_base_settings(), and evaluated_normals().

◆ tangent_cache_dirty_

bool Spline::tangent_cache_dirty_ = true
mutableprotected

◆ tangent_cache_mutex_

std::mutex Spline::tangent_cache_mutex_
mutableprotected

Definition at line 64 of file BKE_spline.hh.

Referenced by evaluated_tangents().

◆ type_

CurveType Spline::type_
protected

Definition at line 59 of file BKE_spline.hh.

Referenced by copy_only_settings(), and type().


The documentation for this class was generated from the following files: