<div dir="ltr">I concur with Alex.<div><br></div><div>-berk</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 1, 2013 at 5:56 PM, Alex Malyushytskyy <span dir="ltr">&lt;<a href="mailto:alexmalvtk@gmail.com" target="_blank">alexmalvtk@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 dir="ltr"><div><div>The code with smartpointer should also work.<br>Assignment to smart pointer will increase the counter. <br>

</div><div>So output will not be deleted when filter goes out of scope.<br></div><div><br>
( <a href="http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers" target="_blank">http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers</a> )<br><br></div>But if you look in VTK api you would not find public functions which return  or pass smartpointer.<br>


</div><div>I think for a reason to avoid duplication of similar function. Returning pointer is minimal and sufficient. <br></div><div><br></div>So people (at least me) are avoiding it, especially if you write piece of code which later could be considered to be included in vtk.<br>


<div><div><br></div><div>Regards,<br></div><div>    Alex<br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 1, 2013 at 9:32 AM, Dominique Töpfer <span dir="ltr">&lt;<a href="mailto:dominique@toepfer-web.de" target="_blank">dominique@toepfer-web.de</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"><div>
    <div>On 01.05.2013 16:50, Berk Geveci wrote:<br>
    </div>
    <blockquote type="cite">
      <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 style="font-size:13px" face="Courier New, Courier,
            monospace">    vtkSmartPointer&lt;vtkReader1&gt; Reader1 =
            vtkSmartPointer&lt;vtkReader1&gt;::New()</font><br style="font-family:arial,sans-serif;font-size:13px">
          <font style="font-size:13px" face="Courier New, Courier,
            monospace">    // set filename and update reader1</font><br style="font-family:arial,sans-serif;font-size:13px">
          <font style="font-size:13px" face="Courier New, Courier,
            monospace">    vtkDataSet * MyDataSet =
            Reader1-&gt;GetOutput();</font><br style="font-family:arial,sans-serif;font-size:13px">
        </div>
        <div><font style="font-size:13px" face="Courier New,
            Courier, monospace">    MyDataSet-&gt;Register(0);</font></div>
      </div>
      <div class="gmail_extra"><br>
        <br>
      </div>
    </blockquote>
    <br></div>
    Yes, but wouldn&#39;t you have to delete MyDataSet manually?<br>
    Why not using SmartPointers also for MyDataSet? From what I
    understand after reading
    <a href="http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers" target="_blank">http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers</a> , the following
    code should also work and memory is released automatically when the
    last pointer pointing to the data goes out of scope:<br>
    <br>
    vtkSmartPointer&lt;vtkDataSet&gt; MyFilter::GetMyDataSet( ... )<br>
    {<br>
        vtkSmartPointer&lt;vtkDataSet&gt; MyDataSet;<div><br>
    <br>
        if(SomeConditions)<br>
        {<br>
            vtkSmartPointer&lt;vtkReader1&gt; Reader1 =
    vtkSmartPointer&lt;vtkReader1&gt;::New()<br>
            // set filename and update reader1<br></div><div>
            MyDataSet = Reader1-&gt;GetOutput();<br>
        }<br>
        else<br>
        {<br>
            vtkSmartPointer&lt;vtkReader2&gt; Reader2 =
    vtkSmartPointer&lt;vtkReader1&gt;::New()<br>
            // set filename and update reader2<br></div>
            MyDataSet = Reader2-&gt;GetOutput();<br>
        }<br>
    <br>
        return MyDataSet;<br>
    }<br>
    <br>
    vtkSmartPointer&lt;vtkDataSet&gt; MyDataSet = GetMyDataSet( ... );<br>
    <br>
    <br>
    Or did I miss something?<br>
    <br>
    Regards,<br>
    Dominique<div><div><br>
    <br>
    <br>
    <blockquote type="cite">
      <div class="gmail_extra">
        <div class="gmail_quote">On Tue, Apr 30, 2013 at 5:14 PM,
          Sunrise <span dir="ltr">&lt;<a 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">
              <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&lt;vtkReader1&gt; Reader1 =
                    vtkSmartPointer&lt;vtkReader1&gt;::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-&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">   
                    vtkSmartPointer&lt;vtkReader2&gt; Reader2 =
                    vtkSmartPointer&lt;vtkReader1&gt;::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-&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
                <div>
                  <div><br>
                    <br>
                    <br>
                    On 04/29/2013 08:20 AM, Berk Geveci wrote:<br>
                  </div>
                </div>
              </div>
              <div>
                <div>
                  <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-&gt;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">&lt;<a 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 &quot;<font face="Courier New,
                              Courier, monospace">Set</font>&quot; 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&lt;vtkSomeReader&gt;
                              myreader =
                              vtkSmartPointer&lt;vtkSomeReader&gt;::New();<br>
                                  ...<br>
                                  vtkDataSet *MyDataSet =
                              Reader-&gt;GetOutput();<br>
                                
                               outputInfo-&gt;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 &quot;myreader&quot; 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-&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 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>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>

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>

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>

Follow this link to subscribe/unsubscribe:
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a>
</pre>
    </blockquote>
    <br>
    <br>
    </div></div><span><font color="#888888"><pre cols="72">-- 
Dominique Töpfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen</pre>
  </font></span></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>
</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>