<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> vtkImageData * screen = w2i->GetOutput();</tt><tt><br>
</tt><tt> cout << " scalar type of w2i output: " <<
screen->GetScalarTypeAsString() << endl; // this is what
I want to cast the pointer to</tt><tt><br>
</tt><tt> cout << " num of components: " <<
screen->GetNumberOfScalarComponents () << </tt><tt>endl;
// == 4, i.e. RGBA</tt><tt><br>
</tt><tt><br>
</tt><tt> cout << " extent: " <<
screen->GetExtent()[0] << " " <<
screen->GetExtent()[1] << " " <<
screen->GetExtent()[2] << " " <<
screen->GetExtent()[3] << " " <<
screen->GetExtent()[4] << " " <<
screen->GetExtent()[5] << endl;</tt><tt><br>
</tt><tt><br>
</tt><tt> int i = 230, j= 230;</tt><tt><br>
</tt><tt> unsigned char * ptr = static_cast<unsigned char
*>(screen->GetScalarPointer(i, j, 0)); </tt><tt><br>
</tt><tt> cout << " value of pixel (" << i << ",
" << j << "): R="<< (int)*ptr << " G="
<< (int)*(ptr+1) << " B=" << (int)*(ptr+2)
<< " "A=" << (int)*(ptr+3) << endl;</tt><tt><br>
</tt><tt> </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"><mdrahos@robodoc.com></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> vtkWindowToImageFilter * w2i =
vtkWindowToImageFilter::New();</tt><tt><br
clear="none">
</tt><tt> w2i->SetInput(rw); // rw is
vtkRenderWindow that you are painting into</tt><tt><br
clear="none">
</tt><tt> w2i->SetInputBufferTypeToRGBA();</tt><tt><br
clear="none">
</tt><tt> w2i->Update();</tt><tt><br
clear="none">
</tt><tt><br clear="none">
</tt><tt> vtkPNGWriter *writer =
vtkPNGWriter::New();</tt><tt><br clear="none">
</tt><tt>
writer->SetInputConnection(w2i->GetOutputPort());</tt><tt><br
clear="none">
</tt><tt> writer->SetFileName(filename);</tt><tt><br
clear="none">
</tt><tt> </tt><tt><br clear="none">
</tt><tt> rw->SetSize(800, 800);</tt><tt><br
clear="none">
</tt><tt> rw->Render();</tt><tt><br clear="none">
</tt><tt> writer->Write();</tt><tt><br
clear="none">
</tt><tt> </tt><tt><br clear="none">
</tt><tt> w2i->Delete();</tt><tt><br
clear="none">
</tt><tt> writer->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>