Skip to main content

Volume Render Strategy

A strategy states how a render gets its voxels. It is the unit that a volume render path works with, and the names of the texture sets derive from it.

A device cannot always hold the full-resolution texture of a volume. The older code built one texture in the constructor of ImageVolume, asked for it at the full dimensions, failed inside the driver and showed a black viewport. A strategy replaces that: a render path states which strategies it can use, the expensive work happens off the frame path, and each render chooses among what already exists.

The pieces​

                        ┌─────────────────────────────────────────────┐
│ ImageVolume │
the data │ · the voxels, through CompositeVoxelManager
and its │ · the named texture sets of this volume │
textures │ · the grid of the full-resolution data │
└─────────────────────────────────────────────┘
▲ ▲
│ reads voxels │ lists its sets
│ │
╔═══════════════════════════╪════════════════════════╪═══════════════════════════╗
║ WHEN THE VIEWPORT ADDS ITS ACTOR, AND AGAIN ON A REBUILD ║
║ │ │ ║
║ VtkVolumeSliceRenderPath│ │ ║
║ │ │ │ ║
║ │ asks │ │ ║
║ ▼ │ │ ║
║ VolumeStrategyProvider ─┘ │ ║
║ │ · reads the GpuSettings │ ║
║ │ · computes the box factors per axis │ ║
║ │ · provisions the texture sets ──────┘ ║
║ │ ║
║ ▼ ║
║ IVolumeRenderStrategy[] the strategies this render path may use ║
║ ║
║ a rebuild runs the provider again, on one of two events, and NEVER on a ║
║ render: loaded the data finished loading ║
║ memory the preset, the downsampling or the budget changed ║
╚═════════════════════════════════════════════════════════════════════════════════╝
│
│ held by the render path
▼
╔═════════════════════════════════════════════════════════════════════════════════╗
║ EVERY RENDER ║
║ ║
║ SelectVolumeStrategy ──────► one strategy, or NOTHING ║
║ │ ║
║ │ the chosen strategy updates anything of its own that moves ║
║ ▼ ║
║ StrategyBinding[] ordered, each with a role: base or refinement ║
║ │ ║
║ ├──────────► the mapper binds the base texture ║
║ │ ║
║ └──────────► the render composes a VoxelQualityRecord ║
╚═════════════════════════════════════════════════════════════════════════════════╝

╔═════════════════════════════════════════════════════════════════════════════════╗
║ WHENEVER NEW DATA ARRIVES ║
║ ║
║ the loader ──► the voxel managers ──► ImageVolume marks the frame ║
║ │ ║
║ ▼ ║
║ every texture whose grid covers that frame ║
║ │ ║
║ ▼ ║
║ refilled at the next render of that texture ║
╚═════════════════════════════════════════════════════════════════════════════════╝
PieceWhat it is
IVolumeRenderStrategyHow one render gets its voxels. It says what to bind, and it keeps what it holds current. A strategy instance belongs to one render path.
VolumeStrategyProviderBuilds the strategies of one render path. A render component defines its own provider, and that is how a new render type defines new texture sets.
SelectVolumeStrategyChooses the strategy of one render, among the strategies that the provider already built.
StrategyBindingOne texture that a strategy offers, with the role base or refinement.
VolumeTextureSetA named set of textures, and the unit of storage, of cost and of eviction.
volumeTextureStoreThe global store of the sets, with one budget for the texture memory of every volume.
CompositeVoxelManagerThe voxels. It holds the full-resolution data and every reduced representation, and it fills a grid from the best sources that it has.
GpuSettingsThe values that a preset gives: the texture edge, the texture memory and the speed. auto takes them from the device; a named preset is fixed.
VoxelQualityRecordThe absolute record of the data that a render drew. It states no verdict.

Where the code is​

Volume Render Sequences gives the sequence of calls as diagrams. The table gives the file of each piece. The paths are under packages/core/src/, except the last row.

