Permalink
Browse files

work from today

  • Loading branch information...
0 parents commit a928131b309b4d490f049b352287eecd54885961 @kylemcdonald committed Jan 8, 2012
@@ -0,0 +1,12 @@
+*.depend
+*.layout
+*.mode*v3
+*.pbxuser
+*.app*
+*.DS_*
+
+.svn/
+obj/
+bin/
+build/
+!data/
@@ -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)

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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 "ofApp.h"
+#include "ofAppGlutWindow.h"
+
+int main() {
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 544, 288, OF_WINDOW);
+ ofRunApp(new ofApp());
+}
@@ -0,0 +1,40 @@
+#include "ofApp.h"
+
+// add saving and loading
+
+void ofApp::setup() {
+ ofSetVerticalSync(true);
+ curvesTool.setup();
+ img.allocate(256, 256, OF_IMAGE_GRAYSCALE);
+ show = true;
+}
+
+void ofApp::update() {
+ for(int x = 0; x < 256; x++) {
+ for(int y = 0; y < 256; y++) {
+ img.setColor(x, y, ofColor(curvesTool[x]));
+ }
+ }
+ img.update();
+}
+
+void ofApp::draw() {
+ ofBackground(0);
+ ofTranslate(16, 16);
+ if(show) {
+ curvesTool.draw();
+ img.draw(256, 0);
+ }
+}
+
+void ofApp::keyPressed(int key) {
+ if(key == '\t') {
+ show = !show;
+ }
+ if(key == 's') {
+ curvesTool.save("curves.yml");
+ }
+ if(key == 'l') {
+ curvesTool.load("curves.yml");
+ }
+}
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "ofMain.h"
+
+#include "ofxCurvesTool.h"
+
+class ofApp : public ofBaseApp {
+public:
+ void setup();
+ void update();
+ void draw();
+ void keyPressed(int key);
+
+ ofxCurvesTool curvesTool;
+ ofImage img;
+ bool show;
+};
@@ -0,0 +1,29 @@
+# ofxCurvesTool is an addon for [openFrameworks](http://openframeworks.cc)
+
+ofxCurvesTool provides an interface for controlling a cubic spline that is continuously evaluated and stored in a lookup table.
+
+## LUT Access
+
+To get access to the data stored inside the curve, just use the `[]` operator. For example, to make a horizontally fading gradient inside a 256x256 image:
+
+ for(int x = 0; x < 256; x++) {
+ for(int y = 0; y < 256; y++) {
+ img.setColor(x, y, ofColor(curvesTool[x]));
+ }
+ }
+
+## Enable/Disable
+
+The interface only listens to mouse and keyboard events when it is drawn. It's a little magical, but if you're interested in the details see the implementation for `ofxCurvesTool::drawEvent()`.
+
+## Loading/Saving
+
+ofxCurvesTool stores data in an anonymous list of lists, using a severely simplified [YAML](https://en.wikipedia.org/wiki/Yml) representation. Call `ofxCurvesTool::save()` or `ofxCurvesTool::load()` with a `.yml` extension.
+
+## Size
+
+By default ofxCurvesTool uses 256 bins, but if you call `ofxCurvesTool::setup(128)` (for example) it will use 128 bins instead.
+
+## Drawing
+
+`ofxCurvesTool::draw()` takes no arguments. You have to position it using `ofTranslate()`. If you happen to scale or rotate `ofxCurvesTool`, it may get confused about where your mouse is clicking.
@@ -0,0 +1,115 @@
+#include "CurveLut.h"
+
+void CurveLut::setup(int n) {
+ this->n = n;
+ lut.resize(n);
+ add(ofVec2f(0, 0));
+ add(ofVec2f(n, n));
+}
+
+bool xSort(const ofVec2f& a, const ofVec2f& b) {
+ return a.x < b.x;
+}
+
+void CurveLut::add(ofVec2f controlPoint) {
+ controlPoint.x = ofClamp(controlPoint.x, 0, n - 1);
+ controlPoint.y = ofClamp(controlPoint.y, 0, n - 1);
+ controlPoints.push_back(controlPoint);
+ sort(controlPoints.begin(), controlPoints.end(), xSort);
+ update();
+}
+
+void CurveLut::set(int i, ofVec2f controlPoint) {
+ int m = controlPoints.size();
+ int lower = 0, upper = n - 1;
+ if(m > 1) {
+ if(i > 0) {
+ lower = controlPoints[i - 1].x + 1;
+ }
+ if(i < m - 1) {
+ upper = controlPoints[i + 1].x - 1;
+ }
+ }
+ controlPoint.x = ofClamp(controlPoint.x, lower, upper);
+ controlPoint.y = ofClamp(controlPoint.y, 0, n - 1);
+ controlPoints[i] = controlPoint;
+ update();
+}
+
+void CurveLut::remove(int i) {
+ controlPoints.erase(controlPoints.begin() + i);
+ update();
+}
+
+// based on code from: http://goo.gl/Y9Ik6
+vector<float> CurveLut::getSecondDerivative() {
+ // build the tridiagonal system
+ // (assume 0 boundary conditions: y2[0]=y2[-1]=0)
+ vector<ofVec2f>& c = controlPoints;
+ int m = c.size();
+ vector< vector<float> > matrix(m, vector<float>(3, 0));
+ vector<float> result(m, 0);
+ matrix[0][1] = 1;
+ for(int i = 1; i < m - 1; i++) {
+ matrix[i][0] = (c[i].x-c[i-1].x) / 6;
+ matrix[i][1] = (c[i+1].x-c[i-1].x) / 3;
+ matrix[i][2] = (c[i+1].x-c[i].x) / 6;
+ result[i] = (c[i+1].y-c[i].y)/(c[i+1].x-c[i].x) - (c[i].y-c[i-1].y)/(c[i].x-c[i-1].x);
+ }
+ matrix[m-1][1]=1;
+
+ // solving pass1 (up->down)
+ for(int i = 1; i < m; i++) {
+ float k = matrix[i][0] / matrix[i-1][1];
+ matrix[i][1] -= k * matrix[i-1][2];
+ matrix[i][0] = 0;
+ result[i] -= k * result[i-1];
+ }
+
+ // solving pass2 (down->up)
+ for(int i = m - 2; i >= 0; i--) {
+ float k = matrix[i][2] / matrix[i+1][1];
+ matrix[i][1] -= k * matrix[i+1][0];
+ matrix[i][2] = 0;
+ result[i] -= k * result[i+1];
+ }
+
+ // return second derivative value for each point P
+ vector<float> y2(m);
+ for (int i = 0; i < m; i++) {
+ y2[i] = result[i] / matrix[i][1];
+ }
+ return y2;
+}
+
+
+void CurveLut::update() {
+ vector<float> sd = getSecondDerivative();
+ int m = controlPoints.size();
+ ofVec2f& first = controlPoints.front();
+ ofVec2f& last = controlPoints.back();
+ for(int x = 0; x < first.x; x++) {
+ lut[x] = first.y;
+ }
+ for(int i = 0; i < m - 1; i++) {
+ ofVec2f& cur = controlPoints[i];
+ ofVec2f& next = controlPoints[i+1];
+ for (int x = cur.x; x < next.x; x++) {
+ float t = (x-cur.x) / (next.x-cur.x);
+ float a = 1-t;
+ float b = t;
+ float h = next.x-cur.x;
+ lut[x] = (a*cur.y + b*next.y + (h*h/6)*((a*a*a-a)*sd[i]+(b*b*b-b)*sd[i+1]));
+ }
+ }
+ for(int x = last.x; x < n; x++) {
+ lut[x] = last.y;
+ }
+ for(int x = 0; x < n; x++) {
+ lut[x] = ofClamp(lut[x], 0, n - 1);
+ }
+}
+
+float CurveLut::operator[](int i) const {
+ return lut[i];
+}
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "ofMain.h"
+
+class CurveLut {
+public:
+ void setup(int n = 256);
+ void add(ofVec2f controlPoint);
+ void set(int i, ofVec2f controlPoint);
+ void remove(int i);
+ void update();
+ float operator[](int i) const;
+ int size() const;
+
+protected:
+ vector<float> getSecondDerivative();
+ int n;
+ vector<float> lut;
+ vector<ofVec2f> controlPoints;
+};
Oops, something went wrong.

0 comments on commit a928131

Please sign in to comment.