Skip to content

Commit

Permalink
reset tag tool text input after a new tool is added
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Sep 4, 2024
1 parent 1cfa33f commit f0c8801
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/layer/annotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ class TagsTab extends Tab {
if (inputElement.validity.valid && !tags.value.includes(value)) {
tags.value.push(value);
tags.changed.dispatch();
inputElement.value = "";
}
},
});
Expand Down
20 changes: 19 additions & 1 deletion src/layer/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ import {
makeCachedDerivedWatchableValue,
makeCachedLazyDerivedWatchableValue,
registerNested,
TrackableValue,
WatchableValue,
} from "#src/trackable_value.js";
import { UserLayerWithAnnotationsMixin } from "#src/ui/annotations.js";
import { setClipboard } from "#src/util/clipboard.js";
import type { Borrowed } from "#src/util/disposable.js";
import { makeValueOrError } from "#src/util/error.js";
import { verifyOptionalObjectProperty } from "#src/util/json.js";
import { verifyInt, verifyOptionalObjectProperty } from "#src/util/json.js";
import {
trackableShaderModeValue,
VolumeRenderingModes,
Expand Down Expand Up @@ -111,6 +112,7 @@ const CHANNEL_DIMENSIONS_JSON_KEY = "channelDimensions";
const VOLUME_RENDERING_JSON_KEY = "volumeRendering";
const VOLUME_RENDERING_GAIN_JSON_KEY = "volumeRenderingGain";
const VOLUME_RENDERING_DEPTH_SAMPLES_JSON_KEY = "volumeRenderingDepthSamples";
const RESOLUTION_LIMIT_JSON_KEY = "resolutionLimit";

export interface ImageLayerSelectionState extends UserLayerSelectionState {
value: any;
Expand All @@ -123,6 +125,7 @@ const [
] = getVolumeRenderingDepthSamplesBoundsLogScale();
export class ImageUserLayer extends Base {
opacity = trackableAlphaValue(0.5);
resolutionLimit = new TrackableValue<number>(100, verifyInt);
blendMode = trackableBlendModeValue();
fragmentMain = getTrackableFragmentMain();
shaderError = makeWatchableShaderError();
Expand Down Expand Up @@ -204,6 +207,7 @@ export class ImageUserLayer extends Base {
isLocalDimension;
this.blendMode.changed.add(this.specificationChanged.dispatch);
this.opacity.changed.add(this.specificationChanged.dispatch);
this.resolutionLimit.changed.add(this.specificationChanged.dispatch);
this.volumeRenderingGain.changed.add(this.specificationChanged.dispatch);
this.fragmentMain.changed.add(this.specificationChanged.dispatch);
this.shaderControlState.changed.add(this.specificationChanged.dispatch);
Expand Down Expand Up @@ -251,6 +255,7 @@ export class ImageUserLayer extends Base {
this.channelCoordinateSpace,
),
renderScaleTarget: this.sliceViewRenderScaleTarget,
resolutionLimit: this.resolutionLimit,
renderScaleHistogram: this.sliceViewRenderScaleHistogram,
localPosition: this.localPosition,
channelCoordinateSpace: this.channelCoordinateSpace,
Expand All @@ -266,6 +271,7 @@ export class ImageUserLayer extends Base {
this.channelCoordinateSpace,
),
depthSamplesTarget: this.volumeRenderingDepthSamplesTarget,
resolutionLimit: this.resolutionLimit,
chunkResolutionHistogram:
this.volumeRenderingChunkResolutionHistogram,
localPosition: this.localPosition,
Expand Down Expand Up @@ -293,6 +299,7 @@ export class ImageUserLayer extends Base {
restoreState(specification: any) {
super.restoreState(specification);
this.opacity.restoreState(specification[OPACITY_JSON_KEY]);
this.resolutionLimit.restoreState(specification[RESOLUTION_LIMIT_JSON_KEY]);
verifyOptionalObjectProperty(specification, BLEND_JSON_KEY, (blendValue) =>
this.blendMode.restoreState(blendValue),
);
Expand Down Expand Up @@ -337,6 +344,7 @@ export class ImageUserLayer extends Base {
toJSON() {
const x = super.toJSON();
x[OPACITY_JSON_KEY] = this.opacity.toJSON();
x[RESOLUTION_LIMIT_JSON_KEY] = this.resolutionLimit.toJSON();
x[BLEND_JSON_KEY] = this.blendMode.toJSON();
x[SHADER_JSON_KEY] = this.fragmentMain.toJSON();
x[SHADER_CONTROLS_JSON_KEY] = this.shaderControlState.toJSON();
Expand Down Expand Up @@ -468,6 +476,16 @@ const LAYER_CONTROLS: LayerControlDefinition<ImageUserLayer>[] = [
target: layer.sliceViewRenderScaleTarget,
})),
},
{
label: "Only load first (n) resolutions",
toolJson: RESOLUTION_LIMIT_JSON_KEY,
...rangeLayerControl((layer) => {
return {
value: layer.resolutionLimit,
options: { min: 0, max: 10, step: 1 },
};
}),
},
{
label: "Blending (slice)",
toolJson: BLEND_JSON_KEY,
Expand Down
10 changes: 10 additions & 0 deletions src/sliceview/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class SliceViewBackend extends SliceViewIntermediateBase {
};

updateVisibleChunks() {
console.log("updateVisibleChunks!");
const projectionParameters = this.projectionParameters.value;
const chunkManager = this.chunkManager;
const visibility = this.visibility.value;
Expand Down Expand Up @@ -158,6 +159,13 @@ export class SliceViewBackend extends SliceViewIntermediateBase {
i < numVisibleSources;
++i
) {
console.log("RL", (layer as any).resolutionLimit.value);
if ((layer as any).resolutionLimit) {
if (i > (layer as any).resolutionLimit.value) {
console.log("SKIP!");
continue;
}
}
const tsource = visibleSources[i];
const prefetchOffsets = chunkManager.queueManager.enablePrefetch.value
? getPrefetchChunkOffsets(this.velocityEstimator, tsource)
Expand Down Expand Up @@ -414,6 +422,7 @@ export class SliceViewRenderLayerBackend
{
rpcId: number;
renderScaleTarget: SharedWatchableValue<number>;
resolutionLimit: SharedWatchableValue<number>;
localPosition: WatchableValueInterface<Float32Array>;

numVisibleChunksNeeded: number;
Expand All @@ -425,6 +434,7 @@ export class SliceViewRenderLayerBackend
constructor(rpc: RPC, options: any) {
super(rpc, options);
this.renderScaleTarget = rpc.get(options.renderScaleTarget);
this.resolutionLimit = rpc.get(options.resolutionLimit);
this.localPosition = rpc.get(options.localPosition);
this.numVisibleChunksNeeded = 0;
this.numVisibleChunksAvailable = 0;
Expand Down
14 changes: 13 additions & 1 deletion src/sliceview/renderlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ import type {
} from "#src/sliceview/frontend.js";
import type { SliceViewPanel } from "#src/sliceview/panel.js";
import type { WatchableValueInterface } from "#src/trackable_value.js";
import { constantWatchableValue } from "#src/trackable_value.js";
import {
constantWatchableValue,
TrackableValue,
} from "#src/trackable_value.js";
import type { Borrowed } from "#src/util/disposable.js";
import { verifyInt } from "#src/util/json.js";
import { HistogramSpecifications } from "#src/webgl/empirical_cdf.js";
import type { ShaderModule } from "#src/webgl/shader.js";
import type { RpcId, SharedObject } from "#src/worker_rpc.js";
Expand All @@ -61,6 +65,7 @@ export interface SliceViewRenderLayerOptions {
*/
transform: WatchableValueInterface<RenderLayerTransformOrError>;
renderScaleTarget?: WatchableValueInterface<number>;
resolutionLimit?: WatchableValueInterface<number>;
renderScaleHistogram?: RenderScaleHistogram;

/**
Expand Down Expand Up @@ -96,6 +101,7 @@ export abstract class SliceViewRenderLayer<
transform: WatchableValueInterface<RenderLayerTransformOrError>;

renderScaleTarget: WatchableValueInterface<number>;
resolutionLimit: WatchableValueInterface<number>;
renderScaleHistogram?: RenderScaleHistogram;

// This is only used by `ImageRenderLayer` currently, but is defined here because
Expand Down Expand Up @@ -183,6 +189,9 @@ export abstract class SliceViewRenderLayer<

const { renderScaleTarget = trackableRenderScaleTarget(1) } = options;
this.renderScaleTarget = renderScaleTarget;
const { resolutionLimit = new TrackableValue<number>(1, verifyInt) } =
options;
this.resolutionLimit = resolutionLimit;
this.renderScaleHistogram = options.renderScaleHistogram;
this.transform = options.transform;
this.localPosition = options.localPosition;
Expand Down Expand Up @@ -217,6 +226,9 @@ export abstract class SliceViewRenderLayer<
renderScaleTarget: this.registerDisposer(
SharedWatchableValue.makeFromExisting(rpc, this.renderScaleTarget),
).rpcId,
resolutionLimit: this.registerDisposer(
SharedWatchableValue.makeFromExisting(rpc, this.resolutionLimit),
).rpcId,
...this.rpcTransfer,
});
this.rpcId = sharedObject.rpcId;
Expand Down
9 changes: 9 additions & 0 deletions src/volume_rendering/volume_render_layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ interface VolumeRenderingAttachmentState {

export interface VolumeRenderingRenderLayerOptions {
gain: WatchableValueInterface<number>;
resolutionLimit: WatchableValueInterface<number>;
multiscaleSource: MultiscaleVolumeChunkSource;
transform: WatchableValueInterface<RenderLayerTransformOrError>;
shaderError: WatchableShaderError;
Expand Down Expand Up @@ -217,6 +218,7 @@ export class VolumeRenderingRenderLayer extends PerspectiveViewRenderLayer {
localPosition: WatchableValueInterface<Float32Array>;
shaderControlState: ShaderControlState;
depthSamplesTarget: WatchableValueInterface<number>;
resolutionLimit: WatchableValueInterface<number>;
chunkResolutionHistogram: RenderScaleHistogram;
mode: TrackableVolumeRenderingModeValue;
backend: ChunkRenderLayerFrontend;
Expand Down Expand Up @@ -263,6 +265,7 @@ export class VolumeRenderingRenderLayer extends PerspectiveViewRenderLayer {
this.shaderControlState = options.shaderControlState;
this.localPosition = options.localPosition;
this.depthSamplesTarget = options.depthSamplesTarget;
this.resolutionLimit = options.resolutionLimit || 999999;
this.chunkResolutionHistogram = options.chunkResolutionHistogram;
this.mode = options.mode;
this.modeOverride = trackableShaderModeValue();
Expand Down Expand Up @@ -652,6 +655,9 @@ outputValue = vec4(1.0, 1.0, 1.0, 1.0);
this.registerDisposer(
this.depthSamplesTarget.changed.add(this.redrawNeeded.dispatch),
);
this.registerDisposer(
this.resolutionLimit.changed.add(this.redrawNeeded.dispatch),
);
this.registerDisposer(this.gain.changed.add(this.redrawNeeded.dispatch));
this.registerDisposer(
this.shaderControlState.changed.add(this.redrawNeeded.dispatch),
Expand Down Expand Up @@ -682,6 +688,9 @@ outputValue = vec4(1.0, 1.0, 1.0, 1.0);
renderScaleTarget: this.registerDisposer(
SharedWatchableValue.makeFromExisting(rpc, this.depthSamplesTarget),
).rpcId,
resolutionLimit: this.registerDisposer(
SharedWatchableValue.makeFromExisting(rpc, this.resolutionLimit),
).rpcId,
});
this.backend = sharedObject;
}
Expand Down

0 comments on commit f0c8801

Please sign in to comment.