[vtkusers] vtkResliceImageViewer::SetInputData() slow when executed after vtkDICOMImageReader::Update()

David Gobbi david.gobbi at gmail.com
Tue Feb 13 11:59:58 EST 2018


Regarding speed and the VTK imaging pipeline, you have to be careful about
"streaming" capabilities of VTK, especially for 3D images.

"Streaming" means that for each filter (or reader or mapper) the VTK
imaging pipeline has a settable UpdateExtent, which specifies a region of
the image.  I.e. a filter can be requested to only operate on part of the
image.  If you use obj2->SetInputConnection(obj1->GetOutputPort()), then
"obj2" will control the UpdateExtent of "obj1".  In other words, the
consumer of a filter's output controls the UpdateExtent of that filter.

Here's where this is important with respect to speed.  When you display a
slice of an image, the mapper will request an UpdateExtent for the voxels
in that slice.  The pipeline will forward this UpdateExtent all the way
back along the pipeline, usually all the way to the reader.  So if the user
is trying to scroll through the slices, this can cause the reader to
re-execute for every single new slice.  Obviously this will be slow.  One
way to avoid this is to call Update() on the reader before connecting the
reader to the rest of the pipeline.  Calling Update() before the pipeline
sets the UpdateExtent will cause the reader to read the entire volume into
memory just once.  If it isn't possible to call Update() before connecting
the reader to the pipeline, you can instead call UpdateWholeExtent() at any
point after the pipeline is created.

In general, when you build an image pipeline in VTK, you can consider which
parts of the pipeline are "static" (only need to be executed once) and
which are "dynamic" (respond to user interaction).  After setting up the
"static" part of the pipeline, call UpdateWholeExtent() on it.  You can go
even further by connecting the "static" part of the pipeline to the
"dynamic" part of the pipeline with SetInputData() instead of
SetInputConnection().  This will ensure that pipeline requests are never
forwarded from the "dynamic" part of the pipeline to the "static" part.

So, in summary: the default behavior of the VTK image display pipeline is
to stream regions of the image rather than to execute the filters over the
whole image.  In some situations this is good, but in other situations
you'll want to override this behavior by either calling Update() yourself
and/or by using SetInputData() instead of SetInputConnection().

 - David


On Tue, Feb 13, 2018 at 7:37 AM, Sankhesh Jhaveri <
sankhesh.jhaveri at kitware.com> wrote:

> I see. That makes sense since its a viewport and not a filter. Have you
> seen the vtkImageResliceMapper class. Perhaps try slicing with that
> instead of the vtkImageResliceViewer, to see if you get better
> performance.
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180213/f10a4bce/attachment.html>


More information about the vtkusers mailing list