Skip to content

Commit

Permalink
feat(ImageCPRMapper): add updatedExtents support
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Feb 22, 2025
1 parent 6f57a27 commit 508e35a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Sources/Rendering/Core/ImageCPRMapper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,25 @@ export interface vtkImageCPRMapper
* @param imageData
*/
setImageConnection(imageData: vtkOutputPort): void;

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

/**
* Retrieves the updated extents.
*
* This array is cleared after every successful render.
*/
getUpdatedExtents(): Extent[];
}

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

const DEFAULT_VALUES = {
const defaultValues = (initialValues) => ({
width: 10,
uniformOrientation: [0, 0, 0, 1],
useUniformOrientation: false,
Expand All @@ -344,12 +344,14 @@ const DEFAULT_VALUES = {
projectionSlabThickness: 1,
projectionSlabNumberOfSamples: 1,
projectionMode: ProjectionMode.MAX,
};
updatedExtents: [],
...initialValues,
});

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

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

// Inheritance
vtkAbstractImageMapper.extend(publicAPI, model, initialValues);
Expand All @@ -374,6 +376,7 @@ export function extend(publicAPI, model, initialValues = {}) {
'projectionSlabThickness',
'projectionSlabNumberOfSamples',
'projectionMode',
'updatedExtents',
]);
CoincidentTopologyHelper.implementCoincidentTopologyMethods(publicAPI, model);

Expand Down
19 changes: 19 additions & 0 deletions Sources/Rendering/OpenGL/ImageCPRMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
const reBuildTex =
!cachedScalarsEntry?.oglObject?.getHandle() ||
cachedScalarsEntry?.hash !== volumeTextureHash;
const updatedExtents = model.renderable.getUpdatedExtents();
const hasUpdatedExtents = !!updatedExtents.length;

if (reBuildTex) {
model.volumeTexture = vtkOpenGLTexture.newInstance();
model.volumeTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
Expand Down Expand Up @@ -236,6 +239,22 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
model.volumeTexture = cachedScalarsEntry.oglObject;
}

if (hasUpdatedExtents) {
// If hasUpdatedExtents, then the texture is partially updated.
// clear the array to acknowledge the update.
model.renderable.setUpdatedExtents([]);

const dims = image.getDimensions();
model.volumeTexture.create3DFilterableFromDataArray(
dims[0],
dims[1],
dims[2],
scalars,
false,
updatedExtents
);
}

// Rebuild the color texture if needed
const numComp = scalars.getNumberOfComponents();
const ppty = actor.getProperty();
Expand Down

0 comments on commit 508e35a

Please sign in to comment.