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

Sankhesh Jhaveri sankhesh.jhaveri at kitware.com
Fri Feb 9 11:52:47 EST 2018


Hi,

First of all, you should not be calling vtkSmartPointer<vtkImageData>::New()
for data if you intend to use that variable for storing the output from
reader. That way you don’t end up with a dangling pointer/memory leak.

Secondly, note that the output from the reader is not available until
reader->Update() is called. The faster portion of your code is fast because
the reslice viewer has been just getting a default vtkImageData object.

As for slowness you see, could you please provide details on the data type
and size and how much time is spent in SetInputData?

Hope that helps,
Sankhesh
​

On Fri, Feb 9, 2018 at 11:22 AM ochampao <ochampao at hotmail.com> wrote:

> Hello vtkusers!
>
> I am experimenting with a simple dicom viewer similar to the FourPaneViewer
> example (see [1] for link). But I am observing a behaviour which I can't
> explain. In particular, when I place the
> vtkResliceImageViewer::SetInputData()
> calls before calling the vtkDICOMImageReader::Update(), the dataset is
> loaded extremely fast (approximately 2 seconds). However when
> vtkResliceImageViewer::SetInputData() calls are placed after
> vtkDICOMImageReader::Update(), then loading the dataset requires
> significantly more time to load (approximately 22 seconds). See minimal
> code example below.
>
> Why is the code slower when executed after the Update() call and how can
> this be avoided?
>
> Is it wrong to place the SetInputData() call after Update()? If yes, how
> can
> the vtkImageData object be passed to SetInputData() so that it is still
> fast?
>
> For the slower case, when stepping through the code with the debugger, I
> can
> see that the call to Update() is still fast but the debugger spends most of
> its time at SetInputData().
>
> Eventually, what I'd like to do is group the code that reads the dicom into
> a separate function that returns a vtkImageData reference to the pipeline.
> But from this experiment it seems to work very slow.
>
> Thanks,
> Panos.
>
> =======
>
> Here is a minimal example of my code to demonstrate the two situation
> (commented is the slow case):
>
> void addImage(const char* filename)
> {
>     vtkSmartPointer< vtkDICOMImageReader > reader =
>         vtkSmartPointer< vtkDICOMImageReader >::New();
>     reader->SetDirectoryName(filename);
>
>     vtkSmartPointer<vtkImageData> data =
>         vtkSmartPointer<vtkImageData>::New();
>
>     data = reader->GetOutput();
>
>     //---------------------------------------
>     // SetInputData() works very fast if here
>     resliceImageViewer1->SetInputData(data);
>     resliceImageViewer2->SetInputData(data);
>     resliceImageViewer3->SetInputData(data);
>     // ---------------------------------------
>
>     reader->Update();
>
>     //---------------------------------------
>     // SetInputData() works very slow if here
>     //
>     //resliceImageViewer1->SetInputData(data);
>     //resliceImageViewer2->SetInputData(data);
>     //resliceImageViewer2->SetInputData(data);
>     //---------------------------------------
>
>     /*
>         code to setup widgets (orientation, slice#, window/level color)
>     */
>
>     resliceImageViewer1->Render();
>     resliceImageViewer2->Render();
>     resliceImageViewer3->Render();
> }
>
> ========
> References:
>
> [1]:
> https://github.com/Kitware/VTK/tree/master/Examples/GUI/Qt/FourPaneViewer
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>
-- 
Sankhesh Jhaveri *Sr. Research & Development Engineer* | Kitware
<http://www.kitware.com/> | (518) 881-4417
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180209/f0d709e6/attachment.html>


More information about the vtkusers mailing list