moved the graphics code into David's new structure

* removed unused and unneeded classes and added the ones that were
missing
* put the most recent graphics code into David's great structural org!

current issues:
* the config file is still not loading at the start of the code (only
in RefractiveIndex.cpp does it work - not in main.cpp - where the 'full
screen', etc. are set
* the analyses being called in RefractiveIndex.cpp always run the first
listed one twice - weird!
* the saving (NUM_SAVE_PER_RUN) and frame (_frame_cnt_max) conditions
are competing - can we relate them?
This commit is contained in:
Jamie Allen 2012-02-18 20:37:22 +01:00
parent 7109c65d63
commit 8d0dfc3626
21 changed files with 975 additions and 325 deletions

View File

@ -10,13 +10,14 @@
#include "RefractiveIndex.h" #include "RefractiveIndex.h"
#include "IResponseAnalysis.h"
#include "ShadowScapesAnalysis.h" #include "ShadowScapesAnalysis.h"
#include "ColorMultiAnalysis.h" #include "RelaxRateAnalysis.h"
#include "ColorSingleAnalysis.h" #include "IResponseAnalysis.h"
#include "CamFrameRateAnalysis.h" #include "ShapeFromShadingAnalysis.h"
#include "StrobeAnalysis.h"
#include "CamNoiseAnalysis.h" #include "CamNoiseAnalysis.h"
#include "LatencyTestAnalysis.h" #include "ColorSingleAnalysis.h"
#include "ColorMultiAnalysis.h"
#include "DiffNoiseAnalysis.h" #include "DiffNoiseAnalysis.h"
#include "ofxXmlSettings.h" #include "ofxXmlSettings.h"
@ -94,17 +95,29 @@ void RefractiveIndex::setup()
//void ofPixels::allocate(int w, int h, ofImageType type) //void ofPixels::allocate(int w, int h, ofImageType type)
// setup analysis //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 RelaxRateAnalysis());
// _analysisVector.push_back(new IResponseAnalysis());
_analysisVector.push_back(new ShapeFromShadingAnalysis());
// _analysisVector.push_back(new StrobeAnalysis());
// _analysisVector.push_back(new CamNoiseAnalysis());
// _analysisVector.push_back(new ColorSingleAnalysis());
// _analysisVector.push_back(new ColorMultiAnalysis());
_analysisVector.push_back(new ShadowScapesAnalysis());
_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()); _analysisVector.push_back(new DiffNoiseAnalysis());
_currentAnalysisIndx = 0; _currentAnalysisIndx = 0;
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx); _currentAnalysis = _analysisVector.at(_currentAnalysisIndx);

View File

@ -32,6 +32,7 @@
#include "AbstractAnalysis.h" #include "AbstractAnalysis.h"
#include "RefractiveIndex.h" #include "RefractiveIndex.h"
#include "ofxFileHelper.h"
// 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() {
@ -65,15 +66,16 @@ void AbstractAnalysis::create_dir()
replaceTime+=time.at(i); replaceTime+=time.at(i);
} }
} }
ofxFileHelper fileHelper;
_whole_file_path = ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ;
//cout << "_whole_file_path = " << _whole_file_path << endl;
ofDirectory dir; if(!fileHelper.doesDirectoryExist(_whole_file_path)){
fileHelper.makeDirectory(ANALYSIS_PATH);
_whole_file_path= string(ANALYSIS_PATH)+ RefractiveIndex::_location+"/"+ _name+"/"+replaceTime ; fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location);
//directories have to be created one level at a time hence repeated calls fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name);
if(!dir.doesDirectoryExist(_whole_file_path)){ fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
dir.createDirectory(string(ANALYSIS_PATH)+RefractiveIndex::_location+"/", true,false);
dir.createDirectory(string(ANALYSIS_PATH)+RefractiveIndex::_location+"/"+ _name+"/", true,false);
dir.createDirectory(string(ANALYSIS_PATH)+RefractiveIndex::_location+"/"+ _name+"/"+replaceTime+"/", true,false);
} }
//////////////////////////////END DIRECTORY CREATION ////////////////////////////////////////////////// //////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////

View File

