Import Geant4 11.1.0.beta source tree
This commit is contained in:
@@ -1292,8 +1292,8 @@ void G4OpenInventorQtExaminerViewer::mouseoverCB(void *aThis, SoEventCallback *e
|
||||
SoGetBoundingBoxAction bAction(viewportRegion);
|
||||
bAction.apply((SoFullPath*)path);
|
||||
SbBox3f bBox = bAction.getBoundingBox();
|
||||
SbVec3f center = bBox.getCenter();
|
||||
center.getValue(x,y,z);
|
||||
SbVec3f centr = bBox.getCenter();
|
||||
centr.getValue(x,y,z);
|
||||
ssZPos << "Pos: " << x << " " << y << " " << z;
|
||||
|
||||
G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
|
||||
|
||||
@@ -189,11 +189,8 @@ G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) {
|
||||
// needs a kernel visit. (In this respect, it differs from the
|
||||
// OpenGL drivers, where it's done in SetView.)
|
||||
(vp.GetScaleFactor () != fVP.GetScaleFactor ()) ||
|
||||
// If G4OpenInventor ever introduces VAMs, the following might need
|
||||
// changing to a complete comparison, i.e., remove ".size()". See
|
||||
// G4OpenGLStoredViewer::CompareForKernelVisit.
|
||||
(vp.GetVisAttributesModifiers() !=
|
||||
fVP.GetVisAttributesModifiers()) ||
|
||||
fVP.GetVisAttributesModifiers()) ||
|
||||
(vp.IsSpecialMeshRendering() !=
|
||||
fVP.IsSpecialMeshRendering())
|
||||
)
|
||||
@@ -525,29 +522,25 @@ void G4OpenInventorViewer::Escape(){
|
||||
void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
|
||||
if(!fGL2PSAction) return;
|
||||
fGL2PSAction->setFileName(aFile.c_str());
|
||||
fGL2PSAction->setExportImageFormat(GL2PS_EPS);
|
||||
// Use gl2ps default buffer (2048*2048)
|
||||
fGL2PSAction->setBufferSize(0);
|
||||
fGL2PSAction->setExportImageFormat_EPS();
|
||||
fGL2PSAction->setTitleAndProducer("Geant4 output","Geant4");
|
||||
G4cout << "Produce " << aFile << "..." << G4endl;
|
||||
if (fGL2PSAction->enableFileWriting()) {
|
||||
ViewerRender();
|
||||
fGL2PSAction->disableFileWriting();
|
||||
}
|
||||
fGL2PSAction->resetBufferSizeParameters();
|
||||
}
|
||||
|
||||
void G4OpenInventorViewer::WritePDF(const G4String& aFile) {
|
||||
if(!fGL2PSAction) return;
|
||||
fGL2PSAction->setFileName(aFile.c_str());
|
||||
fGL2PSAction->setExportImageFormat(GL2PS_PDF);
|
||||
// Use gl2ps default buffer (2048*2048)
|
||||
fGL2PSAction->setBufferSize(0);
|
||||
fGL2PSAction->setExportImageFormat_PDF();
|
||||
fGL2PSAction->setTitleAndProducer("Geant4 output","Geant4");
|
||||
G4cout << "Produce " << aFile << "..." << G4endl;
|
||||
if (fGL2PSAction->enableFileWriting()) {
|
||||
ViewerRender();
|
||||
fGL2PSAction->disableFileWriting();
|
||||
}
|
||||
fGL2PSAction->resetBufferSizeParameters();
|
||||
}
|
||||
|
||||
void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <Inventor/elements/SoViewportRegionElement.h>
|
||||
#include <Inventor/errors/SoDebugError.h>
|
||||
|
||||
#include "Geant4_gl2ps.h"
|
||||
#include <Inventor/system/gl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -60,30 +60,71 @@ SoGL2PSAction::SoGL2PSAction(
|
||||
const SbViewportRegion& aViewPortRegion
|
||||
)
|
||||
:SoGLRenderAction(aViewPortRegion)
|
||||
,G4OpenGL2PSAction()
|
||||
,fContext(0)
|
||||
,fFile(0)
|
||||
,fFileName("out.pdf")
|
||||
,fTitle("title")
|
||||
,fProducer("HEPVis::SoGL2PSAction")
|
||||
,fFormat(TOOLS_GL2PS_PDF)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
setFileName("out.ps");
|
||||
SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
|
||||
}
|
||||
|
||||
bool SoGL2PSAction::enableFileWriting(
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
SoGL2PSAction::~SoGL2PSAction()
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
fFile = ::fopen(fFileName,"w");
|
||||
if(!fFile) {
|
||||
closeFile();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void SoGL2PSAction::setFileName(const std::string& aFileName)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
fFileName = aFileName;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void SoGL2PSAction::setTitleAndProducer(const std::string& aTitle,const std::string& aProducer)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
fTitle = aTitle;
|
||||
fProducer = aProducer;
|
||||
}
|
||||
|
||||
void SoGL2PSAction::setExportImageFormat_PS() {fFormat = TOOLS_GL2PS_PS;}
|
||||
void SoGL2PSAction::setExportImageFormat_EPS() {fFormat = TOOLS_GL2PS_EPS;}
|
||||
void SoGL2PSAction::setExportImageFormat_TEX() {fFormat = TOOLS_GL2PS_TEX;}
|
||||
void SoGL2PSAction::setExportImageFormat_PDF() {fFormat = TOOLS_GL2PS_PDF;}
|
||||
void SoGL2PSAction::setExportImageFormat_SVG() {fFormat = TOOLS_GL2PS_SVG;}
|
||||
void SoGL2PSAction::setExportImageFormat_PGF() {fFormat = TOOLS_GL2PS_PGF;}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool SoGL2PSAction::enableFileWriting()
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(!openFile()) {
|
||||
SoDebugError::post("SoGL2PSAction::enableFileWriting",
|
||||
"Cannot open file %s",fFileName.c_str());
|
||||
"openFile() failed for fil %s",
|
||||
fFileName.c_str());
|
||||
return false;
|
||||
}
|
||||
#ifdef __COIN__
|
||||
#else //SGI
|
||||
const SbViewportRegion& vpr = getViewportRegion();
|
||||
SoViewportRegionElement::set(getState(),vpr);
|
||||
G4gl2psBegin();
|
||||
SbVec2s origin = vpr.getViewportOriginPixels();
|
||||
SbVec2s size = vpr.getViewportSizePixels();
|
||||
if(!beginPage(origin[0],origin[1],size[0],size[1])) {
|
||||
SoDebugError::post("SoGL2PSAction::enableFileWriting","beginPage() failed");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@@ -95,10 +136,146 @@ void SoGL2PSAction::disableFileWriting(
|
||||
{
|
||||
#ifdef __COIN__
|
||||
#else //SGI
|
||||
gl2psEndPage();
|
||||
endPage();
|
||||
#endif
|
||||
::fclose(fFile);
|
||||
fFile = 0;
|
||||
closeFile();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void SoGL2PSAction::beginTraversal(
|
||||
SoNode* aNode
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(fContext && fFile) {
|
||||
#ifdef __COIN__
|
||||
const SbViewportRegion& vpr = getViewportRegion();
|
||||
SoViewportRegionElement::set(getState(),vpr);
|
||||
SbVec2s origin = vpr.getViewportOriginPixels();
|
||||
SbVec2s size = vpr.getViewportSizePixels();
|
||||
if(!beginPage(origin[0],origin[1],size[0],size[1])) {
|
||||
SoDebugError::post("SoGL2PSAction::beginTraversal","beginPage() failed");
|
||||
return;
|
||||
}
|
||||
traverse(aNode);
|
||||
if(!endPage()) {
|
||||
SoDebugError::post("SoGL2PSAction::beginTraversal","endPage() failed");
|
||||
return;
|
||||
}
|
||||
#else //SGI
|
||||
SoGLRenderAction::beginTraversal(aNode);
|
||||
#endif
|
||||
} else {
|
||||
SoGLRenderAction::beginTraversal(aNode);
|
||||
}
|
||||
}
|
||||
|
||||
#include <tools/gl2ps>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool SoGL2PSAction::openFile()
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(fFile) {
|
||||
::fclose(fFile);
|
||||
fFile = 0;
|
||||
}
|
||||
if(fContext) {
|
||||
::tools_gl2psDeleteContext(fContext);
|
||||
fContext = 0;
|
||||
}
|
||||
|
||||
fContext = ::tools_gl2psCreateContext();
|
||||
if(!fContext) return false;
|
||||
|
||||
tools_gl2ps_gl_funcs_t _funcs = {
|
||||
(tools_glIsEnabled_func)glIsEnabled,
|
||||
(tools_glBegin_func)glBegin,
|
||||
(tools_glEnd_func)glEnd,
|
||||
(tools_glGetFloatv_func)glGetFloatv,
|
||||
(tools_glVertex3f_func)glVertex3f,
|
||||
(tools_glGetBooleanv_func)glGetBooleanv,
|
||||
(tools_glGetIntegerv_func)glGetIntegerv,
|
||||
(tools_glRenderMode_func)glRenderMode,
|
||||
(tools_glFeedbackBuffer_func)glFeedbackBuffer,
|
||||
(tools_glPassThrough_func)glPassThrough
|
||||
};
|
||||
::tools_gl2ps_set_gl_funcs(fContext,&_funcs);
|
||||
|
||||
fFile = ::fopen(fFileName.c_str(),"wb");
|
||||
if(!fFile) {
|
||||
::tools_gl2psDeleteContext(fContext);
|
||||
fContext = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void SoGL2PSAction::closeFile()
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(fFile) {
|
||||
::fclose(fFile);
|
||||
fFile = 0;
|
||||
}
|
||||
if(fContext) {
|
||||
::tools_gl2psDeleteContext(fContext);
|
||||
fContext = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool SoGL2PSAction::beginPage(int a_x,int a_y,int a_w,int a_h)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(!fContext) return false;
|
||||
if(!fFile) return false;
|
||||
|
||||
if( (a_w<=0) || (a_h<=0) ) return false;
|
||||
|
||||
int options =
|
||||
TOOLS_GL2PS_BEST_ROOT |
|
||||
TOOLS_GL2PS_DRAW_BACKGROUND |
|
||||
TOOLS_GL2PS_USE_CURRENT_VIEWPORT;
|
||||
int sort = TOOLS_GL2PS_BSP_SORT;
|
||||
|
||||
int vp[4];
|
||||
vp[0] = a_x;
|
||||
vp[1] = a_y;
|
||||
vp[2] = a_w;
|
||||
vp[3] = a_h;
|
||||
|
||||
int bufferSize = 0;
|
||||
|
||||
tools_GLint res = ::tools_gl2psBeginPage
|
||||
(fContext,fTitle.c_str(),fProducer.c_str(),
|
||||
vp,fFormat,sort,options,TOOLS_GL_RGBA,0, NULL,0,0,0,
|
||||
bufferSize,fFile,fFileName.c_str());
|
||||
if (res == TOOLS_GL2PS_ERROR) return false;
|
||||
|
||||
// enable blending for all
|
||||
::tools_gl2psEnable(fContext,TOOLS_GL2PS_BLEND);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool SoGL2PSAction::endPage()
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
int _status = 0;
|
||||
if(fContext) {
|
||||
_status = ::tools_gl2psEndPage(fContext);
|
||||
}
|
||||
if (_status == TOOLS_GL2PS_OVERFLOW) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -113,19 +290,19 @@ bool SoGL2PSAction::addBitmap(
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(!fFile) return false;
|
||||
if(!fContext) return false;
|
||||
GLboolean valid;
|
||||
glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
|
||||
::glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
|
||||
if(!valid) return false;
|
||||
float pos[4];
|
||||
glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
|
||||
::glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
|
||||
int xoff = -(int)(aXmove + aXorig);
|
||||
int yoff = -(int)(aYmove + aYorig);
|
||||
int x = (int)(pos[0] + xoff);
|
||||
int y = (int)(pos[1] + yoff);
|
||||
// Should clip against viewport area :
|
||||
GLint vp[4];
|
||||
glGetIntegerv(GL_VIEWPORT,vp);
|
||||
::glGetIntegerv(GL_VIEWPORT,vp);
|
||||
GLsizei w = aWidth;
|
||||
GLsizei h = aHeight;
|
||||
if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
|
||||
@@ -134,31 +311,9 @@ bool SoGL2PSAction::addBitmap(
|
||||
if(s<=0) return false;
|
||||
float* image = (float*)::malloc(s * sizeof(float));
|
||||
if(!image) return false;
|
||||
glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
|
||||
GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
|
||||
::glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
|
||||
GLint status = ::tools_gl2psDrawPixels(fContext,w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
|
||||
::free(image);
|
||||
return (status!=GL2PS_SUCCESS ? false : true);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void SoGL2PSAction::beginTraversal(
|
||||
SoNode* aNode
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(fFile) {
|
||||
#ifdef __COIN__
|
||||
const SbViewportRegion& vpr = getViewportRegion();
|
||||
SoViewportRegionElement::set(getState(),vpr);
|
||||
G4gl2psBegin();
|
||||
traverse(aNode);
|
||||
gl2psEndPage();
|
||||
#else //SGI
|
||||
// Should have already do G4gl2psBegin() before
|
||||
SoGLRenderAction::beginTraversal(aNode);
|
||||
// Should do gl2psEndPage() after
|
||||
#endif
|
||||
} else {
|
||||
SoGLRenderAction::beginTraversal(aNode);
|
||||
}
|
||||
return (status!=TOOLS_GL2PS_SUCCESS ? false : true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user