Skip to content

Commit

Permalink
feat(VolumeMapper): support updating image regions
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Jun 4, 2024
1 parent ac4d712 commit eda0053
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 61 deletions.
29 changes: 28 additions & 1 deletion Sources/Rendering/Core/VolumeMapper/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import vtkPiecewiseFunction from "../../../Common/DataModel/PiecewiseFunction";
import { Bounds, Range } from "../../../types";
import { Bounds, Range, Vector3 } from "../../../types";
import vtkAbstractMapper3D, { IAbstractMapper3DInitialValues } from "../AbstractMapper3D";
import { BlendMode, FilterMode } from "./Constants";

/**
* Represents a 3D region of a volume.
*/
export interface VolumeRegion {
start: Vector3;
size: Vector3;
}

/**
*
*/
Expand Down Expand Up @@ -278,6 +286,25 @@ export interface vtkVolumeMapper extends vtkAbstractMapper3D {
*/
setLAOKernelRadius(LAOKernelRadius: number): void;

/**
* Tells the mapper to only update the specified regions.
*
* If there are zero regions, the mapper updates the entire volume texture.
* Otherwise, the mapper will only update the texture by the specified regions
* during the next render call.
*
* This array is cleared after a successful render.
* @param regions
*/
setRegionsToUpdate(regions: VolumeRegion[]): boolean;

/**
* Retrieves the regions to update.
*
* This array is cleared after every successful render.
*/
getRegionsToUpdate(): VolumeRegion[];

/**
*
*/
Expand Down
9 changes: 6 additions & 3 deletions Sources/Rendering/Core/VolumeMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function vtkVolumeMapper(publicAPI, model) {
// ----------------------------------------------------------------------------

// TODO: what values to use for averageIPScalarRange to get GLSL to use max / min values like [-Math.inf, Math.inf]?
const DEFAULT_VALUES = {
const defaultValues = (initialValues) => ({
bounds: [1, -1, 1, -1, 1, -1],
sampleDistance: 1.0,
imageSampleDistance: 1.0,
Expand All @@ -163,12 +163,14 @@ const DEFAULT_VALUES = {
localAmbientOcclusion: false,
LAOKernelSize: 15,
LAOKernelRadius: 7,
};
regionsToUpdate: [],
...initialValues,
});

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
Object.assign(model, defaultValues(initialValues));

vtkAbstractMapper3D.extend(publicAPI, model, initialValues);

Expand All @@ -190,6 +192,7 @@ export function extend(publicAPI, model, initialValues = {}) {
'localAmbientOcclusion',
'LAOKernelSize',
'LAOKernelRadius',
'regionsToUpdate',
]);

macro.setGetArray(publicAPI, model, ['ipScalarRange'], 2);
Expand Down
Loading

0 comments on commit eda0053

Please sign in to comment.