Struct efd::Efd

source ·
pub struct Efd<const D: usize>
where U<D>: EfdDim<D>,
{ /* private fields */ }
Expand description

Elliptical Fourier Descriptor coefficients. Provide transformation between discrete points and coefficients.

Start with Efd::from_curve() and its related methods.

Transformation

The transformation of normalized coefficients.

Implements Kuhl and Giardina method of normalizing the coefficients An, Bn, Cn, Dn. Performs 3 separate normalizations. First, it makes the data location invariant by re-scaling the data to a common origin. Secondly, the data is rotated with respect to the major axis. Thirdly, the coefficients are normalized with regard to the absolute value of A₁.

Please see GeoVar for more information.

Raw Coefficients

The coefficients is contained with na::Matrix, use Efd::try_from_coeffs() to input the coefficients externally.

See also Efd::from_parts_unchecked() and Efd::into_inner() without checking data.

Implementations§

source§

impl<const D: usize> Efd<D>
where U<D>: EfdDim<D>,

source

pub const fn from_parts_unchecked( coeffs: Coeffs<D>, geo: GeoVar<Rot<D>, D> ) -> Self

Create object from a matrix directly.

The array size is (harmonic) x (dimension x 2). The dimension is D.

Zero harmonic is allowed but meaningless. If the harmonic is zero, some operations will panic.

use efd::{Efd2, GeoVar};
let path = Efd2::from_parts_unchecked(vec![], GeoVar::identity()).generate(20);
assert_eq!(path.len(), 0);

See also Efd::into_inner().

source

pub fn try_from_coeffs(coeffs: Coeffs<D>) -> Option<Self>

Create object from a matrix with boundary check and normalization.

The array size is (harmonic) x (dimension x 2). The dimension is D.

Return none if the harmonic is zero.

source

pub fn try_from_coeffs_unnorm(coeffs: Coeffs<D>) -> Option<Self>

Create object from a matrix with boundary check.

The array size is (harmonic) x (dimension x 2). The dimension is D.

Return none if the harmonic is zero.

source

pub fn from_curve<C>(curve: C, is_open: bool) -> Self
where C: Curve<D>,

Fully automated coefficient calculation.

  1. The initial harmonic number is the same as the curve point.
  2. Fourier Power Anaysis (FPA) uses 99.99% threshold.
Tail End Closed

If curve.first() != curve.last(), the curve will be automatically closed when is_open is false.

Open Curve Option

The open curve option is for the curve that duplicated a reversed part of itself. For example,

let efd = efd::Efd2::from_curve(path_open, true);

is equivalent to

let path_closed = path_open
    .iter()
    .chain(path_open.iter().rev().skip(1))
    .cloned()
    .collect::<Vec<_>>();
let efd = efd::Efd2::from_curve(path_closed, false);

but not actually increase the data size.

Panics

Panics if the curve length is not greater than 2 in debug mode. This function check the lengths only. Please use valid_curve() to verify the curve if there has NaN input.

source

pub fn from_curve_nyquist<C>(curve: C, is_open: bool) -> Self
where C: Curve<D>,

Same as Efd::from_curve(), but if your sampling points are large, use Nyquist Frequency as an initial harmonic number.

Nyquist Frequency is half of the sample number.

Please ensure the sampling points are generated from a known function and are more than enough. Otherwise, it will cause undersampling.

source

pub fn from_curve_harmonic<C>(curve: C, is_open: bool, harmonic: usize) -> Self
where C: Curve<D>,

Manual coefficient calculation.

  1. The initial harmonic is decide by user.
  2. No harmonic reduced. Please call Efd::fourier_power_anaysis().
Panics

Panics if the specific harmonic is zero or the curve length is not greater than 2 in the debug mode. This function check the lengths only. Please use valid_curve() to verify the curve if there has NaN input.

source

pub fn from_curve_harmonic_and_get<C>( curve: C, is_open: bool, harmonic: usize ) -> (Self, Vec<f64>)
where C: Curve<D>,

Same as Efd::from_curve_harmonic() but get the the theta value of each point coordinate of the curve.

See also get_target_pos() if you want to ignore the coefficients.

Panics

Please see Efd::from_curve_harmonic().

source

pub fn from_curve_harmonic_unnorm<C>( curve: C, is_open: bool, harmonic: usize ) -> Self
where C: Curve<D>,

Same as Efd::from_curve_harmonic() but without normalization.

source

pub fn with_geo(self, geo: GeoVar<Rot<D>, D>) -> Self

A builder method for changing geometric variables.

source

pub fn fourier_power_anaysis<T>(self, threshold: T) -> Self
where Option<f64>: From<T>,

Use Fourier Power Anaysis (FPA) to reduce the harmonic number.

The coefficient memory will be saved but cannot be used twice due to undersampling.

