What is the Shallow Copy and DeepCopy

Hi to everyone;

SomeOne can tell me what is the difference between Shallow Copy, DeepCopy and simple affectation?

for exemple: what is the difference between:

1- vtkImagedata* image = filter->GetOutput();
2- image ->ShallowCopy (filrer->GetOutput());
3- image-> DeepCopy(filter->GetOutput());

Thank’s in advance

This wiki page describes deep versus shallow copy in general, but you likely want to know about the specific differences in vtkImageData. In particular, this part of the VTK documentation indicates that the deep copy copies pipeline connections that are not copied in the shallow copy. Perhaps the VTK discourse would be a good place for this question.

2 Likes

The wiki page describes this well. In practice, ShallowCopy can be much faster for large data sets, but you need to be very careful when you use it, as data sharing with the source node may have unintended side effects. Most often ShallowCopy is used with a source object that gets deleted soon after the copy.