ROOT  6.06/09
Reference Guide
TImageDump.cxx
Go to the documentation of this file.
1 // @(#)root/postscript:$Id$
2 // Author: Valeriy Onuchin
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TImageDump
13 \ingroup PS
14 
15 Save canvas as an image (GIF, JPEG, PNG, XPM, TIFF etc.).
16 
17 Example:
18 ~~~ {.cpp}
19  $ root -b
20  root [0] .x hsimple.C
21  root [1] c1->Print("c1.gif");
22 ~~~
23 TImageDump can be used in any mode (batch, interactive) as follows
24 ~~~ {.cpp}
25  TCanvas *c1;
26  TImageDump *imgdump = new TImageDump("test.png");
27  c1->Paint();
28  imgdump->Close();
29 ~~~
30 */
31 
32 #include "TImageDump.h"
33 #include "TImage.h"
34 #include "TMath.h"
35 #include "TPoint.h"
36 #include "TColor.h"
37 #include "TVirtualPad.h"
38 #include "TEnv.h"
39 #include "TROOT.h"
40 #include "TSystem.h"
41 #include "TText.h"
42 #include "RStipples.h"
43 #include "TList.h"
44 #include "TStyle.h"
45 #include "TObjString.h"
46 #include "TObjArray.h"
47 
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default constructor
53 
55 {
56  fStream = 0;
57  fImage = 0;
58  gVirtualPS = this;
59  fType = 0;
60  SetTitle("IMG");
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Initialize batch image interface
65 ///
66 /// fname : image file name
67 ///
68 /// The possible workstation types are:
69 /// - 111 - Portrait
70 /// - 112 - Landscape
71 /// - 114 - preview, keep in memory (do not write on delete)
72 
73 TImageDump::TImageDump(const char *fname, Int_t wtype) : TVirtualPS(fname, wtype)
74 {
75  Open(fname, wtype);
76  gVirtualPS = this;
77  SetTitle("IMG");
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Open a image file
82 
83 void TImageDump::Open(const char *fname, Int_t type)
84 {
85  fStream = 0;
87  fType = type;
88  SetName(fname);
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// destructor
93 
95 {
96  Close();
97 
98  delete fImage;
99  fImage = 0;
100 
101  gVirtualPS = 0;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Close a image file
106 
108 {
109  // if fType == 114 - do not write image
110  if (!fImage || (fType == 114)) {
111  return;
112  }
113 
114  //if (fType == 112) fImage->Flip(90);
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Draw a Box
120 
122 {
123  if (!gPad || !fImage) {
124  return;
125  }
126 
127  fImage->BeginPaint();
128 
129  static Double_t x[4], y[4];
130  Int_t ix1 = x1 < x2 ? XtoPixel(x1) : XtoPixel(x2);
131  Int_t ix2 = x1 < x2 ? XtoPixel(x2) : XtoPixel(x1);
132  Int_t iy1 = y1 < y2 ? YtoPixel(y1) : YtoPixel(y2);
133  Int_t iy2 = y1 < y2 ? YtoPixel(y2) : YtoPixel(y1);
134 
135  if (ix1<0 || ix2 <0 || iy1 < 0 || iy2 <0) return; // box is not visible
136 
137  if (TMath::Abs(ix2-ix1) < 1) ix2 = ix1+1;
138  if (TMath::Abs(iy1-iy2) < 1) iy1 = iy2+1;
139 
140  Int_t fillis = fFillStyle/1000;
141  Int_t fillsi = fFillStyle%1000;
142 
143  TColor *col = gROOT->GetColor(fFillColor);
144  if (!col) { // no color, set it white
145  fFillColor = 10;
146  col = gROOT->GetColor(fFillColor);
147  if (!col) return;
148  }
149 
150  TColor *linecol = gROOT->GetColor(fLineColor);
151  if (!linecol) { // no color, set it to black
152  fLineColor = 1;
153  linecol = gROOT->GetColor(fLineColor);
154  }
155 
156  if ((fillis == 3) || (fillis == 2)) {
157  if (fillsi > 99) {
158  x[0] = x1; y[0] = y1;
159  x[1] = x2; y[1] = y1;
160  x[2] = x2; y[2] = y2;
161  x[3] = x1; y[3] = y2;
162  return;
163  }
164  if ((fillsi > 0) && (fillsi < 26)) {
165  x[0] = x1; y[0] = y1;
166  x[1] = x2; y[1] = y1;
167  x[2] = x2; y[2] = y2;
168  x[3] = x1; y[3] = y2;
169  DrawPS(-4, &x[0], &y[0]);
170  }
171  if (fillsi == -3) {
172  // fill style = -3 ... which is NEVER used now
173  }
174  }
175 
176  if (fillis == 1) {
177  fImage->DrawBox(ix1, iy1, ix2, iy2, col->AsHexString(), 1, TVirtualX::kFilled);
178  }
179 
180  if (fillis == 0) {
181  if (fLineWidth<=0) return;
182  fImage->DrawBox(ix1, iy1, ix2, iy2, linecol->AsHexString(), fLineWidth, TVirtualX::kHollow);
183  }
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Draw a Frame around a box
188 ///
189 /// - mode = -1 the box looks as it is behind the screen
190 /// - mode = 1 the box looks as it is in front of the screen
191 /// border is the border size in already pre-computed dark is the
192 /// color for the dark part of the frame light is the color for the light
193 /// part of the frame
194 
196  Int_t mode, Int_t bordersize, Int_t dark, Int_t light)
197 {
198  if (!gPad || !fImage) {
199  return;
200  }
201 
202  fImage->BeginPaint();
203 
204  bordersize = bordersize < 1 ? 1 : bordersize;
205 
206  TColor *col;
207  TColor *lo = gROOT->GetColor(dark);
208  if (!lo) {
209  lo = gROOT->GetColor(10);
210  }
211  TColor *hi = gROOT->GetColor(light);
212  if (!hi) {
213  hi = gROOT->GetColor(10);
214  }
215 
216  Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
217 
218  px1 = XtoPixel(x1); py1 = YtoPixel(y1);
219  px2 = XtoPixel(x2); py2 = YtoPixel(y2);
220  if (px1 < px2) {pxl = px1; pxt = px2;}
221  else {pxl = px2; pxt = px1;}
222  if (py1 > py2) {pyl = py1; pyt = py2;}
223  else {pyl = py2; pyt = py1;}
224 
225  if (bordersize == 1) {
226  col = gROOT->GetColor(fLineColor);
227  if (!col) {
228  fLineColor = 1;
229  col = gROOT->GetColor(fLineColor);
230  if (!col) return;
231  }
232  fImage->DrawBox(pxl, pyl, pxt, pyt-1, col->AsHexString(), TVirtualX::kFilled);
233  return;
234  }
235 
236  if (!fImage->IsValid()) {
237  col = gROOT->GetColor(light);
238  if (!col) {
239  col = gROOT->GetColor(10);
240  if (!col) return;
241  }
242  fImage->DrawBox(pxl, pyl, pxt, pyt, // force image creation and resizing
243  "#ffffffff", 1, TVirtualX::kFilled);
244  }
245 
246  TPoint frame[6];
247 
248  frame[0].fX = pxl; frame[0].fY = pyl;
249  frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
250  frame[2].fX = pxl + bordersize; frame[2].fY = pyt + bordersize;
251  frame[3].fX = pxt - bordersize; frame[3].fY = pyt + bordersize;;
252  frame[4].fX = pxt; frame[4].fY = pyt;
253  frame[5].fX = pxl; frame[5].fY = pyt;
254 
255  if (mode == -1) col = lo;
256  else col = hi;
257 
258  fImage->DrawFillArea(6, frame, col->AsHexString());
259 
260  frame[0].fX = pxl; frame[0].fY = pyl;
261  frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
262  frame[2].fX = pxt - bordersize; frame[2].fY = frame[1].fY;
263  frame[3].fX = frame[2].fX; frame[3].fY = pyt + bordersize;
264  frame[4].fX = pxt; frame[4].fY = pyt;
265  frame[5].fX = pxt; frame[5].fY = pyl;
266 
267  if (mode == -1) col = hi;
268  else col = lo;
269 
270  fImage->DrawFillArea(6, frame, col->AsHexString());
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// not used
275 
277 {
278  if (!gPad || !fImage) {
279  return;
280  }
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// draw polymarker
285 
287 {
288  if (!gPad || !fImage) {
289  return;
290  }
291 
292  fImage->BeginPaint();
293 
295  static TPoint pt[20];
296 
297  if (ms > 7 && ms <= 19) ms = 20;
298  if (ms == 4) ms = 24;
299 
300  // Define the marker size
301  const Int_t kBASEMARKER = 8;
302  Double_t msize = fMarkerSize * kBASEMARKER;
303  if (ms == 6) msize *= 0.2;
304  if (ms == 7) msize *= 0.3;
305  Double_t m = msize;
306  Double_t m2 = m/2;
307  Double_t m3 = m/3;
308  Double_t m6 = m/6;
309 
310  TColor *col = gROOT->GetColor(fMarkerColor);
311  if (!col) { // no color
312  fMarkerColor = 1;
313  col = gROOT->GetColor(fMarkerColor);
314  if (!col) return;
315  }
316 
317  // Draw the marker according to the type
318  Short_t ix,iy;
319  for (Int_t i=0;i<n;i++) {
320  ix = XtoPixel(xw[i]);
321  iy = YtoPixel(yw[i]);
322 
323  switch (ms) {
324  // Dots (.) big, medium and small
325  case 7:
326  fImage->PutPixel((UInt_t)ix-1, (UInt_t)iy-1, col->AsHexString());
327  fImage->PutPixel((UInt_t)ix-1, (UInt_t)iy+1, col->AsHexString());
328  fImage->PutPixel((UInt_t)ix+1, (UInt_t)iy+1, col->AsHexString());
329  fImage->PutPixel((UInt_t)ix+1, (UInt_t)iy-1, col->AsHexString());
330  case 6:
331  fImage->PutPixel((UInt_t)ix, (UInt_t)iy-1, col->AsHexString());
332  fImage->PutPixel((UInt_t)ix, (UInt_t)iy+1, col->AsHexString());
333  fImage->PutPixel((UInt_t)ix-1, (UInt_t)iy, col->AsHexString());
334  fImage->PutPixel((UInt_t)ix+1, (UInt_t)iy, col->AsHexString());
335  case 1:
336  fImage->PutPixel((UInt_t)ix, (UInt_t)iy, col->AsHexString());
337  break;
338  // Plus (+)
339  case 2:
340  fImage->DrawLine(UInt_t(ix-m2), UInt_t(iy), UInt_t(ix+m2), UInt_t(iy), col->AsHexString());
341  fImage->DrawLine(UInt_t(ix), UInt_t(iy-m2), UInt_t(ix), UInt_t(iy+m2), col->AsHexString());
342  break;
343  // X shape (X)
344  case 5:
345  fImage->DrawLine(UInt_t(ix-m2), UInt_t(iy-m2), UInt_t(ix+m2), UInt_t(iy+m2), col->AsHexString());
346  fImage->DrawLine(UInt_t(ix-m2), UInt_t(iy+m2), UInt_t(ix+m2), UInt_t(iy-m2), col->AsHexString());
347  break;
348  // Asterisk shape (*)
349  case 3:
350  case 31:
351  fImage->DrawLine(UInt_t(ix-m2), UInt_t(iy), UInt_t(ix+m2), UInt_t(iy), col->AsHexString());
352  fImage->DrawLine(UInt_t(ix), UInt_t(iy-m2), UInt_t(ix), UInt_t(iy+m2), col->AsHexString());
353  fImage->DrawLine(UInt_t(ix-m2), UInt_t(iy-m2), UInt_t(ix+m2), UInt_t(iy+m2), col->AsHexString());
354  fImage->DrawLine(UInt_t(ix-m2), UInt_t(iy+m2), UInt_t(ix+m2), UInt_t(iy-m2), col->AsHexString());
355  break;
356  // Circle
357  case 4:
358  case 24:
359  fImage->DrawCircle(ix, iy, Int_t(msize/2), col->AsHexString(), 1);
360  break;
361  // Circle
362  case 8:
363  case 20:
364  fImage->DrawCircle(ix, iy, Int_t(msize/2), col->AsHexString(), -1);
365  break;
366  // Square
367  case 21:
368  fImage->FillRectangle(col->AsHexString(), UInt_t(ix-m2), UInt_t(iy-m2), UInt_t(m), UInt_t(m));
369  break;
370  case 25:
371  fImage->DrawRectangle(UInt_t(ix-m2), UInt_t(iy-m2), UInt_t(m), UInt_t(m), col->AsHexString());
372  break;
373  // Down triangle
374  case 23:
375  case 32:
376  pt[0].fX = Short_t(ix-m2); pt[0].fY = Short_t(iy-m2);
377  pt[1].fX = Short_t(ix+m2); pt[1].fY = Short_t(iy-m2);
378  pt[2].fX = Short_t(ix); pt[2].fY = Short_t(iy+m2);
379  pt[3].fX = Short_t(ix-m2); pt[3].fY = Short_t(iy-m2);
380  ms == 32 ? fImage->DrawPolyLine(4, pt, col->AsHexString()) :
381  fImage->FillPolygon(3, pt, col->AsHexString());
382  break;
383  // Up triangle
384  case 22:
385  case 26:
386  pt[0].fX = Short_t(ix); pt[0].fY = Short_t(iy-m2);
387  pt[1].fX = Short_t(ix+m2); pt[1].fY = Short_t(iy+m2);
388  pt[2].fX = Short_t(ix-m2); pt[2].fY = Short_t(iy+m2);
389  pt[3].fX = Short_t(ix); pt[3].fY = Short_t(iy-m2);
390  ms == 26 ? fImage->DrawPolyLine(4, pt, col->AsHexString()) :
391  fImage->FillPolygon(3, pt, col->AsHexString());
392  break;
393  case 27:
394  case 33:
395  pt[0].fX = Short_t(ix); pt[0].fY = Short_t(iy-m2);
396  pt[1].fX = Short_t(ix+m3); pt[1].fY = Short_t(iy);
397  pt[2].fX = Short_t(ix); pt[2].fY = Short_t(iy+m2);
398  pt[3].fX = Short_t(ix-m3); pt[3].fY = Short_t(iy);
399  pt[4].fX = Short_t(ix); pt[4].fY = Short_t(iy-m2);
400  ms == 27 ? fImage->DrawPolyLine(5, pt, col->AsHexString()) :
401  fImage->FillPolygon(4, pt, col->AsHexString());
402  break;
403  case 28:
404  case 34:
405  pt[0].fX = Short_t(ix-m6); pt[0].fY = Short_t(iy-m6);
406  pt[1].fX = Short_t(ix-m6); pt[1].fY = Short_t(iy-m2);
407  pt[2].fX = Short_t(ix+m6); pt[2].fY = Short_t(iy-m2);
408  pt[3].fX = Short_t(ix+m6); pt[3].fY = Short_t(iy-m6);
409  pt[4].fX = Short_t(ix+m2); pt[4].fY = Short_t(iy-m6);
410  pt[5].fX = Short_t(ix+m2); pt[5].fY = Short_t(iy+m6);
411  pt[6].fX = Short_t(ix+m6); pt[6].fY = Short_t(iy+m6);
412  pt[7].fX = Short_t(ix+m6); pt[7].fY = Short_t(iy+m2);
413  pt[8].fX = Short_t(ix-m6); pt[8].fY = Short_t(iy+m2);
414  pt[9].fX = Short_t(ix-m6); pt[9].fY = Short_t(iy+m6);
415  pt[10].fX = Short_t(ix-m2); pt[10].fY = Short_t(iy+m6);
416  pt[11].fX = Short_t(ix-m2); pt[11].fY = Short_t(iy-m6);
417  pt[12].fX = Short_t(ix-m6); pt[12].fY = Short_t(iy-m6);
418  ms == 28 ? fImage->DrawPolyLine(13, pt, col->AsHexString()) :
419  fImage->FillPolygon(12, pt, col->AsHexString());
420  break;
421  case 29:
422  case 30:
423  pt[0].fX = Short_t(ix); pt[0].fY = Short_t(iy+m2);
424  pt[1].fX = Short_t(ix+0.112255*m); pt[1].fY = Short_t(iy+0.15451*m);
425  pt[2].fX = Short_t(ix+0.47552*m); pt[2].fY = Short_t(iy+0.15451*m);
426  pt[3].fX = Short_t(ix+0.181635*m); pt[3].fY = Short_t(iy-0.05902*m);
427  pt[4].fX = Short_t(ix+0.29389*m); pt[4].fY = Short_t(iy-0.40451*m);
428  pt[5].fX = Short_t(ix); pt[5].fY = Short_t(iy-0.19098*m);
429  pt[6].fX = Short_t(ix-0.29389*m); pt[6].fY = Short_t(iy-0.40451*m);
430  pt[7].fX = Short_t(ix-0.181635*m); pt[7].fY = Short_t(iy-0.05902*m);
431  pt[8].fX = Short_t(ix-0.47552*m); pt[8].fY = Short_t(iy+0.15451*m);
432  pt[9].fX = Short_t(ix-0.112255*m); pt[9].fY = Short_t(iy+0.15451*m);
433  pt[10].fX = Short_t(ix); pt[10].fY = Short_t(iy+m2);
434  ms == 30 ? fImage->DrawPolyLine(11, pt, col->AsHexString()) :
435  fImage->DrawFillArea(10, pt, col->AsHexString());
436  break;
437  default:
438  fImage->PutPixel(UInt_t(ix), UInt_t(iy), col->AsHexString());
439  break;
440  }
441  }
442 }
443 
444 ////////////////////////////////////////////////////////////////////////////////
445 /// This function defines a path with xw and yw and draw it according the
446 /// value of nn:
447 ///
448 /// - If nn > 0 a line is drawn.
449 /// - If nn < 0 a closed polygon is drawn.
450 
452 {
453  if (!gPad || !fImage || !nn) {
454  return;
455  }
456 
457  fImage->BeginPaint();
458 
459  TColor *col = 0;
460  Int_t fais = 0 , fasi = 0;
461  Bool_t line = nn > 1;
462  UInt_t n = TMath::Abs(nn);
463 
464  fais = fFillStyle/1000;
465  fasi = fFillStyle%1000;
466 
467  Short_t px1, py1, px2, py2;
468  static const UInt_t gCachePtSize = 200;
469  static TPoint gPointCache[gCachePtSize];
470  Bool_t del = kTRUE;
471 
472 
473  // SetLineStyle
474  Int_t ndashes = 0;
475  char *dash = 0;
476  static char dashList[10];
477  Int_t dashLength = 0;
478  Int_t dashSize = 0;
479 
480  if (line) {
481  if (fLineWidth<=0) return;
482  // dash lines
483  if (fLineStyle > 1) {
485  TObjArray *tokens = st.Tokenize(" ");
486  ndashes = tokens->GetEntries();
487  dash = new char[ndashes];
488 
489  for (int j = 0; j < ndashes; j++) {
490  Int_t it;
491  sscanf(((TObjString*)tokens->At(j))->GetName(), "%d", &it);
492  dash[j] = (char)(it/4);
493  }
494 
495  dashSize = TMath::Min((int)sizeof(dashList), ndashes);
496  dashLength = 0;
497  for (int i = 0; i < dashSize; i++ ) {
498  dashList[i] = dash[i];
499  dashLength += dashList[i];
500  }
501  delete tokens;
502  delete [] dash;
503  }
504 
505  // SetLineColor
506  col = gROOT->GetColor(fLineColor);
507  if (!col) { // no color, make it black
508  fLineColor = 1;
509  col = gROOT->GetColor(fLineColor);
510  if (!col) return;
511  }
512  }
513 
514  if (n == 1) { // point
515  col = gROOT->GetColor(fFillColor);
516  if (!col) { // no color, make it black
517  fFillColor = 1;
518  col = gROOT->GetColor(fFillColor);
519  if (!col) return;
520  }
521  px1 = XtoPixel(x[0]); py1 = YtoPixel(y[0]);
522  fImage->PutPixel(px1, py1, col->AsHexString());
523  return;
524  }
525 
526  if (n == 2) { // line
527  px1 = XtoPixel(x[0]); py1 = YtoPixel(y[0]);
528  px2 = XtoPixel(x[1]); py2 = YtoPixel(y[1]);
529 
530  // SetLineColor
531  col = gROOT->GetColor(fLineColor);
532  if (!col) { // no color, make it black
533  fLineColor = 1;
534  col = gROOT->GetColor(fLineColor);
535  if (!col) return;
536  }
537  if (fLineStyle < 2) {
538  fImage->DrawLine(px1, py1, px2, py2, col->AsHexString(), fLineWidth);
539  } else {
540  fImage->DrawDashLine(px1, py1, px2, py2, dashSize, (const char*)dashList,
541  col->AsHexString(), fLineWidth);
542  }
543  return;
544  }
545 
546  if (!line && ((fais == 3) || (fais == 2)) && (fasi > 100) ) {
547  return;
548  }
549 
550  TPoint *pt = 0;
551  if (n+1 < gCachePtSize) {
552  pt = (TPoint*)&gPointCache;
553  del = kFALSE;
554  } else {
555  pt = new TPoint[n+1];
556  del = kTRUE;
557  }
558 
559  TColor *fcol = gROOT->GetColor(fFillColor);
560  if (!fcol) { // no color, set it white
561  fFillColor = 10;
562  fcol = gROOT->GetColor(fFillColor);
563  }
564 
565  TColor *lcol = gROOT->GetColor(fLineColor);
566  if (!lcol) { // no color, make it black
567  fLineColor = 1;
568  lcol = gROOT->GetColor(fLineColor);
569  }
570 
571  for (UInt_t i = 0; i < n; i++) {
572  pt[i].fX = XtoPixel(x[i]);
573  pt[i].fY = YtoPixel(y[i]);
574  }
575  pt[n].fX = pt[0].fX;
576  pt[n].fY = pt[0].fY;
577 
578  const char *stipple = (fais == 3) && (fasi > 0) && (fasi < 26) ? (const char*)gStipples[fasi] : 0;
579 
580  // filled polygon
581  if (!line && fFillStyle && (fFillStyle != 4000)) {
582  if (!fcol) return;
583 
584  if (n < 5) { // convex
585  fImage->FillPolygon(n, pt, fcol->AsHexString(), stipple);
586  } else { // non-convex fill area
587  fImage->DrawFillArea(n, pt, fcol->AsHexString(), stipple);
588  }
589  }
590 
591  // hollow polygon or polyline is drawn
592  if (line || !fFillStyle || (fFillStyle == 4000)) {
593  if (!lcol) return;
594  if (!line) {
595  fImage->DrawPolyLine(n+1, pt, fcol->AsHexString(), 1);
596  } else {
597  if (fLineStyle < 2) { // solid
598  fImage->DrawPolyLine(n, pt, lcol->AsHexString(), fLineWidth);
599  } else { // dashed
600  DrawDashPolyLine(n, pt, dashSize, (const char*)dashList,
601  lcol->AsHexString(), fLineWidth);
602  }
603  }
604  }
605  if (del) delete [] pt;
606 }
607 
608 ////////////////////////////////////////////////////////////////////////////////
609 /// not used
610 
612 {
613  if (!gPad || !fImage) {
614  return;
615  }
616 }
617 
618 ////////////////////////////////////////////////////////////////////////////////
619 /// draw dashed polyline
620 
622  const char* pDash, const char* col, UInt_t thick)
623 {
624  Int_t x0 = xy[0].GetX();
625  Int_t y0 = xy[0].GetY();
626  Int_t x = 0;
627  Int_t y = 0;
628 
629  for (Int_t i = 1; i < nn; i++) {
630  x = xy[i].GetX();
631  y = xy[i].GetY();
632 
633  fImage->DrawDashLine(x0, y0, x, y, nDash, pDash, col, thick);
634 
635  x0 = x;
636  y0 = y;
637  }
638 }
639 
640 ////////////////////////////////////////////////////////////////////////////////
641 /// new page
642 
644 {
645  if (gPad && fImage) {
646  UInt_t w = UInt_t(gPad->GetWw()*gPad->GetWNDC());
647  UInt_t h = UInt_t(gPad->GetWh()*gPad->GetHNDC());
648  fImage->DrawRectangle(0, 0, w, h, "#ffffffff");
649  }
650  return;
651 }
652 
653 ////////////////////////////////////////////////////////////////////////////////
654 /// Draw text
655 ///
656 /// - x: x position of the text
657 /// - y: y position of the text
658 
659 void TImageDump::Text(Double_t x, Double_t y, const char *chars)
660 {
661  if (!gPad || !fImage) {
662  return;
663  }
664 
665  fImage->BeginPaint();
666 
667  TText t(x, y, chars);
673  fImage->DrawText(&t, XtoPixel(x), YtoPixel(y));
674 }
675 
676 ////////////////////////////////////////////////////////////////////////////////
677 /// Draw text
678 ///
679 /// - x: x position of the text
680 /// - y: y position of the text
681 
682 void TImageDump::Text(Double_t x, Double_t y, const wchar_t *chars)
683 {
684  if (!gPad || !fImage) {
685  return;
686  }
687 
688  fImage->BeginPaint();
689 
690  TText t(x, y, chars);
696  fImage->DrawText(&t, XtoPixel(x), YtoPixel(y));
697 }
698 
699 
700 ////////////////////////// CellArray code ////////////////////////////////////
702 static Int_t gCellArrayN = 0;
703 static Int_t gCellArrayW = 0;
704 static Int_t gCellArrayH = 0;
705 static Int_t gCellArrayX1 = 0;
706 static Int_t gCellArrayX2 = 0;
707 static Int_t gCellArrayY1 = 0;
708 static Int_t gCellArrayY2 = 0;
709 static Int_t gCellArrayIdx = 0;
710 
711 ////////////////////////////////////////////////////////////////////////////////
712 ///cell array begin
713 
715  Double_t y1, Double_t y2)
716 {
717  if (!gPad || !fImage || (w <= 0) || (h <= 0)) {
718  return;
719  }
720 
721  if (gCellArrayColors) {
722  delete [] gCellArrayColors;
723  }
724 
725  fImage->BeginPaint();
726 
727  gCellArrayN = w * h;
728  gCellArrayW = w;
729  gCellArrayH = h;
731 
732  gCellArrayX1 = x1 < x2 ? XtoPixel(x1) : XtoPixel(x2);
733  gCellArrayX2 = x1 > x2 ? XtoPixel(x2) : XtoPixel(x1);
734  gCellArrayY1 = y1 < y2 ? YtoPixel(y1) : YtoPixel(y2);
735  gCellArrayY2 = y1 < y2 ? YtoPixel(y2) : YtoPixel(y1);
736 
737  gCellArrayIdx = 0;
738 }
739 
740 ////////////////////////////////////////////////////////////////////////////////
741 /// Cell array fill
742 
744 {
745  if (gCellArrayIdx >= gCellArrayN) return;
746 
747  fImage->BeginPaint();
748 
749  gCellArrayColors[gCellArrayIdx] = ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
750  gCellArrayIdx++;
751 }
752 
753 ////////////////////////////////////////////////////////////////////////////////
754 /// Cell array end
755 
757 {
758  if (!fImage || !gCellArrayColors || !gCellArrayW || !gCellArrayH) {
759  return;
760  }
761 
762  fImage->BeginPaint();
763 
766 
767  delete [] gCellArrayColors;
768  gCellArrayColors = 0;
769  gCellArrayN = 0;
770  gCellArrayW = 0;
771  gCellArrayH = 0;
772  gCellArrayX1 = 0;
773  gCellArrayX2 = 0;
774  gCellArrayY1 = 0;
775  gCellArrayY2 = 0;
776  gCellArrayIdx = 0;
777 }
778 
779 ////////////////////////////////////////////////////////////////////////////////
780 /// Set color with its R G B components
781 ///
782 /// - r: % of red in [0,1]
783 /// - g: % of green in [0,1]
784 /// - b: % of blue in [0,1]
785 
786 void TImageDump::SetColor(Float_t /*r*/, Float_t /*g*/, Float_t /*b*/)
787 {
788 }
789 
790 ////////////////////////////////////////////////////////////////////////////////
791 /// x to pixel
792 
794 {
795  return gPad->XtoAbsPixel(x);
796 }
797 
798 ////////////////////////////////////////////////////////////////////////////////
799 /// y to pixel
800 
802 {
803  return gPad->YtoAbsPixel(y);
804 }
void DrawDashPolyLine(Int_t npoints, TPoint *pt, UInt_t nDash, const char *pDash, const char *col, UInt_t thick)
draw dashed polyline
Definition: TImageDump.cxx:621
void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
cell array begin
Definition: TImageDump.cxx:714
const char * GetLineStyleString(Int_t i=1) const
Return line style string (used by PostScript).
Definition: TStyle.cxx:787
void CellArrayEnd()
Cell array end.
Definition: TImageDump.cxx:756
static UInt_t * gCellArrayColors
Definition: TImageDump.cxx:701
An array of TObjects.
Definition: TObjArray.h:39
void Close(Option_t *opt="")
Close a image file.
Definition: TImageDump.cxx:107
TImage * fImage
Definition: TImageDump.h:35
virtual void DrawCellArray(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, UInt_t *)
Definition: TImage.h:233
TLine * line
virtual void DrawBox(Int_t, Int_t, Int_t, Int_t, const char *="#000000", UInt_t=1, Int_t=0)
Definition: TImage.h:204
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
virtual void PutPixel(Int_t, Int_t, const char *="#000000")
Definition: TImage.h:212
const char Option_t
Definition: RtypesCore.h:62
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
virtual void WriteImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:131
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
virtual Bool_t IsValid() const
Definition: TImage.h:246
TH1 * h
Definition: legend2.C:5
SCoord_t fX
Definition: TPoint.h:37
Size_t fMarkerSize
Definition: TAttMarker.h:37
#define gROOT
Definition: TROOT.h:340
void Text(Double_t x, Double_t y, const char *string)
Draw text.
Definition: TImageDump.cxx:659
SCoord_t fY
Definition: TPoint.h:38
Basic string class.
Definition: TString.h:137
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
static Int_t gCellArrayIdx
Definition: TImageDump.cxx:709
virtual void DrawPolyLine(UInt_t, TPoint *, const char *="#000000", UInt_t=1, TImage::ECoordMode=kCoordModeOrigin)
Definition: TImage.h:210
static Int_t gCellArrayY1
Definition: TImageDump.cxx:707
virtual void FillRectangle(const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:208
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
static Int_t gCellArrayW
Definition: TImageDump.cxx:703
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
void NewPage()
new page
Definition: TImageDump.cxx:643
static Int_t gCellArrayN
Definition: TImageDump.cxx:702
virtual void DrawRectangle(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition: TImage.h:206
void DrawPS(Int_t n, Float_t *xw, Float_t *yw)
not used
Definition: TImageDump.cxx:611
Base class for several text objects.
Definition: TText.h:42
SCoord_t GetY() const
Definition: TPoint.h:50
void SetColor(Float_t r, Float_t g, Float_t b)
Set color with its R G B components.
Definition: TImageDump.cxx:786
virtual void SetTextAlign(Short_t align=11)
Definition: TAttText.h:55
Definition: TPoint.h:33
Style_t fMarkerStyle
Definition: TAttMarker.h:36
Int_t XtoPixel(Double_t x)
x to pixel
Definition: TImageDump.cxx:793
static Int_t gCellArrayX1
Definition: TImageDump.cxx:705
Float_t fTextAngle
Definition: TAttText.h:35
static Int_t gCellArrayX2
Definition: TImageDump.cxx:706
Style_t fLineStyle
Definition: TAttLine.h:36
TPaveText * pt
ROOT::R::TRInterface & r
Definition: Object.C:4
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
Color_t fLineColor
Definition: TAttLine.h:35
virtual void SetTextAngle(Float_t tangle=0)
Definition: TAttText.h:56
virtual void DrawDashLine(UInt_t, UInt_t, UInt_t, UInt_t, UInt_t, const char *, const char *="#000000", UInt_t=1)
Definition: TImage.h:202
const char * AsHexString() const
Return color as hexadecimal string.
Definition: TColor.cxx:1134
unsigned int UInt_t
Definition: RtypesCore.h:42
Width_t fLineWidth
Definition: TAttLine.h:37
TMarker * m
Definition: textangle.C:8
virtual ~TImageDump()
destructor
Definition: TImageDump.cxx:94
short Short_t
Definition: RtypesCore.h:35
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
std::ofstream * fStream
Definition: TVirtualPS.h:51
Save canvas as an image (GIF, JPEG, PNG, XPM, TIFF etc.).
Definition: TImageDump.h:33
Int_t fType
Definition: TImageDump.h:36
Font_t fTextFont
Definition: TAttText.h:39
void DrawFrame(Double_t xl, Double_t yl, Double_t xt, Double_t yt, Int_t mode, Int_t border, Int_t dark, Int_t light)
Draw a Frame around a box.
Definition: TImageDump.cxx:195
const unsigned char gStipples[26][32]
Definition: RStipples.h:28
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2240
static TImage * Create()
PyObject * fType
void Open(const char *filename, Int_t type=-111)
Open a image file.
Definition: TImageDump.cxx:83
virtual void DrawText(Int_t=0, Int_t=0, const char *="", Int_t=12, const char *=0, const char *="fixed", EText3DType=TImage::kPlain, const char *=0, Float_t=0)
Definition: TImage.h:216
static const double x1[5]
static Int_t gCellArrayH
Definition: TImageDump.cxx:704
double Double_t
Definition: RtypesCore.h:55
void DrawPolyMarker(Int_t n, Float_t *x, Float_t *y)
not used
Definition: TImageDump.cxx:276
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
The color creation and management class.
Definition: TColor.h:23
virtual void FillPolygon(UInt_t, TPoint *, const char *="#000000", const char *=0, UInt_t=16, UInt_t=16)
Definition: TImage.h:220
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:493
Float_t fTextSize
Definition: TAttText.h:36
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition: TImage.h:200
SCoord_t GetX() const
Definition: TPoint.h:49
static Int_t gCellArrayY2
Definition: TImageDump.cxx:708
ClassImp(TImageDump) TImageDump
Default constructor.
Definition: TImageDump.cxx:49
Color_t fFillColor
Definition: TAttFill.h:35
R__EXTERN TVirtualPS * gVirtualPS
Definition: TVirtualPS.h:91
#define gPad
Definition: TVirtualPad.h:288
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
float type_of_call hi(const int &, const int &)
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition: TVirtualPS.h:40
virtual void DrawCircle(Int_t, Int_t, Int_t, const char *="#000000", Int_t=1)
Definition: TImage.h:237
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
Int_t YtoPixel(Double_t y)
y to pixel
Definition: TImageDump.cxx:801
virtual void DrawFillArea(UInt_t, TPoint *, const char *="#000000", const char *=0, UInt_t=16, UInt_t=16)
Definition: TImage.h:224
const Bool_t kTRUE
Definition: Rtypes.h:91
Color_t fMarkerColor
Definition: TAttMarker.h:35
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
Color_t fTextColor
Definition: TAttText.h:38
const Int_t n
Definition: legend1.C:16
void CellArrayFill(Int_t r, Int_t g, Int_t b)
Cell array fill.
Definition: TImageDump.cxx:743
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw a Box.
Definition: TImageDump.cxx:121
Style_t fFillStyle
Definition: TAttFill.h:36
Short_t fTextAlign
Definition: TAttText.h:37
virtual void BeginPaint(Bool_t=kTRUE)
Definition: TImage.h:198