From 58891e2efd7730a9cd7ac9618d9d5c047efec0e3 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Wed, 28 Mar 2018 15:09:04 -0400 Subject: [PATCH 1/3] fix(Config): Move config to Generic module to prep for adding configs --- .../index.js} | 24 +----- Sources/config/{ => Generic}/proxyFilter.js | 0 Sources/config/{ => Generic}/proxyUI.js | 2 +- .../proxyViewRepresentationMapping.js | 0 Sources/config/configUtils.js | 79 +++++++++++++++++++ Sources/config/index.js | 5 ++ Sources/index.js | 4 +- 7 files changed, 91 insertions(+), 23 deletions(-) rename Sources/config/{glanceProxyConfig.js => Generic/index.js} (91%) rename Sources/config/{ => Generic}/proxyFilter.js (100%) rename Sources/config/{ => Generic}/proxyUI.js (99%) rename Sources/config/{ => Generic}/proxyViewRepresentationMapping.js (100%) create mode 100644 Sources/config/configUtils.js create mode 100644 Sources/config/index.js diff --git a/Sources/config/glanceProxyConfig.js b/Sources/config/Generic/index.js similarity index 91% rename from Sources/config/glanceProxyConfig.js rename to Sources/config/Generic/index.js index 711ec452..4e9df2be 100644 --- a/Sources/config/glanceProxyConfig.js +++ b/Sources/config/Generic/index.js @@ -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( @@ -59,6 +42,7 @@ function createDefaultView(classFactory, ui) { // ---------------------------------------------------------------------------- export default { + name: 'Generic', definitions: { Proxy: { LookupTable: createProxyDefinition(vtkLookupTableProxy), diff --git a/Sources/config/proxyFilter.js b/Sources/config/Generic/proxyFilter.js similarity index 100% rename from Sources/config/proxyFilter.js rename to Sources/config/Generic/proxyFilter.js diff --git a/Sources/config/proxyUI.js b/Sources/config/Generic/proxyUI.js similarity index 99% rename from Sources/config/proxyUI.js rename to Sources/config/Generic/proxyUI.js index 8f2b1f99..8fe37bb9 100644 --- a/Sources/config/proxyUI.js +++ b/Sources/config/Generic/proxyUI.js @@ -1,4 +1,4 @@ -import Palettes from '../Palettes'; +import Palettes from '../../Palettes'; const Volume = [ { diff --git a/Sources/config/proxyViewRepresentationMapping.js b/Sources/config/Generic/proxyViewRepresentationMapping.js similarity index 100% rename from Sources/config/proxyViewRepresentationMapping.js rename to Sources/config/Generic/proxyViewRepresentationMapping.js diff --git a/Sources/config/configUtils.js b/Sources/config/configUtils.js new file mode 100644 index 00000000..4a46a134 --- /dev/null +++ b/Sources/config/configUtils.js @@ -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, +}; diff --git a/Sources/config/index.js b/Sources/config/index.js new file mode 100644 index 00000000..675dff25 --- /dev/null +++ b/Sources/config/index.js @@ -0,0 +1,5 @@ +import Generic from './Generic'; + +export default { + Generic, +}; diff --git a/Sources/index.js b/Sources/index.js index a0103a85..10565f87 100644 --- a/Sources/index.js +++ b/Sources/index.js @@ -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'; @@ -27,7 +27,7 @@ export const { } = ReaderFactory; export const { registerControlTab, unregisterControlTab } = Controls; -export function createViewer(container, proxyConfiguration = defaultConfig) { +export function createViewer(container, proxyConfiguration = Configs.Generic) { const proxyManager = vtkProxyManager.newInstance({ proxyConfiguration }); const mainView = ReactDOM.render( , From 742d1beec9b6b859da72e2cc747f3946543a6512 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Wed, 28 Mar 2018 15:15:19 -0400 Subject: [PATCH 2/3] fix(Config): Add Medical config --- Sources/config/Medical/index.js | 29 +++++++++++++++++++ Sources/config/Medical/proxyDefs.js | 44 +++++++++++++++++++++++++++++ Sources/config/index.js | 2 ++ 3 files changed, 75 insertions(+) create mode 100644 Sources/config/Medical/index.js create mode 100644 Sources/config/Medical/proxyDefs.js diff --git a/Sources/config/Medical/index.js b/Sources/config/Medical/index.js new file mode 100644 index 00000000..d24a1fa2 --- /dev/null +++ b/Sources/config/Medical/index.js @@ -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; diff --git a/Sources/config/Medical/proxyDefs.js b/Sources/config/Medical/proxyDefs.js new file mode 100644 index 00000000..747600bb --- /dev/null +++ b/Sources/config/Medical/proxyDefs.js @@ -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, +}; diff --git a/Sources/config/index.js b/Sources/config/index.js index 675dff25..34add367 100644 --- a/Sources/config/index.js +++ b/Sources/config/index.js @@ -1,5 +1,7 @@ import Generic from './Generic'; +import Medical from './Medical'; export default { Generic, + Medical, }; From 78bef9550f39543cf569022afdb2121709dd0477 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Thu, 29 Mar 2018 00:34:18 -0400 Subject: [PATCH 3/3] fix(index): Set app mode as url parameter --- Sources/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/index.js b/Sources/index.js index 10565f87..cb063118 100644 --- a/Sources/index.js +++ b/Sources/index.js @@ -27,7 +27,10 @@ export const { } = ReaderFactory; export const { registerControlTab, unregisterControlTab } = Controls; -export function createViewer(container, proxyConfiguration = Configs.Generic) { +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( ,