@ -18,7 +18,7 @@ using Poco::Thread;
void CamNoiseAnalysis::setup(int camWidth, int camHeight) void CamNoiseAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100; DELTA_T_SAVE = 200;
NUM_PHASE = 1; NUM_PHASE = 1;
NUM_RUN = 1; NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100; NUM_SAVE_PER_RUN = 100;
@ -67,7 +67,6 @@ void CamNoiseAnalysis::synthesise()
// this runs at frame rate = 33 ms for 30 FPS // this runs at frame rate = 33 ms for 30 FPS
void CamNoiseAnalysis::draw() void CamNoiseAnalysis::draw()
{ {
switch (_state) { switch (_state) {
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
@ -75,22 +74,47 @@ void CamNoiseAnalysis::draw()
// still need to deal with latency frames here - i.e.: there are frames // still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** /// /// *** TODO *** ///
float _number_of_grey_levels=5; ofEnableAlphaBlending();
ofColor aColour;
int _fade_in_frames = _frame_cnt_max/10;
float _number_of_grey_levels=10;
float _frames_per_level = _frame_cnt_max / _number_of_grey_levels; float _frames_per_level = _frame_cnt_max / _number_of_grey_levels;
ofColor someColor; ofColor someColor;
for(int i=0;i<=_number_of_grey_levels;i++){ if (_frame_cnt < _fade_in_frames) {
if (_frame_cnt>= _frames_per_level *( i-1) && +_frame_cnt < _frames_per_level * (i) ) { aColour.set(255, 255, 255, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
//set colour to current grey level ofSetColor(aColour);
c=255-( 255.0 * ( i /_number_of_grey_levels));
someColor.set(c);
}
ofSetColor(someColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight()); ofRect(0, 0, ofGetWidth(), ofGetHeight());
//cout << "FADE IN STROBE TIME " << endl;
} }
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
for(int i=0;i<_number_of_grey_levels;i++){
if (_frame_cnt>= _frames_per_level *( i-1) && +_frame_cnt < _frames_per_level * (i) ) {
//set colour to current grey level
c=255-( 255.0 * ( i /_number_of_grey_levels));
someColor.set(c);
}
ofSetColor(someColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
aColour.set(0, 0, 0, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColour);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
// cout << "FADE OUT STROBE TIME " << endl;
}
_frame_cnt++; _frame_cnt++;
ofDisableAlphaBlending();
break; break;
} }

View File

@ -28,6 +28,7 @@ protected:
bool _RUN_DONE; bool _RUN_DONE;
int _run_cnt, _save_cnt; int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max; float c, _frame_cnt, _frame_cnt_max,_save_cnt_max ;
}; };

View File

@ -45,13 +45,14 @@ using Poco::Thread;
void ColorMultiAnalysis::setup(int camWidth, int camHeight) void ColorMultiAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100; DELTA_T_SAVE = 150; // the right number is about 300
NUM_PHASE = 1; NUM_PHASE = 1;
NUM_RUN = 1; NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100; NUM_SAVE_PER_RUN = 300;
create_dir(); create_dir();
_frame_cnt = 0; _frame_cnt = 0;
_fade_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);
c = 0; c = 0;
} }
@ -95,15 +96,46 @@ void ColorMultiAnalysis::draw()
switch (_state) { switch (_state) {
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
if (_frame_cnt < _frame_cnt_max) { int _fade_in_frames = _frame_cnt_max/50;
if (_frame_cnt < _fade_in_frames) {
ofColor aColor;
aColor.setHsb(c, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255), ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
cout << "FADING IN..." << endl;
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < _frame_cnt_max-_fade_in_frames){
ofColor aColor; ofColor aColor;
aColor.setHsb(c, 255, 255); aColor.setHsb(c, 255, 255);
ofSetColor(aColor); ofSetColor(aColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
//how far are we as a percent of _frame_count_max //how far are we as a percent of _frame_count_max * 360 HUE VALUES
c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
} }
_frame_cnt++;
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
ofColor aColor;
aColor.setHsb(c, 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255), 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_fade_cnt++;
cout << "FADING OUT..." << endl;
}
_frame_cnt++;
break; break;
} }
@ -132,22 +164,18 @@ void ColorMultiAnalysis::draw()
void ColorMultiAnalysis::save_cb(Timer& timer) void ColorMultiAnalysis::save_cb(Timer& timer)
{ {
_save_cnt++; _save_cnt++;
// UPDATE THE COLOR ON THE SCREEN // UPDATE THE COLOR ON THE SCREEN
//float c_last = c; //float c_last = c;
cout << "COLORMULTIANALYSIS::saving...\n"; // cout << "COLORMULTIANALYSIS::saving...\n";
cout << "c_last... " << c << endl; // cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string file = _whole_file_path+"/"+file_name; // cout<<_whole_file_path<<endl;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
if(_save_cnt >= NUM_SAVE_PER_RUN){ if(_save_cnt >= NUM_SAVE_PER_RUN){
_RUN_DONE = true; _RUN_DONE = true;
} }
} }

View File

@ -22,6 +22,6 @@ public:
protected: protected:
bool _RUN_DONE; bool _RUN_DONE;
int _run_cnt, _save_cnt; int _run_cnt, _save_cnt, _fade_cnt;
float c, _frame_cnt, _frame_cnt_max; float c, _frame_cnt, _frame_cnt_max;
}; };

View File

