source: trunk/source/visualization/OpenInventor/src/SoGL2PSAction.cc @ 930

Last change on this file since 930 was 930, checked in by garnier, 15 years ago

rien de special, juste un backup avant de commiter sur cvs

  • Property svn:mime-type set to text/cpp
File size: 6.1 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26#ifdef G4VIS_BUILD_OI_DRIVER
27
28/*----------------------------HEPVis----------------------------------------*/
29/*                                                                          */
30/* Node:             SoGL2PSAction                                          */
31/* Author:           Guy Barrand                                            */
32/*                                                                          */
33/*--------------------------------------------------------------------------*/
34
35//#define G4DEBUG_VIS_OGL 1
36
37// this :
38#include <HEPVis/actions/SoGL2PSAction.h>
39
40// Inventor :
41#include <Inventor/elements/SoViewportRegionElement.h>
42#include <Inventor/errors/SoDebugError.h>
43
44#include "Geant4_gl2ps.h"
45
46#include <stdio.h>
47
48SO_ACTION_SOURCE(SoGL2PSAction)
49//////////////////////////////////////////////////////////////////////////////
50void SoGL2PSAction::initClass(
51)
52//////////////////////////////////////////////////////////////////////////////
53//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
54{
55#ifdef G4DEBUG_VIS_OGL
56  printf("SoGL2PSAction::initClass\n");
57#endif
58  SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
59}
60//////////////////////////////////////////////////////////////////////////////
61SoGL2PSAction::SoGL2PSAction(
62 const SbViewportRegion& aViewPortRegion
63)
64:SoGLRenderAction(aViewPortRegion)
65,G4OpenGL2PSAction()
66//////////////////////////////////////////////////////////////////////////////
67//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
68{
69#ifdef G4DEBUG_VIS_OGL
70  printf("SoGL2PSAction::SoGL2PSAction\n");
71#endif
72  setFileName("out.ps");
73  SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
74}
75
76bool SoGL2PSAction::enableFileWriting(
77)
78//////////////////////////////////////////////////////////////////////////////
79//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
80{
81  fFile = ::fopen(fFileName,"w");
82  if(!fFile) {
83    SoDebugError::post("SoGL2PSAction::enableFileWriting",
84                       "Cannot open file %s",fFileName);
85    return false;
86  }
87#ifdef __COIN__
88#else //SGI
89  const SbViewportRegion& vpr = getViewportRegion();
90  SoViewportRegionElement::set(getState(),vpr);
91  G4gl2psBegin();
92#endif
93  return true;
94}
95//////////////////////////////////////////////////////////////////////////////
96void SoGL2PSAction::disableFileWriting(
97)
98//////////////////////////////////////////////////////////////////////////////
99//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
100{
101#ifdef __COIN__
102#else //SGI
103  gl2psEndPage();       
104#endif
105  ::fclose(fFile);
106  fFile = 0;
107}
108
109//////////////////////////////////////////////////////////////////////////////
110bool SoGL2PSAction::addBitmap(
111 int aWidth
112,int aHeight
113,float aXorig
114,float aYorig
115,float aXmove
116,float aYmove
117)
118/////////////////////////////////////////////////////////////////////////////
119//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
120{
121#ifdef G4DEBUG_VIS_OGL
122  printf("SoGL2PSAction::addBitmap\n");
123#endif
124  if(!fFile) return false;
125  GLboolean valid;
126  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
127  if(!valid) return false;
128  float pos[4];
129  glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
130  int xoff = -(int)(aXmove + aXorig);
131  int yoff = -(int)(aYmove + aYorig);
132  int x = (int)(pos[0] + xoff);
133  int y = (int)(pos[1] + yoff);
134  // Should clip against viewport area :
135  GLint vp[4];
136  glGetIntegerv(GL_VIEWPORT,vp);
137  GLsizei w = aWidth;
138  GLsizei h = aHeight;
139  if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
140  if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
141  int s = 3 * w * h;
142  if(s<=0) return false;
143  float* image = (float*)::malloc(s * sizeof(float));
144  if(!image) return false;
145  glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
146  GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
147  ::free(image);
148  return (status!=GL2PS_SUCCESS ? false : true);
149}
150//////////////////////////////////////////////////////////////////////////////
151void SoGL2PSAction::beginTraversal(
152 SoNode* aNode
153)
154//////////////////////////////////////////////////////////////////////////////
155//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
156{
157  if(fFile) {
158#ifdef __COIN__
159    const SbViewportRegion& vpr = getViewportRegion();
160    SoViewportRegionElement::set(getState(),vpr);
161    G4gl2psBegin();
162    traverse(aNode);
163    gl2psEndPage();       
164#else //SGI
165    // Should have already do G4gl2psBegin() before
166    SoGLRenderAction::beginTraversal(aNode);
167    // Should do gl2psEndPage() after
168#endif
169  } else {
170    SoGLRenderAction::beginTraversal(aNode);
171  }
172}
173
174
175#endif
Note: See TracBrowser for help on using the repository browser.