From 1d5d6abbde2167c458167e7bda6ceeca7ed39d10 Mon Sep 17 00:00:00 2001 From: Tom Schofield Date: Sun, 19 Feb 2012 18:17:45 +0000 Subject: [PATCH] corrected file confusion --- src/ColorMultiAnalysis.cpp | 94 +++++++++++++++++++++++++++--------- src/ColorMultiAnalysis.h | 5 +- src/ColorSingleAnalysis.cpp | 96 +++++++++++++++++++++++++++++++++++-- src/ColorSingleAnalysis.h | 6 ++- 4 files changed, 171 insertions(+), 30 deletions(-) diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index ba21eee..3b2f862 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -90,34 +90,57 @@ void ColorMultiAnalysis::acquire() void ColorMultiAnalysis::synthesise() { - cout<<"SYNTHESISING MULTI"; - // _saved_filenames has all the file names of all the saved images - // _saved_filenames has all the file names of all the saved images //incrementer to whichMesh speed=0.2; //whichMesh is the index in the vector of meshes whichMesh=0; - - cout<<"image loaded "; - //there is a problem with natural vs alphabetical order when loading the files - we need to make a fix for this - int shift=0; - cout<<_saved_filenames.size()<<" image filenames "; + int index=0; - //for(int i=shift;i<_saved_filenames.size()-2;i+=2){ - // cout<<_saved_filenames[i]< display_results_callback(*this, &ColorMultiAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=500; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +} void ColorMultiAnalysis::draw() { @@ -171,12 +194,31 @@ void ColorMultiAnalysis::draw() case STATE_SYNTHESISING: { // display animation of something while the synthesis in on-going... + break; } case STATE_DISPLAY_RESULTS: - { - // display results of the synthesis + { + int imageWidth=640; + int imageHeight =480; + ofPushMatrix(); + ofTranslate(ofGetWidth()/2, ofGetHeight()/2); + ofRotateY(_results_cnt*0.3); + //ofRotateX(90); + //ofRotateZ(whichMesh); + ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400; + ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 ); + + meshes[whichMesh].drawVertices(); + ofPopMatrix(); + whichMesh+=speed; + + if(whichMesh>meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + } + break; } @@ -202,10 +244,16 @@ void ColorMultiAnalysis::save_cb(Timer& timer) // cout<<_whole_file_path<= NUM_SAVE_PER_RUN){ _RUN_DONE = true; } } + +void ColorMultiAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + diff --git a/src/ColorMultiAnalysis.h b/src/ColorMultiAnalysis.h index ef4fc60..55bf291 100755 --- a/src/ColorMultiAnalysis.h +++ b/src/ColorMultiAnalysis.h @@ -15,14 +15,15 @@ public: void setup(int camWidth, int camHeight); void acquire(); void synthesise(); + void display_results(); void draw(); void save_cb(Poco::Timer& timer); + void display_results_cb(Poco::Timer& timer); protected: bool _RUN_DONE; int _run_cnt, _save_cnt, _fade_cnt; - float c, _frame_cnt, _frame_cnt_max; - ofImage image1; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index ec99afa..6779da9 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -15,10 +15,15 @@ using Poco::Timer; using Poco::TimerCallback; using Poco::Thread; +#define COMPARE_RED 1 +#define COMPARE_BLUE 2 +#define COMPARE_GREEN 3 +#define COMPARE_HUE 4 +#define COMPARE_BRIGHTNESS 5 void ColorSingleAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 300; + DELTA_T_SAVE = 100;//300; NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 100; @@ -64,9 +69,65 @@ void ColorSingleAnalysis::acquire() void ColorSingleAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images + //incrementer to whichMesh + speed=0.2; + //whichMesh is the index in the vector of meshes + whichMesh=0; + + int index=0; + + //if you want to see what this looks like with real data ignore the new filenames and load teh old ones. + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + } + + for(int i=1;i<_saved_filenames.size()-2;i+=2){ + + meshes.push_back(ofMesh()); + ofImage image1; + ofImage image2; + + //there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false) + image1.setUseTexture(false); + image2.setUseTexture(false); + //some of the textures are not loading correctly so only make mesh if both the images load + if(image1.loadImage(_saved_filenames[1]) && image2.loadImage(_saved_filenames[i+1])){ + + if(i<_saved_filenames.size()/3){ + setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_RED), image2, &meshes[index]); + } + if(i>=_saved_filenames.size()/3 && i<2* _saved_filenames.size()/3){ + setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_GREEN), image2, &meshes[index]); + } + if(i>= 2* _saved_filenames.size()/3 && i<_saved_filenames.size()){ + setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BLUE), image2, &meshes[index]); + } + index++; + } + } } - +void ColorSingleAnalysis::display_results(){ + + Timer* display_results_timer; + + TimerCallback display_results_callback(*this, &ColorSingleAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=500; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +} void ColorSingleAnalysis::draw() { @@ -134,6 +195,25 @@ void ColorSingleAnalysis::draw() case STATE_DISPLAY_RESULTS: { // display results of the synthesis + int imageWidth=640; + int imageHeight =480; + ofPushMatrix(); + ofTranslate(ofGetWidth()/2, ofGetHeight()/2); + ofRotateY(_results_cnt*0.3); + //ofRotateX(90); + //ofRotateZ(whichMesh); + ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400; + ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 ); + + meshes[whichMesh].drawVertices(); + ofPopMatrix(); + whichMesh+=speed; + + if(whichMesh>meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + } + break; } @@ -152,11 +232,21 @@ void ColorSingleAnalysis::save_cb(Timer& timer) string file_name =ofToString(_save_cnt,2)+"_"+fileNameTag+"_"+ofToString(_run_cnt,2)+".jpg"; + //cout<= NUM_SAVE_PER_RUN) _RUN_DONE = true; } +void ColorSingleAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index 0772c43..2719ecd 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -19,15 +19,17 @@ public: void setup(int camWidth, int camHeight); void acquire(); - void synthesise(); + void synthesise(); + void display_results(); void draw(); void save_cb(Poco::Timer& timer); + void display_results_cb(Poco::Timer& timer); protected: bool _RUN_DONE; string fileNameTag; int _run_cnt, _save_cnt, _fade_cnt; - float r,g,b, _frame_cnt, _frame_cnt_max; + float r,g,b, _frame_cnt, _frame_cnt_max , _results_cnt, _results_cnt_max; };