<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Rane,<br>
    glad it was of help. <br>
    Firstly, please always write into the vtkusers maillist. You can cc
    me if I had responded before, but make sure the email gets public,
    so that people who might encounter a similar issue will be able to
    find the answer. <br>
    <br>
    On to your question: the output of <tt> vtkWindowToImageFilter is </tt>vtkImageData,
    as you can tell from the name. So you can access the pixel values by
    means of GetScalarPointer() method of vtkImageData. You want to cast
    it (it is void*) to whatever type of scalars is the vtkImageData.<br>
    Here is a sample code snippet. <br>
    <tt><br>
    </tt><tt>&nbsp; vtkImageData * screen = w2i-&gt;GetOutput();</tt><tt><br>
    </tt><tt>&nbsp; cout &lt;&lt; " scalar type of w2i output: " &lt;&lt;
      screen-&gt;GetScalarTypeAsString() &lt;&lt; endl;&nbsp; // this is what
      I want to cast the pointer to</tt><tt><br>
    </tt><tt>&nbsp; cout &lt;&lt; "&nbsp; num of components: "&nbsp; &lt;&lt;
      screen-&gt;GetNumberOfScalarComponents () &lt;&lt;&nbsp; </tt><tt>endl;
      // == 4, i.e. RGBA</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp; cout &lt;&lt; " extent: " &lt;&lt;
      screen-&gt;GetExtent()[0] &lt;&lt; " " &lt;&lt;
      screen-&gt;GetExtent()[1] &lt;&lt; " " &lt;&lt;
      screen-&gt;GetExtent()[2] &lt;&lt; " " &lt;&lt;
      screen-&gt;GetExtent()[3] &lt;&lt; " " &lt;&lt;
      screen-&gt;GetExtent()[4] &lt;&lt; " " &lt;&lt;
      screen-&gt;GetExtent()[5] &lt;&lt; endl;</tt><tt><br>
    </tt><tt><br>
    </tt><tt>&nbsp; int i = 230, j= 230;</tt><tt><br>
    </tt><tt>&nbsp; unsigned char * ptr = static_cast&lt;unsigned char
      *&gt;(screen-&gt;GetScalarPointer(i, j, 0));&nbsp; </tt><tt><br>
    </tt><tt>&nbsp; cout &lt;&lt; " value of pixel (" &lt;&lt; i &lt;&lt; ",
      " &lt;&lt; j &lt;&lt; "): R="&lt;&lt; (int)*ptr &lt;&lt; " G="
      &lt;&lt; (int)*(ptr+1) &lt;&lt; " B=" &lt;&lt; (int)*(ptr+2)
      &lt;&lt; " "A=" &lt;&lt; (int)*(ptr+3) &lt;&lt; endl;</tt><tt><br>
    </tt><tt>&nbsp; </tt><br>
    HTH, <br>
    Miro<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 11/18/2013 10:18 AM, R R wrote:<br>
    </div>
    <blockquote
      cite="mid:1384798698.56668.YahooMailNeo@web162801.mail.bf1.yahoo.com"
      type="cite">
      <div style="color:#000; background-color:#fff;
        font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial,
        Lucida Grande, sans-serif;font-size:12pt">Hi Miro,<br>
        <br>
        Thanks so much for your great information and sample code.<span>It
          solved my problem!<br>
          <br>
          I have another question. Would you please let me know is there
          any way that instead of writing image (rendered 2D image) on
          disk, we can save it to an array (m*m) and have access to each
          pixel of the image? What I'm trying to say is that, I need to
          have access to pixels of the rendered image. What I do now, is
          that I save it on disk and then read it to a int array and
          work with the pixel values. I want to skip writing on disk and
          directly have access to the pixels of the rendered image.<br>
        </span>
        <div style="color: rgb(0, 0, 0); font-size: 16px; font-family:
          HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
          Grande,sans-serif; background-color: transparent; font-style:
          normal;"><br>
          <span></span></div>
        <div style="color: rgb(0, 0, 0); font-size: 16px; font-family:
          HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
          Grande,sans-serif; background-color: transparent; font-style:
          normal;"><span>I really appreciate your help.<br>
          </span></div>
        <div style="color: rgb(0, 0, 0); font-size: 16px; font-family:
          HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
          Grande,sans-serif; background-color: transparent; font-style:
          normal;"><span><br>
          </span></div>
        <div style="color: rgb(0, 0, 0); font-size: 16px; font-family:
          HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
          Grande,sans-serif; background-color: transparent; font-style:
          normal;"><span>Thanks,</span></div>
        <div style="color: rgb(0, 0, 0); font-size: 16px; font-family:
          HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
          Grande,sans-serif; background-color: transparent; font-style:
          normal;"><span>Rane<br>
          </span></div>
        <div style="display: block;" class="yahoo_quoted"> <br>
          <br>
          <div style="font-family: HelveticaNeue, Helvetica Neue,
            Helvetica, Arial, Lucida Grande, sans-serif; font-size:
            12pt;">
            <div style="font-family: HelveticaNeue, Helvetica Neue,
              Helvetica, Arial, Lucida Grande, sans-serif; font-size:
              12pt;">
              <div dir="ltr"> <font face="Arial" size="2"> On Friday,
                  November 8, 2013 12:56 PM, Miro Drahos
                  <a class="moz-txt-link-rfc2396E" href="mailto:mdrahos@robodoc.com">&lt;mdrahos@robodoc.com&gt;</a> wrote:<br>
                </font> </div>
              <div class="y_msg_container">
                <div id="yiv9175762545">
                  <div> I don't know what is .pgm format, but for any
                    image you could just use vtkWindowToImageFilter,
                    pass your renderwindow to it as input, and then use
                    the writer with it, e.g.:<br clear="none">
                    <tt><br clear="none">
                    </tt><tt>void savePNG(const char * filename,
                      vtkRenderWindow * rw)</tt><tt><br clear="none">
                    </tt><tt>{</tt><tt><br clear="none">
                    </tt><tt>&nbsp; vtkWindowToImageFilter * w2i =
                      vtkWindowToImageFilter::New();</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp; w2i-&gt;SetInput(rw);&nbsp;&nbsp; // rw is
                      vtkRenderWindow that you are painting into</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp; w2i-&gt;SetInputBufferTypeToRGBA();</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp; w2i-&gt;Update();</tt><tt><br
                        clear="none">
                    </tt><tt><br clear="none">
                    </tt><tt>&nbsp; vtkPNGWriter *writer =
                      vtkPNGWriter::New();</tt><tt><br clear="none">
                    </tt><tt>&nbsp;
                      writer-&gt;SetInputConnection(w2i-&gt;GetOutputPort());</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp; writer-&gt;SetFileName(filename);</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp;&nbsp;&nbsp; </tt><tt><br clear="none">
                    </tt><tt>&nbsp; rw-&gt;SetSize(800, 800);</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp; rw-&gt;Render();</tt><tt><br clear="none">
                    </tt><tt>&nbsp; writer-&gt;Write();</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp;&nbsp;&nbsp; </tt><tt><br clear="none">
                    </tt><tt>&nbsp; w2i-&gt;Delete();</tt><tt><br
                        clear="none">
                    </tt><tt>&nbsp; writer-&gt;Delete();</tt><tt><br
                        clear="none">
                    </tt><tt>}</tt><tt><br clear="none">
                    </tt><tt><br clear="none">
                    </tt>Cheers,<br clear="none">
                    Miro<br clear="none">
                    <br clear="none">
                    <br clear="none">
                    <div class="yiv9175762545yqt3666738621"
                      id="yiv9175762545yqt54972">
                      <div class="yiv9175762545moz-cite-prefix">On
                        11/05/2013 09:31 PM, R R wrote:<br clear="none">
                      </div>
                      <blockquote type="cite">
                        <div
                          style="color:#000;background-color:#fff;font-family:HelveticaNeue,
                          Helvetica Neue, Helvetica, Arial, Lucida
                          Grande, sans-serif;font-size:12pt;">
                          <div>Hello all,</div>
                          <div><br clear="none">
                          </div>
                          <div style="color:rgb(0, 0,
                            0);font-size:16px;font-family:HelveticaNeue,
                            Helvetica Neue, Helvetica, Arial, Lucida
                            Grande,
                            sans-serif;background-color:transparent;font-style:normal;">I
                            have a question about how we can save the
                            result of volume rendering in .pgm format. I
                            mean I have a volume from which a 2D image
                            is created using raycasting and is shown on
                            the screen. I want to save this 2D image in
                            a .pgm file. Could any body please give me
                            some hint how I can do that.</div>
                          <div style="color:rgb(0, 0,
                            0);font-size:16px;font-family:HelveticaNeue,
                            Helvetica Neue, Helvetica, Arial, Lucida
                            Grande,
                            sans-serif;background-color:transparent;font-style:normal;"><br
                              clear="none">
                          </div>
                          <div style="color:rgb(0, 0,
                            0);font-size:16px;font-family:HelveticaNeue,
                            Helvetica Neue, Helvetica, Arial, Lucida
                            Grande,
                            sans-serif;background-color:transparent;font-style:normal;">Thanks
                            so much.</div>
                          <div style="color:rgb(0, 0,
                            0);font-size:16px;font-family:HelveticaNeue,
                            Helvetica Neue, Helvetica, Arial, Lucida
                            Grande,
                            sans-serif;background-color:transparent;font-style:normal;"><br
                              clear="none">
                          </div>
                          <div style="color:rgb(0, 0,
                            0);font-size:16px;font-family:HelveticaNeue,
                            Helvetica Neue, Helvetica, Arial, Lucida
                            Grande,
                            sans-serif;background-color:transparent;font-style:normal;">Regards,</div>
                          <div style="color:rgb(0, 0,
                            0);font-size:16px;font-family:HelveticaNeue,
                            Helvetica Neue, Helvetica, Arial, Lucida
                            Grande,
                            sans-serif;background-color:transparent;font-style:normal;">Rane</div>
                        </div>
                      </blockquote>
                    </div>
                    <br clear="none">
                  </div>
                </div>
                <br>
                <br>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>