@ -18,7 +18,7 @@ using Poco::Thread;
void ColorSingleAnalysis::setup(int camWidth, int camHeight) void ColorSingleAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100; DELTA_T_SAVE = 300;
NUM_PHASE = 1; NUM_PHASE = 1;
NUM_RUN = 1; NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100; NUM_SAVE_PER_RUN = 100;
@ -29,6 +29,9 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
r = 0; r = 0;
g = 0; g = 0;
b = 0; b = 0;
_fade_cnt=0;
fileNameTag = "";
} }
@ -71,26 +74,50 @@ void ColorSingleAnalysis::draw()
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
float one_third_of_frame_count_max=_frame_cnt_max/3; float one_third_of_frame_count_max=_frame_cnt_max/3;
if (_frame_cnt < one_third_of_frame_count_max){
int _fade_in_frames = one_third_of_frame_count_max/10;
if (_frame_cnt < _fade_in_frames){
ofSetColor(ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255), 0, 0);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
fileNameTag = "FADING";
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < one_third_of_frame_count_max){
r=255.0; r=255.0;
g=0.0; g=0.0;
b=0.0; b=0.0;
ofSetColor(r,g,b); ofSetColor(r,g,b);
ofRect(0, 0, ofGetWidth(), ofGetHeight()); ofRect(0, 0, ofGetWidth(), ofGetHeight());
fileNameTag = "RED";
} }
if (_frame_cnt >= one_third_of_frame_count_max && _frame_cnt < 2*one_third_of_frame_count_max){ if (_frame_cnt >= one_third_of_frame_count_max && _frame_cnt < 2*one_third_of_frame_count_max){
r=0.0; r=0.0;
g=255.0; g=255.0;
b=0.0; b=0.0;
ofSetColor(r,g,b); ofSetColor(r,g,b);
ofRect(0, 0, ofGetWidth(), ofGetHeight()); ofRect(0, 0, ofGetWidth(), ofGetHeight());
fileNameTag = "GREEN";
} }
if (_frame_cnt >= 2*one_third_of_frame_count_max && _frame_cnt < _frame_cnt_max){
if (_frame_cnt >= 2*one_third_of_frame_count_max && _frame_cnt < (_frame_cnt_max-_fade_in_frames) ){
r=0.0; r=0.0;
g=0.0; g=0.0;
b=255.0; b=255.0;
ofSetColor(r,g,b); ofSetColor(r,g,b);
ofRect(0, 0, ofGetWidth(), ofGetHeight()); ofRect(0, 0, ofGetWidth(), ofGetHeight());
fileNameTag = "BLUE";
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max){
ofSetColor(0, 0, 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255));
cout << "255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)"<< 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255) << endl;
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_fade_cnt++;
fileNameTag = "FADING";
} }
_frame_cnt++; _frame_cnt++;
@ -122,19 +149,15 @@ void ColorSingleAnalysis::draw()
void ColorSingleAnalysis::save_cb(Timer& timer) void ColorSingleAnalysis::save_cb(Timer& timer)
{ {
_save_cnt++; _save_cnt++;
// cout << "ColorSingleAnalysis::saving...\n";
cout << "ColorSingleAnalysis::saving...\n";
string file_name =ofToString(_frame_cnt,2)+"_"+ofToString((int)r,2)+"_"+ofToString((int)g,2)+"_"+ofToString((int)b,2)+"_"+ofToString(_run_cnt,2)+".jpg"; string file_name =ofToString(_save_cnt,2)+"_"+fileNameTag+"_"+ofToString(_run_cnt,2)+".jpg";
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file); //cout<<_whole_file_path+"/"+file_name<<endl;
cout<<_whole_file_path+"/"+file_name<<endl;
if(_save_cnt >= NUM_SAVE_PER_RUN) if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true; _RUN_DONE = true;

View File

@ -25,9 +25,9 @@ public:
void save_cb(Poco::Timer& timer); void save_cb(Poco::Timer& timer);
protected: protected:
bool _RUN_DONE; bool _RUN_DONE;
int _run_cnt, _save_cnt; string fileNameTag;
int _run_cnt, _save_cnt, _fade_cnt;
float r,g,b, _frame_cnt, _frame_cnt_max; float r,g,b, _frame_cnt, _frame_cnt_max;
}; };

View File

@ -18,12 +18,13 @@ using Poco::Thread;
void DiffNoiseAnalysis::setup(int camWidth, int camHeight) void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100; DELTA_T_SAVE = 600; // right number is about 450
NUM_PHASE = 1; NUM_PHASE = 1;
NUM_RUN = 1; NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100; NUM_SAVE_PER_RUN = 50;
create_dir(); create_dir();
_fade_cnt=0;
_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);
c = 0; c = 0;
@ -68,19 +69,67 @@ void DiffNoiseAnalysis::draw()
switch (_state) { switch (_state) {
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
ofColor aColour; ofColor aColour;
int rectSize = 5;
ofEnableAlphaBlending();
c = ofRandom(0,255); int _fade_in_frames = _frame_cnt_max/10;
aColour.setHsb(c, 255, 255);
if (_frame_cnt < _frame_cnt_max) if (_frame_cnt < _fade_in_frames) {
{
ofSetColor(aColour); for (int i=1; i < ofGetHeight() ; i=i+rectSize)
ofRect(0, 0, ofGetWidth(), ofGetHeight()); {
for (int j=1; j < ofGetWidth(); j=j+rectSize)
{
c = ofRandom(0,255);
aColour.set(c, c, c, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColour);
ofRect(j, i, rectSize, rectSize);
}
}
cout << "FADING IN..." << endl;
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
{
for (int j=1; j < ofGetWidth(); j=j+rectSize)
{
c = ofRandom(0,255);
aColour.set(c, c, c, 255);
ofSetColor(aColour);
ofRect(j, i, rectSize, rectSize);
}
}
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
{
for (int j=1; j < ofGetWidth(); j=j+rectSize)
{
c = ofRandom(0,255);
aColour.set(c, c, c, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColour);
ofRect(j, i, rectSize, rectSize);
}
}
_fade_cnt++;
cout << "FADING OUT..." << endl;
} }
ofDisableAlphaBlending();
_frame_cnt++; _frame_cnt++;
break; break;

View File

@ -27,7 +27,7 @@ public:
protected: protected:
bool _RUN_DONE; bool _RUN_DONE;
int _run_cnt, _save_cnt; int _run_cnt, _save_cnt, _fade_cnt;
float c, _frame_cnt, _frame_cnt_max; float c, _frame_cnt, _frame_cnt_max;
}; };

View File

