ATLAS Offline Software
SoGL2PSAction.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // this :
7 
8 // Inventor :
9 #include <Inventor/nodes/SoDrawStyle.h>
10 #include <Inventor/nodes/SoSeparator.h>
11 #include <Inventor/elements/SoViewportRegionElement.h>
12 #include <Inventor/elements/SoCacheElement.h>
13 #include <Inventor/errors/SoDebugError.h>
14 
15 //LD HEPVis specific #include <HEPVis/SbStyles.h>
16 #include "SbStringHelpers.h"
17 
18 #include "VP1HEPVis/gl2ps.h"
19 
20 #include <stdio.h>
21 
22 SO_ACTION_SOURCE(SoGL2PSAction)
24 void SoGL2PSAction::initClass(
25 )
28 {
29  [[maybe_unused]] static const bool didInit = [&]() {
30  SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
31  SO_ACTION_ADD_METHOD(SoSeparator,separatorAction);
32  SO_ACTION_ADD_METHOD(SoDrawStyle,drawStyleAction);
33  return true;
34  }();
35 }
38  const SbViewportRegion& aViewPortRegion
39 )
40 :SoGLRenderAction(aViewPortRegion)
41 ,m_fileFormat(EPS)
42 ,m_fileName("out.ps")
43 ,m_file(0)
44 ,m_pageOptions(0)
47 {
48  SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
49 
52  GL2PS_SILENT |
54 }
57  Format aFileFormat
58 )
61 {
62  m_fileFormat = aFileFormat;
63 }
66  const SbString& aOptions
67 )
70 {
71  SbPList words = SbStringGetWords(aOptions,";");
72  int wordn = words.getLength();
73  for(int wordi=0;wordi<wordn;wordi++) {
74  SbString& word = *((SbString*)words[wordi]);
75  if(!word.getLength()) continue;
76 
77  SbString option("");
78  SbBool value = FALSE;
79  {SbPList o_v = SbStringGetWords(word,"=");
80  if(o_v.getLength()==2) {
81  option = *((SbString*)o_v[0]);
82  SbString svalue = *((SbString*)o_v[1]);
83  if(SbStringConvertToBool(svalue,value)==FALSE) {
84  SoDebugError::postInfo("SoGL2PSAction::setPageOptions",
85  "value \"%s\" not a bool.\n",svalue.getString());
86  }
87  } else {
88  option = word;
89  value = TRUE;
90  }
91  SbStringDelete(o_v);}
92 
93 #define SET_OPT(a_opt) \
94  if(value==TRUE) {\
95  m_pageOptions |= a_opt;\
96  } else {\
97  m_pageOptions &= ~a_opt;\
98  }
99 
100  if(option=="DEFAULTS") {
103  GL2PS_SILENT |
105  } else if(option=="NONE") {
106  m_pageOptions = 0;
107  } else if(option=="DRAW_BACKGROUND") {
109  } else if(option=="SIMPLE_LINE_OFFSET") {
111  } else if(option=="SILENT") {
113  } else if(option=="BEST_ROOT") {
115  } else if(option=="OCCLUSION_CULL") {
117  } else if(option=="NO_TEXT") {
119  } else if(option=="LANDSCAPE") {
121  } else if(option=="NO_PS3_SHADING") {
123  } else if(option=="NO_PIXMAP") {
125  } else if(option=="USE_CURRENT_VIEWPORT") {
127  } else if(option=="COMPRESS") {
129  } else if(option=="NO_BLENDING") {
131  } else if(option=="TIGHT_BOUNDING_BOX") {
133  } else {
134  SoDebugError::postInfo("SoGL2PSAction::setPageOptions",
135  "bad option \"%s\".\n",option.getString());
136  }
137  }
139 
140  //::printf("debug : SoGL2PSAction::setPageOptions : %d\n",m_pageOptions);
141 
142  return TRUE;
143 }
146  const char* aFileName
147 )
150 {
151  m_fileName = aFileName;
152 }
155 )
158 {
159  if(m_fileFormat==GL2PS_PDF) {
160  m_file = ::fopen(m_fileName.getString(),"wb");
161  } else {
162  m_file = ::fopen(m_fileName.getString(),"w");
163  }
164  if(!m_file) {
165  SoDebugError::post("SoGL2PSAction::enableFileWriting",
166  "Cannot open file %s",m_fileName.getString());
167  return;
168  }
169 }
172 )
175 {
176  ::fclose(m_file);
177  m_file = 0;
178 }
181 ) const
184 {
185  return (m_file?TRUE:FALSE);
186 }
189  int aWidth
190 ,int aHeight
191 ,float aXorig
192 ,float aYorig
193 ,float aXmove
194 ,float aYmove
195 )
198 {
199  if(!m_file) return FALSE;
200  GLboolean valid;
201  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
202  if(valid==GL_FALSE) return FALSE;
203  float pos[4];
204  glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
205  int xoff = -(int)(aXmove + aXorig);
206  int yoff = -(int)(aYmove + aYorig);
207  int x = (int)(pos[0] + xoff);
208  int y = (int)(pos[1] + yoff);
209  // Should clip against viewport area :
210  GLint vp[4];
211  glGetIntegerv(GL_VIEWPORT,vp);
212  GLsizei w = aWidth;
213  GLsizei h = aHeight;
214  if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
215  if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
216  int s = 3 * w * h;
217  if(s<=0) return FALSE;
218  float* image = new float[s];
219  glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
220  GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
221  delete [] image;
222  return (status!=GL2PS_SUCCESS ? FALSE : TRUE);
223 }
226  SbBool aDrawBack
227 )
230 {
231  if(!m_file) return;
232  GLint vp[4];
233  glGetIntegerv(GL_VIEWPORT,vp);
234  if(aDrawBack) {
235  gl2psBeginViewport(vp);
236  } else {
237  GLint opts = 0;
239  gl2psSetOptions(0);
240  gl2psBeginViewport(vp);
242  }
243 }
246 )
249 {
250  if(!m_file) return;
252 }
255  SoNode* aNode
256 )
259 {
260 
261  if(m_file) {
262  const SbViewportRegion& vpr = getViewportRegion();
263  SoViewportRegionElement::set(getState(),vpr);
264 
265  gl2psBegin();
266  traverse(aNode);
268  gl2psEndPage();
269  } else {
270  SoGLRenderAction::beginTraversal(aNode);
271  }
272 }
275 )
278 {
279  if(!m_file) return;
280 
281  int sort = GL2PS_BSP_SORT;
282  //int sort = GL2PS_SIMPLE_SORT;
283 
284  const SbViewportRegion& vpr = getViewportRegion();
285  SoViewportRegionElement::set(getState(),vpr);
286 
287  const SbVec2s& win = vpr.getWindowSize();
288  GLint vp[4];
289  vp[0] = 0;
290  vp[1] = 0;
291  vp[2] = win[0];
292  vp[3] = win[1];
293 
294  int bufsize = 0;
295  gl2psBeginPage("title","HEPVis::SoGL2PSAction",
296  vp,
297  m_fileFormat,
298  sort,
300  GL_RGBA,0, NULL,0,0,0,
301  bufsize,
302  m_file,m_fileName.getString());
303 
304  gl2psBeginViewport(vp);
305 }
310  SoAction* aThis
311 ,SoNode* aNode
312 )
315 {
316  SoGL2PSAction* This = (SoGL2PSAction*)aThis;
317  if(This->m_file) {
318  //SoSeparator may use render caching.
319  aNode->doAction(aThis);
320  } else {
321  SoNode::GLRenderS(aThis,aNode);
322  }
323 }
326  SoAction* aThis
327 ,SoNode* aNode
328 )
331 {
332  SoNode::GLRenderS(aThis,aNode);
333  SoGL2PSAction* This = (SoGL2PSAction*)aThis;
334  if(This->m_file) {
335  SoDrawStyle* soDrawStyle = (SoDrawStyle*)aNode;
336  if(soDrawStyle->style.getValue()==SoDrawStyle::LINES) {
337  float w = soDrawStyle->lineWidth.getValue();
338  gl2psLineWidth(w);
340 
341  /* LD HEPVis specific
342  unsigned short pattern = soDrawStyle->linePattern.getValue();
343  if(pattern==SbLinePattern_solid)
344  gl2psDisable(GL2PS_LINE_STIPPLE);
345  else
346  gl2psEnable(GL2PS_LINE_STIPPLE);
347  */
348  }
349  }
350 }
gl2ps.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
gl2psSetOptions
GL2PSDLL_API GLint gl2psSetOptions(GLint options)
Definition: gl2ps.cxx:6015
python.scripts.cmake_depends.traverse
def traverse(graph, root, reverse=False, maxdepth=None, nodegetter=lambda n:n)
Definition: cmake_depends.py:51
gl2psDrawPixels
GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, GLint yorig, GLenum format, GLenum type, const void *pixels)
Definition: gl2ps.cxx:5815
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
gl2psLineWidth
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
Definition: gl2ps.cxx:5990
GL2PS_SUCCESS
#define GL2PS_SUCCESS
Definition: gl2ps.h:109
GL2PS_LANDSCAPE
#define GL2PS_LANDSCAPE
Definition: gl2ps.h:126
SoGL2PSAction::gl2psBegin
void gl2psBegin()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:274
SoGL2PSAction.h
SoGL2PSAction::SoGL2PSAction
SoGL2PSAction(const SbViewportRegion &)
Definition: SoGL2PSAction.cxx:37
SbStringConvertToBool
SbBool SbStringConvertToBool(const SbString &aString, SbBool &aValue)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbStringHelpers.cxx:133
athena.value
value
Definition: athena.py:124
SoGL2PSAction::addBitmap
SbBool addBitmap(int, int, float=0, float=0, float=0, float=0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:188
SET_OPT
#define SET_OPT(a_opt)
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
x
#define x
LINES
bool LINES
Definition: computils.cxx:40
GL2PS_DRAW_BACKGROUND
#define GL2PS_DRAW_BACKGROUND
Definition: gl2ps.h:120
GL2PS_TIGHT_BOUNDING_BOX
#define GL2PS_TIGHT_BOUNDING_BOX
Definition: gl2ps.h:132
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
SbStringGetWords
SbPList SbStringGetWords(const SbString &aString, const char *aLimiter)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbStringHelpers.cxx:46
SoGL2PSAction::endViewport
void endViewport()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:245
calibdata.valid
list valid
Definition: calibdata.py:45
GL2PS_NO_BLENDING
#define GL2PS_NO_BLENDING
Definition: gl2ps.h:131
SoGL2PSAction::m_fileName
SbString m_fileName
Definition: SoGL2PSAction.h:57
SoGL2PSAction::setPageOptions
SbBool setPageOptions(const SbString &options)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:65
gl2psEndViewport
GL2PSDLL_API GLint gl2psEndViewport(void)
Definition: gl2ps.cxx:5785
extractSporadic.h
list h
Definition: extractSporadic.py:97
GL2PS_COMPRESS
#define GL2PS_COMPRESS
Definition: gl2ps.h:130
SoGL2PSAction::m_pageOptions
int m_pageOptions
Definition: SoGL2PSAction.h:59
GL2PS_SILENT
#define GL2PS_SILENT
Definition: gl2ps.h:122
python.Constants.TRUE
bool TRUE
for job options legacy (TODO: get rid of these!) ----------------------—
Definition: Control/AthenaCommon/python/Constants.py:22
SoGL2PSAction::enableFileWriting
void enableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:154
SoGL2PSAction::disableFileWriting
void disableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:171
GL2PS_LINE_STIPPLE
#define GL2PS_LINE_STIPPLE
Definition: gl2ps.h:138
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
SbStringDelete
void SbStringDelete(SbPList &aList)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SbStringHelpers.cxx:122
GL2PS_BEST_ROOT
#define GL2PS_BEST_ROOT
Definition: gl2ps.h:123
SoGL2PSAction::m_fileFormat
Format m_fileFormat
Definition: SoGL2PSAction.h:56
SoGL2PSAction::fileWritingEnabled
SbBool fileWritingEnabled() const
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:180
GL2PS_NO_PIXMAP
#define GL2PS_NO_PIXMAP
Definition: gl2ps.h:128
MyPlots.image
string image
Definition: MyPlots.py:43
SbStringHelpers.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.Constants.FALSE
bool FALSE
Definition: Control/AthenaCommon/python/Constants.py:23
GL2PS_NO_TEXT
#define GL2PS_NO_TEXT
Definition: gl2ps.h:125
y
#define y
h
SoGL2PSAction
SoGL2PSAction inherits Inventor/SoGLRenderAction.
Definition: SoGL2PSAction.h:17
SoGL2PSAction::m_file
FILE * m_file
Definition: SoGL2PSAction.h:58
GL2PS_BSP_SORT
#define GL2PS_BSP_SORT
Definition: gl2ps.h:105
gl2psBeginViewport
GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4])
Definition: gl2ps.cxx:5776
GL2PS_PDF
#define GL2PS_PDF
Definition: gl2ps.h:97
gl2psGetOptions
GL2PSDLL_API GLint gl2psGetOptions(GLint *options)
Definition: gl2ps.cxx:6024
merge.status
status
Definition: merge.py:17
gl2psBeginPage
GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, GLint nr, GLint ng, GLint nb, GLint buffersize, FILE *stream, const char *filename)
Definition: gl2ps.cxx:5582
GL2PS_USE_CURRENT_VIEWPORT
#define GL2PS_USE_CURRENT_VIEWPORT
Definition: gl2ps.h:129
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
GL2PS_NO_PS3_SHADING
#define GL2PS_NO_PS3_SHADING
Definition: gl2ps.h:127
athena.opts
opts
Definition: athena.py:88
checkFileSG.words
words
Definition: checkFileSG.py:76
SoGL2PSAction::beginTraversal
virtual void beginTraversal(SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:254
SoGL2PSAction::separatorAction
static void separatorAction(SoAction *, SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:309
SoGL2PSAction::Format
Format
Definition: SoGL2PSAction.h:30
GL2PS_OCCLUSION_CULL
#define GL2PS_OCCLUSION_CULL
Definition: gl2ps.h:124
SoGL2PSAction::setFileName
void setFileName(const char *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:145
gl2psDisable
GL2PSDLL_API GLint gl2psDisable(GLint mode)
Definition: gl2ps.cxx:5955
GL2PS_SIMPLE_LINE_OFFSET
#define GL2PS_SIMPLE_LINE_OFFSET
Definition: gl2ps.h:121
SoGL2PSAction::drawStyleAction
static void drawStyleAction(SoAction *, SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:325
SoGL2PSAction::setFileFormat
void setFileFormat(Format)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:56
gl2psEndPage
GL2PSDLL_API GLint gl2psEndPage(void)
Definition: gl2ps.cxx:5749
SoGL2PSAction::beginViewport
void beginViewport(SbBool draw_back=TRUE)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Definition: SoGL2PSAction.cxx:225