Piece or stepCode
The presets, and the limits of a gridutilities/gpuSettingsPresets.ts: setGpuSettingsPreset, gridLimitsOfGpuSettings
The record of the device, and the edge probeutilities/renderingCapabilities.ts, utilities/textureSupport.ts (see GPU device limits)
The fair share of the memory limit of autoRenderingEngine/helpers/volumeRenderStrategy.ts: fairShares
The factors of a reduction, and the reduced gridutilities/voxelGrid/: boxAverageReductionFactors, reducedDimensions, deriveBoxAverageGrid
The default provider and the default selectionRenderingEngine/helpers/volumeRenderStrategy.ts: defaultVolumeStrategyProvider, selectFirstReadyStrategy
The one place that both architectures shareRenderingEngine/helpers/resolveVolumeTexture.ts, called by createVolumeActor and createVolumeSliceActor
The texture sets and the storecache/classes/VolumeTextureSet.ts, cache/volumeTextureStore.ts, ImageVolume.provisionTextureSet
The marks and the deliveriescache/classes/ImageVolume.ts: markFrameTexturesDirty, recordFrameDelivery, markFrameModified
The loadcache/classes/BaseStreamingImageVolume.ts: load, successCallback, takeInCachedImages
The fill of a reduced textureRenderingEngine/vtkClasses/vtkStreamingOpenGLTexture.js: updateTextureFromComposite, fillSliceByBoxStatistic
The selection on each render (generic architecture)RenderingEngine/helpers/volumeStrategyLifecycle.ts: provisionStrategies, applyStrategy, onVolumeData
The sample distance of a 3D renderRenderingEngine/helpers/createVolumeMapper.ts: sampleDistanceOf
The statistic of a labelmappackages/tools/src/stateManagement/segmentation/labelmapModel/labelmapLayerStore.ts: tagLabelmapVolume

How the viewport builds the strategies​

The provider runs when the render path adds its actor, and it never runs on the frame path. It does the expensive thing: it allocates the textures.

With final downsampling off (rendering.lossyDownsampling.final, the default), the default provider always builds the full-resolution strategy. With final downsampling on, the provider reads the GPU settings and answers in one of two ways:

  • The device can hold the full-resolution grid, so the provider builds the full-resolution strategy and provisions the set full-resolution/full-extent.
  • The device cannot, so the provider computes the size of the box on each axis and provisions a reduced set whose name carries those factors.

The reduction is per axis and it is not uniform. An edge of 2049 voxels exceeds a limit of 2048 on one axis and by one voxel, so one axis reduces and the other two do not. A factor can hold a fraction, see VRS-I-12.

The provider derives no representation. A reduced texture fills each slice with the fillPlane of the statistic of the volume (ImageVolume.reductionStatistic) straight from the frames of the volume: a box average for an intensity volume, or a foreground majority for a labelmap. The fill needs no reduced copy of the voxels in CPU memory. A derivation of a volume that holds all of its data would otherwise reduce every voxel during the provision, which takes many seconds on the main thread for 512 × 512 × 2464 voxels. ImageVolume.getGridQuality gives the record of such a texture from the deliveries of the volume.

The textures hold no data at this point. Almost none of the images of the volume have arrived when a viewport adds its actor. The loader fills the voxel managers as the data arrives, ImageVolume marks every texture whose grid covers the new region, and each render refills the marked slices. That is the path that the code already used, and a strategy does not change it.

One render fills a limited number of reduced slices. The fill of a reduced texture runs on the main thread inside the render, so a render stops after rendering.reducedTextureFill.maxSlicesPerRender slices that hold data (16 by default). It also stops when rendering.reducedTextureFill.maxMillisecondsPerRender (8 ms by default) has passed, but only after it filled at least one slice. A value below 1 slice counts as 1. The texture then requests another render for the slices that remain, and the next fill starts where the last one stopped. A slice view sets the start to the slice of its focal point before it draws (setFillHint), so the slice that it shows fills first. While slices wait for the fill, the fidelity of the viewport is loading.

A reduced slice reads only the frames that have arrived. A frame that has not arrived would pull the average towards 0. A replicate is a copy of another frame, so a slice reads a replicate only when no frame of its box has arrived.

How the volume takes a delivery​

ImageVolume states three separate things, and each caller states only what it knows:

