pub struct Efd<D: EfdDim> { /* 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 Transform for more information.
Raw Coefficients
The coefficients is contained with na::Matrix, use
Efd::try_from_coeffs() to input the coefficients externally.
Use Efd::into_inner() to get the matrix of the coefficients.
Implementations§
source§impl<D: EfdDim> Efd<D>
impl<D: EfdDim> Efd<D>
sourcepub fn try_from_coeffs(coeffs: Coeff<D>) -> Option<Self>
pub fn try_from_coeffs(coeffs: Coeff<D>) -> Option<Self>
Create object from a 2D array with boundary check and normalization.
The array size is (harmonic) x (dimension x 2). The dimension is
CoordHint::Dim.
Return none if the harmonic is zero.
sourcepub fn try_from_coeffs_unnorm(coeffs: Coeff<D>) -> Option<Self>
pub fn try_from_coeffs_unnorm(coeffs: Coeff<D>) -> Option<Self>
Create object from a 2D array with boundary check.
The array size is (harmonic) x (dimension x 2). The dimension is
CoordHint::Dim.
Return none if the harmonic is zero.
sourcepub fn from_coeffs_unchecked(coeffs: Coeff<D>) -> Self
pub fn from_coeffs_unchecked(coeffs: Coeff<D>) -> Self
Create object from a 2D array directly.
The array size is (harmonic) x (dimension x 2). The dimension is
CoordHint::Dim.
Zero harmonic is allowed but meaningless. If the harmonic is zero, some operations will panic.
use efd::{Coeff2, Efd2};
let coeff = Coeff2::from_column_slice(&[]);
let path = Efd2::from_coeffs_unchecked(coeff).generate(20);
assert_eq!(path.len(), 0);sourcepub fn from_curve<C>(curve: C, is_open: bool) -> Self
pub fn from_curve<C>(curve: C, is_open: bool) -> Self
Fully automated coefficient calculation.
- The initial harmonic number is the same as the curve point.
- 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.
sourcepub fn from_curve_nyquist<C>(curve: C, is_open: bool) -> Self
pub fn from_curve_nyquist<C>(curve: C, is_open: bool) -> Self
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.
sourcepub fn from_curve_harmonic<C>(curve: C, is_open: bool, harmonic: usize) -> Self
pub fn from_curve_harmonic<C>(curve: C, is_open: bool, harmonic: usize) -> Self
Manual coefficient calculation.
- The initial harmonic is decide by user.
- 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.
sourcepub fn from_curve_harmonic_unnorm<C>(
curve: C,
is_open: bool,
harmonic: usize
) -> Self
pub fn from_curve_harmonic_unnorm<C>( curve: C, is_open: bool, harmonic: usize ) -> Self
Same as Efd::from_curve_harmonic() but without normalization.
sourcepub fn with_geo(self, geo: GeoVar<D::Trans>) -> Self
pub fn with_geo(self, geo: GeoVar<D::Trans>) -> Self
A builder method for changing geometric variables.
sourcepub fn fourier_power_anaysis<T>(self, threshold: T) -> Self
pub fn fourier_power_anaysis<T>(self, threshold: T) -> Self
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.
sourcepub fn normalized(self) -> Self
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.
sourcepub fn into_inner(self) -> Coeff<D>
pub fn into_inner(self) -> Coeff<D>
Consume self and return a raw array of the coefficients.
sourcepub fn coeff(&self, harmonic: usize) -> CKernel<'_, D>
pub fn coeff(&self, harmonic: usize) -> CKernel<'_, D>
Get a view to the specific coefficients. (0..self.harmonic())
sourcepub fn coeffs_iter(&self) -> impl Iterator<Item = CKernel<'_, D>>
pub fn coeffs_iter(&self) -> impl Iterator<Item = CKernel<'_, D>>
Get an iterator over all the coefficients per harmonic.
sourcepub fn coeffs_iter_mut(&mut self) -> impl Iterator<Item = CKernelMut<'_, D>>
pub fn coeffs_iter_mut(&mut self) -> impl Iterator<Item = CKernelMut<'_, D>>
Get a mutable iterator over all the coefficients per harmonic.
sourcepub fn as_geo_mut(&mut self) -> &mut GeoVar<D::Trans>
pub fn as_geo_mut(&mut self) -> &mut GeoVar<D::Trans>
Get the mutable reference of geometric variables.
sourcepub fn distance(&self, rhs: &Self) -> f64
pub fn distance(&self, rhs: &Self) -> f64
Calculate the L1 distance between two coefficient set.
For more distance methods, please see Distance.
sourcepub fn reverse_inplace(&mut self)
pub fn reverse_inplace(&mut self)
Reverse the order of described curve then return a mutable reference.
sourcepub fn reversed(self) -> Self
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.
sourcepub fn generate(&self, n: usize) -> Vec<Coord<D>>
pub fn generate(&self, n: usize) -> Vec<Coord<D>>
Generate the described curve. (theta=TAU)
Panics
Panics if the number of the points n is less than 2.
sourcepub fn generate_half(&self, n: usize) -> Vec<Coord<D>>
pub fn generate_half(&self, n: usize) -> Vec<Coord<D>>
Generate a half of the described curve. (theta=PI)
Panics
Panics if the number of the points n is less than 2.
Trait Implementations§
Auto Trait Implementations§
impl<D> RefUnwindSafe for Efd<D>where
<<<<D as EfdDim>::Trans as Transform>::Coord as CoordHint>::Dim as DimNameMul<Const<2>>>::Output: RefUnwindSafe,
<D as EfdDim>::Trans: RefUnwindSafe,
impl<D> Send for Efd<D>
impl<D> Sync for Efd<D>
impl<D> Unpin for Efd<D>
impl<D> UnwindSafe for Efd<D>where
<<<<D as EfdDim>::Trans as Transform>::Coord as CoordHint>::Dim as DimNameMul<Const<2>>>::Output: UnwindSafe,
<D as EfdDim>::Trans: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.