Skip to content

Commit

Permalink
feat(viewportStatus): Have renderedState to store the status of wheth…
Browse files Browse the repository at this point in the history
…er an image has been rendered yet (#694)

* Initial commit of storing the rendered state

* Add a rendered state to the viewport to record the status of the
rendering

* PR requested changes
  • Loading branch information
wayfarer3130 committed Jul 18, 2023
1 parent 611a684 commit eeef233
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 2 deletions.
27 changes: 26 additions & 1 deletion common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ declare namespace Enums {
GeometryType,
ContourType,
VOILUTFunctionType,
DynamicOperatorType
DynamicOperatorType,
ViewportStatus
}
}
export { Enums }
Expand Down Expand Up @@ -1374,6 +1375,7 @@ type ImageRenderedEventDetail = {
viewportId: string;
renderingEngineId: string;
suppressEvents?: boolean;
viewportStatus: ViewportStatus;
};

// @public (undocumented)
Expand Down Expand Up @@ -1713,6 +1715,8 @@ interface IViewport {
// (undocumented)
setPan(pan: Point2, storeAsInitialCamera?: boolean): any;
// (undocumented)
setRendered(): void;
// (undocumented)
setZoom(zoom: number, storeAsInitialCamera?: boolean): any;
// (undocumented)
sHeight: number;
Expand All @@ -1729,6 +1733,8 @@ interface IViewport {
// (undocumented)
updateRenderingPipeline: () => void;
// (undocumented)
viewportStatus: ViewportStatus;
// (undocumented)
worldToCanvas: (worldPos: Point3) => Point2;
}

Expand Down Expand Up @@ -2210,6 +2216,7 @@ export class StackViewport extends Viewport implements IStackViewport {
element: HTMLDivElement;
viewportId: string;
renderingEngineId: string;
viewportStatus: ViewportStatus;
};
// (undocumented)
getActor: (actorUID: string) => ActorEntry;
Expand Down Expand Up @@ -2601,6 +2608,8 @@ export class Viewport implements IViewport {
// (undocumented)
setPan(pan: Point2, storeAsInitialCamera?: boolean): void;
// (undocumented)
setRendered(): void;
// (undocumented)
setZoom(value: number, storeAsInitialCamera?: boolean): void;
// (undocumented)
sHeight: number;
Expand All @@ -2625,6 +2634,8 @@ export class Viewport implements IViewport {
// (undocumented)
static get useCustomRenderingPipeline(): boolean;
// (undocumented)
viewportStatus: ViewportStatus;
// (undocumented)
worldToCanvas: (worldPos: Point3) => Point2;
}

Expand Down Expand Up @@ -2668,6 +2679,20 @@ type ViewportProperties = {
invert?: boolean;
};

// @public (undocumented)
enum ViewportStatus {
// (undocumented)
LOADING = "loading",
// (undocumented)
NO_DATA = "noData",
// (undocumented)
PRE_RENDER = "preRender",
// (undocumented)
RENDERED = "rendered",
// (undocumented)
RESIZE = "resize"
}

// @public (undocumented)
enum ViewportType {
// (undocumented)
Expand Down
12 changes: 12 additions & 0 deletions common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ type ImageRenderedEventDetail = {
viewportId: string;
renderingEngineId: string;
suppressEvents?: boolean;
viewportStatus: ViewportStatus;
};

// @public (undocumented)
Expand Down Expand Up @@ -1177,6 +1178,7 @@ interface IViewport {
);
setOptions(options: ViewportInputOptions, immediate: boolean): void;
setPan(pan: Point2, storeAsInitialCamera?: boolean);
setRendered(): void;
setZoom(zoom: number, storeAsInitialCamera?: boolean);
sHeight: number;
suppressEvents: boolean;
Expand All @@ -1186,6 +1188,7 @@ interface IViewport {
type: ViewportType;
// (undocumented)
updateRenderingPipeline: () => void;
viewportStatus: ViewportStatus;
worldToCanvas: (worldPos: Point3) => Point2;
}

Expand Down Expand Up @@ -1569,6 +1572,15 @@ type ViewportProperties = {
invert?: boolean;
};

// @public (undocumented)
enum ViewportStatus {
LOADING = 'loading',
NO_DATA = 'noData',
PRE_RENDER = 'preRender',
RENDERED = 'rendered',
RESIZE = 'resize',
}

// @public
enum ViewportType {
ORTHOGRAPHIC = 'orthographic',
Expand Down
3 changes: 3 additions & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,7 @@ type ImageRenderedEventDetail = {
viewportId: string;
renderingEngineId: string;
suppressEvents?: boolean;
viewportStatus: ViewportStatus;
};

// @public (undocumented)
Expand Down Expand Up @@ -3038,6 +3039,7 @@ interface IViewport {
);
setOptions(options: ViewportInputOptions, immediate: boolean): void;
setPan(pan: Point2, storeAsInitialCamera?: boolean);
setRendered(): void;
setZoom(zoom: number, storeAsInitialCamera?: boolean);
sHeight: number;
suppressEvents: boolean;
Expand All @@ -3047,6 +3049,7 @@ interface IViewport {
type: ViewportType;
// (undocumented)
updateRenderingPipeline: () => void;
viewportStatus: ViewportStatus;
worldToCanvas: (worldPos: Point3) => Point2;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/RenderingEngine/BaseVolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BlendModes,
Events,
OrientationAxis,
ViewportStatus,
VOILUTFunctionType,
} from '../enums';
import ViewportType from '../enums/ViewportType';
Expand Down Expand Up @@ -591,6 +592,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
}

this._setVolumeActors(volumeActors);
this.viewportStatus = ViewportStatus.PRE_RENDER;

triggerEvent(this.element, Events.VOLUME_VIEWPORT_NEW_VOLUME, {
viewportId: this.id,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/RenderingEngine/RenderingEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
InternalViewportInput,
NormalizedViewportInput,
} from '../types/IViewport';
import { OrientationAxis } from '../enums';
import { OrientationAxis, ViewportStatus } from '../enums';
import VolumeViewport3D from './VolumeViewport3D';

type ViewportDisplayCoords = {
Expand Down Expand Up @@ -1107,6 +1107,7 @@ class RenderingEngine implements IRenderingEngine {
const eventDetail =
this.renderViewportUsingCustomOrVtkPipeline(viewport);
eventDetailArray.push(eventDetail);
viewport.setRendered();

// This viewport has been rendered, we can remove it from the set
this._needsRender.delete(viewport.id);
Expand Down Expand Up @@ -1251,6 +1252,7 @@ class RenderingEngine implements IRenderingEngine {
suppressEvents,
viewportId,
renderingEngineId,
viewportStatus: viewport.viewportStatus,
};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
ImagePixelModule,
ImagePlaneModule,
} from '../types';
import ViewportStatus from '../enums/ViewportStatus';

const EPSILON = 1; // Slice Thickness

Expand Down Expand Up @@ -696,6 +697,9 @@ class StackViewport extends Viewport implements IStackViewport {
}: StackViewportProperties = {},
suppressEvents = false
): void {
this.viewportStatus = this.csImage
? ViewportStatus.PRE_RENDER
: ViewportStatus.LOADING;
// if voi is not applied for the first time, run the setVOI function
// which will apply the default voi based on the range
if (typeof voiRange !== 'undefined') {
Expand Down Expand Up @@ -753,6 +757,7 @@ class StackViewport extends Viewport implements IStackViewport {
public resetProperties(): void {
this.cpuRenderingInvalidated = true;
this.voiUpdatedWithSetProperties = false;
this.viewportStatus = ViewportStatus.PRE_RENDER;

this.fillWithBackgroundColor();

Expand Down Expand Up @@ -1494,6 +1499,7 @@ class StackViewport extends Viewport implements IStackViewport {
this.voiRange = null;
this.interpolationType = InterpolationType.LINEAR;
this.invert = false;
this.viewportStatus = ViewportStatus.LOADING;

this.fillWithBackgroundColor();

Expand Down Expand Up @@ -1715,6 +1721,7 @@ class StackViewport extends Viewport implements IStackViewport {
}

this._setCSImage(image);
this.viewportStatus = ViewportStatus.PRE_RENDER;

const eventDetail: EventTypes.StackNewImageEventDetail = {
image,
Expand Down Expand Up @@ -2648,6 +2655,7 @@ class StackViewport extends Viewport implements IStackViewport {
element: this.element,
viewportId: this.id,
renderingEngineId: this.renderingEngineId,
viewportStatus: this.viewportStatus,
};
};

Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/RenderingEngine/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { vec2, vec3 } from 'gl-matrix';
import _cloneDeep from 'lodash.clonedeep';

import Events from '../enums/Events';
import ViewportStatus from '../enums/ViewportStatus';
import ViewportType from '../enums/ViewportType';
import renderingEngineCache from './renderingEngineCache';
import { triggerEvent, planar, isImageActor, actorIsA } from '../utilities';
Expand Down Expand Up @@ -50,6 +51,10 @@ class Viewport implements IViewport {
protected flipHorizontal = false;
protected flipVertical = false;
public isDisabled: boolean;
/** Record the renddering status, mostly for testing purposes, but can also
* be useful for knowing things like whether the viewport is initialized
*/
public viewportStatus: ViewportStatus = ViewportStatus.NO_DATA;

/** sx of viewport on the offscreen canvas */
sx: number;
Expand Down Expand Up @@ -117,6 +122,22 @@ class Viewport implements IViewport {
return false;
}

/**
* Indicate that the image has been rendered.
* This will set hte viewportStatus to RENDERED if there is image data
* available to actually be rendered - otherwise, the rendering simply showed
* the background image.
*/
public setRendered() {
if (
this.viewportStatus === ViewportStatus.NO_DATA ||
this.viewportStatus === ViewportStatus.LOADING
) {
return;
}
this.viewportStatus = ViewportStatus.RENDERED;
}

/**
* Returns the rendering engine driving the `Viewport`.
*
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/enums/ViewportStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum ViewportStatus {
/** Initial state before any volumes or stacks are available*/
NO_DATA = 'noData',
/** Stack/volumes are available but are in progress */
LOADING = 'loading',
/** Ready to be rendered */
PRE_RENDER = 'preRender',
/** In the midst of a resize */
RESIZE = 'resize',
/** Rendered image data */
RENDERED = 'rendered',
}

export default ViewportStatus;
2 changes: 2 additions & 0 deletions packages/core/src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import GeometryType from './GeometryType';
import ContourType from './ContourType';
import VOILUTFunctionType from './VOILUTFunctionType';
import DynamicOperatorType from './DynamicOperatorType';
import ViewportStatus from './ViewportStatus';

export {
Events,
Expand All @@ -22,4 +23,5 @@ export {
ContourType,
VOILUTFunctionType,
DynamicOperatorType,
ViewportStatus,
};
3 changes: 3 additions & 0 deletions packages/core/src/types/EventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type IImage from './IImage';
import type IImageVolume from './IImageVolume';
import type { VOIRange } from './voi';
import type VOILUTFunctionType from '../enums/VOILUTFunctionType';
import type ViewportStatus from '../enums/ViewportStatus';
import type DisplayArea from './displayArea';

/**
Expand Down Expand Up @@ -96,6 +97,8 @@ type ImageRenderedEventDetail = {
renderingEngineId: string;
/** Whether to suppress the event */
suppressEvents?: boolean;
/** Include information on whether this is a real rendering or just background */
viewportStatus: ViewportStatus;
};
/**
* IMAGE_VOLUME_MODIFIED Event's data
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/IViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Point3 from './Point3';
import ViewportInputOptions from './ViewportInputOptions';
import { ActorEntry } from './IActor';
import ViewportType from '../enums/ViewportType';
import ViewportStatus from '../enums/ViewportStatus';
import DisplayArea from './displayArea';

/**
Expand Down Expand Up @@ -38,6 +39,8 @@ interface IViewport {
suppressEvents: boolean;
/** if the viewport has been disabled */
isDisabled: boolean;
/** The rendering state of this viewport */
viewportStatus: ViewportStatus;
/** the rotation applied to the view */
getRotation: () => number;
/** frameOfReferenceUID the viewport's default actor is rendering */
Expand Down Expand Up @@ -88,6 +91,8 @@ interface IViewport {
getCanvas(): HTMLCanvasElement;
/** returns camera object */
getCamera(): ICamera;
/** Sets the rendered state to rendered if the render actually showed image data */
setRendered(): void;
/** returns the parallel zoom relative to the default (eg returns 1 after reset) */
getZoom(): number;
/** Sets the relative zoom - set to 1 to reset it */
Expand Down

0 comments on commit eeef233

Please sign in to comment.