Commits

Cliff Biffle committed 9bd3aec

Can now overlay a wireframe (CmdF).

Comments (0)

Files changed (6)

English.lproj/MainMenu.xib

 		</object>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
+			<integer value="296"/>
 			<integer value="533"/>
-			<integer value="296"/>
 		</object>
 		<object class="NSArray" key="IBDocument.PluginDependencies">
 			<bool key="EncodedWithXMLCoder">YES</bool>
 									<reference key="NSOnImage" ref="35465992"/>
 									<reference key="NSMixedImage" ref="502551668"/>
 								</object>
+								<object class="NSMenuItem" id="655022095">
+									<reference key="NSMenu" ref="466310130"/>
+									<string key="NSTitle">Overlay Wireframe</string>
+									<string key="NSKeyEquiv">f</string>
+									<int key="NSKeyEquivModMask">1048576</int>
+									<int key="NSMnemonicLoc">2147483647</int>
+									<reference key="NSOnImage" ref="35465992"/>
+									<reference key="NSMixedImage" ref="502551668"/>
+								</object>
 								<object class="NSMenuItem" id="851891320">
 									<reference key="NSMenu" ref="466310130"/>
 									<bool key="NSIsDisabled">YES</bool>
 					</object>
 					<int key="connectionID">568</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBActionConnection" key="connection">
+						<string key="label">toggleWireframe:</string>
+						<reference key="source" ref="1014"/>
+						<reference key="destination" ref="655022095"/>
+					</object>
+					<int key="connectionID">570</int>
+				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<object class="NSArray" key="orderedObjects">
 							<reference ref="138643579"/>
 							<reference ref="63974516"/>
 							<reference ref="1032511002"/>
+							<reference ref="655022095"/>
 						</object>
 						<reference key="parent" ref="586577488"/>
 					</object>
 						<reference key="object" ref="1032511002"/>
 						<reference key="parent" ref="466310130"/>
 					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">569</int>
+						<reference key="object" ref="655022095"/>
+						<reference key="parent" ref="466310130"/>
+					</object>
 				</object>
 			</object>
 			<object class="NSMutableDictionary" key="flattenedProperties">
 					<string>563.IBPluginDependency</string>
 					<string>564.IBPluginDependency</string>
 					<string>567.IBPluginDependency</string>
+					<string>569.IBPluginDependency</string>
 					<string>57.IBEditorWindowLastContentRect</string>
 					<string>57.IBPluginDependency</string>
 					<string>57.ImportedFromIB2</string>
 					<string>{74, 862}</string>
 					<string>{{6, 978}, {478, 20}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-					<string>{{547, 593}, {264, 243}}</string>
+					<string>{{547, 573}, {264, 263}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>{{475, 832}, {234, 43}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>{{392, 653}, {223, 183}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<integer value="1"/>
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">568</int>
+			<int key="maxID">570</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
 							<string>toggleLighting:</string>
 							<string>toggleRecording:</string>
 							<string>toggleTextures:</string>
+							<string>toggleWireframe:</string>
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<string>id</string>
 							<string>id</string>
 							<string>id</string>
+							<string>id</string>
 						</object>
 					</object>
 					<object class="NSMutableDictionary" key="actionInfosByName">
 							<string>toggleLighting:</string>
 							<string>toggleRecording:</string>
 							<string>toggleTextures:</string>
+							<string>toggleWireframe:</string>
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 								<string key="name">toggleTextures:</string>
 								<string key="candidateClassName">id</string>
 							</object>
+							<object class="IBActionInfo">
+								<string key="name">toggleWireframe:</string>
+								<string key="candidateClassName">id</string>
+							</object>
 						</object>
 					</object>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
     
   FILE *depthOutput;
   
-  NSColor *deviceWhite;
+  NSColor *deviceWhite;  
 }
 
 @property(retain) NSObject <KVDepthMap> *depthMap;
 @property(retain) NSObject <KVRenderer> *renderer;
+@property(retain) NSObject <KVRenderer> *wireRenderer;
+
 @property(assign) BOOL frozen;
 @property(assign, nonatomic) BOOL anaglyph;
 @property(assign, nonatomic) BOOL lightsOn;
 @property(assign, nonatomic) BOOL textured;
+@property(assign, nonatomic) BOOL wireframe;
 @property(nonatomic) BOOL recording;
 @property(assign, nonatomic) projective_transform_t colorTransform;
 
 - (IBAction) toggleRecording: sender;
 - (IBAction) toggleAnaglyph: sender;
 - (IBAction) toggleTextures: sender;
+- (IBAction) toggleWireframe: sender;
 @end
 #import "KVDepthView.h"
 #import "KVPointCloudRenderer.h"
 #import "KVQuadRenderer.h"
+#import "KVWireRenderer.h"
 #import "KVTriStripRenderer.h"
 #import "KVDoubleBufferDepthMap.h"
 #import "KVAveragingDepthMap.h"
 
 @synthesize textured;
 @synthesize depthMap;
+@synthesize wireframe;
+
+@synthesize wireRenderer;
+- (void) setWireRenderer: (NSObject <KVRenderer>*)newRenderer {
+  NSObject <KVRenderer> *currentRenderer = wireRenderer;
+  wireRenderer = [newRenderer retain];
+  [currentRenderer release];
+  
+  newRenderer.color = [NSColor colorWithDeviceRed: 0.0 green: 1.0 blue: 0.0 alpha: 1.0];
+}
+
 @synthesize colorTransform;
-@synthesize renderer;
-
 - (void) setColorTransform: (projective_transform_t)newTransform {
   colorTransform = newTransform;
   [self setNeedsDisplay: YES];
   self.colorTransform = colorTransform;
 }
 
+@synthesize renderer;
 - (void) setRenderer: (NSObject <KVRenderer> *)newRenderer {
   NSObject <KVRenderer> *currentRenderer = renderer;
   renderer = [newRenderer retain];
     .scale = { 0.92F, 0.92F },
   };
   
+  self.wireRenderer = [[[KVWireRenderer alloc] init] autorelease];
+  
   [self selectPointCloudRenderer: nil];
   [self selectStaticDepthMap: nil];
 }
   // Draw right eye or center.
   [self updateModelView];
   [depthMap drawInCurrentOpenGLContextWithRenderer: renderer];
+  if (wireframe) {
+    [depthMap drawInCurrentOpenGLContextWithRenderer: wireRenderer];
+  }
   
   if (self.anaglyph) {
     // Draw left eye.
     glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
     [self updateModelView];
     [depthMap drawInCurrentOpenGLContextWithRenderer: renderer];
-
+    if (wireframe) {
+      [depthMap drawInCurrentOpenGLContextWithRenderer: wireRenderer];
+    }
+    
     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
     
     camera.pos.x -= INTEROCULAR_DISTANCE / 2;
   [sender setState: self.frozen? NSOnState : NSOffState];
 }
 
+- (IBAction) toggleWireframe: sender {
+  self.wireframe = !self.wireframe;
+  [sender setState: self.wireframe? NSOnState : NSOffState];
+}
+
 - (IBAction) toggleLighting: sender {
   self.lightsOn = !lightsOn;
   [sender setState: lightsOn? NSOnState : NSOffState];
+/*
+ * Copyright 2010 Cliff L. Biffle.  All Rights Reserved.
+ * Use of this source code is governed by the Apache License 2.0,
+ * which can be found in the LICENSE file.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "KVAbstractRenderer.h"
+
+// Renders depth samples using a decimated wireframe
+// mesh.
+@interface KVWireRenderer : KVAbstractRenderer {
+}
+
+@end
+/*
+ * Copyright 2010 Cliff L. Biffle.  All Rights Reserved.
+ * Use of this source code is governed by the Apache License 2.0,
+ * which can be found in the LICENSE file.
+ */
+
+#import "KVWireRenderer.h"
+#import "types.h"
+#import "utility.h"
+
+#define STRIDE (5)
+
+@implementation KVWireRenderer
+
+- (void) drawInCurrentOpenGLContext: (const linear_depth_t *)zs
+                             colors: (const colors_t *)colors {
+  NSLog(@"hi");
+  KVAbstractRendererProjector projector =
+      (KVAbstractRendererProjector) [self methodForSelector: @selector(projectInto:x:y:z:)];
+  
+  glBegin(GL_LINES);
+  vec3f_t baseColor = [self colorAsRGBVector];
+  glColor3fv(&baseColor.x);
+  
+  for (int y = 0; y < 480 - STRIDE; y += STRIDE) {
+    for (int x = 0; x < 640 - STRIDE; x += STRIDE) {
+      // A CCW traversal of the neighboring points:
+      int xs[4] = { x, x, x + STRIDE, x + STRIDE };
+      int ys[4] = { y, y + STRIDE, y + STRIDE, y };
+      
+      BOOL skip = NO;
+      vec3f_t coords[4];
+      GLfloat minDepth = 1000.F, maxDepth = -1000.F;
+      for (int i = 0; i < 4; i++) {
+        GLfloat d = zs->z[ys[i]][xs[i]] - 0.02F;
+        
+        if (d == 0.F) skip = YES;
+        
+        minDepth = fminf(minDepth, d);
+        maxDepth = fmaxf(maxDepth, d);
+        
+        projector(self, @selector(projectInto:x:y:z:), &coords[i], xs[i], ys[i], d);
+      }
+      
+      if (fabsf(minDepth - maxDepth) > 0.4F) skip = YES;
+      
+      if (skip) continue;
+      
+      for (int i = 0; i < 4; i++) {
+        int nextI = (i + 1) % 4;
+        glVertex3fv(&coords[i].x);
+        glVertex3fv(&coords[nextI].x);
+      }
+    }
+  }
+  glEnd();
+}
+
+@end

KinectViewer.xcodeproj/project.pbxproj

 		C70E66AA129C9024004A44B3 /* libusb.h in Headers */ = {isa = PBXBuildFile; fileRef = C70E6690129C8FD5004A44B3 /* libusb.h */; };
 		C70E66BB129C906C004A44B3 /* libdriver.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C70E669F129C9005004A44B3 /* libdriver.a */; };
 		C70E66CA129C9121004A44B3 /* libusb-1.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C70E66C9129C9121004A44B3 /* libusb-1.0.dylib */; };
+		C758017712A3522700391C33 /* KVWireRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = C758017612A3522700391C33 /* KVWireRenderer.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
 		C70E6690129C8FD5004A44B3 /* libusb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libusb.h; sourceTree = "<group>"; };
 		C70E669F129C9005004A44B3 /* libdriver.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libdriver.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		C70E66C9129C9121004A44B3 /* libusb-1.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libusb-1.0.dylib"; path = "usr/local/lib/libusb-1.0.dylib"; sourceTree = SDKROOT; };
+		C758017512A3522700391C33 /* KVWireRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KVWireRenderer.h; sourceTree = "<group>"; };
+		C758017612A3522700391C33 /* KVWireRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KVWireRenderer.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
 				C708F46912A03E8F00656901 /* KVQuadRenderer.m */,
 				C708F46212A03E8500656901 /* KVTriStripRenderer.h */,
 				C708F46312A03E8500656901 /* KVTriStripRenderer.m */,
+				C758017512A3522700391C33 /* KVWireRenderer.h */,
+				C758017612A3522700391C33 /* KVWireRenderer.m */,
 			);
 			name = Renderers;
 			sourceTree = "<group>";
 				C708F46B12A03E8F00656901 /* KVQuadRenderer.m in Sources */,
 				C708F55912A0728800656901 /* KVDoubleBufferDepthMap.m in Sources */,
 				C708F5E412A0779500656901 /* KVAveragingDepthMap.m in Sources */,
+				C758017712A3522700391C33 /* KVWireRenderer.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};