Skip to content

Commit

Permalink
Merge pull request Kitware#1849 from daker/add-ts-datamodel
Browse files Browse the repository at this point in the history
docs(ts): add more typescript definitions for DataModels
  • Loading branch information
jourdain authored Apr 13, 2021
2 parents 7981542 + 2c77ee9 commit 54451ff
Show file tree
Hide file tree
Showing 20 changed files with 867 additions and 186 deletions.
130 changes: 86 additions & 44 deletions Sources/Common/Core/DataArray/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,65 @@
import { TypedArray, VtkDataArray, VtkRange } from "vtk.js/Sources/macro";
import { TypedArray, VtkObject, vtkRange } from "vtk.js/Sources/macro";

/**
* Output of the rangeHelper instance
*/
interface VtkStatisticInformation {
min: number;
max: number;
count: number;
sum: number;
mean: number;
min: number;
max: number;
count: number;
sum: number;
mean: number;
}

/**
* Helper class used to compute data range of a set of numbers
*/
interface VtkRangeHelper {
add(value: number): void;
get(): VtkStatisticInformation;
getRange(): VtkRange;
interface vtkRangeHelper {
add(value: number): void;
get(): VtkStatisticInformation;
getRange(): vtkRange;
}

export interface vtkDataArray extends VtkObject {
getElementComponentSize(): number;
/**
*
* @param tupleIdx
* @param componentIndex (default: 0)
*/
getComponent(tupleIdx: number, componentIndex: number): number;
setComponent(tupleIdx: number, componentIndex: number, value: number): void;
getData(): TypedArray;
/**
* Return the range of the given component.
*
* @param componentIndex (default: -1)
*/
getRange(componentIndex?: number): vtkRange;
setRange(rangeValue: vtkRange, componentIndex: number): [number, number];
setTuple(idx: number, tuple: Array<number>): void;
/**
*
* @param idx
* @param tupleToFill (default [])
*/
getTuple(idx: number, tupleToFill?: Array<number>): Array<number>;
/**
*
* @param idx (default: 1)
*/
getTupleLocation(idx: number): number;
getNumberOfComponents(): number;
getNumberOfValues(): number;
getNumberOfTuples(): number;
getDataType(): string;
newClone(): vtkDataArray;
getName(): string;
setData: (typedArray: TypedArray, numberOfComponents?: number) => void;
getState(): object;
// --- via macro --
setName: (name: string) => boolean;
setNumberOfComponents: (numberOfComponents: number) => boolean;
}

// ----------------------------------------------------------------------------
Expand All @@ -38,13 +80,13 @@ interface VtkRangeHelper {
* @param {Number} [component] (default: 0) indice to use inside tuple size
* @param {Number} [numberOfComponents] (default: 1) size of the tuple
*/
export function computeRange(values: number[], component?: number, numberOfComponents?: number): VtkRange;
export function computeRange(values: number[], component?: number, numberOfComponents?: number): vtkRange;

/**
* Create helper object that can be used to gather min, max, count, sum of
* a set of values.
*/
export function createRangeHelper(): VtkRangeHelper
export function createRangeHelper(): vtkRangeHelper

/**
* Return the name of a typed array
Expand Down Expand Up @@ -80,54 +122,54 @@ export function extend(publicAPI: object, model: object, initialValues?: object)
* Method use to create a new instance of vtkDataArray
* @param {object} [initialValues] for pre-setting some of its content
*/
export function newInstance(initialValues?: object): VtkDataArray;
export function newInstance(initialValues?: object): vtkDataArray;

/**
* Constants capturing the number of bytes per element based on its data type.
*/
export enum DataTypeByteSize {
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
}

/**
* Constants capturing the various VTK data types.
*/
export enum VtkDataTypes {
VOID,
CHAR,
SIGNED_CHAR,
UNSIGNED_CHAR,
SHORT,
UNSIGNED_SHORT,
INT,
UNSIGNED_INT,
FLOAT,
DOUBLE,
VOID,
CHAR,
SIGNED_CHAR,
UNSIGNED_CHAR,
SHORT,
UNSIGNED_SHORT,
INT,
UNSIGNED_INT,
FLOAT,
DOUBLE,
}

/**
* Default vtkDataArray export
*/
declare const vtkDataArray: {
newInstance: typeof newInstance,
extend: typeof extend,
// static
computeRange: typeof computeRange,
createRangeHelper: typeof createRangeHelper,
getDataType: typeof getDataType,
getMaxNorm: typeof getMaxNorm,
// constants
DataTypeByteSize: typeof DataTypeByteSize,
VtkDataTypes: typeof VtkDataTypes,
DefaultDataType: VtkDataTypes,
export declare const vtkDataArray: {
newInstance: typeof newInstance,
extend: typeof extend,
// static
computeRange: typeof computeRange,
createRangeHelper: typeof createRangeHelper,
getDataType: typeof getDataType,
getMaxNorm: typeof getMaxNorm,
// constants
DataTypeByteSize: typeof DataTypeByteSize,
VtkDataTypes: typeof VtkDataTypes,
DefaultDataType: VtkDataTypes,
};

export default vtkDataArray;
Empty file.
58 changes: 58 additions & 0 deletions Sources/Common/DataModel/CardinalSpline1D/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import vtkSpline1D from 'vtk.js/Sources/Common/DataModel/Spline1D';


interface ICardinalSpline1DInitialValues {}

export interface vtkCardinalSpline1D extends vtkSpline1D {

/**
*
* @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
*/
computeOpenCoefficients(size: number, work: Float32Array, x: number[], y: number[]): void;

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

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

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

/**
* vtkCardinalSpline1D 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 vtkCardinalSpline1D: {
newInstance: typeof newInstance,
extend: typeof extend
};
export default vtkCardinalSpline1D;
2 changes: 1 addition & 1 deletion Sources/Common/DataModel/Cell/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface vtkCell extends VtkObject {
initialize(points: vtkPoints, pointIdsList?: number[] | null): void;

/**
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
* @return {Number[]} The bounds for the mapper.
*/
getBounds(): number[];
Expand Down
61 changes: 61 additions & 0 deletions Sources/Common/DataModel/Cone/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { VtkObject } from 'vtk.js/Sources/macro';


interface IConeInitialValues {
angle?: number;
}

export interface vtkCone extends VtkObject {

/**
* Given the point x evaluate the cone equation.
* @param {Number[]} x The point coordinate.
*/
evaluateFunction(x: number[]): number[];

/**
* Given the point x evaluate the equation for the cone gradient.
* @param {Number[]} x The point coordinate.
*/
evaluateGradient(x: number[]): number[];

/**
* Get the angle of the cone.
*/
getAngle(): number;

/**
* Set the value representing the angle of the cone.
* @param {Number} angle The angle of the cone.
*/
setAngle(angle: number): boolean;
}

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

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

/**
* vtkCone computes the implicit function and/or gradient for a cone. vtkCone is
* a concrete implementation of vtkImplicitFunction. TODO: Currently the cone's
* axis of rotation is along the x-axis with the apex at the origin. To
* transform this to a different location requires the application of a
* transformation matrix. This can be performed by supporting transforms at the
* implicit function level, and should be added.
*/
export declare const vtkCone: {
newInstance: typeof newInstance,
extend: typeof extend;
};
export default vtkCone;
Loading

0 comments on commit 54451ff

Please sign in to comment.