egami
C++ Image Processing program
/homes/esi30/DCS339/coursework/src/Processes/select_roi.cpp
Go to the documentation of this file.
00001 #include <memory>
00002 #include <tuple>
00003 #include <string>
00004 
00005 #include <gtkmm/image.h>
00006 #include <gtkmm/messagedialog.h>
00007 
00008 #include "../display_unit.hpp"
00009 #include "../processing_page.hpp"
00010 #include "../processing_unit.hpp"
00011 #include "../utils.hpp"
00012 
00013 namespace{
00014     Display_unit *impl(const Image_unit *in){
00015         if(in->has_roi()){
00016             Gtk::MessageDialog d("Region of interest already in selection. Unselect first.");
00017             d.run();
00018             return nullptr;
00019         }
00020 
00021         std::tuple<int,int,int,int> zone=in->selection();
00022 
00023         if(std::get<0>(zone)<0 || std::get<1>(zone)<0 || std::get<2>(zone)<0 || std::get<3>(zone)<0){
00024             Gtk::MessageDialog d("No selection avaible, please select a zone first. See help for more informations.");
00025             d.run();
00026             return nullptr;
00027         }
00028 
00029         if(std::get<0>(zone)+std::get<2>(zone)>static_cast<int>(in->height()) || std::get<1>(zone)+std::get<3>(zone)>static_cast<int>(in->width())){
00030             Gtk::MessageDialog d("Selection error. Please, reselect. See help for more informations.");
00031             d.run();
00032             return nullptr;
00033         }
00034 
00035         Image_unit *out=new Image_unit(*in);
00036         out->clip(std::get<0>(zone),  std::get<1>(zone),  std::get<2>(zone),  std::get<3>(zone));
00037         return out;
00038     }
00039 }
00040 
00041 namespace Processes{
00042     void select_roi(){
00043         Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/select_roi.png"));
00044         std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Select ROI", icon, false));
00045         Processing_page::add_unit_to_page("Tools", pu);
00046     }
00047 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends