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 @@
- quick search now show branches in addition to leaves
- added context in region hierarchy view
- added coordinate entry dialog
- switching templates will now fallback to use the newest parcellation in the same series
## Bugfix
......
......@@ -220,9 +220,45 @@ export class Effect {
const foundAtlas = atlas && result.atlases.find(a => a.id === atlas.id)
const foundParc = parcellation && result.parcellations.find(a => a.id === parcellation.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.parcellations = foundParc && [foundParc] || result.parcellations
result.parcellations = foundParc && [foundParc] || prevNextParcs[0] && [prevNextParcs[0]] || result.parcellations
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 { select, Store } from "@ngrx/store";
import { combineLatest, concat, NEVER, Observable, of, Subject, Subscription } from "rxjs";
import { switchMap, distinctUntilChanged, map, debounceTime, shareReplay, take, withLatestFrom, filter } from "rxjs/operators";
import { SAPI } from "src/atlasComponents/sapi";
import { combineLatest, concat, NEVER, Observable, of, Subject } from "rxjs";
import { switchMap, distinctUntilChanged, map, debounceTime, shareReplay, take, withLatestFrom, filter, takeUntil } from "rxjs/operators";
import { SxplrTemplate } from "src/atlasComponents/sapi/sxplrTypes"
import { selectedTemplate } from "src/state/atlasSelection/selectors";
import { panelMode, panelOrder } from "src/state/userInterface/selectors";
......@@ -15,6 +14,7 @@ import { EnumClassicalView } from "src/atlasComponents/constants"
import { atlasSelection } from "src/state";
import { floatEquality } from "common/util"
import { CURRENT_TEMPLATE_DIM_INFO, TemplateInfo } from "../../layerCtrl.service/layerCtrl.util";
import { DestroyDirective } from "src/util/directives/destroy.directive";
const MAX_DIM = 200
......@@ -43,21 +43,25 @@ function getDim(triplet: number[], view: EnumClassicalView) {
templateUrl: './perspectiveViewSlider.template.html',
styleUrls: ['./perspectiveViewSlider.style.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [
DestroyDirective,
]
})
export class PerspectiveViewSlider implements OnDestroy {
export class PerspectiveViewSlider {
#destroy$ = inject(DestroyDirective).destroyed$
@ViewChild(ResizeObserverDirective)
resizeDirective: ResizeObserverDirective
public minimapControl = new FormControl()
public minimapControl = new FormControl<number>(0)
public recalcViewportSize$ = new Subject()
private selectedTemplate$ = this.store$.pipe(
select(selectedTemplate),
distinctUntilChanged((o, n) => o?.id === n?.id),
)
private subscriptions: Subscription[] = []
private maximisedPanelIndex$ = combineLatest([
this.store$.pipe(
select(panelMode),
......@@ -243,7 +247,7 @@ export class PerspectiveViewSlider implements OnDestroy {
public scrubberPosition$ = this.rangeControlMinMaxValue$.pipe(
switchMap(minmaxval => concat(
of(null),
of(null as number),
this.minimapControl.valueChanges,
).pipe(
map(newval => {
......@@ -329,41 +333,56 @@ export class PerspectiveViewSlider implements OnDestroy {
constructor(
private store$: Store,
private sapi: SAPI,
@Inject(NEHUBA_INSTANCE_INJTKN) private nehubaViewer$: Observable<NehubaViewerUnit>,
@Inject(CURRENT_TEMPLATE_DIM_INFO) private tmplInfo$: Observable<TemplateInfo>,
) {
this.subscriptions.push(
combineLatest([
this.nehubaViewer$,
this.rangeControlSetting$,
]).pipe(
switchMap(([ nehubaViewer, rangeCtrl ]) => this.minimapControl.valueChanges.pipe(
withLatestFrom(this.navPosition$.pipe(
map(value => value?.real)
)),
map(([newValue, currentPosition]) => ({ nehubaViewer, rangeCtrl, newValue, currentPosition }))
))
).subscribe(({ nehubaViewer, rangeCtrl, newValue, currentPosition }) => {
if (newValue === null) return
const { anatomicalOrientation } = rangeCtrl
if (!anatomicalOrientation) return
const idx = anatOriToIdx[anatomicalOrientation]
const newNavPosition = [...currentPosition]
newNavPosition[idx] = newValue
nehubaViewer.setNavigationState({
position: newNavPosition,
positionReal: true
})
}),
)
}
combineLatest([
this.nehubaViewer$,
this.rangeControlSetting$,
]).pipe(
switchMap(([ nehubaViewer, rangeCtrl ]) => this.minimapControl.valueChanges.pipe(
withLatestFrom(this.navPosition$.pipe(
map(value => value?.real)
)),
map(([newValue, currentPosition]) => ({ nehubaViewer, rangeCtrl, newValue, currentPosition }))
)),
takeUntil(this.#destroy$)
).subscribe(({ nehubaViewer, rangeCtrl, newValue, currentPosition }) => {
if (newValue === null) return
const { anatomicalOrientation } = rangeCtrl
if (!anatomicalOrientation) return
const idx = anatOriToIdx[anatomicalOrientation]
const newNavPosition = [...currentPosition]
newNavPosition[idx] = newValue
nehubaViewer.setNavigationState({
position: newNavPosition,
positionReal: true
})
})
ngOnDestroy(): void {
this.subscriptions.forEach(s => s.unsubscribe());
combineLatest([
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() {
this.store$.dispatch(
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