cplot.h

Go to the documentation of this file.
00001 /**
00002 \file    cplot.h
00003 \brief   C functions for 2D plotting directly to a compressed bitmap.
00004 
00005 \author  Glenn D. MacGougan (GDM)
00006 \date    2008-04-18
00007 \since   2007-12-19
00008 
00009 \b "LICENSE INFORMATION" \n
00010 Copyright (c) 2007, refer to 'author' doxygen tags \n
00011 All rights reserved. \n
00012 
00013 Redistribution and use in source and binary forms, with or without
00014 modification, are permitted provided the following conditions are met: \n
00015 
00016 - Redistributions of source code must retain the above copyright
00017   notice, this list of conditions and the following disclaimer. \n
00018 - Redistributions in binary form must reproduce the above copyright
00019   notice, this list of conditions and the following disclaimer in the
00020   documentation and/or other materials provided with the distribution. \n
00021 - The name(s) of the contributor(s) may not be used to endorse or promote 
00022   products derived from this software without specific prior written 
00023   permission. \n
00024 
00025 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00026 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00029 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00031 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00032 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00033 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00034 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00035 SUCH DAMAGE.
00036 */
00037 
00038 #ifndef _CPLOT_H_
00039 #define _CPLOT_H_
00040 
00041 #ifdef __cplusplus
00042 extern "C" 
00043 {
00044 #endif
00045 
00046 typedef int BOOL;
00047 
00048 #ifndef FALSE
00049 #define FALSE (0)
00050 #endif
00051 #ifndef TRUE
00052 #define TRUE (1)
00053 #endif
00054 
00055 /// \brief  These are the supported colors.
00056 typedef enum 
00057 {
00058   CPLOT_WHITE       = 0,
00059   CPLOT_BLACK       = 1,
00060   CPLOT_BLUE        = 2,
00061   CPLOT_GREEN       = 3,
00062   CPLOT_PURPLE      = 4,
00063   CPLOT_MAGENTA     = 5,
00064   CPLOT_DARKBLUE    = 6,
00065   CPLOT_INDIANRED   = 7,
00066   CPLOT_BABYBLUE    = 8,
00067   CPLOT_PAISLYBLUE  = 9,
00068   CPLOT_LIGHTPURPLE = 10,      
00069   CPLOT_DARKPURPLE  = 11,
00070   CPLOT_GREYPURPLE  = 12,
00071   CPLOT_BROWN       = 13,
00072   CPLOT_RED         = 14,
00073   CPLOT_PINK        = 15,
00074   CPLOT_YELLOW      = 16,
00075   CPLOT_ORANGE      = 17,
00076   CPLOT_CYAN        = 18,
00077   CPLOT_LIMEGREEN   = 19,
00078   CPLOT_GREY        = 20,
00079   CPLOT_LIGHTGREY   = 21
00080 } CPLOT_enumColor;
00081 
00082 
00083 /// \brief  A container struct used in CPLOT_structAxisOptions.
00084 typedef struct
00085 {
00086   BOOL doNotUseDefault;
00087   double val;
00088 } CPLOT_structAxisSubOption;
00089 
00090 /// \brief  A container struct for axis options.
00091 typedef struct 
00092 {
00093   char* label;
00094   CPLOT_structAxisSubOption lowerlimit;
00095   CPLOT_structAxisSubOption upperlimit;
00096   CPLOT_structAxisSubOption tickstart;
00097   CPLOT_structAxisSubOption ticksize;
00098   CPLOT_structAxisSubOption tickend;
00099   BOOL isGridOn;  
00100 
00101 }CPLOT_structAxisOptions;
00102 
00103 
00104 /// \brief  The user specified plot options.
00105 typedef struct 
00106 {
00107   int numberOfSeries;     //!< The total number of series to be plotted.  
00108   int PlotSize_Width_cm;  //!< The size of the plot portion of the figure [cm].
00109   int PlotSize_Height_cm; //!< The size of the plot portion of the figure [cm].
00110   char* title;            //!< The title string if any. NULL if none.
00111   
00112   /** \brief  The ylabel on the right hand side of the plot. NULL if none. Usually NULL.
00113 
00114     Data can be plotted with respect to y ticks on the right 
00115     hand side of the plot window. 
00116     For example, plot elevation angle (0-90, left side y ticks) 
00117     and plot azimuth angle (-180-180, right side y ticks). 
00118 
00119     \code
00120     rhs_ytick = lhs_ytick * scale_factor + offset
00121     e.g.
00122     Y_Label,              = "Elevation (deg)"
00123     Y_RightYLabel,        = "Azimuth (deg)"
00124     Y_RightYOffset,       = -180
00125     Y_RightYScaleFactor,  = 4
00126     \endcode
00127   */
00128   char*  y_label_right;            
00129   double y_label_right_scale_factor;  //!< Scale the lhs y ticks by this value for the rhs ticks.
00130   double y_label_right_bias;          //!< Offset the rhs y ticks by this value after scaling.
00131   CPLOT_enumColor RightYLabelColor;   //!< The color of the right y label.
00132 
00133   CPLOT_structAxisOptions x; //!< General axis options for X.
00134   CPLOT_structAxisOptions y; //!< General axis options for Y.
00135 
00136   /** 
00137   \brief  A boolean indicating if the special GPS x axis label is to be used.
00138           Enabling X_UseGPSLabel assumes that the X part of the 
00139           series is a GPS time of week, (0-604800 s), and will
00140           compute the corresponding UTC time and include it 
00141           below each xtick.
00142   */   
00143   BOOL useGPSLabel; 
00144   int UTCOffset;  //!< The GPS/UTC offset (always +ve).   
00145 
00146   BOOL plotStatistics; //!< A boolean indicating if statistics are to be included in the figure.
00147   
00148   BOOL plotLabelOnRight; //!< Place labels and statistics on the right of the plot. Otherwise below the plot.
00149 
00150   CPLOT_enumColor figureBackgroundColor; //!< The figure background color.
00151 
00152   double endOfWarmupEpoch;
00153 
00154   BOOL redrawAxes;
00155   
00156 }CPLOT_structPlotOptions;
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 /// \brief  These are the dimensions of the plot part of the image in pixels.
00165 typedef struct 
00166 {
00167   int Width;  // pixels
00168   int Height; // pixels
00169 } CPLOT_structImageSizeInPixels;
00170 
00171 /// \brief  These are the coordinates in the image of parts of the axes.
00172 typedef struct CPLOT_structAxes
00173 {
00174   int StartX;           // pixels
00175   int StartY;           // pixels
00176   int FinishX;          // pixels 
00177   int FinishY;          // pixels
00178   int Width;            // pixels
00179   int Height;           // pixels
00180   int TickDashInPixels; // length of tick dash used
00181 } CPLOT_structAxes;
00182 
00183 /// \brief  A container for statistics information.
00184 typedef struct
00185 {
00186   double min;
00187   double max;
00188   double mean;
00189   double stdev;
00190   double rms;
00191   double range;
00192 } CPLOT_structStats;
00193 
00194 /// \brief  The container for series data and user options.
00195 typedef struct 
00196 {
00197   double *X; //!< A pointer to the x series array.
00198   double *Y; //!< A pointer to the y series array.
00199   int n;     //!< The number of items in X and Y arrays.
00200 
00201   CPLOT_structStats xStats; //!< Internally computed statistics.
00202   CPLOT_structStats yStats; //!< Internally computed statistics.
00203 
00204   BOOL connected;         //!< Are the data points connected.
00205   CPLOT_enumColor color;  //!< The color of the data points/line.
00206   char* label;            //!< The series label, NULL if none.
00207   char* units;            //!< The series units, NULL if none.
00208   int precision;          //!< The number of significant digits in the statistics.
00209   BOOL markOutlierData;   //!< Should the outlier data be marked.
00210   
00211 }CPLOT_structSeries;
00212 
00213 
00214 /// \brief  An RGB container.
00215 typedef struct
00216 {
00217   unsigned char Blue;
00218   unsigned char Green;
00219   unsigned char Red;
00220   unsigned char Reserved;
00221 } CPLOT_structRGB;
00222 
00223 
00224 /// \brief  Internal information container.
00225 typedef struct
00226 {
00227   double xtickstart;        // data units
00228   double xtickend;          // data units
00229   double xticksize;         // data units
00230   double ytickstart;        // data units
00231   double ytickend;          // data units
00232   double yticksize;         // data units
00233   double RangeX;            // MaxX - MinX // data units
00234   double RangeY;            // MaxY - MinY // data units
00235   double OnePercentRangeX;
00236   double OnePercentRangeY;
00237   double ScaleX;            // Scale X to pixels, mAxes.Width / RangeX
00238   double ScaleY;            // Scale Y to pixels, mAxes.Height / RangeY
00239   double MinX;              // data units
00240   double MaxX;              // data units
00241   double MinY;              // data units
00242   double MaxY;              // data units
00243 } CPLOT_structInfoInDataUnits;
00244 
00245 /// \brief  The 22 color default color table!
00246 typedef struct 
00247 {
00248   CPLOT_structRGB White; 
00249   CPLOT_structRGB Black;
00250   CPLOT_structRGB Blue;     
00251   CPLOT_structRGB Green;
00252   CPLOT_structRGB Purple;
00253   CPLOT_structRGB Magenta;
00254   CPLOT_structRGB DarkBlue;
00255   CPLOT_structRGB IndianRed;
00256   CPLOT_structRGB BabyBlue;
00257   CPLOT_structRGB PaislyBlue;
00258   CPLOT_structRGB LightPurple;      
00259   CPLOT_structRGB DarkPurple;
00260   CPLOT_structRGB GreyPurple;
00261   CPLOT_structRGB Brown;
00262   CPLOT_structRGB Red;
00263   CPLOT_structRGB Pink;            
00264   CPLOT_structRGB Yellow;
00265   CPLOT_structRGB Orange;
00266   CPLOT_structRGB Cyan;
00267   CPLOT_structRGB LimeGreen;
00268   CPLOT_structRGB Grey;
00269   CPLOT_structRGB LightGrey;            
00270 
00271 }CPLOT_structColorTable;   
00272 
00273 
00274 /// \brief  A data container for holding the bitmap bytes.
00275 typedef struct
00276 {  
00277   unsigned      nrows;   //!< The number of rows in the matrix.
00278   unsigned      ncols;   //!< The number of columns in the matrix.
00279   unsigned char **data;  //!< This is a pointer to an array of bytes row vectors.
00280 
00281 } CPLOT_structByteMatrix;
00282 
00283 
00284 /// \brief  The CPLOT C sytle object.
00285 typedef struct
00286 {
00287   BOOL mIsAxesDrawn;          //!< A boolean indicating if the axes are drawn.
00288   int mSeriesIndex;           //!< An index for the series.
00289   int mFootNoteIndex;         //!< An index for footnotes.
00290     
00291   int mLabelWidth;            //!< The width for a label [pixels].
00292   int mStatsValueHeight;      //!< The height allocation for the statisitics values.
00293   int mYLabelAllowance;       //!< The allowance for the ylabel [pixels].
00294   int mRightYLabelAllowance;  //!< The allowance for the right ylabel [pixels].
00295   int mTitleAllowance;        //!< The allowance for the title [pixels].
00296   int mXLabelAllowance;       //!< The allowance for the xlabel [pixels].
00297   
00298   CPLOT_structImageSizeInPixels mImage; //!< The image size [pixels].
00299 
00300   CPLOT_structAxes mAxes;
00301 
00302   CPLOT_structInfoInDataUnits mData;
00303 
00304   CPLOT_structPlotOptions  mOptions;    //!< The plotting options
00305   
00306 
00307   CPLOT_structColorTable mDefaultColorTable;
00308   BOOL mUseDefaultColorTable;
00309   unsigned char* mColorTable;
00310   
00311   CPLOT_structByteMatrix  mPlotData;
00312 
00313 } CPLOT;
00314 
00315 
00316 /// \brief  Initialize the general plotting options.
00317 /// \return TRUE(1) if successful, FALSE(0) otherwise.
00318 BOOL CPLOT_PlotOptionsInit( CPLOT_structPlotOptions *Opt );
00319 
00320 
00321 /// \brief  Initialize the main CPLOT data container.
00322 /// \return TRUE(1) if successful, FALSE(0) otherwise.
00323 BOOL CPLOT_Init( CPLOT* P );
00324 
00325 /// \brief  Set all the general plotting options.
00326 /// \return TRUE(1) if successful, FALSE(0) otherwise.
00327 BOOL CPLOT_SetPlotOptions( 
00328   CPLOT *P, 
00329   CPLOT_structPlotOptions *opt
00330   );
00331 
00332 /// \brief  Plot a data series. Call this function repeatedly 
00333 ///         for each data series.
00334 /// \return TRUE(1) if successful, FALSE(0) otherwise.
00335 BOOL CPLOT_Plot( 
00336   CPLOT *P, 
00337   CPLOT_structSeries *Series 
00338   );
00339 
00340 /// \brief  Once plotting is complete, save the bitmap to the
00341 ///         file specified.
00342 /// \return TRUE(1) if successful, FALSE(0) otherwise.
00343 BOOL CPLOT_SaveToFile( 
00344   CPLOT *P,
00345   const char *FileName 
00346   );
00347 
00348 
00349 BOOL CPLOT_IsNAN( double value );
00350 BOOL CPLOT_IsPostiveINF( double value );
00351 BOOL CPLOT_IsNegativeINF( double value );
00352 
00353 #ifdef __cplusplus
00354 }
00355 #endif
00356 
00357 
00358 #endif // _CPLOT_H_
00359 
00360 
00361 
00362 
00363 

Generated on Sun Feb 8 15:31:09 2009 for The Zenautics Matrix Project by  doxygen 1.5.4