MemberWhat it doesWho calls it
markFrameTexturesDirtyForgets the image that the voxel manager last resolved for the frame, and marks the frame in every texture whose grid covers itevery caller that changes the image of a frame
recordFrameDeliveryRecords the quality of the framea loader, which knows the quality of the data that it delivered
markFrameModifiedMarks the textures of the frame. It records no qualityan edit of the voxels at an unchanged quality, such as a labelmap

Only a caller that knows the quality records it. A lower record never replaces a higher one, so a record of FULL_RESOLUTION for a thumbnail would stay for ever. The cache adds an image before the loader calls successCallback, so a listener of the cache only marks the textures of an image whose quality is not known yet, and successCallback records the delivery right after it.

BaseStreamingImageVolume.invalidateVolume records nothing. Every voxel then holds other data, such as the next dimension group of a dynamic volume, so the volume discards its composite and builds it again from the deliveries of the data that the grid now shows, and it marks every texture.

How the load reaches a reduced texture​

The reduced-copy pipeline (derived representations, reduced images, slabs and the brick index) is under further development on the branch brick-loader. A reduced texture reads the frames of the volume directly, so it needs no derived copy.

The loader keeps the true decoded size. The request states the type of the buffer and no size, so an image keeps the size that the decoder produced: a sub-resolution HTJ2K decode and a JLS thumbnail stay small in the cache. The voxel manager of the volume scales such an image when it reads it, so the primary grid answers over its whole extent.

When the strategies are rebuilt​

The provider runs again whenever something changes that could change its answer. A render path is long-lived, and two things move under it:

ReasonWhat changed
loadedThe data of the volume finished loading, so a strategy that could not draw before may now be worth building
memoryThe GPU settings preset, the lossy downsampling, the texture budget or the display sets of auto changed, so a strategy may need to be rebuilt, or replaced by one that the device can afford

A rebuild is an event, and never a render, so VRS-C-1 still holds: nothing allocates on the frame path.

Two rules make a rebuild safe:

  • A provider must be safe to run more than once. A texture set that the store already holds comes back as it is, so a second run of the same provider allocates nothing.
  • A strategy that the provider names again keeps its identity. A provider builds fresh objects, and a fresh object holds no claim on its texture set, so a rebuild that replaced a live strategy would leave that claim behind and the store could never evict the set. The render path therefore keeps the object that it already holds whenever the provider names it again, and it deactivates only the strategies that the provider stopped naming.

A strategy whose set the store evicted answers that it is not ready, and the selection passes over it at once, with no rebuild needed. The rebuild is what restores it.

How one render selects a strategy​

The selection runs on the frame path and it cannot fail. Every strategy already exists, so the selection allocates nothing, there is no refusal to answer and there is nothing to repeat.

The default selection keeps the strategy of the previous render while that strategy is still ready, and otherwise takes the first ready one. A render path that wants something else supplies its own function; the choice is a parameter of the render path and never a branch inside it.

Three answers are legal, and each means something different:

The selection answersWhat happens
a strategy with bindingsthe render binds the base texture, and reads any refinement textures in the way that render defines
a strategy with no bindingsthe strategy is ready, and the data is not in a texture. The full-resolution data may live in the voxel manager of a device that cannot hold the texture, and the render reads the composite
nothingno texture is bound at all. A CPU render answers this way for its lossless pass

The phase of a render is not defined here​

"Reduced for the first render, full resolution for the lossless render" is a real case, and it is not in this version. A phased render is tightly bound to how that render draws, so the render component that implements phases names its own phases and reads them in its own selection function. The record that the selection receives is open for exactly that reason: a reader takes the fields that it needs by name, and it must not assume that the record holds nothing else.

How a strategy keeps what it holds current​

A strategy is asked to update itself on each render. Most strategies do nothing there, because a full-extent texture never moves and the volume already marks its dirty slices.

How the quality is reported​

The render reports the quality, and no other piece can. The render is the only party that knows which textures it used and how it used them.

The case that settles it: a 3D render may read a coarse maximum-value texture only to decide which fine bricks to sample. The quality of that coarse texture is not the quality of the image, so a record composed from "the textures that were bound" would be wrong. Only the render knows that one texture answered a question and the others drew the picture.

The record states no verdict. A reader compares it against its own requirement, which is how two viewports over one volume report differently at one moment, and how a viewport reports lossless when the display resolution sits below the resolution of the data.

