From 29e4a00e081ab4fbdfe569de165a3b2605b0f538 Mon Sep 17 00:00:00 2001 From: dviid Date: Sun, 12 Feb 2012 09:39:36 +0100 Subject: [PATCH] State Machine APP with exit > fixed #defines > fixed ::exit(1); --- example/RefractiveIndex.cpp | 24 ++++++++++++++++++------ example/RefractiveIndex.h | 8 +++++--- src/AbstractAnalysis.h | 12 +++++++----- src/CamFrameRateAnalysis.cpp | 5 +++++ src/CamFrameRateAnalysis.h | 7 ------- src/CamNoiseAnalysis.cpp | 5 +++++ src/CamNoiseAnalysis.h | 6 ------ src/ColorMultiAnalysis.cpp | 27 ++++++++++++++------------- src/ColorMultiAnalysis.h | 4 ---- src/ColorSingleAnalysis.cpp | 5 +++++ src/ColorSingleAnalysis.h | 6 ------ src/DiffNoiseAnalysis.cpp | 5 +++++ src/DiffNoiseAnalysis.h | 6 ------ src/IResponseAnalysis.cpp | 6 +++++- src/IResponseAnalysis.h | 6 ------ src/LatencyTestAnalysis.cpp | 5 +++++ src/LatencyTestAnalysis.h | 10 ++-------- 17 files changed, 76 insertions(+), 71 deletions(-) diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index 8931e25..822a942 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -58,7 +58,7 @@ void RefractiveIndex::setup() // _vid_id = XML.getValue("config:camera:id", CAMERA_ID); _vid_w = XML.getValue("config:camera:width", CAMERA_ACQU_WIDTH); - _vid_h = XML.getValue("config:camera:width", CAMERA_ACQU_HEIGHT); + _vid_h = XML.getValue("config:camera:height", CAMERA_ACQU_HEIGHT); // int fps = XML.getValue("config:display:fps", 30); @@ -92,7 +92,7 @@ void RefractiveIndex::setup() _analysisAdapator = NULL; //getting a warning from the OFlog that the pixels aren't allocated - // void ofPixels::allocate(int w, int h, ofImageType type) + //void ofPixels::allocate(int w, int h, ofImageType type) // setup analysis @@ -161,6 +161,8 @@ void RefractiveIndex::state_analysis() _state = ISTATE_TRANSITION; break; case ISTATE_END: + stop_camera(); + ::exit(1); break; case ISTATE_UNDEF: break; @@ -190,10 +192,7 @@ void RefractiveIndex::draw() void RefractiveIndex::setup_camera() { - if(_vid_stream_open) { - _vidGrabber.close(); - _vid_stream_open = false; - } + stop_camera(); if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) { ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber"; @@ -206,8 +205,21 @@ void RefractiveIndex::setup_camera() } +void RefractiveIndex::stop_camera() +{ + if(_vid_stream_open) { + _vidGrabber.close(); + _vid_stream_open = false; + } +} + void RefractiveIndex::keyPressed (int key) { if( key =='f') ofToggleFullscreen(); +} + +void RefractiveIndex::exit() +{ + stop_camera(); } \ No newline at end of file diff --git a/example/RefractiveIndex.h b/example/RefractiveIndex.h index 3036272..278974c 100644 --- a/example/RefractiveIndex.h +++ b/example/RefractiveIndex.h @@ -22,9 +22,11 @@ public: void setup(); void update(); void draw(); + void exit(); // refindx void setup_camera(); + void stop_camera(); void analysis_cb(string & analysis); void start_analysis(); void stop_analysis(); @@ -34,9 +36,9 @@ public: void keyPressed (int key); void keyReleased(int key){;} void mouseMoved(int x, int y ){;} - void mouseDragged(int x, int y, int button); - void mousePressed(int x, int y, int button); - void mouseReleased(int x, int y, int button); + void mouseDragged(int x, int y, int button){;} + void mousePressed(int x, int y, int button){;} + void mouseReleased(int x, int y, int button){;} void windowResized(int w, int h){;} protected: diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index 74e38b2..45317cc 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -7,10 +7,8 @@ #include "ofMain.h" #include "ofEvents.h" - #include -//#define ANALYSIS_PATH "data/analysis/" #define ANALYSIS_PATH "analysis/" #define STATE_STOP 0xDEADBEEF @@ -34,9 +32,8 @@ protected: // the runnable function in the thread virtual void synthesize() = 0; - // this means that this function needs to be overwritten by children that inherit this class - - + // this means that this function needs to be overwritten by children that inherit this class + public: string _name; @@ -48,5 +45,10 @@ protected: int _state; string _whole_file_path; + float DELTA_T_SAVE; + int NUM_PHASE; + int NUM_RUN; + int NUM_SAVE_PER_RUN; + friend class AnalysisAdaptor; }; \ No newline at end of file diff --git a/src/CamFrameRateAnalysis.cpp b/src/CamFrameRateAnalysis.cpp index 7d5a1c6..3db72f3 100755 --- a/src/CamFrameRateAnalysis.cpp +++ b/src/CamFrameRateAnalysis.cpp @@ -18,6 +18,11 @@ using Poco::Thread; void CamFrameRateAnalysis::setup(int camWidth, int camHeight) { + DELTA_T_SAVE = 1000/30; + NUM_PHASE = 1; + NUM_RUN = 1; + NUM_SAVE_PER_RUN = 100; + create_dir(); _frame_cnt = 0; diff --git a/src/CamFrameRateAnalysis.h b/src/CamFrameRateAnalysis.h index c8fc374..d3d72d6 100755 --- a/src/CamFrameRateAnalysis.h +++ b/src/CamFrameRateAnalysis.h @@ -9,13 +9,6 @@ #include "Poco/Timer.h" -#define DELTA_T_SAVE 1000/30 //timer call back needs to be at main app frame rate ie 1000/30 -#define NUM_PHASE 1 -//#define TIME_PER_RUN 3*1000 -#define NUM_RUN 1 -//#define SYNTH_TIME TIME_PER_RUN *NUM_RUN //the number of millis it takes for the whole sequence -#define NUM_SAVE_PER_RUN 100 //this must be equal to the number of frames it takes for the whole analysis to draw - ie _frame_cnt_max - class CamFrameRateAnalysis : public AbstractAnalysis { diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index 566c6aa..8b8a31c 100755 --- a/src/CamNoiseAnalysis.cpp +++ b/src/CamNoiseAnalysis.cpp @@ -18,6 +18,11 @@ using Poco::Thread; void CamNoiseAnalysis::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; diff --git a/src/CamNoiseAnalysis.h b/src/CamNoiseAnalysis.h index f180a58..85d6924 100755 --- a/src/CamNoiseAnalysis.h +++ b/src/CamNoiseAnalysis.h @@ -9,12 +9,6 @@ #include "Poco/Timer.h" -#define DELTA_T_SAVE 100 //the milisecond timing -#define NUM_PHASE 1 -#define NUM_RUN 1 -#define NUM_SAVE_PER_RUN 100 - - class CamNoiseAnalysis : public AbstractAnalysis { public: diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index 23167e8..8b14ade 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -45,6 +45,11 @@ using Poco::Thread; void ColorMultiAnalysis::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); @@ -81,19 +86,15 @@ void ColorMultiAnalysis::synthesize() void ColorMultiAnalysis::draw() { - - if (_frame_cnt < _frame_cnt_max) - { - 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 - c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); - } - _frame_cnt++; - - + if (_frame_cnt < _frame_cnt_max) { + 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 + c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); + } + _frame_cnt++; } diff --git a/src/ColorMultiAnalysis.h b/src/ColorMultiAnalysis.h index 61af16c..f540e01 100755 --- a/src/ColorMultiAnalysis.h +++ b/src/ColorMultiAnalysis.h @@ -1,7 +1,3 @@ -#define DELTA_T_SAVE 100 //the milisecond timing -#define NUM_PHASE 1 -#define NUM_RUN 1 -#define NUM_SAVE_PER_RUN 100 #pragma once #include "AbstractAnalysis.h" diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index 9e8c561..9d8a7fb 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -18,6 +18,11 @@ using Poco::Thread; void ColorSingleAnalysis::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); diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index 059f5be..968c46a 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -9,12 +9,6 @@ #include "Poco/Timer.h" -#define DELTA_T_SAVE 100 //the milisecond timing -#define NUM_PHASE 1 -#define NUM_RUN 1 -#define NUM_SAVE_PER_RUN 100 - - class ColorSingleAnalysis : public AbstractAnalysis { public: diff --git a/src/DiffNoiseAnalysis.cpp b/src/DiffNoiseAnalysis.cpp index ef00e10..8c063d0 100755 --- a/src/DiffNoiseAnalysis.cpp +++ b/src/DiffNoiseAnalysis.cpp @@ -18,6 +18,11 @@ using Poco::Thread; void DiffNoiseAnalysis::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); diff --git a/src/DiffNoiseAnalysis.h b/src/DiffNoiseAnalysis.h index f179ae3..da07b69 100755 --- a/src/DiffNoiseAnalysis.h +++ b/src/DiffNoiseAnalysis.h @@ -9,12 +9,6 @@ #include "Poco/Timer.h" -#define DELTA_T_SAVE 1000/30 //timer call back needs to be at main app frame rate ie 1000/30 -#define NUM_PHASE 1 -#define NUM_RUN 1 -#define NUM_SAVE_PER_RUN 100 //this analysis actually necessarily saves a random quantity of frames = about half this number - - class DiffNoiseAnalysis : public AbstractAnalysis { public: diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index 54d9e4e..33f295f 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -15,9 +15,13 @@ using Poco::Timer; using Poco::TimerCallback; using Poco::Thread; - void IResponseAnalysis::setup(int camWidth, int camHeight) { + DELTA_T_SAVE = 100; + NUM_PHASE = 1; + NUM_RUN = 1; + NUM_SAVE_PER_RUN = 100; + create_dir(); _frame_cnt = 0; _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); diff --git a/src/IResponseAnalysis.h b/src/IResponseAnalysis.h index b33647c..44addbc 100755 --- a/src/IResponseAnalysis.h +++ b/src/IResponseAnalysis.h @@ -9,12 +9,6 @@ #include "Poco/Timer.h" -#define DELTA_T_SAVE 100 //the milisecond timing -#define NUM_PHASE 1 -#define NUM_RUN 1 -#define NUM_SAVE_PER_RUN 100 - - class IResponseAnalysis : public AbstractAnalysis { public: diff --git a/src/LatencyTestAnalysis.cpp b/src/LatencyTestAnalysis.cpp index f13e906..9556816 100755 --- a/src/LatencyTestAnalysis.cpp +++ b/src/LatencyTestAnalysis.cpp @@ -18,6 +18,11 @@ 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); diff --git a/src/LatencyTestAnalysis.h b/src/LatencyTestAnalysis.h index f3d0bd3..6ffeaf3 100755 --- a/src/LatencyTestAnalysis.h +++ b/src/LatencyTestAnalysis.h @@ -8,15 +8,9 @@ #include "AbstractAnalysis.h" #include "Poco/Timer.h" - -#define DELTA_T_SAVE 100 //the milisecond timing -#define NUM_PHASE 1 -#define NUM_RUN 1 -#define NUM_SAVE_PER_RUN 100 - - + class LatencyTestAnalysis : public AbstractAnalysis -{ +{ public: LatencyTestAnalysis(): AbstractAnalysis("LATENCY_TEST"){;} virtual ~LatencyTestAnalysis(){;}