plot_window_subplot.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00034 #include <acado/user_interaction/plot_window_subplot.hpp>
00035 #include <acado/curve/curve.hpp>
00036 
00037 
00038 BEGIN_NAMESPACE_ACADO
00039 
00040 
00041 
00042 //
00043 // PUBLIC MEMBER FUNCTIONS:
00044 //
00045 
00046 PlotWindowSubplot::PlotWindowSubplot( )
00047 {
00048 
00049         plotVariableX     = 0;
00050         plotVariableY     = 0;
00051         plotVariablesGrid = 0;
00052         plotExpressionX   = 0;
00053         plotExpressionY   = 0;
00054         plotEnum          = PLOT_NOTHING;
00055 
00056         plotMode   = PM_UNKNOWN;
00057         plotFormat = PF_PLAIN;
00058 
00059         xRangeLowerLimit = INFTY;
00060         xRangeUpperLimit = INFTY;
00061         yRangeLowerLimit = INFTY;
00062         yRangeUpperLimit = INFTY;
00063 
00064     plot3D = BT_FALSE;
00065 
00066         nLines     = 0;
00067         lineValues = 0;
00068 
00069         nData = 0;
00070         data  = 0;
00071 
00072         next = 0;
00073 }
00074 
00075 
00076 PlotWindowSubplot::PlotWindowSubplot(   const Expression& _expression,
00077                                                                                 const char* const _title,
00078                                                                                 const char* const _xLabel,
00079                                                                                 const char* const _yLabel,
00080                                                                                 PlotMode _plotMode,
00081                                                                                 double _xRangeLowerLimit,
00082                                                                                 double _xRangeUpperLimit,
00083                                                                                 double _yRangeLowerLimit,
00084                                                                                 double _yRangeUpperLimit
00085                                                                                 )
00086 {
00087 
00088     if( _expression.isVariable() == BT_TRUE ){
00089 
00090         plotVariableX     = 0;
00091         plotVariableY     = new Expression(_expression);
00092         plotVariablesGrid = 0;
00093         plotExpressionX   = 0;
00094         plotExpressionY   = 0;
00095     }
00096     else{
00097 
00098         plotVariableX     = 0;
00099         plotVariableY     = 0;
00100         plotVariablesGrid = 0;
00101         plotExpressionX   = 0;
00102         plotExpressionY   = new Expression(_expression);
00103     }
00104 
00105         plotEnum = PLOT_NOTHING;
00106 
00107         setTitle( _title );
00108         setXLabel( _xLabel );
00109         setYLabel( _yLabel );
00110 
00111         setPlotMode( _plotMode );
00112         setPlotFormat( PF_PLAIN );
00113 
00114         setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
00115 
00116     plot3D = BT_FALSE;
00117 
00118         nLines     = 0;
00119         lineValues = 0;
00120 
00121         nData = 0;
00122         data  = 0;
00123 
00124         next = 0;
00125 }
00126 
00127 
00128 PlotWindowSubplot::PlotWindowSubplot(   const Expression& _expressionX,
00129                                                                                 const Expression& _expressionY,
00130                                                                                 const char* const _title,
00131                                                                                 const char* const _xLabel,
00132                                                                                 const char* const _yLabel,
00133                                                                                 PlotMode _plotMode,
00134                                                                                 double _xRangeLowerLimit,
00135                                                                                 double _xRangeUpperLimit,
00136                                                                                 double _yRangeLowerLimit,
00137                                                                                 double _yRangeUpperLimit
00138                                                                                 )
00139 {
00140 
00141     if( _expressionX.isVariable() == BT_TRUE && _expressionY.isVariable() == BT_TRUE ){
00142 
00143         plotVariableX     = new Expression(_expressionX);
00144         plotVariableY     = new Expression(_expressionY);
00145         plotVariablesGrid = 0;
00146         plotExpressionX   = 0;
00147         plotExpressionY   = 0;
00148     }
00149     else{
00150 
00151         plotVariableX     = 0;
00152         plotVariableY     = 0;
00153         plotVariablesGrid = 0;
00154         plotExpressionX   = new Expression(_expressionX);
00155         plotExpressionY   = new Expression(_expressionY);
00156     }
00157 
00158         plotEnum          = PLOT_NOTHING;
00159 
00160         setTitle( _title );
00161         setXLabel( _xLabel );
00162         setYLabel( _yLabel );
00163 
00164         setPlotMode( _plotMode );
00165         setPlotFormat( PF_PLAIN );
00166 
00167         setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
00168 
00169     plot3D = BT_FALSE;
00170 
00171         nLines     = 0;
00172         lineValues = 0;
00173 
00174         nData = 0;
00175         data  = 0;
00176 
00177         next = 0;
00178 }
00179 
00180 
00181 
00182 PlotWindowSubplot::PlotWindowSubplot(   PlotName _name,
00183                                                                                 const char* const _title,
00184                                                                                 const char* const _xLabel,
00185                                                                                 const char* const _yLabel,
00186                                                                                 PlotMode _plotMode,
00187                                                                                 double _xRangeLowerLimit,
00188                                                                                 double _xRangeUpperLimit,
00189                                                                                 double _yRangeLowerLimit,
00190                                                                                 double _yRangeUpperLimit
00191                                                                                 )
00192 {
00193         plotVariableX     = 0;
00194     plotVariableY     = 0;
00195     plotVariablesGrid = 0;
00196         plotExpressionX   = 0;
00197         plotExpressionY   = 0;
00198         plotEnum          = _name;
00199 
00200         setTitle( _title );
00201         setXLabel( _xLabel );
00202         setYLabel( _yLabel );
00203 
00204         setPlotMode( _plotMode );
00205         setPlotFormat( PF_PLAIN );
00206 
00207         setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
00208 
00209     plot3D = BT_FALSE;
00210 
00211         nLines     = 0;
00212         lineValues = 0;
00213 
00214         nData = 0;
00215         data  = 0;
00216 
00217         next = 0;
00218 }
00219 
00220 
00221 PlotWindowSubplot::PlotWindowSubplot( const VariablesGrid& _plotVariable,
00222                                       const char* const _title,
00223                                       const char* const _xLabel,
00224                                       const char* const _yLabel,
00225                                       PlotMode _plotMode,
00226                                       double _xRangeLowerLimit,
00227                                       double _xRangeUpperLimit,
00228                                       double _yRangeLowerLimit,
00229                                       double _yRangeUpperLimit,
00230                                       BooleanType  _plot3D   )
00231 {
00232         plotVariableX     = 0;
00233         plotVariableY     = 0;
00234         plotVariablesGrid = new VariablesGrid(_plotVariable);
00235         plotExpressionX   = 0;
00236         plotExpressionY   = 0;
00237         plotEnum          = PLOT_NOTHING;
00238 
00239     setTitle( _title );
00240     setXLabel( _xLabel );
00241     setYLabel( _yLabel );
00242 
00243     setPlotMode( _plotMode );
00244         setPlotFormat( PF_PLAIN );
00245 
00246     setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
00247 
00248     plot3D = _plot3D;
00249 
00250     nLines     = 0;
00251     lineValues = 0;
00252 
00253     nData = 0;
00254     data  = 0;
00255 
00256     next = 0;
00257 }
00258 
00259 
00260 PlotWindowSubplot::PlotWindowSubplot( const Curve& _curve,
00261                                       double _xRangeLowerLimit,
00262                                       double _xRangeUpperLimit,
00263                                       const char* const _title,
00264                                       const char* const _xLabel,
00265                                       const char* const _yLabel,
00266                                       PlotMode _plotMode,
00267                                       double _yRangeLowerLimit,
00268                                       double _yRangeUpperLimit
00269                                                                           )
00270 {
00271         
00272         
00273         plotVariableX     = 0;
00274         plotVariableY     = 0;
00275         plotVariablesGrid = new VariablesGrid;
00276         plotExpressionX   = 0;
00277         plotExpressionY   = 0;
00278         plotEnum          = PLOT_NOTHING;
00279 
00280         // discretize function for plotting
00281     Grid grid( _xRangeLowerLimit,_xRangeUpperLimit,100 );
00282     _curve.discretize( grid,*plotVariablesGrid );
00283 
00284     setTitle( _title );
00285     setXLabel( _xLabel );
00286     setYLabel( _yLabel );
00287 
00288     setPlotMode( _plotMode );
00289         setPlotFormat( PF_PLAIN );
00290 
00291     setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
00292 
00293     plot3D = BT_FALSE;
00294 
00295     nLines     = 0;
00296     lineValues = 0;
00297 
00298     nData = 0;
00299     data  = 0;
00300 
00301     next = 0;
00302 }
00303 
00304 PlotWindowSubplot::PlotWindowSubplot( const PlotWindowSubplot& rhs )
00305 {
00306         if( rhs.plotVariableX != 0 )
00307                 plotVariableX = new Expression(*rhs.plotVariableX);
00308         else
00309                 plotVariableX = 0;
00310 
00311         if( rhs.plotVariableY != 0 )
00312                 plotVariableY = new Expression(*rhs.plotVariableY);
00313         else
00314                 plotVariableY = 0;
00315 
00316         if( rhs.plotVariablesGrid != 0 )
00317                 plotVariablesGrid = new VariablesGrid(*rhs.plotVariablesGrid);
00318         else
00319                 plotVariablesGrid = 0;
00320 
00321         if( rhs.plotExpressionX != 0 )
00322                 plotExpressionX = new Expression(*rhs.plotExpressionX);
00323         else
00324                 plotExpressionX = 0;
00325 
00326         if( rhs.plotExpressionY != 0 )
00327                 plotExpressionY = new Expression(*rhs.plotExpressionY);
00328         else
00329                 plotExpressionY = 0;
00330 
00331         plotEnum = rhs.plotEnum;
00332 
00333         setTitle( rhs.title );
00334         setXLabel( rhs.xLabel );
00335         setYLabel( rhs.yLabel );
00336 
00337         setPlotMode( rhs.plotMode );
00338         setPlotFormat( rhs.plotFormat );
00339 
00340         setRanges( rhs.xRangeLowerLimit,rhs.xRangeUpperLimit,rhs.yRangeLowerLimit,rhs.yRangeUpperLimit );
00341 
00342     plot3D = rhs.plot3D;
00343 
00344         nLines = rhs.nLines;
00345         if ( rhs.lineValues == 0 )
00346                 lineValues = 0;
00347         else
00348         {
00349                 lineValues = new double[nLines];
00350                 for( uint i=0; i<nLines; ++i )
00351                         lineValues[i] = rhs.lineValues[i];
00352         }
00353 
00354         nData = 0;
00355         data = 0;
00356         for( uint i=0; i<rhs.nData; ++i )
00357                 if ( rhs.data[i] != 0 )
00358                         addData( *(rhs.data[i]) );
00359 
00360         next = 0;
00361 }
00362 
00363 
00364 PlotWindowSubplot::~PlotWindowSubplot( )
00365 {
00366         if ( plotVariableX != 0 )
00367                 delete plotVariableX;
00368 
00369         if ( plotVariableY != 0 )
00370                 delete plotVariableY;
00371 
00372     if ( plotVariablesGrid != 0 )
00373         delete plotVariablesGrid;
00374 
00375         if ( plotExpressionX != 0 )
00376                 delete plotExpressionX;
00377 
00378         if ( plotExpressionY != 0 )
00379                 delete plotExpressionY;
00380 
00381         if ( lineValues != 0 )
00382                 free( lineValues );
00383 
00384         if ( data != 0 )
00385         {
00386                 for( uint i=0; i<nData; ++i )
00387                         delete data[i];
00388                 free( data );
00389         }
00390 }
00391 
00392 
00393 PlotWindowSubplot& PlotWindowSubplot::operator=( const PlotWindowSubplot& rhs )
00394 {
00395         if ( this != &rhs )
00396         {
00397                 if ( plotVariableX != 0 )
00398                         delete plotVariableX;
00399         
00400                 if ( plotVariableY != 0 )
00401                         delete plotVariableY;
00402 
00403                 if ( plotVariablesGrid != 0 )
00404                         delete plotVariablesGrid;
00405 
00406                 if ( plotExpressionX != 0 )
00407                         delete plotExpressionX;
00408 
00409                 if ( plotExpressionY != 0 )
00410                         delete plotExpressionY;
00411 
00412                 if ( lineValues != 0 )
00413                         free( lineValues );
00414 
00415                 if ( data != 0 )
00416                         delete[] data;
00417 
00418 
00419                 if( rhs.plotVariableX != 0 )
00420                         plotVariableX = new Expression(*rhs.plotVariableX);
00421                 else
00422                         plotVariableX = 0;
00423 
00424                 if( rhs.plotVariableY != 0 )
00425                         plotVariableY = new Expression(*rhs.plotVariableY);
00426                 else
00427                         plotVariableY = 0;
00428 
00429                 if( rhs.plotVariablesGrid != 0 )
00430                         plotVariablesGrid = new VariablesGrid(*rhs.plotVariablesGrid);
00431                 else
00432                         plotVariablesGrid = 0;
00433 
00434                 if( rhs.plotExpressionX != 0 )
00435                         plotExpressionX = new Expression(*rhs.plotExpressionX);
00436                 else
00437                         plotExpressionX = 0;
00438 
00439                 if( rhs.plotExpressionY != 0 )
00440                         plotExpressionY = new Expression(*rhs.plotExpressionY);
00441                 else
00442                         plotExpressionY = 0;
00443 
00444                 plotEnum = rhs.plotEnum;
00445 
00446                 setTitle( rhs.title );
00447                 setXLabel( rhs.xLabel );
00448                 setYLabel( rhs.yLabel );
00449 
00450                 setPlotMode( rhs.plotMode );
00451                 setPlotFormat( rhs.plotFormat );
00452 
00453                 setRanges( rhs.xRangeLowerLimit,rhs.xRangeUpperLimit,rhs.yRangeLowerLimit,rhs.yRangeUpperLimit );
00454 
00455                 plot3D = rhs.plot3D;
00456 
00457                 nLines = rhs.nLines;
00458                 if ( rhs.lineValues == 0 )
00459                         lineValues = 0;
00460                 else
00461                 {
00462                         lineValues = new double[nLines];
00463                         for( uint i=0; i<nLines; ++i )
00464                                 lineValues[i] = rhs.lineValues[i];
00465                 }
00466 
00467                 nData = 0;
00468                 data = 0;
00469                 for( uint i=0; i<rhs.nData; ++i )
00470                         if ( rhs.data[i] != 0 )
00471                                 addData( *(rhs.data[i]) );
00472 
00473                 next = 0;
00474         }
00475 
00476         return *this;
00477 }
00478 
00479 
00480 
00481 returnValue PlotWindowSubplot::addLine( double _lineValue
00482                                                                                 )
00483 {
00484     ++nLines;
00485     lineValues = (double*)realloc( lineValues,nLines*sizeof(double) );
00486     lineValues[nLines-1] = _lineValue;
00487 
00488         return SUCCESSFUL_RETURN;
00489 }
00490 
00491 
00492 returnValue PlotWindowSubplot::addData( const VariablesGrid& _newData
00493                                                                                 )
00494 {
00495     ++nData;
00496     data = (VariablesGrid**)realloc( data,nData*sizeof(VariablesGrid*) );
00497     data[nData-1] = new VariablesGrid( _newData );
00498 
00499         return SUCCESSFUL_RETURN;
00500 }
00501 
00502 
00503 
00504 //
00505 // PROTECTED MEMBER FUNCTIONS:
00506 //
00507 
00508 
00509 
00510 
00511 
00512 
00513 CLOSE_NAMESPACE_ACADO
00514 
00515 
00516 /*
00517  *      end of file
00518  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:49