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
30
31////////////////////////////////////////////////////////////////////////////////
32/// Capture viewer to file. Arguments are:
33/// - 'viewer' - viewer object to capture from
34/// - 'format' - output format - only postscript types presently.
35/// One of kEPS_SIMPLE, kEPS_BSP, kPDF_SIMPLE or kPDF_BSP
36/// See TGLOutput::CapturePostscript() for meanings
37/// - 'filePath' - file output name. If null defaults to './viewer.eps' or './viewer.pdf'
38/// depending on format requested
39///
40/// Note : Output files can be large and take considerable time (up to mins)
41/// to generate
42
43Bool_t TGLOutput::Capture(TGLViewer & viewer, EFormat format, const char * filePath)
44{
45 switch(format) {
46 case(kEPS_SIMPLE):
47 case(kEPS_BSP):
48 case(kPDF_SIMPLE):
49 case(kPDF_BSP): {
50 return CapturePostscript(viewer, format, filePath);
51 }
52 }
53
54 assert(kFALSE);
55 return kFALSE;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Capture viewer to postscript file. Arguments are:
60/// - 'viewer' - viewer object to capture from
61/// - 'format' - output format
62/// - kEPS_SIMPLE - lower quality EPS
63/// - kEPS_BSP - higher quality EPS
64/// - kPDF_SIMPLE - lower quality PDF
65/// - kPDF_BSP - higher quality PDF
66/// - 'filePath' - file output name. If null defaults to './viewer.eps' or './viewer.pdf'
67/// depending on format requested
68
70{
71 if (!filePath || !filePath[0]) {
72 if (format == kEPS_SIMPLE || format == kEPS_BSP) {
73 filePath = "viewer.eps";
74 } else if (format == kPDF_SIMPLE || format == kPDF_BSP) {
75 filePath = "viewer.pdf";
76 }
77 }
78 Info("TGLOutput::Postscript()", "Start creating %s.", filePath);
79 std::cout << "Please wait.";
80
81 if (FILE *output = fopen (filePath, "w+b"))
82 {
83 Int_t gl2psFormat;
84 Int_t gl2psSort;
85
86 switch(format) {
87 case kEPS_SIMPLE:
88 gl2psFormat = GL2PS_EPS;
89 gl2psSort = GL2PS_SIMPLE_SORT;
90 break;
91 case kEPS_BSP:
92 gl2psFormat = GL2PS_EPS;
93 gl2psSort = GL2PS_BSP_SORT;
94 break;
95 case kPDF_SIMPLE:
96 gl2psFormat = GL2PS_PDF;
97 gl2psSort = GL2PS_SIMPLE_SORT;
98 break;
99 case kPDF_BSP:
100 gl2psFormat = GL2PS_PDF;
101 gl2psSort = GL2PS_BSP_SORT;
102 break;
103 default:
104 assert(kFALSE);
105 return kFALSE;
106 }
107 Int_t buffsize = 0, state = GL2PS_OVERFLOW;
108 viewer.DoDraw();
109 viewer.fIsPrinting = kTRUE;
110 while (state == GL2PS_OVERFLOW) {
111 buffsize += 1024*1024;
112 gl2psBeginPage ("ROOT Scene Graph", "ROOT", NULL,
113 gl2psFormat, gl2psSort, GL2PS_USE_CURRENT_VIEWPORT
114 | GL2PS_SILENT | GL2PS_BEST_ROOT | GL2PS_OCCLUSION_CULL | 0,
115 GL_RGBA, 0, NULL,0, 0, 0,
116 buffsize, output, NULL);
117 viewer.DoDraw();
118 state = gl2psEndPage();
119 std::cout << ".";
120 }
121 std::cout << std::endl;
122 fclose (output);
123 viewer.fIsPrinting = kFALSE;
124 if (!gSystem->AccessPathName(filePath)) {
125 Info("TGLOutput::Postscript", "Finished creating %s.", filePath);
126 return kTRUE;
127 }
128 } else {
129 Error("TGLOutput::Postscript", "Failed to create %s. ", filePath);
130 }
131
132 return kFALSE;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// this function used by gl-in-pad
137
139{
140 Info("TGLOutput::StartEmbeddedPS", "PS output started ...");
141
142 gVirtualPS->PrintStr("@");
143 gVirtualPS->PrintStr("% Start gl2ps EPS@");
144 gVirtualPS->PrintStr("newpath gsave save@");
145 Double_t xx[2] = {0.}, yy[2] = {0.};
146 xx[0] = gPad->GetUxmin();
147 yy[0] = gPad->GetUymin();
148 xx[1] = gPad->GetUxmax();
149 yy[1] = gPad->GetUymax();
150 gVirtualPS->PrintStr("@");
151
152 GLint vp[4];
153 glGetIntegerv(GL_VIEWPORT,vp);
154 gVirtualPS->DrawPS(0, xx, yy);
155 gVirtualPS->PrintStr(" exch");
156 xx[0] = xx[1];
157 yy[0] = yy[1];
158 gVirtualPS->DrawPS(0, xx, yy);
159 gVirtualPS->PrintStr(" 4 1 roll exch sub 3 1 roll sub");
160 gVirtualPS->WriteInteger(2*4*gPad->GetBorderSize());
161 gVirtualPS->PrintStr(" sub exch");
162 gVirtualPS->WriteInteger(2*4*gPad->GetBorderSize());
163 gVirtualPS->PrintStr(" sub exch");
164 gVirtualPS->WriteInteger((Int_t)(vp[3]));
165 gVirtualPS->WriteInteger((Int_t)(vp[2]));
166 gVirtualPS->PrintStr(" 4 1 roll div 3 1 roll exch div exch scale@");
167 gVirtualPS->PrintStr("@");
168 gVirtualPS->PrintStr("countdictstack@");
169 gVirtualPS->PrintStr("mark@");
170 gVirtualPS->PrintStr("/showpage {} def@");
171
172 // Close the gVirtualPS output stream
173 std::ofstream *fs = (std::ofstream*)gVirtualPS->GetStream();
174 fs->close();
175
176}
177
178////////////////////////////////////////////////////////////////////////////////
179///this function used by gl-in-pad
180/// Restore the gVirtualPS output stream
181
183{
184 std::ofstream *fs = new std::ofstream(gVirtualPS->GetName(),std::ios::app);
186 gVirtualPS->PrintStr("@");
187 gVirtualPS->PrintStr("cleartomark@");
188 gVirtualPS->PrintStr("countdictstack exch sub { end } repeat@");
189 gVirtualPS->PrintStr("restore grestore@");
190 gVirtualPS->PrintStr("% End gl2ps EPS@");
191
192 Info("TGLOutput::CloseEmbeddedPS", "PS output finished");
193}
194
195////////////////////////////////////////////////////////////////////////////////
196///this function used by gl-viewer, embedded into pad
197
199{
201
202 FILE *output = fopen (gVirtualPS->GetName(), "a");
203 if (!output) {
204 //Quite stupid fix, since if fopen fails, CloseEmbeddedPS will also
205 //fail but still I have to do it.
206 Error("TGLOutput::Capture", "can not open file for embedding ps");
208 return;
209 }
210
211 Int_t gl2psFormat = GL2PS_EPS;
212 Int_t gl2psSort = GL2PS_BSP_SORT;
213 Int_t buffsize = 0, state = GL2PS_OVERFLOW;
214 viewer.DoDraw();
215 viewer.fIsPrinting = kTRUE;
216
217 while (state == GL2PS_OVERFLOW) {
218 buffsize += 1024*1024;
219 gl2psBeginPage ("ROOT Scene Graph", "ROOT", NULL,
220 gl2psFormat, gl2psSort, GL2PS_USE_CURRENT_VIEWPORT
221 | GL2PS_SILENT | GL2PS_BEST_ROOT | GL2PS_OCCLUSION_CULL | 0,
222 GL_RGBA, 0, NULL,0, 0, 0,
223 buffsize, output, NULL);
224 viewer.DoDraw();
225 state = gl2psEndPage();
226 std::cout << ".";
227 }
228
229 std::cout << std::endl;
230 fclose (output);
231 viewer.fIsPrinting = kFALSE;
232
234}
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
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:560
R__EXTERN TVirtualPS * gVirtualPS
Definition TVirtualPS.h:81
#define gPad
Wrapper class for GL capture & output routines.
Definition TGLOutput.h:26
static Bool_t Capture(TGLViewer &viewer, EFormat format, const char *filePath=nullptr)
Capture viewer to file.
Definition TGLOutput.cxx:43
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:69
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition TGLViewer.h:55
Bool_t fIsPrinting
debug mode (forced rebuild + draw scene/frustum/interest boxes)
Definition TGLViewer.h:157
void DoDraw(Bool_t swap_buffers=kTRUE)
Draw out the viewer.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
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:1283
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()