diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index ca1df18..c788b9c 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -94,9 +94,9 @@ void RefractiveIndex::setup() //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 ShadowScapesAnalysis(V)); + //_analysisVector.push_back(new ShadowScapesAnalysis(H)); + //_analysisVector.push_back(new ShadowScapesAnalysis(D)); _analysisVector.push_back(new RelaxRateAnalysis()); @@ -114,10 +114,13 @@ void RefractiveIndex::setup() _analysisVector.push_back(new DiffNoiseAnalysis()); - _currentAnalysisIndx = 0; - _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); + //_currentAnalysisIndx = 0; + //_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); - _state = ISTATE_START; + //_state = ISTATE_START; + + _currentAnalysis = NULL; + _state = ISTATE_UNDEF; } @@ -157,7 +160,9 @@ void RefractiveIndex::state_analysis() case ISTATE_TRANSITION: if(_currentAnalysisIndx >= _analysisVector.size()) { _currentAnalysisIndx = 0; - _state = ISTATE_END; + _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); + _state = ISTATE_START; + //_state = ISTATE_END; } else { _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); _state = ISTATE_START; @@ -179,23 +184,16 @@ void RefractiveIndex::state_analysis() } void RefractiveIndex::update() -{ +{ state_analysis(); - - // this has been moved to each class - /* - RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera - - if (_vidGrabber.isFrameNew()) - { - _pixels = _vidGrabber.getPixelsRef(); //get ofPixels from the camera - } - */ - } void RefractiveIndex::draw() { + // refractive mauve + //ofBackground(113, 110, 136); + + // black ofBackground(0, 0, 0); //TODO: Needs to return to a black screen - not to exit... @@ -252,78 +250,112 @@ void RefractiveIndex::keyPressed (int key) // i.e.: ask david how to shut off the prior Analysis if it's not finished running from here? - /* - if(key == '1') + if(key == 'x') { - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(0); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysis = NULL; + _state = ISTATE_UNDEF; + } + + else if(key == '1') + { + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 0; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '2') + else if(key == '2') { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(1); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 1; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '3') - { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(2); - _state = ISTATE_START; + else if(key == '3') + { + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 2; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '4') - { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(3); - _state = ISTATE_START; + else if(key == '4') + { + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 3; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '5') + else if(key == '5') { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(4); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 4; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '6') + else if(key == '6') { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(5); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 5; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '7') + else if(key == '7') { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(6); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 6; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '8') + else if(key == '8') { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(7); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 7; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - if(key == '9') + else if(key == '9') { - - // something needs to go here to cancel the prior analysis - _currentAnalysis = _analysisVector.at(8); - _state = ISTATE_START; + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 8; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; + } + + else if(key == '0') + { + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 9; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; + } + + else if(key == 'q') + { + if(_currentAnalysis) + _analysisAdapator->stop(); + _currentAnalysisIndx = 10; + if(!_currentAnalysis) + _state = ISTATE_TRANSITION; } - */ } diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index 34de6e1..921b093 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -36,13 +36,16 @@ // this is the main threaded loop for a given analysis void AbstractAnalysis::do_synthesize() { + _saved_filenames.clear(); _state = STATE_ACQUIRING; acquire(); + if(_state == STATE_STOP) goto exit; _state = STATE_SYNTHESISING; synthesise(); + if(_state == STATE_STOP) goto exit; _state = STATE_DISPLAY_RESULTS; displayresults(); - +exit: ofNotifyEvent(_synthesize_cb, _name); } diff --git a/src/AnalysisAdaptor.h b/src/AnalysisAdaptor.h index 2e32464..8e2f116 100755 --- a/src/AnalysisAdaptor.h +++ b/src/AnalysisAdaptor.h @@ -21,19 +21,23 @@ public: void start() { + _stopping = false; _runnable = new RunnableAdapter(*_analysis, &AbstractAnalysis::do_synthesize); _worker.start(*_runnable); } void stop() { + if(_stopping) return; + _stopping = true; _analysis->_state = STATE_STOP; - _worker.join(); + _worker.join(); } protected: AbstractAnalysis* _analysis; Thread _worker; // - RunnableAdapter* _runnable; + RunnableAdapter* _runnable; + bool _stopping; }; diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index 24b84a0..b2bed40 100755 --- a/src/CamNoiseAnalysis.cpp +++ b/src/CamNoiseAnalysis.cpp @@ -65,7 +65,7 @@ void CamNoiseAnalysis::acquire() _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -77,7 +77,7 @@ void CamNoiseAnalysis::acquire() void CamNoiseAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index 7721f35..b541ef6 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -65,7 +65,7 @@ void ColorMultiAnalysis::acquire() _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -77,6 +77,8 @@ void ColorMultiAnalysis::acquire() void ColorMultiAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images + while(!_RUN_DONE && _state != STATE_STOP) + Thread::sleep(3); } void ColorMultiAnalysis::displayresults() @@ -84,6 +86,8 @@ void ColorMultiAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){ diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index 4f161bd..8798949 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -73,7 +73,7 @@ void ColorSingleAnalysis::acquire() _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -84,7 +84,7 @@ void ColorSingleAnalysis::acquire() void ColorSingleAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } @@ -93,6 +93,8 @@ void ColorSingleAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){ diff --git a/src/DiffNoiseAnalysis.cpp b/src/DiffNoiseAnalysis.cpp index 42783a0..0873c1f 100755 --- a/src/DiffNoiseAnalysis.cpp +++ b/src/DiffNoiseAnalysis.cpp @@ -65,7 +65,7 @@ void DiffNoiseAnalysis::acquire() _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -75,7 +75,7 @@ void DiffNoiseAnalysis::acquire() void DiffNoiseAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } @@ -85,6 +85,8 @@ void DiffNoiseAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){ diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index 1e42690..bf9f071 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -61,7 +61,7 @@ void IResponseAnalysis::acquire() _RUN_DONE = false; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -74,7 +74,7 @@ void IResponseAnalysis::acquire() void IResponseAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } @@ -84,6 +84,8 @@ void IResponseAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){ diff --git a/src/RelaxRateAnalysis.cpp b/src/RelaxRateAnalysis.cpp index 8b65ce3..61cc838 100755 --- a/src/RelaxRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -61,7 +61,7 @@ void RelaxRateAnalysis::acquire() _RUN_DONE = false; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -74,7 +74,7 @@ void RelaxRateAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } @@ -84,6 +84,8 @@ void RelaxRateAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){ diff --git a/src/ShapeFromShadingAnalysis.cpp b/src/ShapeFromShadingAnalysis.cpp index bec4205..d41fed0 100755 --- a/src/ShapeFromShadingAnalysis.cpp +++ b/src/ShapeFromShadingAnalysis.cpp @@ -78,7 +78,7 @@ void ShapeFromShadingAnalysis::acquire() _animation_cnt16 = 0; _animation_reset = false; // coundn't get this to work - so using seperate counters - shitty! - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -90,7 +90,7 @@ void ShapeFromShadingAnalysis::acquire() void ShapeFromShadingAnalysis::synthesise() { - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } @@ -99,6 +99,8 @@ void ShapeFromShadingAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){ diff --git a/src/StrobeAnalysis.cpp b/src/StrobeAnalysis.cpp index fa80380..08dbbc5 100755 --- a/src/StrobeAnalysis.cpp +++ b/src/StrobeAnalysis.cpp @@ -64,7 +64,7 @@ void StrobeAnalysis::acquire() _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _strobe_cnt = 0; - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); save_timer->stop(); @@ -76,7 +76,7 @@ void StrobeAnalysis::acquire() void StrobeAnalysis::synthesise() { // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE) + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } @@ -85,6 +85,8 @@ void StrobeAnalysis::displayresults() for(float i=1;i<_saved_filenames.size();i++){ + if(_state == STATE_STOP) return; + cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; while(!_image_shown){