How to use "nearest"?
Although I have been able to get some things done with jit.gen, jit.gl pix is still a bit of a mystery. Specifically, I would love to do the following:
set the x and y values of any cell in a 3-plane matrix which has a z-plane value of 0 to the values of the nearest cell with a non-zero value.
Here is a patch doing something similar with jit.expr:
Is it possible to do this with jit.gl.pix? What is the best way to learn more about how to use jit.gl.pix? (Intuition and experimentation are proving too slow for this one; I need some real tutorials. Specifically, I would love to better understand how I can alter geometry with that object.)
Thanks in advance!
jit.gl.pix is really meant for image processing on the GPU, not geometry processing. You'll want to use jit.gen for geometry work.
Any jit.expr expression can be converted to a jit.gen patch. Finding the nearest cell that meets a condition to the current cell being processed isn't possible because there aren't for/while loops in gen patches at this point.
The nearest operator grabs the value of the cell of a matrix you direct it to. The first inlet of nearest is the input you're going to grab a value from. The second input is a coordinate from [0, 1] that specifies which cell to grab.
If you try to make what you're working on in to a gen patcher, post back with questions when you get stuck. I think it'll be easiest to help that way. Right now, I'm not exactly sure what you're trying to do.
Thank you Wesley Smith! Even just that information about the intended purpose of jit.gl.pix helped alot; this was not obvious to me from the documentation.
Here is a simple reworking of the patch I posted before, but doing the same thing with jit.gen:
Now I know how to use jit.gen instead of jit.expr, but I am at a loss as to how to approach the following:
I create a plane using jit.gl.mesh, and apply a live video as texture. If I filter out part of the video, leaving it black, I want to do the same to the plane.
My strategy is to set the x and y coordinates of any point in the mesh whose texture is black to their closest neighbor which is not black. This would leave a non-rectangular mesh with essentially the shape of the visible part of the input video. I have managed to do this using xray.jit objects, but now I want to port that to jit.gen.
Any suggestions? If anyone can help me with this, I will post the results in a useful patch. (The patch posted here is pared down to the bare minimum.)
"My strategy is to set the x and y coordinates of any point in the mesh whose texture is black to their closest neighbor which is not black."
You can't do this without a loop and the jitter gen objects don't support loop constructs at this point. You can get the values of neighboring cells, but you can only query a fixed number of them.
An alternante solution would be to use transparency, but I'm guessing you have a reason for not wanting to do that. Which xray objects did you use? Some of those objects cannot be translated into jitter gen patches at this point.
Thank you again!
I used xray.jit.cellcoords feeding into xray.jit.cellvalue.
To draw a mesh to emulate the filtered video, it was necessary to do this twice; once for x and once for y.
I tried everything I could think of with jit.gen last night, trying to prove you wrong, but in the end I now believe you, jit.gen won't do a lookup.
I will give it a try with xray.jit.cellcoords feeding in to jit.gen and see if that gives some performance enhancement.
The main reason I don't want to use transparency is because I need to use this in a jit.phys.world, with other objects colliding with the mesh. The way I am doing it now works for my purposes, but it would be great to have an object which is more elegant.
For what it is worth, here is the same patcher again without the jit.expr and with a defineable z-plane extrusion:
Thanks W.S.!
xray.jit.cellcoords is one of the objects that jit.gen cannot emulate unfortunately.
Here is the patch I promised. I am using this in conjunction with a Kinect camera, and it comes in handy. I'm still looking for ways to cut down on the cpu use.
Thanks again to Wesley Smith, j.m.pelletier, and yair; I have greatly benefitted from their largesse.
The patch:
Hello,
Great patch !
About your patch Lembert, I would have a question :
How to change the place of the objects falling down, I would like them to came from upper screen, not seeable at the beggining ? But I didn't achieve it...
Thank you really much.