Permalink
Browse files

21 pattern gray code sample app. not using the initial 1 gray pattern…

… right now
  • Loading branch information...
1 parent fd94de4 commit dc552dc5497a6224b7914df0c9f816e817983d6d @kylemcdonald kylemcdonald committed Nov 6, 2011

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,9 @@
+//THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
+//THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
+OF_PATH = ../../..
+
+//THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
+#include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
+
+OTHER_LDFLAGS = $(OF_CORE_LIBS)
+HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.openFrameworks</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+</dict>
+</plist>
@@ -0,0 +1,8 @@
+#include "testApp.h"
+#include "ofAppGlutWindow.h"
+
+int main() {
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, testApp::tw, testApp::th, OF_FULLSCREEN);
+ ofRunApp(new testApp());
+}
@@ -0,0 +1,110 @@
+#include "testApp.h"
+
+#include "GrayCodeGenerator.h"
+GrayCodeGenerator generator;
+bool capturing = false;
+int totalDirection = 2;
+int totalStyles = 2;
+
+int capture = 0;
+int style = 0; // gray, patterns
+int direction = 0; // false/true, 2 values
+int pattern = 0; // 0-9, 10 values
+
+string curDirectory;
+long bufferTime = 120;
+bool needToCapture = false;
+long captureTime = 0;
+
+void generate() {
+ generator.setSize(testApp::tw, testApp::th);
+ generator.setOrientation(direction == 0 ? PatternGenerator::VERTICAL : PatternGenerator::HORIZONTAL);
+ generator.setInverse(false);
+ generator.generate();
+
+ stringstream dirStr;
+ dirStr << capture << "/";
+ if(style > 0) {
+ dirStr << (direction == 0 ? "vertical/" : "horizontal/");
+ }
+ curDirectory = dirStr.str();
+}
+
+bool nextState() {
+ if(style == 0) {
+ style++;
+ generate();
+ } else {
+ pattern++;
+ if(pattern == generator.size()) {
+ pattern = 0;
+ direction++;
+ if(direction == totalDirection) {
+ direction = 0;
+ style = 0;
+ capture++;
+ generate();
+ return false;
+ }
+ generate();
+ }
+ }
+ return true;
+}
+
+void testApp::setup() {
+ ofSetVerticalSync(true);
+ ofHideCursor();
+ ofSetDataPathRoot("../../../../../SharedData/quick/");
+ ofSetLogLevel(OF_LOG_VERBOSE);
+ camera.setup();
+ generate();
+}
+
+void testApp::update() {
+ if(!capturing) {
+ camera.update();
+ }
+ if(camera.isPhotoNew()) {
+ ofDirectory::createDirectory(curDirectory, true, true);
+ bool success = camera.savePhoto(curDirectory + ofToString(pattern) + ".jpg");
+ if(nextState()) {
+ captureTime = ofGetElapsedTimeMillis();
+ needToCapture = true;
+ } else {
+ capturing = false;
+ }
+ }
+}
+
+void testApp::draw() {
+ if(capturing) {
+ ofBackground(128);
+ if(style > 0) {
+ generator.get(pattern).draw(0, 0);
+ }
+ } else {
+ ofBackground(255);
+ ofPushMatrix();
+ ofTranslate(tw / 2, th / 2);
+ ofSetColor(255);
+ ofScale(.75, .75);
+ ofTranslate(-camera.getLivePixels().getWidth() / 2, -camera.getLivePixels().getHeight() / 2);
+ camera.draw(0, 0);
+ ofPopMatrix();
+ }
+ if(needToCapture && (ofGetElapsedTimeMillis() - captureTime) > bufferTime) {
+ camera.takePhoto();
+ needToCapture = false;
+ }
+}
+
+void testApp::keyPressed(int key) {
+ if(key == ' ') {
+ camera.takePhoto();
+ capturing = true;
+ }
+ if(key == 'f') {
+ ofToggleFullscreen();
+ }
+}
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "ofMain.h"
+
+#include "ofxEdsdk.h"
+
+class testApp : public ofBaseApp {
+public:
+ void setup();
+ void update();
+ void draw();
+ void keyPressed(int key);
+
+ const static int tw = 1024;
+ const static int th = 768;
+
+ ofxEdsdk::Camera camera;
+};

0 comments on commit dc552dc

Please sign in to comment.