State Machine APP with exit

> fixed #defines
> fixed ::exit(1);
This commit is contained in:
dviid 2012-02-12 09:39:36 +01:00
parent b5a713dcf9
commit 29e4a00e08
17 changed files with 76 additions and 71 deletions

View File

@ -58,7 +58,7 @@ void RefractiveIndex::setup()
// <camera> // <camera>
_vid_id = XML.getValue("config:camera:id", CAMERA_ID); _vid_id = XML.getValue("config:camera:id", CAMERA_ID);
_vid_w = XML.getValue("config:camera:width", CAMERA_ACQU_WIDTH); _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);
// <display> // <display>
int fps = XML.getValue("config:display:fps", 30); int fps = XML.getValue("config:display:fps", 30);
@ -161,6 +161,8 @@ void RefractiveIndex::state_analysis()
_state = ISTATE_TRANSITION; _state = ISTATE_TRANSITION;
break; break;
case ISTATE_END: case ISTATE_END:
stop_camera();
::exit(1);
break; break;
case ISTATE_UNDEF: case ISTATE_UNDEF:
break; break;
@ -190,10 +192,7 @@ void RefractiveIndex::draw()
void RefractiveIndex::setup_camera() void RefractiveIndex::setup_camera()
{ {
if(_vid_stream_open) { stop_camera();
_vidGrabber.close();
_vid_stream_open = false;
}
if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) { if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) {
ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber"; 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) void RefractiveIndex::keyPressed (int key)
{ {
if( key =='f') if( key =='f')
ofToggleFullscreen(); ofToggleFullscreen();
} }
void RefractiveIndex::exit()
{
stop_camera();
}

View File

@ -22,9 +22,11 @@ public:
void setup(); void setup();
void update(); void update();
void draw(); void draw();
void exit();
// refindx // refindx
void setup_camera(); void setup_camera();
void stop_camera();
void analysis_cb(string & analysis); void analysis_cb(string & analysis);
void start_analysis(); void start_analysis();
void stop_analysis(); void stop_analysis();
@ -34,9 +36,9 @@ public:
void keyPressed (int key); void keyPressed (int key);
void keyReleased(int key){;} void keyReleased(int key){;}
void mouseMoved(int x, int y ){;} void mouseMoved(int x, int y ){;}
void mouseDragged(int x, int y, int button); void mouseDragged(int x, int y, int button){;}
void mousePressed(int x, int y, int button); void mousePressed(int x, int y, int button){;}
void mouseReleased(int x, int y, int button); void mouseReleased(int x, int y, int button){;}
void windowResized(int w, int h){;} void windowResized(int w, int h){;}
protected: protected:

View File

@ -7,10 +7,8 @@
#include "ofMain.h" #include "ofMain.h"
#include "ofEvents.h" #include "ofEvents.h"
#include <string> #include <string>
//#define ANALYSIS_PATH "data/analysis/"
#define ANALYSIS_PATH "analysis/" #define ANALYSIS_PATH "analysis/"
#define STATE_STOP 0xDEADBEEF #define STATE_STOP 0xDEADBEEF
@ -36,7 +34,6 @@ protected:
virtual void synthesize() = 0; 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: public:
string _name; string _name;
@ -48,5 +45,10 @@ protected:
int _state; int _state;
string _whole_file_path; string _whole_file_path;
float DELTA_T_SAVE;
int NUM_PHASE;
int NUM_RUN;
int NUM_SAVE_PER_RUN;
friend class AnalysisAdaptor; friend class AnalysisAdaptor;
}; };

View File

@ -18,6 +18,11 @@ using Poco::Thread;
void CamFrameRateAnalysis::setup(int camWidth, int camHeight) 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(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;

View File

@ -9,13 +9,6 @@
#include "Poco/Timer.h" #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 class CamFrameRateAnalysis : public AbstractAnalysis
{ {

View File

@ -18,6 +18,11 @@ using Poco::Thread;
void CamNoiseAnalysis::setup(int camWidth, int camHeight) void CamNoiseAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;

View File

@ -9,12 +9,6 @@
#include "Poco/Timer.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 CamNoiseAnalysis : public AbstractAnalysis class CamNoiseAnalysis : public AbstractAnalysis
{ {
public: public:

View File

@ -45,6 +45,11 @@ using Poco::Thread;
void ColorMultiAnalysis::setup(int camWidth, int camHeight) void ColorMultiAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
@ -81,9 +86,7 @@ void ColorMultiAnalysis::synthesize()
void ColorMultiAnalysis::draw() void ColorMultiAnalysis::draw()
{ {
if (_frame_cnt < _frame_cnt_max) {
if (_frame_cnt < _frame_cnt_max)
{
ofColor aColor; ofColor aColor;
aColor.setHsb(c, 255, 255); aColor.setHsb(c, 255, 255);
ofSetColor(aColor); ofSetColor(aColor);
@ -92,8 +95,6 @@ void ColorMultiAnalysis::draw()
c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max);
} }
_frame_cnt++; _frame_cnt++;
} }

View File

@ -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 #pragma once
#include "AbstractAnalysis.h" #include "AbstractAnalysis.h"

View File

@ -18,6 +18,11 @@ using Poco::Thread;
void ColorSingleAnalysis::setup(int camWidth, int camHeight) void ColorSingleAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);

View File

@ -9,12 +9,6 @@
#include "Poco/Timer.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 ColorSingleAnalysis : public AbstractAnalysis class ColorSingleAnalysis : public AbstractAnalysis
{ {
public: public:

View File

@ -18,6 +18,11 @@ using Poco::Thread;
void DiffNoiseAnalysis::setup(int camWidth, int camHeight) void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);

View File

@ -9,12 +9,6 @@
#include "Poco/Timer.h" #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 class DiffNoiseAnalysis : public AbstractAnalysis
{ {
public: public:

View File

@ -15,9 +15,13 @@ using Poco::Timer;
using Poco::TimerCallback; using Poco::TimerCallback;
using Poco::Thread; using Poco::Thread;
void IResponseAnalysis::setup(int camWidth, int camHeight) void IResponseAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);

View File

@ -9,12 +9,6 @@
#include "Poco/Timer.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 IResponseAnalysis : public AbstractAnalysis class IResponseAnalysis : public AbstractAnalysis
{ {
public: public:

View File

@ -18,6 +18,11 @@ using Poco::Thread;
void LatencyTestAnalysis::setup(int camWidth, int camHeight) void LatencyTestAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000); _frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);

View File

@ -9,12 +9,6 @@
#include "Poco/Timer.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 class LatencyTestAnalysis : public AbstractAnalysis
{ {
public: public: