Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add viewer tab on settings #1148

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 98 additions & 2 deletions src/ui/config/configCmp/config.component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { Component, OnDestroy, OnInit } from '@angular/core'
import {Component, Inject, OnDestroy, OnInit, Optional} from '@angular/core'
import { select, Store } from '@ngrx/store';
import { combineLatest, Observable, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, startWith } from 'rxjs/operators';
import { SUPPORTED_PANEL_MODES } from 'src/services/state/ngViewerState.store';
import { ngViewerActionSetPanelOrder } from 'src/services/state/ngViewerState.store.helper';
import { VIEWER_CONFIG_ACTION_TYPES, StateInterface as ViewerConfiguration } from 'src/services/state/viewerConfig.store'
import { IavRootStoreInterface } from 'src/services/stateStore.service';
import { isIdentityQuat } from 'src/viewerModule/nehuba/util';
import {isIdentityQuat, NEHUBA_INSTANCE_INJTKN} from 'src/viewerModule/nehuba/util';
import {MatSlideToggleChange} from "@angular/material/slide-toggle";
import {MatSliderChange} from "@angular/material/slider";
import { PureContantService } from 'src/util';
import { ngViewerActionSwitchPanelMode } from 'src/services/state/ngViewerState/actions';
import { ngViewerSelectorPanelMode, ngViewerSelectorPanelOrder } from 'src/services/state/ngViewerState/selectors';
import { viewerStateSelectorNavigation } from 'src/services/state/viewerState/selectors';
import {VIEWER_INJECTION_TOKEN} from "src/ui/layerbrowser/layerDetail/layerDetail.component";
import {NehubaViewerUnit} from "src/viewerModule/nehuba";

const GPU_TOOLTIP = `Higher GPU usage can cause crashes on lower end machines`
const ANIMATION_TOOLTIP = `Animation can cause slowdowns in lower end machines`
const MOBILE_UI_TOOLTIP = `Mobile UI enables touch controls`
const AXIS_LINE_TOOLTIP = `Show axis lines on the slice views`
fsdavid marked this conversation as resolved.
Show resolved Hide resolved
const BACKGROUND_COLORING_TOOLTIP = `Show ble background coloring on the perspective view`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, blue, not ble.

Also, for constants like this, can we use constants.js and import here?

const SCALE_BAR = `Show scale bar`
const ROOT_TEXT_ORDER: [string, string, string, string] = ['Coronal', 'Sagittal', 'Axial', '3D']
const OBLIQUE_ROOT_TEXT_ORDER: [string, string, string, string] = ['Slice View 1', 'Slice View 2', 'Slice View 3', '3D']

