[vtkusers] Difference between vtkSmartPointer assignment operator and ShallowCopy

Oleksandr Malyushytsky omalyushytskyvtkuser at gmail.com
Wed Oct 24 21:37:40 EDT 2018


Typical filter does not change the input.

vtkNew<vtkPolyData> polyData; // assume polydata reference count =1

{

    vtkNew<vtkTransformPolyDataFilter> transformFilter;
    transformFilter->SetInputData(polyData); // polyData reference
count is incremented = 2

    transformFilter->SetTransform(transformation);

    transformFilter->Update(); // filter produced new polydata with count 1

// at this point there are 2 polydata in the memory

}
// smartpointer deleted transformFilter

// output polydata is deleted since its reference count dropped to 0


// polyData reference count is incremented = 1


On Wed, Oct 24, 2018 at 5:46 PM Berti Krüger <berti_krueger at hotmail.com>
wrote:

> Thanks Oleksandr for the great answer.
>
> OK, i see, so when i use ShallowCopy, i copy the underlying structure of
> the vtk object e.g. attributes like the pointers the vtk object consists of
> without copying the content which the pointers point to.
>
> So for example by using a ShallowCopy on a vtkPolydata object i copy all
> the underlying pointers to things like vtkPointSet, vtkDataSet, Cells,
> Lines, Vertices, Points etc. which a vtkPolydata object is composed of but
> unlike using a DeepCopy not the actual content (vertices and stuff arrays)
> which these pointers point to.
>
> By using the vtkSmartPointer i get a reference counted pointer to the
> vtkObject without transfering the ownership of this object. It only
> increments the lease count by one and if the lease count becomes zero the
> destructor of the object is called.
>
>
>
> Just one question:
>
> Does every vtk filter copies the data it is given to?
>
> e.g.
>
> When using
>
>     vtkNew<vtkTransformPolyDataFilter> transformFilter;
>
>     transformFilter->SetInputData(polyData);
>
>     transformFilter->SetTransform(transformation);
>
>     transformFilter->Update();
>
>
>
> does the polyData exists twice in memory (the original polyData and the filter keeps its own transformed copy of the polyData)?
>
>
>
> Thanks and regards,
>
>
> Berti
>
>
>
> Am Do, 25. Okt, 2018 um 2:15 VORMITTAGS schrieb Oleksandr Malyushytsky <
> omalyushytskyvtkuser at gmail.com>:
>
> vtkSmartPointer has nothing to do with neither deep or shallow copy.
>
> if you assign vtk object to smartpointer the reference count of vtk object
> is incremented,
> there is only one vtkObject in the memory. Once smartpointer is released
> (going out of scope  for example) vtk object reference count  it was
> pointing is decremented.
> In another words vtkSmartPointer is like a normal pointer, which adds
> does reference couning.
>
> Operations with smartpointer DO NOT copy any data related to the object
> they point to.
>
>
> While deep and shalow copy are always performed with 2 different objects.
>
>
>
>
>
> On Wed, Oct 24, 2018 at 3:19 PM Berti Krüger <berti_krueger at hotmail.com>
> wrote:
>
>> Hello.
>>
>> I (hopefully) already understand the difference between the ShallowCopy
>> and the DeepCopy method (e.g. copying only the pointer vs. copying the
>> pointer and the content pointed to).
>>
>> But what i don't understand yet is, what is the difference between using
>> the overloaded assignment operator of vtkSmartPointer and the ShallowCopy
>> method, e.g. what is the difference between
>>
>>
>> vtkSmartPointer<vtkPolydata> myStrangePolydata =
>> vtkSmartPointer<vtkPolydata>::New();
>>
>>
>> myStrangePolydata = vtkTransmogrifyFilter->GetOutput();
>>
>>
>> and
>>
>>
>> myStangePolydata->ShallowCopy(vtkTransmogrifyFilter->GetOutput();
>>
>>
>>
>> Does it make a difference to the reference count of the vtkSmartPointer?
>>
>>
>> Thank you very much in advance.
>>
>>
>> Cheers,
>> Berti
>> _______________________________________________
>> 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 VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> https://public.kitware.com/mailman/listinfo/vtkusers
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181024/39cca47d/attachment.html>


More information about the vtkusers mailing list