From 8f9a8b4c06bb168b91cb0a3971c3dc37fb67220f Mon Sep 17 00:00:00 2001 From: Comment Date: Wed, 12 Mar 2014 09:16:46 +0000 Subject: image store working --- offsetProject/addons.make | 1 + offsetProject/src/imageStore.cpp | 8 +++ offsetProject/src/imageStore.h | 142 +++++++++++++++++++++++++++++++++++++++ offsetProject/src/main.cpp | 2 +- offsetProject/src/ofApp.cpp | 29 ++++---- offsetProject/src/ofApp.h | 7 +- 6 files changed, 169 insertions(+), 20 deletions(-) create mode 100644 offsetProject/src/imageStore.cpp create mode 100644 offsetProject/src/imageStore.h diff --git a/offsetProject/addons.make b/offsetProject/addons.make index ab4486b..05d5c04 100644 --- a/offsetProject/addons.make +++ b/offsetProject/addons.make @@ -1,2 +1,3 @@ ofxKinect ofxOpenCv +ofxJSON diff --git a/offsetProject/src/imageStore.cpp b/offsetProject/src/imageStore.cpp new file mode 100644 index 0000000..da6241d --- /dev/null +++ b/offsetProject/src/imageStore.cpp @@ -0,0 +1,8 @@ +#include "imageStore.h" + +long ofToLong(const string& intString) { + long x = 0; + istringstream cur(intString); + cur >> x; + return x; +} \ No newline at end of file diff --git a/offsetProject/src/imageStore.h b/offsetProject/src/imageStore.h new file mode 100644 index 0000000..3cfb7eb --- /dev/null +++ b/offsetProject/src/imageStore.h @@ -0,0 +1,142 @@ +#pragma once + +#define IMAGE_STORE_SIZE 256 + +#define MIN_TILE_SIZE 8 +#define MAX_TILE_SIZE 32 + +#include "ofMain.h" +#include "ofxJSONElement.h" + +long ofToLong(const string& intString); + +class imageStore : public ofThread{ + + public: + + float interval; //time between refreshes in seconds + + std::string instagram_url; + ofxJSONElement response; + std::map images; + deque to_update; + + imageStore(){ + instagram_url = "https://api.instagram.com/v1/tags/tycleeson/media/recent?client_id=c1d74d701fdf4ddd9f8d30ee9e8f944b"; + interval=5.00f; + } + + void set_interval(float _interval){ + interval=_interval; + } + + void start(){ + startThread(true, false); // blocking, verbose + } + + void stop(){ + stopThread(); + } + + //-------------------------- + void threadedFunction(){ + + //1st get the pre-existing images + + ofDirectory image_path(ofToString(IMAGE_STORE_SIZE)+"/"); + cerr<<"image path: "<::iterator i=images.begin();i!=images.end();++i){ + if(i->second.isUsingTexture()){ + drawcount++; + } + } + //cout<<"loaded "<::iterator i=images.begin();i!=images.end();++i){ + if(i->second.isUsingTexture()){ + i->second.draw(ofToLong(i->first)%(long)(ofGetWidth()-i->second.getWidth()+1),ofToLong(i->first)%(long)(ofGetHeight()-i->second.getHeight()+1)); + } + } + unlock(); + } + } + + +}; \ No newline at end of file diff --git a/offsetProject/src/main.cpp b/offsetProject/src/main.cpp index 1fa9125..9013dff 100644 --- a/offsetProject/src/main.cpp +++ b/offsetProject/src/main.cpp @@ -1,6 +1,6 @@ #include "ofApp.h" int main() { - ofSetupOpenGL(1600, 900, OF_WINDOW); + ofSetupOpenGL(600, 400, OF_WINDOW); ofRunApp(new ofApp()); } diff --git a/offsetProject/src/ofApp.cpp b/offsetProject/src/ofApp.cpp index 00c7f57..f65746e 100644 --- a/offsetProject/src/ofApp.cpp +++ b/offsetProject/src/ofApp.cpp @@ -38,9 +38,20 @@ get list of images in defined folder load them and create mip maps store indexed by file stub +start thread when a new image comes in load and create mip maps -save to + +how to store pictures +threaded loader works away in the background +when a new picture comes in + +a data structure which is part of the threaded object +each image contains a mutex to enable the threaded object to be accessed +the instagram id is just used to match against incoming - there needs to be the pattern matching algorithm + +how to draw pictures +need to search the db for pictures of a certain colour */ //-------------------------------------------------------------- @@ -49,19 +60,7 @@ void ofApp::setup() { ofSetFrameRate(60); - ofDirectory image_path(ofToString(IMAGE_STORE_SIZE)+"/"); - cerr<<"image path: "<