#pragma once #define IMAGE_STORE_SIZE 256 #define MIN_TILE_SIZE 8 #define MAX_TILE_SIZE 16 #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; ofImage img; img.allocate(MAX_TILE_SIZE,MAX_TILE_SIZE,OF_IMAGE_COLOR); images["000000"]=img; colours["000000"]=ofColor(0,0,0); } void set_interval(float _interval){ interval=_interval; } void start(){ startThread(true, false); // blocking, verbose } void stop(){ stopThread(); } //naive implementation //too slow! //looks shit! //how to make the search algorithm faster and better //http://www.semanticmetadata.net/lire/ /* 1. The box nature of the image matching isn't appealing 2. The way that the images flip quickly isn't appealing can we improve this by changing the screen gradually in some way? search tree/ octree each node associates an image, start with a black image a node owns a volume of RGB space new image: determine which octant it lands in subdivide the octant in R, G or B and give half to each image Q: does this lead to the possibility that images end up in the wrong place? with the naive algorithm, we measure distance between the colours in RGB space it becomes a long process because the number of calculations increases exponentially space partitioning: we observe that the image will often be nearest to an image in the same box although it may not be if they are at the edges so at each level, each node of the tree contains a list of images we traverse the tree and try to find the lowest level box with a match if the lowest level box with a match has more than 1 we compute distance? a difference algorithm minimise the error this involves comparing every pixel though gpu? put every quarter of every image into an image tree every image has an entry on levels 1-8 start at level 8 (most detailed) check the leaf node ie 10110101 01101001 00110101 if there are 1 or more images here choose one if none go to the next level... ie 1011010 0110100 0011010 if there are more than 1 images here find the nearest if there is 1 choose it if there are none go to the next level */ std::map colours; ofImage& get_image(const ofColor& col){ //float shortest_dist=999999.0f; int sd=1000; ofImage& im=images.begin()->second; std::string s=images.begin()->first; for (map::iterator it=images.begin();it!=images.end();++it){ ofColor& c=colours[it->first]; int rd=c.v[0]-col.v[0]; int gd=c.v[1]-col.v[1]; int bd=c.v[2]-col.v[2]; //float dist=pow((float)((rd*rd)+(gd*gd)+(bd*bd)),0.5); int dist=abs(rd)+abs(gd)+abs(bd); if (distsecond; s=it->first; } } //cerr<<"got image "<::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)); } } */ map::iterator it=images.begin(); if (it!=images.end()){ for (int i=0;isecond.isUsingTexture()){ it->second.draw(i*MAX_TILE_SIZE,j*MAX_TILE_SIZE); } it++; if (it==images.end()) it=images.begin(); } } } unlock(); } } };