/******************************************************************** ** 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 : ICLQt/demos/plot-component/plot-component.cpp ** ** Module : ICLQt ** ** 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 #include #include HBox gui; void mouse(const MouseEvent &e){ std::cout << "MouseEvent {"; if(e.isMoveEvent()) std::cout << " move" << std::endl; if(e.isPressEvent()) std::cout << " press" << std::endl; if(e.isReleaseEvent()) std::cout << " release" << std::endl; if(e.isDragEvent()) std::cout << " drag" << std::endl; std::cout << " pos: " << e.getPos32f() << std::endl; std::cout << " widget pos: " << e.getWidgetPos() << std::endl; std::cout << "}" << std::endl; } void init(){ bool gl = pa("-gl"); gui << ( VBox() << Plot(0,6.5,-1,1,gl).handle("plot1").minSize(15,12) << Plot(0,6.5,-1,1,gl).handle("plot2").minSize(15,12) << Plot(-5,5,-5,5,gl).handle("plot9").minSize(15,12) ) << ( VBox() << Plot(0,6.5,-1,1,gl).handle("plot3").minSize(15,12) << Plot(0,6.5,-1,1,gl).handle("plot4").minSize(15,12) << Plot(0,0,0,0,gl).handle("plot10").minSize(15,12) ) << (VBox() << Plot(-9,9,-9,9,gl).handle("plot5").minSize(15,12) << Plot(0,0,0,0,gl).handle("plot6").minSize(15,12) << Plot(0,0,0,0,gl).handle("plot11").minSize(15,12) ) << (VBox() << Plot(0,0,0,0,gl,"something [pi]").handle("plot7").minSize(15,12) << Plot(0,0,0,0,gl).handle("plot8").minSize(15,12) << Plot(0,0,0,0,gl).handle("plot12").minSize(15,12) << CheckBox("animate",true).out("run") ) << Show(); gui["plot1"].install(mouse); } float f_sin(float x, float){ return (sin(x)+1)*127; } float f_sin_cos(float x, float y){ return (sin(x)*cos(2*y)+1)*55 + 145; } void run(){ while(!gui["run"].as()){ Thread::msleep(100); } static PlotHandle plots[] = { gui["plot1"], gui["plot2"], gui["plot3"], gui["plot4"], gui["plot5"], gui["plot6"], gui["plot7"], gui["plot8"], gui["plot9"], gui["plot10"], gui["plot11"], gui["plot12"], }; // static std::vector sinData(100); // static std::vector cosData(100); //static std::vector tanData(100); static PlotWidget::SeriesBuffer sinData(100),cosData(100),tanData(100); static std::vector scatterData1(5000); static std::vector scatterData2(5000); static std::vector scatterData3(1000); static Time t = Time::now(); float dtSec = (Time::now()-t).toSecondsDouble(); static Array2D grid(30,30); static bool first = true; if(first){ first = false; for(int x=0;x 1.E-10 ? sinData.back()/cosData.back() : 1.E30); static std::vector fData(100); for(size_t xi=0;xi fDataSamples(100); for(size_t i=0;i X(fDataSamples.size(), 5); DynMatrix Y(fDataSamples.size(), 1); for(size_t i=0;i R = Y*X.pinv(false); static std::vector fApprox(fData.size()); for(size_t xi=0;xilock(); if(i!=8 ){ plot->clear(); } if(i < 4){ plot->setPropertyValue("tics.y-distance",0.25); }else if(i<6 || i>=8){ plot->setPropertyValue("tics.y-distance",3); plot->setPropertyValue("tics.x-distance",3); }else{ plot->setPropertyValue("tics.y-distance",0.5); plot->setPropertyValue("tics.x-distance",1); } if(i==0 || i==3){ plot->linewidth(1); plot->color(255,0,0); if(i==0){ plot->fill(255,0,0,100); plot->setPropertyValue("enable fill",true); } plot->label("sin(x)"); plot->series(sinData); } if(i==1 || i == 3){ plot->color(0,255,0); if(i==1) plot->sym('o',2); plot->label("cos (x)"); plot->series(cosData); } if(i==2 || i == 3){ plot->color(0,100,255); plot->label("tan (x)"); plot->series(tanData); } if(i == 4){ plot->label("red noise"); plot->color(255,0,0); plot->scatter(scatterData1); plot->label("dirty blue noise"); plot->color(0,100,255); plot->scatter(scatterData2); } if(i == 5){ plot->color(0,200,255); plot->label("some nice shape"); plot->scatter(scatterData3,true); plot->color(255,0,0); plot->fill(255,0,0,100); plot->rect(-.2,-.2,.4,.4); plot->line(0,0,3,3); plot->text(3,3,"the center"); } if( i == 6){ plot->setDataViewPort(Range32f(sinSeries[0].y, sinSeries[sinSeriesUsed-1].y), Range32f(0,0)); plot->color(255,0,0); plot->label("continous data"); plot->series(&sinSeries[0].x, sinSeriesUsed, 2); // plot->addSeriesData(&sinSeries[0].x, sinSeriesUsed, // new AbstractPlotWidget::Pen(QColor(255,0,0)), "continous data", 2); plot->setBackgroundFunction(f_sin); } if(i == 7){ //float xs[] = { 1,2,3,4}; //float ys[] = { 1,2,3,4}; plot->setDataViewPort(Range32f(0,4),Range32f(-.8,.8)); const float data[8] = {.1,.2,.3,.4,.5,.6,-.7,.3}; const float data2[8] = {0.7,.1,.2,.3,.4,.5,.6,-.7}; const float data3[10] = {.3,.4,.5,0.7,.1,.2,.3,.4,.5,.6}; plot->color(255,0,0); plot->fill(255,0,0,100); plot->label("red bars"); plot->bars(data,8); plot->color(0,255,0); plot->fill(0,255,0,100); plot->label("green bars"); plot->bars(data2,8); plot->color(0,100,255); plot->fill(0,100,255,100); plot->label("blue bars"); plot->bars(data3,10); //plot->addScatterData('x',xs,ys,4,"dummy data"); } if(i == 8){ static Time last = Time::now(); float dtS = (Time::now() -last).toSecondsDouble(); if( dtS > 5){ plot->clear(); last = Time::now(); } plot->color(dtS*50,0,255-dtS*50); plot->linestrip(scatterData3); plot->color(0,0,0); plot->title("shape drawn as linestrip"); plot->setPropertyValue("borders.top",18); } if(i == 9){ plot->color(255,0,0); plot->grid(grid); plot->setDataViewPort(rxGrid,ryGrid); plot->setPropertyValue("labels.x-precision",0); plot->setPropertyValue("labels.y-precision",0); plot->title("some distorted grid"); plot->setPropertyValue("borders.top",18); plot->setBackgroundFunction(f_sin_cos); } if(i == 10){ plot->fill(255,0,0,100); plot->setDataViewPort(Range32f(0,1),Range32f(-50,50)); plot->setPropertyValue("enable fill",true); plot->setPropertyValue("tics.x-distance",0.2); plot->setPropertyValue("tics.y-distance",5); plot->setPropertyValue("labels.x-precision",1); plot->setPropertyValue("labels.y-precision",0); plot->label("orig. function"); plot->series(fData); plot->sym('x',2); plot->color(0,100,255); plot->label("samples"); plot->scatter(fDataSamples); plot->nosym(); plot->color(0,255,0); plot->fill(0,255,0,100); plot->label("regression result"); plot->series(fApprox); } if(i==11){ plot->setPropertyValue("enable fill",true); plot->setDataViewPort(Range32f(0,2*M_PI),Range32f(-1,1)); plot->nocolor(); plot->label("sin"); plot->fill(255,0,0); plot->bars(sinData.data(), sinData.size()/5,5); plot->label("cos"); plot->fill(0,255,0); plot->bars(cosData.data(), cosData.size()/5,5); plot->label("tan"); plot->fill(0,50,255); plot->bars(tanData.data(), tanData.size()/5,5); } plot->unlock(); plot.render(); } static FPSLimiter fpsLimit(20,10); fpsLimit.wait(); } int main(int n, char **ppc){ return ICLApp(n,ppc,"-use-opengl|-gl",init,run).exec(); }