<div dir="ltr">In general (unless I missed something), it looks fine. A couple of notes:<div><br></div><div>1. You don't need to even shallow copy, you can simply save the output from any of the internal filters (I typically use a vtkSmartPointer to hold on to the reference). e.g.</div><div><br></div><div>  vtkSmartPointer<vtkDataObject> intermediaResult = <span style="font-size:12.8px">filt1</span>->GetOutput();</div><div><br></div><div>2. You can connect fil1 and filt2 in a pipeline too, to avoid keeping the intermediate dataset explicitly:</div><div><br></div><div>   filter2->SetInputConnection(filt1->GetOutputPort());</div><div>   filter2->Update();</div><div>   output->ShallowCopy(filter2->GetOutput());</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 2, 2017 at 6:42 AM, Cornelis Bockemühl <span dir="ltr"><<a href="mailto:cornelis.bockemuehl@gmail.com" target="_blank">cornelis.bockemuehl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear all,<div><br></div><div>Would the following construct be safe in terms of proper data handling inside a filter or would I generate some "unpredictable results", like data being copied over other data that is still being used?</div><div><br></div><div>My purpose is of course to copy data only if it is absolutely required. And I assume that within the different filters, data are again handled correctly.</div><div><br></div><div>...::RequestData(...)</div><div>{</div><div>  // get input and output</div><div>  vtkPolyData* input0 = vtkPolyData::SafeDownCast(<wbr>info->Get(vtkDataObject::DATA_<wbr>OBJECT()));</div><div>  vtkPolyData* output = vtkPolyData::SafeDownCast(...)<wbr>;</div><div>  ...</div><div><br></div><div>  // intermediate data storage</div><div>  vtkSmartPointer<vtkPolyData> intermediateData = vtkSmartPointer<vtkPolyData>::<wbr>New();</div><div><br></div><div>  // first filter</div><div>  vtkSmartPointer<vtkSomeFilter> filt1 = vtkSmartPointer<vtkSomeFilter><wbr>::New();</div><div>  filt1->SetInputData(input0);</div><div>  ...</div><div>  filt1->Update();</div><div>  intermediateData->ShallowCopy(<wbr>filt1->GetOutput());</div><div><br></div><div>  // second filter</div><div>  vtkSmartPointer<<wbr>vtkSomeOtherFilter> filt2 = vtkSmartPointer<<wbr>vtkSomeOtherFilter>::New();</div><div>  filt2->SetInputData(<wbr>intermediateData);</div><div>  ...</div><div>  filt2->Update();</div><div>  intermediateData->ShallowCopy(<wbr>filt2->GetOutput()); // !!! actually replacing the input data...</div><div><br></div><div>  // some more filters in the same way as filt2 - with always reusing intermediateData...</div><div>  ...</div><div><br></div><div>  // return the results</div><div>  output->ShallowCopy(<wbr>intermediateData);<br></div><div>}</div><div><div><br></div><div>Any comments?</div><div><br></div><div>Of course I could play safe and</div><div><br></div><div>1) replace all "ShallowCopy" with "DeepCopy", and</div><div>2) generate an intermediate data object for each and every filter that I am applying</div><div><br></div><div>but this for sure would blow up my memory enormously!</div><div><br></div><div>Maybe there is also some document that clearly states what is the proper "behaviour" inside filters like that, some kind of "code of conduct" regarding memory management in VTK?</div><div><br></div><div>Thanks for any helpful hints!</div><div><br></div><div>Regards,</div><div>Cornelis</div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_-7045021852117245839gmail_signature">Cornelis Bockemühl<br>Basel, Schweiz<br></div>
</font></span></div></div>
<br>______________________________<wbr>_________________<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/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" rel="noreferrer" target="_blank">http://paraview.org/Wiki/<wbr>ParaView</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=ParaView" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/paraview" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/paraview</a><br>
<br></blockquote></div><br></div>