Mike - Yes it does, thanks! <br><br>Quoting David G. - <br>"The "ShallowCopy" method does not mean quite the same thing for<br>
vtkDataSet as it does for vtkCell. What I mean to say in C++ speak<br>
is: vtkCell and vtkDataSet do not share a common base class that<br>
defines a "ShallowCopy" method. Each has its own particular<br>
definition of ShallowCopy."<br><br>You point exactly what I was surprised about: Because I thought <br>that Copy are important things, I looked for a virtual function in<br>vtkObject - possibly pure -, the one that is shared by every object.<br>
(I voluntary omit vtkObjectBase). It means that it is possible to <br>create VTK objects that don't implement a Copy mechanism. <br><br>This is the case for vtkDataObject: There is no Copy functions. <br>However, a vtkExecutive is associated to a vtkDataObject. It<br>
means that generic filters working on vtkDataObject cannot <br>perform Shallow/DeepCopy. I don't know if I am clear enough...<br><br>Is there a reason to forbid 'abstract' copy (ie without knowing<br>the exact implementation)?<br>
<br>Jerome<br><br><br><div class="gmail_quote">2009/12/15 Michael Jackson <span dir="ltr"><<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
// Produce a 'Read Only' copy to be used as Input<br>
inputCopy->ShallowCopy(input);<br>
// Add the Input to the 'internal' pipeline<br>
blend->AddInput(inputCopy);<br>
// Update the 'internal' pipeline<br>
blend->Update();<br>
<br>
/* Now, blend produced an entirely brand new 'output' object after the<br>
* update method was called. The 'input' to the blend filter should have<br>
* never been modified by the blend filter. Because the output is a brand<br>
* new object you do not need to deep copy it.<br>
*/<br>
output->DeepCopy(blend->GetOutput());<br>
/* If you want to 'save' the output for use later you might want to<br>
* call 'output->Register(NULL);' which will increase the reference<br>
* count of the object so when the 'blend' filter goes out of scope<br>
* and is destroyed the pointer that represents 'output' will NOT be<br>
* deleted. Another way to accomplish the same goal would be to again<br>
* shallow copy the output into another variable.<br>
*/<br>
<br>
Basically the difference between a shallow copy and a deep copy is this.<br>
The Shallow copy only makes a copy of the pointer to each of the internal<br>
data structures and increases the reference count on each of those objects.<br>
So on a 32 bit system you are copying a single 32 bit value (which happens<br>
to be a pointer) into a new location. Thus you may have 2 objects (input and<br>
inputcopy) BUT they share the same exact data structures internally. So changing<br>
the data in one will effect the other.<br>
A deep copy will make a copy of the actual DATA that the pointer points to. Thus you<br>
end up with 2 versions of the data. One in "input" and one in "inputcopy". Changing<br>
the data in one of those will NOT effect the other object.<br>
<br>
To use an abstract example. If you have a vtk object that wraps 1 GigaByte of data and perform<br>
a shallow copy then your memory requirements only go up maybe 100 bytes (all the<br>
overhead of the vtk object) or so. If you do a DEEP copy then your memory requirements<br>
jumps from 1 GigaByte to 2 Gigabytes because all the actual data is copied.<br>
<br>
Does that help?<div class="im"><br>
_________________________________________________________<br>
Mike Jackson <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>
<br></div><div><div></div><div class="h5">
On Dec 15, 2009, at 12:13 PM, Jérôme wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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!<br>
<br>
This made me look at the documentation of ShallowCopy/DeepCopy. Finally, I found this class:<br>
<a href="http://www.vtk.org/doc/nightly/html/classvtkCell.html#a573202e8c9c3b5367b35fe7ad3fdfb43" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkCell.html#a573202e8c9c3b5367b35fe7ad3fdfb43</a><br>
<br>
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!<br>
<br>
Do I mistake if I rather propose:<br>
inputCopy->ShallowCopy(input);<br>
blend->AddInput(inputCopy);<br>
blend->Update();<br>
output->DeepCopy(blend->GetOutput());<br>
<br>
Jerome<br>
<br>
2009/12/15 Michael Jackson <<a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a>><br>
<br>
<br>
On Dec 15, 2009, at 11:53 AM, Bill Lorensen wrote:<br>
<br>
After seeing Berk's reply it looks as though his<br>
vtkImageData* inputCopy = input->NewInstance();<br>
inputCopy->ShallowCopy(input);<br>
blend->AddInput(inputCopy);<br>
blend->Update();<br>
output->ShallowCopy(blend->GetOutput());<br>
<br>
would be:<br>
<br>
blend->AddInput(input);<br>
blend->Update()<br>
this->GraftOutput(blend->GetOutput());<br>
<br>
Bill,<br>
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.<br>
<br>
Maybe what is needed is this:<br>
<br>
/* Get a Shallow copy from the input */<br>
vtkImageData* inputCopy = input->NewShallowCopyInstance();<br>
<br>
blend->AddInput(inputCopy);<br>
blend->Update();<br>
output->ShallowCopy(blend->GetOutput());<br>
/* Don't Forget to memory clean up somewhere.*/<br>
<br>
_________________________________________________________<br>
Mike Jackson <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>
BlueQuartz Software <a href="http://www.bluequartz.net" target="_blank">www.bluequartz.net</a><br>
Principal Software Engineer Dayton, Ohio<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br>