Skip to content

Commit

Permalink
Merge pull request #543 from Kitware/source-proxy-for-filtering
Browse files Browse the repository at this point in the history
fix(SourceProxy): Add support for filter algo
  • Loading branch information
jourdain authored Feb 1, 2018
2 parents 157f344 + 5468ef1 commit e6569f4
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 110 deletions.
41 changes: 29 additions & 12 deletions Sources/Proxy/Core/AbstractRepresentationProxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ import macro from 'vtk.js/Sources/macro';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkScalarsToColors from 'vtk.js/Sources/Common/Core/ScalarsToColors';

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

function connectMapper(mapper, input) {
const algo = input.getAlgo();
if (algo) {
mapper.setInputConnection(algo.getOutputPort());
} else {
mapper.setInputData(input.getDataset());
}
}

// ----------------------------------------------------------------------------
// vtkAbstractRepresentationProxy methods
// ----------------------------------------------------------------------------
Expand All @@ -21,10 +10,30 @@ function vtkAbstractRepresentationProxy(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkAbstractRepresentationProxy');

function updateConnectivity() {
if (model.input) {
let count = model.sourceDependencies.length;
while (count--) {
model.sourceDependencies[count].setInputData(model.input.getDataset());
}
}
}

publicAPI.setInput = (source) => {
if (model.sourceSubscription) {
model.sourceSubscription.unsubscribe();
model.sourceSubscription = null;
}
publicAPI.gcPropertyLinks();
model.input = source;
publicAPI.updateColorByDomain();

if (model.input) {
updateConnectivity();
model.sourceSubscription = model.input.onDatasetChange(
updateConnectivity
);
}
};

publicAPI.getInputDataSet = () =>
Expand Down Expand Up @@ -268,6 +277,13 @@ function vtkAbstractRepresentationProxy(publicAPI, model) {
},
});
};

publicAPI.delete = macro.chain(() => {
if (model.sourceSubscription) {
model.sourceSubscription.unsubscribe();
model.sourceSubscription = null;
}
}, publicAPI.delete);
}