Expand All @@ -33,6 +38,9 @@ export class ConfigComponent implements OnInit, OnDestroy {
public GPU_TOOLTIP = GPU_TOOLTIP
public ANIMATION_TOOLTIP = ANIMATION_TOOLTIP
public MOBILE_UI_TOOLTIP = MOBILE_UI_TOOLTIP
public AXIS_LINE_TOOLTIP = AXIS_LINE_TOOLTIP
public BACKGROUND_COLORING_TOOLTIP = BACKGROUND_COLORING_TOOLTIP
public SCALE_BAR = SCALE_BAR
public supportedPanelModes = SUPPORTED_PANEL_MODES

/**
Expand All @@ -55,11 +63,22 @@ export class ConfigComponent implements OnInit, OnDestroy {

private viewerObliqueRotated$: Observable<boolean>

private nehubaViewer: NehubaViewerUnit
private get viewer(){
return this.injectedViewer || (window as any).viewer
}

constructor(
private store: Store<IavRootStoreInterface>,
private pureConstantService: PureContantService,
@Optional() @Inject(VIEWER_INJECTION_TOKEN) private injectedViewer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no longer need for VIEWER_INJECTION_TOKEN

@Optional() @Inject(NEHUBA_INSTANCE_INJTKN) nehubaViewer$: Observable<NehubaViewerUnit>
) {

this.subscriptions.push(
nehubaViewer$.subscribe(viewer => this.nehubaViewer = viewer)
)

this.useMobileUI$ = this.pureConstantService.useTouchUI$

this.gpuLimit$ = this.store.pipe(
Expand Down Expand Up @@ -185,4 +204,81 @@ export class ConfigComponent implements OnInit, OnDestroy {
}

public stepSize: number = 10

public get axisLineVisible() {
const panel: any = Array.from(this.viewer.display.panels)[0]
return panel?.viewer?.showAxisLines?.value
}
Comment on lines +208 to +211
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an easier method

viewer.showAxisLines.value

and to set:

viewer.showAxisLines.restoreState(true || false)

What I am more concerned is this method called on every render cycle, which could make it a big liability.


public set axisLineVisible(value) {
const panel: any = Array.from(this.viewer.display.panels)[0]
if (panel && panel.viewer) {
panel.viewer.showAxisLines.value = value
}
}

public toggleAxisLines(value) {
this.axisLineVisible = value
}
Comment on lines +213 to +222
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.



public get showScaleBar() {
const panel: any = Array.from(this.viewer.display.panels).find((p: any) => p.viewer?.orthographicProjection)
return panel?.viewer?.showScaleBar?.value
}

public set showScaleBar(value) {
const panel: any = Array.from(this.viewer.display.panels).find((p: any) => p.viewer?.orthographicProjection)
if (panel && panel.viewer) {
panel.viewer.showScaleBar.value = value
}
}

public toggleScaleBar(value) {
this.showScaleBar = value
}
Comment on lines +225 to +239
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above with viewer.showScaleBar



public get sliceBackgroundRgb() {
const color = this.sliceBackground
return '#' + [color[0], color[1], color[2]].map(x => x.toString(16).length === 1 ? '0' + x.toString(16) : x.toString(16))
.join('')
}

public get sliceBackground() {
const panel: any = Array.from(this.viewer.display.panels).find((p: any) => p.viewer?.orthographicProjection)
return panel?.config?.layout.useNehubaPerspective.drawSubstrates.color
}
Comment on lines +248 to +251
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an easier way to get nehuba config

(window as any).nehubaViewer.config

That being said, we should probably do what we did with nehubaViewer, and inject it as an observable.

e.g. something like

@Optional() @Inject(NEHUBA_INSTANCE_INJTKN) nehubaViewer$:


public set sliceBackground(value) {
const panel: any = Array.from(this.viewer.display.panels).find((p: any) => p.viewer?.orthographicProjection)
if (panel && panel.config) {
panel.config.layout.useNehubaPerspective.drawSubstrates.color = value
}
this.nehubaViewer.redraw()
}

public setSliceBackground(value) {
this.sliceBackground = [...this.hexToRgb(value), 0.2]
}

public get showBackground() {
return this.sliceBackground[3] > 0
}

public set showBackground(value) {
const panel: any = Array.from(this.viewer.display.panels).find((p: any) => p.viewer?.orthographicProjection)
if (panel && panel.config) {
panel.config.layout.useNehubaPerspective.drawSubstrates.color[3] = value ? 0.2 : 0
}
this.nehubaViewer.redraw()
}
Comment on lines +269 to +275
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we set the drawSubstrates to falsy, and then call redraw, it would also work (probably more performant)


public toggleShowBackground(value) {
this.showBackground = value
}

public hexToRgb = hex => hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(m, r, g, b) => '#' + r + r + g + g + b + b)
.substring(1).match(/.{2}/g).map(x => parseInt(x, 16))
Comment on lines +281 to +282
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use SO answer (at least directly). It's CC-SA license, and not compatible with our code.

There is a hextorgb code in repository (it's in worker, so unfortunately you can't import it, but you can copy paste it)


}
43 changes: 43 additions & 0 deletions src/ui/config/configCmp/config.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,49 @@
</div>
</mat-tab>

<!-- viewer -->
<mat-tab label="Viewer">
<div class="m-4">

<!-- Show axis lines -->
<div class="d-flex mb-2 align-items-center">
<mat-slide-toggle
[checked]="axisLineVisible"
(change)="toggleAxisLines($event.checked)">
Axis lines
</mat-slide-toggle>
<small iav-stop="click mousedown mouseup" [matTooltip]="AXIS_LINE_TOOLTIP" class="ml-2 fas fa-question"></small>
</div>

<!-- Scale bar -->
<div class="d-flex mb-2 align-items-center">
<mat-slide-toggle
[checked]="showScaleBar"
(change)="toggleScaleBar($event.checked)">
Scale bar
</mat-slide-toggle>
<small iav-stop="click mousedown mouseup" [matTooltip]="BACKGROUND_COLORING_TOOLTIP" class="ml-2 fas fa-question"></small>
</div>

<!-- Background colouring -->
<div class="d-flex mb-2 align-items-center">
<mat-slide-toggle
[checked]="showBackground"
(change)="toggleShowBackground($event.checked)">
Background colouring
</mat-slide-toggle>
<small iav-stop="click mousedown mouseup" [matTooltip]="BACKGROUND_COLORING_TOOLTIP" class="ml-2 fas fa-question"></small>
<div *ngIf="showBackground" class="ml-3">
<input type="color" id="backgroundColorPicker" name="backgroundColorPicker"
(change)="setSliceBackground(backgroundColorPicker.value)"
#backgroundColorPicker
[value]="sliceBackgroundRgb">
</div>
</div>

</div>
</mat-tab>

<!-- plugin csp -->
<mat-tab label="Plugin Permission">
<plugin-csp-controller></plugin-csp-controller>
Expand Down