We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm trying to triangulate the point cloud generated in the PointCloud example by Shiffman. I can delete the origin point from the kinect and the wall behind me with an if and alpha values, but when I add TRIANGLE_STRIP into beginShape() instead od POINTS, I can find these points again. How can I delete them?!Code and images below...
THANKS...
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
// Kinect Library object
Kinect kinect;
// Angle for rotation
float a = 0;
// We'll use a lookup table so that we don't have to repeat the math over and over
float[] depthLookUp = new float[2048];
void setup() {
// Rendering in P3D
size(800, 600, P3D);
kinect = new Kinect(this);
kinect.initDepth();
smooth();
// Lookup table for all possible depth values (0 - 2047)
for (int i = 0; i < depthLookUp.length; i++) {
depthLookUp[i] = rawDepthToMeters(i);
}
}
void draw() {
background(0);
// Get the raw depth as array of integers
int[] depth = kinect.getRawDepth();
// We're just going to calculate and draw every 4th pixel (equivalent of 160x120)
int skip = 6;
// Translate and rotate
translate(width/2, height/2, -50);
rotateY(a);
//beginShape(POINTS);
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < kinect.width; x += skip) {
for (int y = 0; y < kinect.height; y += skip) {
int offset = x + y*kinect.width;
// Convert kinect data to world xyz coordinate
int rawDepth = depth[offset];
PVector v = depthToWorld(x, y, rawDepth);
noFill();
//depth
if (rawDepth > 300 && rawDepth < 800) {
stroke(255);
} else {
stroke(0, 0);
}
// Scale up by 200
float factor = 400;
// Draw a point
vertex(v.x*factor, v.y*factor, factor-v.z*factor);
}
}
endShape();
// Rotate
a += 0.015f;
}
// These functions come from: http://graphics.stanford.edu/~mdfisher/Kinect.html
float rawDepthToMeters(int depthValue) {
if (depthValue < 2047) {
return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
}
return 0.0f;
}
PVector depthToWorld(int x, int y, int depthValue) {
final double fx_d = 1.0 / 5.9421434211923247e+02;
final double fy_d = 1.0 / 5.9104053696870778e+02;
final double cx_d = 3.3930780975300314e+02;
final double cy_d = 2.4273913761751615e+02;
PVector result = new PVector();
double depth = depthLookUp[depthValue];//rawDepthToMeters(depthValue);
result.x = (float)((x - cx_d) * depth * fx_d);
result.y = (float)((y - cy_d) * depth * fy_d);
result.z = (float)(depth);
return result;
}
Answers
i think the problem might be that your triangle strip is wrapping around the rows of the data.
ie the last point of row 0 is part of a triangle with the first point of row 1.
actually, it's worse than that - points 0, 1 and 2 of row 0 are a triangle, as are 1, 2, and 3, as are 2, 3, 4... these will be almost co-linear.
TRIANGLE_STRIP here: https://processing.org/reference/beginShape_.html
I know what you mean. So, how I can triangulate them?!
And why if I put an alpha value = 0 I can see them just the same?
well, you can connect items in the 0th row with items in the 1st row etc (one triangle strip per row)
so that A1 B1 A2 is a triangle, B1 A2 B2 is a triangle etc
given that you are sampling points you could offset alternate lines to make it look less like a square grid and more like a triangular one
but what colour do you draw the line? what if one of the 3 points is invisible?
if one of the 3 points is invisible we get a gradient line from a transparent color to white, but I don't want to see the "entire/gradient" line!! I can't understand how I can exclude these points from the array list, that's my problem. I don't know if you understand what I mean...
any ideas?!
Maybe try putting the vertex(...) call in the passing branch of the if(...) instead of stroke(255) and get rid of the else.
a small runnable example that didn't need a kinect might be useful.