[Paraview] Question about data (memory) management

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Thu Feb 2 09:46:08 EST 2017


In general (unless I missed something), it looks fine. A couple of notes:

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.

  vtkSmartPointer<vtkDataObject> intermediaResult = filt1->GetOutput();

2. You can connect fil1 and filt2 in a pipeline too, to avoid keeping the
intermediate dataset explicitly:

   filter2->SetInputConnection(filt1->GetOutputPort());
   filter2->Update();
   output->ShallowCopy(filter2->GetOutput());



On Thu, Feb 2, 2017 at 6:42 AM, Cornelis Bockemühl <
cornelis.bockemuehl at gmail.com> wrote:

> Dear all,
>
> 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?
>
> 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.
>
> ...::RequestData(...)
> {
>   // get input and output
>   vtkPolyData* input0 = vtkPolyData::SafeDownCast(
> info->Get(vtkDataObject::DATA_OBJECT()));
>   vtkPolyData* output = vtkPolyData::SafeDownCast(...);
>   ...
>
>   // intermediate data storage
>   vtkSmartPointer<vtkPolyData> intermediateData =
> vtkSmartPointer<vtkPolyData>::New();
>
>   // first filter
>   vtkSmartPointer<vtkSomeFilter> filt1 = vtkSmartPointer<vtkSomeFilter>
> ::New();
>   filt1->SetInputData(input0);
>   ...
>   filt1->Update();
>   intermediateData->ShallowCopy(filt1->GetOutput());
>
>   // second filter
>   vtkSmartPointer<vtkSomeOtherFilter> filt2 = vtkSmartPointer<
> vtkSomeOtherFilter>::New();
>   filt2->SetInputData(intermediateData);
>   ...
>   filt2->Update();
>   intermediateData->ShallowCopy(filt2->GetOutput()); // !!! actually
> replacing the input data...
>
>   // some more filters in the same way as filt2 - with always reusing
> intermediateData...
>   ...
>
>   // return the results
>   output->ShallowCopy(intermediateData);
> }
>
> Any comments?
>
> Of course I could play safe and
>
> 1) replace all "ShallowCopy" with "DeepCopy", and
> 2) generate an intermediate data object for each and every filter that I
> am applying
>
> but this for sure would blow up my memory enormously!
>
> 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?
>
> Thanks for any helpful hints!
>
> Regards,
> Cornelis
>
> --
> Cornelis Bockemühl
> Basel, Schweiz
>
> _______________________________________________
> 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 ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Search the list archives at: http://markmail.org/search/?q=ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/paraview
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20170202/e8738b0b/attachment.html>


More information about the ParaView mailing list