RefractiveIndex/example/RefractiveIndex.cpp

216 lines
5.7 KiB
C++
Raw Normal View History

2012-01-24 15:13:07 +01:00
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ author: dviid
2012-01-24 16:52:22 +01:00
~ contact: dviid@labs.ciid.dk
2012-01-24 15:13:07 +01:00
*/
#include "RefractiveIndex.h"
#include "IResponseAnalysis.h"
#include "StrobeAnalysis.h"
#include "ShadowScapesAnalysis.h"
2012-01-24 16:52:22 +01:00
#include "ColorMultiAnalysis.h"
#include "ColorSingleAnalysis.h"
#include "CamFrameRateAnalysis.h"
#include "CamNoiseAnalysis.h"
#include "LatencyTestAnalysis.h"
#include "DiffNoiseAnalysis.h"
2012-01-24 15:13:07 +01:00
#define CAMERA_ID 1
#define CAMERA_ACQU_WIDTH 640
#define CAMERA_ACQU_HEIGHT 480
2012-01-24 16:52:22 +01:00
ofPixels RefractiveIndex::_pixels;
ofVideoGrabber RefractiveIndex::_vidGrabber;
int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id;
bool RefractiveIndex::_vid_stream_open;
bool RefractiveIndex::_vid_toggle_on;
string RefractiveIndex::_location;
2012-01-24 15:13:07 +01:00
void RefractiveIndex::setup()
{
// rate
ofSetFrameRate(30);
ofSetVerticalSync(TRUE);
// camera
_vid_w = CAMERA_ACQU_WIDTH;
_vid_h = CAMERA_ACQU_HEIGHT;
_vid_id = CAMERA_ID;
_vid_stream_open = false;
2012-01-24 16:52:22 +01:00
_vid_toggle_on = false;
2012-01-24 15:13:07 +01:00
// gui
2012-01-24 16:52:22 +01:00
_gui.loadFont("MONACO.TTF", 8);
2012-01-24 15:13:07 +01:00
_gui.setup("REFRACTIVE INDEX", 0, 0, ofGetWidth(), ofGetHeight());
// -> PANEL #0
_gui.addPanel("configuration", 4, false);
_gui.setWhichPanel(0);
// --> COLUMN #0
_gui.setWhichColumn(0);
2012-01-24 16:52:22 +01:00
//GET THE INPUT NAMES FROM THE QT VIDEO GRABBER
_gui.addToggle("more cam settings", "SETTINGS", 0);
_gui.addToggle("turn on camera", "CAM_IS_GO", 0);
2012-01-24 15:13:07 +01:00
_gui.addButtonSlider("camera width", "CAM_WIDTH", _vid_w, CAMERA_ACQU_WIDTH, 1920, true);
_gui.addButtonSlider("camera height", "CAM_HEIGHT", _vid_h, CAMERA_ACQU_HEIGHT, 1080, true);
_gui.setWhichColumn(1);
_gui.addToggle("run", "RUN", 0);
_gui.setupEvents();
_gui.enableEvents();
// -- this gives you back an ofEvent for all events in this control panel object
ofAddListener(_gui.guiEvent, this, &RefractiveIndex::eventsIn);
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
_currentAnalysis = NULL;
_analysisAdapator = NULL;
2012-01-24 16:52:22 +01:00
//getting a warning from the OFlog that the pixels aren't allocated
// void ofPixels::allocate(int w, int h, ofImageType type)
//_pixels.allocate(
_location="MIDDLESBOROUGH";
//setup_camera();
2012-01-24 15:13:07 +01:00
}
void RefractiveIndex::update()
{
_gui.update();
2012-01-24 16:52:22 +01:00
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
if (_vidGrabber.isFrameNew())
{
_pixels = _vidGrabber.getPixelsRef(); //get ofPixels from the camera
}
2012-01-24 15:13:07 +01:00
}
void RefractiveIndex::draw()
{
2012-01-24 16:52:22 +01:00
ofBackground(0, 0, 0);
2012-01-24 15:13:07 +01:00
if(_currentAnalysis)
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
_currentAnalysis->draw();
2012-01-24 16:52:22 +01:00
// i would like to pass the pixels we've just got from the camera into the draw function for the current analysis here
// but the way that 'draw' functino in _currentAnalysis, which is an AbstractAnalysis, is as a "Pure Virtual Function"
// which i think means it can't be passed any arguments or data???
//_currentAnalysis->draw(_pixels);
else
2012-01-24 15:13:07 +01:00
_gui.draw();
2012-01-24 16:52:22 +01:00
// if there is a new frame in the camera
/* if (_vidGrabber.isFrameNew())
{
_vidGrabber.draw(0,0); //get ofPixels from the camera
}*/
2012-01-24 15:13:07 +01:00
}
void RefractiveIndex::setup_camera()
{
if(_vid_stream_open) {
_vidGrabber.close();
_vid_stream_open = false;
}
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) {
ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber";
return;
2012-01-24 16:52:22 +01:00
}
_vidGrabber.listDevices();
_vidGrabber.setVerbose(true);
2012-01-24 15:13:07 +01:00
_vid_stream_open = true;
2012-01-24 16:52:22 +01:00
_vidGrabber.setDeviceID(_vid_id);
2012-01-24 15:13:07 +01:00
}
void RefractiveIndex::keyPressed (int key)
{
if( key =='f')
2012-01-24 16:52:22 +01:00
ofToggleFullscreen();
2012-01-24 15:13:07 +01:00
else if( key =='s') {
if(_currentAnalysis && _analysisAdapator) {
2012-01-24 16:52:22 +01:00
_analysisAdapator->stop();
2012-01-24 15:13:07 +01:00
delete _currentAnalysis;
delete _analysisAdapator;
_currentAnalysis = NULL;
_analysisAdapator = NULL;
2012-01-24 16:52:22 +01:00
cout << "bingo!\n\n"; //bingo means 'stop analysis'?
2012-01-24 15:13:07 +01:00
}
}
}
void RefractiveIndex::mouseDragged(int x, int y, int button)
{
_gui.mouseDragged(x, y, button);
}
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
void RefractiveIndex::mousePressed(int x, int y, int button)
{
_gui.mousePressed(x, y, button);
}
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
void RefractiveIndex::mouseReleased(int x, int y, int button)
{
2012-01-24 16:52:22 +01:00
_gui.mouseReleased();
2012-01-24 15:13:07 +01:00
}
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
void RefractiveIndex::eventsIn(guiCallbackData& data)
{
if(data.getDisplayName() == "run"){
2012-01-24 16:52:22 +01:00
ofLog(OF_LOG_VERBOSE) << "run...";
//_currentAnalysis = new ShadowScapesAnalysis(); // create an analysis and give it an adaptor
//_currentAnalysis = new StrobeAnalysis(); // create an analysis and give it an adaptor
//_currentAnalysis = new IResponseAnalysis(); // create an analysis and give it an adaptor
//_currentAnalysis = new ColorMultiAnalysis();
//_currentAnalysis = new CamFrameRateAnalysis();
//_currentAnalysis = new CamNoiseAnalysis();
_currentAnalysis = new ColorSingleAnalysis();
//_currentAnalysis = new LatencyTestAnalysis();
//_currentAnalysis = new DiffNoiseAnalysis();
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis); //Adaptors start and stop
2012-01-24 15:13:07 +01:00
_currentAnalysis->setup(_vid_w, _vid_h);
_analysisAdapator->start();
}
2012-01-24 16:52:22 +01:00
if(data.getDisplayName() == "turn on camera" ){
_vid_toggle_on=!_vid_toggle_on;
if (_vid_toggle_on)
{
setup_camera();
} else if (!_vid_toggle_on) {
_vidGrabber.close();
}
}
//more cam settings", "SETTINGS"
if( data.getDisplayName() == "more cam settings" ){
_vidGrabber.videoSettings();
}
2012-01-24 15:13:07 +01:00
}
void RefractiveIndex::grabBackgroundEvent(guiCallbackData & data)
{
2012-01-24 16:52:22 +01:00
2012-01-24 15:13:07 +01:00
}