plot_window_subplot.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 #include <acado/curve/curve.hpp>
36 
37 
39 
40 
41 
42 //
43 // PUBLIC MEMBER FUNCTIONS:
44 //
45 
47 {
48 
49  plotVariableX = 0;
50  plotVariableY = 0;
52  plotExpressionX = 0;
53  plotExpressionY = 0;
55 
58 
63 
64  plot3D = BT_FALSE;
65 
66  nLines = 0;
67  lineValues = 0;
68 
69  nData = 0;
70  data = 0;
71 
72  next = 0;
73 }
74 
75 
77  const char* const _title,
78  const char* const _xLabel,
79  const char* const _yLabel,
80  PlotMode _plotMode,
81  double _xRangeLowerLimit,
82  double _xRangeUpperLimit,
83  double _yRangeLowerLimit,
84  double _yRangeUpperLimit
85  )
86 {
87 
88  if( _expression.isVariable() == BT_TRUE ){
89 
90  plotVariableX = 0;
91  plotVariableY = new Expression(_expression);
93  plotExpressionX = 0;
94  plotExpressionY = 0;
95  }
96  else{
97 
98  plotVariableX = 0;
99  plotVariableY = 0;
100  plotVariablesGrid = 0;
101  plotExpressionX = 0;
102  plotExpressionY = new Expression(_expression);
103  }
104 
106 
107  setTitle( _title );
108  setXLabel( _xLabel );
109  setYLabel( _yLabel );
110 
111  setPlotMode( _plotMode );
113 
114  setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
115 
116  plot3D = BT_FALSE;
117 
118  nLines = 0;
119  lineValues = 0;
120 
121  nData = 0;
122  data = 0;
123 
124  next = 0;
125 }
126 
127 
129  const Expression& _expressionY,
130  const char* const _title,
131  const char* const _xLabel,
132  const char* const _yLabel,
133  PlotMode _plotMode,
134  double _xRangeLowerLimit,
135  double _xRangeUpperLimit,
136  double _yRangeLowerLimit,
137  double _yRangeUpperLimit
138  )
139 {
140 
141  if( _expressionX.isVariable() == BT_TRUE && _expressionY.isVariable() == BT_TRUE ){
142 
143  plotVariableX = new Expression(_expressionX);
144  plotVariableY = new Expression(_expressionY);
145  plotVariablesGrid = 0;
146  plotExpressionX = 0;
147  plotExpressionY = 0;
148  }
149  else{
150 
151  plotVariableX = 0;
152  plotVariableY = 0;
153  plotVariablesGrid = 0;
154  plotExpressionX = new Expression(_expressionX);
155  plotExpressionY = new Expression(_expressionY);
156  }
157 
159 
160  setTitle( _title );
161  setXLabel( _xLabel );
162  setYLabel( _yLabel );
163 
164  setPlotMode( _plotMode );
166 
167  setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
168 
169  plot3D = BT_FALSE;
170 
171  nLines = 0;
172  lineValues = 0;
173 
174  nData = 0;
175  data = 0;
176 
177  next = 0;
178 }
179 
180 
181 
183  const char* const _title,
184  const char* const _xLabel,
185  const char* const _yLabel,
186  PlotMode _plotMode,
187  double _xRangeLowerLimit,
188  double _xRangeUpperLimit,
189  double _yRangeLowerLimit,
190  double _yRangeUpperLimit
191  )
192 {
193  plotVariableX = 0;
194  plotVariableY = 0;
195  plotVariablesGrid = 0;
196  plotExpressionX = 0;
197  plotExpressionY = 0;
198  plotEnum = _name;
199 
200  setTitle( _title );
201  setXLabel( _xLabel );
202  setYLabel( _yLabel );
203 
204  setPlotMode( _plotMode );
206 
207  setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
208 
209  plot3D = BT_FALSE;
210 
211  nLines = 0;
212  lineValues = 0;
213 
214  nData = 0;
215  data = 0;
216 
217  next = 0;
218 }
219 
220 
222  const char* const _title,
223  const char* const _xLabel,
224  const char* const _yLabel,
225  PlotMode _plotMode,
226  double _xRangeLowerLimit,
227  double _xRangeUpperLimit,
228  double _yRangeLowerLimit,
229  double _yRangeUpperLimit,
230  BooleanType _plot3D )
231 {
232  plotVariableX = 0;
233  plotVariableY = 0;
234  plotVariablesGrid = new VariablesGrid(_plotVariable);
235  plotExpressionX = 0;
236  plotExpressionY = 0;
238 
239  setTitle( _title );
240  setXLabel( _xLabel );
241  setYLabel( _yLabel );
242 
243  setPlotMode( _plotMode );
245 
246  setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
247 
248  plot3D = _plot3D;
249 
250  nLines = 0;
251  lineValues = 0;
252 
253  nData = 0;
254  data = 0;
255 
256  next = 0;
257 }
258 
259 
261  double _xRangeLowerLimit,
262  double _xRangeUpperLimit,
263  const char* const _title,
264  const char* const _xLabel,
265  const char* const _yLabel,
266  PlotMode _plotMode,
267  double _yRangeLowerLimit,
268  double _yRangeUpperLimit
269  )
270 {
271 
272 
273  plotVariableX = 0;
274  plotVariableY = 0;
276  plotExpressionX = 0;
277  plotExpressionY = 0;
279 
280  // discretize function for plotting
281  Grid grid( _xRangeLowerLimit,_xRangeUpperLimit,100 );
282  _curve.discretize( grid,*plotVariablesGrid );
283 
284  setTitle( _title );
285  setXLabel( _xLabel );
286  setYLabel( _yLabel );
287 
288  setPlotMode( _plotMode );
290 
291  setRanges( _xRangeLowerLimit,_xRangeUpperLimit,_yRangeLowerLimit,_yRangeUpperLimit );
292 
293  plot3D = BT_FALSE;
294 
295  nLines = 0;
296  lineValues = 0;
297 
298  nData = 0;
299  data = 0;
300 
301  next = 0;
302 }
303 
305 {
306  if( rhs.plotVariableX != 0 )
308  else
309  plotVariableX = 0;
310 
311  if( rhs.plotVariableY != 0 )
313  else
314  plotVariableY = 0;
315 
316  if( rhs.plotVariablesGrid != 0 )
318  else
319  plotVariablesGrid = 0;
320 
321  if( rhs.plotExpressionX != 0 )
323  else
324  plotExpressionX = 0;
325 
326  if( rhs.plotExpressionY != 0 )
328  else
329  plotExpressionY = 0;
330 
331  plotEnum = rhs.plotEnum;
332 
333  setTitle( rhs.title );
334  setXLabel( rhs.xLabel );
335  setYLabel( rhs.yLabel );
336 
337  setPlotMode( rhs.plotMode );
338  setPlotFormat( rhs.plotFormat );
339 
341 
342  plot3D = rhs.plot3D;
343 
344  nLines = rhs.nLines;
345  if ( rhs.lineValues == 0 )
346  lineValues = 0;
347  else
348  {
349  lineValues = new double[nLines];
350  for( uint i=0; i<nLines; ++i )
351  lineValues[i] = rhs.lineValues[i];
352  }
353 
354  nData = 0;
355  data = 0;
356  for( uint i=0; i<rhs.nData; ++i )
357  if ( rhs.data[i] != 0 )
358  addData( *(rhs.data[i]) );
359 
360  next = 0;
361 }
362 
363 
365 {
366  if ( plotVariableX != 0 )
367  delete plotVariableX;
368 
369  if ( plotVariableY != 0 )
370  delete plotVariableY;
371 
372  if ( plotVariablesGrid != 0 )
373  delete plotVariablesGrid;
374 
375  if ( plotExpressionX != 0 )
376  delete plotExpressionX;
377 
378  if ( plotExpressionY != 0 )
379  delete plotExpressionY;
380 
381  if ( lineValues != 0 )
382  free( lineValues );
383 
384  if ( data != 0 )
385  {
386  for( uint i=0; i<nData; ++i )
387  delete data[i];
388  free( data );
389  }
390 }
391 
392 
394 {
395  if ( this != &rhs )
396  {
397  if ( plotVariableX != 0 )
398  delete plotVariableX;
399 
400  if ( plotVariableY != 0 )
401  delete plotVariableY;
402 
403  if ( plotVariablesGrid != 0 )
404  delete plotVariablesGrid;
405 
406  if ( plotExpressionX != 0 )
407  delete plotExpressionX;
408 
409  if ( plotExpressionY != 0 )
410  delete plotExpressionY;
411 
412  if ( lineValues != 0 )
413  free( lineValues );
414 
415  if ( data != 0 )
416  delete[] data;
417 
418 
419  if( rhs.plotVariableX != 0 )
421  else
422  plotVariableX = 0;
423 
424  if( rhs.plotVariableY != 0 )
426  else
427  plotVariableY = 0;
428 
429  if( rhs.plotVariablesGrid != 0 )
431  else
432  plotVariablesGrid = 0;
433 
434  if( rhs.plotExpressionX != 0 )
436  else
437  plotExpressionX = 0;
438 
439  if( rhs.plotExpressionY != 0 )
441  else
442  plotExpressionY = 0;
443 
444  plotEnum = rhs.plotEnum;
445 
446  setTitle( rhs.title );
447  setXLabel( rhs.xLabel );
448  setYLabel( rhs.yLabel );
449 
450  setPlotMode( rhs.plotMode );
451  setPlotFormat( rhs.plotFormat );
452 
454 
455  plot3D = rhs.plot3D;
456 
457  nLines = rhs.nLines;
458  if ( rhs.lineValues == 0 )
459  lineValues = 0;
460  else
461  {
462  lineValues = new double[nLines];
463  for( uint i=0; i<nLines; ++i )
464  lineValues[i] = rhs.lineValues[i];
465  }
466 
467  nData = 0;
468  data = 0;
469  for( uint i=0; i<rhs.nData; ++i )
470  if ( rhs.data[i] != 0 )
471  addData( *(rhs.data[i]) );
472 
473  next = 0;
474  }
475 
476  return *this;
477 }
478 
479 
480 
482  )
483 {
484  ++nLines;
485  lineValues = (double*)realloc( lineValues,nLines*sizeof(double) );
486  lineValues[nLines-1] = _lineValue;
487 
488  return SUCCESSFUL_RETURN;
489 }
490 
491 
493  )
494 {
495  ++nData;
496  data = (VariablesGrid**)realloc( data,nData*sizeof(VariablesGrid*) );
497  data[nData-1] = new VariablesGrid( _newData );
498 
499  return SUCCESSFUL_RETURN;
500 }
501 
502 
503 
504 //
505 // PROTECTED MEMBER FUNCTIONS:
506 //
507 
508 
509 
510 
511 
512 
514 
515 
516 /*
517  * end of file
518  */
returnValue setXLabel(const std::string &_xLabel)
returnValue addData(const VariablesGrid &_newData)
BooleanType isVariable() const
returnValue setYLabel(const std::string &_yLabel)
const double INFTY
PlotWindowSubplot & operator=(const PlotWindowSubplot &rhs)
PlotMode
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
VariablesGrid * plotVariablesGrid
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue setTitle(const std::string &_title)
#define CLOSE_NAMESPACE_ACADO
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
returnValue addLine(double _lineValue)
PlotName
returnValue setRanges(double _xRangeLowerLimit, double _xRangeUpperLimit, double _yRangeLowerLimit, double _yRangeUpperLimit)
PlotWindowSubplot * next
returnValue setPlotMode(PlotMode _plotMode)
Allows to work with piecewise-continous function defined over a scalar time interval.
Definition: curve.hpp:52
void rhs(const real_t *x, real_t *f)
#define BT_TRUE
Definition: acado_types.hpp:47
Allows to manage sub-windows of user-specified plot windows for algorithmic outputs (for internal use...
#define BEGIN_NAMESPACE_ACADO
#define BT_FALSE
Definition: acado_types.hpp:49
returnValue discretize(const Grid &discretizationGrid, VariablesGrid &result) const
Definition: curve.cpp:392
returnValue setPlotFormat(PlotFormat _plotFormat)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:59