ATLAS Offline Software
Loading...
Searching...
No Matches
SoGL2PSAction.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
22SO_ACTION_SOURCE(SoGL2PSAction)
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}
36
38 const SbViewportRegion& aViewPortRegion
39)
40:SoGLRenderAction(aViewPortRegion)
42,m_fileName("out.ps")
43,m_file(0)
47{
48 SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
49
54}
55
57 Format aFileFormat
58)
61{
62 m_fileFormat = aFileFormat;
63}
64
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") {
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 }
138 SbStringDelete(words);
139
140 //::printf("debug : SoGL2PSAction::setPageOptions : %d\n",m_pageOptions);
141
142 return TRUE;
143}
144
146 const char* aFileName
147)
150{
151 m_fileName = aFileName;
152}
153
155)
158{
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}
170
172)
175{
176 ::fclose(m_file);
177 m_file = 0;
178}
179
181) const
184{
185 return (m_file?TRUE:FALSE);
186}
187
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}
224
226 SbBool aDrawBack
227)
230{
231 if(!m_file) return;
232 GLint vp[4];
233 glGetIntegerv(GL_VIEWPORT,vp);
234 if(aDrawBack) {
236 } else {
237 GLint opts = 0;
238 gl2psGetOptions(&opts);
241 gl2psSetOptions(opts);
242 }
243}
244
246)
249{
250 if(!m_file) return;
252}
253
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}
273
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,
298 sort,
300 GL_RGBA,0, NULL,0,0,0,
301 bufsize,
302 m_file,m_fileName.getString());
303
305}
306
310 SoAction* aThis
311,SoNode* aNode
312)
315{
316 SoGL2PSAction* This = static_cast<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}
324
326 SoAction* aThis
327,SoNode* aNode
328)
331{
332 SoNode::GLRenderS(aThis,aNode);
333 SoGL2PSAction* This = static_cast<SoGL2PSAction*>(aThis);
334 if(This->m_file) {
335 SoDrawStyle* soDrawStyle = static_cast<SoDrawStyle*>(aNode);
336 if(soDrawStyle->style.getValue()==SoDrawStyle::LINES) {
337 float w = soDrawStyle->lineWidth.getValue();
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}
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
SbPList SbStringGetWords(const SbString &aString, const char *aLimiter)
SbBool SbStringConvertToBool(const SbString &aString, SbBool &aValue)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void SbStringDelete(SbPList &aList)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
#define SET_OPT(a_opt)
#define y
#define x
Header file for AthHistogramAlgorithm.
SoGL2PSAction inherits Inventor/SoGLRenderAction.
SbString m_fileName
SoGL2PSAction(const SbViewportRegion &)
void setFileFormat(Format)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
Format m_fileFormat
void setFileName(const char *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void endViewport()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void gl2psBegin()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void enableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual void beginTraversal(SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
static void initClass()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void disableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
static void separatorAction(SoAction *, SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SbBool addBitmap(int, int, float=0, float=0, float=0, float=0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
static void drawStyleAction(SoAction *, SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SbBool fileWritingEnabled() const
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void beginViewport(SbBool draw_back=TRUE)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SbBool setPageOptions(const SbString &options)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
GL2PSDLL_API GLint gl2psEndViewport(void)
Definition gl2ps.cxx:5787
GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, GLint yorig, GLenum format, GLenum type, const void *pixels)
Definition gl2ps.cxx:5817
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:5584
GL2PSDLL_API GLint gl2psSetOptions(GLint options)
Definition gl2ps.cxx:6017
GL2PSDLL_API GLint gl2psDisable(GLint mode)
Definition gl2ps.cxx:5957
GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4])
Definition gl2ps.cxx:5778
GL2PSDLL_API GLint gl2psEndPage(void)
Definition gl2ps.cxx:5751
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
Definition gl2ps.cxx:5992
GL2PSDLL_API GLint gl2psGetOptions(GLint *options)
Definition gl2ps.cxx:6026
#define GL2PS_TIGHT_BOUNDING_BOX
Definition gl2ps.h:132
#define GL2PS_NO_BLENDING
Definition gl2ps.h:131
#define GL2PS_BSP_SORT
Definition gl2ps.h:105
#define GL2PS_SIMPLE_LINE_OFFSET
Definition gl2ps.h:121
#define GL2PS_OCCLUSION_CULL
Definition gl2ps.h:124
#define GL2PS_SILENT
Definition gl2ps.h:122
#define GL2PS_LINE_STIPPLE
Definition gl2ps.h:138
#define GL2PS_BEST_ROOT
Definition gl2ps.h:123
#define GL2PS_DRAW_BACKGROUND
Definition gl2ps.h:120
#define GL2PS_SUCCESS
Definition gl2ps.h:109
#define GL2PS_LANDSCAPE
Definition gl2ps.h:126
#define GL2PS_NO_PS3_SHADING
Definition gl2ps.h:127
#define GL2PS_COMPRESS
Definition gl2ps.h:130
#define GL2PS_NO_PIXMAP
Definition gl2ps.h:128
#define GL2PS_USE_CURRENT_VIEWPORT
Definition gl2ps.h:129
#define GL2PS_PDF
Definition gl2ps.h:97
#define GL2PS_NO_TEXT
Definition gl2ps.h:125