LookupTableManager

LookupTableManager

var LookupTableManager = require('paraviewweb/src/Common/Core/LookupTableManager'),
instance = new LookupTableManager();

constructor()

Create an instance of a LookupTableManager.

addLookupTable(name, range, preset) : LookupTable

Create a new LookupTable for a given name, scalar range and which preset should
be used. If no preset name is provided, the ‘spectralflip’ preset will be used.

The method will return the newly created LookupTable instance.

removeLookupTable(name)

Remove the LookupTable instance that was registered under the given name.

getLookupTable(name)

Return the LookupTable instance that was registered under the given name.

addFields(fieldsMap)

This will create a LookupTable for each field defined within the map using
the given scalar range.

// fieldsMap can look like that
var fieldsMap = {
'pressure': [-2, 4],
'temperature': [20, 28],
'velocity': [0, 234]
};

onChange(callback) : subscription

Helper method used to bind a listener to the change topic.
This will return a subscription object.

More information can be found on Monologue.js as we rely on it for our
observer methods.

Source

index.js
import Monologue from 'monologue.js';

import LookupTable from 'paraviewweb/src/Common/Core/LookupTable';

const TOPIC = {
CHANGE: 'LookupTable.change',
ACTIVE_CHANGE: 'LookupTable.active.change',
LIST_CHANGE: 'LookupTable.list.change',
};

export default class LookupTableManager {
constructor() {
this.luts = {};
this.lutSubscriptions = {};

this.onChangeCallback = (data, envelope) => {
this.emit(TOPIC.CHANGE, data);
};
}

addLookupTable(name, range, preset) {
if (!this.activeField) {
this.activeField = name;
}

let lut = this.luts[name];
if (lut === undefined) {
lut = new LookupTable(name);

this.luts[name] = lut;
this.lutSubscriptions[name] = lut.onChange(this.onChangeCallback);
}

lut.setPreset(preset || 'spectralflip');
if (range[0] < range[1]) {
lut.setScalarRange(range[0], range[1]);
} else {
lut.setScalarRange(0, 1);
}

this.emit(TOPIC.LIST_CHANGE, this);

return lut;
}

removeLookupTable(name) {
if (this.luts.hasOwn(name)) {
this.lutSubscriptions[name].unsubscribe();
this.luts[name].destroy();

delete this.luts[name];
delete this.lutSubscriptions[name];

this.emit(TOPIC.LIST_CHANGE, this);
}
}

updateActiveLookupTable(name) {
setTimeout(() => {
this.emit(TOPIC.ACTIVE_CHANGE, name);
}, 0);
this.activeField = name;
}

getLookupTable(name) {
return this.luts[name];
}

addFields(fieldsRange, lutConfigs) {
Object.keys(fieldsRange).forEach((field) => {
const lut = this.addLookupTable(field, fieldsRange[field]);
if (lutConfigs && lutConfigs[field]) {
if (lutConfigs[field].discrete !== undefined) {
lut.discrete = lutConfigs[field].discrete;
}
if (lutConfigs[field].preset) {
lut.setPreset(lutConfigs[field].preset);
} else if (lutConfigs[field].controlpoints) {
lut.updateControlPoints(lutConfigs[field].controlpoints);
}
if (lutConfigs[field].range) {
lut.setScalarRange(
lutConfigs[field].range[0],
lutConfigs[field].range[1]
);
}
}
});
}

getActiveField() {
return this.activeField;
}

onChange(callback) {
return this.on(TOPIC.CHANGE, callback);
}

onFieldsChange(callback) {
return this.on(TOPIC.LIST_CHANGE, callback);
}

onActiveLookupTableChange(callback) {
return this.on(TOPIC.ACTIVE_CHANGE, callback);
}
}

// Add Observer pattern using Monologue.js
Monologue.mixInto(LookupTableManager);