We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › finding color of a 3d pixel
Page Index Toggle Pages: 1
finding color of a 3d pixel (Read 1698 times)
finding color of a 3d pixel
Nov 20th, 2009, 10:55am
 
I'm not sure if this is so simple i'm missing it but I can't figure out how to do it.  I'm trying to get the color of a pixel at a particular x,y,z coordinate.  If you can't do it directly, then I thought you may be able to iterate through z slices, turn them into a PImage, and get the pixels from that.  But even that's not clear how to do.

I am new to the world of 3d (and somewhat new to java and processing) but I am a programmer by profession so I can figure out the details...I just can't figure out the best way to go about it.

Thanks for your expertise!
Re: finding color of a 3d pixel
Reply #1 - Nov 21st, 2009, 1:03pm
 
You should explain a bit more what you want to do.
Cause how should it work? you draw a sphere in 3d space and fill it red. So is a point inside the sphere now red, or is it colorless, or black?

I would say the question is what you want to achieve with your programm and maybe we find a solution for it. but i would say there is no real colorpicking in 3d space.
Re: finding color of a 3d pixel
Reply #2 - Nov 21st, 2009, 3:21pm
 
Take a look at some of the color picking examples.

http://processing.org/hacks/hacks:picking_color_buffer
http://processing.org/discourse/yabb2/?num=1236203309
Re: finding color of a 3d pixel
Reply #3 - Nov 24th, 2009, 7:24pm
 
@jeffg: thank you for the links.  That's a clever hack and may be the basis for something in need.

@Cedric:  You're right.  When I think about it further there are 2 things I didn't think of: 1, space with nothing in it doesn't have a color and 2, shapes don't have inherent volume (i.e. a plane rendered from the right angle would be invisible).

To define my question more precisely, imagine you have a probe in the space at point (x,y,z).  And then imagine a solid yellow sphere passing through that point.  Whenever the probe is in that sphere it would read "yellow" and whenever it wasn't it would read maybe "null".  

Of course now I see that 3d rendering has no need to define a solid object because all you'll ever see is the outside of it.  I assume that's something to do with the method of drawing the object via ray tracing.  But isn't there some point in the calculation where the renderer has to say "if you shoot a ray out in this direction, you'll hit a surface at point (x,y,z)"?  How does the renderer know where the edges of its objects are?  I feel like if I knew how that process worked I could tap into it to get my "3d points".

Thanks so much for any further help you can give.
Re: finding color of a 3d pixel
Reply #4 - Feb 4th, 2010, 4:49pm
 
OpenGL (and therefore processing) doesn't work by ray tracing. I think it works by calculating how a triangle would look, after it has been translated, rotated etc.

A simple (but probably very naive) way of doing what you want, would be to (in a buffer) translate so that your view is at the location where you want to sample the color (voxel so to speak) set the FOV to one (pixel) deep (and wide&high?) then perform a getpixel() on the centre of the screen(buffer) if its the same as the background move back a bit, getpixel() again, etc until you are at your original position or get a non background color.

I'm sure there are better ways of doing this, or at least improving this method. ie check that you are not looking at the background to start with.

Another way is to keep a table of the mid point of (the two opposite vertices of) all of your cubes spheres etc then look up which one is closest to the x,y,x you are looking for (use Pythagoras's theorem) and is less than the radius (distance between vertices)/2 from that point.

wont quite work if its in the corner of a cube, but you prob can refine this a bit and get it to work.



Re: finding color of a 3d pixel
Reply #5 - Feb 4th, 2010, 4:51pm
 
Also you could look up collision detection which may have some hints which will help you.
Re: finding color of a 3d pixel
Reply #6 - Feb 5th, 2010, 10:00am
 
intertwined slices can be the most confusing in my opinion lol Cheesy
Page Index Toggle Pages: 1