<div dir="ltr">If you want the output of an algorithm to stick around after deleting it, you need to call Register() on the data object. Something like:<div><br></div><div><font face="Courier New, Courier, monospace" style="font-size:13px"> vtkSmartPointer<vtkReader1> Reader1 = vtkSmartPointer<vtkReader1>::New()</font><br style="font-family:arial,sans-serif;font-size:13px">
<font face="Courier New, Courier, monospace" style="font-size:13px"> // set filename and update reader1</font><br style="font-family:arial,sans-serif;font-size:13px"><font face="Courier New, Courier, monospace" style="font-size:13px"> vtkDataSet * MyDataSet = Reader1->GetOutput();</font><br style="font-family:arial,sans-serif;font-size:13px">
</div><div style><font face="Courier New, Courier, monospace" style="font-size:13px"> MyDataSet->Register(0);</font></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 5:14 PM, Sunrise <span dir="ltr"><<a href="mailto:helios.corona@gmail.com" target="_blank">helios.corona@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>Thanks for the answer, Berk.<br>
<br>
I have a follow up question, which I guess I can solve it with
strong pointers. Assume the following<br>
<br>
<font face="Courier New, Courier, monospace">vtkDataSet *
MyFilter::GetMyDataSet(...)<br>
{<br>
</font>
<blockquote><font face="Courier New, Courier, monospace">if(SomeConditions)</font><br>
<font face="Courier New, Courier, monospace">{</font><br>
<font face="Courier New, Courier, monospace">
vtkSmartPointer<vtkReader1> Reader1 =
vtkSmartPointer<vtkReader1>::New()</font><br>
<font face="Courier New, Courier, monospace"> // set filename
and update reader1</font><br>
<font face="Courier New, Courier, monospace"> vtkDataSet *
MyDataSet = Reader1->GetOutput();</font><br>
<font face="Courier New, Courier, monospace">}</font><br>
<font face="Courier New, Courier, monospace">else</font><br>
<font face="Courier New, Courier, monospace">{</font><br>
<font face="Courier New, Courier, monospace">
vtkSmartPointer<vtkReader2> Reader2 =
vtkSmartPointer<vtkReader1>::New()</font><br>
<font face="Courier New, Courier, monospace">
// set filename and update reader2</font><br>
<font face="Courier New, Courier, monospace">
vtkDataSet * MyDataSet = Reader2->GetOutput();</font><br>
<font face="Courier New, Courier, monospace">}</font><br>
<br>
<font face="Courier New, Courier, monospace">// MyDataSet is out
of scope here!<br>
// Even if I remove if condition, they will be out of scope
outside of this function.<br>
<br>
return MyDataSet;<br>
</font></blockquote>
<font face="Courier New, Courier, monospace">}<br>
</font><br>
I want to make both <font face="Courier New, Courier, monospace">reader1</font>
and <font face="Courier New, Courier, monospace">reader2</font>
become SmartPointers. Otherwise I have leak. At compile time I do
not know how the code will end, only at the run time it make the
decision. So I do not know when to delete <font face="Courier
New, Courier, monospace">reader1</font> and <font face="Courier
New, Courier, monospace">reader2</font>.<br>
<br>
I do not want to use descrutor too. there are more readers than
the sample code that I put here, so at compile time the destructor
do not know how many <font face="Courier New, Courier, monospace">reader1</font>
and/or <font face="Courier New, Courier, monospace">reader2</font>
has been declared in order to delete them manually. So, I prefer
to declare all of them with Smart Pointers.<br>
<br>
But here is the problem: <font face="Courier New, Courier,
monospace">reader1</font> and <font face="Courier New, Courier,
monospace">reade2</font> are in clauses of If condition, and
they are in a function outside of RequestData. So they will go out
of scope.<br>
<br>
If using a strong pointer fix this problem, how can I apply a
strong pointer on <font face="Courier New, Courier, monospace">MyDataSet</font>
in VTK?<br>
<br>
Again, thank you very much.<br>
<br>
-Sia<div><div class="h5"><br>
<br>
<br>
On 04/29/2013 08:20 AM, Berk Geveci wrote:<br>
</div></div></div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr">It does a shallow copy. The information object
holds a strong reference to the data object so
<div><br>
</div>
<div><span>outputInfo->Set(</span><span>vtkDataObject::DATA_OBJECT(),</span><span>MyDataSet);</span><br>
</div>
<div><span><br>
</span></div>
<div><font face="arial, helvetica, sans-serif">so it
will increment the reference count of MyDataSet preventing
it from going out of scope.</font></div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
<div><font face="arial, helvetica, sans-serif">-berk</font></div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Sun, Apr 28, 2013 at 11:41 AM,
Sunrise <span dir="ltr"><<a href="mailto:helios.corona@gmail.com" target="_blank">helios.corona@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> I am wondering if the
"<font face="Courier New, Courier, monospace">Set</font>"
method in <font face="Courier New, Courier, monospace">vtkInformation</font>
class performs a deep-copy or shallow-copy when I set a <font face="Courier New, Courier, monospace">DATA_OBJECT</font>
into it?<br>
<br>
Suppose I have some <font face="Courier New, Courier,
monospace">vtkDataSet</font> and I want to append them
into <font face="Courier New, Courier, monospace">outputInfo</font>
of a filter inside its <font face="Courier New, Courier,
monospace">RequestData</font> method. <br>
<br>
<font face="Courier New, Courier, monospace">int
Filter1::RequestData(...)<br>
{<br>
vtkSmartPointer<vtkSomeReader> myreader =
vtkSmartPointer<vtkSomeReader>::New();<br>
...<br>
vtkDataSet *MyDataSet = Reader->GetOutput();<br>
outputInfo->Set(vtkDataObject::DATA_OBJECT(),MyDataSet);<br>
...<br>
}</font><br>
<br>
at the end of <font face="Courier New, Courier,
monospace">RequestData</font>, both the pointer <font face="Courier New, Courier, monospace">myreader</font>
and its data on the heap would be out of scope. Since I
made them smart pointers, both pointer "myreader" and the
data on the heap will be deleted (right?).<br>
<br>
But in the next filter of the pipeline (say Filter2 is
connected to Filter1), I can receive the data in <font face="Courier New, Courier, monospace">inputInfo</font><br>
<br>
<font face="Courier New, Courier, monospace">int
Filter2::RequestData(...)<br>
{<br>
...<br>
... inputInfo->Get(vtkDataObject::DATA_OBJECT());<br>
}</font><br>
<br>
I am wondering why still I can get the data, since data
deferenced by <font face="Courier New, Courier,
monospace">MyDataSet</font> in previous filter no longer
exists?<br>
<br>
Does <font face="Courier New, Courier, monospace">vtkInformation::Set</font>
perform a deep copy?<br>
<br>
Thank you.<br>
</div>
<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>
</div>
<br>
</div>
</blockquote>
<br>
</div></div></div>
<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></div><br></div>