<div dir="ltr"><div class="markdown-here-wrapper" style="font-family:"Lucida Sans",Cantarell,Verdana,sans-serif;color:rgb(11,83,148)"><p style="margin:0px 0px 1.2em!important">Hi,</p>
<p style="margin:0px 0px 1.2em!important">First of all, you should not be calling <code style="font-size:0.95em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(218,218,218);background-color:rgb(232,232,232);border-radius:3px;display:inline">vtkSmartPointer<vtkImageData>::New()</code> for <code style="font-size:0.95em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(218,218,218);background-color:rgb(232,232,232);border-radius:3px;display:inline">data</code> if you intend to use that variable for storing the output from <code style="font-size:0.95em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(218,218,218);background-color:rgb(232,232,232);border-radius:3px;display:inline">reader</code>. That way you don’t end up with a dangling pointer/memory leak.</p>
<p style="margin:0px 0px 1.2em!important">Secondly, note that the output from the reader is not available until <code style="font-size:0.95em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(218,218,218);background-color:rgb(232,232,232);border-radius:3px;display:inline">reader->Update()</code> is called. The faster portion of your code is fast because the reslice viewer has been just getting a default <code style="font-size:0.95em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(218,218,218);background-color:rgb(232,232,232);border-radius:3px;display:inline">vtkImageData</code> object.</p>
<p style="margin:0px 0px 1.2em!important">As for slowness you see, could you please provide details on the data type and size and how much time is spent in <code style="font-size:0.95em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(218,218,218);background-color:rgb(232,232,232);border-radius:3px;display:inline">SetInputData</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IGFuZCBo
b3cgbXVjaCB0aW1lIGlzIHNwZW50IGluIGBTZXRJbnB1dERhdGFgPzwvZGl2PjxkaXY+PGJyPjwv
ZGl2PjxkaXY+SG9wZSB0aGF0IGhlbHBzLDwvZGl2PjxkaXY+PGcgY2xhc3M9ImdyXyBncl82MzEg
Z3ItYWxlcnQgZ3Jfc3BlbGwgZ3JfaW5saW5lX2NhcmRzIGdyX3J1bl9hbmltIENvbnRleHR1YWxT
cGVsbGluZyBpbnMtZGVsIG11bHRpUmVwbGFjZSIgaWQ9IjYzMSIgZGF0YS1nci1pZD0iNjMxIj5T
YW5raGVzaDwvZz48L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 9, 2018 at 11:22 AM ochampao <<a href="mailto:ochampao@hotmail.com">ochampao@hotmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello vtkusers!<br>
<br>
I am experimenting with a simple dicom viewer similar to the FourPaneViewer<br>
example (see [1] for link). But I am observing a behaviour which I can't<br>
explain. In particular, when I place the<br>
vtkResliceImageViewer::SetInputData()<br>
calls before calling the vtkDICOMImageReader::Update(), the dataset is<br>
loaded extremely fast (approximately 2 seconds). However when<br>
vtkResliceImageViewer::SetInputData() calls are placed after<br>
vtkDICOMImageReader::Update(), then loading the dataset requires<br>
significantly more time to load (approximately 22 seconds). See minimal<br>
code example below.<br>
<br>
Why is the code slower when executed after the Update() call and how can<br>
this be avoided?<br>
<br>
Is it wrong to place the SetInputData() call after Update()? If yes, how can<br>
the vtkImageData object be passed to SetInputData() so that it is still<br>
fast?<br>
<br>
For the slower case, when stepping through the code with the debugger, I can<br>
see that the call to Update() is still fast but the debugger spends most of<br>
its time at SetInputData().<br>
<br>
Eventually, what I'd like to do is group the code that reads the dicom into<br>
a separate function that returns a vtkImageData reference to the pipeline.<br>
But from this experiment it seems to work very slow.<br>
<br>
Thanks,<br>
Panos.<br>
<br>
=======<br>
<br>
Here is a minimal example of my code to demonstrate the two situation<br>
(commented is the slow case):<br>
<br>
void addImage(const char* filename)<br>
{<br>
    vtkSmartPointer< vtkDICOMImageReader > reader =<br>
        vtkSmartPointer< vtkDICOMImageReader >::New();<br>
    reader->SetDirectoryName(filename);<br>
<br>
    vtkSmartPointer<vtkImageData> data =<br>
        vtkSmartPointer<vtkImageData>::New();<br>
<br>
    data = reader->GetOutput();<br>
<br>
    //---------------------------------------<br>
    // SetInputData() works very fast if here<br>
    resliceImageViewer1->SetInputData(data);<br>
    resliceImageViewer2->SetInputData(data);<br>
    resliceImageViewer3->SetInputData(data);<br>
    // ---------------------------------------<br>
<br>
    reader->Update();<br>
<br>
    //---------------------------------------<br>
    // SetInputData() works very slow if here<br>
    //<br>
    //resliceImageViewer1->SetInputData(data);<br>
    //resliceImageViewer2->SetInputData(data);<br>
    //resliceImageViewer2->SetInputData(data);<br>
    //---------------------------------------<br>
<br>
    /*<br>
        code to setup widgets (orientation, slice#, window/level color)<br>
    */<br>
<br>
    resliceImageViewer1->Render();<br>
    resliceImageViewer2->Render();<br>
    resliceImageViewer3->Render();<br>
}<br>
<br>
========<br>
References:<br>
<br>
[1]:<br>
<a href="https://github.com/Kitware/VTK/tree/master/Examples/GUI/Qt/FourPaneViewer" rel="noreferrer" target="_blank">https://github.com/Kitware/VTK/tree/master/Examples/GUI/Qt/FourPaneViewer</a><br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html</a><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://vtk.org/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div class="inbox-inbox-inbox-inbox-inbox-inbox-inbox-markdown-here-wrapper" style="font-family:"proza libre",sans-serif;color:rgb(0,56,107)"><h5 id="inbox-inbox-inbox-inbox-inbox-inbox-inbox-sankhesh-jhaveri" style="margin:1.3em 0px 1em;padding:0px;font-size:1.1em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);font-weight:bold;color:rgb(11,65,148)">Sankhesh Jhaveri</h5>
<h6 id="inbox-inbox-inbox-inbox-inbox-inbox-inbox--sr-research-development-engineer-kitware-http-www-kitware-com-518-881-4417" style="margin:1.3em 0px 1em;padding:0px;font-size:1em;color:rgb(11,83,148);font-family:"open sans",sans-serif;font-weight:normal"><em>Sr. Research & Development Engineer</em> | <a href="http://www.kitware.com/">Kitware</a> | (518) 881-4417</h6>
<div title="MDH:PGIgc3R5bGU9ImZvbnQtZmFtaWx5OiB2ZXJkYW5hLCBzYW5zLXNlcmlmOyBjb2xvcjogcmdiKDEx
LCA4MywgMTQ4KTsiPjxmb250IHNpemU9IjIiPiMjIyMjU2Fua2hlc2ggSmhhdmVyaTwvZm9udD48
L2I+PGRpdj48Zm9udCBjb2xvcj0iIzBiNTM5NCIgZmFjZT0idmVyZGFuYSwgc2Fucy1zZXJpZiIg
c2l6ZT0iMiI+PGI+PGJyPjwvYj48L2ZvbnQ+PGRpdj48c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6
IGFyaWFsLCBzYW5zLXNlcmlmOyBjb2xvcjogcmdiKDExLCA4MywgMTQ4KTsiPjxzcGFuIHN0eWxl
PSJmb250LWZhbWlseTogdmVyZGFuYSwgc2Fucy1zZXJpZjsiPjxpPiMjIyMjIypTci4gUmVzZWFy
Y2ggJmFtcDsgRGV2ZWxvcG1lbnQgRW5naW5lZXIqPC9pPiZuYnNwO3wmbmJzcDs8L3NwYW4+PC9z
cGFuPjxzcGFuIHN0eWxlPSJmb250LWZhbWlseTogdmVyZGFuYSwgc2Fucy1zZXJpZjsgY29sb3I6
IHJnYigxMSwgODMsIDE0OCk7Ij48YSBocmVmPSJodHRwOi8vd3d3LmtpdHdhcmUuY29tLyIgdGFy
Z2V0PSJfYmxhbmsiIHN0eWxlPSJjb2xvcjogcmdiKDE3LCA4NSwgMjA0KTsiPktpdHdhcmU8L2E+
Jm5ic3A7fCZuYnNwOzwvc3Bhbj48c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6IHZlcmRhbmEsIHNh
bnMtc2VyaWY7IGNvbG9yOiByZ2IoMTEsIDgzLCAxNDgpOyI+KDUxOCkgODgxLTQ0MTc8L3NwYW4+
PGJyPjwvZGl2PjxkaXY+PGRpdj48ZGl2PjxzcGFuIHN0eWxlPSJmb250LWZhbWlseTogdmVyZGFu
YSwgc2Fucy1zZXJpZjsgY29sb3I6IHJnYigxMSwgODMsIDE0OCk7Ij48L3NwYW4+PC9kaXY+PC9k
aXY+PC9kaXY+PC9kaXY+" style="height:0px;width:0px;max-height:0px;max-width:0px;overflow:hidden;font-size:0em;padding:0px;margin:0px">​</div></div></div></div>