<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">On 01.05.2013 16:50, Berk Geveci wrote:<br>
    </div>
    <blockquote
cite="mid:CAE32kpV9z0sU+2rZGLZw3J3vMpNvko4GyDJqQVnXFfy-SkDVZw@mail.gmail.com"
      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">&nbsp; &nbsp; 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">&nbsp;&nbsp;&nbsp; // 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">&nbsp;&nbsp;&nbsp; vtkDataSet * MyDataSet =
            Reader1-&gt;GetOutput();</font><br
            style="font-family:arial,sans-serif;font-size:13px">
        </div>
        <div style=""><font style="font-size:13px" face="Courier New,
            Courier, monospace">&nbsp; &nbsp; MyDataSet-&gt;Register(0);</font></div>
      </div>
      <div class="gmail_extra"><br>
        <br>
      </div>
    </blockquote>
    <br>
    Yes, but wouldn't you have to delete MyDataSet manually?<br>
    Why not using SmartPointers also for MyDataSet? From what I
    understand after reading
    <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers">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>
    &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkDataSet&gt; MyDataSet;<br>
    <br>
    &nbsp;&nbsp;&nbsp; if(SomeConditions)<br>
    &nbsp;&nbsp;&nbsp; {<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkReader1&gt; Reader1 =
    vtkSmartPointer&lt;vtkReader1&gt;::New()<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // set filename and update reader1<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyDataSet = Reader1-&gt;GetOutput();<br>
    &nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp; else<br>
    &nbsp;&nbsp;&nbsp; {<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkReader2&gt; Reader2 =
    vtkSmartPointer&lt;vtkReader1&gt;::New()<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // set filename and update reader2<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyDataSet = Reader2-&gt;GetOutput();<br>
    &nbsp;&nbsp;&nbsp; }<br>
    <br>
    &nbsp;&nbsp;&nbsp; return MyDataSet;<br>
    }<br>
    <br>
    vtkSmartPointer&lt;vtkDataSet&gt; MyDataSet = GetMyDataSet( ... );<br>
    <br>
    <br>
    Or did I miss something?<br>
    <br>
    Regards,<br>
    Dominique<br>
    <br>
    <br>
    <blockquote
cite="mid:CAE32kpV9z0sU+2rZGLZw3J3vMpNvko4GyDJqQVnXFfy-SkDVZw@mail.gmail.com"
      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 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">
              <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">&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
                <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-&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
                            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>
                </div>
              </div>
            </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>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>

Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the VTK FAQ at: <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Dominique T&ouml;pfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen</pre>
  </body>
</html>