From 4e143892f5abbe75e8c433fe42cf7435aae078dc Mon Sep 17 00:00:00 2001 From: damian Date: Wed, 3 Feb 2010 08:20:38 +0100 Subject: [PATCH] - menu system modified: artvertiser.cpp modified: models.xml --- artvertiser/artvertiser.cpp | 239 ++++++++++++++++++++++++++++++++++++++------ artvertiser/models.xml | 45 ++++++--- 2 files changed, 239 insertions(+), 45 deletions(-) rewrite artvertiser/models.xml (100%) diff --git a/artvertiser/artvertiser.cpp b/artvertiser/artvertiser.cpp index 8cb9f88..6c201c0 100644 --- a/artvertiser/artvertiser.cpp +++ b/artvertiser/artvertiser.cpp @@ -192,9 +192,18 @@ CvPoint2D32f *c1 = new CvPoint2D32f[4]; vector artvert_roi_vec; char *image_path; -vector< string > model_file_list; -int which_model_file=0; -bool next_model_requested = false; +typedef struct _Artvert +{ + string model_file; + string artvert_image_file; + string artist; + string advert; + string name; +} Artvert; + +vector< Artvert > artvert_list; +int which_artvert=0; +bool next_artvert_requested = false; vector< bool > model_file_needs_training; #include "ofxXmlSettings/ofxXmlSettings.h" @@ -225,6 +234,18 @@ bool show_status = false; bool show_profile_results = false; string status_string = ""; +// menu +// hide after 5s +#define MENU_HIDE_TIME 5.0f +bool menu_show = false; +FTime menu_timer; +bool menu_is_showing = false; +bool menu_up = false; +bool menu_down = false; +bool menu_accept = false; +void updateMenu(); +void drawMenu(); + /* use this to read paths from the file system string getExtension(const string &file) @@ -426,19 +447,29 @@ void exit_handler() } } -bool loadOrTrain( bool wants_training, const char* model_file ) +bool loadOrTrain( int new_index ) { - bool trained = multi->loadOrTrainCache( wants_training, model_file); + // fetch data + if ( new_index < 0 || new_index >= artvert_list.size() ) + { + fprintf(stderr,"loadOrTrain: invalid index %i (artvert_list has %i members)\n", new_index, artvert_list.size() ); + return false; + + } + bool wants_training = model_file_needs_training[new_index]; + string model_file = artvert_list[new_index].model_file; + + bool trained = multi->loadOrTrainCache( wants_training, model_file.c_str()); if ( !trained ) return false; // copy char model_file before munging with strcat - char s[strlen(model_file)]; - strcpy (s, model_file); + char s[1024]; + strcpy (s, model_file.c_str()); strcat(s, ".roi"); roi_vec = readROI(s); - strcpy( s, model_file ); + strcpy( s, model_file.c_str() ); strcat(s, ".artvertroi"); artvert_roi_vec = readROI(s); if ( artvert_roi_vec.empty() ) @@ -448,7 +479,7 @@ bool loadOrTrain( bool wants_training, const char* model_file ) } // load model_image for use with diffing, later - model_image = cvLoadImage(model_file); + model_image = cvLoadImage(model_file.c_str()); c1[0].x = roi_vec[0]; c1[0].y = roi_vec[1]; @@ -467,15 +498,15 @@ bool loadOrTrain( bool wants_training, const char* model_file ) bool loadOrTrainNext() { // get next filename - string filename = model_file_list.at(which_model_file); - printf("next model requested: loading model %i:%s\n", which_model_file, filename.c_str() ); + string filename = artvert_list.at(which_artvert).model_file; + printf("next model requested: loading model %i:%s\n", which_artvert, filename.c_str() ); // load or train - bool success = loadOrTrain( model_file_needs_training.at(which_model_file), filename.c_str() ); + bool success = loadOrTrain( which_artvert /*model_file_needs_training.at(which_artvert ), filename.c_str()*/ ); // store if we need to train again - model_file_needs_training[which_model_file] = !success; + model_file_needs_training[which_artvert ] = !success; // for next time - which_model_file = (which_model_file+1)%model_file_list.size(); + which_artvert = (which_artvert +1)%artvert_list.size(); return success; } @@ -515,7 +546,14 @@ static bool init( int argc, char** argv ) { if (i==argc-1) usage(argv[0]); - model_file_list.push_back( argv[i+1] ); + Artvert a; + a.model_file = argv[i+1]; + a.artist = "unknown artist"; + a.name = "cmdline"; + a.advert = "unknown advert"; + a.artvert_image_file = "artvert1.png"; + // store + artvert_list.push_back( a ); printf(" -m: adding model image '%s'\n", argv[i+1] ); i++; } @@ -621,37 +659,50 @@ static bool init( int argc, char** argv ) ofxXmlSettings data; data.loadFile( model_file_list_file ); - if ( data.getNumTags( "models" ) == 1 ) + if ( data.getNumTags( "artverts" ) == 1 ) { - data.pushTag( "models" ); - int num_filenames = data.getNumTags( "model" ); - printf(" -ml: opened %s, %i models\n", model_file_list_file, num_filenames ); + data.pushTag( "artverts" ); + int num_filenames = data.getNumTags( "artvert" ); + printf(" -ml: opened %s, %i artverts\n", model_file_list_file, num_filenames ); for ( int i=0; i %s:%s:%s:%s\n", a.name.c_str(), a.artist.c_str(), + a.advert.c_str(), a.artvert_image_file.c_str() ); + artvert_list.push_back( a ); data.popTag(); } data.popTag(); } else { - printf(" -ml: error reading '%s'\n", model_file_list_file ); + printf(" -ml: error reading '%s': couldn't find 'artverts' tag\n", model_file_list_file ); } } // check if model file list is empty - if ( model_file_list.empty() ) + if ( artvert_list.empty() ) { // add default - model_file_list.push_back("model.bmp"); + Artvert a; + a.model_file = "model.bmp"; + a.name = "unnamed"; + a.artist = "unknown artist"; + a.advert = "unknown advert"; + a.artvert_image_file = "artvert1.png"; + artvert_list.push_back( a ); } // set up training flags - for ( int i=0; i