Commits

Cliff Biffle committed 6f88052

Switched from KFKinect to KVKinectHardware and KVO-based frame distribution.

  • Participants
  • Parent commits 661a5f7

Comments (0)

Files changed (4)

File KVDepthView.h

 #import <OpenGL/glu.h>
 
 #import "types.h"
-#import "KFKinect.h"
 
 @protocol KVSpaceModel;
 
   GLint viewWidth, viewHeight;
 } camera_t;
 
-@interface KVDepthView : NSOpenGLView <KFKinectDepthDelegate, KFKinectColorDelegate> {
+@interface KVDepthView : NSOpenGLView {
   camera_t camera;
   
   BOOL usingTrackball;
 @property(assign, nonatomic) projective_transform_t colorTransform;
 @property(assign, nonatomic) NSString *polygonMode;
 
-- (void) depthFieldUpdated: (const depth_t *)buffer from: (KFKinect *)kinect;
-- (void) colorFieldUpdated: (const colors_t *)buffer from: (KFKinect *)kinect;
+@property (assign) NSData *latestDepthSamples;
+@property (assign) NSData *latestColorSamples;
 
 - (IBAction) selectPointCloudRenderer: sender;
 - (IBAction) selectMeshRenderer: sender;

File KVDepthView.m

 
 #pragma mark --- KFKinect Delegate Implementation ---
 
-- (void) depthFieldUpdated: (const depth_t *)buffer from: (KFKinect *)kinect {
+- (void) setLatestDepthSamples: (NSData *)data {
+  const uint8_t *buffer = [data bytes];
   @synchronized (self) {
     if (recording) {
       fwrite(buffer, sizeof(uint16_t), 640*480, depthOutput);
   }
       
   if (!self.frozen) {
-    [spaceModel setDepthSamples: [NSData dataWithBytesNoCopy: (void *) buffer length: sizeof *buffer freeWhenDone: NO]];
+    [spaceModel setDepthSamples: data];
     [self setNeedsDisplay: YES];
   }
 }
 
-- (void) colorFieldUpdated: (const colors_t *)buffer from: (KFKinect *)kinect {
+- (NSData *)latestDepthSamples {
+  return nil;
+}
+
+- (void) setLatestColorSamples: (NSData *)data {
   if (!self.frozen) {
-    [spaceModel setColorSamples: [NSData dataWithBytesNoCopy: (void *) buffer length: sizeof *buffer freeWhenDone: NO]];
+    [spaceModel setColorSamples: data];
     [self setNeedsDisplay: YES];
   }
 }
 
+- (NSData *)latestColorSamples {
+  return nil;
+}
+
 @end

File KinectViewerAppDelegate.h

  */
 
 #import <Cocoa/Cocoa.h>
-#import "KFKinect.h"
+#import "KVKinectHardware.h"
 
 @class KVDepthView;
 
   
   // Interface to the active Kinect.  If no Kinect is being
   // used (i.e. we're replaying a file) this will be nil.
-  KFKinect *kinect;
+  KVKinectHardware *kinect;
 }
 
 @property (assign) IBOutlet NSWindow *window;

File KinectViewerAppDelegate.m

     NSLog(@"Playing %@", replayFile);
     [NSThread detachNewThreadSelector:@selector(replayThread:) toTarget:self withObject:replayFile];
   } else {
-    kinect = [[KFKinect alloc] initWithDepthDelegate: depthView
-                                       colorDelegate: depthView];
+    kinect = [[KVKinectHardware alloc] init];
+    [depthView bind: @"latestDepthSamples" toObject: kinect withKeyPath: @"latestDepthSamples" options: nil];
+    [depthView bind: @"latestColorSamples" toObject: kinect withKeyPath: @"latestColorSamples" options: nil];
     [kinect open];
   }
 }
       size_t r = 0;
       r = read(fd, bytes, sizeof(depth_t));
       if (r < sizeof(depth_t)) break;
-      [depthView depthFieldUpdated: bytes from: nil];
+      [depthView setLatestDepthSamples: [NSData dataWithBytesNoCopy: bytes length: sizeof(depth_t) freeWhenDone: NO]];
       usleep(1000000 / 30);
     } while (YES);
     close(fd);