key input controls

This commit is contained in:
dviid 2012-02-21 21:18:25 +01:00
parent 2903c7a969
commit 3c13d95bc4
11 changed files with 140 additions and 85 deletions

View File

@ -94,9 +94,9 @@ void RefractiveIndex::setup()
//TODO: whichever one of these is first - it always runs twice ? //TODO: whichever one of these is first - it always runs twice ?
_analysisVector.push_back(new ShadowScapesAnalysis(V)); //_analysisVector.push_back(new ShadowScapesAnalysis(V));
_analysisVector.push_back(new ShadowScapesAnalysis(H)); //_analysisVector.push_back(new ShadowScapesAnalysis(H));
_analysisVector.push_back(new ShadowScapesAnalysis(D)); //_analysisVector.push_back(new ShadowScapesAnalysis(D));
_analysisVector.push_back(new RelaxRateAnalysis()); _analysisVector.push_back(new RelaxRateAnalysis());
@ -114,10 +114,13 @@ void RefractiveIndex::setup()
_analysisVector.push_back(new DiffNoiseAnalysis()); _analysisVector.push_back(new DiffNoiseAnalysis());
_currentAnalysisIndx = 0; //_currentAnalysisIndx = 0;
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); //_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: case ISTATE_TRANSITION:
if(_currentAnalysisIndx >= _analysisVector.size()) { if(_currentAnalysisIndx >= _analysisVector.size()) {
_currentAnalysisIndx = 0; _currentAnalysisIndx = 0;
_state = ISTATE_END; _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
_state = ISTATE_START;
//_state = ISTATE_END;
} else { } else {
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
_state = ISTATE_START; _state = ISTATE_START;
@ -181,21 +186,14 @@ void RefractiveIndex::state_analysis()
void RefractiveIndex::update() void RefractiveIndex::update()
{ {
state_analysis(); 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() void RefractiveIndex::draw()
{ {
// refractive mauve
//ofBackground(113, 110, 136);
// black
ofBackground(0, 0, 0); ofBackground(0, 0, 0);
//TODO: Needs to return to a black screen - not to exit... //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? // i.e.: ask david how to shut off the prior Analysis if it's not finished running from here?
/* if(key == 'x')
if(key == '1')
{ {
// something needs to go here to cancel the prior analysis if(_currentAnalysis)
_currentAnalysis = _analysisVector.at(0); _analysisAdapator->stop();
_state = ISTATE_START; _currentAnalysis = NULL;
_state = ISTATE_UNDEF;
} }
if(key == '2') else if(key == '1')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(1); _currentAnalysisIndx = 0;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '3') else if(key == '2')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(2); _currentAnalysisIndx = 1;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '4') else if(key == '3')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(3); _currentAnalysisIndx = 2;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '5') else if(key == '4')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(4); _currentAnalysisIndx = 3;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '6') else if(key == '5')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(5); _currentAnalysisIndx = 4;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '7') else if(key == '6')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(6); _currentAnalysisIndx = 5;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '8') else if(key == '7')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(7); _currentAnalysisIndx = 6;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
} }
if(key == '9') else if(key == '8')
{ {
if(_currentAnalysis)
// something needs to go here to cancel the prior analysis _analysisAdapator->stop();
_currentAnalysis = _analysisVector.at(8); _currentAnalysisIndx = 7;
_state = ISTATE_START; if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '9')
{
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;
} }
*/
} }

View File

@ -36,13 +36,16 @@
// this is the main threaded loop for a given analysis // this is the main threaded loop for a given analysis
void AbstractAnalysis::do_synthesize() { void AbstractAnalysis::do_synthesize() {
_saved_filenames.clear();
_state = STATE_ACQUIRING; _state = STATE_ACQUIRING;
acquire(); acquire();
if(_state == STATE_STOP) goto exit;
_state = STATE_SYNTHESISING; _state = STATE_SYNTHESISING;
synthesise(); synthesise();
if(_state == STATE_STOP) goto exit;
_state = STATE_DISPLAY_RESULTS; _state = STATE_DISPLAY_RESULTS;
displayresults(); displayresults();
exit:
ofNotifyEvent(_synthesize_cb, _name); ofNotifyEvent(_synthesize_cb, _name);
} }

View File

@ -21,12 +21,15 @@ public:
void start() void start()
{ {
_stopping = false;
_runnable = new RunnableAdapter<AbstractAnalysis>(*_analysis, &AbstractAnalysis::do_synthesize); _runnable = new RunnableAdapter<AbstractAnalysis>(*_analysis, &AbstractAnalysis::do_synthesize);
_worker.start(*_runnable); _worker.start(*_runnable);
} }
void stop() void stop()
{ {
if(_stopping) return;
_stopping = true;
_analysis->_state = STATE_STOP; _analysis->_state = STATE_STOP;
_worker.join(); _worker.join();
} }
@ -35,5 +38,6 @@ protected:
AbstractAnalysis* _analysis; AbstractAnalysis* _analysis;
Thread _worker; // Thread _worker; //
RunnableAdapter<AbstractAnalysis>* _runnable; RunnableAdapter<AbstractAnalysis>* _runnable;
bool _stopping;
}; };

View File

@ -65,7 +65,7 @@ void CamNoiseAnalysis::acquire()
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -77,7 +77,7 @@ void CamNoiseAnalysis::acquire()
void CamNoiseAnalysis::synthesise() void CamNoiseAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }

View File

@ -65,7 +65,7 @@ void ColorMultiAnalysis::acquire()
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -77,6 +77,8 @@ void ColorMultiAnalysis::acquire()
void ColorMultiAnalysis::synthesise() void ColorMultiAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
} }
void ColorMultiAnalysis::displayresults() void ColorMultiAnalysis::displayresults()
@ -84,6 +86,8 @@ void ColorMultiAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){

View File

@ -73,7 +73,7 @@ void ColorSingleAnalysis::acquire()
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -84,7 +84,7 @@ void ColorSingleAnalysis::acquire()
void ColorSingleAnalysis::synthesise() void ColorSingleAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }
@ -93,6 +93,8 @@ void ColorSingleAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){

View File

@ -65,7 +65,7 @@ void DiffNoiseAnalysis::acquire()
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -75,7 +75,7 @@ void DiffNoiseAnalysis::acquire()
void DiffNoiseAnalysis::synthesise() void DiffNoiseAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }
@ -85,6 +85,8 @@ void DiffNoiseAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){

View File

@ -61,7 +61,7 @@ void IResponseAnalysis::acquire()
_RUN_DONE = false; _RUN_DONE = false;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -74,7 +74,7 @@ void IResponseAnalysis::acquire()
void IResponseAnalysis::synthesise() void IResponseAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }
@ -84,6 +84,8 @@ void IResponseAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){

View File

@ -61,7 +61,7 @@ void RelaxRateAnalysis::acquire()
_RUN_DONE = false; _RUN_DONE = false;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -74,7 +74,7 @@ void RelaxRateAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }
@ -84,6 +84,8 @@ void RelaxRateAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){

View File

@ -78,7 +78,7 @@ void ShapeFromShadingAnalysis::acquire()
_animation_cnt16 = 0; _animation_cnt16 = 0;
_animation_reset = false; // coundn't get this to work - so using seperate counters - shitty! _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); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -90,7 +90,7 @@ void ShapeFromShadingAnalysis::acquire()
void ShapeFromShadingAnalysis::synthesise() void ShapeFromShadingAnalysis::synthesise()
{ {
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }
@ -99,6 +99,8 @@ void ShapeFromShadingAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){

View File

@ -64,7 +64,7 @@ void StrobeAnalysis::acquire()
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _strobe_cnt = 0; _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _strobe_cnt = 0;
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
save_timer->stop(); save_timer->stop();
@ -76,7 +76,7 @@ void StrobeAnalysis::acquire()
void StrobeAnalysis::synthesise() void StrobeAnalysis::synthesise()
{ {
// _saved_filenames has all the file names of all the saved images // _saved_filenames has all the file names of all the saved images
while(!_RUN_DONE) while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3); Thread::sleep(3);
} }
@ -85,6 +85,8 @@ void StrobeAnalysis::displayresults()
for(float i=1;i<_saved_filenames.size();i++){ for(float i=1;i<_saved_filenames.size();i++){
if(_state == STATE_STOP) return;
cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; cout << "_saved_filenames[i]" << _saved_filenames[i] << endl;
while(!_image_shown){ while(!_image_shown){