/******************************************************************** ** 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 : ICLGeom/demos/simplex-2D/simplex-2D.cpp ** ** Module : ICLGeom ** ** 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 GUI gui; typedef FixedColVector Pos; float error_function(const Pos &p){ return ::sqrt(sqr(p[0]-400) + sqr(p[1]-550)); } void init(){ gui << Draw().minSize(20,20).handle("draw") << Show(); Img32f bg(Size(1000,1000),1); Channel32f bgc = bg[0]; for(int y=0;ysetAutoResetQueue(false); } void run(){ static SimplexOptimizer opt(error_function,2,1); static std::vector curr = SimplexOptimizer::createDefaultSimplex(Pos(950,840)); static float err = 10000; DrawHandle draw = gui["draw"]; std::vector ps(curr.size()); for(unsigned int i=0;icolor((!(step%3))*255, (!((step+1)%3))*255, (!((step+2)%3))*255,255); draw->linestrip(ps); draw->fill(255,255,255,255); draw->color(0,0,0,0); draw->rect(0,25,400,50); draw->color(255,0,0,255); draw->text("error: " + str(err), 30,30,10); draw.render(); SimplexOptimizer::Result r = opt.optimize(curr); curr = r.vertices; err = r.fx; Thread::msleep(100); } int main(int n, char **ppc){ return ICLApp(n,ppc,"",init,run).exec(); };