The Finite Resolution Dynamics Software
plotcover.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// @file plotcover.h
4 ///
5 /// Plotting a cover in a bitmap image file.
6 /// This file contains the definition of a function that plots a cover
7 /// in a bitmap image file.
8 ///
9 /// @author Pawel Pilarczyk
10 ///
11 /////////////////////////////////////////////////////////////////////////////
12 
13 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
14 //
15 // This file is part of my research software package. This is free software;
16 // you can redistribute it and/or modify it under the terms of the GNU
17 // General Public License as published by the Free Software Foundation;
18 // either version 2 of the License, or (at your option) any later version.
19 //
20 // This software is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with this software; see the file "license.txt". If not, write to the
27 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 // MA 02111-1307, USA.
29 
30 // Started on March 14, 2009. Last revision: March 19, 2009.
31 
32 
33 #ifndef _FINRESDYN_PLOTCOVER_H_
34 #define _FINRESDYN_PLOTCOVER_H_
35 
36 
37 // include selected header files from the CHomP library
38 #include "chomp/system/textfile.h"
39 #include "chomp/bitmaps/bitmaps.h"
40 
41 // include local header files
42 #include "streams.h"
43 
44 
45 // --------------------------------------------------
46 // ------------------ plot a cover ------------------
47 // --------------------------------------------------
48 
49 template <class CoverType>
50 inline void plotCover (const CoverType &cover, const char *filename,
51  int width)
52 {
53  using namespace chomp::homology;
54 
55  // make sure that the dimension of the phase space is two
56  if (cover. dim () != 2)
57  throw "Trying to plot a cover of dimension other than 2.";
58 
59  // retrieve the type of numbers used in the cover
60  typedef typename CoverType::NumberType NumType;
61 
62  // retrieve the left corner of the covered rectangle
63  NumType leftCorner [2];
64  cover. getLeftCorner (leftCorner);
65 
66  // retrieve the widths of the covered box in each direction
67  NumType boxWidths [2];
68  cover. getBoxWidths (boxWidths);
69 
70  // make sure that the requested width of the bitmap file is correct
71  if (width < 1)
72  width = 1;
73 
74  // determine the height of the bitmap file
75  int height = static_cast <int> (boxWidths [1] / boxWidths [0] *
76  width + 1);
77  if (height < 1)
78  height = 1;
79 
80  // create an empty bitmap file
81  bmpfile bmp (height);
82  bmp. invertedpicture ();
83  const int pallength = 3;
84  int32 palette [pallength] = {0x000000, 0x7F7F7F, 0xFFFFFF};
85  bmp. create (filename, width, height, 4, pallength, palette);
86 
87  // plot the elements of the cover
88  NumType leftBounds [2];
89  NumType rightBounds [2];
90  int left [2];
91  int right [2];
92  int bmpSize [2];
93  bmpSize [0] = width;
94  bmpSize [1] = height;
95  for (int n = 0; n < cover. size (); ++ n)
96  {
97  cover. get (n, leftBounds, rightBounds);
98  for (int i = 0; i < 2; ++ i)
99  {
100  left [i] = static_cast<int> ((leftBounds [i] -
101  leftCorner [i]) / boxWidths [i] *
102  bmpSize [i]);
103  if (left [i] >= bmpSize [i])
104  left [i] = bmpSize [i] - 1;
105  right [i] = static_cast<int> ((rightBounds [i] -
106  leftCorner [i]) / boxWidths [i] *
107  bmpSize [i]) + 1;
108  if (right [i] > bmpSize [i])
109  right [i] = bmpSize [i] - 1;
110  if (right [i] <= left [i])
111  right [i] = left [i] + 1;
112  }
113 
114  for (int x = left [0]; x < right [0]; ++ x)
115  {
116  for (int y = left [1]; y < right [1]; ++ y)
117  {
118  int color = 1;
119  if ((x == left [0]) ||
120  (x == right [0] - 1) ||
121  (y == left [1]) ||
122  (y == right [1] - 1))
123  {
124  color = 0;
125  }
126  bmp. putpixel (x, y, color, true);
127  }
128  }
129  }
130 
131  return;
132 } /* plotCover */
133 
134 #endif // _FINRESDYN_PLOTCOVER_H_
135 
Various output streams for the program.
void plotCover(const CoverType &cover, const char *filename, int width)
Definition: plotcover.h:50