From: maziyar <ma...@ua...> - 2005-05-02 20:14:05
|
Hi, I am using the basic_manager tutorial provided for vxl gui (vgui), except I have modified it by adding an extra menu item to save data to an external file. The code is below. Basically, when I call my_save(), it first loads an image (using load_image(), the unmodified code provided by the basic_manager tutorial), then it calls my function "save_data()" which should then save a vector to a file. The problem is this: if I don't call load_image(), or if I cancel load_image at the browse dialog box, the save_data WORKS and creates an external file, "my_object.bvl", to save the data in. However, if load_imag is called, and an image is selected, then the save data no longer creates the "my_object.bvl" file and thus does not save the data to the external file. All the other code is exactly the same as the basic_manager tutorial provided in the VXL installation. My only modification is the addition of the my_save() menu item and the save_data() member function. Any assistance would be greatly appreciated. Thanks void basic_manager::my_save() { load_image(); save_data(); } bool basic_manager::save_data() { if (!messagebox("Would you like to save the training set?")){ return false; } //else, save data vsl_b_ofstream bfs("my_object.bvl"); if (!bfs){ vcl_cerr<<"Failed to open my_object.bvl for output."<<vcl_endl; } else{ vcl_vector<float> test(4); test[0] = 1.0; test[1] = 1.0; test[2] = 1.0; test[3] = 1.0; vsl_b_write(bfs,test); bfs.close(); } return true; } //Function to load an image then redraw so image appears void basic_manager::load_image() { vgui_dialog load_image_dlg("Load image file"); static vcl_string image_filename = ""; static vcl_string ext = "*.*"; load_image_dlg.file("Image Filename:", ext, image_filename); if (!load_image_dlg.ask()) return; img_ = vil1_load(image_filename.c_str()); itab_->set_image(img_); } |