diff --git a/README b/README
index 01ae918..c1dc255 100644
--- a/README
+++ b/README
@@ -6,6 +6,5 @@ configuring OpenFrameworks
these files are configured according to OpenFrameworks addons - http://ofxaddons.com/howto
(1) drag-drop "ReflectiveIndex" folder into your OpenFrameworks project
-(2) Install depedencies: {ofxDirList, ofxXmlSettings};
-(3) Make sure that the config file config/config.refindx is in your "data" folder
-(4) Press Play!
+(2) Install depedencies: {ofxDirList, ofxControlPanel, ofxXmlSettings};
+(3) Press Play!
diff --git a/config/config.refindx b/config/config.refindx
deleted file mode 100644
index 12fde79..0000000
--- a/config/config.refindx
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
- 1
- 640
- 480
-
-
- 30
- true
- 800
- 800
-
-
- MIDDLESBOROUGH
-
-
\ No newline at end of file
diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp
index 377cafb..822a942 100644
--- a/example/RefractiveIndex.cpp
+++ b/example/RefractiveIndex.cpp
@@ -26,21 +26,16 @@
#define CAMERA_ACQU_WIDTH 640
#define CAMERA_ACQU_HEIGHT 480
-#define LOCATION "????-not-config-???"
+#define LOCATION "MIDDLESBOROUGH"
-#define ISTATE_ACQU_START 0xAAAA
-#define ISTATE_ACQU_STOP 0xBBBB
-#define ISTATE_SYNTH_START 0xCCCC
-#define ISTATE_SYNTH_STOP 0xDDDD
-
-#define ISTATE_TRANSITION 0xFFFF
-#define ISTATE_UNDEF 0xEEEE
-#define ISTATE_END 0x1111
+#define ISTATE_UNDEF 0xEEEE
+#define ISTATE_START 0xAAAA
+#define ISTATE_STOP 0xBBBB
+#define ISTATE_TRANSITION 0xCCCC
+#define ISTATE_END 0xDDDD
int _state = ISTATE_UNDEF;
-bool _in_acquisition = true;
-
ofPixels RefractiveIndex::_pixels;
ofVideoGrabber RefractiveIndex::_vidGrabber;
int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id;
@@ -94,119 +89,77 @@ void RefractiveIndex::setup()
cout << "RRRRRREADY!" << endl;
+ _analysisAdapator = NULL;
+
//getting a warning from the OFlog that the pixels aren't allocated
//void ofPixels::allocate(int w, int h, ofImageType type)
// setup analysis
- AnalysisAdaptor* adpt;
- adpt = new AnalysisAdaptor(new ShadowScapesAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new StrobeAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new IResponseAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new ColorMultiAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new CamFrameRateAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new CamNoiseAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new ColorSingleAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new LatencyTestAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
- adpt = new AnalysisAdaptor(new DiffNoiseAnalysis());
- _acquisitionMap[adpt->_analysis->_name];
+ _analysisVector.push_back(new ShadowScapesAnalysis());
+ _analysisVector.push_back(new StrobeAnalysis());
+ _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 = _acquisitionMap.begin();
- _currentAnalysisAdaptor = _currentAnalysisIndx->second;
- _currentAnalysis = _currentAnalysisAdaptor->_analysis;
+ _currentAnalysisIndx = 0;
+ _currentAnalysis = _analysisVector.at(_currentAnalysisIndx);
- _state = ISTATE_ACQU_START;
+ _state = ISTATE_START;
}
-void RefractiveIndex::acquire_cb(string & analysis)
+void RefractiveIndex::analysis_cb(string & analysis)
{
- assert(analysis == _currentAnalysis->_name);
- _state = ISTATE_ACQU_STOP;
-}
-
-void RefractiveIndex::synthesize_cb(string & analysis)
-{
- TAnalysisMap::iterator it = _synthesisMap.find(analysis);
- if(it != _synthesisMap.end()) {
- AnalysisAdaptor* adpt = it->second;
- AbstractAnalysis* a = adpt->_analysis;
- adpt->stop();
- ofRemoveListener(a->_acquire_cb, this, &RefractiveIndex::acquire_cb);
- ofRemoveListener(a->_synthesize_cb, this, &RefractiveIndex::synthesize_cb);
- }
+ assert(analysis == _currentAnalysis->_name);
- //_state = ISTATE_SYNTH_STOP;
+ _state = ISTATE_STOP;
}
-
void RefractiveIndex::start_analysis()
{
- ofAddListener(_currentAnalysis->_acquire_cb, this, &RefractiveIndex::acquire_cb);
- ofAddListener(_currentAnalysis->_synthesize_cb, this, &RefractiveIndex::synthesize_cb);
+ ofAddListener(_currentAnalysis->_synthesize_cb, this, &RefractiveIndex::analysis_cb);
+ _analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
_currentAnalysis->setup(_vid_w, _vid_h);
- _currentAnalysisAdaptor->start();
+ _analysisAdapator->start();
}
void RefractiveIndex::stop_analysis()
{
- if(_currentAnalysisAdaptor == NULL) return;
+ if(_analysisAdapator == NULL) return;
- _currentAnalysisAdaptor->stop(); //blocking
- ofRemoveListener(_currentAnalysis->_acquire_cb, this, &RefractiveIndex::acquire_cb);
- ofRemoveListener(_currentAnalysis->_synthesize_cb, this, &RefractiveIndex::synthesize_cb);
+ _analysisAdapator->stop(); //blocking
+ ofRemoveListener(_currentAnalysis->_synthesize_cb, this, &RefractiveIndex::analysis_cb);
_currentAnalysis = NULL;
- _currentAnalysisAdaptor = NULL;
+ delete _analysisAdapator;
+ _analysisAdapator = NULL;
}
-void RefractiveIndex::state_machine_analysis()
+void RefractiveIndex::state_analysis()
{
- static int synth_cnt = 0;
-
switch (_state) {
- case ISTATE_ACQU_START:
+ case ISTATE_START:
start_analysis();
_state = ISTATE_UNDEF;
break;
- case ISTATE_ACQU_STOP:
- // continue to synthesis
- _acquisitionMap.erase(_currentAnalysisIndx);
- _synthesisMap[_currentAnalysis->_name] = _currentAnalysisAdaptor;
- _state = ISTATE_TRANSITION;
- break;
- case ISTATE_TRANSITION:
- if(_currentAnalysisIndx != _acquisitionMap.end()) {
- _currentAnalysisIndx++;
- _currentAnalysisAdaptor = _currentAnalysisIndx->second;
- _currentAnalysis = _currentAnalysisAdaptor->_analysis;
+ case ISTATE_TRANSITION:
+ if(_currentAnalysisIndx >= _analysisVector.size()) {
+ _currentAnalysisIndx = 0;
+ _state = ISTATE_END;
} else {
- if(_synthesisMap.size() > 0) {
- if(_in_acquisition) {
- _currentAnalysisIndx = _synthesisMap.begin();
- _in_acquisition = false;
- }
- if(!_acquisitionMap.empty() && _currentAnalysisIndx != _synthesisMap.end()) {
- _currentAnalysisIndx++;
- _currentAnalysisAdaptor = _currentAnalysisIndx->second;
- _currentAnalysis = _currentAnalysisAdaptor->_analysis;
- _state = ISTATE_UNDEF;
- } else if(_acquisitionMap.empty()) {
- _state = ISTATE_END;
- }
- }
+ _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
+ _state = ISTATE_START;
}
- break;
- case ISTATE_SYNTH_STOP:
-
+ break;
+ case ISTATE_STOP:
+ stop_analysis(); // blocking
+ _state = ISTATE_TRANSITION;
+ break;
case ISTATE_END:
stop_camera();
::exit(1);
@@ -220,7 +173,7 @@ void RefractiveIndex::state_machine_analysis()
void RefractiveIndex::update()
{
- state_machine_analysis();
+ state_analysis();
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
@@ -266,7 +219,7 @@ void RefractiveIndex::keyPressed (int key)
ofToggleFullscreen();
}
-void RefractiveIndex::exit()
+void RefractiveIndex::exit()
{
stop_camera();
}
\ No newline at end of file
diff --git a/example/RefractiveIndex.h b/example/RefractiveIndex.h
index 4faa480..278974c 100644
--- a/example/RefractiveIndex.h
+++ b/example/RefractiveIndex.h
@@ -8,14 +8,12 @@
#include "ofMain.h"
#include "ofEvents.h"
+//#include "ofxControlPanel.h"
#include "AbstractAnalysis.h"
#include "AnalysisAdaptor.h"
-typedef map TAnalysisMap;
-typedef vector TAnalysisVec;
-
class RefractiveIndex : public ofBaseApp
{
public:
@@ -26,22 +24,13 @@ public:
void draw();
void exit();
- // camera
+ // refindx
void setup_camera();
void stop_camera();
-
- // starts the whole process
+ void analysis_cb(string & analysis);
void start_analysis();
-
- // stops the whole process
void stop_analysis();
-
- // callbacks
- void acquire_cb(string & analysis);
- void synthesize_cb(string & analysis);
-
- // state machine
- void state_machine_analysis();
+ void state_analysis();
// ofx
void keyPressed (int key);
@@ -53,17 +42,17 @@ public:
void windowResized(int w, int h){;}
protected:
-
+
+ //void eventsIn(guiCallbackData & data);
+ //void grabBackgroundEvent(guiCallbackData & data);
+
+ // gui
+ //ofxControlPanel _gui;
+
AbstractAnalysis* _currentAnalysis;
- AnalysisAdaptor* _currentAnalysisAdaptor;
- AnalysisAdaptor* _currentSynthesisAdaptor;
- TAnalysisMap::iterator _currentAnalysisIndx;
-
- TAnalysisMap _acquisitionMap;
- TAnalysisMap _synthesisMap;
-
- TAnalysisVec _display_results_vector;
-
+ int _currentAnalysisIndx;
+ AnalysisAdaptor* _analysisAdapator;
+ vector _analysisVector;
public:
// acquisition
@@ -75,6 +64,7 @@ public:
static bool _vid_toggle_on;
// this should be in xml
- static string _location;
+ static string _location;
+
};
\ No newline at end of file
diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp
index 1abdff9..751109a 100644
--- a/src/AbstractAnalysis.cpp
+++ b/src/AbstractAnalysis.cpp
@@ -34,13 +34,7 @@
#include "RefractiveIndex.h"
void AbstractAnalysis::do_synthesize() {
- // acquire images + pattern on display
- pattern_acquire();
- // acquire notify obeservers
- ofNotifyEvent(_acquire_cb, _name);
- // analysis and synthesis of acquired images
synthesize();
- // synthesize notify obeservers
ofNotifyEvent(_synthesize_cb, _name);
}
diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h
index b54c8b3..45317cc 100755
--- a/src/AbstractAnalysis.h
+++ b/src/AbstractAnalysis.h
@@ -28,20 +28,16 @@ public:
protected:
- // creates working directory
- virtual void create_dir();
-
- // acquire images from camera and display patters on screen
- virtual void pattern_acquire() = 0;
+ virtual void create_dir();
- // analyses and sythesizes images acquired
- virtual void synthesize() = 0;
-
+ // 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
+
public:
string _name;
- // event notification / callbacks
- ofEvent _acquire_cb;
+ // event
ofEvent _synthesize_cb;
protected:
diff --git a/src/AnalysisAdaptor.h b/src/AnalysisAdaptor.h
index 7ea3829..2e32464 100755
--- a/src/AnalysisAdaptor.h
+++ b/src/AnalysisAdaptor.h
@@ -31,10 +31,8 @@ public:
_worker.join();
}
-public:
+protected:
AbstractAnalysis* _analysis;
-
-protected:
Thread _worker; //
RunnableAdapter* _runnable;
};