Skip to content
Snippets Groups Projects
Commit d4679feb authored by Xiao Gui's avatar Xiao Gui
Browse files

fix: switch space fallback to related parcs first

fix: p/n shortcut updates pip
parent b4fdb3ae
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
- quick search now show branches in addition to leaves - quick search now show branches in addition to leaves
- added context in region hierarchy view - added context in region hierarchy view
- added coordinate entry dialog - added coordinate entry dialog
- switching templates will now fallback to use the newest parcellation in the same series
## Bugfix ## Bugfix
......
...@@ -220,9 +220,45 @@ export class Effect { ...@@ -220,9 +220,45 @@ export class Effect {
const foundAtlas = atlas && result.atlases.find(a => a.id === atlas.id) const foundAtlas = atlas && result.atlases.find(a => a.id === atlas.id)
const foundParc = parcellation && result.parcellations.find(a => a.id === parcellation.id) const foundParc = parcellation && result.parcellations.find(a => a.id === parcellation.id)
const foundSpace = template && result.spaces.find(a => a.id === template.id) const foundSpace = template && result.spaces.find(a => a.id === template.id)
const prevNextParcs = (() => {
const FUSE = 10
let prevParcId = parcellation.prevId
let currentParcId = parcellation.id
let breakPrev = false
let breakNext = false
let iter = 0
const returnArr = []
// eslint-disable-next-line no-constant-condition
while (true) {
if (iter > FUSE || (breakPrev && breakNext)) {
break
}
iter ++
if (!breakPrev) {
const prevParc = result.parcellations.find(p => p.id === prevParcId)
if (prevParc) {
returnArr.push(prevParc)
prevParcId = prevParc.prevId
} else {
breakPrev = true
}
}
if (!breakNext) {
const nextParc = result.parcellations.find(p => p.prevId === currentParcId)
if (nextParc) {
returnArr.splice(0, 0, nextParc)
currentParcId = nextParc.id
} else {
breakNext = true
}
}
}
return returnArr
})()
result.atlases = foundAtlas && [foundAtlas] || result.atlases result.atlases = foundAtlas && [foundAtlas] || result.atlases
result.parcellations = foundParc && [foundParc] || result.parcellations result.parcellations = foundParc && [foundParc] || prevNextParcs[0] && [prevNextParcs[0]] || result.parcellations
result.spaces = foundSpace && [foundSpace] || result.spaces result.spaces = foundSpace && [foundSpace] || result.spaces
/** /**
......
import { Component, OnDestroy, Inject, ViewChild, ChangeDetectionStrategy } from "@angular/core"; import { Component, Inject, ViewChild, ChangeDetectionStrategy, inject } from "@angular/core";
import { FormControl } from "@angular/forms"; import { FormControl } from "@angular/forms";
import { select, Store } from "@ngrx/store"; import { select, Store } from "@ngrx/store";
import { combineLatest, concat, NEVER, Observable, of, Subject, Subscription } from "rxjs"; import { combineLatest, concat, NEVER, Observable, of, Subject } from "rxjs";
import { switchMap, distinctUntilChanged, map, debounceTime, shareReplay, take, withLatestFrom, filter } from "rxjs/operators"; import { switchMap, distinctUntilChanged, map, debounceTime, shareReplay, take, withLatestFrom, filter, takeUntil } from "rxjs/operators";
import { SAPI } from "src/atlasComponents/sapi";
import { SxplrTemplate } from "src/atlasComponents/sapi/sxplrTypes" import { SxplrTemplate } from "src/atlasComponents/sapi/sxplrTypes"
import { selectedTemplate } from "src/state/atlasSelection/selectors"; import { selectedTemplate } from "src/state/atlasSelection/selectors";
import { panelMode, panelOrder } from "src/state/userInterface/selectors"; import { panelMode, panelOrder } from "src/state/userInterface/selectors";
...@@ -15,6 +14,7 @@ import { EnumClassicalView } from "src/atlasComponents/constants" ...@@ -15,6 +14,7 @@ import { EnumClassicalView } from "src/atlasComponents/constants"
import { atlasSelection } from "src/state"; import { atlasSelection } from "src/state";
import { floatEquality } from "common/util" import { floatEquality } from "common/util"
import { CURRENT_TEMPLATE_DIM_INFO, TemplateInfo } from "../../layerCtrl.service/layerCtrl.util"; import { CURRENT_TEMPLATE_DIM_INFO, TemplateInfo } from "../../layerCtrl.service/layerCtrl.util";
import { DestroyDirective } from "src/util/directives/destroy.directive";
const MAX_DIM = 200 const MAX_DIM = 200
...@@ -43,21 +43,25 @@ function getDim(triplet: number[], view: EnumClassicalView) { ...@@ -43,21 +43,25 @@ function getDim(triplet: number[], view: EnumClassicalView) {
templateUrl: './perspectiveViewSlider.template.html', templateUrl: './perspectiveViewSlider.template.html',
styleUrls: ['./perspectiveViewSlider.style.css'], styleUrls: ['./perspectiveViewSlider.style.css'],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [
DestroyDirective,
]
}) })
export class PerspectiveViewSlider implements OnDestroy { export class PerspectiveViewSlider {
#destroy$ = inject(DestroyDirective).destroyed$
@ViewChild(ResizeObserverDirective) @ViewChild(ResizeObserverDirective)
resizeDirective: ResizeObserverDirective resizeDirective: ResizeObserverDirective
public minimapControl = new FormControl() public minimapControl = new FormControl<number>(0)
public recalcViewportSize$ = new Subject() public recalcViewportSize$ = new Subject()
private selectedTemplate$ = this.store$.pipe( private selectedTemplate$ = this.store$.pipe(
select(selectedTemplate), select(selectedTemplate),
distinctUntilChanged((o, n) => o?.id === n?.id), distinctUntilChanged((o, n) => o?.id === n?.id),
) )
private subscriptions: Subscription[] = []
private maximisedPanelIndex$ = combineLatest([ private maximisedPanelIndex$ = combineLatest([
this.store$.pipe( this.store$.pipe(
select(panelMode), select(panelMode),
...@@ -243,7 +247,7 @@ export class PerspectiveViewSlider implements OnDestroy { ...@@ -243,7 +247,7 @@ export class PerspectiveViewSlider implements OnDestroy {
public scrubberPosition$ = this.rangeControlMinMaxValue$.pipe( public scrubberPosition$ = this.rangeControlMinMaxValue$.pipe(
switchMap(minmaxval => concat( switchMap(minmaxval => concat(
of(null), of(null as number),
this.minimapControl.valueChanges, this.minimapControl.valueChanges,
).pipe( ).pipe(
map(newval => { map(newval => {
...@@ -329,41 +333,56 @@ export class PerspectiveViewSlider implements OnDestroy { ...@@ -329,41 +333,56 @@ export class PerspectiveViewSlider implements OnDestroy {
constructor( constructor(
private store$: Store, private store$: Store,
private sapi: SAPI,
@Inject(NEHUBA_INSTANCE_INJTKN) private nehubaViewer$: Observable<NehubaViewerUnit>, @Inject(NEHUBA_INSTANCE_INJTKN) private nehubaViewer$: Observable<NehubaViewerUnit>,
@Inject(CURRENT_TEMPLATE_DIM_INFO) private tmplInfo$: Observable<TemplateInfo>, @Inject(CURRENT_TEMPLATE_DIM_INFO) private tmplInfo$: Observable<TemplateInfo>,
) { ) {
this.subscriptions.push( combineLatest([
combineLatest([ this.nehubaViewer$,
this.nehubaViewer$, this.rangeControlSetting$,
this.rangeControlSetting$, ]).pipe(
]).pipe( switchMap(([ nehubaViewer, rangeCtrl ]) => this.minimapControl.valueChanges.pipe(
switchMap(([ nehubaViewer, rangeCtrl ]) => this.minimapControl.valueChanges.pipe( withLatestFrom(this.navPosition$.pipe(
withLatestFrom(this.navPosition$.pipe( map(value => value?.real)
map(value => value?.real) )),
)), map(([newValue, currentPosition]) => ({ nehubaViewer, rangeCtrl, newValue, currentPosition }))
map(([newValue, currentPosition]) => ({ nehubaViewer, rangeCtrl, newValue, currentPosition })) )),
)) takeUntil(this.#destroy$)
).subscribe(({ nehubaViewer, rangeCtrl, newValue, currentPosition }) => { ).subscribe(({ nehubaViewer, rangeCtrl, newValue, currentPosition }) => {
if (newValue === null) return if (newValue === null) return
const { anatomicalOrientation } = rangeCtrl const { anatomicalOrientation } = rangeCtrl
if (!anatomicalOrientation) return if (!anatomicalOrientation) return
const idx = anatOriToIdx[anatomicalOrientation] const idx = anatOriToIdx[anatomicalOrientation]
const newNavPosition = [...currentPosition] const newNavPosition = [...currentPosition]
newNavPosition[idx] = newValue newNavPosition[idx] = newValue
nehubaViewer.setNavigationState({ nehubaViewer.setNavigationState({
position: newNavPosition, position: newNavPosition,
positionReal: true positionReal: true
}) })
}), })
)
}
ngOnDestroy(): void { combineLatest([
this.subscriptions.forEach(s => s.unsubscribe()); this.sliceviewIsNormal$,
this.navPosition$,
this.maximisedPanelIndex$,
]).pipe(
filter(([ sliceViewIsNormal ]) => sliceViewIsNormal),
map(([ _, ...rest ]) => rest),
takeUntil(this.#destroy$)
).subscribe(([ navPos, maximisedIdx]) => {
const realPos = navPos?.real
if (!realPos) {
return
}
const pos = navPos.real[maximisedIdx === 0? 1 : maximisedIdx === 1? 0 : 2]
const diff = Math.abs(this.minimapControl.value - pos)
if (diff > 1e6) {
this.minimapControl.setValue(pos)
}
})
} }
resetSliceview() { resetSliceview() {
this.store$.dispatch( this.store$.dispatch(
atlasSelection.actions.navigateTo({ atlasSelection.actions.navigateTo({
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment