diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index 4957be5..03e38f9 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -10,13 +10,14 @@ #include "RefractiveIndex.h" -#include "IResponseAnalysis.h" #include "ShadowScapesAnalysis.h" -#include "ColorMultiAnalysis.h" -#include "ColorSingleAnalysis.h" -#include "CamFrameRateAnalysis.h" +#include "RelaxRateAnalysis.h" +#include "IResponseAnalysis.h" +#include "ShapeFromShadingAnalysis.h" +#include "StrobeAnalysis.h" #include "CamNoiseAnalysis.h" -#include "LatencyTestAnalysis.h" +#include "ColorSingleAnalysis.h" +#include "ColorMultiAnalysis.h" #include "DiffNoiseAnalysis.h" #include "ofxXmlSettings.h" @@ -94,17 +95,29 @@ void RefractiveIndex::setup() //void ofPixels::allocate(int w, int h, ofImageType type) - // setup analysis + //TODO: whichever one of these is first - it always runs twice ? + + // _analysisVector.push_back(new ShadowScapesAnalysis(V)); + // _analysisVector.push_back(new ShadowScapesAnalysis(H)); + // _analysisVector.push_back(new ShadowScapesAnalysis(D)); + + // _analysisVector.push_back(new RelaxRateAnalysis()); + + // _analysisVector.push_back(new IResponseAnalysis()); + + _analysisVector.push_back(new ShapeFromShadingAnalysis()); + + // _analysisVector.push_back(new StrobeAnalysis()); + + // _analysisVector.push_back(new CamNoiseAnalysis()); + + // _analysisVector.push_back(new ColorSingleAnalysis()); + + // _analysisVector.push_back(new ColorMultiAnalysis()); - _analysisVector.push_back(new ShadowScapesAnalysis()); - _analysisVector.push_back(new IResponseAnalysis()); - _analysisVector.push_back(new ColorMultiAnalysis()); - _analysisVector.push_back(new CamFrameRateAnalysis()); - _analysisVector.push_back(new CamNoiseAnalysis()); - _analysisVector.push_back(new ColorSingleAnalysis()); - _analysisVector.push_back(new LatencyTestAnalysis()); _analysisVector.push_back(new DiffNoiseAnalysis()); - + + _currentAnalysisIndx = 0; _currentAnalysis = _analysisVector.at(_currentAnalysisIndx); diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index 41132a8..4d8b78d 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -32,6 +32,7 @@ #include "AbstractAnalysis.h" #include "RefractiveIndex.h" +#include "ofxFileHelper.h" // this is the main threaded loop for a given analysis void AbstractAnalysis::do_synthesize() { @@ -65,15 +66,16 @@ void AbstractAnalysis::create_dir() replaceTime+=time.at(i); } } + + ofxFileHelper fileHelper; + _whole_file_path = ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ; + //cout << "_whole_file_path = " << _whole_file_path << endl; - ofDirectory dir; - - _whole_file_path= string(ANALYSIS_PATH)+ RefractiveIndex::_location+"/"+ _name+"/"+replaceTime ; - //directories have to be created one level at a time hence repeated calls - if(!dir.doesDirectoryExist(_whole_file_path)){ - dir.createDirectory(string(ANALYSIS_PATH)+RefractiveIndex::_location+"/", true,false); - dir.createDirectory(string(ANALYSIS_PATH)+RefractiveIndex::_location+"/"+ _name+"/", true,false); - dir.createDirectory(string(ANALYSIS_PATH)+RefractiveIndex::_location+"/"+ _name+"/"+replaceTime+"/", true,false); + if(!fileHelper.doesDirectoryExist(_whole_file_path)){ + fileHelper.makeDirectory(ANALYSIS_PATH); + fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location); + fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name); + fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime); } //////////////////////////////END DIRECTORY CREATION ////////////////////////////////////////////////// diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index 67fa8fd..b61757c 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 = 100; + DELTA_T_SAVE = 200; NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 100; @@ -67,7 +67,6 @@ void CamNoiseAnalysis::synthesise() // this runs at frame rate = 33 ms for 30 FPS void CamNoiseAnalysis::draw() { - switch (_state) { case STATE_ACQUIRING: { @@ -75,22 +74,47 @@ void CamNoiseAnalysis::draw() // still need to deal with latency frames here - i.e.: there are frames /// *** TODO *** /// - float _number_of_grey_levels=5; + ofEnableAlphaBlending(); + ofColor aColour; + + int _fade_in_frames = _frame_cnt_max/10; + float _number_of_grey_levels=10; float _frames_per_level = _frame_cnt_max / _number_of_grey_levels; ofColor someColor; - for(int i=0;i<=_number_of_grey_levels;i++){ - if (_frame_cnt>= _frames_per_level *( i-1) && +_frame_cnt < _frames_per_level * (i) ) { - //set colour to current grey level - c=255-( 255.0 * ( i /_number_of_grey_levels)); - someColor.set(c); - - } - ofSetColor(someColor); + if (_frame_cnt < _fade_in_frames) { + aColour.set(255, 255, 255, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + ofSetColor(aColour); ofRect(0, 0, ofGetWidth(), ofGetHeight()); + //cout << "FADE IN STROBE TIME " << endl; } + + if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){ + + + for(int i=0;i<_number_of_grey_levels;i++){ + if (_frame_cnt>= _frames_per_level *( i-1) && +_frame_cnt < _frames_per_level * (i) ) { + //set colour to current grey level + c=255-( 255.0 * ( i /_number_of_grey_levels)); + someColor.set(c); + } + ofSetColor(someColor); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + } + + } + + if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) { + aColour.set(0, 0, 0, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + ofSetColor(aColour); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + // cout << "FADE OUT STROBE TIME " << endl; + } + + _frame_cnt++; + ofDisableAlphaBlending(); break; } diff --git a/src/CamNoiseAnalysis.h b/src/CamNoiseAnalysis.h index ed50f1e..79b1ff3 100755 --- a/src/CamNoiseAnalysis.h +++ b/src/CamNoiseAnalysis.h @@ -28,6 +28,7 @@ protected: bool _RUN_DONE; int _run_cnt, _save_cnt; - float c, _frame_cnt, _frame_cnt_max; + float c, _frame_cnt, _frame_cnt_max,_save_cnt_max ; + }; diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index 32e3caa..322dc00 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -45,13 +45,14 @@ using Poco::Thread; void ColorMultiAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 100; + DELTA_T_SAVE = 150; // the right number is about 300 NUM_PHASE = 1; NUM_RUN = 1; - NUM_SAVE_PER_RUN = 100; + NUM_SAVE_PER_RUN = 300; create_dir(); _frame_cnt = 0; + _fade_cnt=0; _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); c = 0; } @@ -95,15 +96,46 @@ void ColorMultiAnalysis::draw() switch (_state) { case STATE_ACQUIRING: { - if (_frame_cnt < _frame_cnt_max) { + int _fade_in_frames = _frame_cnt_max/50; + + if (_frame_cnt < _fade_in_frames) { + ofColor aColor; + + aColor.setHsb(c, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255), ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + + ofSetColor(aColor); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + + cout << "FADING IN..." << endl; + } + + if (_frame_cnt >= _fade_in_frames && _frame_cnt < _frame_cnt_max-_fade_in_frames){ + ofColor aColor; aColor.setHsb(c, 255, 255); ofSetColor(aColor); - ofRect(0, 0, ofGetWidth(), ofGetHeight()); - //how far are we as a percent of _frame_count_max + + //how far are we as a percent of _frame_count_max * 360 HUE VALUES c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); + + ofRect(0, 0, ofGetWidth(), ofGetHeight()); } - _frame_cnt++; + + if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) { + + ofColor aColor; + + aColor.setHsb(c, 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255), 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255)); + + ofSetColor(aColor); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + + _fade_cnt++; + cout << "FADING OUT..." << endl; + + } + + _frame_cnt++; break; } @@ -132,22 +164,18 @@ void ColorMultiAnalysis::draw() void ColorMultiAnalysis::save_cb(Timer& timer) { _save_cnt++; - + // UPDATE THE COLOR ON THE SCREEN //float c_last = c; - - cout << "COLORMULTIANALYSIS::saving...\n"; - cout << "c_last... " << c << endl; + + // cout << "COLORMULTIANALYSIS::saving...\n"; + // cout << "c_last... " << c << endl; string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - string file = _whole_file_path+"/"+file_name; - + // cout<<_whole_file_path<= NUM_SAVE_PER_RUN){ _RUN_DONE = true; } - } diff --git a/src/ColorMultiAnalysis.h b/src/ColorMultiAnalysis.h index 39f2591..eff1c3a 100755 --- a/src/ColorMultiAnalysis.h +++ b/src/ColorMultiAnalysis.h @@ -22,6 +22,6 @@ public: protected: bool _RUN_DONE; - int _run_cnt, _save_cnt; + int _run_cnt, _save_cnt, _fade_cnt; float c, _frame_cnt, _frame_cnt_max; }; diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index 4d7641e..18d88a3 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 = 100; + DELTA_T_SAVE = 300; NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 100; @@ -29,6 +29,9 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight) r = 0; g = 0; b = 0; + + _fade_cnt=0; + fileNameTag = ""; } @@ -71,26 +74,50 @@ void ColorSingleAnalysis::draw() case STATE_ACQUIRING: { float one_third_of_frame_count_max=_frame_cnt_max/3; - if (_frame_cnt < one_third_of_frame_count_max){ + + int _fade_in_frames = one_third_of_frame_count_max/10; + + if (_frame_cnt < _fade_in_frames){ + ofSetColor(ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255), 0, 0); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + fileNameTag = "FADING"; + } + + if (_frame_cnt >= _fade_in_frames && _frame_cnt < one_third_of_frame_count_max){ r=255.0; g=0.0; b=0.0; ofSetColor(r,g,b); ofRect(0, 0, ofGetWidth(), ofGetHeight()); + fileNameTag = "RED"; } + if (_frame_cnt >= one_third_of_frame_count_max && _frame_cnt < 2*one_third_of_frame_count_max){ r=0.0; g=255.0; b=0.0; ofSetColor(r,g,b); ofRect(0, 0, ofGetWidth(), ofGetHeight()); + fileNameTag = "GREEN"; } - if (_frame_cnt >= 2*one_third_of_frame_count_max && _frame_cnt < _frame_cnt_max){ + + if (_frame_cnt >= 2*one_third_of_frame_count_max && _frame_cnt < (_frame_cnt_max-_fade_in_frames) ){ r=0.0; g=0.0; b=255.0; ofSetColor(r,g,b); ofRect(0, 0, ofGetWidth(), ofGetHeight()); + fileNameTag = "BLUE"; + } + + if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max){ + + ofSetColor(0, 0, 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255)); + cout << "255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)"<< 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255) << endl; + + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + _fade_cnt++; + fileNameTag = "FADING"; } _frame_cnt++; @@ -122,19 +149,15 @@ void ColorSingleAnalysis::draw() void ColorSingleAnalysis::save_cb(Timer& timer) { _save_cnt++; - - - cout << "ColorSingleAnalysis::saving...\n"; - string file_name =ofToString(_frame_cnt,2)+"_"+ofToString((int)r,2)+"_"+ofToString((int)g,2)+"_"+ofToString((int)b,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - - string file = _whole_file_path+"/"+file_name; - + + // cout << "ColorSingleAnalysis::saving...\n"; + + string file_name =ofToString(_save_cnt,2)+"_"+fileNameTag+"_"+ofToString(_run_cnt,2)+".jpg"; + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(file); + //cout<<_whole_file_path+"/"+file_name<= NUM_SAVE_PER_RUN) _RUN_DONE = true; diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index f2c3614..0772c43 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -25,9 +25,9 @@ public: void save_cb(Poco::Timer& timer); protected: - + bool _RUN_DONE; - int _run_cnt, _save_cnt; + string fileNameTag; + int _run_cnt, _save_cnt, _fade_cnt; float r,g,b, _frame_cnt, _frame_cnt_max; - }; diff --git a/src/DiffNoiseAnalysis.cpp b/src/DiffNoiseAnalysis.cpp index f157030..a2a32cf 100755 --- a/src/DiffNoiseAnalysis.cpp +++ b/src/DiffNoiseAnalysis.cpp @@ -18,12 +18,13 @@ using Poco::Thread; void DiffNoiseAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 100; + DELTA_T_SAVE = 600; // right number is about 450 NUM_PHASE = 1; NUM_RUN = 1; - NUM_SAVE_PER_RUN = 100; + NUM_SAVE_PER_RUN = 50; create_dir(); + _fade_cnt=0; _frame_cnt = 0; _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); c = 0; @@ -68,19 +69,67 @@ void DiffNoiseAnalysis::draw() switch (_state) { case STATE_ACQUIRING: { - /// *** TODO *** /// - // still need to deal with latency frames here - i.e.: there are frames - /// *** TODO *** /// ofColor aColour; + int rectSize = 5; + ofEnableAlphaBlending(); - c = ofRandom(0,255); - aColour.setHsb(c, 255, 255); - if (_frame_cnt < _frame_cnt_max) - { - ofSetColor(aColour); - ofRect(0, 0, ofGetWidth(), ofGetHeight()); + int _fade_in_frames = _frame_cnt_max/10; + + if (_frame_cnt < _fade_in_frames) { + + for (int i=1; i < ofGetHeight() ; i=i+rectSize) + { + for (int j=1; j < ofGetWidth(); j=j+rectSize) + { + c = ofRandom(0,255); + aColour.set(c, c, c, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + ofSetColor(aColour); + ofRect(j, i, rectSize, rectSize); + } + } + + cout << "FADING IN..." << endl; + } + + + + if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){ + + for (int i=1; i < ofGetHeight() ; i=i+rectSize) + { + for (int j=1; j < ofGetWidth(); j=j+rectSize) + { + c = ofRandom(0,255); + aColour.set(c, c, c, 255); + ofSetColor(aColour); + ofRect(j, i, rectSize, rectSize); + + } + } + } + + + if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) { + + for (int i=1; i < ofGetHeight() ; i=i+rectSize) + { + for (int j=1; j < ofGetWidth(); j=j+rectSize) + { + c = ofRandom(0,255); + aColour.set(c, c, c, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + ofSetColor(aColour); + ofRect(j, i, rectSize, rectSize); + } + } + + _fade_cnt++; + cout << "FADING OUT..." << endl; } + + + ofDisableAlphaBlending(); + _frame_cnt++; break; diff --git a/src/DiffNoiseAnalysis.h b/src/DiffNoiseAnalysis.h index 90164ab..93d57ae 100755 --- a/src/DiffNoiseAnalysis.h +++ b/src/DiffNoiseAnalysis.h @@ -27,7 +27,7 @@ public: protected: bool _RUN_DONE; - int _run_cnt, _save_cnt; + int _run_cnt, _save_cnt, _fade_cnt; float c, _frame_cnt, _frame_cnt_max; }; diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index bf18312..624f78e 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -67,6 +67,7 @@ void IResponseAnalysis::draw() { switch (_state) { + case STATE_ACQUIRING: { /// *** TODO *** /// @@ -77,11 +78,11 @@ void IResponseAnalysis::draw() { ofSetColor(c, c, c); ofRect(0, 0, ofGetWidth(), ofGetHeight()); - c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); + c = 255.0 * (_frame_cnt_max*_frame_cnt_max - _frame_cnt*_frame_cnt)/(_frame_cnt_max*_frame_cnt_max); } _frame_cnt++; - + break; } @@ -108,26 +109,18 @@ void IResponseAnalysis::draw() void IResponseAnalysis::save_cb(Timer& timer) { _save_cnt++; - - // UPDATE THE COLOR ON THE SCREEN - //float c_last = c; - + cout << "IResponseAnalysis::saving...\n"; - cout << "c_last... " << c << endl; + //cout << "c_last... " << c << endl; string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; string thisLocation = RefractiveIndex::_location; - + //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); - string file = _whole_file_path+"/"+file_name; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(file); - if(_save_cnt >= NUM_SAVE_PER_RUN) _RUN_DONE = true; - } diff --git a/src/IResponseAnalysis.h b/src/IResponseAnalysis.h index 3a61a5f..07e2c95 100755 --- a/src/IResponseAnalysis.h +++ b/src/IResponseAnalysis.h @@ -29,5 +29,6 @@ protected: bool _RUN_DONE; int _run_cnt, _save_cnt; float c, _frame_cnt, _frame_cnt_max; + }; diff --git a/src/LatencyTestAnalysis.cpp b/src/LatencyTestAnalysis.cpp deleted file mode 100755 index a397f58..0000000 --- a/src/LatencyTestAnalysis.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - ~ author: dviid - ~ contact: dviid@labs.ciid.dk - */ - -#include "LatencyTestAnalysis.h" -#include "ofMain.h" - -#include "Poco/Timer.h" -#include "Poco/Thread.h" - -#include "RefractiveIndex.h" - -using Poco::Timer; -using Poco::TimerCallback; -using Poco::Thread; - - -void LatencyTestAnalysis::setup(int camWidth, int camHeight) -{ - DELTA_T_SAVE = 100; - NUM_PHASE = 1; - NUM_RUN = 1; - NUM_SAVE_PER_RUN = 100; - - create_dir(); - _frame_cnt = 0; - _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); - c = 0; -} - - -void LatencyTestAnalysis::acquire() -{ - - Timer* save_timer; - - TimerCallback save_callback(*this, &LatencyTestAnalysis::save_cb); - - // RUN ROUTINE - for(int i = 0; i < NUM_RUN; i++) { - - _run_cnt = i; - - cout << "RUN NUM = " << i; - - save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files - save_timer->start(save_callback); - _RUN_DONE = false; - _frame_cnt = 0; _save_cnt = 0; - - while(!_RUN_DONE) - Thread::sleep(3); - - save_timer->stop(); - } -} - -void LatencyTestAnalysis::synthesise() -{ - // _saved_filenames has all the file names of all the saved images -} - - -// this runs at frame rate = 33 ms for 30 FPS -void LatencyTestAnalysis::draw() -{ - - switch (_state) { - case STATE_ACQUIRING: - { - /// *** TODO *** /// - // still need to deal with latency frames here - i.e.: there are frames - /// *** TODO *** /// - - if (_frame_cnt < _frame_cnt_max/3) - { - c = 0; - - ofSetColor(c, c, c); - cout<<"1st third"<= _frame_cnt_max/3 && _frame_cnt < 2*( _frame_cnt_max/3)) - { - c = 255; - cout<<"2nd third"<= 2*( _frame_cnt_max/3) && _frame_cnt < _frame_cnt_max) - { - c = 0; - cout<<"3rd third"<= NUM_SAVE_PER_RUN) - _RUN_DONE = true; - -} diff --git a/src/CamFrameRateAnalysis.cpp b/src/RelaxRateAnalysis.cpp similarity index 67% rename from src/CamFrameRateAnalysis.cpp rename to src/RelaxRateAnalysis.cpp index ebc22ab..bc210e8 100755 --- a/src/CamFrameRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -3,7 +3,7 @@ ~ contact: dviid@labs.ciid.dk */ -#include "CamFrameRateAnalysis.h" +#include "RelaxRateAnalysis.h" #include "ofMain.h" #include "Poco/Timer.h" @@ -16,27 +16,29 @@ using Poco::TimerCallback; using Poco::Thread; -void CamFrameRateAnalysis::setup(int camWidth, int camHeight) +void RelaxRateAnalysis::setup(int camWidth, int camHeight) { - DELTA_T_SAVE = 1000/30; + DELTA_T_SAVE = 300; NUM_PHASE = 1; NUM_RUN = 1; NUM_SAVE_PER_RUN = 100; create_dir(); + _level = 0; + _flip = 1; _frame_cnt = 0; _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); - c = 0; + c = 0; } -void CamFrameRateAnalysis::acquire() +void RelaxRateAnalysis::acquire() { Timer* save_timer; - TimerCallback save_callback(*this, &CamFrameRateAnalysis::save_cb); + TimerCallback save_callback(*this, &RelaxRateAnalysis::save_cb); // RUN ROUTINE for(int i = 0; i < NUM_RUN; i++) { @@ -57,13 +59,13 @@ void CamFrameRateAnalysis::acquire() } } -void CamFrameRateAnalysis::synthesise() +void RelaxRateAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images } // this runs at frame rate = 33 ms for 30 FPS -void CamFrameRateAnalysis::draw() +void RelaxRateAnalysis::draw() { switch (_state) { @@ -72,24 +74,31 @@ void CamFrameRateAnalysis::draw() /// *** TODO *** /// // still need to deal with latency frames here - i.e.: there are frames /// *** TODO *** /// - float totalTime=_frame_cnt_max/2; - - float numSteps=10; - - vectorstepLengths; - - - //c must increase until frame_cnt_max * 0.5 and then decrease afterwards - - - if (_frame_cnt < _frame_cnt_max) + + if (_frame_cnt <= _frame_cnt_max) { + + float lightLevel=pow(_level,2); + ofSetColor(c, c, c); ofRect(0, 0, ofGetWidth(), ofGetHeight()); - c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); - cout<<_frame_cnt< strobe_callback(*this, &ShadowScapesAnalysis::scan_cb); - - _state = STATE_SCAN; - - scan_timer.start(strobe_callback); - - while(_state != STATE_ANALYSIS) - Thread::sleep(5); - - scan_timer.stop(); - // do analysis here - // go back to the files i've saved and do the math here - - - /* - while(_state != STATE_STOP) - Thread::sleep(100); - */ + + // RUN ROUTINE + for(int i = 0; i < NUM_RUN; i++) { + + Timer save_timer(0, DELTA_T_SAVE); + TimerCallback save_callback(*this, &ShadowScapesAnalysis::save_cb); + + _RUN_DONE = false; + _frame_cnt = 0; _save_cnt = 0; + + save_timer.start(save_callback); + + while(!_RUN_DONE) + Thread::sleep(3); + + save_timer.stop(); + } } @@ -92,33 +100,98 @@ void ShadowScapesAnalysis::draw() switch (_state) { case STATE_ACQUIRING: { - static int _pos; + _line += _step; - if(_state == STATE_ANALYSIS) { - ofSetColor(0, 200, 0); - ofRect(0, 0, ofGetWidth(), ofGetHeight()); - return; - } + //cout << "* _line:" << _line << endl; - if(_state == STATE_SCAN) { - if(_pos != _line) { - //take snap?? - _pos = _line; - } - ofSetColor(255, 255, 255); + if(_dir == V) { - if(_dir == H) ofRect(_pos, 0, 50, ofGetHeight()); - else if(_dir == V) ofRect(0, _pos, ofGetWidth(), 50); + ofEnableAlphaBlending(); + + ofSetColor(255, 255, 255); + ofRect(0, (_line-2*_scanLineWidth), ofGetWidth(), _scanLineWidth); + + for (float i=0; i<25; i++) + { + ofSetColor(255, 255, 255, i*5.0); + ofRect(0, (_line-2*_scanLineWidth)+(2*_scanLineWidth/(i+1)), ofGetWidth(), _scanLineWidth); + ofRect(0, (_line-2*_scanLineWidth)-(2*_scanLineWidth/(i+1)), ofGetWidth(), _scanLineWidth); + } + + ofDisableAlphaBlending(); } - + if(_dir == H) { + + ofEnableAlphaBlending(); + + ofSetColor(255, 255, 255); + ofRect( (_line-2*_scanLineWidth), 0, _scanLineWidth, ofGetHeight()); + + for (float i=0; i<25; i++) + { + ofSetColor(255, 255, 255, i*5); + ofRect( (_line-2*_scanLineWidth)+(2*_scanLineWidth/(i+1)), 0, _scanLineWidth, ofGetHeight()); + ofRect( (_line-2*_scanLineWidth)-(2*_scanLineWidth/(i+1)), 0, _scanLineWidth, ofGetHeight()); + } + ofDisableAlphaBlending(); + + } + + if(_dir == D) { + + ofEnableAlphaBlending(); + + ofPushMatrix(); + + ofTranslate(-ofGetWidth(), 0); + ofRotate(-45); + + ofSetColor(255, 255, 255); + ofRect(0, (_line-_scanLineWidth)+ofGetHeight()-_scanLineWidth, 2*ofGetWidth(), _scanLineWidth); + + for (float i=0; i<25; i++) + { + ofSetColor(255, 255, 255, i*5); + ofRect(0, (_line-_scanLineWidth)+ofGetHeight()-_scanLineWidth+(2*_scanLineWidth/(i+1)), 2*ofGetWidth(), _scanLineWidth); + ofRect(0, (_line-_scanLineWidth)+ofGetHeight()-_scanLineWidth-(2*_scanLineWidth/(i+1)), 2*ofGetWidth(), _scanLineWidth); + } + + ofPopMatrix(); + ofDisableAlphaBlending(); + } + + + + if(_dir == V && int(_line) >= (ofGetHeight()+4*_scanLineWidth)){ + cout << "VERTICAL IS DONE - _line >= (ofGetHeight()+4*_scanLineWidth) is TRUE" << endl; + _state = STATE_SYNTHESISING; + _RUN_DONE = true; + } + + if(_dir == H && int(_line) >= (ofGetWidth()+4*_scanLineWidth)) { + + //cout << "HORIZONTAL IS DONE - _line >= (ofGetWidth()+4*_scanLineWidth)) is TRUE" << endl; + _state = STATE_SYNTHESISING; + _RUN_DONE = true; + + } + + if(_dir == D && int(_line) >= (1.5*ofGetHeight()+4*_scanLineWidth)) { + //cout << "DIAGONAL IS DONE - _line >= (1.5*ofGetHeight()+4*_scanLineWidth)) is TRUE" << endl; + _state = STATE_SYNTHESISING; + _RUN_DONE = true; + } + break; } case STATE_SYNTHESISING: { // display animation of something while the synthesis in on-going... + + _state = STATE_DISPLAY_RESULTS; break; } @@ -128,21 +201,32 @@ void ShadowScapesAnalysis::draw() break; } - default: break; } - } -void ShadowScapesAnalysis::scan_cb(Timer& timer) +void ShadowScapesAnalysis::save_cb(Timer& timer) { - _line += _step; - - if((_dir == H && _line >= ofGetWidth()) || - (_dir == V && _line >= ofGetHeight())) { - _state = STATE_ANALYSIS; + + cout << "ShadowScapesAnalysis::saving...\n"; + string file_name; + + if(_dir == H) { + file_name = ofToString(_save_cnt, 2)+"_H_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg"; } + + if(_dir == V) { + file_name = ofToString(_save_cnt, 2)+"_V_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg"; + } + + if(_dir == D) { + file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg"; + } + + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _save_cnt++; + } diff --git a/src/ShadowScapesAnalysis.h b/src/ShadowScapesAnalysis.h index 9519898..f30258b 100755 --- a/src/ShadowScapesAnalysis.h +++ b/src/ShadowScapesAnalysis.h @@ -54,13 +54,17 @@ public: void synthesise(); void draw(); - void scan_cb(Poco::Timer& timer); + void save_cb(Poco::Timer& timer); protected: - int _line; - int _speed; // pix per second - int _step; + bool _RUN_DONE; + float _line; + float _speed; // pix per second + float _scanLineWidth; // pix per second + float _step; shadow_type _dir; + int _run_cnt, _save_cnt; + float c, _frame_cnt, _frame_cnt_max; }; \ No newline at end of file diff --git a/src/ShapeFromShadingAnalysis.cpp b/src/ShapeFromShadingAnalysis.cpp new file mode 100755 index 0000000..4736499 --- /dev/null +++ b/src/ShapeFromShadingAnalysis.cpp @@ -0,0 +1,350 @@ +/* + ~ author: dviid + ~ contact: dviid@labs.ciid.dk + */ + +#include "ShapeFromShadingAnalysis.h" +#include "ofMain.h" + +#include "Poco/Timer.h" +#include "Poco/Thread.h" + +#include "RefractiveIndex.h" + +using Poco::Timer; +using Poco::TimerCallback; +using Poco::Thread; + + +void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight) +{ + DELTA_T_SAVE = 300; + NUM_PHASE = 1; + NUM_RUN = 1; + NUM_SAVE_PER_RUN = 100; + + create_dir(); + + _level = 0; + _flip = 1; + _frame_cnt = 0; + + _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); + c = 0; +} + + +void ShapeFromShadingAnalysis::acquire() +{ + + Timer* save_timer; + + TimerCallback save_callback(*this, &ShapeFromShadingAnalysis::save_cb); + + // RUN ROUTINE + for(int i = 0; i < NUM_RUN; i++) { + + _run_cnt = i; + + cout << "RUN NUM = " << i; + + save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files + save_timer->start(save_callback); + _RUN_DONE = false; + _frame_cnt = 0; _save_cnt = 0; + _animation_cnt1 = 0; + _animation_cnt2 = 0; + _animation_cnt3 = 0; + _animation_cnt4 = 0; + _animation_cnt5 = 0; + _animation_cnt6 = 0; + _animation_cnt7 = 0; + _animation_cnt8 = 0; + _animation_cnt9 = 0; + _animation_cnt10 = 0; + _animation_cnt11 = 0; + _animation_cnt12 = 0; + _animation_cnt13 = 0; + _animation_cnt14 = 0; + _animation_cnt15 = 0; + _animation_cnt16 = 0; + _animation_reset = false; // coundn't get this to work - so using seperate counters - shitty! + + while(!_RUN_DONE) + Thread::sleep(3); + + save_timer->stop(); + } +} + +void ShapeFromShadingAnalysis::synthesise() +{ + // _saved_filenames has all the file names of all the saved images +} + +// this runs at frame rate = 33 ms for 30 FPS +void ShapeFromShadingAnalysis::draw() +{ + + switch (_state) { + case STATE_ACQUIRING: + { + if (_frame_cnt <= _frame_cnt_max) + { + + ofEnableAlphaBlending(); + + + int _quarter_frame_cnt_max = _frame_cnt_max/4; + int _half_frame_cnt_max = _frame_cnt_max/2; + int _threequarters_frame_cnt_max = 3*_frame_cnt_max/4; + + //TODO: put in CROSS FADES, ETC§E + + /* + if (_animation_reset == true) + { + _animation_cnt1 = 0; + _animation_cnt2 = 0; + _animation_cnt3 = 0; + _animation_cnt4 = 0; + } + */ + + if(_frame_cnt < _quarter_frame_cnt_max) { + + quad = "QUAD1"; + //cout << quad << endl; + + if(_frame_cnt <= _quarter_frame_cnt_max/4) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt1, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(3*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + _animation_cnt1++; + } + + if(_frame_cnt <= _quarter_frame_cnt_max/2) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt2, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + _animation_cnt2++; + } + + if(_frame_cnt <= _quarter_frame_cnt_max) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt3, 0, _quarter_frame_cnt_max/4, 0, 255)); + + ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + _animation_cnt3++; + } + + if((7*_quarter_frame_cnt_max/8 < _frame_cnt) && (_frame_cnt < _quarter_frame_cnt_max)) + { + + ofSetColor(0, 0, 0, ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255)); + //cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl; + + ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + _animation_cnt4++; + } + + + } + + + if((_frame_cnt >= _frame_cnt_max/4) && (_frame_cnt < _frame_cnt_max/2)){ + + quad = "QUAD2"; + //cout << quad << endl; + + int _local_frame_count = _frame_cnt - _quarter_frame_cnt_max; + //cout << "_local_frame_count" << _local_frame_count << endl; + + if(_local_frame_count < _quarter_frame_cnt_max/4) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt5, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(0, 3*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2); + //cout << "_animation_cnt1: " << _animation_cnt1 << endl; + + _animation_cnt5++; + } + + if(_local_frame_count < _quarter_frame_cnt_max/2) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt6, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(0, 2.5*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2); + _animation_cnt6++; + } + + if(_local_frame_count < _quarter_frame_cnt_max) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt7, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(0, 2.25*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2); + _animation_cnt7++; + } + + if((7*_quarter_frame_cnt_max/8 < _local_frame_count) && (_local_frame_count < _quarter_frame_cnt_max)) + { + + ofSetColor(0, 0, 0, ofMap(_animation_cnt8, 0, _quarter_frame_cnt_max/8, 0, 255)); + //cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl; + + ofRect(0, 2.25*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2); + //ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + _animation_cnt8++; + } + + + + } + + + //draw bottom middle + if ((_frame_cnt >= _frame_cnt_max/2) && (_frame_cnt < 3*_frame_cnt_max/4)) { + + quad = "QUAD3"; + //cout << quad << endl; + + int _local_frame_count = _frame_cnt - _half_frame_cnt_max; + //cout << "_local_frame_count" << _local_frame_count << endl; + + + + if(_local_frame_count <= _quarter_frame_cnt_max/4) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt9, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight()); + //cout << "_animation_cnt1: " << _animation_cnt1 << endl; + + _animation_cnt9++; + } + + if(_local_frame_count < _quarter_frame_cnt_max/2) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt10, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(1.25*ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight()); + _animation_cnt10++; + } + + if(_local_frame_count < _quarter_frame_cnt_max) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt11, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(1.5*ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight()); + _animation_cnt11++; + } + + if((7*_quarter_frame_cnt_max/8 < _local_frame_count) && (_local_frame_count < _quarter_frame_cnt_max)) + { + + ofSetColor(0, 0, 0, ofMap(_animation_cnt12, 0, _quarter_frame_cnt_max/8, 0, 255)); + //cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl; + + ofRect(1.5*ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight()); + //ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + //ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight()); + _animation_cnt12++; + } + + + + + + } + + + //draw left + if((_frame_cnt >= 3*_frame_cnt_max/4) && (_frame_cnt <= _frame_cnt_max) ){ + + quad = "QUAD4"; + //cout << quad << endl; + + int _local_frame_count = _frame_cnt - _threequarters_frame_cnt_max; + //cout << "_local_frame_count" << _local_frame_count << endl; + + + if(_local_frame_count <= _quarter_frame_cnt_max/4) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt13, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(0, ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2); + //cout << "_animation_cnt13: " << _animation_cnt1 << endl; + + _animation_cnt13++; + } + + if(_local_frame_count < _quarter_frame_cnt_max/2) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt14, 0, _quarter_frame_cnt_max/4, 0, 255)); + + ofRect(0, 1.25*ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2); + _animation_cnt14++; + } + + if(_local_frame_count < _quarter_frame_cnt_max) + { + ofSetColor(255, 255, 255, ofMap(_animation_cnt15, 0, _quarter_frame_cnt_max/4, 0, 255)); + ofRect(0, 1.5*ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2); + _animation_cnt15++; + } + + if((7*_quarter_frame_cnt_max/8 < _local_frame_count) && (_local_frame_count < _quarter_frame_cnt_max)) + { + + ofSetColor(0, 0, 0, ofMap(_animation_cnt16, 0, _quarter_frame_cnt_max/8, 0, 255)); + //cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl; + + ofRect(0, 1.5*ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2); + + _animation_cnt16++; + } + + } + + ofDisableAlphaBlending(); + } + + _frame_cnt++; + //cout << "_frame_cnt:" << _frame_cnt << endl; + + break; + } + + case STATE_SYNTHESISING: + { + // display animation of something while the synthesis in on-going... + break; + } + + case STATE_DISPLAY_RESULTS: + { + // display results of the synthesis + break; + } + + + default: + break; + } + + +} + +// this runs at save_cb timer rate = DELTA_T_SAVE +void ShapeFromShadingAnalysis::save_cb(Timer& timer) +{ + //cout << "ShapeFromShadingAnalysis::saving...\n"; + + string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg"; + + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _save_cnt++; + + if(_save_cnt >= NUM_SAVE_PER_RUN) + _RUN_DONE = true; + +} diff --git a/src/ShapeFromShadingAnalysis.h b/src/ShapeFromShadingAnalysis.h new file mode 100755 index 0000000..e1c4b0c --- /dev/null +++ b/src/ShapeFromShadingAnalysis.h @@ -0,0 +1,53 @@ +/* + ~ author: dviid + ~ contact: dviid@labs.ciid.dk + */ + +#pragma once + +#include "AbstractAnalysis.h" + +#include "Poco/Timer.h" + + +class ShapeFromShadingAnalysis : public AbstractAnalysis +{ +public: + ShapeFromShadingAnalysis(): AbstractAnalysis("SHAPEFROMSHADING"){;} + virtual ~ShapeFromShadingAnalysis(){;} + +public: + + void setup(int camWidth, int camHeight); + void acquire(); + void synthesise(); + void draw(); + + void save_cb(Poco::Timer& timer); + +protected: + + string quad; + bool _RUN_DONE; + float _flip, _level; + int _run_cnt, _save_cnt; + int _animation_cnt1; + int _animation_cnt2; + int _animation_cnt3; + int _animation_cnt4; + int _animation_cnt5; + int _animation_cnt6; + int _animation_cnt7; + int _animation_cnt8; + int _animation_cnt9; + int _animation_cnt10; + int _animation_cnt11; + int _animation_cnt12; + int _animation_cnt13; + int _animation_cnt14; + 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; + +}; diff --git a/src/StrobeAnalysis.cpp b/src/StrobeAnalysis.cpp new file mode 100755 index 0000000..4680699 --- /dev/null +++ b/src/StrobeAnalysis.cpp @@ -0,0 +1,161 @@ +/* + ~ author: dviid + ~ contact: dviid@labs.ciid.dk + */ + +#include "StrobeAnalysis.h" +#include "ofMain.h" + +#include "Poco/Timer.h" +#include "Poco/Thread.h" + +#include "RefractiveIndex.h" + +using Poco::Timer; +using Poco::TimerCallback; +using Poco::Thread; + +void StrobeAnalysis::setup(int camWidth, int camHeight) +{ + DELTA_T_SAVE = 100; + NUM_RUN = 1; + + _strobe_cnt = 0; + _strobe_cnt_max = 20; // 40 x 500 ms = 20000 ms = 20 seconds run time + _strobe_interval = 1000; //every 0.5seconds = 15 frames + _frame_cnt_max = _strobe_cnt_max * _strobe_interval * ofGetFrameRate()/1000; + + // The British Health and Safety Executive recommend that a net flash rate for a bank of strobe lights does not exceed 5 flashes per second, at which only 5% of photosensitive epileptics are at risk. It also recommends that no strobing effect continue for more than 30 seconds, due to the potential for discomfort and disorientation. + + //or 20 times, every one second... + _save_cnt_max = _strobe_cnt_max*_strobe_interval/DELTA_T_SAVE; + + create_dir(); +} + + +void StrobeAnalysis::acquire() +{ + + Timer* save_timer; + + TimerCallback save_callback(*this, &StrobeAnalysis::save_cb); + + // RUN ROUTINE + for(int i = 0; i < NUM_RUN; i++) { + + _run_cnt = i; + _save_cnt = 0; + _frame_cnt = 0; + + cout << "RUN NUM = " << i; + + save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files + save_timer->start(save_callback); + _RUN_DONE = false; + _frame_cnt = 0; _save_cnt = 0; + + while(!_RUN_DONE) + Thread::sleep(3); + + save_timer->stop(); + } +} + +void StrobeAnalysis::synthesise() +{ + // _saved_filenames has all the file names of all the saved images +} + +// this runs at frame rate = 33 ms for 30 FPS +void StrobeAnalysis::draw() +{ + + switch (_state) { + case STATE_ACQUIRING: + { + ofEnableAlphaBlending(); + ofColor aColour; + int _fade_in_frames = _frame_cnt_max/10; + cout<< "_fade_in_frames" << _fade_in_frames<< endl; + + if (_frame_cnt < _fade_in_frames) { + + aColour.set(255, 255, 255, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + ofSetColor(aColour); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + //cout << "FADE IN STROBE TIME " << endl; + + + } + + if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){ + + //cout << "_frame_cnt: " << _frame_cnt << endl; + //cout << "frame_cnt % 15: " << _frame_cnt%15 << endl; + //cout << "MAIN STROBE TIME " << endl; + + if (_frame_cnt%int(ofGetFrameRate()*_strobe_interval/1000) < (ofGetFrameRate()*_strobe_interval/1000)/2) + { + ofSetColor(255, 255, 255); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + _strobe_cnt++; + _strobe_on = 1; + } else if (_frame_cnt%int(ofGetFrameRate()*_strobe_interval/1000) >= (ofGetFrameRate()*_strobe_interval/1000)/2) + { + ofSetColor(0, 0, 0); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + _strobe_on = 0; + } + + } + + if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) { + aColour.set(255, 255, 255, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); + ofSetColor(aColour); + ofRect(0, 0, ofGetWidth(), ofGetHeight()); + // cout << "FADE OUT STROBE TIME " << endl; + } + + _frame_cnt++; + ofDisableAlphaBlending(); + + break; + } + + case STATE_SYNTHESISING: + { + // display animation of something while the synthesis in on-going... + break; + } + + case STATE_DISPLAY_RESULTS: + { + // display results of the synthesis + break; + } + + + default: + break; + } + +} + +// this runs at save_cb timer rate = DELTA_T_SAVE +void StrobeAnalysis::save_cb(Timer& timer) +{ + string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg"; + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _save_cnt++; + + cout << "_save_cnt" << _save_cnt << endl; + + cout << "_save_cnt_max" << _save_cnt_max << endl; + + //TODO: something fucked here with my calc of _save_cnt_max - new structure should fix it? + if(_save_cnt >= _save_cnt_max-10) { + _RUN_DONE = true; + } + +} diff --git a/src/CamFrameRateAnalysis.h b/src/StrobeAnalysis.h similarity index 53% rename from src/CamFrameRateAnalysis.h rename to src/StrobeAnalysis.h index d137f00..ca1cf93 100755 --- a/src/CamFrameRateAnalysis.h +++ b/src/StrobeAnalysis.h @@ -10,11 +10,11 @@ #include "Poco/Timer.h" -class CamFrameRateAnalysis : public AbstractAnalysis +class StrobeAnalysis : public AbstractAnalysis { public: - CamFrameRateAnalysis(): AbstractAnalysis("CAM_NOISE"){;} - virtual ~CamFrameRateAnalysis(){;} + StrobeAnalysis(): AbstractAnalysis("STROBE"){;} + virtual ~StrobeAnalysis(){;} public: @@ -28,7 +28,10 @@ public: protected: bool _RUN_DONE; - int _run_cnt, _save_cnt; - float c, _frame_cnt, _frame_cnt_max; + int _strobe_cnt, _run_cnt, _strobe_cnt_max; + int _save_cnt; + int _frame_cnt, _frame_cnt_max, _save_cnt_max ; + int _strobe_interval; + bool _strobe_on; };