/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLIO/apps/multi-viewer/multi-viewer.cpp ** ** Module : ICLIO ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include #include VSplit gui; struct Input{ std::string a,b; GenericGrabber grabber; ImageHandle handle; const ImgBase *lastImage; std::string id; void operator()(){ lastImage = grabber.grab(); handle = lastImage; } void save(){ if(out) out->send(lastImage); } SmartPtr out; }; int nInputs = -1; Array2D inputs; bool asyncMode = false; void save_all(){ std::string fn; bool ok = false; struct Evt : public ICLApp::AsynchronousEvent{ std::string &fn; bool &ok; Evt(std::string &fn, bool &ok):fn(fn),ok(ok){} void execute(){ try{ static std::string lastDir; fn = saveFileDialog("","save files (# is replaced by the input-ID)",lastDir); if(fn.length()){ lastDir = File(fn).getDir(); } }catch(...){ } ok = true; } }; ICLApp::instance()->executeInGUIThread(new Evt(fn,ok)); while(!ok) Thread::msleep(10); if(fn.length()){ MatchResult r = match(fn,"([^#]*)#([^#]*)",3); if(r.matched && r.submatches.size()>2){ std::string pref = r.submatches[1]; std::string suff = r.submatches[2]; for(int i=0;i ts = tok(s,"@"); if(!ts.size()) return ""; return ts[0]; } void init(){ if(pa("-r")) GenericGrabber::resetBus("dc"); ProgArg p = pa("-i"); Size layout = pa("-l") ? pa("-l").as() : Size(ceil(nInputs*0.5),2); ICLASSERT_THROW(layout.getDim() >= nInputs, ICLException("given layout has less cells than the given number of inputs")); std::vector rows(layout.height); inputs = Array2D(layout); for(int i=0;i()); if(pa("-f")) in.grabber.useDesired(pa("-f").as()); if(pa("-d")) in.grabber.useDesired(pa("-d").as()); rows[i/layout.width] << Image().label(in.id + ": "+in.a+" "+fix_at_stuff(in.b)).handle(in.id); if(pa("-o")){ ProgArg o = pa("-o"); if((int)(2*i+1) >= o.n()){ throw ICLException("less outputs were given to -o " "then inputs were given to -i"); } in.out = new GenericImageOutput(o[2*i], o[2*i+1]); } } for(int i=0;i(in.id); }catch(...){}; } } template void run(){ while(!gui["on"].as()){ Thread::msleep(10); if(!N && !asyncMode){ static ButtonHandle save = gui["save"]; if(save.wasTriggered()){ save_all(); } } } if(!N){ gui["fps"].render(); if(!asyncMode){ static ButtonHandle save = gui["save"]; for(int i=0;i 8) throw ICLException("asynchronous mode is only supported for up to 8 inputs!"); if(nInputs > 0) app.addThread(run<0>); if(nInputs > 1) app.addThread(run<1>); if(nInputs > 2) app.addThread(run<2>); if(nInputs > 3) app.addThread(run<3>); if(nInputs > 4) app.addThread(run<4>); if(nInputs > 5) app.addThread(run<5>); if(nInputs > 6) app.addThread(run<6>); if(nInputs > 7) app.addThread(run<7>); }else{ app.addThread(run<0>); } return app.exec(); }