@@ -4,12 +4,20 @@ import WidgetManagerConstants from '@kitware/vtk.js/Widgets/Core/WidgetManager/C
44
55import {
66 DEFAULT_VIEW_TYPE ,
7- VIEW_TYPES ,
8- VIEW_ORIENTATIONS ,
7+ DEFAULT_AXIS_PRESET ,
8+ VIEW_TYPE_VALUES ,
9+ DEFAULT_VIEW_TYPES ,
10+ DEFAULT_LPS_VIEW_TYPES ,
11+ DEFAULT_VIEW_ORIENTATION ,
912} from 'paraview-glance/src/components/core/VtkView/constants' ;
1013import { DEFAULT_BACKGROUND } from 'paraview-glance/src/components/core/VtkView/palette' ;
1114
12- import { remapIdValues , wrapMutationAsAction } from 'paraview-glance/src/utils' ;
15+ import {
16+ remapIdValues ,
17+ wrapMutationAsAction ,
18+ getLPSDirections ,
19+ updateViewOrientationFromBasisAndAxis ,
20+ } from 'paraview-glance/src/utils' ;
1321
1422const { CaptureOn } = WidgetManagerConstants ;
1523
@@ -21,7 +29,7 @@ export default ({ proxyManager }) => ({
2129 backgroundColors : { } , // viewType -> bg
2230 globalBackgroundColor : DEFAULT_BACKGROUND ,
2331 axisType : 'arrow' ,
24- axisPreset : 'default' ,
32+ axisPreset : DEFAULT_AXIS_PRESET ,
2533 axisVisible : true ,
2634 annotationOpacity : 1 ,
2735 interactionStyle3D : '3D' ,
@@ -30,8 +38,14 @@ export default ({ proxyManager }) => ({
3038 // If null, it will be calculated and set on first use
3139 firstPersonMovementSpeed : null ,
3240 maxTextureLODSize : 50000 , // Units are in KiB
33- viewOrder : VIEW_TYPES . map ( ( v ) => v . value ) ,
41+ viewOrder : Object . values ( VIEW_TYPE_VALUES ) ,
3442 visibleCount : 1 ,
43+ // a basis in column-major order (list of 3 vectors): number[3][3]
44+ viewOrientation : DEFAULT_VIEW_ORIENTATION ,
45+ // for each view type, the corresponding text to display { viewType: text }
46+ viewTypes : DEFAULT_VIEW_TYPES ,
47+ masterSourceId : null , // null or string
48+ previousConfigurationPreset : null , // null or string, can only be set to a string
3549 } ,
3650 mutations : {
3751 setGlobalBackground ( state , background ) {
@@ -66,6 +80,18 @@ export default ({ proxyManager }) => ({
6680 mapViewTypeToId ( state , { viewType, viewId } ) {
6781 Vue . set ( state . viewTypeToId , viewType , viewId ) ;
6882 } ,
83+ setViewTypes ( state , types ) {
84+ state . viewTypes = types ;
85+ } ,
86+ setViewOrientation ( state , orientation ) {
87+ state . viewOrientation = orientation ;
88+ } ,
89+ setMasterSourceId ( state , { sourceId } ) {
90+ state . masterSourceId = sourceId ;
91+ } ,
92+ setPreviousConfigurationPreset ( state , preset ) {
93+ state . previousConfigurationPreset = preset ;
94+ } ,
6995 changeBackground ( state , { viewType, color } ) {
7096 state . backgroundColors [ viewType ] = color ;
7197 } ,
@@ -97,8 +123,11 @@ export default ({ proxyManager }) => ({
97123 const view = proxyManager . createProxy ( 'Views' , type , { name } ) ;
98124
99125 // Update orientation
100- const { axis, orientation, viewUp } = VIEW_ORIENTATIONS [ name ] ;
101- view . updateOrientation ( axis , orientation , viewUp ) ;
126+ updateViewOrientationFromBasisAndAxis (
127+ view ,
128+ state . viewOrientation ,
129+ name
130+ ) ;
102131
103132 // set background to transparent
104133 view . setBackground ( 0 , 0 , 0 , 0 ) ;
@@ -167,11 +196,86 @@ export default ({ proxyManager }) => ({
167196 } ) ;
168197 commit ( 'setAxisType' , axisType ) ;
169198 } ,
170- setAxisPreset ( { commit } , axisPreset ) {
199+ setAxisPreset ( { commit, dispatch } , axisPreset ) {
171200 proxyManager . getViews ( ) . forEach ( ( view ) => {
172201 view . setPresetToOrientationAxes ( axisPreset ) ;
173202 } ) ;
174203 commit ( 'setAxisPreset' , axisPreset ) ;
204+ dispatch ( 'configureViewOrientationAndTypes' ) ;
205+ } ,
206+ setViewOrientation ( { commit, state } , orientation ) {
207+ commit ( 'setViewOrientation' , orientation ) ;
208+ Object . entries ( state . viewTypeToId ) . forEach ( ( [ viewType , viewId ] ) => {
209+ const view = proxyManager . getProxyById ( viewId ) ;
210+ const [ type , name ] = viewType . split ( ':' ) ;
211+ updateViewOrientationFromBasisAndAxis (
212+ view ,
213+ orientation ,
214+ name ,
215+ type === 'View3D' ? 100 : 0
216+ ) ;
217+ } ) ;
218+ } ,
219+ setViewTypes ( { commit } , viewTypes ) {
220+ commit ( 'setViewTypes' , viewTypes ) ;
221+ } ,
222+ configureViewOrientationAndTypes ( { commit, dispatch, state } ) {
223+ if ( state . axisPreset === 'lps' ) {
224+ const masterSource =
225+ state . masterSourceId &&
226+ proxyManager . getProxyById ( state . masterSourceId ) ;
227+ if ( masterSource ?. getDataset ( ) . isA ( 'vtkImageData' ) ) {
228+ // lps mode with a master volume
229+ const directionMatrix = masterSource . getDataset ( ) . getDirection ( ) ;
230+ const lpsDirections = getLPSDirections ( directionMatrix ) ;
231+ const axisToXYZ = [ 'x' , 'y' , 'z' ] ;
232+ const viewTypes = {
233+ [ VIEW_TYPE_VALUES . default ] : '3D' ,
234+ [ VIEW_TYPE_VALUES [ axisToXYZ [ lpsDirections . l . axis ] ] ] : 'Sagittal' ,
235+ [ VIEW_TYPE_VALUES [ axisToXYZ [ lpsDirections . p . axis ] ] ] : 'Coronal' ,
236+ [ VIEW_TYPE_VALUES [ axisToXYZ [ lpsDirections . s . axis ] ] ] : 'Axial' ,
237+ } ;
238+ const viewOrientation = [
239+ lpsDirections . l . vector ,
240+ lpsDirections . p . vector ,
241+ lpsDirections . s . vector ,
242+ ] ;
243+ dispatch ( 'setViewTypes' , viewTypes ) ;
244+ dispatch ( 'setViewOrientation' , viewOrientation ) ;
245+ } else if ( state . previousConfigurationPreset !== 'lps' ) {
246+ // lps mode but no master volume and previous configuration wasn't lps
247+ dispatch ( 'setViewTypes' , DEFAULT_LPS_VIEW_TYPES ) ;
248+ dispatch ( 'setViewOrientation' , DEFAULT_VIEW_ORIENTATION ) ;
249+ }
250+ } else {
251+ // Not in lps mode
252+ dispatch ( 'setViewTypes' , DEFAULT_VIEW_TYPES ) ;
253+ dispatch ( 'setViewOrientation' , DEFAULT_VIEW_ORIENTATION ) ;
254+ }
255+ commit ( 'setPreviousConfigurationPreset' , state . axisPreset ) ;
256+ } ,
257+ updateMasterSourceId ( { dispatch, state } , datasets ) {
258+ const hiddenDatasets = proxyManager
259+ . getRepresentations ( )
260+ . filter ( ( r ) => ! r . isVisible ( ) )
261+ . map ( ( r ) => r . getInput ( ) . getProxyId ( ) ) ;
262+ const fullyVisibleDatasets = datasets . filter (
263+ ( dataset ) => ! hiddenDatasets . includes ( dataset )
264+ ) ;
265+
266+ if ( ! fullyVisibleDatasets . includes ( state . masterSourceId ) ) {
267+ if ( fullyVisibleDatasets . length === 0 ) {
268+ dispatch ( 'setMasterSourceId' , { sourceId : null } ) ;
269+ } else {
270+ dispatch ( 'setMasterSourceId' , { sourceId : fullyVisibleDatasets [ 0 ] } ) ;
271+ }
272+ }
273+ } ,
274+ setMasterSourceId ( { commit, dispatch, state } , { sourceId } ) {
275+ commit ( 'setMasterSourceId' , { sourceId } ) ;
276+ if ( state . axisPreset === 'lps' ) {
277+ dispatch ( 'configureViewOrientationAndTypes' ) ;
278+ }
175279 } ,
176280 setAxisVisible ( { commit } , visible ) {
177281 proxyManager . getViews ( ) . forEach ( ( view ) => {
0 commit comments