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

Reply via email to