Scope, and the rule for a change to this document​

The user requirements of this work are MR-U-* in cornerstone3D#2921 and VFS-U-* in cornerstone3D#2902. This document does not restate them, and it does not change one.

This document holds the design, in two sections with different change rules:

  • § Contracts — what a consumer of this design may rely on. Change one of these in two cases only: the statement describes the behaviour wrongly, or the intended behaviour itself changes. That a contract is inconvenient to implement is never a reason to change it.
  • § Implementation choices — how this version does the work. Change any of these freely when a better approach appears.

§ Contracts​

VRS-C-1. Provisioning never runs on the frame path. A render allocates no texture and derives no representation.

VRS-C-1.1. A provider may run again, on an event that could change its answer. A provider must therefore be safe to run more than once, and a second run of the same provider allocates nothing.

VRS-C-1.2. A strategy that a rebuild names again keeps its identity, so what that strategy holds stays balanced. A strategy that a rebuild stops naming is deactivated, so the store can evict its set.

VRS-C-2. The selection cannot fail. It chooses among strategies that already exist, so no caller handles a refusal and no caller repeats a request.

VRS-C-3. A strategy need not be backed by a texture. A ready strategy that offers no binding states that the data is available by another means.

VRS-C-4. A render may select no strategy. Nothing is bound, and that is not an error.

VRS-C-5. The render reports the quality, composed from the bindings that it used and from how it used them.

VRS-C-6. A strategy instance belongs to one render path. It is therefore the single owner of anything mutable that it holds.

VRS-C-7. The name of a texture set derives from the strategy. Two viewports that choose one strategy share one set, and they do not allocate two.

VRS-C-8. The set is the unit of eviction. A budget never evicts a set that a viewport draws: a render path claims the set that it draws. A legacy viewport claims the set of each volume actor while it holds that actor, and releases the claim when it removes the actor or ends, so a budget can evict the set of a volume that no viewport draws. A backstop set is evicted last, so a fill always finds a source.

VRS-C-9. The identity of a texture is stable and is not its grid. The grid is state of that texture, which is what lets a basis point move.

VRS-C-10. The record that the selection receives is open. A render component adds the fields that its own function reads, and no existing caller changes.

VRS-C-11. With final downsampling off (rendering.lossyDownsampling.final), a volume renders as in 4.x: it gets a full-resolution texture, no GPU settings preset applies, and a 3D render uses the sample distance of 4.x. Every render path reads the GPU settings through gpuSettingsForRender, which gives no settings in that case. CPU rendering (useCPURendering) also gets no settings, because the presets describe the limits of a WebGL GPU, not CPU memory.

§ Implementation choices​

VRS-I-1. The default provider builds the full-resolution strategy when it gets no GPU settings (see VRS-C-11) or the GPU settings admit it, and the reduced-resolution strategy otherwise. It reads the capability alone: a performance-bound choice belongs to task T14, which supplies its own provider.

VRS-I-2. The default selection keeps the strategy of the previous render while that strategy is ready, and otherwise takes the first ready one.

VRS-I-3. One class serves the full-resolution and the reduced-resolution strategies, because they differ only in the grid that they state.

VRS-I-4. The name of a reduced set carries the factors of the box and the statistic.

VRS-I-5. The store holds no budget until an application states one, so a viewport behaves as it behaved before the store existed.

VRS-I-6. Removed: the area index of a set moved to the branch brick-loader.

VRS-I-7. Removed: the slab that re-points moved to the branch brick-loader.

VRS-I-8. The volume slice render path reads the base binding alone.

VRS-I-9. The default provider derives no representation. A reduced texture fills by the statistic of the volume from the frames of the volume, and its record comes from the deliveries of the volume.

VRS-I-10. Removed: the derivation in batches moved to the branch brick-loader.

VRS-I-11. A legacy viewport pins its set instead of claiming it. A claim needs a release at every removal of an actor, and a legacy viewport has many such paths.

