diff --git a/src/features/feature-view/feature-view.component.html b/src/features/feature-view/feature-view.component.html index 1c31b1e9cb8dad38f19f8471bbb1056451f20f34..41a18ab45fb8ec4dea3855ffdff863b80feafe36 100644 --- a/src/features/feature-view/feature-view.component.html +++ b/src/features/feature-view/feature-view.component.html @@ -83,7 +83,7 @@ </mat-tab> <mat-tab *ngIf="busy$ | async"> - <ng-template matTabLabel=""> + <ng-template matTabLabel> <spinner-cmp></spinner-cmp> </ng-template> </mat-tab> diff --git a/src/util/colorMaps.ts b/src/util/colorMaps.ts index ad3ab450b293f301dc90182328e1bd2b06002a7a..e62b785434757f3e36bf1c28cc92e401fa9b2a50 100644 --- a/src/util/colorMaps.ts +++ b/src/util/colorMaps.ts @@ -18,6 +18,8 @@ export enum EnumColorMapName{ INFERNO='inferno', GREYSCALE='greyscale', + + RGB="rgb (3 channel)" } interface IColorMap{ @@ -41,6 +43,7 @@ interface IColorMap{ * vec3 rgb; */ main: string + override?: () => string } export const mapKeyColorMap = new Map<EnumColorMapName, IColorMap>([ @@ -200,5 +203,27 @@ export const mapKeyColorMap = new Map<EnumColorMapName, IColorMap>([ header: COLORMAP_IS_GREYSCALE, premain: '', main: 'rgb=vec3(x, x, x);' + } ], + + + [ EnumColorMapName.RGB, { + header: '', + main: '', + premain: '', + override() { + const removeBg = false + const lowThreshold = 0 + const highThreshold = 1 + const contrast = 0 + const brightness = 0 + + const _lowThreshold = lowThreshold + 1e-10 + const getChan = (variable: string, idx: number) => `float ${variable} = ( toNormalized(getDataValue( ${idx} )) - ${_lowThreshold.toFixed(10)} ) / ( ${ highThreshold - _lowThreshold } ) ${ brightness > 0 ? '+' : '-' } ${Math.abs(brightness).toFixed(10)};` + return `void main() { ${getChan('r', 0)} ${getChan('g', 1)} ${getChan('b', 2)} +${ removeBg ? 'if (r < 0.01 && g < 0.01 && b < 0.01 ) { emitTransparent(); } else {' : '' } +emitRGB(vec3(r, g, b) * exp(${contrast.toFixed(10)})); +${ removeBg ? '}' : '' } +}` + } } ] ]) diff --git a/src/util/constants.ts b/src/util/constants.ts index 763bc0695829eec89caa1c15c41d86be61d720ad..da2e383309c9b2493780cb429a65b669ccb65941 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -8,8 +8,6 @@ export const LOCAL_STORAGE_CONST = { AGREE_COOKIE: 'fzj.xg.iv.AGREE_COOKIE', AGREE_KG_TOS: 'fzj.xg.iv.AGREE_KG_TOS', QUICK_TOUR_VIEWED: 'fzj.dg.iv.QUICK_TOUR_VIEWED', - - FAV_DATASET: 'fzj.xg.iv.FAV_DATASET_V2', } export const COOKIE_VERSION = '0.3.0' @@ -84,10 +82,14 @@ export const getShader = ({ contrast = 0, removeBg = false } = {}): string => { - const { header, main, premain } = mapKeyColorMap.get(colormap) || (() => { + const { header, main, premain, override } = mapKeyColorMap.get(colormap) || (() => { return mapKeyColorMap.get(EnumColorMapName.GREYSCALE) })() + if (override) { + return override() + } + // so that if lowthreshold is defined to be 0, at least some background removal will be done const _lowThreshold = lowThreshold + 1e-10 return `${header} diff --git a/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts b/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts index a37e9608e7b8b96c48673a3d3043ecfb99688997..5947f3b6c1bf8f9377502d47c76dbd6dfcaead4f 100644 --- a/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts +++ b/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts @@ -2,10 +2,10 @@ import { Injectable } from "@angular/core"; import { createEffect } from "@ngrx/effects"; import { select, Store } from "@ngrx/store"; import { forkJoin, from, of } from "rxjs"; -import { switchMap, withLatestFrom, filter, catchError, map, debounceTime, shareReplay, distinctUntilChanged, startWith, pairwise, tap } from "rxjs/operators"; -import { Feature, NgLayerSpec, NgPrecompMeshSpec, NgSegLayerSpec, SxplrAtlas, SxplrParcellation, SxplrTemplate, VoiFeature } from "src/atlasComponents/sapi/sxplrTypes"; +import { switchMap, withLatestFrom, catchError, map, debounceTime, shareReplay, distinctUntilChanged, tap } from "rxjs/operators"; +import { NgLayerSpec, NgPrecompMeshSpec, NgSegLayerSpec, SxplrAtlas, SxplrParcellation, SxplrTemplate, VoiFeature } from "src/atlasComponents/sapi/sxplrTypes"; import { SAPI } from "src/atlasComponents/sapi" -import { atlasAppearance, atlasSelection, userInteraction } from "src/state"; +import { atlasAppearance, atlasSelection } from "src/state"; import { arrayEqual } from "src/util/array"; import { EnumColorMapName } from "src/util/colorMaps"; import { getShader } from "src/util/constants"; @@ -88,43 +88,6 @@ export class LayerCtrlEffects { }) )) - onShownFeature = createEffect(() => this.store.pipe( - select(userInteraction.selectors.selectedFeature), - startWith(null as Feature), - pairwise(), - map(([ prev, curr ]) => { - const removeLayers: atlasAppearance.const.NgLayerCustomLayer[] = [] - const addLayers: atlasAppearance.const.NgLayerCustomLayer[] = [] - - /** - * TODO: use proper guard functions - */ - if (!!prev?.['bbox']) { - const prevVoi = prev as VoiFeature - prevVoi.bbox - removeLayers.push( - ...LayerCtrlEffects.TransformVolumeModel(prevVoi.ngVolume) - ) - } - if (!!curr?.['bbox']) { - const currVoi = curr as VoiFeature - addLayers.push( - ...LayerCtrlEffects.TransformVolumeModel(currVoi.ngVolume) - ) - } - return { removeLayers, addLayers } - }), - filter(({ removeLayers, addLayers }) => removeLayers.length !== 0 || addLayers.length !== 0), - switchMap(({ removeLayers, addLayers }) => of(...[ - ...removeLayers.map( - l => atlasAppearance.actions.removeCustomLayer({ id: l.id }) - ), - ...addLayers.map( - l => atlasAppearance.actions.addCustomLayer({ customLayer: l }) - ) - ])) - )) - onATPClearBaseLayers = createEffect(() => this.#onATP$.pipe( withLatestFrom( this.store.pipe( diff --git a/src/viewerModule/nehuba/ngLayerCtlModule/ngLayerCtl/ngLayerCtrl.component.ts b/src/viewerModule/nehuba/ngLayerCtlModule/ngLayerCtl/ngLayerCtrl.component.ts index 396c86af6fcf966ba2e97c35608a35b517b779d4..71d2acd47818b95728595616c3a0d53c9efddf6f 100644 --- a/src/viewerModule/nehuba/ngLayerCtlModule/ngLayerCtl/ngLayerCtrl.component.ts +++ b/src/viewerModule/nehuba/ngLayerCtlModule/ngLayerCtl/ngLayerCtrl.component.ts @@ -6,6 +6,8 @@ import { Observable } from "rxjs"; import { atlasAppearance, atlasSelection } from "src/state"; import { NehubaViewerUnit, NEHUBA_INSTANCE_INJTKN } from "src/viewerModule/nehuba"; import { getExportNehuba } from "src/util/fn"; +import { getShader } from "src/util/constants"; +import { EnumColorMapName } from "src/util/colorMaps"; type Vec4 = [number, number, number, number] type Mat4 = [Vec4, Vec4, Vec4, Vec4] @@ -102,14 +104,25 @@ export class NgLayerCtrlCmp implements OnChanges, OnDestroy{ } } - ngOnChanges(): void { + async ngOnChanges() { if (this.name && this.source) { const { name } = this if (this.removeLayer) { this.removeLayer() this.removeLayer = null } - console.log('foo', this.source) + try { + const resp = await fetch(`${this.source}/meta.json`) + const metaJson = await resp.json() + const is3D = metaJson?.data?.type === "image/3d" + if (is3D) { + this.shader = getShader({ + colormap: EnumColorMapName.RGB + }) + } + // eslint-disable-next-line no-empty + } catch (e) {} + this.store.dispatch( atlasAppearance.actions.addCustomLayer({ customLayer: {