plotcover.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// @file plotcover.h
00004 ///
00005 /// Plotting a cover in a bitmap image file.
00006 /// This file contains the definition of a function that plots a cover
00007 /// in a bitmap image file.
00008 ///
00009 /// @author Pawel Pilarczyk
00010 ///
00011 /////////////////////////////////////////////////////////////////////////////
00012 
00013 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
00014 //
00015 // This file is part of my research software package.  This is free software;
00016 // you can redistribute it and/or modify it under the terms of the GNU
00017 // General Public License as published by the Free Software Foundation;
00018 // either version 2 of the License, or (at your option) any later version.
00019 //
00020 // This software is distributed in the hope that it will be useful,
00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 // GNU General Public License for more details.
00024 //
00025 // You should have received a copy of the GNU General Public License along
00026 // with this software; see the file "license.txt".  If not, write to the
00027 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00028 // MA 02111-1307, USA.
00029 
00030 // Started on March 14, 2009. Last revision: March 19, 2009.
00031 
00032 
00033 #ifndef _FINRESDYN_PLOTCOVER_H_
00034 #define _FINRESDYN_PLOTCOVER_H_
00035 
00036 
00037 // include selected header files from the CHomP library
00038 #include "chomp/system/textfile.h"
00039 #include "chomp/bitmaps/bitmaps.h"
00040 
00041 // include local header files
00042 #include "streams.h"
00043 
00044 
00045 // --------------------------------------------------
00046 // ------------------ plot a cover ------------------
00047 // --------------------------------------------------
00048 
00049 template <class CoverType>
00050 inline void plotCover (const CoverType &cover, const char *filename,
00051         int width)
00052 {
00053         using namespace chomp::homology;
00054 
00055         // make sure that the dimension of the phase space is two
00056         if (cover. dim () != 2)
00057                 throw "Trying to plot a cover of dimension other than 2.";
00058 
00059         // retrieve the type of numbers used in the cover
00060         typedef typename CoverType::NumberType NumType;
00061 
00062         // retrieve the left corner of the covered rectangle
00063         NumType leftCorner [2];
00064         cover. getLeftCorner (leftCorner);
00065 
00066         // retrieve the widths of the covered box in each direction
00067         NumType boxWidths [2];
00068         cover. getBoxWidths (boxWidths);
00069 
00070         // make sure that the requested width of the bitmap file is correct
00071         if (width < 1)
00072                 width = 1;
00073 
00074         // determine the height of the bitmap file
00075         int height = static_cast <int> (boxWidths [1] / boxWidths [0] *
00076                 width + 1);
00077         if (height < 1)
00078                 height = 1;
00079 
00080         // create an empty bitmap file
00081         bmpfile bmp (height);
00082         bmp. invertedpicture ();
00083         const int pallength = 3;
00084         int32 palette [pallength] = {0x000000, 0x7F7F7F, 0xFFFFFF};
00085         bmp. create (filename, width, height, 4, pallength, palette);
00086 
00087         // plot the elements of the cover
00088         NumType leftBounds [2];
00089         NumType rightBounds [2];
00090         int left [2];
00091         int right [2];
00092         int bmpSize [2];
00093         bmpSize [0] = width;
00094         bmpSize [1] = height;
00095         for (int n = 0; n < cover. size (); ++ n)
00096         {
00097                 cover. get (n, leftBounds, rightBounds);
00098                 for (int i = 0; i < 2; ++ i)
00099                 {
00100                         left [i] = static_cast<int> ((leftBounds [i] -
00101                                 leftCorner [i]) / boxWidths [i] *
00102                                 bmpSize [i]);
00103                         if (left [i] >= bmpSize [i])
00104                                 left [i] = bmpSize [i] - 1;
00105                         right [i] = static_cast<int> ((rightBounds [i] -
00106                                 leftCorner [i]) / boxWidths [i] *
00107                                 bmpSize [i]) + 1;
00108                         if (right [i] > bmpSize [i])
00109                                 right [i] = bmpSize [i] - 1;
00110                         if (right [i] <= left [i])
00111                                 right [i] = left [i] + 1;
00112                 }
00113 
00114                 for (int x = left [0]; x < right [0]; ++ x)
00115                 {
00116                         for (int y = left [1]; y < right [1]; ++ y)
00117                         {
00118                                 int color = 1;
00119                                 if ((x == left [0]) ||
00120                                         (x == right [0] - 1) ||
00121                                         (y == left [1]) ||
00122                                         (y == right [1] - 1))
00123                                 {
00124                                         color = 0;
00125                                 }
00126                                 bmp. putpixel (x, y, color, true);
00127                         }
00128                 }
00129         }
00130 
00131         return;
00132 } /* plotCover */
00133 
00134 #endif // _FINRESDYN_PLOTCOVER_H_
00135 

Generated on Mon Apr 12 15:09:57 2010 for The Finite Resolution Dynamics Software by  doxygen 1.5.3