26 #ifdef G4VIS_BUILD_OI_DRIVER
36 #include <HEPVis/nodes/SoImageWriter.h>
38 #include <Inventor/errors/SoDebugError.h>
39 #include <Inventor/elements/SoViewportRegionElement.h>
40 #include <Inventor/actions/SoGLRenderAction.h>
42 #include <HEPVis/SbGL.h>
43 #include <HEPVis/SbPainterPS.h>
53 typedef unsigned char Uchar;
58 static int sWidth = 0;
59 static int sHeight = 0;
60 static float* sImage = 0;
61 static int getRGB(
unsigned int,
unsigned int,
double&,
double&,
double&);
63 SO_NODE_SOURCE(SoImageWriter)
65 void SoImageWriter::initClass (
70 SO_NODE_INIT_CLASS(SoImageWriter,SoNode,
"Node");
73 SoImageWriter::SoImageWriter(
80 SO_NODE_CONSTRUCTOR(SoImageWriter);
82 SO_NODE_ADD_FIELD(fileName,(
"out.ps"));
90 SoImageWriter::~SoImageWriter (
97 void SoImageWriter::enable(
105 void SoImageWriter::disable(
113 SbBool SoImageWriter::getStatus(
121 void SoImageWriter::GLRender(
122 SoGLRenderAction* aAction
129 if(!fEnabled)
return;
130 SbViewportRegion vpr = SoViewportRegionElement::get(aAction->getState());
131 const SbVec2s& win = vpr.getWindowSize();
135 SoDebugError::postInfo(
"SoImageWriter::GLRender",
"null area window !");
142 float* image =
new float[
s];
148 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
180 SbPainterPS painterPS;
181 painterPS.openFileForWriting(fileName.getValue().getString());
182 if(!painterPS.getStream()) {
183 SoDebugError::postInfo(
"SoImageWriter::GLRender",
184 "can't open file \"%s\".",fileName.getValue().getString());
186 painterPS.setWindowSize(w,h);
188 painterPS.setBitsPerPixel(4);
189 painterPS.beginTraversal();
190 painterPS.clearColorBuffer(1.,1.,1.);
195 painterPS.putImageInStream((
unsigned int)w,(
unsigned int)h,getRGB);
197 painterPS.endTraversal();
199 painterPS.closeStream();
339 float* pimag = sImage + 3 * (sWidth * (sHeight - 1 - aY) + aX);
340 aRed = *pimag;pimag++;
341 aGreen = *pimag;pimag++;
342 aBlue = *pimag;pimag++;
static constexpr double s