The default threshold is 99.99%.

Panics

Panics if the threshold is not in 0..1, or the harmonic is zero.

source

pub fn set_harmonic(&mut self, harmonic: usize)

Set the harmonic number of the coefficients.

Panics

Panics if the harmonic is zero or greater than the current harmonic.

source

pub fn normalized(self) -> Self

Force normalize the coefficients.

If the coefficients are constructed by *_unnorm or *_unchecked methods, this method will normalize them.

Panics

Panics if the harmonic is zero.

source

pub fn into_inner(self) -> (Coeffs<D>, GeoVar<Rot<D>, D>)

Consume self and return the parts of this type.

See also Efd::from_parts_unchecked().

source

pub fn coeffs(&self) -> &[Kernel<D>]

Get a reference to the coefficients.

source

pub fn coeff(&self, harmonic: usize) -> &Kernel<D>

Get a view to the specific coefficients. (0..self.harmonic())

source

pub fn coeffs_iter(&self) -> impl Iterator<Item = &Kernel<D>>

Get an iterator over all the coefficients per harmonic.

source

pub fn coeffs_iter_mut(&mut self) -> impl Iterator<Item = &mut Kernel<D>>

Get a mutable iterator over all the coefficients per harmonic.

source

pub fn as_geo(&self) -> &GeoVar<Rot<D>, D>

Get the reference of geometric variables.

source

pub fn as_geo_mut(&mut self) -> &mut GeoVar<Rot<D>, D>

Get the mutable reference of geometric variables.

source

pub fn is_open(&self) -> bool

Check if the descibed curve is open.

source

pub fn harmonic(&self) -> usize

Get the harmonic number of the coefficients.

source

pub fn is_valid(&self) -> bool

Check if the coefficients are valid.

  • The harmonic number must be greater than 0.
  • All the coefficients must not be NaN or zero.

It is only helpful if this object is constructed by Efd::from_parts_unchecked().

source

pub fn distance(&self, rhs: &Self) -> f64

Calculate the L1 distance between two coefficient set.

For more distance methods, please see Distance.

source

pub fn reverse_inplace(&mut self)

Reverse the order of described curve then return a mutable reference.

source

pub fn reversed(self) -> Self

Consume and return a reversed version of the coefficients. This method can avoid mutable require.

Please clone the object if you want to do self-comparison.

source

pub fn generate(&self, n: usize) -> Vec<Coord<D>>

Generate (reconstruct) the described curve. (theta=0~TAU)

Panics

Panics if the number of the points n is less than 2.

source

pub fn generate_half(&self, n: usize) -> Vec<Coord<D>>

Generate (reconstruct) a half of the described curve. (theta=0~PI)

Panics

Panics if the number of the points n is less than 2.

source

pub fn generate_norm(&self, n: usize) -> Vec<Coord<D>>

Generate (reconstruct) the described curve. (theta=0~TAU)

Normalized curve is without transformation.

Panics

Panics if the number of the points n is less than 2.

source

pub fn generate_norm_half(&self, n: usize) -> Vec<Coord<D>>

Generate (reconstruct) a half of the described curve. (t=0~PI)

Normalized curve is without transformation.

Panics

Panics if the number of the points n is less than 2.

source

pub fn generate_by(&self, t: &[f64]) -> Vec<Coord<D>>

Generate (reconstruct) a described curve in a series of time t.

source

pub fn generate_norm_by(&self, t: &[f64]) -> Vec<Coord<D>>

Generate (reconstruct) a normalized curve in a series of time t.

Normalized curve is without transformation.

Trait Implementations§

source§

impl<const D: usize> Clone for Efd<D>
where U<D>: EfdDim<D>,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const D: usize> Debug for Efd<D>
where U<D>: EfdDim<D>,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const D: usize> Distance for Efd<D>
where U<D>: EfdDim<D>,

source§

fn err_buf(&self, rhs: &Self) -> Vec<f64>

Calculate the error between each pair of datas.
source§

fn square_err(&self, rhs: &Self) -> f64

Calculate the square error.
source§

fn l0_norm(&self, rhs: &Self) -> f64

Calculate the L0 norm of the error.
source§

fn l1_norm(&self, rhs: &Self) -> f64

Calculate the L1 norm of the error.
source§

fn l2_norm(&self, rhs: &Self) -> f64

Calculate the L2 norm of the error.
source§

fn lp_norm(&self, rhs: &Self, p: i32) -> f64

Calculate the Lp norm of the error.

Auto Trait Implementations§

§

impl<const D: usize> !RefUnwindSafe for Efd<D>

§

impl<const D: usize> !Send for Efd<D>

§

impl<const D: usize> !Sync for Efd<D>

§

impl<const D: usize> !Unpin for Efd<D>

§

impl<const D: usize> !UnwindSafe for Efd<D>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.