// ----------------------------------------------------------------------------
Expand All @@ -277,6 +293,7 @@ function vtkAbstractRepresentationProxy(publicAPI, model) {
const DEFAULT_VALUES = {
actors: [],
volumes: [],
sourceDependencies: [],
};

// ----------------------------------------------------------------------------
Expand All @@ -292,4 +309,4 @@ function extend(publicAPI, model, initialValues = {}) {
macro.proxy(publicAPI, model);
}

export default { extend, connectMapper };
export default { extend };
2 changes: 1 addition & 1 deletion Sources/Proxy/Core/ProxyManager/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default function addRegistrationAPI(publicAPI, model) {
const viewToUse = view || publicAPI.getActiveView();

// Can only get a representation for a source and a view
if (!sourceToUse || !viewToUse) {
if (!sourceToUse || !viewToUse || !sourceToUse.getType()) {
return null;
}

Expand Down
84 changes: 72 additions & 12 deletions Sources/Proxy/Core/SourceProxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,98 @@ function vtkSourceProxy(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkSourceProxy');

function updateDataset() {
if (model.algo) {
publicAPI.setDataset(model.algo.getOutputData(), model.type);
// API ----------------------------------------------------------------------

publicAPI.setInputProxy = (source) => {
if (model.inputSubscription) {
model.inputSubscription();
model.inputSubscription = null;
}
}
model.inputProxy = source;
if (model.inputProxy) {
model.inputSubscription = source.onModified(
publicAPI.update,
-1
).unsubscribe; // Trigger at next cycle
}
publicAPI.update();
};

// API ----------------------------------------------------------------------
// --------------------------------------------------------------------------

publicAPI.setInputData = (ds, type) => {
if (model.dataset !== ds) {
model.dataset = ds;
model.type = type || ds.getClassName();
publicAPI.modified();
publicAPI.invokeDatasetChange();
}
};

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

publicAPI.setInputAlgorithm = (algo, type) => {
publicAPI.setInputAlgorithm = (algo, type, autoUpdate = true) => {
if (model.algo !== algo) {
model.algo = algo;
if (model.algoSubscription) {
model.algoSubscription();
model.algoSubscription = null;
}
if (algo) {
publicAPI.setInputData(algo.getOutputData(), type);
model.algoSubscription = algo.onModified(updateDataset, -1).unsubscribe; // Trigger at next cycle
if (algo && autoUpdate) {
model.algoSubscription = algo.onModified(() => {
publicAPI.update();
}, -1).unsubscribe; // Trigger at next cycle
publicAPI.update();
}
}
};

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

publicAPI.update = () => {
if (model.algo && model.inputProxy) {
model.algo.setInputData(model.inputProxy.getDataset());
}
if (model.updateDomain && model.inputProxy) {
model.updateDomain(publicAPI, model.inputProxy.getDataset());
}
if (model.algo) {
publicAPI.setInputData(model.algo.getOutputData(), model.type);
}
};

publicAPI.getUpdate = () => model.algo.getMTime() > model.dataset.getMTime();

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

publicAPI.delete = macro.chain(() => {
if (model.algoSubscription) {
model.algoSubscription();
model.algoSubscription = null;
}
if (model.inputSubscription) {
model.inputSubscription();
model.inputSubscription = null;
}
}, publicAPI.delete);

// --------------------------------------------------------------------------
// Initialisation
// --------------------------------------------------------------------------

if (model.inputProxy) {
model.inputSubscription = model.inputProxy.onModified(() => {
publicAPI.update();
}, -1).unsubscribe; // Trigger at next cycle
}
if (model.algoFactory) {
publicAPI.setInputAlgorithm(
model.algoFactory.newInstance(),
null,
model.autoUpdate
);
}
publicAPI.update();
}

// ----------------------------------------------------------------------------
Expand All @@ -71,11 +123,16 @@ export function extend(publicAPI, model, initialValues = {}) {
'algo',
'inputProxy',
]);
macro.set(publicAPI, model, ['name', 'inputProxy']);
macro.set(publicAPI, model, ['name']);
macro.event(publicAPI, model, 'DatasetChange');
macro.proxy(publicAPI, model);

// Object specific methods
vtkSourceProxy(publicAPI, model);
macro.proxy(publicAPI, model);

if (model.proxyPropertyMapping) {
macro.proxyPropertyMapping(publicAPI, model, model.proxyPropertyMapping);
}
}

// ----------------------------------------------------------------------------
Expand All @@ -84,4 +141,7 @@ export const newInstance = macro.newInstance(extend, 'vtkSourceProxy');

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

export default { newInstance, extend };
export default {
newInstance,
extend,
};
24 changes: 5 additions & 19 deletions Sources/Proxy/Representations/GeometryRepresentationProxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const PROPERTIES_DEFAULT = {
function vtkGeometryRepresentationProxy(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkGeometryRepresentationProxy');
const superSetInput = publicAPI.setInput;

// parent methods
model.selectedArray = null; // Default use solid color

// Internals
model.mapper = vtkMapper.newInstance({
Expand All @@ -40,21 +36,11 @@ function vtkGeometryRepresentationProxy(publicAPI, model) {
model.actor = vtkActor.newInstance();
model.property = model.actor.getProperty();

// API ----------------------------------------------------------------------

publicAPI.setInput = (source) => {
superSetInput(source);

if (!source) {
return;
}

vtkAbstractRepresentationProxy.connectMapper(model.mapper, source);

// connect rendering pipeline
model.actor.setMapper(model.mapper);
model.actors.push(model.actor);
};
// Auto connect mappers
model.sourceDependencies.push(model.mapper);
// connect rendering pipeline
model.actor.setMapper(model.mapper);
model.actors.push(model.actor);
}

// ----------------------------------------------------------------------------
Expand Down
37 changes: 14 additions & 23 deletions Sources/Proxy/Representations/MoleculeRepresentationProxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import vtkAbstractRepresentationProxy from 'vtk.js/Sources/Proxy/Core/AbstractRe
function vtkMoleculeRepresentationProxy(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkMoleculeRepresentationProxy');
const superSetInput = publicAPI.setInput;

// Internals
model.filter = vtkMoleculeToRepresentation.newInstance();
Expand All @@ -22,32 +21,24 @@ function vtkMoleculeRepresentationProxy(publicAPI, model) {
model.sphereActor = vtkActor.newInstance();
model.stickActor = vtkActor.newInstance();

// API ----------------------------------------------------------------------

publicAPI.setInput = (source) => {
superSetInput(source);
model.sourceDependencies.push(model.filter);

if (!source) {
return;
}
// render sphere
model.sphereMapper.setInputConnection(model.filter.getOutputPort(0));
model.sphereMapper.setScaleArray(model.filter.getSphereScaleArrayName());
model.sphereActor.setMapper(model.sphereMapper);

vtkAbstractRepresentationProxy.connectMapper(model.filter, source);
// render sticks
model.stickMapper.setInputConnection(model.filter.getOutputPort(1));
model.stickMapper.setScaleArray('stickScales');
model.stickMapper.setOrientationArray('orientation');
model.stickActor.setMapper(model.stickMapper);

// render sphere
model.sphereMapper.setInputConnection(model.filter.getOutputPort(0));
model.sphereMapper.setScaleArray(model.filter.getSphereScaleArrayName());
model.sphereActor.setMapper(model.sphereMapper);
// Add actors
model.actors.push(model.sphereActor);
model.actors.push(model.stickActor);

// render sticks
model.stickMapper.setInputConnection(model.filter.getOutputPort(1));
model.stickMapper.setScaleArray('stickScales');
model.stickMapper.setOrientationArray('orientation');
model.stickActor.setMapper(model.stickMapper);

// Add actors
model.actors.push(model.sphereActor);
model.actors.push(model.stickActor);
};
// API ----------------------------------------------------------------------

publicAPI.setColorBy = () => {};
publicAPI.getColorBy = () => [];
Expand Down
34 changes: 19 additions & 15 deletions Sources/Proxy/Representations/SliceRepresentationProxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,40 @@ function vtkSliceRepresentationProxy(publicAPI, model) {
model.actor = vtkImageSlice.newInstance();
model.property = model.actor.getProperty();

// API ----------------------------------------------------------------------
// connect rendering pipeline
model.actor.setMapper(model.mapper);
model.actors.push(model.actor);

publicAPI.setInput = (source) => {
superSetInput(source);

if (!source) {
return;
}

vtkAbstractRepresentationProxy.connectMapper(model.mapper, source);
function setInputData(inputDataset) {
const state = updateDomains(
publicAPI.getInputDataSet(),
inputDataset,
publicAPI.getDataArray(),
model,
publicAPI.updateProxyProperty
);
publicAPI.set(state);

// Init slice location
const extent = publicAPI.getInputDataSet().getExtent();
const extent = inputDataset.getExtent();
publicAPI.setXSlice(Math.floor(mean(extent[0], extent[1])));
publicAPI.setYSlice(Math.floor(mean(extent[2], extent[3])));
publicAPI.setZSlice(Math.floor(mean(extent[4], extent[5])));
}

// connect rendering pipeline
model.actor.setMapper(model.mapper);
model.actors.push(model.actor);
// Keep things updated
model.sourceDependencies.push(model.mapper);
model.sourceDependencies.push({ setInputData });

// Create a link handler on source
// API ----------------------------------------------------------------------

publicAPI.setInput = (source) => {
superSetInput(source);

if (!source) {
return;
}

// Create a link handler on source
// Ensure the delete will clear all possible conbinaison
['SliceX', 'SliceY', 'SliceZ', 'ColorWindow', 'ColorLevel'].forEach(
(linkName) => {
Expand Down
Loading

0 comments on commit e6569f4

Please sign in to comment.