/******************************************************************** ** 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/plot-widget-3D/plot-widget-3D.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 #include #include GUI gui; Scene scene; static Range32f round_range(Range32f r){ if(r.minVal > r.maxVal){ std::swap(r.minVal,r.maxVal); } float m = fabs(r.maxVal - r.minVal); float f = 1; if( m > 1 ){ while( m/f > 100){ f *= 10; } }else{ while( m/f < 10){ f *= 0.1; } } r.minVal = floor(r.minVal/f) * f; r.maxVal = ceil(r.maxVal/f) * f; return r; } void init(){ gui << Plot3D().handle("plot").minSize(32,24) << Show(); if(pa("-r")){ SHOW(round_range(Range32f(pa("-r",0),pa("-r",1)))); ::exit(0); } } void add_scatter(PlotHandle3D &plot){ static const int N = 100000; static std::vector ps(N); static std::vector cs(N); GRand r(0,4); FixedMatrix T(0.000001,0,0, 0,0.000002,0, 0,0,0.000004); // T *= create_rot_3D(1,2,3); for(int i=0;iscatter(ps,cs,Range32f(-0.00001,0.00001)); } static Time tt = Time::now(); static float t = 0; float f(float x, float y){ float r = sqrt(sqr(x-50) + sqr(y-50)); return sin(0.2*r - 3*t) * exp(-(r*r)/800); } void add_function(PlotHandle3D &plot){ plot->setViewPort(Range32f(0,0),Range32f(0,0),Range32f(-3,3)); plot->nocolor(); t = tt.age().toSecondsDouble(); static SceneObject *o = 0; o = plot->surf(f,Range32f(0,100),Range32f(0,100), 200, 200, o); } void add_label(PlotHandle3D &plot){ TODO_LOG("labels are distorted -> text-lables must be added to " " an extra root-object, that moves the labels, but does not " " scale each of these! or can we perhaps invert the scaling " " of the text by setting up it's paricular transformation?"); plot->color(255,255,255,255); plot->label(Vec(50,50,-3),"sin(r)"); } void run(){ PlotHandle3D plot = gui["plot"]; plot->lock(); plot->clear(); add_scatter(plot); add_function(plot); add_label(plot); plot->unlock(); plot->render(); Thread::msleep(30); } int main(int n, char **a){ return ICLApp(n,a,"-r(2)",init,run).exec(); }