VRS-I-12. A reduced texture spans the full-resolution extent. The mappers allocate the dimensions of the reduced grid, and vtk.js maps the texture over the extent of the full-resolution imageData. On an axis of N source voxels and M texels, texel j therefore covers the source [j · N / M, (j + 1) · N / M), and the box of the fill must be that same range:

  • The factor of an axis is N / M, and it can hold a fraction. A fill averages the source over the range of the texel, and a source voxel that an end of the range cuts counts with the part of it that lies inside the range. The foreground majority of a labelmap uses the same weights.
  • deriveBoxAverageGrid of that factor gives the spacing s · N / M and puts the centre of box j at the centre of its range, so a CPU grid of the same reduction agrees with the texture.
  • boxAverageReductionFactors takes the largest M that fits the limits. It takes a whole factor f that divides N in place of that M when N / f is at least DIVISOR_PREFERENCE_MIN_RATIO (0.9) of M, because the box is then exact and whole.
  • An exception applies when the edge limit reduces an axis and the largest edge that fits is above WHOLE_FACTOR_MIN_FITTING_EDGE (1024). The axis then takes the whole factor f = ceil(N / maxTextureEdge) and M = ceil(N / f), with the box spacing N / M. For example, 2464 slices under an edge limit of 2048 give f = 2 and M = 1232, not 2048. A smaller texture helps the stability of the GPU, and at these sizes the loss of quality is small. The memory limit then reduces the axis further only when the grid still holds too many voxels. A reduction that the memory limit causes, and an edge reduction whose largest fit is 1024 or less, take the largest M that fits.
  • A whole factor that does not divide N gives ceil(N / f) texels, which do not span N source voxels. A texture of such a grid draws stretched, so no reduced texture uses one.

VRS-I-13. A dynamic (4D) volume is not reduced: its factors are [1, 1, 1], and it draws one full-resolution texture of the current dimension group, as in 4.x. The dynamic texture update writes full frames before any check of the grid, and the reduced fill reads frames by image-id index. An open issue tracks the support, to resolve after the first merge.

VRS-I-14. A volume of more than one component (for example RGB) is not reduced: its factors are [1, 1, 1]. The reduced fill and its upload have no component stride. An open issue tracks the support, to resolve after the first merge.

For both cases, the mapper does not refuse the allocation when the texture is larger than the GPU settings (gridFitsGpuSettings). It tries the upload, as in 4.x.

The frames of the acquisition plane​

This section applies only when rendering.lossyDownsampling.final is on, and the final downsampling reduces the texture of a volume.

What a user sees. A generic PlanarViewport shows the source volume in the acquisition plane. The source draws the loaded image of the nearest acquired frame in place of the reduced slice. The frame has full resolution, so the fidelity indicator reports the quality of the frame. Outside the acquisition plane, the viewport draws the reduced slice.

The limits.

  • The frame has no interpolation between frames. The viewport shows the nearest frame.
  • The reduced slice shows until the frame loads.
  • viewport.getActors() has one more entry for the frame. That entry has no referencedId, so a measurement tool does not see a second target.
  • The legacy viewports (StackViewport, VolumeViewport) keep the reduced slice, as in 4.x.
  • The viewport does not draw the frame for a slab thicker than one acquired slice, for a blend mode other than composite, for a dynamic volume, or for a CPU volume path.

PlanarRenderPathDecisionService.canDrawAcquiredFrames holds these conditions, and planarAcquiredFrames.ts draws the frame.

What a new render type defines​

A new render type supplies two things, and it changes no existing file:

  1. A provider, which decides which strategies exist and provisions the texture sets that they need. This is where a new kind of texture set is introduced.
  2. A selection function, which decides which of those strategies one render uses. This is where a phased render puts its phases.

Everything else — the store, the budget, the eviction, the dirty marking and the refill — is shared and needs no change.

What this version does not do​

ItemWhere it belongs
A ladder of grids. The provider builds one reduced grid, which is the largest that the device allows, and it never builds a coarse grid that a finer one later replaces. The resolution of a render therefore does not change while a volume loads, although its values refinea provider that reads the load progress
A phased render, and a vocabulary of phasesthe render component that implements one
A consumer of the refinement rolethe multi-texture render component
A performance-bound choice of strategytask T14
An automatic policy with recorded fixturestask T15
A brick loader, and the sets that it would provisiontask T7
The state that a user sees, and the indicator of OHIFtasks T3 and T6