From 6b401b8424d76d7d53c1bed4c63013ddd6b52ba2 Mon Sep 17 00:00:00 2001 From: Tom Schofield Date: Mon, 20 Feb 2012 11:25:55 +0000 Subject: [PATCH] added synthesise and display results to all analysis classes --- src/AbstractAnalysis.cpp | 36 ++++++++++++- src/AbstractAnalysis.h | 14 ++++- src/CamNoiseAnalysis.cpp | 86 +++++++++++++++++++++++++++-- src/CamNoiseAnalysis.h | 6 ++- src/ColorMultiAnalysis.cpp | 13 ++--- src/ColorSingleAnalysis.cpp | 16 +++--- src/DiffNoiseAnalysis.cpp | 90 +++++++++++++++++++++++++++++-- src/DiffNoiseAnalysis.h | 6 ++- src/IResponseAnalysis.cpp | 92 ++++++++++++++++++++++++++++++-- src/IResponseAnalysis.h | 8 +-- src/RelaxRateAnalysis.cpp | 90 +++++++++++++++++++++++++++++-- src/RelaxRateAnalysis.h | 6 ++- src/ShadowScapesAnalysis.cpp | 88 ++++++++++++++++++++++++++++-- src/ShadowScapesAnalysis.h | 6 ++- src/ShapeFromShadingAnalysis.cpp | 88 +++++++++++++++++++++++++++++- src/ShapeFromShadingAnalysis.h | 6 ++- src/StrobeAnalysis.cpp | 87 +++++++++++++++++++++++++++++- src/StrobeAnalysis.h | 6 ++- 18 files changed, 688 insertions(+), 56 deletions(-) diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index e5432e1..9e4009f 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -233,8 +233,8 @@ void AbstractAnalysis::setMeshFromPixels(ofPixels somePixels, ofImage currentSec vectorAbstractAnalysis:: getListOfImageFilePaths(string location, string whichAnalysis){ string path = ofToDataPath("")+"debug_analysis/"+location+"/"+whichAnalysis; - ofxDirList dirList; - + //ofxDirList dirList; + ofDirectory dirList; int numDirs = dirList.listDir(path); vectordirectoryNames; @@ -281,3 +281,35 @@ vectorAbstractAnalysis:: getListOfImageFilePaths(string location, string return fileNamesToReturn; } +int AbstractAnalysis::getRecordedValueFromFileName(string str){ + //split filename by underscore - there HAS to be a quicker way of doing things - its ONE LINE in java :( + char * cstr, *p; + vectortokens; + //string str ("Please split this phrase into tokens"); + + //make char pointer array + cstr = new char [str.size()+1]; + //copy string to char pointer array + strcpy (cstr, str.c_str()); + + //tokenise char p array and put first results into pointer? + p=strtok (cstr,"_"); + + while (p!=NULL) + { + p=strtok(NULL,"_"); + //push tokenised char into vector + tokens.push_back(p); + + } + delete[] cstr; + char *p1; + //cstr = new char [str.size()+1]; + //strcpy (cstr, str.c_str()); + + p1=strtok (tokens[tokens.size()-2],"."); + + return ofToInt(p1); +} + + diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index a759f17..1b79490 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -16,6 +16,12 @@ #define STATE_DISPLAY_RESULTS 0x3333 #define STATE_STOP 0xDEADBEEF +#define COMPARE_RED 1 +#define COMPARE_BLUE 2 +#define COMPARE_GREEN 3 +#define COMPARE_HUE 4 +#define COMPARE_BRIGHTNESS 5 + class AbstractAnalysis { public: @@ -49,9 +55,15 @@ protected: //uses the returned pixels from make3DZmap to make a mesh of points whose Z positions are set by the brightness values in ofPixels - ofPixels is being used as a convenient container for a bunch of z coordinates virtual void setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh); + //HELPER FUNCTIONS - //this is purely for debug purposes and loads old images from middlesborough test + //this is purely for debug/viewing purposes and loads old images from middlesborough test virtual vector getListOfImageFilePaths(string location, string whichAnalysis); + + //splits up the filename and returns the recorded value eg brightness + //EG FILENAME : DIFF_NOISE_7_85.7322.jpg RETURNS : 85.7322 + virtual int getRecordedValueFromFileName(string str); + public: string _name; diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index da1b400..b78677c 100755 --- a/src/CamNoiseAnalysis.cpp +++ b/src/CamNoiseAnalysis.cpp @@ -18,7 +18,7 @@ using Poco::Thread; void CamNoiseAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 200; + DELTA_T_SAVE = 100;//200; NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 100; @@ -59,9 +59,62 @@ void CamNoiseAnalysis::acquire() void CamNoiseAnalysis::synthesise() { - + //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=true; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &CamNoiseAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +} // this runs at frame rate = 33 ms for 30 FPS @@ -128,6 +181,27 @@ void CamNoiseAnalysis::draw() case STATE_DISPLAY_RESULTS: { // display results of the synthesis + // 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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + break; } @@ -151,9 +225,15 @@ void CamNoiseAnalysis::save_cb(Timer& timer) ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(file); + _saved_filenames.push_back(ofToDataPath("")+file); if(_save_cnt >= NUM_SAVE_PER_RUN) _RUN_DONE = true; } +void CamNoiseAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} \ No newline at end of file diff --git a/src/CamNoiseAnalysis.h b/src/CamNoiseAnalysis.h index 79b1ff3..fd33821 100755 --- a/src/CamNoiseAnalysis.h +++ b/src/CamNoiseAnalysis.h @@ -19,16 +19,18 @@ 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; int _run_cnt, _save_cnt; - float c, _frame_cnt, _frame_cnt_max,_save_cnt_max ; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index 3b2f862..a2f4f9e 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -41,11 +41,7 @@ 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 ColorMultiAnalysis::setup(int camWidth, int camHeight) { @@ -98,15 +94,15 @@ void ColorMultiAnalysis::synthesise() 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=true; + bool debug=false; if(debug){ _saved_filenames.clear(); _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); } - + //clear vector so we don't add to it on successive runs + meshes.clear(); for(int i=0;i<_saved_filenames.size()-2;i+=2){ - meshes.push_back(ofMesh()); ofImage image1; ofImage image2; @@ -116,6 +112,7 @@ void ColorMultiAnalysis::synthesise() //some of the textures are not loading correctly so only make mesh if both the images load if(image1.loadImage(_saved_filenames[0]) && image2.loadImage(_saved_filenames[i+1])){ cout<<"setting mesh"< 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 = new Timer(0, 20); // timing interval for saving files display_results_timer->start(display_results_callback); _RUN_DONE = false; _results_cnt=0; diff --git a/src/DiffNoiseAnalysis.cpp b/src/DiffNoiseAnalysis.cpp index a2a32cf..fb6587f 100755 --- a/src/DiffNoiseAnalysis.cpp +++ b/src/DiffNoiseAnalysis.cpp @@ -18,7 +18,7 @@ using Poco::Thread; void DiffNoiseAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 600; // right number is about 450 + DELTA_T_SAVE = 100;//600; // right number is about 450 NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 50; @@ -59,11 +59,63 @@ void DiffNoiseAnalysis::acquire() void DiffNoiseAnalysis::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=true; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &DiffNoiseAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +}// this runs at frame rate = 33 ms for 30 FPS -// this runs at frame rate = 33 ms for 30 FPS void DiffNoiseAnalysis::draw() { switch (_state) { @@ -144,6 +196,28 @@ void DiffNoiseAnalysis::draw() case STATE_DISPLAY_RESULTS: { // display results of the synthesis + // 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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + + break; } @@ -178,7 +252,7 @@ void DiffNoiseAnalysis::save_cb(Timer& timer) ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(file); + _saved_filenames.push_back(ofToDataPath("")+file); } _save_cnt++; @@ -186,3 +260,11 @@ void DiffNoiseAnalysis::save_cb(Timer& timer) _RUN_DONE = true; } +void DiffNoiseAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + + diff --git a/src/DiffNoiseAnalysis.h b/src/DiffNoiseAnalysis.h index 93d57ae..17c9ab2 100755 --- a/src/DiffNoiseAnalysis.h +++ b/src/DiffNoiseAnalysis.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; int _run_cnt, _save_cnt, _fade_cnt; - float c, _frame_cnt, _frame_cnt_max; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index 624f78e..8ba948b 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -15,12 +15,14 @@ using Poco::Timer; using Poco::TimerCallback; using Poco::Thread; + + void IResponseAnalysis::setup(int camWidth, int camHeight) { DELTA_T_SAVE = 100; NUM_PHASE = 1; NUM_RUN = 1; - NUM_SAVE_PER_RUN = 100; + NUM_SAVE_PER_RUN = 50;//100; create_dir(); _frame_cnt = 0; @@ -55,11 +57,65 @@ void IResponseAnalysis::acquire() } } + void IResponseAnalysis::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=true; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &IResponseAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +} // this runs at frame rate = 33 ms for 30 FPS @@ -88,6 +144,7 @@ void IResponseAnalysis::draw() case STATE_SYNTHESISING: { + // display animation of something while the synthesis in on-going... break; } @@ -95,6 +152,26 @@ void IResponseAnalysis::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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + break; } @@ -118,9 +195,18 @@ void IResponseAnalysis::save_cb(Timer& timer) //RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera // fileName = imageSaveFolderPath+whichAnalysis+"_"+ofToString(100.0*i*scanLineSpeed/ofGetHeight(),2)+"%_"+ofToString(i)+".jpg"; //ofSaveImage(vectorOfPixels[i], fileName, OF_IMAGE_QUALITY_BEST); - + _saved_filenames.push_back(ofToDataPath("")+_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); if(_save_cnt >= NUM_SAVE_PER_RUN) _RUN_DONE = true; } +void IResponseAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + + diff --git a/src/IResponseAnalysis.h b/src/IResponseAnalysis.h index 07e2c95..b4fb710 100755 --- a/src/IResponseAnalysis.h +++ b/src/IResponseAnalysis.h @@ -19,16 +19,18 @@ 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; int _run_cnt, _save_cnt; - float c, _frame_cnt, _frame_cnt_max; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; diff --git a/src/RelaxRateAnalysis.cpp b/src/RelaxRateAnalysis.cpp index bc210e8..273ccbb 100755 --- a/src/RelaxRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -18,10 +18,10 @@ using Poco::Thread; void RelaxRateAnalysis::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; + NUM_SAVE_PER_RUN = 50;//100; create_dir(); @@ -61,8 +61,62 @@ void RelaxRateAnalysis::acquire() void RelaxRateAnalysis::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=true; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &RelaxRateAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +} + // this runs at frame rate = 33 ms for 30 FPS void RelaxRateAnalysis::draw() @@ -111,6 +165,27 @@ void RelaxRateAnalysis::draw() case STATE_DISPLAY_RESULTS: { // display results of the synthesis + // 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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + break; } @@ -136,9 +211,16 @@ void RelaxRateAnalysis::save_cb(Timer& timer) ofSaveImage(RefractiveIndex::_pixels, file, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(file); + _saved_filenames.push_back(ofToDataPath("")+file); if(_save_cnt >= NUM_SAVE_PER_RUN) _RUN_DONE = true; } +void RelaxRateAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + diff --git a/src/RelaxRateAnalysis.h b/src/RelaxRateAnalysis.h index 0a38e5c..cd89eac 100755 --- a/src/RelaxRateAnalysis.h +++ b/src/RelaxRateAnalysis.h @@ -20,16 +20,18 @@ 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; float _flip, _level; int _run_cnt, _save_cnt; - float c, _frame_cnt, _frame_cnt_max; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; diff --git a/src/ShadowScapesAnalysis.cpp b/src/ShadowScapesAnalysis.cpp index f3b64a5..52f3e9b 100755 --- a/src/ShadowScapesAnalysis.cpp +++ b/src/ShadowScapesAnalysis.cpp @@ -89,10 +89,62 @@ void ShadowScapesAnalysis::acquire() void ShadowScapesAnalysis::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); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &ShadowScapesAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + +} // the animation draw - and the output draw void ShadowScapesAnalysis::draw() { @@ -191,13 +243,33 @@ void ShadowScapesAnalysis::draw() { // display animation of something while the synthesis in on-going... - _state = STATE_DISPLAY_RESULTS; break; } case STATE_DISPLAY_RESULTS: { // display results of the synthesis + // 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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + break; } @@ -225,8 +297,16 @@ void ShadowScapesAnalysis::save_cb(Timer& timer) if(_dir == D) { file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg"; } - + _saved_filenames.push_back(ofToDataPath("")+_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); _save_cnt++; - + } +void ShadowScapesAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + diff --git a/src/ShadowScapesAnalysis.h b/src/ShadowScapesAnalysis.h index f30258b..eb6f62a 100755 --- a/src/ShadowScapesAnalysis.h +++ b/src/ShadowScapesAnalysis.h @@ -51,10 +51,12 @@ 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: @@ -65,6 +67,6 @@ protected: float _step; shadow_type _dir; int _run_cnt, _save_cnt; - float c, _frame_cnt, _frame_cnt_max; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; \ No newline at end of file diff --git a/src/ShapeFromShadingAnalysis.cpp b/src/ShapeFromShadingAnalysis.cpp index 4736499..010c40a 100755 --- a/src/ShapeFromShadingAnalysis.cpp +++ b/src/ShapeFromShadingAnalysis.cpp @@ -77,9 +77,64 @@ void ShapeFromShadingAnalysis::acquire() } } + void ShapeFromShadingAnalysis::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); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &ShapeFromShadingAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + } // this runs at frame rate = 33 ms for 30 FPS @@ -323,6 +378,26 @@ void ShapeFromShadingAnalysis::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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + break; } @@ -340,7 +415,8 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer) //cout << "ShapeFromShadingAnalysis::saving...\n"; string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg"; - + _saved_filenames.push_back(ofToDataPath("")+_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); _save_cnt++; @@ -348,3 +424,11 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer) _RUN_DONE = true; } +void ShapeFromShadingAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + + diff --git a/src/ShapeFromShadingAnalysis.h b/src/ShapeFromShadingAnalysis.h index e1c4b0c..811b66b 100755 --- a/src/ShapeFromShadingAnalysis.h +++ b/src/ShapeFromShadingAnalysis.h @@ -20,10 +20,12 @@ 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: @@ -48,6 +50,6 @@ protected: int _animation_cnt15; int _animation_cnt16; int _animation_reset; // this reset part didn't get working - so using 16 different counters! yay! - float c, _frame_cnt, _frame_cnt_max; + float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max; }; diff --git a/src/StrobeAnalysis.cpp b/src/StrobeAnalysis.cpp index 4680699..42a3edb 100755 --- a/src/StrobeAnalysis.cpp +++ b/src/StrobeAnalysis.cpp @@ -64,7 +64,61 @@ void StrobeAnalysis::acquire() void StrobeAnalysis::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); + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(int i=0;i<_saved_filenames.size()-1;i++){ + + + 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[i]) && image2.loadImage(_saved_filenames[i+1])){ + meshes.push_back(ofMesh()); + cout<<"setting mesh"< display_results_callback(*this, &StrobeAnalysis::display_results_cb); + // display results of the synthesis + + display_results_timer = new Timer(0, 20); // timing interval for saving files + display_results_timer->start(display_results_callback); + _RUN_DONE = false; + _results_cnt=0; + _results_cnt_max=300; + + while(!_RUN_DONE) + Thread::sleep(3); + + display_results_timer->stop(); + } // this runs at frame rate = 33 ms for 30 FPS @@ -132,6 +186,26 @@ void StrobeAnalysis::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; + cout<meshes.size() -1 || whichMesh<0){ + speed*=-1; + whichMesh+=speed; + + } + break; } @@ -146,6 +220,8 @@ void StrobeAnalysis::draw() void StrobeAnalysis::save_cb(Timer& timer) { string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg"; + _saved_filenames.push_back(ofToDataPath("")+_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); _save_cnt++; @@ -159,3 +235,12 @@ void StrobeAnalysis::save_cb(Timer& timer) } } + +void StrobeAnalysis::display_results_cb(Timer& timer){ + _results_cnt++; + if (_results_cnt>_results_cnt_max) { + _RUN_DONE=true; + } +} + + diff --git a/src/StrobeAnalysis.h b/src/StrobeAnalysis.h index ca1cf93..b453c11 100755 --- a/src/StrobeAnalysis.h +++ b/src/StrobeAnalysis.h @@ -20,10 +20,12 @@ 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: @@ -32,6 +34,8 @@ protected: int _save_cnt; int _frame_cnt, _frame_cnt_max, _save_cnt_max ; + float _results_cnt, _results_cnt_max; + int _strobe_interval; bool _strobe_on; };