Greens-code
A modular quantum transport code
write_jpg.hpp
1 #ifndef INCLUDE_WRITE_JPG
2 #define INCLUDE_WRITE_JPG
3 
4 #include "image_parser.hpp"
5 #include <vector>
6 
7 #include "my_mkl.hpp"
8 #include "input_file.hpp"
9 
10 #include <memory>
11 
12 class Bild;
13 
24 {
25 public:
26  ~jpg_image_processor() throw() {};
27 private:
28 
29  STD_TR1::shared_ptr<palette> my_palette;
30 
31  bool do_jpg;
32  std::string filename_extension;
33 
34  const char* name() const { return "jpg_image";};
35  void init();
36 
37  void process_image_( MPI_Comm comm,
38  const Bild& b,
39  const std::string& filen );
40 };
41 
42 //for efficiency reasons, use template instead of function pointer calls
43 
60 class palette: public loadable_Object{
61 public:
62  typedef STD_TR1::shared_ptr<palette> ref;
63 
64  void write_ppm_info(const Bild& bild,
65  FILE* file)
66  { use_palette_( bild, file);};
67 
68 protected:
69  template <class effective_palette>
70  void write_ppm(const Bild& bild,
71  FILE* file,
72  const effective_palette& t) const;
73 
74 private:
75  virtual void use_palette_(const Bild&,
76  FILE* file) = 0;
77 };
78 
87 class default_palette: public palette{
88 public:
89  void precalc(const complex& c) const {
90  tmp = abs(c)*abs(c);
91  white = (tmp <= white_thrshld);
92 
93  if (tmp > 10000){
94  if (c.real() < 0)
95  {
96  tmp=0;
97  }else{
98  white = true;
99  }
100  }else{
101  tmp -= delta_eff;
102  }
103 
104  if (tmp < 0.) tmp = 0.;
105 
106  tmp = atan(tmp * scale) * M_2_PI;
107  };
108 
109  char red(const complex& c) const { if (white) return 255; return tmp * 255.;};
110  char green(const complex& c) const { if (white) return 255; return tmp*tmp*(1.-tmp)*27./4.*255.;};
111  char blue(const complex& c) const { if (white) return 255; return tmp * (1. - tmp) * (1. - tmp) * 27./4. * 255.;};
112 
113 private:
114 
115  void use_palette_(const Bild&, FILE*);
116 
117  virtual const char* name() const { return "default_palette";};
118  double white_thrshld;
119 
120  void init();
121 
122  double scale;
123  double delta;
124  double delta_eff;
125  mutable double tmp;
126  mutable bool white;
127 };
128 
136 class log_palette: public palette{
137 public:
138  void precalc(const complex& c) const {
139  tmp = abs(c)*abs(c);
140  white = (tmp == 0.);
141  if (!white){
142  tmp = (log(tmp) + y0) * scale;
143  if (tmp < 0) tmp = 0;
144  if (tmp > 1) tmp = 1;
145  }
146  };
147 
148  char red(const complex& c) const { if (white) return 255; return tmp * 255.;};
149  char green(const complex& c) const { if (white) return 255; return tmp*tmp*(1.-tmp)*27./4.*255.;};
150  char blue(const complex& c) const { if (white) return 255; return tmp * (1. - tmp) * (1. - tmp) * 27./4. * 255.;};
151 
152 private:
153 
154  void use_palette_(const Bild&, FILE*);
155 
156  virtual const char* name() const { return "log_palette";};
157 
158  void init();
159 
160  double scale;
161  double y0;
162  mutable double tmp;
163  mutable bool white;
164 };
165 
177 class height_palette: public palette{
178 private:
179  bool arctanscale;
180 public:
181  void precalc(const complex& c) const {
182 
183  double f(max*(std::max(abs(c)*abs(c) - min,0.)));
184  if (arctanscale){
185  f = atan(f / 6553) * M_2_PI * 65535;
186  }
187  tmp = (f > 65535) ? 65530 : static_cast<int>(f);};
188 
189  char red(const complex& c) const { return tmp / 256.;};
190  char green(const complex& c) const { return tmp % 256;};
191  char blue(const complex& c) const { return 0;};
192 
193 private:
194 
195  void use_palette_(const Bild&, FILE*);
196 
197  virtual const char* name() const { return "height_palette";};
198 
199  void init();
200 
201  double max;
202  double min;
203 
204  mutable int tmp;
205 };
206 
207 
209 public:
210  void precalc(const complex& c) const {
211  tmp = abs(c);
212  white = (tmp == 0.);
213  tmp -= delta_eff;
214  if (tmp < 0.) tmp = 0.;
215  tmp = atan(tmp * scale) * M_2_PI;};
216 
217  char red(const complex& c) const { if (white) return 255; return tmp * 255.;};
218  char green(const complex& c) const { if (white) return 255; return tmp*tmp*(1.-tmp)*27./4.*255.;};
219  char blue(const complex& c) const { if (white) return 255; return tmp * (1. - tmp) * (1. - tmp) * 27./4. * 255.;};
220 
221 private:
222 
223  void use_palette_(const Bild&, FILE*);
224 
225  virtual const char* name() const { return "multilayer_default_palette";};
226 
227  void init();
228 
229  double scale;
230  double delta;
231  double delta_eff;
232  mutable double tmp;
233  mutable bool white;
234 };
235 
236 
248 class complex_palette: public palette{
249 public:
250  void precalc(const complex& c) const {
251  if (part == 0) {
252  tmp = c.real();
253  } else if (part == 1) {
254  tmp = c.imag();
255  } else if (part == 2) {
256  tmp = abs(c);
257  } else if (part == 3) {
258  tmp = atan2(c.imag(),c.real());
259  }
260  tmp = atan(tmp * scale) * M_1_PI + 0.5;
261  };
262 
263  // modelled after the 9-class RdBu colormap (see http://colorbrewer2.org/)
264  // to reverse the map, simply replace (1.-tmp) with tmp
265  char red(const complex& c) const {
266  return (0.70448+1.52424*(1.-tmp)-2.18358*(1.-tmp)*(1.-tmp)) * 255.;
267  };
268  char green(const complex& c) const {
269  return (0.0754843+3.05864*(1.-tmp)-2.77681*(1.-tmp)*(1.-tmp)) * 255;
270  };
271  char blue(const complex& c) const {
272  return (0.0892454+2.55404*(1.-tmp)-1.9815*(1.-tmp)*(1.-tmp))* 255.;
273  };
274 
275 private:
276 
277  void use_palette_(const Bild&, FILE*);
278 
279  virtual const char* name() const { return "complex_palette";};
280 
281  void init();
282 
283  double scale;
284  double delta;
285 
286  int part;
287 
288  mutable double tmp;
289 };
290 
297 class parula_palette: public palette{
298 public:
299  void precalc(const complex& c) const {
300  tmp = abs(c)*abs(c);
301 
302  white = (tmp <= white_thrshld);
303 
304  if (tmp > 10000){
305  if (c.real() < 0)
306  {
307  tmp=0;
308  }else{
309  white = true;
310  }
311  }else{
312  tmp -= delta_eff;
313  }
314 
315  if (tmp < 0.) tmp = 0.;
316 
317  tmp = atan(tmp * scale) * M_2_PI;
318  };
319 
320  char red(const complex& c) const {
321  if (white) return 255;
322  return (0.205465 -4.48508 *tmp+40.8598 *tmp*tmp-169.805 *tmp*tmp*tmp+343.401 *tmp*tmp*tmp*tmp-315.711 *tmp*tmp*tmp*tmp*tmp+106.514 *tmp*tmp*tmp*tmp*tmp*tmp) * 255.;
323  };
324  char green(const complex& c) const {
325  if (white) return 255;
326  return (0.164678 +2.97057 *tmp-15.2531 *tmp*tmp+59.0754 *tmp*tmp*tmp-113.712 *tmp*tmp*tmp*tmp+99.8169 *tmp*tmp*tmp*tmp*tmp-32.0779 *tmp*tmp*tmp*tmp*tmp*tmp) * 255.;
327  };
328  char blue(const complex& c) const {
329  if (white) return 255;
330  return (0.53106 +5.66654 *tmp-32.4304 *tmp*tmp+85.9473 *tmp*tmp*tmp-126.792 *tmp*tmp*tmp*tmp+95.8767 *tmp*tmp*tmp*tmp*tmp-28.7464 *tmp*tmp*tmp*tmp*tmp*tmp) * 255.;
331  };
332 
333 private:
334 
335  void use_palette_(const Bild&, FILE*);
336 
337  virtual const char* name() const { return "parula_palette";};
338  double white_thrshld;
339 
340  void init();
341 
342  double scale;
343  double delta;
344  double delta_eff;
345  mutable double tmp;
346  mutable bool white;
347 };
348 
349 
357 public:
358  void precalc(const complex& c) const {
359  tmp = abs(c)*abs(c);
360  white = (tmp == 0.);
361  if (!white){
362  tmp = (log(tmp) + y0) * scale;
363  if (tmp < 0) tmp = 0;
364  // if (tmp > 1) tmp = 1;
365  if (tmp > 0.89) tmp = 0.89;
366  }
367  };
368 
369  char red(const complex& c) const {
370  if (white) return 255;
371  return (0.205465 -4.48508 *tmp+40.8598 *tmp*tmp-169.805 *tmp*tmp*tmp+343.401 *tmp*tmp*tmp*tmp-315.711 *tmp*tmp*tmp*tmp*tmp+106.514 *tmp*tmp*tmp*tmp*tmp*tmp) * 255.;
372  };
373  char green(const complex& c) const {
374  if (white) return 255;
375  return (0.164678 +2.97057 *tmp-15.2531 *tmp*tmp+59.0754 *tmp*tmp*tmp-113.712 *tmp*tmp*tmp*tmp+99.8169 *tmp*tmp*tmp*tmp*tmp-32.0779 *tmp*tmp*tmp*tmp*tmp*tmp) * 255.;
376  };
377  char blue(const complex& c) const {
378  if (white) return 255;
379  return (0.53106 +5.66654 *tmp-32.4304 *tmp*tmp+85.9473 *tmp*tmp*tmp-126.792 *tmp*tmp*tmp*tmp+95.8767 *tmp*tmp*tmp*tmp*tmp-28.7464 *tmp*tmp*tmp*tmp*tmp*tmp) * 255.;
380  };
381 
382 private:
383 
384  void use_palette_(const Bild&, FILE*);
385 
386  virtual const char* name() const { return "parula_log_palette";};
387 
388  void init();
389 
390  double scale;
391  double y0;
392  mutable double tmp;
393  mutable bool white;
394 };
395 
396 
397 #endif
use logarithmic black-blue-green-yellow-orange-red palette,
Definition: write_jpg.hpp:136
class to turn a complex value into a color
Definition: write_jpg.hpp:60
Class to contain wave-function image data.
Definition: generate_wavefunction.hpp:25
Make a jpg image out of a wavefunction jpg_image_processor:
Definition: write_jpg.hpp:23
Abstract base class to process calculated wavefunctions.
Definition: image_parser.hpp:21
creates a povray height ppm This palette will use red and green values to create a height field that ...
Definition: write_jpg.hpp:177
An abstract base class supporting xml_file_reading of input parameters.
Definition: input_file.hpp:79
Definition: write_jpg.hpp:208
a blue-white-red palette to visualize negative/positive values (in the real/imaginary part) ...
Definition: write_jpg.hpp:248
the default black-blue-green-yellow-orange-red palette
Definition: write_jpg.hpp:87
a yellow-green-blue palette similar to MATLAB&#39;s parula colormap
Definition: write_jpg.hpp:297
use a logarithmic yellow-green-blue palette similar to MATLAB&#39;s parula colormap
Definition: write_jpg.hpp:356