diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index 9623d1b..16f8144 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -34,6 +34,9 @@ #include "RefractiveIndex.h" #include "ofxFileHelper.h" + +vector AbstractAnalysis::meshes; + // this is the main threaded loop for a given analysis void AbstractAnalysis::do_synthesize() { _state = STATE_ACQUIRING; @@ -41,6 +44,7 @@ void AbstractAnalysis::do_synthesize() { _state = STATE_SYNTHESISING; synthesise(); _state = STATE_DISPLAY_RESULTS; + display_results(); ofNotifyEvent(_synthesize_cb, _name); } @@ -143,7 +147,70 @@ ofPixels AbstractAnalysis::calculateListOfZValues(ofImage image1, ofImage image2 } -void AbstractAnalysis:: setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh){ +ofPixels AbstractAnalysis::calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison, int colourValue){ + //zScale is the mapping factor from pixel difference to shift on the zPlane + int zScale=200; + + ofPixels imagePixels1 = image1.getPixelsRef(); + ofPixels imagePixels2 = image2.getPixelsRef(); + + ofPixels difference; + //this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly? + unsigned char * thesePixels = new unsigned char[ imagePixels1.getWidth()*imagePixels1.getHeight()*3]; + + //where are we in the image pixel array + int x=0; + int y=0; + + //for each pixel... + for(int i=0;iimagePixels1.getWidth()){ + x=0; + y++; + + } + } + + difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3); + + return difference; + +} + +void AbstractAnalysis::setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh){ int x=0; int y=0; @@ -165,3 +232,87 @@ void AbstractAnalysis:: setMeshFromPixels(ofPixels somePixels, ofImage currentSe } } + +vectorAbstractAnalysis:: getListOfImageFilePaths(string location, string whichAnalysis){ + + string path = ofToDataPath("")+"debug_analysis/"+location+"/"+whichAnalysis; + //ofxDirList dirList; + ofDirectory dirList; + int numDirs = dirList.listDir(path); + + vectordirectoryNames; + + //get the last folder alphabetically - this should probably change to do something fancy with date to find most recent but don't want to code that until we are sure + string dirName=dirList.getName(numDirs-1); + + + const char *results=dirName.c_str(); + + ofFile file=ofFile(path+"/"+dirName); + vectorfileNamesToReturn; + + + // get + if(file.isDirectory()){ + dirList.listDir(path+"/"+dirName); + //if there are no files, exit here + if(dirList.size()==0){ + //if it's empty return an error warning + fileNamesToReturn.push_back("NO FILE HERE!"); + cout<<"NO FILE HERE!"; + return fileNamesToReturn; + } + for (int i=0; itokens; + //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 a7da748..5131112 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: @@ -39,11 +45,28 @@ protected: // analysis + synthesize images - all the children (see - do_synthesize) virtual void synthesise() = 0; + + //added tom s 19/2 function runs a call back exactly like acquire. + virtual void display_results() = 0; + //returns ofPixels which contain the color differences between the two images. Is overloaded to include comparison with values written in to file names for some analyses virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison); + virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison, int colourValue); + //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/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); + + static vectormeshes; + + public: string _name; @@ -64,7 +87,7 @@ protected: //added Tom S 19/2/12 //each mesh in the vector is a seperate 3D point cloud which is coloured with pixel data and shifted in the z plane according to the specified type of colour difference eg red value or hue - vectormeshes; + //make this vector were static //how fast to move from one mesh to the next float speed; //the index (inside the vector of meshes) of the current mesh being displayed diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index c737e9a..81eb861 100755 --- a/src/CamNoiseAnalysis.cpp +++ b/src/CamNoiseAnalysis.cpp @@ -59,9 +59,68 @@ 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; + float iterator=1; + //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); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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 @@ -136,6 +195,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; } @@ -159,9 +239,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; + } +} 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 7d97f12..29482bb 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -41,15 +41,11 @@ 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) { - DELTA_T_SAVE = 50;//150; // the right number is about 300 + DELTA_T_SAVE = 100;//150; // the right number is about 300 NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 100;//; @@ -90,34 +86,64 @@ 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]<100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + 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[0]) && image2.loadImage(_saved_filenames[i+1])){ + cout<<"setting mesh"< 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() { @@ -182,12 +208,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; } @@ -213,10 +258,14 @@ void ColorMultiAnalysis::save_cb(Timer& timer) // cout<<_whole_file_path<>>>>>> tom if(_save_cnt >= NUM_SAVE_PER_RUN){ _RUN_DONE = true; } @@ -227,3 +276,11 @@ void ColorMultiAnalysis::save_cb(Timer& timer) //} >>>>>>> 88fa0375934e9ad87053542e88a0f9fe61af0a66 } + +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 0ee5153..49a2f07 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -18,7 +18,7 @@ using Poco::Thread; 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 +64,72 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + 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()); + + 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, 20); // 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() { @@ -142,6 +205,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; } @@ -160,11 +242,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; }; diff --git a/src/DiffNoiseAnalysis.cpp b/src/DiffNoiseAnalysis.cpp index 54e635b..7a13e62 100755 --- a/src/DiffNoiseAnalysis.cpp +++ b/src/DiffNoiseAnalysis.cpp @@ -59,11 +59,68 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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) { @@ -154,6 +211,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; } @@ -188,7 +267,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++; @@ -196,3 +275,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 efa0e96..0ae3ca7 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -15,6 +15,8 @@ using Poco::Timer; using Poco::TimerCallback; using Poco::Thread; + + void IResponseAnalysis::setup(int camWidth, int camHeight) { DELTA_T_SAVE = 100; @@ -55,11 +57,70 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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 @@ -90,6 +151,7 @@ void IResponseAnalysis::draw() case STATE_SYNTHESISING: { + // display animation of something while the synthesis in on-going... break; } @@ -97,6 +159,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; } @@ -120,9 +202,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 521e049..759176f 100755 --- a/src/RelaxRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -18,7 +18,7 @@ using Poco::Thread; void RelaxRateAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 300; + DELTA_T_SAVE = 130; NUM_PHASE = 1; NUM_RUN = 3; NUM_SAVE_PER_RUN = 100; @@ -61,8 +61,67 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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() @@ -112,6 +171,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; } @@ -137,9 +217,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 c39a34f..3da5f7e 100755 --- a/src/ShadowScapesAnalysis.cpp +++ b/src/ShadowScapesAnalysis.cpp @@ -89,10 +89,67 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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 +248,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 +302,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 5bb67dd..882a14a 100755 --- a/src/ShapeFromShadingAnalysis.cpp +++ b/src/ShapeFromShadingAnalysis.cpp @@ -77,9 +77,69 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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 +383,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 +420,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 +429,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 5778165..a4f81c2 100755 --- a/src/StrobeAnalysis.cpp +++ b/src/StrobeAnalysis.cpp @@ -64,7 +64,66 @@ 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; + float iterator=1; + bool debug=false; + if(debug){ + _saved_filenames.clear(); + _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); + + //hack to limit number of meshes. + if(_saved_filenames.size()>100){ + iterator= _saved_filenames.size() /100; + } + + } + //clear vector so we don't add to it on successive runs + meshes.clear(); + + for(float i=0;i<_saved_filenames.size()-1;i+=iterator){ + + + 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 @@ -139,6 +198,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; } @@ -153,6 +232,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++; @@ -166,3 +247,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; };