Skip to content

Commit

Permalink
Merge pull request #51 from Kitware/app_modes
Browse files Browse the repository at this point in the history
App modes (adds Medical)
  • Loading branch information
floryst authored Mar 29, 2018
2 parents f448f2d + 78bef95 commit b09038f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,13 @@ import vtkSliceRepresentationProxy from 'vtk.js/Sources/Proxy/Representations/Sl
import vtkView from 'vtk.js/Sources/Proxy/Core/ViewProxy';
import vtkVolumeRepresentationProxy from 'vtk.js/Sources/Proxy/Representations/VolumeRepresentationProxy';

import ConfigUtils from '../configUtils';

import proxyUI from './proxyUI';
import proxyFilter from './proxyFilter';
import proxyViewRepresentationMapping from './proxyViewRepresentationMapping';

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

function createProxyDefinition(classFactory, ui = {}, links = []) {
return {
class: classFactory,
options: {
links,
ui,
},
};
}

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

function activateOnCreate(def) {
def.options.activateOnCreate = true;
return def;
}

// ----------------------------------------------------------------------------
const { createProxyDefinition, activateOnCreate } = ConfigUtils;

function createDefaultView(classFactory, ui) {
return activateOnCreate(
Expand All @@ -59,6 +42,7 @@ function createDefaultView(classFactory, ui) {

// ----------------------------------------------------------------------------
export default {
name: 'Generic',
definitions: {
Proxy: {
LookupTable: createProxyDefinition(vtkLookupTableProxy),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Palettes from '../Palettes';
import Palettes from '../../Palettes';

const Volume = [
{
Expand Down
29 changes: 29 additions & 0 deletions Sources/config/Medical/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ConfigUtils from '../configUtils';
import Generic from '../Generic';

import proxyDefs from './proxyDefs';

const { deepCopyPath, objAssignPath } = ConfigUtils;

function copyAssign(config, path, value) {
const newConfig = deepCopyPath(config, path);
objAssignPath(newConfig, path, value);
return newConfig;
}

let config = Generic;
config = copyAssign(config, 'name', 'Medical');

// Mark piecewise function editor as advanced.
// Assumed to be the 3rd object in the options array from Generic ui config.
config = copyAssign(
config,
'definitions.Representations.Volume.options.ui.2.advanced',
1
);

// Our views come with lps orientation axes by default
config = copyAssign(config, 'definitions.Views', proxyDefs.Views);

const Medical = config;
export default Medical;
44 changes: 44 additions & 0 deletions Sources/config/Medical/proxyDefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import vtkView from 'vtk.js/Sources/Proxy/Core/ViewProxy';
import vtk2DView from 'vtk.js/Sources/Proxy/Core/View2DProxy';

import ConfigUtils from '../configUtils';
import proxyUI from '../Generic/proxyUI';

const { activateOnCreate, createProxyDefinition } = ConfigUtils;

function createDefaultView(classFactory, ui) {
return activateOnCreate(
createProxyDefinition(
classFactory,
ui,
[
{ link: 'AnnotationOpacity', property: 'annotationOpacity' },
{
link: 'OrientationAxesVisibility',
property: 'orientationAxesVisibility',
},
{
link: 'OrientationAxesPreset',
property: 'presetToOrientationAxes',
},
],
{}, // definitionOptions
// props
{
presetToOrientationAxes: 'lps',
}
)
);
}

const Views = {
View3D: createDefaultView(vtkView, proxyUI.View3D),
View2D: createDefaultView(vtk2DView, proxyUI.View2D),
View2D_X: createDefaultView(vtk2DView, proxyUI.View2D),
View2D_Y: createDefaultView(vtk2DView, proxyUI.View2D),
View2D_Z: createDefaultView(vtk2DView, proxyUI.View2D),
};

export default {
Views,
};
79 changes: 79 additions & 0 deletions Sources/config/configUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// ----------------------------------------------------------------------------

function createProxyDefinition(
classFactory,
ui = [],
links = [],
definitionOptions = {},
props = {}
) {
return {
class: classFactory,
options: Object.assign({ links, ui }, definitionOptions),
props,
};
}

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

function activateOnCreate(def) {
def.options.activateOnCreate = true;
return def;
}

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

function deepCopyPath(rootObj, pathSpec) {
const path = typeof pathSpec === 'string' ? pathSpec.split('.') : pathSpec;
const newRootObj = Object.assign({}, rootObj);

let obj = newRootObj;
while (path.length) {
const prop = path.shift();
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
if (obj[prop] instanceof Array) {
// handles case when prop is an array
obj[prop] = Array.from(obj[prop]);
} else {
// copy as object
obj[prop] = Object.assign({}, obj[prop]);
}
obj = obj[prop];
} else {
throw new Error(`Invalid property path given: ${path}`);
}
}

return newRootObj;
}

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

function objAssignPath(rootObj, pathSpec, value) {
const path = typeof pathSpec === 'string' ? pathSpec.split('.') : pathSpec;
let obj = rootObj;

while (path.length > 1) {
const prop = path.shift();
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
obj = obj[prop];
} else {
throw new Error(`Invalid property path given: ${path}`);
}
}

if (path.length === 1) {
const lastProp = path.shift();
obj[lastProp] = value;
} else {
throw new Error(`Invalid property path given: ${path}`);
}
}

// ----------------------------------------------------------------------------
export default {
createProxyDefinition,
activateOnCreate,
deepCopyPath,
objAssignPath,
};
7 changes: 7 additions & 0 deletions Sources/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Generic from './Generic';
import Medical from './Medical';

export default {
Generic,
Medical,
};
7 changes: 5 additions & 2 deletions Sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React from 'react';
import './io/ParaViewGlanceReaders';
import './properties';

import defaultConfig from './config/glanceProxyConfig';
import Configs from './config';
import MainView from './MainView';
import * as Controls from './controls';
import ReaderFactory from './io/ReaderFactory';
Expand All @@ -27,7 +27,10 @@ export const {
} = ReaderFactory;
export const { registerControlTab, unregisterControlTab } = Controls;

export function createViewer(container, proxyConfiguration = defaultConfig) {
export function createViewer(container, proxyConfig = null) {
const { mode } = vtkURLExtract.extractURLParameters();
const proxyConfiguration = proxyConfig || Configs[mode] || Configs.Generic;

const proxyManager = vtkProxyManager.newInstance({ proxyConfiguration });
const mainView = ReactDOM.render(
<MainView proxyManager={proxyManager} />,
Expand Down

0 comments on commit b09038f

Please sign in to comment.