1. Cliff Biffle
  2. kinect-viewer

Commits

Cliff Biffle  committed 81adcd4

All renderers now take a base color parameter, so I can color the foreground differently from the background.

  • Participants
  • Parent commits e0d3bca
  • Branches default

Comments (0)

Files changed (2)

File KVDepthView.h

View file
 }
 
 @property(retain) NSMutableData *rawDepthField;
-@property(copy) void (^renderAction)(NSData *);
+@property(copy) void (^renderAction)(NSData *, const vec3f_t *);
 @property(assign) BOOL frozen;
 @property(assign, nonatomic) BOOL lightsOn;
 @property(nonatomic) BOOL separateForeground;

File KVDepthView.m

View file
 
 - (void) computeLinearDepthField: (NSMutableData *)output 
                     andFoldUsing: (GLfloat (^)(int,int,GLfloat,GLfloat))fold;
-- (void) drawDepthFieldAsPoints: (NSData *)field;
-- (void) drawDepthFieldAsCards: (NSData *)field;
-- (void) drawDepthFieldAsMesh: (NSData *)field;
-- (void) drawDepthFieldAsQuads: (NSData *)field usingMode: (GLenum)mode;
-- (void) drawDepthFieldAsTris: (NSData *)field usingMode: (GLenum)mode;
+- (void) drawDepthFieldAsPoints: (NSData *)field baseColor: (const vec3f_t *)color;
+- (void) drawDepthFieldAsCards: (NSData *)field baseColor: (const vec3f_t *)color;
+- (void) drawDepthFieldAsMesh: (NSData *)field baseColor: (const vec3f_t *)color;
+- (void) drawDepthFieldAsQuads: (NSData *)field usingMode: (GLenum)mode baseColor: (const vec3f_t *)color;
+- (void) drawDepthFieldAsTris: (NSData *)field usingMode: (GLenum)mode baseColor: (const vec3f_t *)color;
 @end
 
 @implementation KVDepthView
   GLfloat ambientColor[4] = { 0, 0, 0, 1 };
   glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
   
-  GLfloat diffuseColor[4] = { 1.f, 0.0f, 0.0f, 1.0f };
+  GLfloat diffuseColor[4] = { 1.f, 1.0f, 1.0f, 1.0f };
   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);
   
   GLfloat globalAmbient[4] = { 0.1f, 0.1f, 0.1f, 1.0f };
   
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
-  (self.renderAction)(backgroundDepthField);
-  if (separateForeground) (self.renderAction)(foregroundDepthField);
+  vec3f_t color = { 1,1,1 };
+  (self.renderAction)(backgroundDepthField, &color);
+  if (separateForeground) {
+    color = (vec3f_t){ 1, 0, 0 };
+    (self.renderAction)(foregroundDepthField, &color);
+  }
   
   [[self openGLContext] flushBuffer];
 }
 #pragma mark --- Actions ---
 
 - (IBAction) selectPointCloudRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsPoints: field]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsPoints: field baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 - (IBAction) selectMeshRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsMesh: field]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsMesh: field baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 - (IBAction) selectCardCloudRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsCards: field]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsCards: field baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 - (IBAction) selectFilledQuadRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsQuads: field usingMode: GL_FILL]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsQuads: field usingMode: GL_FILL baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 - (IBAction) selectMeshedQuadRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsQuads: field usingMode: GL_LINE]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsQuads: field usingMode: GL_LINE baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 - (IBAction) selectFilledTriRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsTris: field usingMode: GL_FILL]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsTris: field usingMode: GL_FILL baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 - (IBAction) selectMeshedTriRenderer: sender {
-  self.renderAction = ^(NSData *field){ [self drawDepthFieldAsTris: field usingMode: GL_LINE]; };
+  self.renderAction = ^(NSData *field, const vec3f_t *color){ 
+    [self drawDepthFieldAsTris: field usingMode: GL_LINE baseColor: color]; 
+  };
   [self setNeedsDisplay: YES];
 }
 
 	cross_product(&a, &b, out);
 }
 
-- (void) drawDepthFieldAsTris: (NSData *)field usingMode: (GLenum)mode {
+- (void) drawDepthFieldAsTris: (NSData *)field 
+                    usingMode: (GLenum)mode 
+                    baseColor: (const vec3f_t *)color {
   /*
    * Theory: each horizontal raster row of the image is converted to a
    * triangle strip, using the simplest possible method:
   vec3f_t normal;
   
   glPolygonMode(GL_FRONT, mode);
-  glColor3f(1,1,1);
+  glColor3fv(&color->x);
 
   for (int y = 0; y < 479; y++) {
     glBegin(GL_TRIANGLE_STRIP);
   }
 }
 
-- (void) drawDepthFieldAsQuads: (NSData *)field usingMode: (GLenum)mode {
+- (void) drawDepthFieldAsQuads: (NSData *)field 
+                     usingMode: (GLenum)mode 
+                     baseColor: (const vec3f_t *)color {
   axes();
   
   const GLfloat *depths = [field bytes];
 
   glPolygonMode(GL_FRONT, mode);
   glBegin(GL_QUADS);
-  glColor3f(1,1,1);
+  glColor3fv(&color->x);
 
   for (int y = 0; y < 479; y++) {
     for (int x = 0; x < 639; x++) {
   glEnd();
 }
 
-- (void) drawDepthFieldAsMesh: (NSData *)field {
+- (void) drawDepthFieldAsMesh: (NSData *)field baseColor: (const vec3f_t *)color {
   /*
    * Implementation note: each iteration needs only draw the top and left lines.
    */
   axes();
   
   const GLfloat *depths = [field bytes];
-  
+  glColor3fv(&color->x);
+
   glBegin(GL_LINES);
   for (int y = 0; y < 479; y++) {
     for (int x = 0; x < 639; x++) {
   glEnd();
 }
 
-- (void) drawDepthFieldAsCards: (NSData *)field {
+- (void) drawDepthFieldAsCards: (NSData *)field baseColor: (const vec3f_t *)color {
   axes();
   
   const GLfloat *depths = [field bytes];
-  
+  glColor3fv(&color->x);
+
   glBegin(GL_QUADS);
   glNormal3f(0, 0, -1);
   for (int y = 0; y < 480; y++) {
   glEnd();
 }
 
-- (void) drawDepthFieldAsPoints: (NSData *)field {
+- (void) drawDepthFieldAsPoints: (NSData *)field baseColor: (const vec3f_t *)color {
   axes();
   
   const GLfloat *depths = [field bytes];
+  glColor3fv(&color->x);
 
   glBegin(GL_POINTS);
   for (int y = 0; y < 480; y++) {