[vtkusers] vtkResliceImageViewer::SetInputData() slow when executed after vtkDICOMImageReader::Update()
david.gobbi at gmail.com
Thu Feb 15 09:56:14 EST 2018
I peeked at the vtkResliceImageViewer source code and I see that
its SetInputData() is not a simple setter method, it does a lot of work
internally. This is very unusual for a VTK SetInputData() method.
Your hypothesis about GetScalarRange() seems to be mostly correct.
If things are done as follows, the SetInputData() method is fast:
When GetScalarRange() is called, the result is cached so that when
it's called again from the viewer it's fast.
For case (3), I suspect that the viewer updates one slice of its input
(via streaming) before calling GetScalarRange(). So that's why it
would be fast in that case: the range is computed for just one slice,
instead of for the entire volume.
On Wed, Feb 14, 2018 at 8:24 AM, ochampao <ochampao at hotmail.com> wrote:
> Hi David and thanks for the detailed reply.
> Your reply makes clear the difference between "streaming" data vs. loading
> the whole volume in memory. However, with these in mind, I still can't
> explain the behaviour I observe in the minimal example that I have posted
> above (see , same code repeated below as well). Namely, if we assume
> reader->Update() loads the whole volume in memory, then why calling
> resliceImageViewer->SetInputData(data) takes longer to complete if
> is called at positions (1) or (2)?
> When stepping through the code to see what causes this delay (when Update()
> is called at position (1) or (2) ) I have noticed that execution spends
> of its time at the following line:
> of the function vtkResliceImageViewer::SetInputData(vtkImageData *in)
> 450 in vtkResliceImageViewer.cxx).
> I guess, since the image is not yet loaded (when Update() is called at (3)
> calculating the scalar range on an "empty" image takes no time. It is as if
> in case (3) we are "cheating" and skipping the GetScalarRange()
> Doesn't GetScalarRange() get executed at some point even for case (3), and
> if yes, why does it take less time?
> #include "vtkDICOMImageReader.h"
> #include "vtkImageData.h"
> #include "vtkInteractorStyleImage.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkResliceImageViewer.h"
> #include "vtkSmartPointer.h"
> int main(int argc, char** argv)
> vtkNew<vtkDICOMImageReader> reader;
> vtkNew<vtkResliceImageViewer> resliceImageViewer;
> vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
> vtkNew<vtkInteractorStyleImage> style;
> vtkNew<vtkRenderWindow> renderWindow;
> vtkNew<vtkRenderer> renderer;
> vtkSmartPointer<vtkImageData> data;
> renderer->SetBackground(0.0, 0.0, 0.0);
> //reader->Update(); // --> (1) SetInputData() takes ~18 seconds
> data = reader->GetOutput();
> //reader->Update(); // --> (2) SetInputData() takes ~18 seconds
> reader->Update(); // --> (3) SetInputData() takes less than 1 seconds
> return 0;
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtkusers