Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLOutput.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Richard Maunder, Olivier Couet 02/07/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, 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#include "TGLOutput.h"
13
14#include <iostream>
15#include <fstream>
16#include "TVirtualPad.h"
17#include "TVirtualPS.h"
18#include "TGLViewer.h"
19#include "TSystem.h"
20#include "gl2ps.h"
21#include "TError.h"
22#include <cassert>
23
24/** \class TGLOutput
25\ingroup opengl
26Wrapper class for GL capture & output routines
27*/
28
29
30////////////////////////////////////////////////////////////////////////////////
31/// Capture viewer to file. Arguments are:
32/// - 'viewer' - viewer object to capture from
33/// - 'format' - output format - only postscript types presently.
34/// One of kEPS_SIMPLE, kEPS_BSP, kPDF_SIMPLE or kPDF_BSP
35/// See TGLOutput::CapturePostscript() for meanings
36/// - 'filePath' - file output name. If null defaults to './viewer.eps' or './viewer.pdf'
37/// depending on format requested
38///
39/// Note : Output files can be large and take considerable time (up to mins)
40/// to generate
41
43{
44 switch(format) {
45 case(kEPS_SIMPLE):
46 case(kEPS_BSP):
47 case(kPDF_SIMPLE):
48 case(kPDF_BSP): {
50 }
51 }
52
54 return kFALSE;
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Capture viewer to postscript file. Arguments are:
59/// - 'viewer' - viewer object to capture from
60/// - 'format' - output format
61/// - kEPS_SIMPLE - lower quality EPS
62/// - kEPS_BSP - higher quality EPS
63/// - kPDF_SIMPLE - lower quality PDF
64/// - kPDF_BSP - higher quality PDF
65/// - 'filePath' - file output name. If null defaults to './viewer.eps' or './viewer.pdf'
66/// depending on format requested
67
69{
70 if (!filePath || !filePath[0]) {
71 if (format == kEPS_SIMPLE || format == kEPS_BSP) {
72 filePath = "viewer.eps";
73 } else if (format == kPDF_SIMPLE || format == kPDF_BSP) {
74 filePath = "viewer.pdf";
75 }
76 }
77 Info("TGLOutput::Postscript()", "Start creating %s.", filePath);
78 std::cout << "Please wait.";
79
80 if (FILE *output = fopen (filePath, "w+b"))
81 {
84
85 switch(format) {
86 case kEPS_SIMPLE:
89 break;
90 case kEPS_BSP:
93 break;
94 case kPDF_SIMPLE:
97 break;
98 case kPDF_BSP:
101 break;
102 default:
103 assert(kFALSE);
104 return kFALSE;
105 }
106 Int_t bufsize = 0, state = GL2PS_OVERFLOW;
107 viewer.DoDraw();
108 viewer.fIsPrinting = kTRUE;
109 while (state == GL2PS_OVERFLOW) {
110 bufsize += 1024*1024;
111 gl2psBeginPage ("ROOT Scene Graph", "ROOT", nullptr,
114 GL_RGBA, 0, nullptr,0, 0, 0,
115 bufsize, output, nullptr);
116 viewer.DoDraw();
117 state = gl2psEndPage();
118 std::cout << ".";
119 }
120 std::cout << std::endl;
121 fclose (output);
122 viewer.fIsPrinting = kFALSE;
124 Info("TGLOutput::Postscript", "Finished creating %s.", filePath);
125 return kTRUE;
126 }
127 } else {
128 Error("TGLOutput::Postscript", "Failed to create %s. ", filePath);
129 }
130
131 return kFALSE;
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// this function used by gl-in-pad
136
138{
139 Info("TGLOutput::StartEmbeddedPS", "PS output started ...");
140
141 gVirtualPS->PrintStr("@");
142 gVirtualPS->PrintStr("% Start gl2ps EPS@");
143 gVirtualPS->PrintStr("newpath gsave save@");
144 Double_t xx[2] = {0.}, yy[2] = {0.};
145 xx[0] = gPad->GetUxmin();
146 yy[0] = gPad->GetUymin();
147 xx[1] = gPad->GetUxmax();
148 yy[1] = gPad->GetUymax();
149 gVirtualPS->PrintStr("@");
150
151 GLint vp[4];
153 gVirtualPS->DrawPS(0, xx, yy);
154 gVirtualPS->PrintStr(" exch");
155 xx[0] = xx[1];
156 yy[0] = yy[1];
157 gVirtualPS->DrawPS(0, xx, yy);
158 gVirtualPS->PrintStr(" 4 1 roll exch sub 3 1 roll sub");
159 gVirtualPS->WriteInteger(2*4*gPad->GetBorderSize());
160 gVirtualPS->PrintStr(" sub exch");
161 gVirtualPS->WriteInteger(2*4*gPad->GetBorderSize());
162 gVirtualPS->PrintStr(" sub exch");
165 gVirtualPS->PrintStr(" 4 1 roll div 3 1 roll exch div exch scale@");
166 gVirtualPS->PrintStr("@");
167 gVirtualPS->PrintStr("countdictstack@");
168 gVirtualPS->PrintStr("mark@");
169 gVirtualPS->PrintStr("/showpage {} def@");
170
171 // Close the gVirtualPS output stream
172 std::ofstream *fs = (std::ofstream*)gVirtualPS->GetStream();
173 fs->close();
174
175}
176
177////////////////////////////////////////////////////////////////////////////////
178///this function used by gl-in-pad
179/// Restore the gVirtualPS output stream
180
182{
183 std::ofstream *fs = new std::ofstream(gVirtualPS->GetName(),std::ios::app);
185 gVirtualPS->PrintStr("@");
186 gVirtualPS->PrintStr("cleartomark@");
187 gVirtualPS->PrintStr("countdictstack exch sub { end } repeat@");
188 gVirtualPS->PrintStr("restore grestore@");
189 gVirtualPS->PrintStr("% End gl2ps EPS@");
190
191 Info("TGLOutput::CloseEmbeddedPS", "PS output finished");
192}
193
194////////////////////////////////////////////////////////////////////////////////
195///this function used by gl-viewer, embedded into pad
196
198{
200
201 FILE *output = fopen (gVirtualPS->GetName(), "a");
202 if (!output) {
203 //Quite stupid fix, since if fopen fails, CloseEmbeddedPS will also
204 //fail but still I have to do it.
205 Error("TGLOutput::Capture", "can not open file for embedding ps");
207 return;
208 }
209
212 Int_t bufsize = 0, state = GL2PS_OVERFLOW;
213 viewer.DoDraw();
214 viewer.fIsPrinting = kTRUE;
215
216 while (state == GL2PS_OVERFLOW) {
217 bufsize += 1024*1024;
218 gl2psBeginPage ("ROOT Scene Graph", "ROOT", nullptr,
221 GL_RGBA, 0, nullptr,0, 0, 0,
222 bufsize, output, nullptr);
223 viewer.DoDraw();
224 state = gl2psEndPage();
225 std::cout << ".";
226 }
227
228 std::cout << std::endl;
229 fclose (output);
230 viewer.fIsPrinting = kFALSE;
231
233}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
R__EXTERN TVirtualPS * gVirtualPS
Definition TVirtualPS.h:81
#define gPad
static Bool_t Capture(TGLViewer &viewer, EFormat format, const char *filePath=nullptr)
Capture viewer to file.
Definition TGLOutput.cxx:42
static void CloseEmbeddedPS()
this function used by gl-in-pad Restore the gVirtualPS output stream
static void StartEmbeddedPS()
this function used by gl-in-pad
@ kEPS_SIMPLE
Definition TGLOutput.h:28
@ kPDF_SIMPLE
Definition TGLOutput.h:28
static Bool_t CapturePostscript(TGLViewer &viewer, EFormat format, const char *filePath)
Capture viewer to postscript file.
Definition TGLOutput.cxx:68
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition TGLViewer.h:55
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1307
virtual void SetStream(std::ofstream *os)
Definition TVirtualPS.h:72
virtual void WriteInteger(Int_t i, Bool_t space=kTRUE)
Write one Integer to the file.
virtual void DrawPS(Int_t n, Float_t *xw, Float_t *yw)=0
virtual void PrintStr(const char *string="")
Output the string str in the output buffer.
virtual void * GetStream() const
Definition TVirtualPS.h:71
static void output()