@ -67,6 +67,7 @@ void IResponseAnalysis::draw()
{ {
switch (_state) { switch (_state) {
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
/// *** TODO *** /// /// *** TODO *** ///
@ -77,11 +78,11 @@ void IResponseAnalysis::draw()
{ {
ofSetColor(c, c, c); ofSetColor(c, c, c);
ofRect(0, 0, ofGetWidth(), ofGetHeight()); ofRect(0, 0, ofGetWidth(), ofGetHeight());
c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max); c = 255.0 * (_frame_cnt_max*_frame_cnt_max - _frame_cnt*_frame_cnt)/(_frame_cnt_max*_frame_cnt_max);
} }
_frame_cnt++; _frame_cnt++;
break; break;
} }
@ -108,26 +109,18 @@ void IResponseAnalysis::draw()
void IResponseAnalysis::save_cb(Timer& timer) void IResponseAnalysis::save_cb(Timer& timer)
{ {
_save_cnt++; _save_cnt++;
// UPDATE THE COLOR ON THE SCREEN
//float c_last = c;
cout << "IResponseAnalysis::saving...\n"; cout << "IResponseAnalysis::saving...\n";
cout << "c_last... " << c << endl; //cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location; string thisLocation = RefractiveIndex::_location;
//RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera //RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
// fileName = imageSaveFolderPath+whichAnalysis+"_"+ofToString(100.0*i*scanLineSpeed/ofGetHeight(),2)+"%_"+ofToString(i)+".jpg"; // fileName = imageSaveFolderPath+whichAnalysis+"_"+ofToString(100.0*i*scanLineSpeed/ofGetHeight(),2)+"%_"+ofToString(i)+".jpg";
//ofSaveImage(vectorOfPixels[i], fileName, OF_IMAGE_QUALITY_BEST); //ofSaveImage(vectorOfPixels[i], fileName, OF_IMAGE_QUALITY_BEST);
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
if(_save_cnt >= NUM_SAVE_PER_RUN) if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true; _RUN_DONE = true;
} }

View File

@ -29,5 +29,6 @@ protected:
bool _RUN_DONE; bool _RUN_DONE;
int _run_cnt, _save_cnt; int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max; float c, _frame_cnt, _frame_cnt_max;
}; };

View File

