From ab6c3d5be52a4985cfc87f26c92c1c14dc217603 Mon Sep 17 00:00:00 2001 From: dviid Date: Fri, 6 Apr 2012 13:21:44 +0200 Subject: [PATCH] unloading images --- src/AbstractAnalysis.cpp | 9 +++- src/AbstractAnalysis.h | 8 ++- src/ShadowScapesAnalysis.cpp | 100 +++++++++++++++++++++++++++++++++-- src/ShadowScapesAnalysis.h | 3 ++ 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index f0b83ee..564d0ab 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -12,8 +12,12 @@ void AbstractAnalysis::do_synthesize() { cout << "NUM_RUN: " << i << endl; _saved_filenames_analysis.clear(); - _saved_filenames_synthesis.clear(); - + _saved_filenames_synthesis.clear(); + + if(_state == STATE_STOP) goto exit; + _state = STATE_ALLOCATE; + allocate(); + if(_state == STATE_STOP) goto exit; _state = STATE_ACQUIRING; acquire(); if(_state == STATE_STOP) goto exit; @@ -22,6 +26,7 @@ void AbstractAnalysis::do_synthesize() { if(_state == STATE_STOP) goto exit; _state = STATE_DISPLAY_RESULTS; displayresults(); + _state = STATE_CLEANUP; cleanup(); } diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index 298f9a6..c70dbd0 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -13,10 +13,13 @@ #define ANALYSIS_PATH "analysis/" #define SYNTHESIS_PATH "synthesis/" +#define STATE_ALLOCATE 0x0010 +#define STATE_CLEANUP 0x0001 #define STATE_ACQUIRING 0x1111 #define STATE_SYNTHESISING 0x2222 #define STATE_DISPLAY_RESULTS 0x3333 #define STATE_STOP 0xDEADBEEF +#define STATE_DEF 0x0000 class AbstractAnalysis { @@ -48,8 +51,11 @@ protected: // display the results from disk virtual void displayresults() = 0; + + // allocate all images + virtual void allocate() {;} - // display the results from disk + // deallocate all images virtual void cleanup() {;} diff --git a/src/ShadowScapesAnalysis.cpp b/src/ShadowScapesAnalysis.cpp index 4af38e2..62255a1 100755 --- a/src/ShadowScapesAnalysis.cpp +++ b/src/ShadowScapesAnalysis.cpp @@ -51,6 +51,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) _show_image = false; _image_shown = false; + /* image1.clear(); image2.clear(); image3.clear(); @@ -97,6 +98,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + */ } @@ -224,24 +226,116 @@ void ShadowScapesAnalysis::displayresults() if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; - } - + } else { + _show_image = true; + _image_shown = false; + + } +/* if(image3.loadImage(_saved_filenames_synthesis[i])){ - image3.loadImage(_saved_filenames_synthesis[i]); + //image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; } + */ } } +void ShadowScapesAnalysis::allocate() +{ + _RUN_DONE = false; + + image1.clear(); + image3.clear(); + image4.clear(); + image5.clear(); + + image1.setUseTexture(false); + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR); + image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR); + image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR); + image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR); + + + while(!_RUN_DONE && _state != STATE_STOP) + Thread::sleep(3); +} + +void ShadowScapesAnalysis::cleanup() +{ + _RUN_DONE = false; + + image1.clear(); + image3.clear(); + image4.clear(); + image5.clear(); + + while(!_RUN_DONE && _state != STATE_STOP) + Thread::sleep(3); +} + + // the animation draw - and the output draw void ShadowScapesAnalysis::draw() { switch (_state) { + case STATE_ALLOCATE: + { + image2.clear(); + image2.setUseTexture(true); + image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR); + + cvColorImage1.clear(); + cvGrayImage1.clear(); + cvGrayDiff1.clear(); + + cvColorImage2.clear(); + cvGrayImage2.clear(); + cvGrayDiff2.clear(); + + cvConvertorImage.clear(); + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + _state = STATE_DEF; + + _RUN_DONE = true; + break; + } + case STATE_CLEANUP: + { + image2.clear(); + + cvColorImage1.clear(); + cvGrayImage1.clear(); + cvGrayDiff1.clear(); + + cvColorImage2.clear(); + cvGrayImage2.clear(); + cvGrayDiff2.clear(); + + _state = STATE_DEF; + + _RUN_DONE = true; + break; + } + case STATE_ACQUIRING: { _line += _step; diff --git a/src/ShadowScapesAnalysis.h b/src/ShadowScapesAnalysis.h index 9a3b89a..90008a4 100755 --- a/src/ShadowScapesAnalysis.h +++ b/src/ShadowScapesAnalysis.h @@ -25,6 +25,9 @@ public: void acquire(); void synthesise(); void displayresults(); + + void allocate(); + void cleanup(); void draw();