DataSet

Introduction

vtkDataSet is an abstract class that specifies an interface for dataset
objects. vtkDataSet also provides methods to provide information about
the data, such as center, bounding box, and representative length.

In vtk a dataset consists of a structure (geometry and topology) and
attribute data. The structure is defined implicitly or explicitly as
a collection of cells. The geometry of the structure is contained in
point coordinates plus the cell interpolation functions. The topology
of the dataset structure is defined by cell types and how the cells
share their defining points.

Attribute data in vtk is either point data (data at points) or cell data
(data at cells). Typically filters operate on point data, but some may
operate on cell data, both cell and point data, either one, or none.

Methods

extend

Method used to decorate a given object (publicAPI+model) with vtkDataSet 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 IDataSetInitialValues No (default: {})

getCellData

Get dataset’s cell data

getFieldData

Get dataset’s field data

getPointData

Get dataset’s point data.

newInstance

Method used to create a new instance of vtkDataSet.

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

setCellData

Set dataset’s cell data

Argument Type Required Description
cellData vtkDataSetAttributes Yes

setFieldData

Set dataset’s field data

Argument Type Required Description
fieldData vtkDataSetAttributes Yes

setPointData

Set dataset’s point data.

Argument Type Required Description
pointData vtkDataSetAttributes Yes

Source

Constants.d.ts
export declare enum FieldAssociations {
FIELD_ASSOCIATION_POINTS = 0,
FIELD_ASSOCIATION_CELLS = 1,
FIELD_ASSOCIATION_NONE = 2,
FIELD_ASSOCIATION_POINTS_THEN_CELLS = 3,
FIELD_ASSOCIATION_VERTICES = 4,
FIELD_ASSOCIATION_EDGES = 5,
FIELD_ASSOCIATION_ROWS = 6,
NUMBER_OF_ASSOCIATIONS = 7,
}

export declare enum FieldDataTypes {
UNIFORM = 0,
DATA_OBJECT_FIELD = 0,
COORDINATE = 1,
POINT_DATA = 1,
POINT = 2,
POINT_FIELD_DATA = 2,
CELL = 3,
CELL_FIELD_DATA = 3,
VERTEX = 4,
VERTEX_FIELD_DATA = 4,
EDGE = 5,
EDGE_FIELD_DATA = 5,
ROW = 6,
ROW_DATA = 6,
}
Constants.js
// Specify how data arrays can be used by data objects
export const FieldDataTypes = {
UNIFORM: 0, // data that does not vary over points/cells/etc.
DATA_OBJECT_FIELD: 0, // to match VTK

COORDINATE: 1, // data that specifies the location of each point
POINT_DATA: 1, // to match VTK

POINT: 2, // data defined at each point, but that does not specify the point location
POINT_FIELD_DATA: 2, // to match VTK

CELL: 3, // data defined at each cell, but that does not specify the cell
CELL_FIELD_DATA: 3, // to match VTK

VERTEX: 4, // data defined at each graph vertex, but that does not specify the graph vertex
VERTEX_FIELD_DATA: 4, // to match VTK

EDGE: 5, // data defined at each graph edge, but that does not specify the graph edge
EDGE_FIELD_DATA: 5, // to match VTK

ROW: 6, // data specifying a table row
ROW_DATA: 6, // to match VTK
};

export const FieldAssociations = {
FIELD_ASSOCIATION_POINTS: 0,
FIELD_ASSOCIATION_CELLS: 1,
FIELD_ASSOCIATION_NONE: 2,
FIELD_ASSOCIATION_POINTS_THEN_CELLS: 3,
FIELD_ASSOCIATION_VERTICES: 4,
FIELD_ASSOCIATION_EDGES: 5,
FIELD_ASSOCIATION_ROWS: 6,
NUMBER_OF_ASSOCIATIONS: 7,
};

export default {
FieldDataTypes,
FieldAssociations,
};
index.d.ts
import vtkDataSetAttributes from '../DataSetAttributes';
import { vtkObject } from "../../../interfaces" ;
import { FieldAssociations, FieldDataTypes } from "./Constants";

/**
*
*/
export interface IDataSetInitialValues {}

export interface vtkDataSet extends vtkObject {

/**
* Get dataset's cell data
*/
getCellData(): vtkDataSetAttributes;

/**
* Get dataset's field data
*/
getFieldData(): vtkDataSetAttributes;

/**
* Get dataset's point data.
*/
getPointData(): vtkDataSetAttributes;

/**
* Set dataset's cell data
* @param {vtkDataSetAttributes} cellData
*/
setCellData(cellData: vtkDataSetAttributes): boolean;

/**
* Set dataset's field data
* @param {vtkDataSetAttributes} fieldData
*/
setFieldData(fieldData: vtkDataSetAttributes): boolean;

/**
* Set dataset's point data.
* @param {vtkDataSetAttributes} pointData
*/
setPointData(pointData: vtkDataSetAttributes): boolean;
}

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

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

/**
* vtkDataSet is an abstract class that specifies an interface for dataset
* objects. vtkDataSet also provides methods to provide information about
* the data, such as center, bounding box, and representative length.
*
* In vtk a dataset consists of a structure (geometry and topology) and
* attribute data. The structure is defined implicitly or explicitly as
* a collection of cells. The geometry of the structure is contained in
* point coordinates plus the cell interpolation functions. The topology
* of the dataset structure is defined by cell types and how the cells
* share their defining points.
*
* Attribute data in vtk is either point data (data at points) or cell data
* (data at cells). Typically filters operate on point data, but some may
* operate on cell data, both cell and point data, either one, or none.
*/
export declare const vtkDataSet: {
newInstance: typeof newInstance;
extend: typeof extend;
FieldAssociation: typeof FieldAssociations;
FieldDataTypes: typeof FieldDataTypes;
};
export default vtkDataSet;
index.js
import macro from 'vtk.js/Sources/macros';
import vtk from 'vtk.js/Sources/vtk';
import vtkDataSetAttributes from 'vtk.js/Sources/Common/DataModel/DataSetAttributes';
import Constants from 'vtk.js/Sources/Common/DataModel/DataSet/Constants';

// import vtkBoundingBox from '../BoundingBox';
// import * as vtkMath from '../../Core/Math';
//
// function getBounds(dataset) {
// if (dataset.bounds) {
// return dataset.bounds;
// }
// if (dataset.type && dataset[dataset.type]) {
// const ds = dataset[dataset.type];
// if (ds.bounds) {
// return ds.bounds;
// }
// if (ds.Points && ds.Points.bounds) {
// return ds.Points.bounds;
// }

// if (ds.Points && ds.Points.values) {
// const array = ds.Points.values;
// const bbox = [...vtkBoundingBox.INIT_BOUNDS];
// const size = array.length;
// const delta = ds.Points.numberOfComponents ? ds.Points.numberOfComponents : 3;
// for (let idx = 0; idx < size; idx += delta) {
// vtkBoundingBox.addPoint(bbox, array[idx * delta], array[(idx * delta) + 1], array[(idx * delta) + 2]);
// }
// ds.Points.bounds = bbox;
// return ds.Points.bounds;
// }
// }
// return vtkMath.createUninitializedBounds();
// }

// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

const DATASET_FIELDS = ['pointData', 'cellData', 'fieldData'];

// ----------------------------------------------------------------------------
// vtkDataSet methods
// ----------------------------------------------------------------------------

function vtkDataSet(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkDataSet');

// Add dataset attributes
DATASET_FIELDS.forEach((fieldName) => {
if (!model[fieldName]) {
model[fieldName] = vtkDataSetAttributes.newInstance();
} else {
model[fieldName] = vtk(model[fieldName]);
}
});

const superShallowCopy = publicAPI.shallowCopy;
publicAPI.shallowCopy = (other, debug = false) => {
superShallowCopy(other, debug);
DATASET_FIELDS.forEach((fieldName) => {
model[fieldName] = vtkDataSetAttributes.newInstance();
model[fieldName].shallowCopy(other.getReferenceByName(fieldName));
});
};
}

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

const DEFAULT_VALUES = {
// pointData: null,
// cellData: null,
// fieldData: null,
};

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

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

// Object methods
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, DATASET_FIELDS);

// Object specific methods
vtkDataSet(publicAPI, model);
}

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

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

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

export default { newInstance, extend, ...Constants };