Spline1D

Introduction

vtkSpline1D provides methods for creating a 1D cubic spline object from given
parameters, and allows for the calculation of the spline value and derivative
at any given point inside the spline intervals.

Methods

computeCloseCoefficients

Argument Type Required Description
size Number Yes
work Float32Array Yes
x Array. Yes
y Array. Yes

computeOpenCoefficients

Argument Type Required Description
size Number Yes
work Float32Array Yes
x Array. Yes
y Array. Yes
options Object Yes
options.leftConstraint BoundaryCondition Yes
options.leftValue Number Yes
options.rightConstraint BoundaryCondition Yes
options.rightValue Number Yes

extend

Method used to decorate a given object (publicAPI+model) with vtkSpline1D characteristics.

Argument Type Required Description
publicAPI Yes object on which methods will be bounds (public)
model Yes object on which data structure will be bounds (protected)
initialValues ISpline1DInitialValues No (default: {})

getValue

Argument Type Required Description
intervalIndex Number Yes
t Number Yes

newInstance

Method used to create a new instance of vtkSpline1D.

Argument Type Required Description
initialValues ISpline1DInitialValues No for pre-setting some of its content

Source

Constants.js
// Boundary conditions available to compute open splines
// DEFAULT : desired slope at boundary point is derivative from two points (boundary and second interior)
// DERIVATIVE : desired slope at boundary point is the boundary value given.
// SECOND_DERIVATIVE : second derivative at boundary point is the boundary value given.
// SECOND_DERIVATIVE_INTERIOR_POINT : desired second derivative at boundary point is the boundary value given times second derivative
// at first interior point.

export const BoundaryCondition = {
DEFAULT: 0,
DERIVATIVE: 1,
SECOND_DERIVATIVE: 2,
SECOND_DERIVATIVE_INTERIOR_POINT: 3,
};

export default {
BoundaryCondition,
};
index.d.ts
import { vtkObject } from '../../../interfaces';

export interface ISpline1DInitialValues {}

// Boundary conditions available to compute open splines
// DEFAULT : desired slope at boundary point is derivative from two points (boundary and second interior)
// DERIVATIVE : desired slope at boundary point is the boundary value given.
// SECOND_DERIVATIVE : second derivative at boundary point is the boundary value given.
// SECOND_DERIVATIVE_INTERIOR_POINT : desired second derivative at boundary point is the boundary value given times second derivative
// at first interior point.
export enum BoundaryCondition {
DEFAULT,
DERIVATIVE,
SECOND_DERIVATIVE,
SECOND_DERIVATIVE_INTERIOR_POINT,
}

export interface vtkSpline1D extends vtkObject {
/**
*
* @param {Number} size
* @param {Float32Array} work
* @param {Number[]} x
* @param {Number[]} y
*/
computeCloseCoefficients(
size: number,
work: Float32Array,
x: number[],
y: number[]
): void;

/**
*
* @param {Number} size
* @param {Float32Array} work
* @param {Number[]} x
* @param {Number[]} y
* @param {Object} options
* @param {BoundaryCondition} options.leftConstraint
* @param {Number} options.leftValue
* @param {BoundaryCondition} options.rightConstraint
* @param {Number} options.rightValue
*/
computeOpenCoefficients(
size: number,
work: Float32Array,
x: number[],
y: number[],
options: {
leftConstraint: BoundaryCondition;
leftValue: number;
rightConstraint: BoundaryCondition;
rightValue: Number;
}
): void;

/**
*
* @param {Number} intervalIndex
* @param {Number} t
*/
getValue(intervalIndex: number, t: number): void;
}

/**
* Method used to decorate a given object (publicAPI+model) with vtkSpline1D characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {ISpline1DInitialValues} [initialValues] (default: {})
*/
export function extend(
publicAPI: object,
model: object,
initialValues?: ISpline1DInitialValues
): void;

/**
* Method used to create a new instance of vtkSpline1D.
* @param {ISpline1DInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(
initialValues?: ISpline1DInitialValues
): vtkSpline1D;

/**
* vtkSpline1D provides methods for creating a 1D cubic spline object from given
* parameters, and allows for the calculation of the spline value and derivative
* at any given point inside the spline intervals.
*/
export declare const vtkSpline1D: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkSpline1D;
index.js
import macro from 'vtk.js/Sources/macros';

const { vtkErrorMacro } = macro;

// ----------------------------------------------------------------------------
// vtkSpline1D methods
// ----------------------------------------------------------------------------

function vtkSpline1D(publicAPI, model) {
// Set our classname
model.classHierarchy.push('vtkSpline1D');

// --------------------------------------------------------------------------

publicAPI.computeCloseCoefficients = (size, work, x, y) => {
vtkErrorMacro(
`${
model.classHierarchy.slice(-1)[0]
} should implement computeCloseCoefficients`
);
};

// --------------------------------------------------------------------------

publicAPI.computeOpenCoefficients = (size, work, x, y, options = {}) => {
vtkErrorMacro(
`${
model.classHierarchy.slice(-1)[0]
} should implement computeOpenCoefficients`
);
};

// --------------------------------------------------------------------------

publicAPI.getValue = (intervalIndex, t) => {
vtkErrorMacro(
`${model.classHierarchy.slice(-1)[0]} should implement getValue`
);
};
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Build VTK API
macro.obj(publicAPI, model);
vtkSpline1D(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkSpline1D');

// ----------------------------------------------------------------------------

export default { newInstance, extend };