[vtkusers] How to get the input to a filter as algorithm output?

Jérôme jerome.velut at gmail.com
Tue Dec 15 14:46:19 EST 2009


Mike - Yes it does, thanks!

Quoting David G. -
"The "ShallowCopy" method does not mean quite the same thing for
vtkDataSet as it does for vtkCell.  What I mean to say in C++ speak
is: vtkCell and vtkDataSet do not share a common base class that
defines a "ShallowCopy" method.  Each has its own particular
definition of ShallowCopy."

You point exactly what I was surprised about: Because I thought
that Copy are important things, I looked for a virtual function in
vtkObject - possibly pure -, the one that is shared by every object.
(I voluntary omit vtkObjectBase). It means that it is possible to
create VTK objects that don't implement a Copy mechanism.

This is the case for vtkDataObject: There is no Copy functions.
However, a vtkExecutive is associated to a vtkDataObject. It
means that generic filters working on vtkDataObject cannot
perform Shallow/DeepCopy. I don't know if I am clear enough...

Is there a reason to forbid 'abstract' copy (ie without knowing
the exact implementation)?

Jerome


2009/12/15 Michael Jackson <mike.jackson at bluequartz.net>

> // Produce a 'Read Only' copy to be used as Input
> inputCopy->ShallowCopy(input);
> // Add the Input to the 'internal' pipeline
> blend->AddInput(inputCopy);
> // Update the 'internal' pipeline
> blend->Update();
>
> /* Now, blend produced an entirely brand new 'output' object after the
> * update method was called. The 'input' to the blend filter should have
> * never been modified by the blend filter. Because the output is a brand
> * new object you do not need to deep copy it.
> */
> output->DeepCopy(blend->GetOutput());
> /* If you want to 'save' the output for use later you might want to
> * call 'output->Register(NULL);' which will increase the reference
> * count of the object so when the 'blend' filter goes out of scope
> * and is destroyed the pointer that represents 'output' will NOT be
> * deleted. Another way to accomplish the same goal would be to again
> * shallow copy the output into another variable.
> */
>
> Basically the difference between a shallow copy and a deep copy is this.
> The Shallow copy only makes a copy of the pointer to each of the internal
> data structures and increases the reference count on each of those objects.
> So on a 32 bit system you are copying a single 32 bit value (which happens
> to be a pointer) into a new location. Thus you may have 2 objects (input
> and
> inputcopy) BUT they share the same exact data structures internally. So
> changing
> the data in one will effect the other.
>  A deep copy will make a copy of the actual DATA that the pointer points
> to. Thus you
> end up with 2 versions of the data. One in "input" and one in "inputcopy".
> Changing
> the data in one of those will NOT effect the other object.
>
>  To use an abstract example. If you have a vtk object that wraps 1 GigaByte
> of data and perform
> a shallow copy then your memory requirements only go up maybe 100 bytes
> (all the
> overhead of the vtk object) or so. If you do a DEEP copy then your memory
> requirements
> jumps from 1 GigaByte to 2 Gigabytes because all the actual data is copied.
>
>  Does that help?
>
> _________________________________________________________
> Mike Jackson                  mike.jackson at bluequartz.net
>
> On Dec 15, 2009, at 12:13 PM, Jérôme wrote:
>
>  Oops... it seems that I understand now some weird "bad extent"
>> happening... I will keep this thread bookmarked, since it teaches a lot
>> about VTK pipelining!
>>
>> This made me look at the documentation of ShallowCopy/DeepCopy. Finally, I
>> found this class:
>>
>> http://www.vtk.org/doc/nightly/html/classvtkCell.html#a573202e8c9c3b5367b35fe7ad3fdfb43
>>
>> where it is said that ShallowCopy is for read-only copy... Is the code
>> snippet right? ShallowCopying the output of the internal filter should then
>> produce a read-only output for the main filter!
>>
>> Do I mistake if I rather propose:
>> inputCopy->ShallowCopy(input);
>> blend->AddInput(inputCopy);
>> blend->Update();
>> output->DeepCopy(blend->GetOutput());
>>
>> Jerome
>>
>> 2009/12/15 Michael Jackson <mike.jackson at bluequartz.net>
>>
>>
>> On Dec 15, 2009, at 11:53 AM, Bill Lorensen wrote:
>>
>> After seeing Berk's reply it looks as though his
>> vtkImageData* inputCopy = input->NewInstance();
>> inputCopy->ShallowCopy(input);
>> blend->AddInput(inputCopy);
>> blend->Update();
>> output->ShallowCopy(blend->GetOutput());
>>
>> would be:
>>
>> blend->AddInput(input);
>> blend->Update()
>> this->GraftOutput(blend->GetOutput());
>>
>> Bill,
>>  As, Berk explained, you _really_ need to have a shallow copy to decouple
>> the internal and external pipelines. If this is not done the all sorts of
>> "Bad" will happen.
>>
>>  Maybe what is needed is this:
>>
>> /* Get a Shallow copy from the input */
>> vtkImageData* inputCopy = input->NewShallowCopyInstance();
>>
>> blend->AddInput(inputCopy);
>> blend->Update();
>> output->ShallowCopy(blend->GetOutput());
>> /* Don't Forget to memory clean up somewhere.*/
>>
>> _________________________________________________________
>> Mike Jackson                  mike.jackson at bluequartz.net
>> BlueQuartz Software                    www.bluequartz.net
>> Principal Software Engineer                  Dayton, Ohio
>>
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091215/4bc2af45/attachment.htm>


More information about the vtkusers mailing list