@ -1,150 +0,0 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "LatencyTestAnalysis.h"
#include "ofMain.h"
#include "Poco/Timer.h"
#include "Poco/Thread.h"
#include "RefractiveIndex.h"
using Poco::Timer;
using Poco::TimerCallback;
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);
c = 0;
}
void LatencyTestAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<LatencyTestAnalysis> save_callback(*this, &LatencyTestAnalysis::save_cb);
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
cout << "RUN NUM = " << i;
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
_RUN_DONE = false;
_frame_cnt = 0; _save_cnt = 0;
while(!_RUN_DONE)
Thread::sleep(3);
save_timer->stop();
}
}
void LatencyTestAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void LatencyTestAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
if (_frame_cnt < _frame_cnt_max/3)
{
c = 0;
ofSetColor(c, c, c);
cout<<"1st third"<<endl;
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
if (_frame_cnt >= _frame_cnt_max/3 && _frame_cnt < 2*( _frame_cnt_max/3))
{
c = 255;
cout<<"2nd third"<<endl;
ofSetColor(c, c, c);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
if (_frame_cnt >= 2*( _frame_cnt_max/3) && _frame_cnt < _frame_cnt_max)
{
c = 0;
cout<<"3rd third"<<endl;
ofSetColor(c, c, c);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
// this runs at save_cb timer rate = DELTA_T_SAVE
void LatencyTestAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
// UPDATE THE COLOR ON THE SCREEN
//float c_last = c;
cout << "LatencyTestAnalysis::saving...\n";
cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location;
//RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
// fileName = imageSaveFolderPath+whichAnalysis+"_"+ofToString(100.0*i*scanLineSpeed/ofGetHeight(),2)+"%_"+ofToString(i)+".jpg";
//ofSaveImage(vectorOfPixels[i], fileName, OF_IMAGE_QUALITY_BEST);
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true;
}

View File

@ -3,7 +3,7 @@
~ contact: dviid@labs.ciid.dk ~ contact: dviid@labs.ciid.dk
*/ */
#include "CamFrameRateAnalysis.h" #include "RelaxRateAnalysis.h"
#include "ofMain.h" #include "ofMain.h"
#include "Poco/Timer.h" #include "Poco/Timer.h"
@ -16,27 +16,29 @@ using Poco::TimerCallback;
using Poco::Thread; using Poco::Thread;
void CamFrameRateAnalysis::setup(int camWidth, int camHeight) void RelaxRateAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 1000/30; DELTA_T_SAVE = 300;
NUM_PHASE = 1; NUM_PHASE = 1;
NUM_RUN = 1; NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100; NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_level = 0;
_flip = 1;
_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);
c = 0; c = 0;
} }
void CamFrameRateAnalysis::acquire() void RelaxRateAnalysis::acquire()
{ {
Timer* save_timer; Timer* save_timer;
TimerCallback<CamFrameRateAnalysis> save_callback(*this, &CamFrameRateAnalysis::save_cb); TimerCallback<RelaxRateAnalysis> save_callback(*this, &RelaxRateAnalysis::save_cb);
// RUN ROUTINE // RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) { for(int i = 0; i < NUM_RUN; i++) {
@ -57,13 +59,13 @@ void CamFrameRateAnalysis::acquire()
} }
} }
void CamFrameRateAnalysis::synthesise() 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
} }
// this runs at frame rate = 33 ms for 30 FPS // this runs at frame rate = 33 ms for 30 FPS
void CamFrameRateAnalysis::draw() void RelaxRateAnalysis::draw()
{ {
switch (_state) { switch (_state) {
@ -72,24 +74,31 @@ void CamFrameRateAnalysis::draw()
/// *** TODO *** /// /// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames // still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** /// /// *** TODO *** ///
float totalTime=_frame_cnt_max/2;
if (_frame_cnt <= _frame_cnt_max)
float numSteps=10;
vector<float>stepLengths;
//c must increase until frame_cnt_max * 0.5 and then decrease afterwards
if (_frame_cnt < _frame_cnt_max)
{ {
float lightLevel=pow(_level,2);
ofSetColor(c, c, c); ofSetColor(c, c, c);
ofRect(0, 0, ofGetWidth(), ofGetHeight()); ofRect(0, 0, ofGetWidth(), ofGetHeight());
c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max);
cout<<_frame_cnt<<endl; c = ofMap(lightLevel, 0, pow(_frame_cnt_max/2,2), 0, 255);
if (_frame_cnt <= (_frame_cnt_max/2)) {
_level+=1;
} else {
_level-=1;
}
} else {
cout << "RELAXRATE RUN COMPLETED" << endl;
_state = STATE_SYNTHESISING;
} }
_frame_cnt++;
_frame_cnt++;
cout << "_frame_cnt:" << _frame_cnt << endl;
break; break;
} }
@ -115,10 +124,10 @@ void CamFrameRateAnalysis::draw()
} }
// this runs at save_cb timer rate = DELTA_T_SAVE // this runs at save_cb timer rate = DELTA_T_SAVE
void CamFrameRateAnalysis::save_cb(Timer& timer) void RelaxRateAnalysis::save_cb(Timer& timer)
{ {
_save_cnt++; _save_cnt++;
cout << "RelaxRateAnalysis::saving...\n";
//cout << "c_last... " << c << endl; //cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location; string thisLocation = RefractiveIndex::_location;

View File

@ -8,12 +8,13 @@
#include "AbstractAnalysis.h" #include "AbstractAnalysis.h"
#include "Poco/Timer.h" #include "Poco/Timer.h"
class LatencyTestAnalysis : public AbstractAnalysis
{ class RelaxRateAnalysis : public AbstractAnalysis
{
public: public:
LatencyTestAnalysis(): AbstractAnalysis("LATENCY_TEST"){;} RelaxRateAnalysis(): AbstractAnalysis("RELAXRATE"){;}
virtual ~LatencyTestAnalysis(){;} virtual ~RelaxRateAnalysis(){;}
public: public:
@ -27,6 +28,7 @@ public:
protected: protected:
bool _RUN_DONE; bool _RUN_DONE;
float _flip, _level;
int _run_cnt, _save_cnt; int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max; float c, _frame_cnt, _frame_cnt_max;

View File

@ -46,36 +46,44 @@ using Poco::Thread;
void ShadowScapesAnalysis::setup(int camWidth, int camHeight) void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
{ {
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir(); create_dir();
_speed = 300; _speed = 900.0; // 900.0 is the correct number
_scanLineWidth = 100.0;
_run_cnt = 0;
_save_cnt = 0;
} }
void ShadowScapesAnalysis::acquire() void ShadowScapesAnalysis::acquire()
{ {
int w; int w;
if(_dir == H) w = ofGetWidth(); if (_dir == V) w = ofGetHeight();
else if(_dir == V) w = ofGetHeight(); if (_dir == H) w = ofGetWidth();
_step = ((w / _speed) * 1000) / 50; if (_dir == D) w = ofGetHeight();
_step = ((w/_speed) * 1000.0) / 500.0;
_line = 0; _line = 0;
Timer scan_timer(0, 50);
// RUN ROUTINE
TimerCallback<ShadowScapesAnalysis> strobe_callback(*this, &ShadowScapesAnalysis::scan_cb); for(int i = 0; i < NUM_RUN; i++) {
_state = STATE_SCAN; Timer save_timer(0, DELTA_T_SAVE);
TimerCallback<ShadowScapesAnalysis> save_callback(*this, &ShadowScapesAnalysis::save_cb);
scan_timer.start(strobe_callback);
_RUN_DONE = false;
while(_state != STATE_ANALYSIS) _frame_cnt = 0; _save_cnt = 0;
Thread::sleep(5);
save_timer.start(save_callback);
scan_timer.stop();
// do analysis here while(!_RUN_DONE)
// go back to the files i've saved and do the math here - Thread::sleep(3);
/* save_timer.stop();
while(_state != STATE_STOP) }
Thread::sleep(100);
*/
} }
@ -92,33 +100,98 @@ void ShadowScapesAnalysis::draw()
switch (_state) { switch (_state) {
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
static int _pos; _line += _step;
if(_state == STATE_ANALYSIS) { //cout << "* _line:" << _line << endl;
ofSetColor(0, 200, 0);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
return;
}
if(_state == STATE_SCAN) { if(_dir == V) {
if(_pos != _line) {
//take snap??
_pos = _line;
}
ofSetColor(255, 255, 255);
if(_dir == H) ofRect(_pos, 0, 50, ofGetHeight()); ofEnableAlphaBlending();
else if(_dir == V) ofRect(0, _pos, ofGetWidth(), 50);
ofSetColor(255, 255, 255);
ofRect(0, (_line-2*_scanLineWidth), ofGetWidth(), _scanLineWidth);
for (float i=0; i<25; i++)
{
ofSetColor(255, 255, 255, i*5.0);
ofRect(0, (_line-2*_scanLineWidth)+(2*_scanLineWidth/(i+1)), ofGetWidth(), _scanLineWidth);
ofRect(0, (_line-2*_scanLineWidth)-(2*_scanLineWidth/(i+1)), ofGetWidth(), _scanLineWidth);
}
ofDisableAlphaBlending();
} }
if(_dir == H) {
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
ofRect( (_line-2*_scanLineWidth), 0, _scanLineWidth, ofGetHeight());
for (float i=0; i<25; i++)
{
ofSetColor(255, 255, 255, i*5);
ofRect( (_line-2*_scanLineWidth)+(2*_scanLineWidth/(i+1)), 0, _scanLineWidth, ofGetHeight());
ofRect( (_line-2*_scanLineWidth)-(2*_scanLineWidth/(i+1)), 0, _scanLineWidth, ofGetHeight());
}
ofDisableAlphaBlending();
}
if(_dir == D) {
ofEnableAlphaBlending();
ofPushMatrix();
ofTranslate(-ofGetWidth(), 0);
ofRotate(-45);
ofSetColor(255, 255, 255);
ofRect(0, (_line-_scanLineWidth)+ofGetHeight()-_scanLineWidth, 2*ofGetWidth(), _scanLineWidth);
for (float i=0; i<25; i++)
{
ofSetColor(255, 255, 255, i*5);
ofRect(0, (_line-_scanLineWidth)+ofGetHeight()-_scanLineWidth+(2*_scanLineWidth/(i+1)), 2*ofGetWidth(), _scanLineWidth);
ofRect(0, (_line-_scanLineWidth)+ofGetHeight()-_scanLineWidth-(2*_scanLineWidth/(i+1)), 2*ofGetWidth(), _scanLineWidth);
}
ofPopMatrix();
ofDisableAlphaBlending();
}
if(_dir == V && int(_line) >= (ofGetHeight()+4*_scanLineWidth)){
cout << "VERTICAL IS DONE - _line >= (ofGetHeight()+4*_scanLineWidth) is TRUE" << endl;
_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
if(_dir == H && int(_line) >= (ofGetWidth()+4*_scanLineWidth)) {
//cout << "HORIZONTAL IS DONE - _line >= (ofGetWidth()+4*_scanLineWidth)) is TRUE" << endl;
_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
if(_dir == D && int(_line) >= (1.5*ofGetHeight()+4*_scanLineWidth)) {
//cout << "DIAGONAL IS DONE - _line >= (1.5*ofGetHeight()+4*_scanLineWidth)) is TRUE" << endl;
_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
break; break;
} }
case STATE_SYNTHESISING: case STATE_SYNTHESISING:
{ {
// display animation of something while the synthesis in on-going... // display animation of something while the synthesis in on-going...
_state = STATE_DISPLAY_RESULTS;
break; break;
} }
@ -128,21 +201,32 @@ void ShadowScapesAnalysis::draw()
break; break;
} }
default: default:
break; break;
} }
} }
void ShadowScapesAnalysis::scan_cb(Timer& timer) void ShadowScapesAnalysis::save_cb(Timer& timer)
{ {
_line += _step;
cout << "ShadowScapesAnalysis::saving...\n";
if((_dir == H && _line >= ofGetWidth()) || string file_name;
(_dir == V && _line >= ofGetHeight())) {
_state = STATE_ANALYSIS; if(_dir == H) {
file_name = ofToString(_save_cnt, 2)+"_H_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg";
} }
if(_dir == V) {
file_name = ofToString(_save_cnt, 2)+"_V_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg";
}
if(_dir == D) {
file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg";
}
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_save_cnt++;
} }

View File

@ -54,13 +54,17 @@ public:
void synthesise(); void synthesise();
void draw(); void draw();
void scan_cb(Poco::Timer& timer); void save_cb(Poco::Timer& timer);
protected: protected:
int _line; bool _RUN_DONE;
int _speed; // pix per second float _line;
int _step; float _speed; // pix per second
float _scanLineWidth; // pix per second
float _step;
shadow_type _dir; shadow_type _dir;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
}; };

