@thewtex/vtk.js-esm
Version:
Visualization Toolkit for the Web
114 lines (96 loc) • 4.12 kB
JavaScript
import macro from '../../macro.js';
import vtkImageData from '../../Common/DataModel/ImageData.js';
import vtkDataArray from '../../Common/Core/DataArray.js';
function vtkRTAnalyticSource(publicAPI, model) {
var _this = this;
// Set our className
model.classHierarchy.push('vtkRTAnalyticSource');
publicAPI.requestData = function (inData, outData) {
if (model.deleted) {
return;
}
var state = {};
var dataset = {
type: 'vtkImageData',
mtime: model.mtime,
metadata: {
source: 'vtkRTAnalyticSource',
state: state
}
}; // Add parameter used to create dataset as metadata.state[*]
['standardDeviation', 'center', 'frequency', 'magnitude', 'maximum'].forEach(function (field) {
state[field] = [].concat(model[field]);
});
var id = vtkImageData.newInstance(dataset);
id.setSpacing(1.0, 1.0, 1.0);
id.setExtent.apply(_this, model.wholeExtent);
id.setOrigin(0.0, 0.0, 0.0);
id.setDirection(model.dataDirection);
var dims = [0, 0, 0];
dims = dims.map(function (_, i) {
return model.wholeExtent[i * 2 + 1] - model.wholeExtent[i * 2] + 1;
});
var newArray = new Uint8Array(dims[0] * dims[1] * dims[2]);
var temp2 = 1.0 / (2.0 * model.standardDeviation * model.standardDeviation);
var xval = 0;
var yval = 0;
var zval = 0;
var scale = [1.0 / (model.wholeExtent[1] - model.wholeExtent[0]), 1.0 / (model.wholeExtent[3] - model.wholeExtent[2]), 1.0 / (model.wholeExtent[5] - model.wholeExtent[4])];
var i = 0;
for (var z = model.wholeExtent[4]; z <= model.wholeExtent[5]; z++) {
zval = (model.center[2] - z) * scale[2];
var zfactor = model.magnitude[2] * Math.cos(model.frequency[2] * zval);
zval *= zval;
for (var y = model.wholeExtent[2]; y <= model.wholeExtent[3]; y++) {
yval = (model.center[1] - y) * scale[1];
var yfactor = model.magnitude[1] * Math.sin(model.frequency[1] * yval);
yval *= yval;
for (var x = model.wholeExtent[0]; x <= model.wholeExtent[1]; x++) {
xval = (model.center[0] - x) * scale[0];
var sum = zval + yval + xval * xval;
var xfactor = model.magnitude[0] * Math.sin(model.frequency[0] * xval);
newArray[i] = model.maximum * Math.exp(-sum * temp2) + xfactor + yfactor + zfactor + model.offset;
i++;
}
}
}
var da = vtkDataArray.newInstance({
numberOfComponents: 1,
values: newArray
});
da.setName('scalars');
var cpd = id.getPointData();
cpd.setScalars(da); // Update output
outData[0] = id;
};
} // ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
var DEFAULT_VALUES = {
offset: 40,
maximum: 120,
center: [0, 0, 0],
frequency: [60, 30, 40],
magnitude: [10, 18, 5],
standardDeviation: 0.5,
wholeExtent: [-10, 10, -10, 10, -10, 10],
dataDirection: [1, 0, 0, 0, 1, 0, 0, 0, 1]
}; // ----------------------------------------------------------------------------
function extend(publicAPI, model) {
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, ['offset', 'maximum', 'standardDeviation']);
macro.setGetArray(publicAPI, model, ['center', 'frequency', 'magnitude'], 3);
macro.setGetArray(publicAPI, model, ['wholeExtent'], 6);
macro.setGetArray(publicAPI, model, ['dataDirection'], 9);
macro.algo(publicAPI, model, 0, 1);
vtkRTAnalyticSource(publicAPI, model);
} // ----------------------------------------------------------------------------
var newInstance = macro.newInstance(extend, 'vtkRTAnalyticSource'); // ----------------------------------------------------------------------------
var vtkRTAnalyticSource$1 = {
newInstance: newInstance,
extend: extend
};
export default vtkRTAnalyticSource$1;
export { extend, newInstance };