Commits

Cliff Biffle committed f7eec66

Factored the depth field computation out of the rendering methods and added a linearized depth cache to allow more interesting renderers.

  • Participants
  • Parent commits caeb0a0

Comments (0)

Files changed (2)

 
 @interface KVDepthView : NSOpenGLView <KFKinectDelegate> {
   NSMutableData *rawDepthField;
+  NSMutableData *linearDepthField;
   
   camera_t camera;
   
 - (void) resizeGL;
 - (void) updateProjection;
 - (void) updateModelView;
+
+- (void) computeLinearDepthField;
 - (void) drawDepthFieldAsPoints;
 - (void) drawDepthFieldAsCards;
 @end
 }
 
 - (void) awakeFromNib {
-  rawDepthField = [[NSMutableData alloc] initWithBytes: calloc(640 * 480, sizeof(uint16_t))
-                                                length: (640 * 480 * sizeof(uint16_t))];
+  rawDepthField = [[NSMutableData alloc] initWithBytesNoCopy: calloc(640 * 480, sizeof(uint16_t))
+                                                      length: (640 * 480 * sizeof(uint16_t))];
+  linearDepthField = [[NSMutableData alloc] initWithBytesNoCopy: calloc(640 * 480, sizeof(GLfloat))
+                                                         length: (640 * 480 * sizeof(GLfloat))];
   [self buildDepthTable];
 }
 
 }
 
 - (void) depthFieldUpdated: (KFKinect *)kinect {
+  [self computeLinearDepthField];
   [self setNeedsDisplay: YES];
 }
 
   glTranslatef(-320, -240, 0);
 }
 
+- (void) computeLinearDepthField {
+  const uint16_t *depths = [rawDepthField bytes];
+  GLfloat *linear = [linearDepthField mutableBytes];
+  
+  for (int y = 0; y < 480; y++) {
+    for (int x = 0; x < 640; x++) {
+      GLfloat d1 = depthTable[depths[y * 640 + x]];
+      if (d1 < 0.1F) d1 = 0.F;
+      linear[y * 640 + x] = d1;
+    }
+  }
+}
+
 static void axes() {
   glBegin(GL_LINES);
   glColor3f(1, 1, 1);
 - (void) drawDepthFieldAsCards {
   axes();
   
-  const uint16_t *depths = [rawDepthField bytes];
+  const GLfloat *depths = [linearDepthField bytes];
   
   glBegin(GL_QUADS);
   for (int y = 0; y < 480; y++) {
     for (int x = 0; x < 640; x++) {
-      GLfloat d1 = depthTable[depths[y * 640 + x]];
+      GLfloat d1 = depths[y * 640 + x];
       if (d1 < 0.1) continue;
       
       GLfloat dr = 1 + (d1 / 1);
 - (void) drawDepthFieldAsPoints {
   axes();
   
-  const uint16_t *depths = [rawDepthField bytes];
-  
+  const GLfloat *depths = [linearDepthField bytes];
+
   glBegin(GL_POINTS);
   for (int y = 0; y < 480; y++) {
     for (int x = 0; x < 640; x++) {
-      GLfloat d1 = depthTable[depths[y * 640 + x]];
+      GLfloat d1 = depths[y * 640 + x];
       if (d1 < 0.1F) continue;
       
       GLfloat dr = 1.F + d1;