<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">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">&nbsp;&nbsp;&nbsp;
          vtkSmartPointer&lt;vtkReader1&gt; Reader1 =
          vtkSmartPointer&lt;vtkReader1&gt;::New()</font><br>
        <font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; // set filename
          and update reader1</font><br>
        <font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; vtkDataSet *
          MyDataSet = Reader1-&gt;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">&nbsp;&nbsp;&nbsp;
          vtkSmartPointer&lt;vtkReader2&gt; Reader2 =
          vtkSmartPointer&lt;vtkReader1&gt;::New()</font><br>
        <font face="Courier New, Courier, monospace">
          &nbsp;&nbsp;&nbsp; // set filename and update reader2</font><br>
        <font face="Courier New, Courier, monospace">
          &nbsp;&nbsp;&nbsp; vtkDataSet * MyDataSet = Reader2-&gt;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<br>
      <br>
      <br>
      On 04/29/2013 08:20 AM, Berk Geveci wrote:<br>
    </div>
    <blockquote
cite="mid:CAE32kpXefk-4_98s6oNaqFwZqoCveWJ4JBK0A8_YrLMbqQybYQ@mail.gmail.com"
      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 style="font-family:'Courier
            New',Courier,monospace;font-size:13px">outputInfo-&gt;Set(</span><span
            style="font-family:'Courier
            New',Courier,monospace;font-size:13px">vtkDataObject::DATA_OBJECT(),</span><span
            style="font-family:'Courier
            New',Courier,monospace;font-size:13px">MyDataSet);</span><br>
        </div>
        <div><span style="font-family:'Courier
            New',Courier,monospace;font-size:13px"><br>
          </span></div>
        <div style=""><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 style=""><font face="arial, helvetica, sans-serif"><br>
          </font></div>
        <div style=""><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">&lt;<a moz-do-not-send="true"
              href="mailto:helios.corona@gmail.com" target="_blank">helios.corona@gmail.com</a>&gt;</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>
                &nbsp;&nbsp; &nbsp;vtkSmartPointer&lt;vtkSomeReader&gt; myreader =
                vtkSmartPointer&lt;vtkSomeReader&gt;::New();<br>
                &nbsp;&nbsp; &nbsp;...<br>
                &nbsp;&nbsp;&nbsp; vtkDataSet *MyDataSet = Reader-&gt;GetOutput();<br>
                &nbsp;&nbsp;
                &nbsp;outputInfo-&gt;Set(vtkDataObject::DATA_OBJECT(),MyDataSet);<br>
                &nbsp;&nbsp;&nbsp; ...<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>
                &nbsp;&nbsp; &nbsp;...<br>
                &nbsp;&nbsp; &nbsp;... inputInfo-&gt;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 moz-do-not-send="true"
              href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
            <br>
            Visit other Kitware open-source projects at <a
              moz-do-not-send="true"
              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
              moz-do-not-send="true"
              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 moz-do-not-send="true"
              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>
  </body>
</html>