egami
C++ Image Processing program
/homes/esi30/DCS339/coursework/src/Processes/roberts.cpp
Go to the documentation of this file.
00001 #include <array>
00002 #include <memory>
00003 #include <string>
00004 
00005 #include <gtkmm/image.h>
00006 #include <gtkmm/dialog.h>
00007 #include <gtkmm/checkbutton.h>
00008 #include <gtkmm/stock.h>
00009 
00010 #include "../display_unit.hpp"
00011 #include "../processing_page.hpp"
00012 #include "../processing_unit.hpp"
00013 #include "../utils.hpp"
00014 #include "convolution.hpp"
00015 #include "utils.hpp"
00016 
00017 namespace{
00018     class Config: public Gtk::Dialog {
00019         public:
00020             Config(): q("Algorithm:"), rX("Roberts X"), rY("Roberts Y") {
00021                 set_resizable(false);
00022 
00023                 get_vbox()->pack_start(q);
00024                 get_vbox()->pack_start(rX);
00025                 get_vbox()->pack_start(rY);
00026 
00027                 rX.set_active();
00028                 rY.set_active();
00029 
00030                 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
00031                 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
00032 
00033                 show_all_children();
00034             }
00035 
00036             bool is_act() const {
00037                 return rX.get_active() || rY.get_active();
00038             }
00039 
00040             bool do_rX() const {
00041                 return rX.get_active();
00042             }
00043 
00044             bool do_rY() const {
00045                 return rY.get_active();
00046             }
00047 
00048         private:
00049             Gtk::Label q;
00050             Gtk::CheckButton rX, rY;
00051     };
00052 
00053     Display_unit* impl(const Image_unit *in){
00054         Config c;
00055         if(c.run()!=Gtk::RESPONSE_OK || !(c.is_act()))
00056             return nullptr;
00057         c.hide();
00058 
00059         Image_unit *out=nullptr;
00060 
00061         if(c.do_rX()){
00062             std::array<std::array<double, 3>, 3> kernel={{{{0., 0., 0.}},{{0., 0., -1.}},{{0., 1., 0.}}}};
00063             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00064             add_max(&out, tmp.get());
00065         }
00066         if(c.do_rY()){
00067             std::array<std::array<double, 3>, 3> kernel={{{{0., 0., 0.}},{{0., -1., 0.}},{{0., 0., 1.}}}};
00068             std::unique_ptr<Image_unit> tmp(apply<1>(in, kernel, 1));
00069             add_max(&out, tmp.get());
00070         }
00071 
00072         return out;
00073     }
00074 }
00075 
00076 namespace Processes{
00077     void roberts(){
00078         Gtk::Image icon(cmake_install_prefix+std::string("/share/egami/icons/roberts.png"));
00079         std::shared_ptr<Processing_unit> pu(new Processing_unit(Processing(&impl), "Roberts", icon, false));
00080         Processing_page::add_unit_to_page("Edge detection", pu);
00081     }
00082 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends