You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. Created by Richel Bilderbeek on Fri Jun 10 2005.
  20. ==============================================================================
  21. */
  22. #ifndef __JUCETICE_GNUPLOTINTERFACE_HEADER__
  23. #define __JUCETICE_GNUPLOTINTERFACE_HEADER__
  24. #if JUCE_LINUX
  25. //==============================================================================
  26. /**
  27. Gnuplot interface class.
  28. This let you plot data directly from the application (obviously you have
  29. to install gnuplot package before using this class).
  30. This is fully functional in linux only.
  31. @code
  32. Gnuplot myPlot;
  33. myPlot.setMultiplot (true);
  34. Array<double> data1 (1000);
  35. for (int j = 0; j != 1000; ++j)
  36. {
  37. const double jD = static_cast<double>(j);
  38. data1.set (j, sin (jD / 100.0));
  39. }
  40. myPlot.plot (data1);
  41. @endcode
  42. */
  43. class Gnuplot
  44. {
  45. public:
  46. //==============================================================================
  47. /** Styles of the plot */
  48. enum GnuplotStyle
  49. {
  50. styleLines,
  51. stylePoints,
  52. styleLinespoints,
  53. styleImpulses,
  54. styleDots,
  55. styleSteps,
  56. styleErrorbars,
  57. styleBoxes,
  58. styleBoxerrorbars,
  59. };
  60. /** Output type for the plot */
  61. enum GnuplotTerminal
  62. {
  63. terminalX11,
  64. terminalWxt,
  65. terminalPng
  66. };
  67. //==============================================================================
  68. /** Costructor */
  69. Gnuplot();
  70. /** Destructor */
  71. ~Gnuplot();
  72. //==============================================================================
  73. void addWindow (const int nWindows = 1);
  74. void changeWindow (const int);
  75. //==============================================================================
  76. void setTerminal (const GnuplotTerminal&);
  77. void setOutput (const String& output);
  78. void setStyle (const GnuplotStyle&);
  79. void setMultiplot (const bool isMultiple);
  80. void setYlabel (const String&);
  81. void setXlabel (const String&);
  82. //==============================================================================
  83. void plot (const String& file, const String& title = "y");
  84. void plot (const Array<double>& x, const String& title = "y");
  85. void plot (const Array<double>& x, const Array<double>& y, const String& title = "data");
  86. void plot (const Array<double>& x, const Array<double>& y, const Array<double>& z, const String& title = "z");
  87. void emptyPlot();
  88. private:
  89. void* mGnuPipe;
  90. String mTerminal;
  91. String mStyle;
  92. Array<StringArray> mWindowData;
  93. int mCurrentWindowNumber;
  94. static int mTempFileNumber;
  95. void setLineStyles();
  96. const String readFileName() const;
  97. const String createTempFileName();
  98. void createTempFile (const String&, const Array<double>&);
  99. void createTempFile (const String&, const Array<double>&, const Array<double>&);
  100. void createTempFile (const String&, const Array<double>&, const Array<double>&, const Array<double>&);
  101. void plotTempFile2D (const String&, const String&);
  102. void plotTempFile3D (const String&, const String&);
  103. void execute (const String&) const;
  104. };
  105. #endif
  106. #endif