350
src/ShapeFromShadingAnalysis.cpp Executable file
View File

@ -0,0 +1,350 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "ShapeFromShadingAnalysis.h"
#include "ofMain.h"
#include "Poco/Timer.h"
#include "Poco/Thread.h"
#include "RefractiveIndex.h"
using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 300;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir();
_level = 0;
_flip = 1;
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
c = 0;
}
void ShapeFromShadingAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<ShapeFromShadingAnalysis> save_callback(*this, &ShapeFromShadingAnalysis::save_cb);
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
cout << "RUN NUM = " << i;
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
_RUN_DONE = false;
_frame_cnt = 0; _save_cnt = 0;
_animation_cnt1 = 0;
_animation_cnt2 = 0;
_animation_cnt3 = 0;
_animation_cnt4 = 0;
_animation_cnt5 = 0;
_animation_cnt6 = 0;
_animation_cnt7 = 0;
_animation_cnt8 = 0;
_animation_cnt9 = 0;
_animation_cnt10 = 0;
_animation_cnt11 = 0;
_animation_cnt12 = 0;
_animation_cnt13 = 0;
_animation_cnt14 = 0;
_animation_cnt15 = 0;
_animation_cnt16 = 0;
_animation_reset = false; // coundn't get this to work - so using seperate counters - shitty!
while(!_RUN_DONE)
Thread::sleep(3);
save_timer->stop();
}
}
void ShapeFromShadingAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void ShapeFromShadingAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
if (_frame_cnt <= _frame_cnt_max)
{
ofEnableAlphaBlending();
int _quarter_frame_cnt_max = _frame_cnt_max/4;
int _half_frame_cnt_max = _frame_cnt_max/2;
int _threequarters_frame_cnt_max = 3*_frame_cnt_max/4;
//TODO: put in CROSS FADES, ETC§E
/*
if (_animation_reset == true)
{
_animation_cnt1 = 0;
_animation_cnt2 = 0;
_animation_cnt3 = 0;
_animation_cnt4 = 0;
}
*/
if(_frame_cnt < _quarter_frame_cnt_max) {
quad = "QUAD1";
//cout << quad << endl;
if(_frame_cnt <= _quarter_frame_cnt_max/4)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt1, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(3*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt1++;
}
if(_frame_cnt <= _quarter_frame_cnt_max/2)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt2, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt2++;
}
if(_frame_cnt <= _quarter_frame_cnt_max)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt3, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt3++;
}
if((7*_quarter_frame_cnt_max/8 < _frame_cnt) && (_frame_cnt < _quarter_frame_cnt_max))
{
ofSetColor(0, 0, 0, ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255));
//cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl;
ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt4++;
}
}
if((_frame_cnt >= _frame_cnt_max/4) && (_frame_cnt < _frame_cnt_max/2)){
quad = "QUAD2";
//cout << quad << endl;
int _local_frame_count = _frame_cnt - _quarter_frame_cnt_max;
//cout << "_local_frame_count" << _local_frame_count << endl;
if(_local_frame_count < _quarter_frame_cnt_max/4)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt5, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(0, 3*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2);
//cout << "_animation_cnt1: " << _animation_cnt1 << endl;
_animation_cnt5++;
}
if(_local_frame_count < _quarter_frame_cnt_max/2)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt6, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(0, 2.5*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2);
_animation_cnt6++;
}
if(_local_frame_count < _quarter_frame_cnt_max)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt7, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(0, 2.25*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2);
_animation_cnt7++;
}
if((7*_quarter_frame_cnt_max/8 < _local_frame_count) && (_local_frame_count < _quarter_frame_cnt_max))
{
ofSetColor(0, 0, 0, ofMap(_animation_cnt8, 0, _quarter_frame_cnt_max/8, 0, 255));
//cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl;
ofRect(0, 2.25*ofGetHeight()/4, ofGetWidth(), ofGetHeight()/2);
//ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt8++;
}
}
//draw bottom middle
if ((_frame_cnt >= _frame_cnt_max/2) && (_frame_cnt < 3*_frame_cnt_max/4)) {
quad = "QUAD3";
//cout << quad << endl;
int _local_frame_count = _frame_cnt - _half_frame_cnt_max;
//cout << "_local_frame_count" << _local_frame_count << endl;
if(_local_frame_count <= _quarter_frame_cnt_max/4)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt9, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight());
//cout << "_animation_cnt1: " << _animation_cnt1 << endl;
_animation_cnt9++;
}
if(_local_frame_count < _quarter_frame_cnt_max/2)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt10, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(1.25*ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight());
_animation_cnt10++;
}
if(_local_frame_count < _quarter_frame_cnt_max)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt11, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(1.5*ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight());
_animation_cnt11++;
}
if((7*_quarter_frame_cnt_max/8 < _local_frame_count) && (_local_frame_count < _quarter_frame_cnt_max))
{
ofSetColor(0, 0, 0, ofMap(_animation_cnt12, 0, _quarter_frame_cnt_max/8, 0, 255));
//cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl;
ofRect(1.5*ofGetWidth()/4, 0, -ofGetWidth()/2, ofGetHeight());
//ofRect(2.25*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.5*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
//ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt12++;
}
}
//draw left
if((_frame_cnt >= 3*_frame_cnt_max/4) && (_frame_cnt <= _frame_cnt_max) ){
quad = "QUAD4";
//cout << quad << endl;
int _local_frame_count = _frame_cnt - _threequarters_frame_cnt_max;
//cout << "_local_frame_count" << _local_frame_count << endl;
if(_local_frame_count <= _quarter_frame_cnt_max/4)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt13, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(0, ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2);
//cout << "_animation_cnt13: " << _animation_cnt1 << endl;
_animation_cnt13++;
}
if(_local_frame_count < _quarter_frame_cnt_max/2)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt14, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(0, 1.25*ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2);
_animation_cnt14++;
}
if(_local_frame_count < _quarter_frame_cnt_max)
{
ofSetColor(255, 255, 255, ofMap(_animation_cnt15, 0, _quarter_frame_cnt_max/4, 0, 255));
ofRect(0, 1.5*ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2);
_animation_cnt15++;
}
if((7*_quarter_frame_cnt_max/8 < _local_frame_count) && (_local_frame_count < _quarter_frame_cnt_max))
{
ofSetColor(0, 0, 0, ofMap(_animation_cnt16, 0, _quarter_frame_cnt_max/8, 0, 255));
//cout << "4 counter: " << ofMap(_animation_cnt4, 0, _quarter_frame_cnt_max/8, 0, 255) << endl;
ofRect(0, 1.5*ofGetHeight()/4, ofGetWidth(), -ofGetHeight()/2);
_animation_cnt16++;
}
}
ofDisableAlphaBlending();
}
_frame_cnt++;
//cout << "_frame_cnt:" << _frame_cnt << endl;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
// this runs at save_cb timer rate = DELTA_T_SAVE
void ShapeFromShadingAnalysis::save_cb(Timer& timer)
{
//cout << "ShapeFromShadingAnalysis::saving...\n";
string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg";
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_save_cnt++;
if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true;
}

