32#ifndef _CMGRAPHS_PLOTMDEC_H_
33#define _CMGRAPHS_PLOTMDEC_H_
37#include "chomp/bitmaps/colorpal.h"
50template <
class MorseDecType>
52 const char *filename,
int xCoord,
int yCoord,
53 int size = 0,
bool colorBar =
true)
55 typedef typename MorseDecType::CubSetType CubSetType;
56 typedef typename MorseDecType::CubeType CubeType;
57 typedef typename MorseDecType::CubeType::CoordType CoordType;
61 int nSets = m. count ();
62 for (
int n = 0; n < nSets; ++ n)
66 dim = m [n] [0]. dim ();
71 if (nSets && ((xCoord >= dim) || (yCoord >= dim)))
72 throw "Coordinates out of range for plotting Morse decomp.";
75 CoordType *coord =
new CoordType [(dim < 2) ? 2 : dim];
76 coord [0] = coord [1] = 0;
83 int nColors = nSets ? nSets : 1;
88 for (
int n = 0; n < nSets; ++ n)
90 const CubSetType &theSet = m [n];
96 int setSize = theSet. size ();
97 for (
int i = 0; i < setSize; ++ i)
99 const CubeType &q = theSet [i];
102 throw "Inconsistent dim of cubes.";
104 if (width <= coord [xCoord])
105 width = coord [xCoord] + 1;
106 if (height <= coord [yCoord])
107 height = coord [yCoord] + 1;
108 if (xoffset > coord [xCoord])
109 xoffset = coord [xCoord];
110 if (yoffset > coord [yCoord])
111 yoffset = coord [yCoord];
116 if (yoffset > height)
127 int colorBoxSize = 16;
128 int colorBarHeight = colorBar ? (colorBoxSize + 1) : 0;
129 int colorBarWidth = colorBar ?
130 (nColors * colorBoxSize + nColors - 1) : 0;
131 height += colorBarHeight;
132 if (width < colorBarWidth)
133 width = colorBarWidth;
134 int bottomHeight = colorBarHeight;
140 chomp::homology::ColorPalette col (nColors);
141 if (colorBar && nColors && nSets)
143 for (
int n = 0; n < nColors; ++ n)
145 int xMin = n * (colorBoxSize + 1);
146 int xMax = xMin + colorBoxSize;
147 int yMin = height - colorBarHeight + 1;
148 int yMax = yMin + colorBarHeight;
150 for (
int x = xMin; x < xMax; ++ x)
152 for (
int y = yMin; y < yMax; ++ y)
154 img. putPixel (x, y, color);
162 for (
int n = 0; n < nSets; ++ n)
164 const CubSetType &theSet = m [n];
165 if (theSet. empty ())
167 int color = col [colorNumber ++];
168 int setSize = theSet. size ();
169 for (
int i = 0; i < setSize; ++ i)
171 const CubeType &q = theSet [i];
174 throw "Inconsistent dim of cubes to plot.";
176 img. putPixel (coord [xCoord] - xoffset, height -
177 coord [yCoord] + yoffset - 1 - bottomHeight,
184 img. save (filename);
An interface to the PNG library.
void plotMorseDecompositionPNG(const MorseDecType &m, const char *filename, int xCoord, int yCoord, int size=0, bool colorBar=true)
Saves all the Morse sets in the provided Morse decomposition to a PNG file.