You have to remember to reply to the vtk users board as well, don't direct the emails to just me.<br><br>How big is your render window, you're only sampling the first 1041 / 3 pixels there, and I wouldn't be surprised if they were all black. You should also verify that the image data is 3 component unsigned char. I would also make sure that your png actually contains something by just writing it to disk.<br>
<br>Mark<br><br><br><div class="gmail_quote">On Thu, Apr 24, 2008 at 1:15 PM, <<a href="mailto:yenanqu@scs.fsu.edu">yenanqu@scs.fsu.edu</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Here is my code:<br>
======================================<div class="Ih2E3d"><br>
renWin->Render();<br>
vtkWindowToImageFilter * w2i = vtkWindowToImageFilter::New();<br>
vtkPNGWriter * writer = vtkPNGWriter::New();<br>
w2i->SetInput( renWin );<br></div>
writer->SetInput( w2i->GetOutput() );<br>
w2i->Update();<br>
vtkImageData * id = w2i->GetOutput();<br>
id->Update();<br>
//int* siz = id->GetDimensions();<br>
//unsigned long ms = id->GetActualMemorySize();<br>
//int ms1 = id->GetScalarSize();<br>
unsigned char* pPix;<br>
pPix = (unsigned char*)id->GetScalarPointer();<br>
<br>
for(int ee=0;ee<1041;ee++){<br>
int pp = pPix[ee];<br>
cout<<" "<<pp;<br>
}<br>
===============================================<br>
The thing I can be sure is there is no problem with id (vtkImageData)<div><div></div><div class="Wj3C7c"><br>
<br>
Yenan<br>
<br>
<br>
<br>
Quoting Mark Wyszomierski <<a href="mailto:markww@gmail.com" target="_blank">markww@gmail.com</a>>:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Are you sure you actually set any of the RGB components in the first place?<br>
You could just be allocating the image array, all elements are set to zero,<br>
and you'll just get a zero for every element you access.<br>
<br>
Mark<br>
<br>
On Thu, Apr 24, 2008 at 12:49 PM, <<a href="mailto:yenanqu@scs.fsu.edu" target="_blank">yenanqu@scs.fsu.edu</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
when I do<br>
"unsigned char *pVtkPix = (unsigned char *)pImgData->GetScalarPointer();"<br>
it doesn't seem to get the scarlar pointer, I have already do all the<br>
update thing before this, and I also could get dimensions from pImgData. but<br>
when I output all the RGB value with your method, they are all 0.<br>
this stuff really kills me~~~<br>
<br>
<br>
Yenan<br>
<br>
<br>
Quoting Mark Wyszomierski <<a href="mailto:markww@gmail.com" target="_blank">markww@gmail.com</a>>:<br>
<br>
I think the RGB pixel data is usually allocated like:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
RGBRGBRGB etc....<br>
<br>
so you have numPixels * 3 actual elements in your image data array.<br>
<br>
You get a pixel pointer as usual and cast it to (unsigned char*):<br>
<br>
// Get a pointer to the actual pixel data.<br>
unsigned char *pVtkPix = (unsigned char *)pImgData->GetScalarPointer();<br>
<br>
// These are the r,g and b values for the first pixel:<br>
int rr = pVtkPix[0];<br>
int gg = pVtkPix[1];<br>
int bb = pVtkPix[2];<br>
<br>
// For the second pixel:<br>
rr = pVtkPix[3];<br>
gg = pVtkPix[4];<br>
bb = pVtkPix[5];<br>
<br>
and so on. Make sure you don't have RGBA data, if you do, then you just<br>
have<br>
an extra index per pixel which is the alpha component. Let me know if that<br>
helps,<br>
<br>
Mark<br>
<br>
<br>
On Wed, Apr 23, 2008 at 7:08 PM, <<a href="mailto:yenanqu@scs.fsu.edu" target="_blank">yenanqu@scs.fsu.edu</a>> wrote:<br>
<br>
Hi, Mark, I did have the data that is three component. Your example only<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
shows how to get pixel data that is one component which I never got in my<br>
code before. Do you have any idea how to retrieve this three component<br>
data?<br>
I have try bunch of methods, but none of them is working. any help will<br>
be<br>
greatly appreciated.<br>
<br>
Yenan<br>
<br>
Quoting Mark Wyszomierski <<a href="mailto:markww@gmail.com" target="_blank">markww@gmail.com</a>>:<br>
<br>
Hi,<br>
><br>
> It's definitely possible to get the scalar value from a vtkImageData<br>
> object. You need to know the type of data your object is stored in<br>
> though, for example you'll have difficulty getting the scalar value if<br>
> your data is three component RGB and you're trying to get a single<br>
> pixel scalar pixel value.<br>
><br>
> I have an example of getting the pixel value that the mouse moves over<br>
> in an image here:<br>
><br>
><br>
><br>
<a href="http://devsample.org/index.php?option=com_content&task=view&id=48&Itemid=27" target="_blank">http://devsample.org/index.php?option=com_content&task=view&id=48&Itemid=27</a><br>
><br>
> which may help.<br>
><br>
> Mark<br>
><br>
><br>
> On Thu, Mar 27, 2008 at 1:37 PM, <<a href="mailto:yenanqu@scs.fsu.edu" target="_blank">yenanqu@scs.fsu.edu</a>> wrote:<br>
><br>
> > Hi, all,<br>
> > I found bunch of the VTK methods to retrieve pixel data from vtk<br>
> > object, such as<br>
> > GetPixelData, GetRGBACharPixelData, etc, but none of them is working,<br>
> > Does anyone know how to get pixel data from VTK object? Thanks in<br>
> > advance.<br>
> ><br>
> > Yenan<br>
> ><br>
> > ----------------------------------------------------------------<br>
> > This message was sent using IMP, the Internet Messaging Program.<br>
> ><br>
> ><br>
> > --<br>
> > This message has been scanned for viruses and<br>
> > dangerous content by MailScanner, and is<br>
> > believed to be clean.<br>
> ><br>
> > _______________________________________________<br>
> > This is the private VTK discussion list.<br>
> > Please keep messages on-topic. Check the FAQ at:<br>
> > <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><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>
> ><br>
> --<br>
> This message has been scanned for viruses and<br>
> dangerous content by MailScanner, and is<br>
> believed to be clean.<br>
><br>
><br>
><br>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<br>
<br>
<br>
--<br>
This message has been scanned for viruses and<br>
dangerous content by MailScanner, and is<br>
believed to be clean.<br>
<br>
<br>
<br>
</blockquote>
--<br>
This message has been scanned for viruses and<br>
dangerous content by MailScanner, and is<br>
believed to be clean.<br>
<br>
<br>
<br>
</blockquote>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<br>
<br>
<br>
--<br>
This message has been scanned for viruses and<br>
dangerous content by MailScanner, and is<br>
believed to be clean.<br>
<br>
<br>
</blockquote>
<br>
--<br>
This message has been scanned for viruses and<br>
dangerous content by MailScanner, and is<br>
believed to be clean.<br>
<br>
<br>
</blockquote>
<br>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<br>
<br>
<br>
-- <br>
This message has been scanned for viruses and<br>
dangerous content by MailScanner, and is<br>
believed to be clean.<br>
<br>
</div></div></blockquote></div><br>