53
src/ShapeFromShadingAnalysis.h Executable file
View File

@ -0,0 +1,53 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#pragma once
#include "AbstractAnalysis.h"
#include "Poco/Timer.h"
class ShapeFromShadingAnalysis : public AbstractAnalysis
{
public:
ShapeFromShadingAnalysis(): AbstractAnalysis("SHAPEFROMSHADING"){;}
virtual ~ShapeFromShadingAnalysis(){;}
public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);
protected:
string quad;
bool _RUN_DONE;
float _flip, _level;
int _run_cnt, _save_cnt;
int _animation_cnt1;
int _animation_cnt2;
int _animation_cnt3;
int _animation_cnt4;
int _animation_cnt5;
int _animation_cnt6;
int _animation_cnt7;
int _animation_cnt8;
int _animation_cnt9;
int _animation_cnt10;
int _animation_cnt11;
int _animation_cnt12;
int _animation_cnt13;
int _animation_cnt14;
int _animation_cnt15;
int _animation_cnt16;
int _animation_reset; // this reset part didn't get working - so using 16 different counters! yay!
float c, _frame_cnt, _frame_cnt_max;
};

161
src/StrobeAnalysis.cpp Executable file
View File

@ -0,0 +1,161 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "StrobeAnalysis.h"
#include "ofMain.h"
#include "Poco/Timer.h"
#include "Poco/Thread.h"
#include "RefractiveIndex.h"
using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
void StrobeAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 100;
NUM_RUN = 1;
_strobe_cnt = 0;
_strobe_cnt_max = 20; // 40 x 500 ms = 20000 ms = 20 seconds run time
_strobe_interval = 1000; //every 0.5seconds = 15 frames
_frame_cnt_max = _strobe_cnt_max * _strobe_interval * ofGetFrameRate()/1000;
// The British Health and Safety Executive recommend that a net flash rate for a bank of strobe lights does not exceed 5 flashes per second, at which only 5% of photosensitive epileptics are at risk. It also recommends that no strobing effect continue for more than 30 seconds, due to the potential for discomfort and disorientation.
//or 20 times, every one second...
_save_cnt_max = _strobe_cnt_max*_strobe_interval/DELTA_T_SAVE;
create_dir();
}
void StrobeAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<StrobeAnalysis> save_callback(*this, &StrobeAnalysis::save_cb);
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
_save_cnt = 0;
_frame_cnt = 0;
cout << "RUN NUM = " << i;
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
_RUN_DONE = false;
_frame_cnt = 0; _save_cnt = 0;
while(!_RUN_DONE)
Thread::sleep(3);
save_timer->stop();
}
}
void StrobeAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void StrobeAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
ofEnableAlphaBlending();
ofColor aColour;
int _fade_in_frames = _frame_cnt_max/10;
cout<< "_fade_in_frames" << _fade_in_frames<< endl;
if (_frame_cnt < _fade_in_frames) {
aColour.set(255, 255, 255, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColour);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
//cout << "FADE IN STROBE TIME " << endl;
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
//cout << "_frame_cnt: " << _frame_cnt << endl;
//cout << "frame_cnt % 15: " << _frame_cnt%15 << endl;
//cout << "MAIN STROBE TIME " << endl;
if (_frame_cnt%int(ofGetFrameRate()*_strobe_interval/1000) < (ofGetFrameRate()*_strobe_interval/1000)/2)
{
ofSetColor(255, 255, 255);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_strobe_cnt++;
_strobe_on = 1;
} else if (_frame_cnt%int(ofGetFrameRate()*_strobe_interval/1000) >= (ofGetFrameRate()*_strobe_interval/1000)/2)
{
ofSetColor(0, 0, 0);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_strobe_on = 0;
}
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
aColour.set(255, 255, 255, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColour);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
// cout << "FADE OUT STROBE TIME " << endl;
}
_frame_cnt++;
ofDisableAlphaBlending();
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
// this runs at save_cb timer rate = DELTA_T_SAVE
void StrobeAnalysis::save_cb(Timer& timer)
{
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg";
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_save_cnt++;
cout << "_save_cnt" << _save_cnt << endl;
cout << "_save_cnt_max" << _save_cnt_max << endl;
//TODO: something fucked here with my calc of _save_cnt_max - new structure should fix it?
if(_save_cnt >= _save_cnt_max-10) {
_RUN_DONE = true;
}
}

View File

@ -10,11 +10,11 @@
#include "Poco/Timer.h" #include "Poco/Timer.h"
class CamFrameRateAnalysis : public AbstractAnalysis class StrobeAnalysis : public AbstractAnalysis
{ {
public: public:
CamFrameRateAnalysis(): AbstractAnalysis("CAM_NOISE"){;} StrobeAnalysis(): AbstractAnalysis("STROBE"){;}
virtual ~CamFrameRateAnalysis(){;} virtual ~StrobeAnalysis(){;}
public: public:
@ -28,7 +28,10 @@ public:
protected: protected:
bool _RUN_DONE; bool _RUN_DONE;
int _run_cnt, _save_cnt; int _strobe_cnt, _run_cnt, _strobe_cnt_max;
float c, _frame_cnt, _frame_cnt_max; int _save_cnt;
int _frame_cnt, _frame_cnt_max, _save_cnt_max ;
int _strobe_interval;
bool _strobe_on;
}; };