00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _FINRESDYN_PLOTCOVER_H_
00034 #define _FINRESDYN_PLOTCOVER_H_
00035
00036
00037
00038 #include "chomp/system/textfile.h"
00039 #include "chomp/bitmaps/bitmaps.h"
00040
00041
00042 #include "streams.h"
00043
00044
00045
00046
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
00056 if (cover. dim () != 2)
00057 throw "Trying to plot a cover of dimension other than 2.";
00058
00059
00060 typedef typename CoverType::NumberType NumType;
00061
00062
00063 NumType leftCorner [2];
00064 cover. getLeftCorner (leftCorner);
00065
00066
00067 NumType boxWidths [2];
00068 cover. getBoxWidths (boxWidths);
00069
00070
00071 if (width < 1)
00072 width = 1;
00073
00074
00075 int height = static_cast <int> (boxWidths [1] / boxWidths [0] *
00076 width + 1);
00077 if (height < 1)
00078 height = 1;
00079
00080
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
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 }
00133
00134 #endif // _FINRESDYN_PLOTCOVER_H_
00135