Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
@@ -0,0 +1,111 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateScene.cc,v 2.3 1998/11/06 13:42:25 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// OpenGL immediate scene - draws immediately to buffer
// (saving space on server).
#ifdef G4VIS_BUILD_OPENGL_DRIVER
// Included here - problems with HP compiler if not before other includes?
#include "G4NURBS.hh"
// Here follows a special for Mesa, the OpenGL emulator. Does not affect
// other OpenGL's, as far as I'm aware. John Allison 18/9/96.
#define CENTERLINE_CLPP /* CenterLine C++ workaround: */
// Also seems to be required for HP's CC and AIX xlC, at least.
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLTransform3D.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4Transform3D.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4VisAttributes.hh"
#include "G4OpenGLImmediateScene.hh"
G4OpenGLImmediateScene::G4OpenGLImmediateScene (G4VGraphicsSystem& system,
const G4String& name):
G4OpenGLScene (system, fSceneIdCount++, name)
{
fSceneCount++;
}
G4OpenGLImmediateScene::~G4OpenGLImmediateScene ()
{
fSceneCount--;
}
#include <iomanip.h>
void G4OpenGLImmediateScene::BeginPrimitives
(const G4Transform3D& objectTransformation) {
G4VScene::BeginPrimitives (objectTransformation);
glPushMatrix();
G4OpenGLTransform3D oglt (objectTransformation);
/*************************** Check matrix.
const GLdouble* m = oglt.GetGLMatrix ();
G4cout << "G4OpenGLTransform3D matrix:";
for (int i = 0; i < 16; i++) {
if ((i % 4) == 0) G4cout << '\n';
G4cout << setw (15) << m[i];
}
G4cout << endl;
*****************************************/
glMultMatrixd (oglt.GetGLMatrix ());
}
void G4OpenGLImmediateScene::EndPrimitives () {
glPopMatrix();
if (fReadyForTransients) {
glFlush ();
}
G4VScene::EndPrimitives ();
}
void G4OpenGLImmediateScene::BeginModeling () {
if (fpView -> GetViewParameters ().GetDrawingStyle() == G4ViewParameters::hlr) {
initialize_hlr = true;
}
G4VScene::BeginModeling();
}
void G4OpenGLImmediateScene::EndModeling () {
G4VScene::EndModeling ();
if (fpView -> GetViewParameters ().GetDrawingStyle() == G4ViewParameters::hlr) {
initialize_hlr = true;
// glDisable (GL_POLYGON_OFFSET_FILL);
}
}
G4int G4OpenGLImmediateScene::GetSceneCount () {
return fSceneCount;
}
G4int G4OpenGLImmediateScene::fSceneIdCount = 0;
G4int G4OpenGLImmediateScene::fSceneCount = 0;
#endif
@@ -0,0 +1,35 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateView.cc,v 2.1 1998/07/13 17:11:25 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 7th February 1997
// Class G4OpenGLImmediateView : Encapsulates the `immediateness' of
// an OpenGL view, for inheritance by
// derived (X, Xm...) classes.
#ifdef G4VIS_BUILD_OPENGL_DRIVER
#include "G4OpenGLImmediateView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
G4OpenGLImmediateView::G4OpenGLImmediateView (G4OpenGLImmediateScene& scene):
G4VView (scene, -1),
G4OpenGLView (scene),
fScene (scene)
{}
#endif
@@ -0,0 +1,60 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateWin32.cc,v 2.1 1998/07/13 17:11:26 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// OpenGLImmediateWin32 graphics system factory.
#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4VisFeaturesOfOpenGL.hh"
#include "G4VScene.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLImmediateWin32.hh"
#include "G4OpenGLImmediateWin32View.hh"
G4OpenGLImmediateWin32::G4OpenGLImmediateWin32 ():
G4VGraphicsSystem ("OpenGLImmediateWin32",
"OGLIWin32",
G4VisFeaturesOfOpenGLIWin32 (),
G4VGraphicsSystem::threeD) {}
G4VScene* G4OpenGLImmediateWin32::CreateScene () {
G4VScene* pScene = new G4OpenGLImmediateScene (*this);
G4cout << G4OpenGLImmediateScene::GetSceneCount ()
<< ' ' << fName << " scenes extanct." << endl;
return pScene;
}
G4VView* G4OpenGLImmediateWin32::CreateView (G4VScene& scene) {
G4VView* pView =
new G4OpenGLImmediateWin32View ((G4OpenGLImmediateScene&) scene);
if (pView) {
if (pView -> GetViewId () < 0) {
G4cerr << "G4OpenGLImmediateWin32::CreateView: error flagged by negative"
" view id in G4OpenGLImmediateWin32View creation."
"\n Destroying view and returning null pointer."
<< endl;
delete pView;
pView = 0;
}
}
else {
G4cerr << "G4OpenGLImmediateWin32::CreateView: null pointer on"
" new G4OpenGLImmediateWin32View." << endl;
}
return pView;
}
#endif
@@ -0,0 +1,98 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateWin32View.cc,v 2.2 1998/08/04 14:17:16 ajw Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Class G4OpenGLImmediateWin32View : a class derived from G4OpenGLWin32View and
// G4OpenGLImmediateView.
#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
#include "G4OpenGLImmediateWin32View.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
G4OpenGLImmediateWin32View::G4OpenGLImmediateWin32View (G4OpenGLImmediateScene& scene):
G4OpenGLView (scene),
G4OpenGLWin32View (scene),
G4OpenGLImmediateView (scene),
G4VView (scene, scene.IncrementViewCount ()) {
if (fViewId < 0) return; // In case error in base class instantiation.
// ensure a suitable window was found
CreateGLWin32Context ();
CreateMainWindow ();
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
if (doublebuffer) {
doublebuffer = false;
glDrawBuffer (GL_FRONT);
}
// clear the buffers and window.
ClearView ();
FinishView ();
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
}
void G4OpenGLImmediateWin32View::DrawView () {
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
if (doublebuffer) {
doublebuffer = false;
glDrawBuffer (GL_FRONT);
}
if (white_background == true) {
glClearColor (1., 1., 1., 1.);
} else {
glClearColor (0., 0., 0., 1.);
}
glClearDepth (1.0);
G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
//Make sure current viewer is attached and clean...
//Win32 version needed
//glXMakeCurrent (dpy, win, cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
if(style!=G4ViewParameters::hlr &&
haloing_enabled) {
HaloingFirstPass ();
NeedKernelVisit ();
ProcessView ();
glFlush ();
HaloingSecondPass ();
}
NeedKernelVisit (); // Always need to visit G4 kernel.
ProcessView ();
FinishView ();
}
#endif
@@ -0,0 +1,62 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateX.cc,v 2.2 1998/11/06 13:42:26 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 27th March 1996
// OpenGL graphics system factory.
#ifdef G4VIS_BUILD_OPENGLX_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4VisFeaturesOfOpenGL.hh"
#include "G4VScene.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLImmediateX.hh"
#include "G4OpenGLImmediateXView.hh"
G4OpenGLImmediateX::G4OpenGLImmediateX ():
G4VGraphicsSystem ("OpenGLImmediateX",
"OGLIX",
G4VisFeaturesOfOpenGLIX (),
G4VGraphicsSystem::threeD) {}
G4VScene* G4OpenGLImmediateX::CreateScene (const G4String& name) {
G4VScene* pScene = new G4OpenGLImmediateScene (*this, name);
G4cout << G4OpenGLImmediateScene::GetSceneCount ()
<< ' ' << fName << " scenes extanct." << endl;
return pScene;
}
G4VView* G4OpenGLImmediateX::CreateView (G4VScene& scene,
const G4String& name) {
G4VView* pView =
new G4OpenGLImmediateXView ((G4OpenGLImmediateScene&) scene, name);
if (pView) {
if (pView -> GetViewId () < 0) {
G4cerr << "G4OpenGLImmediateX::CreateView: error flagged by negative"
" view id in G4OpenGLImmediateXView creation."
"\n Destroying view and returning null pointer."
<< endl;
delete pView;
pView = 0;
}
}
else {
G4cerr << "G4OpenGLImmediateX::CreateView: null pointer on"
" new G4OpenGLImmediateXView." << endl;
}
return pView;
}
#endif
@@ -0,0 +1,111 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateXView.cc,v 2.3 1998/11/06 13:42:27 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 7th February 1997
// Class G4OpenGLImmediateXView : a class derived from G4OpenGLXView and
// G4OpenGLImmediateView.
#ifdef G4VIS_BUILD_OPENGLX_DRIVER
#include "G4OpenGLImmediateXView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
G4OpenGLImmediateXView::G4OpenGLImmediateXView (G4OpenGLImmediateScene& scene,
const G4String& name):
G4OpenGLView (scene),
G4OpenGLXView (scene),
G4OpenGLImmediateView (scene),
G4VView (scene, scene.IncrementViewCount (), name) {
if (fViewId < 0) return; // In case error in base class instantiation.
// ensure a suitable window was found
if (!vi_immediate) {
G4cerr << "G4OpenGLImmediateXView::G4OpenGLImmediateXView -"
" G4OpenGLXView couldn't get a visual." << endl;
fViewId = -1; // This flags an error.
return;
}
CreateGLXContext (vi_immediate);
InitializeGLView ();
CreateMainWindow ();
// clear the buffers and window.
ClearView ();
FinishView ();
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
if (doublebuffer) {
doublebuffer = false;
glDrawBuffer (GL_FRONT);
}
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
}
void G4OpenGLImmediateXView::DrawView () {
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
if (doublebuffer) {
doublebuffer = false;
glDrawBuffer (GL_FRONT);
}
if (white_background == true) {
glClearColor (1., 1., 1., 1.);
} else {
glClearColor (0., 0., 0., 1.);
}
glClearDepth (1.0);
G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
//Make sure current viewer is attached and clean...
glXMakeCurrent (dpy, win, cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
if(style!=G4ViewParameters::hlr &&
haloing_enabled) {
HaloingFirstPass ();
NeedKernelVisit ();
ProcessView ();
glFlush ();
HaloingSecondPass ();
}
NeedKernelVisit (); // Always need to visit G4 kernel.
ProcessView ();
FinishView ();
}
#endif
@@ -0,0 +1,61 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateXm.cc,v 2.2 1998/11/06 13:42:28 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// OpenGL graphics system factory.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4VisFeaturesOfOpenGL.hh"
#include "G4VScene.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLImmediateXm.hh"
#include "G4OpenGLImmediateXmView.hh"
G4OpenGLImmediateXm::G4OpenGLImmediateXm ():
G4VGraphicsSystem ("OpenGLImmediateXm",
"OGLIXm",
G4VisFeaturesOfOpenGLIXm (),
G4VGraphicsSystem::threeD) {}
G4VScene* G4OpenGLImmediateXm::CreateScene (const G4String& name) {
G4VScene* pScene = new G4OpenGLImmediateScene (*this, name);
G4cout << G4OpenGLImmediateScene::GetSceneCount ()
<< ' ' << fName << " scenes extanct." << endl;
return pScene;
}
G4VView* G4OpenGLImmediateXm::CreateView (G4VScene& scene,
const G4String& name) {
G4VView* pView =
new G4OpenGLImmediateXmView ((G4OpenGLImmediateScene&) scene, name);
if (pView) {
if (pView -> GetViewId () < 0) {
G4cerr << "G4OpenGLImmediateXm::CreateView: error flagged by"
" negative view id in G4OpenGLImmediateXmView creation."
"\n Destroying view and returning null pointer." << endl;
delete pView;
pView = 0;
}
}
else {
G4cerr << "G4OpenGLImmediateXm::CreateView: null pointer on"
" new G4OpenGLImmediateXmView." << endl;
}
return pView;
}
#endif
@@ -0,0 +1,123 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLImmediateXmView.cc,v 2.3 1998/11/06 13:42:29 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// Class G4OpenGLImmediateXmView : a class derived from G4OpenGLXmView
// and G4OpenGLImmediateView.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLImmediateXmView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
G4OpenGLImmediateXmView::G4OpenGLImmediateXmView
(G4OpenGLImmediateScene& scene,
const G4String& name):
G4OpenGLView (scene),
G4OpenGLXmView (scene),
G4OpenGLImmediateView (scene),
G4VView (scene, scene.IncrementViewCount (), name) {
if (fViewId < 0) return; // In case error in base class instantiation.
// ensure a suitable window was found
if (!vi_immediate) {
G4cerr << "G4OpenGLImmediateXmView::G4OpenGLImmediateXmView -"
" G4OpenGLXmView couldn't get a visual." << endl;
fViewId = -1; // This flags an error.
return;
}
CreateGLXContext (vi_immediate);
InitializeGLView ();
CreateMainWindow ();
// clear the buffers and window.
ClearView ();
FinishView ();
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glLineWidth (1.0);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel (GL_FLAT);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//The following code is useless in its current position, as the
//G4OpenGLXmView constructor gets called *after* it, and hence sets
//doublebuffer to true or false there, after our little test to correct
//it in the case of a double buffer being got for an immediate view.
//Hence, code moved to DrawView.
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
// if (doublebuffer) {
// doublebuffer = false;
// glDrawBuffer (GL_FRONT);
// }
}
void G4OpenGLImmediateXmView::DrawView () {
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
if (doublebuffer) {
doublebuffer = false;
glDrawBuffer (GL_FRONT);
}
if (white_background == true) {
glClearColor (1., 1., 1., 1.);
} else {
glClearColor (0., 0., 0., 1.);
}
glClearDepth (1.0);
G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
//Make sure current viewer is attached and clean...
glXMakeCurrent (dpy, win, cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
if(style!=G4ViewParameters::hlr &&
haloing_enabled) {
HaloingFirstPass ();
NeedKernelVisit ();
ProcessView ();
glFlush ();
HaloingSecondPass ();
}
NeedKernelVisit (); // Always need to visit G4 kernel.
ProcessView ();
FinishView ();
}
#endif
@@ -0,0 +1,559 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLScene.cc,v 2.8 1998/11/06 13:42:32 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 27th March 1996
// OpenGL stored scene - creates OpenGL display lists.
// OpenGL immediate scene - draws immediately to buffer
// (saving space on server).
#ifdef G4VIS_BUILD_OPENGL_DRIVER
// Included here - problems with HP compiler if not before other includes?
#include "G4NURBS.hh"
// Here follows a special for Mesa, the OpenGL emulator. Does not affect
// other OpenGL's, as far as I'm aware. John Allison 18/9/96.
#define CENTERLINE_CLPP /* CenterLine C++ workaround: */
// Also seems to be required for HP's CC and AIX xlC, at least.
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLTransform3D.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4Transform3D.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4VMarker.hh"
#include "G4Polyhedron.hh"
#include "G4VisAttributes.hh"
G4OpenGLScene::G4OpenGLScene (G4VGraphicsSystem& system,
G4int id,
const G4String& name):
G4VScene (system, id, name)
{
initialize_hlr = true;
// glPolygonOffset (1.0, 2);
}
G4OpenGLScene::~G4OpenGLScene ()
{
ClearStore ();
}
//Method for handling G4Polyline objects (from tracking or wireframe).
void G4OpenGLScene::AddPrimitive (const G4Polyline& line)
{
const G4Colour& c = GetColour (line);
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
if (fpView -> GetViewParameters ().IsMarkerNotHidden ())
glDisable (GL_DEPTH_TEST);
else glEnable (GL_DEPTH_TEST);
glDisable (GL_LIGHTING);
glBegin (GL_LINE_STRIP);
G4int nPoints = line.entries ();
for (G4int iPoint = 0; iPoint < nPoints; iPoint++) {
G4double x, y, z;
x = line(iPoint).x();
y = line(iPoint).y();
z = line(iPoint).z();
glVertex3d (x, y, z);
}
glEnd ();
}
void G4OpenGLScene::AddPrimitive (const G4Text& text) {
MarkerSizeType sizeType;
G4double size = GetMarkerSize (text, sizeType);
G4cerr
<< "G4OpenGLScene::AddPrimitive (const G4Text& text) not implemented yet."
<< "\n Called with text " << text.GetText ()
<< " at " << text.GetPosition ()
<< ", size " << size
<< ", offsets " << text.GetXOffset () << ", " << text.GetYOffset ()
<< ", type " << sizeType
<< endl;
}
void G4OpenGLScene::AddPrimitive (const G4Circle& circle) {
const G4Colour& c = GetColour (circle);
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
if (fpView -> GetViewParameters ().IsMarkerNotHidden ())
glDisable (GL_DEPTH_TEST);
else glEnable (GL_DEPTH_TEST);
glDisable (GL_LIGHTING);
G4VMarker::FillStyle style = circle.GetFillStyle();
switch (style) {
case G4VMarker::noFill:
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
break;
case G4VMarker::hashed:
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glLineStipple (1, 0x0101);
break;
case G4VMarker::filled:
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
break;
default:
G4cerr << "Unrecognised fill style for G4Circle in G4OpenGLScene."
<< "\nUsing G4VMarker::filled." << endl;
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
break;
}
G4Point3D centre = circle.GetPosition();
G4bool userSpecified = (circle.GetWorldSize() || circle.GetScreenSize());
const G4VMarker& def = fpView -> GetViewParameters().GetDefaultMarker();
//Make sure we Draw circles...
glEnable (GL_POINT_SMOOTH);
G4double size;
G4double scale = fpView -> GetViewParameters().GetGlobalMarkerScale();
if (size = scale * // Assignment intentional.
userSpecified ? circle.GetWorldSize() : def.GetWorldSize()) {
// Draw in world coordinates...
GLdouble winx, winy, winz;
GLdouble* model_matrix = new GLdouble[16];
GLdouble* proj_matrix = new GLdouble[16];
GLint* v_port = new GLint[4];
// glPointSize (5.0); //Still have to work out correspondance between
// //world and screen units.
glGetDoublev (GL_MODELVIEW_MATRIX, model_matrix);
glGetDoublev (GL_PROJECTION_MATRIX, proj_matrix);
glGetIntegerv (GL_VIEWPORT, v_port);
gluProject (size, size, size,
model_matrix,
proj_matrix,
v_port,
&winx, &winy, &winz);
glPointSize (winx);
glBegin (GL_POINTS);
glVertex3d (centre.x(), centre.y(), centre.z());
glEnd ();
delete[] model_matrix;
delete[] proj_matrix;
delete[] v_port;
}
else {
size = scale *
userSpecified ? circle.GetScreenSize() : def.GetScreenSize();
// Draw in screen coordinates...
// G4double* projection_matrix = new G4double[16];
// glGetDoublev (GL_MODELVIEW_MATRIX, projection_matrix);
// HepMatrix proj(4, 4, 1);
// for (col = 1; col < 5; col++) {
// for (row = 1; row < 5; row++) {
// proj (row, col) = projection_matrix[(col-1)*4 + (row-1)];
// }
// }
// G4cout << "proj is : \n" << proj << endl;
// proj.invert(ierr);
// G4cout << "ierr is " << ierr << endl;
// G4cout << "proj^-1 is : \n" << proj << endl;
// for (col = 1; col < 5; col++) {
// for (row = 1; row < 5; row++) {
// projection_matrix[(col-1)*4 + (row-1)] = proj (row, col);
// }
// }
// glMultMatrixd (projection_matrix);
// glTranslated (centre.x(), centre.y(), centre.z());
// glBegin (GL_LINE_LOOP);
glPointSize (size);
glBegin (GL_POINTS);
// for (G4int segment = 0; segment < num_sides; segment++) {
// theta = d_theta * segment;
// glVertex3d (sin(theta) * size,
// cos(theta) * size,
// 0.);
// }
glVertex3d (centre.x(), centre.y(), centre.z());
glEnd ();
}
}
void G4OpenGLScene::AddPrimitive (const G4Square& Square) {
const G4Colour& c = GetColour (Square);
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
if (fpView -> GetViewParameters ().IsMarkerNotHidden ())
glDisable (GL_DEPTH_TEST);
else glEnable (GL_DEPTH_TEST);
glDisable (GL_LIGHTING);
G4VMarker::FillStyle style = Square.GetFillStyle();
switch (style) {
case G4VMarker::noFill:
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
break;
case G4VMarker::hashed:
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glLineStipple (1, 0x0101);
break;
case G4VMarker::filled:
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
break;
default:
G4cerr << "Unrecognised fill style for G4Square in G4OpenGLScene."
<< "\nUsing G4VMarker::filled." << endl;
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
break;
}
G4Point3D centre = Square.GetPosition();
// glTranslated (centre.x(), centre.y(), centre.z());
// G4double a = Square.GetWorldSize ();
// if (a <= 0.0) {
// a = 1000.0;
// }
// glBegin (GL_LINE_LOOP);
// glVertex3d ( a, a, 0.);
// glVertex3d (-a, a, 0.);
// glVertex3d (-a, -a, 0.);
// glVertex3d ( a, -a, 0.);
//Make sure we Draw squares...
glDisable (GL_POINT_SMOOTH);
G4bool userSpecified = (Square.GetWorldSize() || Square.GetScreenSize());
const G4VMarker& def = fpView -> GetViewParameters().GetDefaultMarker();
G4double size;
G4double scale = fpView -> GetViewParameters().GetGlobalMarkerScale();
if (size = scale * // Assignment intentional.
userSpecified ? Square.GetWorldSize() : def.GetWorldSize()) {
//Draw in world coordinates...
GLdouble winx, winy, winz;
GLdouble* model_matrix = new GLdouble[16];
GLdouble* proj_matrix = new GLdouble[16];
GLint* v_port = new GLint[4];
// glPointSize (5.0); //Still have to work out correspondance between
// //world and screen units.
glGetDoublev (GL_MODELVIEW_MATRIX, model_matrix);
glGetDoublev (GL_PROJECTION_MATRIX, proj_matrix);
glGetIntegerv (GL_VIEWPORT, v_port);
gluProject (size, size, size,
model_matrix,
proj_matrix,
v_port,
&winx, &winy, &winz);
glPointSize (winx);
// glPointSize (5.0); //Still have to work out correspondance between
// //world units and screen units...
glBegin (GL_POINTS);
glVertex3d (centre.x(), centre.y(), centre.z());
glEnd ();
delete[] model_matrix;
delete[] proj_matrix;
delete[] v_port;
}
else {
size = scale *
userSpecified ? Square.GetScreenSize() : def.GetScreenSize();
// Draw in screen coordinates...
glPointSize (size);
glBegin (GL_POINTS);
glVertex3d (centre.x(), centre.y(), centre.z());
glEnd ();
}
}
//Method for handling G4Polyhedron objects for drawing solids.
void G4OpenGLScene::AddPrimitive (const G4Polyhedron& polyhedron) {
//Assume all facets are convex quadrilaterals.
//Draw each G4Facet individually
G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (polyhedron);
//Get colour, etc..
const G4Colour& c = GetColour (polyhedron);
switch (drawing_style) {
// case (G4ViewParameters::hlhsr):
// cout << "Hidden edge not implememented in G4OpenGL.\n"
// << "Using hidden surface removal." << endl;
case (G4ViewParameters::hsr):
{
glPolygonMode (GL_FRONT, GL_FILL);
glCullFace (GL_BACK);
glEnable (GL_CULL_FACE);
glEnable (GL_LIGHTING);
glEnable (GL_DEPTH_TEST);
GLfloat materialColour [4];
materialColour [0] = c.GetRed ();
materialColour [1] = c.GetGreen ();
materialColour [2] = c.GetBlue ();
materialColour [3] = 1.0;
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
break;
}
case (G4ViewParameters::hlr):
if (initialize_hlr) {
glEnable (GL_STENCIL_TEST);
glClear (GL_STENCIL_BUFFER_BIT);
glStencilFunc (GL_ALWAYS, 0, 1);
glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
glGetDoublev (GL_COLOR_CLEAR_VALUE, clear_colour);
initialize_hlr = false;
// glEnable (GL_POLYGON_OFFSET_FILL);
}
glDepthFunc (GL_LESS);
//drop through to wireframe for first pass...
case (G4ViewParameters::wireframe):
default:
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glDisable (GL_CULL_FACE);
glDisable (GL_LIGHTING);
glEnable (GL_DEPTH_TEST);
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
break;
}
glBegin (GL_QUADS);
//Loop through all the facets...
G4bool notLastFace;
G4Normal3D SurfaceUnitNormal;
do {
//First, find surface normal for the facet...
notLastFace = polyhedron.GetNextUnitNormal (SurfaceUnitNormal);
glNormal3d(SurfaceUnitNormal.x(), SurfaceUnitNormal.y(),
SurfaceUnitNormal.z());
//Loop through the four edges of each G4Facet...
G4bool notLastEdge;
G4Point3D vertex[4];
G4int edgeFlag[4], lastEdgeFlag (true);
edgeFlag[0] = G4int (true);
G4int edgeCount = 0;
glEdgeFlag (GL_TRUE);
do {
notLastEdge = polyhedron.GetNextVertex (vertex[edgeCount],
edgeFlag[edgeCount]);
// Check to see if edge is visible or not...
if (edgeFlag[edgeCount] != lastEdgeFlag) {
lastEdgeFlag = edgeFlag[edgeCount];
if (edgeFlag[edgeCount]) {
glEdgeFlag (GL_TRUE);
} else {
glEdgeFlag (GL_FALSE);
}
}
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
edgeCount++;
} while (notLastEdge);
while (edgeCount++ < 4) { // duplicate last real vertex.
vertex[edgeCount] = vertex[edgeCount-1];
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
}
//do it all over again for hlr 2nd pass...
if (drawing_style == G4ViewParameters::hlr) {
glEnd();
//glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, clear_colour);
glStencilFunc (GL_EQUAL, 0, 1);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
glPolygonMode (GL_FRONT, GL_FILL);
glColor4dv (clear_colour);
edgeCount=0;
glBegin (GL_QUADS);
do {
if (edgeFlag[edgeCount] != lastEdgeFlag) {
lastEdgeFlag = edgeFlag[edgeCount];
if (edgeFlag[edgeCount]) {
glEdgeFlag (GL_TRUE);
} else {
glEdgeFlag (GL_FALSE);
}
}
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
} while (++edgeCount < 4);
glEnd();
//and once more to reset the stencil bits...
glStencilFunc (GL_ALWAYS, 0, 1);
glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
edgeCount=0;
glBegin(GL_QUADS);
do {
if (edgeFlag[edgeCount] != lastEdgeFlag) {
lastEdgeFlag = edgeFlag[edgeCount];
if (edgeFlag[edgeCount]) {
glEdgeFlag (GL_TRUE);
} else {
glEdgeFlag (GL_FALSE);
}
}
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
} while (++edgeCount < 4);
}
} while (notLastFace);
glEnd ();
}
//Method for handling G4NURBS objects for drawing solids.
//Knots and Ctrl Pnts MUST be arrays of GLfloats.
void G4OpenGLScene::AddPrimitive (const G4NURBS& nurb) {
GLUnurbsObj *gl_nurb;
gl_nurb = gluNewNurbsRenderer ();
GLfloat *u_knot_array, *u_knot_array_ptr;
u_knot_array = u_knot_array_ptr = new GLfloat [nurb.GetnbrKnots(G4NURBS::U)];
G4NURBS::KnotsIterator u_iterator (nurb, G4NURBS::U);
while (u_iterator.pick (u_knot_array_ptr++));
GLfloat *v_knot_array, *v_knot_array_ptr;
v_knot_array = v_knot_array_ptr = new GLfloat [nurb.GetnbrKnots(G4NURBS::V)];
G4NURBS::KnotsIterator v_iterator (nurb, G4NURBS::V);
while (v_iterator.pick (v_knot_array_ptr++));
GLfloat *ctrl_pnt_array, *ctrl_pnt_array_ptr;
ctrl_pnt_array = ctrl_pnt_array_ptr =
new GLfloat [nurb.GettotalnbrCtrlPts () * G4NURBS::NofC];
G4NURBS::CtrlPtsCoordsIterator c_p_iterator (nurb);
while (c_p_iterator.pick (ctrl_pnt_array_ptr++));
const G4Colour& c = GetColour (nurb);
switch (GetDrawingStyle(nurb)) {
case (G4ViewParameters::hlhsr):
// G4cout << "Hidden line removal not implememented in G4OpenGL.\n"
// << "Using hidden surface removal." << endl;
case (G4ViewParameters::hsr):
{
glEnable (GL_LIGHTING);
glEnable (GL_DEPTH_TEST);
glEnable (GL_AUTO_NORMAL);
glEnable (GL_NORMALIZE);
gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_FILL);
gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
GLfloat materialColour [4];
materialColour [0] = c.GetRed ();
materialColour [1] = c.GetGreen ();
materialColour [2] = c.GetBlue ();
materialColour [3] = 1.0;
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
break;
}
case (G4ViewParameters::hlr):
// G4cout << "Hidden line removal not implememented in G4OpenGL.\n"
// << "Using wireframe." << endl;
case (G4ViewParameters::wireframe):
default:
glDisable (GL_LIGHTING);
// glDisable (GL_DEPTH_TEST);
glEnable (GL_DEPTH_TEST);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_NORMALIZE);
gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
break;
}
gluBeginSurface (gl_nurb);
G4int u_stride = 4;
G4int v_stride = nurb.GetnbrCtrlPts(G4NURBS::U) * 4;
gluNurbsSurface (gl_nurb,
nurb.GetnbrKnots (G4NURBS::U), (GLfloat*)u_knot_array,
nurb.GetnbrKnots (G4NURBS::V), (GLfloat*)v_knot_array,
u_stride,
v_stride,
ctrl_pnt_array,
nurb.GetUorder (),
nurb.GetVorder (),
GL_MAP2_VERTEX_4);
gluEndSurface (gl_nurb);
delete [] u_knot_array; // These should be allocated with smart allocators
delete [] v_knot_array; // to avoid memory explosion.
delete [] ctrl_pnt_array;
gluDeleteNurbsRenderer (gl_nurb);
}
#endif
@@ -0,0 +1,208 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredScene.cc,v 2.4 1998/11/06 13:42:33 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// OpenGL stored scene - creates OpenGL display lists.
#ifdef G4VIS_BUILD_OPENGL_DRIVER
// Included here - problems with HP compiler if not before other includes?
#include "G4NURBS.hh"
// Here follows a special for Mesa, the OpenGL emulator. Does not affect
// other OpenGL's, as far as I'm aware. John Allison 18/9/96.
#define CENTERLINE_CLPP /* CenterLine C++ workaround: */
// Also seems to be required for HP's CC and AIX xlC, at least.
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLTransform3D.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4Transform3D.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4VisAttributes.hh"
#include "G4VPhysicalVolume.hh"
#include "G4ModelingParameters.hh"
#include "G4OpenGLStoredScene.hh"
inline static unsigned pSolidHashFun
(const G4OpenGLStoredScene::G4VSolidPointer& pSolid) {
return (unsigned)pSolid;
}
G4OpenGLStoredScene::G4OpenGLStoredScene (G4VGraphicsSystem& system,
const G4String& name):
G4OpenGLScene (system, fSceneIdCount++, name),
fMemoryForDisplayLists (true),
fTopPODL (0),
fSolidDictionary (pSolidHashFun)
{
fSceneCount++;
}
G4OpenGLStoredScene::~G4OpenGLStoredScene ()
{
fSceneCount--;
}
void G4OpenGLStoredScene::BeginPrimitives
(const G4Transform3D& objectTransformation) {
G4VScene::BeginPrimitives (objectTransformation);
if (fMemoryForDisplayLists) {
if (!(fDisplayListId = glGenLists (1))) { // Could pre-allocate?
G4cout << "********************* WARNING! ********************\n"
<<"Unable to allocate any more display lists in OpenGL.\n "
<< " Continuing drawing in IMMEDIATE MODE.\n"
<< "***************************************************" << endl;
fMemoryForDisplayLists = false;
}
}
if (fMemoryForDisplayLists) {
if (fReadyForTransients) {
fTODLList.append (fDisplayListId);
fTODLTransformList.append (objectTransformation);
glDrawBuffer (GL_FRONT);
glPushMatrix();
G4OpenGLTransform3D oglt (objectTransformation);
glMultMatrixd (oglt.GetGLMatrix ());
glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
}
else {
fPODLList.append (fDisplayListId);
fPODLTransformList.append (objectTransformation);
glNewList (fDisplayListId, GL_COMPILE);
}
} else {
glDrawBuffer (GL_FRONT);
glPushMatrix();
G4OpenGLTransform3D oglt (objectTransformation);
glMultMatrixd (oglt.GetGLMatrix ());
}
}
void G4OpenGLStoredScene::EndPrimitives () {
if (fMemoryForDisplayLists) {
glEndList();
}
if (fReadyForTransients || !fMemoryForDisplayLists) {
glPopMatrix();
glFlush ();
glDrawBuffer (GL_BACK);
}
G4VScene::EndPrimitives ();
}
void G4OpenGLStoredScene::ClearStore () {
int i;
// Delete OpenGL display lists.
for (i = 0; i < fPODLList.entries (); i++) {
if (fPODLList (i)) {
glDeleteLists (fPODLList (i), 1);
} else {
G4cerr << "Warning : NULL display List in fPODLList." << endl;
}
}
for (i = 0; i < fTODLList.entries (); i++) {
if (fTODLList (i)) {
glDeleteLists (fTODLList (i), 1);
} else {
G4cerr << "Warning : NULL display List in fTODLList." << endl;
}
}
if (fTopPODL) glDeleteLists (fTopPODL, 1);
fTopPODL = 0;
fMemoryForDisplayLists = glIsList (fTopPODL = glGenLists (1));
// Clear other lists, dictionary, etc.
fPODLList.clear ();
fTODLList.clear ();
fPODLTransformList.clear ();
fTODLTransformList.clear ();
fSolidDictionary.clear ();
}
void G4OpenGLStoredScene::BeginModeling () {
if (fpView -> GetViewParameters ().GetDrawingStyle() == G4ViewParameters::hlr) {
initialize_hlr = true;
}
G4VScene::BeginModeling();
}
void G4OpenGLStoredScene::EndModeling () {
// Make a List which calls the other lists.
// if (!(fTopPODL = glGenLists (1))) {
// G4Exception ("Unable to allocate display List for fTopPODL in G4OpenGLStoredScene");
// }
glNewList (fTopPODL, GL_COMPILE); {
for (int i = 0; i < fPODLList.entries (); i++) {
glPushMatrix();
G4OpenGLTransform3D oglt (fPODLTransformList (i));
glMultMatrixd (oglt.GetGLMatrix ());
glCallList (fPODLList(i));
glPopMatrix();
}
}
glEndList ();
G4VScene::EndModeling ();
if (fpView -> GetViewParameters ().GetDrawingStyle() == G4ViewParameters::hlr) {
initialize_hlr = false;
// glDisable (GL_POLYGON_OFFSET_FILL);
}
}
void G4OpenGLStoredScene::RequestPrimitives (const G4VSolid& solid) {
if (fReadyForTransients ||
GetModel () -> GetModelingParameters () -> GetRepStyle () ==
G4ModelingParameters::hierarchy) {
G4VScene::RequestPrimitives (solid);
}
else {
// Stop-gap solution for display List re-use. A proper
// implementation would use geometry hierarchy.
G4VSolidPointer pSolid = (G4VSolidPointer) &solid;
if (!(fpCurrentPV -> IsReplicated ()) &&
fSolidDictionary.findValue (pSolid, fDisplayListId)) {
fPODLList.append (fDisplayListId);
fPODLTransformList.append (*fpObjectTransformation);
}
else {
G4VScene::RequestPrimitives (solid);
fSolidDictionary.insertKeyAndValue (pSolid, fDisplayListId);
}
}
}
G4int G4OpenGLStoredScene::fSceneIdCount = 0;
G4int G4OpenGLStoredScene::fSceneCount = 0;
#endif
@@ -0,0 +1,92 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredView.cc,v 2.2 1998/07/13 17:11:34 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 7th February 1997
// Class G4OpenGLStoredView : Encapsulates the `storedness' of
// an OpenGL view, for inheritance by
// derived (X, Xm...) classes.
#ifdef G4VIS_BUILD_OPENGL_DRIVER
#include "G4OpenGLStoredView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
class G4OpenGLStoredScene;
G4OpenGLStoredView::G4OpenGLStoredView (G4OpenGLStoredScene& scene):
G4VView (scene, -1),
G4OpenGLView (scene),
fScene (scene)
{}
void G4OpenGLStoredView::KernelVisitDecision () {
// Trigger a display List refresh if necessary. This is a checklist
// of relevant view parameters.
static G4ViewParameters lastVP; // Initialised to default.
G4bool need = false;
if (
(lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
(lastVP.GetRepStyle () != fVP.GetRepStyle ()) ||
(lastVP.IsCulling () != fVP.IsCulling ()) ||
(lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
(lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
(lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
(lastVP.IsSection () != fVP.IsSection ()) ||
// No need if section plane changes.
(lastVP.IsCutaway () != fVP.IsCutaway ()) ||
(lastVP.GetCutawayPlanes ().entries () !=
fVP.GetCutawayPlanes ().entries ()) ||
// No need if cutaway planes change.
(lastVP.IsExplode () != fVP.IsExplode ()) ||
(lastVP.GetNoOfSides () != fVP.GetNoOfSides ())
) {
need = true;
}
if (!need && lastVP.IsDensityCulling () &&
(lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
need = true;
if (!need && lastVP.IsExplode () &&
(lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
need = true;
if (need) {
lastVP = fVP;
NeedKernelVisit ();
}
}
void G4OpenGLStoredView::DrawDisplayLists () {
if (fScene.fTopPODL) glCallList (fScene.fTopPODL);
G4int nTODLs = fScene.fTODLList.entries ();
for (int i = 0; i < nTODLs; i++) {
glPushMatrix();
G4OpenGLTransform3D oglt (fScene.fTODLTransformList (i));
glMultMatrixd (oglt.GetGLMatrix ());
glCallList (fScene.fTODLList(i));
glPopMatrix();
}
}
#endif
@@ -0,0 +1,61 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredWin32.cc,v 2.1 1998/07/13 17:11:35 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// OpenGLStoredWin32 graphics system factory.
#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4VisFeaturesOfOpenGL.hh"
#include "G4VScene.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLStoredWin32.hh"
#include "G4OpenGLStoredWin32View.hh"
G4OpenGLStoredWin32::G4OpenGLStoredWin32 ():
G4VGraphicsSystem ("OpenGLStoredWin32",
"OGLSWin32",
G4VisFeaturesOfOpenGLSWin32 (),
G4VGraphicsSystem::threeD) {}
G4VScene* G4OpenGLStoredWin32::CreateScene () {
G4VScene* pScene = new G4OpenGLStoredScene (*this);
G4cout << G4OpenGLStoredScene::GetSceneCount ()
<< ' ' << fName << " scenes extanct." << endl;
return pScene;
}
G4VView* G4OpenGLStoredWin32::CreateView (G4VScene& scene) {
G4VView* pView =
new G4OpenGLStoredWin32View ((G4OpenGLStoredScene&) scene);
if (pView) {
if (pView -> GetViewId () < 0) {
delete pView;
pView = 0;
G4cerr << "G4OpenGLStoredWin32::CreateView: error flagged by"
" negative view id in G4OpenGLStoredWin32View creation."
"\n Destroying view and returning null pointer." << endl;
}
}
else {
G4cerr << "G4OpenGLStoredWin32::CreateView: null pointer on"
" new G4OpenGLStoredWin32View." << endl;
}
return pView;
}
#endif
@@ -0,0 +1,86 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredWin32View.cc,v 2.2 1998/08/04 14:22:27 ajw Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Class G4OpenGLStoredWin32View : a class derived from G4OpenGLWin32View and
// G4OpenGLStoredView.
#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
#include "G4OpenGLStoredWin32View.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
G4OpenGLStoredWin32View::G4OpenGLStoredWin32View (G4OpenGLStoredScene& scene):
G4OpenGLView (scene),
G4OpenGLWin32View (scene),
G4OpenGLStoredView (scene),
G4VView (scene, scene.IncrementViewCount ()) {
if (fViewId < 0) return; // In case error in base class instantiation.
//Check that G4OpenGLWin32View got a double buffered colour visual
CreateGLWin32Context ();
CreateMainWindow ();
// clear the buffers and window.
ClearView ();
FinishView ();
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
}
void G4OpenGLStoredWin32View::DrawView () {
if (white_background == true) {
glClearColor (1., 1., 1., 1.);
} else {
glClearColor (0., 0., 0., 1.);
}
//Make sure current viewer is attached and clean...
//Win32 version needed
// glXMakeCurrent (dpy, win, cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
//See if things have changed from last time and remake if necessary...
KernelVisitDecision ();
ProcessView ();
if(style!=G4ViewParameters::hlr &&
haloing_enabled) {
HaloingFirstPass ();
DrawDisplayLists ();
glFlush ();
HaloingSecondPass ();
}
DrawDisplayLists ();
FinishView ();
}
#endif
@@ -0,0 +1,63 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredX.cc,v 2.2 1998/11/06 13:42:34 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// OpenGL graphics system factory.
#ifdef G4VIS_BUILD_OPENGLX_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4VisFeaturesOfOpenGL.hh"
#include "G4VScene.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLStoredX.hh"
#include "G4OpenGLStoredXView.hh"
G4OpenGLStoredX::G4OpenGLStoredX ():
G4VGraphicsSystem ("OpenGLStoredX",
"OGLSX",
G4VisFeaturesOfOpenGLSX (),
G4VGraphicsSystem::threeD) {}
G4VScene* G4OpenGLStoredX::CreateScene (const G4String& name) {
G4VScene* pScene = new G4OpenGLStoredScene (*this, name);
G4cout << G4OpenGLStoredScene::GetSceneCount ()
<< ' ' << fName << " scenes extanct." << endl;
return pScene;
}
G4VView* G4OpenGLStoredX::CreateView (G4VScene& scene,
const G4String& name) {
G4VView* pView =
new G4OpenGLStoredXView ((G4OpenGLStoredScene&) scene, name);
if (pView) {
if (pView -> GetViewId () < 0) {
delete pView;
pView = 0;
G4cerr << "G4OpenGLStoredX::CreateView: error flagged by"
" negative view id in G4OpenGLStoredXView creation."
"\n Destroying view and returning null pointer." << endl;
}
}
else {
G4cerr << "G4OpenGLStoredX::CreateView: null pointer on"
" new G4OpenGLStoredXView." << endl;
}
return pView;
}
#endif
@@ -0,0 +1,98 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredXView.cc,v 2.3 1998/11/06 13:42:35 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 7th February 1997
// Class G4OpenGLStoredXView : a class derived from G4OpenGLXView and
// G4OpenGLStoredView.
#ifdef G4VIS_BUILD_OPENGLX_DRIVER
#include "G4OpenGLStoredXView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
G4OpenGLStoredXView::G4OpenGLStoredXView (G4OpenGLStoredScene& scene,
const G4String& name):
G4OpenGLView (scene),
G4OpenGLXView (scene),
G4OpenGLStoredView (scene),
G4VView (scene, scene.IncrementViewCount (), name) {
if (fViewId < 0) return; // In case error in base class instantiation.
if (!vi_stored) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLStoredXView::G4OpenGLStoredXView -"
" G4OpenGLXView couldn't get a visual." << endl;
return;
}
CreateGLXContext (vi_stored);
InitializeGLView ();
CreateMainWindow ();
// clear the buffers and window.
ClearView ();
FinishView ();
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
}
void G4OpenGLStoredXView::DrawView () {
if (white_background == true) {
glClearColor (1., 1., 1., 1.);
} else {
glClearColor (0., 0., 0., 1.);
}
//Make sure current viewer is attached and clean...
glXMakeCurrent (dpy, win, cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
//See if things have changed from last time and remake if necessary...
KernelVisitDecision ();
ProcessView ();
if(style!=G4ViewParameters::hlr &&
haloing_enabled) {
HaloingFirstPass ();
DrawDisplayLists ();
glFlush ();
HaloingSecondPass ();
}
DrawDisplayLists ();
FinishView ();
}
#endif
@@ -0,0 +1,60 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredXm.cc,v 2.2 1998/11/06 13:42:36 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// OpenGL graphics system factory.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4VisFeaturesOfOpenGL.hh"
#include "G4VScene.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLView.hh"
#include "G4OpenGLStoredXm.hh"
#include "G4OpenGLStoredXmView.hh"
G4OpenGLStoredXm::G4OpenGLStoredXm ():
G4VGraphicsSystem ("OpenGLStoredXm",
"OGLSXm",
G4VisFeaturesOfOpenGLSXm (),
G4VGraphicsSystem::threeD) {}
G4VScene* G4OpenGLStoredXm::CreateScene (const G4String& name) {
G4VScene* pScene = new G4OpenGLStoredScene (*this, name);
G4cout << G4OpenGLStoredScene::GetSceneCount ()
<< ' ' << fName << " scenes extanct." << endl;
return pScene;
}
G4VView* G4OpenGLStoredXm::CreateView (G4VScene& scene, const G4String& name) {
G4VView* pView =
new G4OpenGLStoredXmView ((G4OpenGLStoredScene&) scene, name);
if (pView) {
if (pView -> GetViewId () < 0) {
delete pView;
pView = 0;
G4cerr << "G4OpenGLStoredXm::CreateView: error flagged by"
" negative view id in G4OpenGLStoredXmView creation."
"\n Destroying view and returning null pointer." << endl;
}
}
else {
G4cerr << "G4OpenGLStoredXm::CreateView: null pointer on"
" new G4OpenGLStoredXmView." << endl;
}
return pView;
}
#endif
@@ -0,0 +1,99 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLStoredXmView.cc,v 2.3 1998/11/06 13:42:36 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// Class G4OpenGLStoredXmView : a class derived from G4OpenGLXmView
// and G4OpenGLStoredView.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLStoredXmView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
G4OpenGLStoredXmView::G4OpenGLStoredXmView (G4OpenGLStoredScene& scene,
const G4String& name):
G4OpenGLView (scene),
G4OpenGLXmView (scene),
G4OpenGLStoredView (scene),
G4VView (scene, scene.IncrementViewCount (), name) {
if (fViewId < 0) return; // In case error in base class instantiation.
if (!vi_stored) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLStoredXmView::G4OpenGLStoredXmView -"
" G4OpenGLXmView couldn't get a visual." << endl;
return;
}
CreateGLXContext (vi_stored);
InitializeGLView ();
CreateMainWindow ();
// clear the buffers and window.
ClearView ();
FinishView ();
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel (GL_FLAT);
}
void G4OpenGLStoredXmView::DrawView () {
if (white_background == true) {
glClearColor (1., 1., 1., 1.);
} else {
glClearColor (0., 0., 0., 1.);
}
//Make sure current viewer is attached and clean...
glXMakeCurrent (dpy, win, cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
//See if things have changed from last time and remake if necessary...
KernelVisitDecision ();
ProcessView ();
if(style!=G4ViewParameters::hlr &&
haloing_enabled) {
HaloingFirstPass ();
DrawDisplayLists ();
glFlush ();
HaloingSecondPass ();
}
DrawDisplayLists ();
FinishView ();
}
#endif
@@ -0,0 +1,47 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLTransform3D.cc,v 2.0 1998/07/02 16:46:23 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 24th October 1996
// G4OpenGLTransform3D provides OpenGL style transformation matrix
// from G4Transform3D.
#ifdef G4VIS_BUILD_OPENGL_DRIVER
#include <GL/gl.h>
#include "G4OpenGLTransform3D.hh"
G4OpenGLTransform3D::G4OpenGLTransform3D (const G4Transform3D &t):
G4Transform3D (t) {}
const GLdouble* G4OpenGLTransform3D::GetGLMatrix ()
{
m[0] = (GLdouble)xx;
m[1] = (GLdouble)yx;
m[2] = (GLdouble)zx;
m[3] = (GLdouble)0;
m[4] = (GLdouble)xy;
m[5] = (GLdouble)yy;
m[6] = (GLdouble)zy;
m[7] = (GLdouble)0;
m[8] = (GLdouble)xz;
m[9] = (GLdouble)yz;
m[10] = (GLdouble)zz;
m[11] = (GLdouble)0;
m[12] = (GLdouble)dx;
m[13] = (GLdouble)dy;
m[14] = (GLdouble)dz;
m[15] = (GLdouble)1;
return m;
}
#endif
@@ -0,0 +1,281 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLView.cc,v 2.7 1998/12/16 20:23:39 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 27th March 1996
// OpenGL view - opens window, hard copy, etc.
#ifdef G4VIS_BUILD_OPENGL_DRIVER
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4OpenGLView.hh"
#include "G4OpenGLScene.hh"
#include "G4OpenGLTransform3D.hh"
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
#include "G4VisExtent.hh"
#include "G4LogicalVolume.hh"
#include "G4VSolid.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4Plane3D.hh"
int G4OpenGLView::snglBuf_RGBA[10] =
{ GLX_RGBA, GLX_RED_SIZE, 3, GLX_GREEN_SIZE, 3,
GLX_BLUE_SIZE, 2, GLX_DEPTH_SIZE, 1, None };
int G4OpenGLView::dblBuf_RGBA[11] =
{ GLX_RGBA, GLX_RED_SIZE, 3, GLX_GREEN_SIZE, 3,
GLX_BLUE_SIZE, 2, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None };
G4OpenGLView::G4OpenGLView (G4OpenGLScene& scene):
G4VView (scene, -1),
fScene (scene),
white_background (False),
transparency_enabled (False),
antialiasing_enabled (False),
haloing_enabled (False)
{
// glClearColor (0.0, 0.0, 0.0, 0.0);
// glClearDepth (1.0);
// glDisable (GL_BLEND);
// glDisable (GL_LINE_SMOOTH);
// glDisable (GL_POLYGON_SMOOTH);
}
void G4OpenGLView::InitializeGLView ()
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClearDepth (1.0);
glDisable (GL_BLEND);
glDisable (GL_LINE_SMOOTH);
glDisable (GL_POLYGON_SMOOTH);
}
void G4OpenGLView::ClearView () {
//Below line does not compile with Mesa includes.
//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear (GL_COLOR_BUFFER_BIT);
glClear (GL_DEPTH_BUFFER_BIT);
glClear (GL_STENCIL_BUFFER_BIT);
glFlush ();
}
void G4OpenGLView::SetView () {
// Calculates view representation based on extent of object being
// viewed and (initial) viewpoint. (Note: it can change later due
// to user interaction via visualization system's GUI.)
// Lighting.
GLfloat lightPosition [4];
lightPosition [0] = fVP.GetActualLightpointDirection().x();
lightPosition [1] = fVP.GetActualLightpointDirection().y();
lightPosition [2] = fVP.GetActualLightpointDirection().z();
lightPosition [3] = 0.;
// Light position is "true" light direction, so must come after gluLookAt.
GLfloat ambient [] = { 0.2, 0.2, 0.2, 1.};
GLfloat diffuse [] = { 0.8, 0.8, 0.8, 1.};
glEnable (GL_LIGHT0);
glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
const G4Point3D& target = fVP.GetCurrentTargetPoint ();
// Get radius of scene.
G4double radius = fScene.GetSceneData().GetExtent().GetExtentRadius();
if(radius<=0.) radius = 1.;
const G4double cameraDistance = fVP.GetCameraDistance (radius);
const G4Point3D& pCamera =
target + cameraDistance * fVP.GetViewpointDirection().unit();
const GLdouble near = fVP.GetNearDistance (cameraDistance, radius);
const GLdouble far = fVP.GetFarDistance (cameraDistance, near, radius);
const GLdouble right = fVP.GetFrontHalfHeight (near, radius);
const GLdouble left = -right;
const GLdouble bottom = left;
const GLdouble top = right;
glMatrixMode (GL_PROJECTION); // set up Frustum.
glLoadIdentity();
if (fVP.GetFieldHalfAngle() == 0.) {
glOrtho (left, right, bottom, top, near, far);
}
else {
glFrustum (left, right, bottom, top, near, far);
}
glMatrixMode (GL_MODELVIEW); // apply further transformations to scene.
glLoadIdentity();
const G4Normal3D& upVector = fVP.GetUpVector ();
G4Point3D gltarget;
if (cameraDistance > 1.e-6 * radius) {
gltarget = target;
}
else {
gltarget = target - radius * fVP.GetViewpointDirection().unit();
}
gluLookAt (pCamera.x(), pCamera.y(), pCamera.z(), // Viewpoint.
gltarget.x(), gltarget.y(), gltarget.z(), // Target point.
upVector.x(), upVector.y(), upVector.z()); // Up vector.
// Light position is "true" light direction, so must come after gluLookAt.
glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
// Clip planes.
if (fVP.IsSection () ) { // pair of back to back clip planes.
const G4Plane3D& s = fVP.GetSectionPlane ();
double sArray[4];
sArray[0] = s.a();
sArray[1] = s.b();
sArray[2] = s.c();
sArray[3] = s.d() + radius * 1.e-05;
glClipPlane (GL_CLIP_PLANE0, sArray);
glEnable (GL_CLIP_PLANE0);
sArray[0] = -s.a();
sArray[1] = -s.b();
sArray[2] = -s.c();
sArray[3] = -s.d() + radius * 1.e-05;
glClipPlane (GL_CLIP_PLANE1, sArray);
glEnable (GL_CLIP_PLANE1);
}
else {
glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);
}
}
void G4OpenGLView::HaloingFirstPass () {
//To perform haloing, first Draw all information to the depth buffer
//alone, using a chunky line width, and then Draw all info again, to
//the colour buffer, setting a thinner line width an the depth testing
//function to less than or equal, so if two lines cross, the one
//passing behind the other will not pass the depth test, and so not
//get rendered either side of the infront line for a short distance.
//First, disable writing to the colo(u)r buffer...
glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
//Now enable writing to the depth buffer...
glDepthMask (GL_TRUE);
glDepthFunc (GL_LESS);
glClearDepth (1.0);
//Finally, set the line width to something wide...
glLineWidth (3.0);
}
void G4OpenGLView::HaloingSecondPass () {
//And finally, turn the colour buffer back on with a sesible line width...
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthFunc (GL_LEQUAL);
glLineWidth (1.0);
}
void G4OpenGLView::HLRFirstPass () {
G4cout << "First pass HLR" << endl;
//Hidden line drawing requires three renderings to different buffers, so it
//cannot be treated in G4OpenGLScene alone (as can wireframe or hidden
//surface (solid) mode)
//So, after SIGGRAPH97
//1) Disable the colour and depth buffers, and Draw polygons in wireframe
// mode to the stencil buffer, setting stencil value to 1 where pixels go.
//First, disable writing to the colo(u)r buffer...
glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
//Enable the stencil buffer...
glEnable (GL_STENCIL_TEST);
//Now disable writing to the depth buffer...
glDisable (GL_DEPTH_TEST);
//Clear all stencil buffer values to 0...
glClearStencil (0);
glClear (GL_STENCIL_BUFFER_BIT);
//Prepare stencil buffer...
glStencilFunc (GL_ALWAYS, //When to pass a pixel in the stencil test
0x1, //The ref val to compare with masked stencil val
0x1); //The mask to AND with ref and val before test
glStencilOp (GL_KEEP, //If stencil test fails *irrelevant*
GL_KEEP, //If depth test passes *irrelevant*
GL_REPLACE); //If no depth test *this is applied to every pixel
//drawn to the stencil buffer in this pass*
//Hence, everywhere a pixel is drawn, stencil value=1, 0 everywhere else.
//Set the drawing style to wireframe...
fVP.SetDrawingStyle (G4ViewParameters::wireframe);
NeedKernelVisit ();
ProcessView ();
}
void G4OpenGLView::HLRSecondPass () {
G4cout << "Second pass HLR" << endl;
//2) Use the stencil buffer to mask out pixels where stencil value = 1, and
// render to the stencil buffer as depth tested filled polygons.
glStencilFunc (GL_EQUAL, 0x1, 0x1);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
glDepthFunc (GL_LEQUAL);
glEnable (GL_DEPTH_TEST);
//Set the drawing style to hlhsr (solid)...
fVP.SetDrawingStyle (G4ViewParameters::hsr);
NeedKernelVisit ();
ProcessView ();
}
void G4OpenGLView::HLRThirdPass () {
//3) Turn off the stencil buffer, turn on the colour buffer
// and render polygons in wireframe mode.
G4cout << "Third pass HLR" << endl;
glDisable (GL_STENCIL_TEST);
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
//Set the drawing style to hlr wireframe...
fVP.SetDrawingStyle (G4ViewParameters::wireframe);
NeedKernelVisit ();
ProcessView ();
fVP.SetDrawingStyle (G4ViewParameters::hlr);
}
#endif
@@ -0,0 +1,84 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLWin32View.cc,v 2.2 1998/07/13 17:11:43 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// G4OpenGLWin32View : Class to provide WindowsNT specific
// functionality for OpenGL in GEANT4
#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
#include "G4OpenGLWin32View.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
#include "G4VisExtent.hh"
#include "G4LogicalVolume.hh"
#include "G4VSolid.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
void G4OpenGLWin32View::FinishView () {
//Wait for GL commands to exit before going on...
//Swap buffers if double buffered...
//Flush GL commands...
}
void G4OpenGLWin32View::GetWin32Connection () {
// get a connection.
}
void G4OpenGLWin32View::CreateGLWin32Context () {
// create a GL context
// set attributes of window now the GL context has been created
}
void G4OpenGLWin32View::CreateMainWindow () {
// create a window
// connect the context to a window
}
G4OpenGLWin32View::G4OpenGLWin32View (G4OpenGLScene& scene):
G4VView (scene, -1),
G4OpenGLView (scene)
{
GetWin32Connection ();
if (fViewId < 0) return;
// Try for a visual suitable for OpenGLImmediate..
// first try for a single buffered RGB window
// next try for a double buffered RGB, but Draw to top buffer
// Now try for a visual suitable for OpenGLStored...
// Try for a double buffered RGB window
}
G4OpenGLWin32View::~G4OpenGLWin32View () {
if (fViewId >= 0) {
//Close a window from here
//destroy GL context
//make NULL context current
//destroy the Win32 window
}
}
#endif
@@ -0,0 +1,914 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXView.cc,v 2.6 1998/10/14 14:26:26 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 7th February 1997
// G4OpenGLXView : Class to provide XWindows specific
// functionality for OpenGL in GEANT4
#ifdef G4VIS_BUILD_OPENGLX_DRIVER
#include "G4OpenGLXView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include "G4VisExtent.hh"
#include "G4LogicalVolume.hh"
#include "G4VSolid.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <string.h>
#define NewString(str) \
((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
#define USE_DEFAULT_COLORMAP 1
#define USE_STANDARD_COLORMAP 0
static Bool WaitForNotify (Display*, XEvent* e, char* arg) {
return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
}
void G4OpenGLXView::FinishView () {
glXWaitGL (); //Wait for effects of all previous OpenGL commands to
//be propogated before progressing.
if (doublebuffer == true) {
glXSwapBuffers (dpy, win);
}
else glFlush ();
}
void G4OpenGLXView::GetXConnection () {
// get a connection.
dpy = XOpenDisplay (0);
if (!dpy) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLView::G4OpenGLView couldn't open display." << endl;
return;
}
// make sure OpenGL is supported and installed properly.
if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLView::G4OpenGLView X Server has no GLX extension."
<< endl;
return;
}
}
void G4OpenGLXView::CreateGLXContext (XVisualInfo* v) {
vi = v;
// get window's attributes
if (!XGetWindowAttributes(dpy, XRootWindow (dpy, vi -> screen), &xwa)) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLView::G4OpenGLView couldn't return window attributes"
<< endl;
return;
}
// create a GLX context
cx = glXCreateContext (dpy, vi, 0, true);
if (!cx) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLView::G4OpenGLView couldn't create context."
<< endl;
return;
}
// New stab at getting a colormap
Status status;
XStandardColormap *standardCmaps = XAllocStandardColormap ();
int i, numCmaps;
status = XmuLookupStandardColormap (dpy,
vi -> screen,
vi -> visualid,
vi -> depth,
XA_RGB_DEFAULT_MAP,
False,
True);
if (status == 1) {
status = XGetRGBColormaps (dpy,
XRootWindow (dpy, vi -> screen),
&standardCmaps,
&numCmaps,
XA_RGB_DEFAULT_MAP);
if (status == 1)
for (i = 0; i < numCmaps; i++)
if (standardCmaps[i].visualid == vi -> visualid) {
cmap = standardCmaps[i].colormap;
XFree (standardCmaps);
}
G4cout << "Got standard cmap" << endl;
} else {
cmap = XCreateColormap (dpy,
XRootWindow(dpy, vi -> screen),
vi -> visual,
AllocNone);
G4cout << "Created own cmap" << endl;
}
if (!cmap) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLView::G4OpenGLView failed to allocate a Colormap."
<< endl;
return;
}
}
void G4OpenGLXView::CreateMainWindow () {
// create a window
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
swa.backing_store = WhenMapped;
// G4int WinSize_x;
// G4int WinSize_y;
if (xwa.width > xwa.height) {
WinSize_x = (xwa.height)/2;
WinSize_y = (xwa.height)/2;
}
else {
WinSize_x = (xwa.width)/2;
WinSize_y = (xwa.width)/2;
}
if (WinSize_x < fVP.GetWindowSizeHintX ())
WinSize_x = fVP.GetWindowSizeHintX ();
if (WinSize_y < fVP.GetWindowSizeHintY ())
WinSize_y = fVP.GetWindowSizeHintY ();
x_origin = xwa.x;
y_origin = xwa.y;
G4cout << "Window name: " << fName << endl;
strncpy (charViewName, fName, 100);
char *window_name = charViewName;
char *icon_name = charViewName;
char tmpatom[] = "XA_WM_NORMAL_HINTS";
size_hints = XAllocSizeHints();
wm_hints = XAllocWMHints();
class_hints = XAllocClassHint();
size_hints -> flags = PPosition | PSize | PMinSize;
size_hints -> min_width = 300;
size_hints -> min_height = 200;
XStringListToTextProperty (&window_name, 1, &windowName);
XStringListToTextProperty (&icon_name, 1, &iconName);
wm_hints -> initial_state = NormalState;
wm_hints -> input = True;
wm_hints -> icon_pixmap = icon_pixmap;
wm_hints -> flags = StateHint | IconPixmapHint | InputHint;
class_hints -> res_name = NewString("G4OpenGL");
class_hints -> res_class = NewString("G4OpenGL");
win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin,
y_origin, WinSize_x, WinSize_y, 0, vi -> depth,
InputOutput, vi -> visual,
CWBorderPixel | CWColormap |
CWEventMask | CWBackingStore,
&swa);
XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0,
size_hints, wm_hints, class_hints);
// request X to Draw window on screen.
XMapWindow (dpy, win);
// Wait for window to appear (wait for an "expose" event).
XIfEvent (dpy, &event, WaitForNotify, (char*) win);
// connect the context to a window
glXMakeCurrent (dpy, win, cx);
}
G4OpenGLXView::G4OpenGLXView (G4OpenGLScene& scene):
G4VView (scene, -1),
G4OpenGLView (scene), //ajw
vi_immediate (0),
vi_stored (0),
print_colour (true),
vectored_ps (true)
{
strcpy (print_string, "G4OpenGL.eps");
GetXConnection ();
if (fViewId < 0) return;
// Try for a visual suitable for OpenGLImmediate..
// first try for a single buffered RGB window
if (vi_immediate =
glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA)) {
attributeList = snglBuf_RGBA;
doublebuffer = false;
}
if (!vi_immediate){
// next try for a double buffered RGB, but Draw to top buffer
if (vi_immediate =
glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA)) {
attributeList = dblBuf_RGBA;
doublebuffer = true;
}
}
// Now try for a visual suitable for OpenGLStored...
// Try for a double buffered RGB window
if (vi_stored = glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA)) {
attributeList = dblBuf_RGBA;
doublebuffer = true;
}
// glClearColor (0., 0., 0., 0.);
// glClearDepth (1.);
}
G4OpenGLXView::~G4OpenGLXView () {
if (fViewId >= 0) {
//Close a window from here
glXDestroyContext (dpy, cx);
glXMakeCurrent (dpy, None, NULL);
XDestroyWindow (dpy, win);
XFlush (dpy);
}
}
void G4OpenGLXView::print() {
//cout << "print_col_callback requested with file name: " << print_string << endl;
if (vectored_ps) {
G4int size = 5000000;
GLfloat* feedback_buffer;
GLint returned;
FILE* file;
feedback_buffer = new GLfloat[size];
glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
glRenderMode (GL_FEEDBACK);
DrawView();
returned = glRenderMode (GL_RENDER);
if (print_string) {
file = fopen (print_string, "w");
if (file) {
spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
} else {
printf("Could not open %s\n", print_string);
}
} else {
printBuffer (returned, feedback_buffer);
}
// free (feedback_buffer);
delete[] feedback_buffer;
} else {
XVisualInfo* pvi;
G4bool new_db;
G4bool last_db;
GLXContext pcx = create_GL_print_context(pvi, new_db);
GLXContext tmp_cx;
tmp_cx = cx;
cx=pcx;
last_db=doublebuffer;
doublebuffer=new_db;
Pixmap pmap = XCreatePixmap (dpy,
XRootWindow (dpy, pvi->screen),
WinSize_x, WinSize_y,
pvi->depth);
GLXPixmap glxpmap = glXCreateGLXPixmap (dpy,
pvi,
pmap);
GLXDrawable tmp_win;
tmp_win=win;
win=glxpmap;
glXMakeCurrent (dpy,
glxpmap,
cx);
glViewport (0, 0, WinSize_x, WinSize_y);
ClearView ();
DrawView ();
generateEPS (print_string,
print_colour,
WinSize_x, WinSize_y);
win=tmp_win;
cx=tmp_cx;
doublebuffer=last_db;
glXMakeCurrent (dpy,
glxpmap,
cx);
}
}
void G4OpenGLXView::print3DcolorVertex(GLint size, GLint * count, GLfloat * buffer)
{
G4int i;
printf(" ");
for (i = 0; i < 7; i++) {
printf("%4.2f ", buffer[size - (*count)]);
*count = *count - 1;
}
printf("\n");
}
void G4OpenGLXView::spewWireframeEPS (FILE* file, GLint size, GLfloat* buffer, char* cr) {
GLfloat EPS_GOURAUD_THRESHOLD=0.1;
GLfloat clearColor[4], viewport[4];
GLfloat lineWidth;
G4int i;
glGetFloatv (GL_VIEWPORT, viewport);
glGetFloatv (GL_COLOR_CLEAR_VALUE, clearColor);
glGetFloatv (GL_LINE_WIDTH, &lineWidth);
glGetFloatv (GL_POINT_SIZE, &pointSize);
fputs ("%!PS-Adobe-2.0 EPSF-2.0\n", file);
fprintf (file, "%%%%Creator: %s (using OpenGL feedback)\n", file, cr);
fprintf (file, "%%%%BoundingBox: %g %g %g %g\n", viewport[0], viewport[1], viewport[2], viewport[3]);
fputs ("%%EndComments\n", file);
fputs ("\n", file);
fputs ("gsave\n", file);
fputs ("\n", file);
fputs ("% the gouraudtriangle PostScript fragment below is free\n", file);
fputs ("% written by Frederic Delhoume (delhoume@ilog.fr)\n", file);
fprintf (file, "/threshold %g def\n", EPS_GOURAUD_THRESHOLD);
for (i=0; gouraudtriangleEPS[i]; i++) {
fprintf (file, "%s\n", gouraudtriangleEPS[i]);
}
fprintf(file, "\n%g setlinewidth\n", lineWidth);
fprintf (file, "%g %g %g setrgbcolor\n", clearColor[0], clearColor[1], clearColor[2]);
fprintf (file, "%g %g %g %g rectfill\n\n", viewport[0], viewport[1], viewport[2], viewport[3]);
spewSortedFeedback (file, size, buffer);
fputs ("grestore\n\n", file);
fputs ("showpage\n", file);
fclose(file);
}
void G4OpenGLXView::printBuffer (GLint size, GLfloat* buffer) {
GLint count;
G4int token, nvertices;
count=size;
while(count) {
token=G4int (buffer[size-count]);
count--;
switch (token) {
case GL_PASS_THROUGH_TOKEN:
printf ("GL_PASS_THROUGH_TOKEN\n");
printf (" %4.2f\n", buffer[size-count]);
count--;
break;
case GL_POINT_TOKEN:
printf ("GL_POINT_TOKEN\n");
print3DcolorVertex (size, &count, buffer);
break;
case GL_LINE_TOKEN:
printf ("GL_LINE_TOKEN\n");
print3DcolorVertex (size, &count, buffer);
print3DcolorVertex (size, &count, buffer);
break;
case GL_LINE_RESET_TOKEN:
printf ("GL_LINE_RESET_TOKEN\n");
print3DcolorVertex (size, &count, buffer);
print3DcolorVertex (size, &count, buffer);
break;
case GL_POLYGON_TOKEN:
printf ("GL_POLYGON_TOKEN\n");
nvertices=G4int (buffer[size-count]);
count--;
for (; nvertices>0; nvertices--) {
print3DcolorVertex (size, &count, buffer);
}
}
}
}
G4float* G4OpenGLXView::spewPrimitiveEPS (FILE* file, GLfloat* loc) {
G4int token;
G4int nvertices, i;
GLfloat red, green, blue, intensity;
G4int smooth;
GLfloat dx, dy, dr, dg, db, absR, absG, absB, colormax;
G4int steps;
Feedback3Dcolor *vertex;
GLfloat xstep, ystep, rstep, gstep, bstep;
GLfloat xnext, ynext, rnext, gnext, bnext, distance;
token=G4int (*loc);
loc++;
switch (token) {
case GL_LINE_RESET_TOKEN:
case GL_LINE_TOKEN:
vertex=(Feedback3Dcolor*)loc;
dr=vertex[1].red - vertex[0].red;
dg=vertex[1].green - vertex[0].green;
db=vertex[1].blue - vertex[0].blue;
if (!print_colour) {
dr+=(dg+db);
dr/=3.0;
dg=dr;
db=dr;
}
if (dr!=0 || dg!=0 || db!=0) {
dx=vertex[1].x - vertex[0].x;
dy=vertex[1].y - vertex[0].y;
distance=sqrt(dx*dx + dy*dy);
absR=fabs(dr);
absG=fabs(dg);
absB=fabs(db);
#define Max(a, b) (((a)>(b))?(a):(b))
#define EPS_SMOOTH_LINE_FACTOR 0.06
colormax=Max(absR, Max(absG, absB));
steps=Max(1, G4int (colormax*distance*EPS_SMOOTH_LINE_FACTOR));
xstep=dx/steps;
ystep=dy/steps;
rstep=dr/steps;
gstep=dg/steps;
bstep=db/steps;
xnext=vertex[0].x;
ynext=vertex[0].y;
rnext=vertex[0].red;
gnext=vertex[0].green;
bnext=vertex[0].blue;
if (!print_colour) {
rnext+=(gnext+bnext);
rnext/=3.0;
gnext=rnext;
bnext=rnext;
}
xnext -= xstep/2.0;
ynext -= ystep/2.0;
rnext -= rstep/2.0;
gnext -= gstep/2.0;
bnext -= bstep/2.0;
} else {
steps=0;
}
if (print_colour) {
fprintf (file, "%g %g %g setrgbcolor\n",
vertex[0].red, vertex[0].green, vertex[0].blue);
} else {
intensity = (vertex[0].red + vertex[0].green + vertex[0].blue) / 3.0;
fprintf (file, "%g %g %g setrgbcolor\n",
intensity, intensity, intensity);
}
fprintf (file, "%g %g moveto\n", vertex[0].x, vertex[0].y);
for (i=0; i<steps; i++) {
xnext += xstep;
ynext += ystep;
rnext += rstep;
gnext += gstep;
bnext += bstep;
fprintf (file, "%g %g lineto stroke\n", xnext, ynext);
fprintf (file, "%g %g %g setrgbcolor\n", rnext, gnext, bnext);
fprintf (file, "%g %g moveto\n", xnext, ynext);
}
fprintf (file, "%g %g lineto stroke\n", vertex[1].x, vertex[1].y);
loc += 14;
break;
case GL_POLYGON_TOKEN:
nvertices = G4int (*loc);
loc++;
vertex=(Feedback3Dcolor*)loc;
if (nvertices>0) {
red=vertex[0].red;
green=vertex[0].green;
blue=vertex[0].blue;
smooth=0;
if (!print_colour) {
red+=(green+blue);
red/=3.0;
green=red;
blue=red;
}
if (print_colour) {
for (i=1; i<nvertices; i++) {
if (red!=vertex[i].red || green!=vertex[i].green || blue!=vertex[i].blue) {
smooth=1;
break;
}
}
} else {
for (i=1; i<nvertices; i++) {
intensity = vertex[i].red + vertex[i].green + vertex[i].blue;
intensity/=3.0;
if (red!=intensity) {
smooth=1;
break;
}
}
}
if (smooth) {
G4int triOffset;
for (i=0; i<nvertices-2; i++) {
triOffset = i*7;
fprintf (file, "[%g %g %g %g %g %g]",
vertex[0].x, vertex[i+1].x, vertex[i+2].x,
vertex[0].y, vertex[i+1].y, vertex[i+2].y);
if (print_colour) {
fprintf (file, " [%g %g %g] [%g %g %g] [%g %g %g] gouraudtriangle\n",
vertex[0].red, vertex[0].green, vertex[0].blue,
vertex[i+1].red, vertex[i+1].green, vertex[i+1].blue,
vertex[i+2].red, vertex[i+2].green, vertex[i+2].blue);
} else {
intensity = vertex[0].red + vertex[0].green + vertex[0].blue;
intensity/=3.0;
fprintf (file, " [%g %g %g]", intensity, intensity, intensity);
intensity = vertex[1].red + vertex[1].green + vertex[1].blue;
intensity/=3.0;
fprintf (file, " [%g %g %g]", intensity, intensity, intensity);
intensity = vertex[2].red + vertex[2].green + vertex[2].blue;
intensity/=3.0;
fprintf (file, " [%g %g %g] gouraudtriangle\n", intensity, intensity, intensity);
}
}
} else {
fprintf (file, "newpath\n");
fprintf (file, "%g %g %g setrgbcolor\n", red, green, blue);
fprintf (file, "%g %g moveto\n", vertex[0].x, vertex[0].y);
for (i=1; i<nvertices; i++) {
fprintf (file, "%g %g lineto\n", vertex[i].x, vertex[i].y);
}
fprintf (file, "closepath fill\n\n");
}
}
loc += nvertices*7;
break;
case GL_POINT_TOKEN:
vertex=(Feedback3Dcolor*)loc;
if (print_colour) {
fprintf (file, "%g %g %g setrgbcolor\n", vertex[0].red, vertex[0].green, vertex[0].blue);
} else {
intensity = vertex[0].red + vertex[0].green + vertex[0].blue;
intensity/=3.0;
fprintf (file, "%g %g %g setrgbcolor\n", intensity, intensity, intensity);
}
fprintf(file, "%g %g %g 0 360 arc fill\n\n", vertex[0].x, vertex[0].y, pointSize / 2.0);
loc += 7; /* Each vertex element in the feedback
buffer is 7 GLfloats. */
break;
default:
/* XXX Left as an excersie to the reader. */
printf("Incomplete implementation. Unexpected token (%d).\n", token);
exit(1);
}
return loc;
}
typedef struct _DepthIndex {
GLfloat *ptr;
GLfloat depth;
} DepthIndex;
static int
compare(const void *a, const void *b)
{
DepthIndex *p1 = (DepthIndex *) a;
DepthIndex *p2 = (DepthIndex *) b;
GLfloat diff = p2->depth - p1->depth;
if (diff > 0.0) {
return 1;
} else if (diff < 0.0) {
return -1;
} else {
return 0;
}
}
void G4OpenGLXView::spewSortedFeedback(FILE * file, GLint size, GLfloat * buffer)
{
int token;
GLfloat *loc, *end;
Feedback3Dcolor *vertex;
GLfloat depthSum;
int nprimitives, item;
DepthIndex *prims;
int nvertices, i;
end = buffer + size;
/* Count how many primitives there are. */
nprimitives = 0;
loc = buffer;
while (loc < end) {
token = int (*loc);
loc++;
switch (token) {
case GL_LINE_TOKEN:
case GL_LINE_RESET_TOKEN:
loc += 14;
nprimitives++;
break;
case GL_POLYGON_TOKEN:
nvertices = int (*loc);
loc++;
loc += (7 * nvertices);
nprimitives++;
break;
case GL_POINT_TOKEN:
loc += 7;
nprimitives++;
break;
default:
/* XXX Left as an excersie to the reader. */
printf("Incomplete implementation. Unexpected token (%d).\n",
token);
exit(1);
}
}
/* Allocate an array of pointers that will point back at
primitives in the feedback buffer. There will be one
entry per primitive. This array is also where we keep the
primitive's average depth. There is one entry per
primitive in the feedback buffer. */
prims = (DepthIndex *) malloc(sizeof(DepthIndex) * nprimitives);
item = 0;
loc = buffer;
while (loc < end) {
prims[item].ptr = loc; /* Save this primitive's location. */
token = int (*loc);
loc++;
switch (token) {
case GL_LINE_TOKEN:
case GL_LINE_RESET_TOKEN:
vertex = (Feedback3Dcolor *) loc;
depthSum = vertex[0].z + vertex[1].z;
prims[item].depth = depthSum / 2.0;
loc += 14;
break;
case GL_POLYGON_TOKEN:
nvertices = int (*loc);
loc++;
vertex = (Feedback3Dcolor *) loc;
depthSum = vertex[0].z;
for (i = 1; i < nvertices; i++) {
depthSum += vertex[i].z;
}
prims[item].depth = depthSum / nvertices;
loc += (7 * nvertices);
break;
case GL_POINT_TOKEN:
vertex = (Feedback3Dcolor *) loc;
prims[item].depth = vertex[0].z;
loc += 7;
break;
default:
/* XXX Left as an excersie to the reader. */
assert(1);
}
item++;
}
assert(item == nprimitives);
/* Sort the primitives back to front. */
qsort(prims, nprimitives, sizeof(DepthIndex), compare);
/* Understand that sorting by a primitives average depth
doesn't allow us to disambiguate some cases like self
intersecting polygons. Handling these cases would require
breaking up the primitives. That's too involved for this
example. Sorting by depth is good enough for lots of
applications. */
/* Emit the Encapsulated PostScript for the primitives in
back to front order. */
for (item = 0; item < nprimitives; item++) {
(void) spewPrimitiveEPS(file, prims[item].ptr);
}
free(prims);
}
GLXContext G4OpenGLXView::create_GL_print_context(XVisualInfo*& pvi, G4bool& db) {
pvi = glXChooseVisual (dpy,
XDefaultScreen (dpy),
snglBuf_RGBA);
if (pvi != NULL) {
db=false;
} else {
pvi = glXChooseVisual (dpy,
XDefaultScreen (dpy),
dblBuf_RGBA);
if (NULL) {
db=true;
}
}
return glXCreateContext (dpy,
pvi,
NULL,
False);
}
int G4OpenGLXView::generateEPS (char* filnam,
int inColour,
unsigned int width,
unsigned int height) {
FILE* fp;
GLubyte* pixels;
GLubyte* curpix;
int components, pos, i;
pixels = grabPixels (inColour, width, height);
if (pixels == NULL)
return 1;
if (inColour) {
components = 3;
} else {
components = 1;
}
fp = fopen (filnam, "w");
if (fp == NULL) {
return 2;
}
fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
fprintf (fp, "%%%%Title: %s\n", filnam);
fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height);
fprintf (fp, "%%%%EndComments\n");
fprintf (fp, "gsave\n");
fprintf (fp, "/bwproc {\n");
fprintf (fp, " rgbproc\n");
fprintf (fp, " dup length 3 idiv string 0 3 0 \n");
fprintf (fp, " 5 -1 roll {\n");
fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n");
fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n");
fprintf (fp, " { 2 1 roll } ifelse\n");
fprintf (fp, " }forall\n");
fprintf (fp, " pop pop pop\n");
fprintf (fp, "} def\n");
fprintf (fp, "systemdict /colorimage known not {\n");
fprintf (fp, " /colorimage {\n");
fprintf (fp, " pop\n");
fprintf (fp, " pop\n");
fprintf (fp, " /rgbproc exch def\n");
fprintf (fp, " { bwproc } image\n");
fprintf (fp, " } def\n");
fprintf (fp, "} if\n");
fprintf (fp, "/picstr %d string def\n", width * components);
fprintf (fp, "%d %d scale\n", width, height);
fprintf (fp, "%d %d %d\n", width, height, 8);
fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height);
fprintf (fp, "{currentfile picstr readhexstring pop}\n");
fprintf (fp, "false %d\n", components);
fprintf (fp, "colorimage\n");
curpix = (GLubyte*) pixels;
pos = 0;
for (i = width*height*components; i>0; i--) {
fprintf (fp, "%02hx ", *(curpix++));
if (++pos >= 32) {
fprintf (fp, "\n");
pos = 0;
}
}
if (pos)
fprintf (fp, "\n");
fprintf (fp, "grestore\n");
fprintf (fp, "showpage\n");
delete pixels;
fclose (fp);
return 0;
}
GLubyte* G4OpenGLXView::grabPixels (int inColor, unsigned int width, unsigned int height) {
GLubyte* buffer;
GLint swapbytes, lsbfirst, rowlength;
GLint skiprows, skippixels, alignment;
GLenum format;
int size;
if (inColor) {
format = GL_RGB;
size = width*height*3;
} else {
format = GL_LUMINANCE;
size = width*height*1;
}
buffer = new GLubyte[size];
if (buffer == NULL)
return NULL;
glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);
glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);
glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength);
glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows);
glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels);
glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer);
glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes);
glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst);
glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength);
glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels);
glPixelStorei (GL_UNPACK_ALIGNMENT, alignment);
return buffer;
}
#endif
@@ -0,0 +1,89 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmBox.cc,v 2.1 1998/07/13 17:11:44 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Box container class
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmFramedBox.hh"
#include "G4OpenGLXmBox.hh"
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetShell.hh"
G4OpenGLXmBox::G4OpenGLXmBox (char* n,
G4bool r)
{
name = n;
radio = r;
parent = NULL;
box_row_col = NULL;
}
G4OpenGLXmBox::~G4OpenGLXmBox ()
{}
void G4OpenGLXmBox::AddChild (G4OpenGLXmVWidgetComponent* component)
{
component->AddYourselfTo(this);
Cardinal num_children;
XtVaGetValues (box_row_col,
XmNnumChildren, &num_children,
NULL);
// G4cout << name << " now parents " << num_children << " children." << endl;
}
void G4OpenGLXmBox::AddYourselfTo (G4OpenGLXmVWidgetShell* window)
{
pView = window->GetView ();
ProcesspView ();
parent = window->GetPointerToWidget ();
box_row_col = XtVaCreateManagedWidget (name,
xmRowColumnWidgetClass,
*parent,
XmNadjustMargin, True,
XmNisHomogeneous, False,
XmNlabelString, (XmString)name,
XmNradioAlwaysOne, radio,
XmNradioBehavior, radio,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
}
Widget* G4OpenGLXmBox::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmBox::GetPointerToWidget ()
{
return &box_row_col;
}
char* G4OpenGLXmBox::GetName ()
{
return name;
}
void G4OpenGLXmBox::SetName (char* n)
{
name = n;
}
#endif
@@ -0,0 +1,500 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmConvenienceRoutines.cc,v 2.2 1998/08/13 16:14:34 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 16th April 1997
// G4OpenGLXmConvenienceRoutines :
// Collection of routines to facilitate
// the addition of simple push button boxes,
// and slider bars to the control panel.
//
// See G4OpenGLXmConvenienceRoutines.hh for more information.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
//#include "G4OpenGLXmConvenienceRoutines.hh"
#include "G4OpenGLXmView.hh"
void G4OpenGLXmView::Add_four_arrow_buttons (G4OpenGLXmView* pView,
XtCallbackRec** arrow_callbacks,
Widget* parent_widget) {
Widget arrow_form = XtVaCreateWidget
("arrow_form",
xmFormWidgetClass,
*parent_widget,
XmNfractionBase, 3,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
Widget arrow = XtVaCreateManagedWidget
("up_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 0,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 1,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 1,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 2,
XmNarrowDirection, XmARROW_UP,
NULL);
XtVaSetValues (arrow,
XmNuserData, True,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
arrow_callbacks[0]);
XtAddCallbacks (arrow,
XmNarmCallback,
arrow_callbacks[0]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
arrow_callbacks[0]);
arrow = XtVaCreateManagedWidget
("down_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 2,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 3,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 1,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 2,
XmNarrowDirection, XmARROW_DOWN,
NULL);
XtVaSetValues (arrow,
XmNuserData, False,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
arrow_callbacks[1]);
XtAddCallbacks (arrow,
XmNarmCallback,
arrow_callbacks[1]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
arrow_callbacks[1]);
arrow = XtVaCreateManagedWidget
("left_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 1,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 2,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 0,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 1,
XmNarrowDirection, XmARROW_LEFT,
NULL);
XtVaSetValues (arrow,
XmNuserData, False,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
arrow_callbacks[2]);
XtAddCallbacks (arrow,
XmNarmCallback,
arrow_callbacks[2]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
arrow_callbacks[2]);
arrow = XtVaCreateManagedWidget
("right_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 1,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 2,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 2,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 3,
XmNarrowDirection, XmARROW_RIGHT,
NULL);
XtVaSetValues (arrow,
XmNuserData, True,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
arrow_callbacks[3]);
XtAddCallbacks (arrow,
XmNarmCallback,
arrow_callbacks[3]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
arrow_callbacks[3]);
XtManageChild (arrow_form);
}
void G4OpenGLXmView::Add_radio_box (char* label_string,
Widget* parent_widget,
XtCallbackRec* radio_box_callback,
G4int num_buttons,
G4int default_button,
char* radio_box_name,
char** button_names,
G4OpenGLXmView* pView)
{
XmString button_str;
Arg** args;
args = new Arg* [num_buttons];
Widget button;
G4int i;
for (i = 0; i < num_buttons; i++) {
args[i] = new Arg[7];
button_str = XmStringCreateLocalized (button_names[i]);
XtSetArg (args[i][0], XtNvisual, pView->vi->visual);
XtSetArg (args[i][1], XtNdepth, pView->vi->depth);
XtSetArg (args[i][2], XtNcolormap, pView->cmap);
XtSetArg (args[i][3], XtNborderColor, pView->borcol);
XtSetArg (args[i][4], XtNbackground, pView->bgnd);
XtSetArg (args[i][5], XmNlabelString, button_str);
if (i == default_button) {
XtSetArg (args[i][6], XmNset, True);
} else {
XtSetArg (args[i][6], XmNset, False);
}
}
Widget radio_box = XtVaCreateWidget (radio_box_name,
xmRowColumnWidgetClass,
*parent_widget,
XmNisHomogeneous, False,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, pView,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
XmString lab = XmStringCreateLocalized (label_string);
Widget label = XtVaCreateManagedWidget ("radio_label",
xmLabelWidgetClass,
radio_box,
XmNalignment, XmALIGNMENT_CENTER,
XmNlabelString, lab,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
XmStringFree (lab);
for (i = 0; i < num_buttons; i++) {
button = XtCreateManagedWidget (button_names[i],
xmToggleButtonWidgetClass,
radio_box,
args[i],
7);
XtVaSetValues (button,
XmNuserData, i,
NULL);
XtAddCallbacks (button,
XmNarmCallback,
radio_box_callback);
}
XtManageChild (radio_box);
XmStringFree (button_str);
for (i = 0; i < num_buttons; i++) {
delete[] args[i];
}
delete[] args;
}
void G4OpenGLXmView::Add_set_field (char* w_name,
char* w_text,
Widget* row_col_box,
Widget* wid,
G4double* val,
G4OpenGLXmView* pView)
{
char local_w_text[50];
strcpy (local_w_text, w_text);
char label_name[50];
strcpy (label_name, w_name);
strcat (label_name, "_label");
char text_field_name[50];
strcpy (text_field_name, w_name);
strcat (text_field_name, "_text_field");
XmString local_text = XmStringCreateLocalized (local_w_text);
Widget label = XtVaCreateManagedWidget (label_name,
xmLabelWidgetClass,
*row_col_box,
XmNlabelString, local_text,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
XmStringFree (local_text);
char initial[50];
sprintf (initial, "%6.2f\0", *val);
*wid = XtVaCreateManagedWidget (text_field_name,
xmTextFieldWidgetClass,
*row_col_box,
XmNvalue, (String)initial,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
XtAddCallback (*wid,
XmNvalueChangedCallback,
G4OpenGLXmView::get_double_value_callback,
val);
Widget sep = XtVaCreateManagedWidget ("sep",
xmSeparatorWidgetClass,
*row_col_box,
XmNorientation, XmHORIZONTAL,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
sep = XtVaCreateManagedWidget ("sep",
xmSeparatorWidgetClass,
*row_col_box,
XmNseparatorType, XmNO_LINE,
XmNmargin, 1,
XmNorientation, XmHORIZONTAL,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
}
void G4OpenGLXmView::Add_slider_box (char* label_string,
G4int num_sliders,
char** slider_names,
G4OpenGLXmView* pView,
G4double* min_array,
G4double* max_array,
G4double* value_array,
G4bool* show,
short* decimals,
unsigned char* orientation,
unsigned char* direction,
XtCallbackRec** slider_box_callbacks,
Widget* parent_widget)
{
XmString slider_name_str;
Arg** slider_args;
slider_args = new Arg*[num_sliders];
Widget slider;
G4int j = 0;
G4int i;
for (i = 0; i < num_sliders; i++) {
j = 0;
slider_args[i] = new Arg[13];
slider_name_str = XmStringCreateLtoR (slider_names[i],
XmFONTLIST_DEFAULT_TAG);
XtSetArg (slider_args[i][j],
XtNvisual, pView->vi->visual); j++;
XtSetArg (slider_args[i][j],
XtNdepth, pView->vi->depth); j++;
XtSetArg (slider_args[i][j],
XtNcolormap, pView->cmap); j++;
XtSetArg (slider_args[i][j],
XtNborderColor, pView->borcol); j++;
XtSetArg (slider_args[i][j],
XtNbackground, pView->bgnd); j++;
XtSetArg (slider_args[i][j],
XmNtitleString, slider_name_str); j++;
XtSetArg (slider_args[i][j],
XmNmaximum, G4int(max_array[i] * pow(10.0, (G4double)decimals[i]))); j++;
XtSetArg (slider_args[i][j],
XmNminimum, G4int(min_array[i] * pow(10.0, (G4double)decimals[i]))); j++;
XtSetArg (slider_args[i][j],
XmNvalue, G4int(value_array[i] * pow(10.0, (G4double)decimals[i]))); j++;
XtSetArg (slider_args[i][j],
XmNshowValue, show[i]); j++;
XtSetArg (slider_args[i][j],
XmNdecimalPoints, decimals[i]); j++;
XtSetArg (slider_args[i][j],
XmNorientation, orientation[i]); j++;
XtSetArg (slider_args[i][j],
XmNprocessingDirection, direction[i]); j++;
}
Widget slider_box = XtVaCreateWidget ("slider_box",
xmRowColumnWidgetClass,
*parent_widget,
XmNisHomogeneous, False,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
XmString lab = XmStringCreateLocalized (label_string);
Widget label = XtVaCreateManagedWidget ("slider_label",
xmLabelWidgetClass,
slider_box,
XmNlabelString, lab,
XmNalignment, XmALIGNMENT_CENTER,
XtNvisual, pView->vi->visual,
XtNdepth, pView->vi->depth,
XtNcolormap, pView->cmap,
XtNborderColor, pView->borcol,
XtNbackground, pView->bgnd,
NULL);
XmStringFree (lab);
for (i = 0; i < num_sliders; i++) {
slider = XtCreateManagedWidget (slider_names[i],
xmScaleWidgetClass,
slider_box,
slider_args[i],
j);
XtAddCallbacks (slider,
XmNvalueChangedCallback,
slider_box_callbacks[i]);
XtAddCallbacks (slider,
XmNdragCallback,
slider_box_callbacks[i]);
}
XtManageChild (slider_box);
XmStringFree (slider_name_str);
for (i = 0; i < num_sliders; i++) {
delete[] slider_args[i];
}
delete[] slider_args;
}
void G4OpenGLXmView::get_double_value_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4double* val = (G4double*) clientData;
String string;
XtVaGetValues (w,
XmNvalue, &string,
NULL);
sscanf (string, "%lg", val);
}
void G4OpenGLXmView::get_text_callback (Widget w,
XtPointer clientData,
XtPointer)
{
char* txt = (char*)clientData;
String string;
XtVaGetValues (w,
XmNvalue, &string,
NULL);
sscanf (string, "%s", txt);
}
G4bool G4OpenGLXmView::get_boolean_userData (Widget w)
{
XtPointer userData;
XtVaGetValues (w,XmNuserData,&userData,NULL);
return (G4bool)(unsigned long)userData;
}
G4int G4OpenGLXmView::get_int_userData (Widget w)
{
XtPointer userData;
XtVaGetValues (w,XmNuserData,&userData,NULL);
return (G4int)(unsigned long)userData;
}
#endif
@@ -0,0 +1,200 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmFourArrowButtons.cc,v 2.0 1998/07/02 16:46:37 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Four arrow buttons class. Inherits from G4OpenGLXmVWidgetComponent
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
#include "G4OpenGLXmFourArrowButtons.hh"
#include <X11/Intrinsic.h>
#include "globals.hh"
G4OpenGLXmFourArrowButtons::G4OpenGLXmFourArrowButtons (XtCallbackRec** c)
{
callback = c;
}
G4OpenGLXmFourArrowButtons::~G4OpenGLXmFourArrowButtons ()
{}
void G4OpenGLXmFourArrowButtons::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
{
pView = container->GetView ();
ProcesspView ();
parent = container->GetPointerToWidget ();
arrow_form = XtVaCreateManagedWidget
("arrow_form",
xmFormWidgetClass,
*parent,
XmNfractionBase, 3,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
///////////////`up' arrow///////////////
arrow = XtVaCreateManagedWidget
("up_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 0,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 1,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 1,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 2,
XmNarrowDirection, XmARROW_UP,
XmNuserData, True,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
callback[0]);
XtAddCallbacks (arrow,
XmNarmCallback,
callback[0]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
callback[0]);
///////////////`down' arrow///////////////
arrow = XtVaCreateManagedWidget
("down_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 2,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 3,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 1,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 2,
XmNarrowDirection, XmARROW_DOWN,
XmNuserData, False,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
callback[1]);
XtAddCallbacks (arrow,
XmNarmCallback,
callback[1]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
callback[1]);
///////////////`left' arrow///////////////
arrow = XtVaCreateManagedWidget
("left_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 1,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 2,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 0,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 1,
XmNarrowDirection, XmARROW_LEFT,
XmNuserData, False,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
callback[2]);
XtAddCallbacks (arrow,
XmNarmCallback,
callback[2]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
callback[2]);
///////////////`right' arrow///////////////
arrow = XtVaCreateManagedWidget
("right_arrow",
xmArrowButtonGadgetClass,
arrow_form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 1,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, 2,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 2,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 3,
XmNarrowDirection, XmARROW_RIGHT,
XmNuserData, True,
NULL);
XtAddCallbacks (arrow,
XmNactivateCallback,
callback[3]);
XtAddCallbacks (arrow,
XmNarmCallback,
callback[3]);
XtAddCallbacks (arrow,
XmNdisarmCallback,
callback[3]);
}
Widget* G4OpenGLXmFourArrowButtons::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmFourArrowButtons::GetPointerToWidget ()
{
return &arrow_form;
}
#endif
@@ -0,0 +1,84 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmFramedBox.cc,v 2.1 1998/07/13 17:11:45 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Framed box container class
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmBox.hh"
#include "G4OpenGLXmFramedBox.hh"
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetShell.hh"
G4OpenGLXmFramedBox::G4OpenGLXmFramedBox (char* n,
G4bool r) :
G4OpenGLXmBox (n, r)
{
frame = NULL;
}
G4OpenGLXmFramedBox::~G4OpenGLXmFramedBox ()
{}
void G4OpenGLXmFramedBox::AddChild (G4OpenGLXmVWidgetComponent* component)
{
component->AddYourselfTo(this);
Cardinal num_children;
XtVaGetValues (box_row_col,
XmNnumChildren, &num_children,
NULL);
// G4cout << name << " now parents " << num_children << " children." << endl;
}
void G4OpenGLXmFramedBox::AddYourselfTo (G4OpenGLXmVWidgetShell* window)
{
pView = window->GetView ();
ProcesspView ();
char framename[50];
strcpy (framename, name);
strcat (framename, "_frame");
parent = window->GetPointerToWidget ();
frame = XtVaCreateManagedWidget (framename,
xmFrameWidgetClass,
*parent,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
box_row_col = XtVaCreateManagedWidget (name,
xmRowColumnWidgetClass,
frame,
XmNadjustMargin, True,
XmNisHomogeneous, False,
XmNlabelString, (XmString)name,
XmNradioAlwaysOne, radio,
XmNradioBehavior, radio,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
}
#endif
@@ -0,0 +1,566 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmMainMenubarCallbacks.cc,v 2.4 1998/10/04 11:34:00 ajw Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 16th April 1997
// G4OpenGLXmMainMenubarCallbacks :
// Collection of callback functions
// to handle events generated by the
// main OpenGLXm window menubar.
//
// See G4OpenGLXmMainMenubarCallbacks.hh for more information.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4Xt.hh"
#include "G4OpenGLXmView.hh"
#include "G4OpenGLXmRadioButton.hh"
#include "G4OpenGLXmSliderBar.hh"
#include "G4OpenGLXmFourArrowButtons.hh"
#include "G4OpenGLXmTextField.hh"
#include "G4OpenGLXmPushButton.hh"
#include "G4OpenGLXmBox.hh"
#include "G4OpenGLXmFramedBox.hh"
#include "G4OpenGLXmTopLevelShell.hh"
#include "G4OpenGLXmSeparator.hh"
#ifdef WIN32
#include <strstrea.h>
#else
#include <strstream.h>
#endif
void G4OpenGLXmView::actions_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView;
G4long choice = (G4long)clientData;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
switch (choice) {
case 0:
{
if (!pView->fprotation_top) {
const int rot_len = 50;
char* frot_Name = new char [rot_len];
ostrstream rot_ost (frot_Name, rot_len);
rot_ost.seekp (ios::beg);
rot_ost << pView->GetScene()->GetSceneId() << '-' << pView->fViewId << ends;
pView->fprotation_top = new G4OpenGLXmTopLevelShell (pView,
frot_Name);
pView->fprotation_button_box = new G4OpenGLXmBox ("Rotation button box", True);
pView->fprotation_top->AddChild (pView->fprotation_button_box);
XtCallbackRec* rot_cb_list = new XtCallbackRec[2];
rot_cb_list[0].callback = G4OpenGLXmView::set_rot_subject_callback;
rot_cb_list[0].closure = pView;
rot_cb_list[1].callback = NULL;
pView->fprotation_button1 = new G4OpenGLXmRadioButton ("Object",
rot_cb_list,
True,
0);
pView->fprotation_button2 = new G4OpenGLXmRadioButton ("Camera",
rot_cb_list,
False,
1);
pView->fprotation_button_box->AddChild (pView->fprotation_button1);
pView->fprotation_button_box->AddChild (pView->fprotation_button2);
pView->fprotation_slider_box = new G4OpenGLXmBox ("Rotation slider box", False);
pView->fprotation_top->AddChild (pView->fprotation_slider_box);
XtCallbackRec* rot_slider_list = new XtCallbackRec[2];
rot_slider_list[0].callback = G4OpenGLXmView::set_rot_sens_callback;
rot_slider_list[0].closure = pView;
rot_slider_list[1].callback = NULL;
pView->fprotation_slider = new G4OpenGLXmSliderBar ("Rotation slider",
rot_slider_list,
True,
2,
pView->rot_sens,
pView->rot_sens_limit,
0);
pView->fprotation_slider_box->AddChild (pView->fprotation_slider);
pView->fprotation_arrow_box = new G4OpenGLXmBox ("Rotation arrow box", False);
pView->fprotation_top->AddChild (pView->fprotation_arrow_box);
XtCallbackRec** rotation_callbacks = new XtCallbackRec*[4];
for (G4int i = 0; i < 4; i++) {
rotation_callbacks[i] = new XtCallbackRec[2];
}
rotation_callbacks[0][0].callback = G4OpenGLXmView::phi_rotation_callback;
rotation_callbacks[0][0].closure = pView;
rotation_callbacks[0][1].callback = NULL;
rotation_callbacks[1][0].callback = G4OpenGLXmView::phi_rotation_callback;
rotation_callbacks[1][0].closure = pView;
rotation_callbacks[1][1].callback = NULL;
rotation_callbacks[2][0].callback = G4OpenGLXmView::theta_rotation_callback;
rotation_callbacks[2][0].closure = pView;
rotation_callbacks[2][1].callback = NULL;
rotation_callbacks[3][0].callback = G4OpenGLXmView::theta_rotation_callback;
rotation_callbacks[3][0].closure = pView;
rotation_callbacks[3][1].callback = NULL;
pView->fprotation_arrow = new G4OpenGLXmFourArrowButtons (rotation_callbacks);
pView->fprotation_arrow_box->AddChild (pView->fprotation_arrow);
pView->fprotation_top->Realize ();
}
break;
}
case 1:
{
if (!pView->fppanning_top) {
const int pan_len = 50;
char* fpan_Name = new char [pan_len];
ostrstream pan_ost (fpan_Name, pan_len);
pan_ost.seekp (ios::beg);
pan_ost << pView->GetScene()->GetSceneId() << '-' << pView->fViewId << ends;
pView->fppanning_top = new G4OpenGLXmTopLevelShell (pView,
fpan_Name);
pView->fppanning_box = new G4OpenGLXmFramedBox ("Pan up-down-left-right",
False);
pView->fppanning_top->AddChild (pView->fppanning_box);
XtCallbackRec** pan_callbacks = new XtCallbackRec*[4];
for (G4int i = 0; i < 4; i++) {
pan_callbacks[i] = new XtCallbackRec[2];
}
pan_callbacks[0][0].callback = G4OpenGLXmView::pan_up_down_callback;
pan_callbacks[0][0].closure = pView;
pan_callbacks[0][1].callback = NULL;
pan_callbacks[1][0].callback = G4OpenGLXmView::pan_up_down_callback;
pan_callbacks[1][0].closure = pView;
pan_callbacks[1][1].callback = NULL;
pan_callbacks[2][0].callback = G4OpenGLXmView::pan_left_right_callback;
pan_callbacks[2][0].closure = pView;
pan_callbacks[2][1].callback = NULL;
pan_callbacks[3][0].callback = G4OpenGLXmView::pan_left_right_callback;
pan_callbacks[3][0].closure = pView;
pan_callbacks[3][1].callback = NULL;
pView->fppanning_arrows = new G4OpenGLXmFourArrowButtons (pan_callbacks);
pView->fppanning_box->AddChild (pView->fppanning_arrows);
XtCallbackRec* pan_slider_list = new XtCallbackRec[2];
pan_slider_list[0].callback = G4OpenGLXmView::set_pan_sens_callback;
pan_slider_list[0].closure = pView;
pan_slider_list[1].callback = NULL;
pView->fppanning_slider = new G4OpenGLXmSliderBar ("Panning slider",
pan_slider_list,
True,
2,
pView->pan_sens = pView->GetScene()->GetSceneData().GetExtent().GetExtentRadius() / 10.0,
pView->pan_sens_limit = pView->GetScene()->GetSceneData().GetExtent().GetExtentRadius(),
0);
pView->fppanning_box->AddChild (pView->fppanning_slider);
pView->fpzoom_box = new G4OpenGLXmFramedBox ("Zoom",
False);
pView->fppanning_top->AddChild (pView->fpzoom_box);
XtCallbackRec* zoom_slider_list = new XtCallbackRec[2];
zoom_slider_list[0].callback = G4OpenGLXmView::zoom_callback;
zoom_slider_list[0].closure = pView;
zoom_slider_list[1].callback = NULL;
pView->fpzoom_slider = new G4OpenGLXmSliderBar ("Zoom slider",
zoom_slider_list,
True,
2,
pView->fVP.GetZoomFactor(),
pView->zoom_high,
pView->zoom_low);
pView->fpzoom_box->AddChild (pView->fpzoom_slider);
pView->fpdolly_box = new G4OpenGLXmFramedBox ("Dolly",
False);
pView->fppanning_top->AddChild (pView->fpdolly_box);
XtCallbackRec* dolly_slider_list = new XtCallbackRec[2];
dolly_slider_list[0].callback = G4OpenGLXmView::dolly_callback;
dolly_slider_list[0].closure = pView;
dolly_slider_list[1].callback = NULL;
pView->fpdolly_slider = new G4OpenGLXmSliderBar ("Dolly slider",
dolly_slider_list,
True,
2,
pView->fVP.GetDolly(),
pView->dolly_high = pView->GetScene()->GetSceneData().GetExtent().GetExtentRadius(),
pView->dolly_low = -(pView->GetScene()->GetSceneData().GetExtent().GetExtentRadius()));
// pView->dolly_high,
// pView->dolly_low);
pView->fpdolly_box->AddChild (pView->fpdolly_slider);
pView->fppanning_top->Realize ();
}
break;
}
case 2:
{
if (!pView->fpsetting_top) {
const int set_len = 50;
char* fset_Name = new char [set_len];
ostrstream set_ost (fset_Name, set_len);
set_ost.seekp (ios::beg);
set_ost << pView->GetScene()->GetSceneId() << '-' << pView->fViewId << ends;
pView->fpsetting_top = new G4OpenGLXmTopLevelShell(pView,
fset_Name);
pView->fpsetting_box = new G4OpenGLXmFramedBox ("Set values for control panels",
False);
pView->fpsetting_top->AddChild (pView->fpsetting_box);
pView->fppan_set = new G4OpenGLXmTextField ("Upper limit of pan sensitivity",
&(pView->pan_sens_limit));
pView->fprot_set = new G4OpenGLXmTextField ("Upper limit of rotation sensitivity",
&(pView->rot_sens_limit));
pView->fpzoom_upper = new G4OpenGLXmTextField ("Upper limit of zoom",
&(pView->zoom_high));
pView->fpzoom_lower = new G4OpenGLXmTextField ("Lower limit of zoom",
&(pView->zoom_low));
pView->fpdolly_upper = new G4OpenGLXmTextField ("Upper limit of dolly",
&(pView->dolly_high));
pView->fpdolly_lower = new G4OpenGLXmTextField ("Lower limit of dolly",
&(pView->dolly_low));
XtCallbackRec* ok_list = new XtCallbackRec[2];
ok_list[0].callback = G4OpenGLXmView::update_panels_callback;
ok_list[0].closure = pView;
ok_list[1].callback = NULL;
pView->fpok_button = new G4OpenGLXmPushButton ("ok",
ok_list);
pView->fpsetting_box->AddChild (pView->fppan_set);
pView->fpsetting_box->AddChild (pView->fprot_set);
pView->fpsetting_box->AddChild (pView->fpzoom_upper);
pView->fpsetting_box->AddChild (pView->fpzoom_lower);
pView->fpsetting_box->AddChild (pView->fpdolly_upper);
pView->fpsetting_box->AddChild (pView->fpdolly_lower);
pView->fpsetting_box->AddChild (pView->fpok_button);
pView->fpsetting_top->Realize ();
}
break;
}
default:
G4Exception("Unrecognised widget child of control_callback");
}
return;
}
void G4OpenGLXmView::misc_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView;
G4long choice = (G4long)clientData;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
switch (choice) {
case 0:
{
if (!pView->fpmiscellany_top) {
const int misc_len = 50;
char* fmisc_Name = new char [misc_len];
ostrstream misc_ost (fmisc_Name, misc_len);
misc_ost.seekp (ios::beg);
misc_ost << pView->GetScene()->GetSceneId() << '-' << pView->fViewId << ends;
pView->fpmiscellany_top = new G4OpenGLXmTopLevelShell (pView,
fmisc_Name);
pView->fpwobble_box = new G4OpenGLXmFramedBox ("Wobble view",
True);
pView->fpmiscellany_top->AddChild (pView->fpwobble_box);
XtCallbackRec* wob_cb_list = new XtCallbackRec[2];
wob_cb_list[0].callback = G4OpenGLXmView::wobble_callback;
wob_cb_list[0].closure = pView;
wob_cb_list[1].callback = NULL;
pView->fpwobble_button = new G4OpenGLXmPushButton ("Wobble",
wob_cb_list);
XtCallbackRec* wobble_slider_list = new XtCallbackRec[2];
wobble_slider_list[0].callback = G4OpenGLXmView::set_wob_sens_callback;
wobble_slider_list[0].closure = pView;
wobble_slider_list[1].callback = NULL;
pView->fpwobble_slider = new G4OpenGLXmSliderBar ("Wobble slider",
wobble_slider_list,
True,
0,
20,
50,
0);
pView->fpwobble_box->AddChild (pView->fpwobble_button);
pView->fpwobble_box->AddChild (pView->fpwobble_slider);
pView->fpreset_box = new G4OpenGLXmFramedBox ("Reset view",
True);
pView->fpmiscellany_top->AddChild (pView->fpreset_box);
XtCallbackRec* rst_cb_list = new XtCallbackRec[3];
rst_cb_list[0].callback = G4OpenGLXmView::reset_callback;
rst_cb_list[0].closure = pView;
rst_cb_list[1].callback = G4OpenGLXmView::update_panels_callback;
rst_cb_list[1].closure = pView;
rst_cb_list[2].callback = NULL;
pView->fpreset_button = new G4OpenGLXmPushButton ("Reset",
rst_cb_list);
pView->fpreset_box->AddChild (pView->fpreset_button);
pView->fpproj_style_box = new G4OpenGLXmFramedBox ("Projection style",
True);
pView->fpmiscellany_top->AddChild (pView->fpproj_style_box);
XtCallbackRec* proj_cb_list = new XtCallbackRec[2];
proj_cb_list[0].callback = G4OpenGLXmView::projection_callback;
proj_cb_list[0].closure = pView;
proj_cb_list[1].callback = NULL;
pView->fporthogonal_button = new G4OpenGLXmRadioButton ("Orthographic",
proj_cb_list,
pView->fVP.GetFieldHalfAngle() > 0. ? False : True,
0);
pView->fpperspective_button = new G4OpenGLXmRadioButton ("Perspective",
proj_cb_list,
pView->fVP.GetFieldHalfAngle() > 0. ? True : False,
1);
pView->fpfov_text = new G4OpenGLXmTextField ("Field of view 0.1 -> 89.5 degrees.",
&(pView->fov));
pView->fpproj_style_box->AddChild (pView->fpperspective_button);
pView->fpproj_style_box->AddChild (pView->fporthogonal_button);
pView->fpproj_style_box->AddChild (pView->fpfov_text);
pView->fpmiscellany_top->Realize ();
}
break;
}
case 1:
{
G4Xt::getInstance () -> RequireExitSecondaryLoop (OGL_EXIT_CODE);
break;
}
case 2:
{
if (!pView->fpprint_top) {
const int print_len = 50;
char* fprint_Name = new char [print_len];
ostrstream print_ost (fprint_Name, print_len);
print_ost.seekp (ios::beg);
print_ost << pView->GetScene()->GetSceneId() << '-' << pView->fViewId << ends;
pView->fpprint_top = new G4OpenGLXmTopLevelShell (pView,
fprint_Name);
pView->fpprint_box = new G4OpenGLXmFramedBox ("Create EPS file of current view",
False);
pView->fpprint_top->AddChild (pView->fpprint_box);
pView->fpprint_col_box = new G4OpenGLXmFramedBox ("Colour choice",
True);
pView->fpprint_top->AddChild (pView->fpprint_col_box);
XtCallbackRec* prcol_cb_list = new XtCallbackRec[2];
prcol_cb_list[0].callback = G4OpenGLXmView::set_print_colour_callback;
prcol_cb_list[0].closure = pView;
prcol_cb_list[1].callback = NULL;
pView->fpprint_col_radio1 = new G4OpenGLXmRadioButton ("Black and white",
prcol_cb_list,
pView->print_colour==false ? True : False,
0);
pView->fpprint_col_radio2 = new G4OpenGLXmRadioButton ("Colour",
prcol_cb_list,
pView->print_colour==true ? True : False,
1);
pView->fpprint_col_box->AddChild (pView->fpprint_col_radio1);
pView->fpprint_col_box->AddChild (pView->fpprint_col_radio2);
pView->fpprint_style_box = new G4OpenGLXmFramedBox ("File type",
True);
pView->fpprint_top->AddChild (pView->fpprint_style_box);
XtCallbackRec* prsty_cb_list = new XtCallbackRec[2];
prsty_cb_list[0].callback = G4OpenGLXmView::set_print_style_callback;
prsty_cb_list[0].closure = pView;
prsty_cb_list[1].callback = NULL;
pView->fpprint_style_radio1 = new G4OpenGLXmRadioButton ("Screen dump (pixmap)",
prsty_cb_list,
pView->vectored_ps==false ? True : False,
0);
pView->fpprint_style_radio2 = new G4OpenGLXmRadioButton ("PostScript",
prsty_cb_list,
pView->vectored_ps==true ? True : False,
1);
pView->fpprint_style_box->AddChild (pView->fpprint_style_radio1);
pView->fpprint_style_box->AddChild (pView->fpprint_style_radio2);
pView->fpprint_text = new G4OpenGLXmTextField ("Name of .eps file to save",
(pView->print_string));
pView->fpprint_box->AddChild (pView->fpprint_text);
pView->fpprint_line = new G4OpenGLXmSeparator ();
pView->fpprint_box->AddChild (pView->fpprint_line);
XtCallbackRec* pri_cb_list = new XtCallbackRec[2];
pri_cb_list[0].callback = G4OpenGLXmView::print_callback;
pri_cb_list[0].closure = pView;
pri_cb_list[1].callback = NULL;
pView->fpprint_button = new G4OpenGLXmPushButton ("Create EPS file",
pri_cb_list);
pView->fpprint_box->AddChild (pView->fpprint_button);
pView->fpprint_top->Realize ();
}
///ajw
break;
}
default:
G4Exception("Unrecognised widget child of misc_callback.");
}
return;
}
void G4OpenGLXmView::set_wob_sens_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
short dp = -1;
G4float ten_to_the_dp = 10.;
XtVaGetValues (w,
XmNdecimalPoints, &dp,
NULL);
if (dp == 0) {
ten_to_the_dp = 1.;
} else if ( dp > 0) {
for (G4int i = 1; i < (G4int)dp; i++) {
ten_to_the_dp *= 10.;
}
} else {
G4Exception("Bad value returned for dp in set_rot_sens_callback");
}
pView->wob_sens = (G4float)(cbs->value) / ten_to_the_dp;
}
void G4OpenGLXmView::update_panels_callback (Widget,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
if (pView->fppanning_slider) {
pView->fppanning_slider->SetMaxValue (pView->pan_sens_limit);
}
if (pView->fprotation_slider) {
pView->fprotation_slider->SetMaxValue (pView->rot_sens_limit);
}
if (pView->fpzoom_slider) {
pView->fpzoom_slider->SetMaxValue (pView->zoom_high);
pView->fpzoom_slider->SetMinValue (pView->zoom_low);
pView->fpzoom_slider->SetInitialValue (pView->fVP.GetZoomFactor());
}
if (pView->fpdolly_slider) {
pView->fpdolly_slider->SetMaxValue (pView->dolly_high);
pView->fpdolly_slider->SetMinValue (pView->dolly_low);
}
}
#endif
@@ -0,0 +1,221 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmPanningCallbacks.cc,v 2.3 1998/08/24 13:35:09 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 16th April 1997
// G4OpenGLXmPanningCallbacks :
// Several callback functions used by
// elements of the control panel to`pan'
// the view (i.e. move the viewpoint and
// camera positions by equal amounts).
// Zoom callback is also here.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmView.hh"
void G4OpenGLXmView::zoom_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
short dp = -1;
G4float ten_to_the_dp = 10.;
XtVaGetValues (w,
XmNdecimalPoints, &dp,
NULL);
if (dp == 0) {
ten_to_the_dp = 1.;
} else if ( dp > 0) {
for (G4int i = 1; i < (G4int)dp; i++) {
ten_to_the_dp *= 10.;
}
} else {
G4cout << "dp is " << dp << endl;
return;
}
G4double zoomBy = (G4double)(cbs->value) / ten_to_the_dp;
if (zoomBy <= 0.01) {
zoomBy = 0.01;
}
pView->fVP.SetZoomFactor (zoomBy);
pView->SetView ();
pView->ClearView ();
pView -> DrawView ();
}
void G4OpenGLXmView::dolly_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
short dp = -1;
G4float ten_to_the_dp = 10.;
XtVaGetValues (w,
XmNdecimalPoints, &dp,
NULL);
if (dp == 0) {
ten_to_the_dp = 1.;
} else if ( dp > 0) {
for (G4int i = 1; i < (G4int)dp; i++) {
ten_to_the_dp *= 10.;
}
} else {
G4cout << "dp is " << dp << endl;
return;
}
G4double dolly = (G4double)(cbs->value) / ten_to_the_dp;
pView->fVP.IncrementDolly (dolly);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::pan_left_right_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
pView->pan_right = G4OpenGLXmView::get_boolean_userData (w);
if (cbs->reason == XmCR_ARM) {
left_right_pan_callback (pView,NULL);
} else if (cbs->reason == XmCR_DISARM) {
XtRemoveTimeOut (pView->pan_timer);
}
}
void G4OpenGLXmView::left_right_pan_callback (XtPointer clientData,
XtIntervalId* timer_id)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
G4double delta;
if (pView->pan_right) {
delta = (G4double)pView->pan_sens;
} else {
delta = -((G4double)pView->pan_sens);
}
G4Point3D tp = pView -> fVP.GetCurrentTargetPoint ();
const G4Vector3D& upVector = pView->fVP.GetUpVector ();
const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
tp += delta * unitRight;
pView->fVP.SetCurrentTargetPoint (tp);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
pView->pan_timer = XtAppAddTimeOut
(pView->app,
timer_id == NULL ? 500 : 1,
left_right_pan_callback,
pView);
}
void G4OpenGLXmView::pan_up_down_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
pView->pan_up = G4OpenGLXmView::get_boolean_userData (w);
if (cbs->reason == XmCR_ARM) {
up_down_pan_callback (pView,NULL);
} else if (cbs->reason == XmCR_DISARM) {
XtRemoveTimeOut (pView->pan_timer);
}
}
void G4OpenGLXmView::up_down_pan_callback (XtPointer clientData,
XtIntervalId* timer_id)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
G4double delta;
if (pView->pan_up) {
delta = (G4double)pView->pan_sens;
} else {
delta = -((G4double)pView->pan_sens);
}
G4Point3D tp = pView->fVP.GetCurrentTargetPoint ();
const G4Vector3D& upVector = pView->fVP.GetUpVector ();
const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
tp += delta * unitUp;
pView->fVP.SetCurrentTargetPoint (tp);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
pView->pan_timer = XtAppAddTimeOut
(pView->app,
timer_id == NULL ? 500 : 1,
up_down_pan_callback,
pView);
}
void G4OpenGLXmView::set_pan_sens_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
short dp = -1;
G4float ten_to_the_dp = 10.;
XtVaGetValues (w,
XmNdecimalPoints, &dp,
NULL);
if (dp == 0) {
ten_to_the_dp = 1.;
} else if ( dp > 0) {
for (G4int i = 1; i < (G4int)dp; i++) {
ten_to_the_dp *= 10.;
}
} else {
G4cout << "dp is " << dp << endl;
return;
}
pView->pan_sens = (G4double)((cbs->value) / ten_to_the_dp);
}
#endif
@@ -0,0 +1,89 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmPushButton.cc,v 2.0 1998/07/02 16:46:47 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Push button class. Inherits from G4OpenGLXmVWidgetComponent
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
#include "G4OpenGLXmPushButton.hh"
#include <X11/Intrinsic.h>
#include "globals.hh"
G4OpenGLXmPushButton::G4OpenGLXmPushButton (char* n,
XtCallbackRec* c)
{
name = n;
callback = c;
}
G4OpenGLXmPushButton::~G4OpenGLXmPushButton ()
{}
void G4OpenGLXmPushButton::SetName (char* n)
{
name = n;
XmString button_string = XmStringCreateLocalized (name);
XtVaSetValues (button,
XmNlabelString, button_string,
NULL);
XmStringFree (button_string);
}
char* G4OpenGLXmPushButton::GetName ()
{
return name;
}
void G4OpenGLXmPushButton::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
{
pView = container->GetView ();
ProcesspView ();
parent = container->GetPointerToWidget ();
XmString button_str = XmStringCreateLocalized (name);
button = XtVaCreateManagedWidget
(name,
xmPushButtonWidgetClass,
*parent,
XmNlabelString, button_str,
XmNalignment, XmALIGNMENT_CENTER,
XmNuserData, pView,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XtAddCallbacks (button,
XmNarmCallback,
callback);
XmStringFree (button_str);
}
Widget* G4OpenGLXmPushButton::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmPushButton::GetPointerToWidget ()
{
return &button;
}
#endif
@@ -0,0 +1,90 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmRadioButton.cc,v 2.0 1998/07/02 16:46:49 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Radio button class. Inherits from G4OpenGLXmVWidgetComponent
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
#include "G4OpenGLXmRadioButton.hh"
#include <X11/Intrinsic.h>
#include "globals.hh"
G4OpenGLXmRadioButton::G4OpenGLXmRadioButton (char* n,
XtCallbackRec* c,
G4bool d,
G4int num)
{
name = n;
callback = c;
default_button = d;
number = num;
}
G4OpenGLXmRadioButton::~G4OpenGLXmRadioButton ()
{}
void G4OpenGLXmRadioButton::SetName (char* n)
{
name = n;
XmString button_string = XmStringCreateLocalized (name);
XtVaSetValues (button,
XmNlabelString, button_string,
NULL);
XmStringFree (button_string);
}
char* G4OpenGLXmRadioButton::GetName ()
{
return name;
}
void G4OpenGLXmRadioButton::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
{
pView = container->GetView ();
ProcesspView ();
parent = container->GetPointerToWidget ();
XmString button_string = XmStringCreateLocalized (name);
button = XtVaCreateManagedWidget (name,
xmToggleButtonWidgetClass,
*parent,
XmNlabelString, button_string,
XmNset, default_button,
XmNuserData, number,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XtAddCallbacks (button,
XmNarmCallback,
callback);
XmStringFree (button_string);
}
Widget* G4OpenGLXmRadioButton::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmRadioButton::GetPointerToWidget ()
{
return &button;
}
#endif
@@ -0,0 +1,280 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmRotationCallbacks.cc,v 2.4 1998/08/24 13:35:10 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 16th April 1997
// G4OpenGLXmRotationCallbacks :
// Several callback functions used by
// elements of the control panel to
// rotate the view.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmView.hh"
#include "G4UImanager.hh"
#include "G4ios.hh"
void G4OpenGLXmView::theta_rotation_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
pView->rotate_right = G4OpenGLXmView::get_boolean_userData (w);
if (cbs->reason == XmCR_ARM) {
G4OpenGLXmView::rotate_in_theta (pView, NULL);
} else if (cbs->reason == XmCR_DISARM) {
XtRemoveTimeOut (pView->rotation_timer);
}
}
void G4OpenGLXmView::rotate_in_theta (XtPointer clientData,
XtIntervalId* timer_id)
{
//theta spin stuff here
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
G4double delta_theta;
if (pView->fVP.GetLightsMoveWithCamera()) {
if (pView->rotate_right) {
delta_theta = -((G4double)pView->rot_sens);
} else {
delta_theta = (G4double)pView->rot_sens;
}
} else {
if (pView->rotate_right) {
delta_theta = (G4double)pView->rot_sens;
} else {
delta_theta = -((G4double)pView->rot_sens);
}
}
delta_theta *= deg;
// Rotates by fixed azimuthal angle delta_theta.
G4Vector3D vp = pView->fVP.GetViewpointDirection ().unit ();
G4Vector3D up = pView->fVP.GetUpVector ().unit ();
G4Vector3D& zprime = up;
G4double cosalpha = up.dot (vp);
G4double sinalpha = sqrt (1. - pow (cosalpha, 2));
G4Vector3D viewPoint = pView->fVP.GetViewpointDirection ().unit ();
G4Vector3D yprime = (zprime.cross (viewPoint)).unit ();
G4Vector3D xprime = yprime.cross (zprime);
// Projection of vp on plane perpendicular to up...
G4Vector3D a1 = sinalpha * xprime;
// Required new projection...
G4Vector3D a2 =
sinalpha * (cos (delta_theta) * xprime + sin (delta_theta) * yprime);
// Required Increment vector...
G4Vector3D delta = a2 - a1;
// So new viewpoint is...
viewPoint += delta;
pView->fVP.SetViewAndLights (viewPoint);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
pView->rotation_timer = XtAppAddTimeOut
(pView->app,
timer_id == NULL ? 500 : 1,
G4OpenGLXmView::rotate_in_theta,
pView);
}
void G4OpenGLXmView::phi_rotation_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
pView->rotate_up = G4OpenGLXmView::get_boolean_userData (w);
if (cbs->reason == XmCR_ARM) {
G4OpenGLXmView::rotate_in_phi (pView, NULL);
} else if (cbs->reason == XmCR_DISARM) {
XtRemoveTimeOut (pView->rotation_timer);
}
}
void G4OpenGLXmView::rotate_in_phi (XtPointer clientData,
XtIntervalId* timer_id)
{
//phi spin stuff here
G4double delta_alpha;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
if (pView->fVP.GetLightsMoveWithCamera()) {
if (pView -> rotate_up) {
delta_alpha = -((G4double)pView->rot_sens);
} else {
delta_alpha = (G4double)pView->rot_sens;
}
} else {
if (pView -> rotate_up) {
delta_alpha = (G4double)pView->rot_sens;
} else {
delta_alpha = -((G4double)pView->rot_sens);
}
}
delta_alpha *= deg;
G4Vector3D vp = pView->fVP.GetViewpointDirection ().unit ();
G4Vector3D up = pView->fVP.GetUpVector ().unit ();
G4Vector3D xprime = vp;
G4Vector3D yprime = (up.cross(xprime)).unit();
G4Vector3D zprime = (xprime.cross(yprime)).unit();
G4Vector3D new_vp = cos(delta_alpha) * xprime + sin(delta_alpha) * zprime;
pView->fVP.SetViewAndLights (new_vp.unit());
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
pView->rotation_timer = XtAppAddTimeOut
(pView->app,
timer_id == NULL ? 500 : 1,
G4OpenGLXmView::rotate_in_phi,
pView);
}
void G4OpenGLXmView::set_rot_sens_callback (Widget w,
XtPointer clientData,
XtPointer callData)
{
XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
short dp = -1;
G4float ten_to_the_dp = 10.;
XtVaGetValues (w,
XmNdecimalPoints, &dp,
NULL);
if (dp == 0) {
ten_to_the_dp = 1.;
} else if ( dp > 0) {
for (G4int i = 1; i < (G4int)dp; i++) {
ten_to_the_dp *= 10.;
}
} else {
G4Exception("Bad value returned for dp in set_rot_sens_callback");
}
pView->rot_sens = (G4float)(cbs->value) / ten_to_the_dp;
}
void G4OpenGLXmView::set_rot_subject_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*)clientData;
G4int choice = G4OpenGLXmView::get_int_userData (w);
switch (choice) {
case 0:
{
pView->fVP.SetLightsMoveWithCamera (true);
break;
}
case 1:
{
pView->fVP.SetLightsMoveWithCamera (false);
break;
}
default:
{
G4Exception("Unrecognised choice made in set_rot_subject_callback");
}
}
}
void G4OpenGLXmView::wobble_callback (Widget w,
XtPointer,
XtPointer)
{
G4OpenGLXmView* pView;
XtVaGetValues (w,
XmNuserData, &pView,
NULL);
pView->original_vp = pView->fVP.GetViewpointDirection();
pView->wobble_timer = XtAppAddTimeOut (pView->app,
1000. * (1. / pView->wob_sens),
G4OpenGLXmView::wobble_timer_callback,
pView);
}
void G4OpenGLXmView::wobble_timer_callback (XtPointer clientData,
XtIntervalId*)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*)clientData;
G4Vector3D up = pView->fVP.GetUpVector();
G4Vector3D vp = pView->fVP.GetViewpointDirection();
G4Vector3D third_axis = up.cross(pView->original_vp);
G4double pi_div_by_ten = M_PI / 10.0;
G4Vector3D d_up = 0.1 * (sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
G4Vector3D d_third_axis = 0.1 * (sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
if (pView->frameNo++ == 20) {
if (pView->wobble_timer) {
XtRemoveTimeOut (pView->wobble_timer);
pView->frameNo = 0;
pView->fVP.SetViewAndLights (pView->original_vp);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
} else {
pView->wobble_timer = XtAppAddTimeOut (pView->app,
1000. * (1. / pView->wob_sens),
G4OpenGLXmView::wobble_timer_callback,
pView);
}
}
void G4OpenGLXmView::reset_callback (Widget w,
XtPointer,
XtPointer)
{
G4OpenGLXmView* pView;
XtVaGetValues (w,
XmNuserData, &pView,
NULL);
pView->fVP.SetCurrentTargetPoint(pView->fScene.GetSceneData().GetStandardTargetPoint());
pView->fVP.SetZoomFactor(1.0);
pView->fVP.SetDolly(0.0);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
pView->zoom_low = 0.1;
pView->zoom_high = 10.0;
}
#endif
@@ -0,0 +1,63 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmSeparator.cc,v 2.0 1998/07/02 16:46:53 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Separator class. Inherits from G4OpenGLXmVWidgetComponent
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
#include "G4OpenGLXmSeparator.hh"
#include <X11/Intrinsic.h>
#include "globals.hh"
G4OpenGLXmSeparator::G4OpenGLXmSeparator (unsigned char l)
{
line_type = l;
}
G4OpenGLXmSeparator::~G4OpenGLXmSeparator ()
{}
void G4OpenGLXmSeparator::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
{
pView = container->GetView ();
ProcesspView ();
parent = container->GetPointerToWidget ();
line = XtVaCreateManagedWidget ("sep",
xmSeparatorWidgetClass,
*parent,
XmNseparatorType, line_type,
XmNmargin, 1,
XmNorientation, XmHORIZONTAL,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
}
Widget* G4OpenGLXmSeparator::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmSeparator::GetPointerToWidget ()
{
return &line;
}
#endif
@@ -0,0 +1,208 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmSliderBar.cc,v 2.0 1998/07/02 16:46:55 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Slider bar class. Inherits from G4OpenGLXmVWidgetComponent
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
#include "G4OpenGLXmSliderBar.hh"
#include <X11/Intrinsic.h>
#include <Xm/Scale.h>
#include "globals.hh"
G4OpenGLXmSliderBar::G4OpenGLXmSliderBar (char* n,
XtCallbackRec* c,
G4bool s,
short dp,
G4double v,
G4double max,
G4double min,
unsigned char o,
unsigned char d)
{
name = n;
callback = c;
show = s;
decimal_places = dp;
initial_value = int(v * pow(10.0, (G4double)dp));
max_value = int(max * pow(10.0, (G4double)dp));
min_value = int(min * pow(10.0, (G4double)dp));
orientation = o;
direction = d;
}
G4OpenGLXmSliderBar::~G4OpenGLXmSliderBar ()
{}
char* G4OpenGLXmSliderBar::GetName ()
{
return name;
}
G4bool G4OpenGLXmSliderBar::GetShow ()
{
return show;
}
short G4OpenGLXmSliderBar::GetDecimalPlaces ()
{
return decimal_places;
}
G4double G4OpenGLXmSliderBar::GetInitialValue ()
{
return (G4double)initial_value / pow(10.0, (G4double)GetDecimalPlaces());
}
G4double G4OpenGLXmSliderBar::GetMaxValue ()
{
return (G4double)max_value / pow(10.0, (G4double)GetDecimalPlaces());
}
G4double G4OpenGLXmSliderBar::GetMinValue ()
{
return (G4double)min_value / pow(10.0, (G4double)GetDecimalPlaces());
}
unsigned char G4OpenGLXmSliderBar::GetOrientation ()
{
return orientation;
}
unsigned char G4OpenGLXmSliderBar::GetDirection ()
{
return direction;
}
void G4OpenGLXmSliderBar::SetName (char* n)
{
name = n;
XmString sliderbar_string = XmStringCreateLocalized (name);
XtVaSetValues (sliderbar,
XmNlabelString, sliderbar_string,
NULL);
XmStringFree (sliderbar_string);
}
void G4OpenGLXmSliderBar::SetShow (G4bool s)
{
show = s;
XtVaSetValues (sliderbar,
XmNshowValue, show,
NULL);
}
void G4OpenGLXmSliderBar::SetDecimalPlaces (short dp)
{
decimal_places = dp;
XtVaSetValues (sliderbar,
XmNdecimalPoints, decimal_places,
NULL);
}
void G4OpenGLXmSliderBar::SetInitialValue (G4double v)
{
initial_value = int(v * pow(10.0, (G4double)GetDecimalPlaces()));
XtVaSetValues (sliderbar,
XmNvalue, initial_value,
NULL);
}
void G4OpenGLXmSliderBar::SetMaxValue (G4double v)
{
max_value = int(v * pow(10.0, (G4double)GetDecimalPlaces()));
XtVaSetValues (sliderbar,
XmNmaximum, max_value,
NULL);
}
void G4OpenGLXmSliderBar::SetMinValue (G4double v)
{
min_value = int(v * pow(10.0, (G4double)GetDecimalPlaces()));
XtVaSetValues (sliderbar,
XmNminimum, min_value,
NULL);
}
void G4OpenGLXmSliderBar::SetOrientation (unsigned char o)
{
orientation = o;
XtVaSetValues (sliderbar,
XmNorientation, orientation,
NULL);
}
void G4OpenGLXmSliderBar::SetDirection (unsigned char d)
{
direction = d;
XtVaSetValues (sliderbar,
XmNprocessingDirection, direction,
NULL);
}
void G4OpenGLXmSliderBar::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
{
pView = container->GetView ();
ProcesspView ();
parent = container->GetPointerToWidget ();
XmString name_string = XmStringCreateLocalized (name);
sliderbar = XtVaCreateManagedWidget (name,
xmScaleWidgetClass,
*parent,
XmNtitleString, name_string,
XmNmaximum, max_value,
XmNminimum, min_value,
XmNvalue, initial_value,
XmNshowValue, show,
XmNdecimalPoints, decimal_places,
XmNorientation, orientation,
XmNprocessingDirection, direction,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XtAddCallbacks (sliderbar,
XmNvalueChangedCallback,
callback);
XtAddCallbacks (sliderbar,
XmNdragCallback,
callback);
XmStringFree (name_string);
}
Widget* G4OpenGLXmSliderBar::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmSliderBar::GetPointerToWidget ()
{
return &sliderbar;
}
#endif
@@ -0,0 +1,272 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmStyleCallbacks.cc,v 2.3 1998/10/11 15:58:24 ajw Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 16th April 1997
// G4OpenGLXmStyleCallbacks :
// Several callback functions used by
// elements of the control panel to
// determine how to visualize the view.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmView.hh"
void G4OpenGLXmView::drawing_style_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4long choice = (G4long)clientData;
G4OpenGLXmView* pView;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
G4ViewParameters::DrawingStyle style;
switch (choice) {
case 0:
style = G4ViewParameters::wireframe;
break;
case 1:
style = G4ViewParameters::hlr;
break;
case 2:
style = G4ViewParameters::hsr;
break;
case 3:
style = G4ViewParameters::hlhsr;
break;
default:
G4Exception("Unrecognised case in drawing_style_callback.");
}
pView->fVP.SetDrawingStyle (style);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::rep_style_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4long choice = (G4long)clientData;
G4OpenGLXmView* pView;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
G4ViewParameters::RepStyle style;
switch (choice) {
case 0:
style = G4ViewParameters::polyhedron;
break;
case 1:
style = G4ViewParameters::nurbs;
break;
default:
G4Exception("Unrecognised case in rep_style_callback.");
}
pView->fVP.SetRepStyle (style);
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::background_color_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4long choice = (G4long)clientData;
G4OpenGLXmView* pView;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
//I need to revisit the kernel if the background colour changes and hidden
//line removal is enabled, because hlr drawing utilises the background
//colour in its drawing...
switch (choice) {
case 0:
if (!pView->white_background) {
pView->white_background = true;
if (pView->GetViewParameters().GetDrawingStyle() == G4ViewParameters::hlr) {
pView->SetNeedKernelVisit ();
}
}
break;
case 1:
if (pView->white_background) {
pView->white_background = false;
if (pView->GetViewParameters().GetDrawingStyle() == G4ViewParameters::hlr) {
pView->SetNeedKernelVisit ();
}
}
break;
default:
G4Exception("Unrecognised case in background_color_callback.");
}
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::transparency_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4long choice = (G4long)clientData;
G4OpenGLXmView* pView;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
switch (choice) {
case 0:
pView->transparency_enabled = false;
glDisable (GL_BLEND);
break;
case 1:
pView->transparency_enabled = true;
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel (GL_FLAT);
break;
default:
G4Exception("Unrecognised case in transparency_callback.");
}
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::antialias_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4long choice = (G4long)clientData;
G4OpenGLXmView* pView;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
switch (choice) {
case 0:
pView->antialiasing_enabled = false;
glDisable (GL_LINE_SMOOTH);
glDisable (GL_POLYGON_SMOOTH);
break;
case 1:
pView->antialiasing_enabled = true;
glEnable (GL_LINE_SMOOTH);
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable (GL_POLYGON_SMOOTH);
glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
break;
default:
G4Exception("Unrecognised case in antialiasing_callback.");
}
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::haloing_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4long choice = (G4long)clientData;
G4OpenGLXmView* pView;
XtVaGetValues (XtParent(w),
XmNuserData, &pView,
NULL);
switch (choice) {
case 0:
pView->haloing_enabled = false;
break;
case 1:
pView->haloing_enabled = true;
break;
default:
G4Exception("Unrecognised case in haloing_callback.");
}
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::projection_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*)clientData;
G4int choice = G4OpenGLXmView::get_int_userData (w);
switch (choice) {
case 0:
{
pView->fVP.SetFieldHalfAngle (0.);
break;
}
case 1:
{
if (pView->fov > 89.5 || pView->fov <= 0.0) {
G4cout << "Field half angle should be 0 < angle <= 89.5 degrees.";
G4cout << endl;
}
else {
pView->fVP.SetFieldHalfAngle (pView->fov * deg);
}
break;
}
default:
{
G4Exception("Unrecognised choice made in projection_callback");
}
}
pView->SetView ();
pView->ClearView ();
pView->DrawView ();
}
#endif
@@ -0,0 +1,159 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmTextField.cc,v 2.1 1998/08/04 14:32:39 ajw Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Text field class. Inherits from G4OpenGLXmVWidgetComponent
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
#include "G4OpenGLXmTextField.hh"
#include <X11/Intrinsic.h>
#include "globals.hh"
G4OpenGLXmTextField::G4OpenGLXmTextField (char* n,
G4double* val)
{
name = n;
initial = new char[50];
sprintf (initial, "%6.2f\0", *val);
value = (void*)val;
text=false;
}
G4OpenGLXmTextField::G4OpenGLXmTextField (char* n,
char* val)
{
name = n;
initial = new char[50];
sprintf (initial, "%s", val);
value = (void*)val;
text=true;
// strcpy (initial, val);
}
G4OpenGLXmTextField::~G4OpenGLXmTextField ()
{
delete[] initial;
}
void G4OpenGLXmTextField::SetName (char* n)
{
name = n;
XmString text_string = XmStringCreateLocalized (name);
XtVaSetValues (text_label,
XmNlabelString, text_string,
NULL);
XmStringFree (text_string);
}
char* G4OpenGLXmTextField::GetName ()
{
return name;
}
void G4OpenGLXmTextField::SetValue (G4double val)
{
sprintf (initial, "%6.2f\0", val);
XtVaSetValues (text_field,
XmNvalue, (String)initial,
NULL);
}
void G4OpenGLXmTextField::SetValue (char* val)
{
sprintf (initial, "%s", val);
// strcpy (initial, val);
XtVaSetValues (text_field,
XmNvalue, (String)initial,
NULL);
}
char* G4OpenGLXmTextField::GetValue ()
{
return initial;
}
void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
{
pView = container->GetView ();
ProcesspView ();
parent = container->GetPointerToWidget ();
char local_w_text[50];
strcpy (local_w_text, name);
char label_name[50];
strcpy (label_name, name);
strcat (label_name, "_label");
char text_field_name[50];
strcpy (text_field_name, name);
strcat (text_field_name, "_text_field");
XmString local_text = XmStringCreateLocalized (local_w_text);
text_label = XtVaCreateManagedWidget (label_name,
xmLabelWidgetClass,
*parent,
XmNlabelString, local_text,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XmStringFree (local_text);
text_field = XtVaCreateManagedWidget (text_field_name,
xmTextFieldWidgetClass,
*parent,
XmNvalue, (String)initial,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
if (!text) {
XtAddCallback (text_field,
XmNvalueChangedCallback,
G4OpenGLXmView::get_double_value_callback,
value);
} else {
XtAddCallback (text_field,
XmNvalueChangedCallback,
G4OpenGLXmView::get_text_callback,
value);
}
}
Widget* G4OpenGLXmTextField::GetPointerToParent ()
{
return parent;
}
Widget* G4OpenGLXmTextField::GetPointerToWidget ()
{
return &text_field;
}
#endif
@@ -0,0 +1,104 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmTopLevelShell.cc,v 2.1 1998/07/13 17:11:50 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Top level shell class
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmTopLevelShell.hh"
#include "G4OpenGLXmVWidgetContainer.hh"
G4OpenGLXmTopLevelShell::G4OpenGLXmTopLevelShell (G4OpenGLXmView* v,
char* n)
{
pView = v;
ProcesspView ();
name = n;
toplevel = XtVaCreatePopupShell
(name,
topLevelShellWidgetClass,
top,
XtNiconName, name,
XtNtitle, name,
XmNdeleteResponse, XmDO_NOTHING,
XmNisHomogeneous, False,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
frame = XtVaCreateManagedWidget (name,
xmFrameWidgetClass,
toplevel,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
top_box = XtVaCreateManagedWidget (name,
xmRowColumnWidgetClass,
frame,
XmNadjustMargin, True,
XmNisHomogeneous, False,
XtNvisual, visual,
XtNdepth, depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
}
G4OpenGLXmTopLevelShell::~G4OpenGLXmTopLevelShell ()
{
XtDestroyWidget (toplevel);
}
void G4OpenGLXmTopLevelShell::AddChild (G4OpenGLXmVWidgetContainer* container)
{
container->AddYourselfTo (this);
}
void G4OpenGLXmTopLevelShell::Realize ()
{
Cardinal num_children;
XtVaGetValues (toplevel,
XmNnumChildren, &num_children,
NULL);
// G4cout << name << " now parents " << num_children << " children." << endl;
XtManageChild (toplevel);
XtRealizeWidget (toplevel);
XtPopup (toplevel, XtGrabNonexclusive);
}
Widget* G4OpenGLXmTopLevelShell::GetPointerToWidget ()
{
return &top_box;
}
char* G4OpenGLXmTopLevelShell::GetName ()
{
return name;
}
#endif
@@ -0,0 +1,23 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmVWidgetComponent.cc,v 2.0 1998/07/02 16:47:02 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Base class for all Motif component widgets
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetComponent.hh"
G4OpenGLXmVWidgetComponent::G4OpenGLXmVWidgetComponent ()
{}
G4OpenGLXmVWidgetComponent::~G4OpenGLXmVWidgetComponent ()
{}
#endif
@@ -0,0 +1,23 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmVWidgetContainer.cc,v 2.0 1998/07/02 16:47:03 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Base class for all Motif container widgets
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetContainer.hh"
G4OpenGLXmVWidgetContainer::G4OpenGLXmVWidgetContainer ()
{}
G4OpenGLXmVWidgetContainer::~G4OpenGLXmVWidgetContainer ()
{}
#endif
@@ -0,0 +1,38 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmVWidgetObject.cc,v 2.0 1998/07/02 16:47:05 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Virtual base class for all Motif widgets.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetObject.hh"
G4OpenGLXmVWidgetObject::G4OpenGLXmVWidgetObject ()
{}
G4OpenGLXmVWidgetObject::~G4OpenGLXmVWidgetObject ()
{}
G4OpenGLXmView* G4OpenGLXmVWidgetObject::GetView ()
{
return pView;
}
void G4OpenGLXmVWidgetObject::ProcesspView ()
{
cmap = pView->cmap;
depth = pView->vi->depth;
visual = pView->vi->visual;
borcol = pView->borcol;
bgnd = pView->bgnd;
top = pView->toplevel;
}
#endif
@@ -0,0 +1,23 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmVWidgetShell.cc,v 2.0 1998/07/02 16:47:06 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//Base class for all Motif shell widgets
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmVWidgetShell.hh"
G4OpenGLXmVWidgetShell::G4OpenGLXmVWidgetShell ()
{}
G4OpenGLXmVWidgetShell::~G4OpenGLXmVWidgetShell ()
{}
#endif
@@ -0,0 +1,645 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmView.cc,v 2.6 1998/10/29 09:40:48 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 10th February 1997
// G4OpenGLXmView : Class derived from G4OpenGLXView, to provide
// (Motif) widget OpenGL functionality for GEANT4.
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "globals.hh"
#include "G4OpenGLXmView.hh"
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include "G4ios.hh"
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include "G4VisExtent.hh"
#include "G4LogicalVolume.hh"
#include "G4VSolid.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4VisManager.hh"
#include "G4OpenGLXmSliderBar.hh"
#include "G4Xt.hh"
#include <X11/Shell.h>
static G4ViewParameters viewingParameters;
static void SecondaryLoopPostAction ();
void G4OpenGLXmView::ShowView () {
viewingParameters = fVP;
G4Xt::getInstance () -> SecondaryLoop ();
}
static void SecondaryLoopPostAction ()
{
if(G4Xt::getInstance () -> GetExitSecondaryLoopCode ()==OGL_EXIT_CODE)
{
G4VisManager::GetInstance() -> SetCurrentViewParameters() = viewingParameters;
}
}
void G4OpenGLXmView::GetXmConnection () {
G4Xt* interactorManager = G4Xt::getInstance ();
toplevel = (Widget)interactorManager->GetMainInteractor();
app = XtWidgetToApplicationContext(toplevel);
if (!toplevel) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLXmView::GetXmConnection unable to Initialize"
" application context." << endl;
return;
}
// Better to put this in an X11 resource file !!!
interactorManager->PutStringInResourceDatabase ("\
*glxarea*width: 500\n\
*glxarea*height: 500\n\
*frame*x: 10\n\
*frame*y: 10\n\
*frame*topOffset: 10\n\
*frame*bottomOffset: 10\n\
*frame*rightOffset: 10\n\
*frame*leftOffset: 10\n\
*frame*shadowType: SHADOW_IN\n\
*frame*useColorObj: False\n\
*frame*primaryColorSetId: 3\n\
*frame*secondaryColorSetId: 3\n\
*menubar*useColorObj: False\n\
*menubar*primaryColorSetId: 3\n\
*menubar*secondaryColorSetId: 3\n\
*toplevel*useColorObj: False\n\
*toplevel*primaryColorSetId: 3\n\
*toplevel*secondaryColorSetId: 3\n\
");
interactorManager->AddSecondaryLoopPostAction ((G4SecondaryLoopAction)SecondaryLoopPostAction);
shell = XtAppCreateShell ((String)fName.data(),(String)fName.data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0);
interactorManager->AddShell (shell);
dpy = XtDisplay (shell);
if (!dpy) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLXmView::GetXmConnection unable to connect to display."
<< endl;
return;
}
if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLXmView::GetXmConnection. X Server has no GLX extension."
<< endl;;
return;
}
}
void G4OpenGLXmView::CreateMainWindow () {
bgnd = XWhitePixelOfScreen (XtScreen(shell));
borcol = XBlackPixelOfScreen (XtScreen(shell));
XtVaSetValues (shell,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, &borcol,
XtNbackground, &bgnd,
XmNtitle, fName.data(),
NULL);
main_win = XtVaCreateManagedWidget ("main_win",
xmMainWindowWidgetClass,
shell,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
//*********Create a menu bar for the window********
style_str = XmStringCreateLocalized ("Style");
actions_str = XmStringCreateLocalized ("Actions");
misc_str = XmStringCreateLocalized ("Miscellany");
spec_str = XmStringCreateLocalized ("Special");
menubar = XmVaCreateSimpleMenuBar (main_win,
"menubar",
XmVaCASCADEBUTTON, style_str, 'S',
XmVaCASCADEBUTTON, actions_str, 'A',
XmVaCASCADEBUTTON, misc_str, 'M',
XmVaCASCADEBUTTON, spec_str, 'p',
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XmStringFree (style_str);
XmStringFree (actions_str);
XmStringFree (misc_str);
XmStringFree (spec_str);
G4cout << "Created menubar" << endl;
//*********Create style pulldown menu on menubar*********
rep_str = XmStringCreateLocalized ("Representation");
draw_str = XmStringCreateLocalized ("Drawing");
bgnd_str = XmStringCreateLocalized ("Background color");
style_cascade = XmVaCreateSimplePulldownMenu
(menubar,
"style",
0,
NULL,
XmVaCASCADEBUTTON, rep_str, 'R',
XmVaCASCADEBUTTON, draw_str, 'D',
XmVaCASCADEBUTTON, bgnd_str, 'B',
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XmStringFree (rep_str);
XmStringFree (draw_str);
XmStringFree (bgnd_str);
// G4cout << "Created Style pulldown menu" << endl;
//Add Representation pullright menu to style cascade...
polyhedron_str = XmStringCreateLocalized ("Polyhedron");
nurbs_str = XmStringCreateLocalized ("NURBS");
rep_style_pullright = XmVaCreateSimplePulldownMenu
(style_cascade,
"rep_style",
0,
G4OpenGLXmView::rep_style_callback,
XmVaRADIOBUTTON, polyhedron_str, 'P', NULL, NULL,
XmVaRADIOBUTTON, nurbs_str, 'N', NULL, NULL,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
Widget special_widget;
G4ViewParameters::RepStyle style;
style = fVP.GetRepStyle();
if (style == G4ViewParameters::polyhedron) {
if(special_widget = XtNameToWidget(rep_style_pullright, "button_0")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (style == G4ViewParameters::nurbs) {
if(special_widget = XtNameToWidget(rep_style_pullright, "button_1")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else {
G4Exception("Invalid Representation style in G4OpenGLXmView::CreateContext");
}
XmStringFree (polyhedron_str);
XmStringFree (nurbs_str);
// G4cout << "Created Representation pulldown menu" << endl;
//Add Drawing pullright menu to style cascade...
wireframe_str = XmStringCreateLocalized ("Wireframe");
hlr_str = XmStringCreateLocalized ("Hidden line removal");
hsr_str = XmStringCreateLocalized ("Hidden surface removal");
hlhsr_str = XmStringCreateLocalized ("Hidden line and surface removal");
drawing_style_pullright = XmVaCreateSimplePulldownMenu
(style_cascade,
"drawing_style",
1,
G4OpenGLXmView::drawing_style_callback,
XmVaRADIOBUTTON, wireframe_str, 'W', NULL, NULL,
XmVaRADIOBUTTON, hlr_str, 'L', NULL, NULL,
XmVaRADIOBUTTON, hsr_str, 'S', NULL, NULL,
XmVaRADIOBUTTON, hlhsr_str, 'H', NULL, NULL,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
G4ViewParameters::DrawingStyle d_style;
d_style = fVP.GetDrawingStyle();
if (d_style == G4ViewParameters::wireframe) {
if(special_widget = XtNameToWidget(drawing_style_pullright, "button_0")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (d_style == G4ViewParameters::hlr) {
if(special_widget = XtNameToWidget(drawing_style_pullright, "button_1")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (d_style == G4ViewParameters::hsr) {
if(special_widget = XtNameToWidget(drawing_style_pullright, "button_2")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (d_style == G4ViewParameters::hlhsr) {
if(special_widget = XtNameToWidget(drawing_style_pullright, "button_3")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else {
G4Exception("Invalid Drawing style in G4OpenGLXmView::CreateContext");
}
XmStringFree (wireframe_str);
XmStringFree (hlr_str);
XmStringFree (hsr_str);
XmStringFree (hlhsr_str);
// G4cout << "Created Drawing pullright menu" << endl;
//Add Drawing pullright menu to style cascade...
white_str = XmStringCreateLocalized ("White");
black_str = XmStringCreateLocalized ("Black");
background_color_pullright = XmVaCreateSimplePulldownMenu
(style_cascade,
"background_color",
2,
G4OpenGLXmView::background_color_callback,
XmVaRADIOBUTTON, white_str, 'W', NULL, NULL,
XmVaRADIOBUTTON, black_str, 'B', NULL, NULL,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
if (white_background == true) {
if(special_widget = XtNameToWidget(background_color_pullright,
"button_0")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (white_background == false) {
if(special_widget = XtNameToWidget(background_color_pullright,
"button_1")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else {
G4Exception("white_background in G4OpenGLXmView is neither true nor false!!");
}
XmStringFree (white_str);
XmStringFree (black_str);
// G4cout << "Created Background color pullright menu" << endl;
//*********Create actions pulldown menu on menubar*********
rot_str = XmStringCreateLocalized ("Rotation control panel");
pan_str = XmStringCreateLocalized ("Panning control panel");
set_str = XmStringCreateLocalized ("Set control panel limits");
actions_cascade = XmVaCreateSimplePulldownMenu
(menubar,
"actions",
1,
G4OpenGLXmView::actions_callback,
XmVaPUSHBUTTON, rot_str, 'R', NULL, NULL,
XmVaPUSHBUTTON, pan_str, 'P', NULL, NULL,
XmVaPUSHBUTTON, set_str, 'S', NULL, NULL,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XmStringFree (rot_str);
XmStringFree (pan_str);
XmStringFree (set_str);
G4cout << "Created Actions pulldown menu" << endl;
misc_str = XmStringCreateLocalized ("Miscellany control panel");
exit_str = XmStringCreateLocalized ("Exit to G4Vis>");
print_str = XmStringCreateLocalized ("Create .eps file");
//*********Create miscellany pulldown menu on menubar*********
misc_cascade = XmVaCreateSimplePulldownMenu
(menubar,
"miscellany",
2,
G4OpenGLXmView::misc_callback,
XmVaPUSHBUTTON, misc_str, 'M', NULL, NULL,
XmVaPUSHBUTTON, exit_str, 'E', NULL, NULL,
XmVaPUSHBUTTON, print_str, 'P', NULL, NULL,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XmStringFree (misc_str);
XmStringFree (exit_str);
XmStringFree (print_str);
G4cout << "Created Miscellany pulldown menu" << endl;
trans_str = XmStringCreateLocalized ("Transparency");
anti_str = XmStringCreateLocalized ("Antialiasing");
halo_str = XmStringCreateLocalized ("Haloing");
//*********Create special pulldown menu on menubar*********
spec_cascade = XmVaCreateSimplePulldownMenu
(menubar,
"special",
3,
NULL,
XmVaCASCADEBUTTON, trans_str, 'T',
XmVaCASCADEBUTTON, anti_str, 'A',
XmVaCASCADEBUTTON, halo_str, 'H',
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XmStringFree (trans_str);
XmStringFree (anti_str);
XmStringFree (halo_str);
// G4cout << "Created Special pulldown menu" << endl;
//Add Transparency pullright menu to special cascade...
off_str = XmStringCreateLocalized ("Off");
on_str = XmStringCreateLocalized ("On");
transparency_pullright = XmVaCreateSimplePulldownMenu
(spec_cascade,
"transparency",
0,
G4OpenGLXmView::transparency_callback,
XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
if (transparency_enabled == false) {
if(special_widget = XtNameToWidget(transparency_pullright,
"button_0")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (transparency_enabled == true) {
if(special_widget = XtNameToWidget(transparency_pullright,
"button_1")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else {
G4Exception("transparency_enabled in G4OpenGLXmView is neither true nor false!!");
}
//Add antialias pullright menu to special cascade...
antialias_pullright = XmVaCreateSimplePulldownMenu
(spec_cascade,
"antialias",
1,
G4OpenGLXmView::antialias_callback,
XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
if (antialiasing_enabled == false) {
if(special_widget = XtNameToWidget(antialias_pullright,
"button_0")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (antialiasing_enabled == true) {
if(special_widget = XtNameToWidget(antialias_pullright,
"button_1")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else {
G4Exception("antialiasing_enabled in G4OpenGLXmView is neither true nor false!!");
}
//Add Haloing pullright menu to special cascade...
haloing_pullright = XmVaCreateSimplePulldownMenu
(spec_cascade,
"haloing",
2,
G4OpenGLXmView::haloing_callback,
XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
XmNradioBehavior, True,
XmNradioAlwaysOne, True,
XmNuserData, this,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
if (haloing_enabled == false) {
if(special_widget = XtNameToWidget(haloing_pullright,
"button_0")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else if (haloing_enabled == true) {
if(special_widget = XtNameToWidget(haloing_pullright,
"button_1")) {
XtVaSetValues (special_widget, XmNset, True, NULL);
}
} else {
G4Exception("haloing_enabled in G4OpenGLXmView is neither true nor false!!");
}
XtManageChild (menubar);
frame = XtVaCreateManagedWidget ("frame", xmFrameWidgetClass, main_win,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
glxarea = XtVaCreateManagedWidget ("glxarea",
xmDrawingAreaWidgetClass,
frame,
XtNvisual, vi -> visual,
XtNdepth, vi -> depth,
XtNcolormap, cmap,
XtNborderColor, borcol,
XtNbackground, bgnd,
NULL);
XtAddCallback (glxarea,
XmNexposeCallback,
G4OpenGLXmView::expose_callback,
this);
XtAddCallback (glxarea,
XmNresizeCallback,
G4OpenGLXmView::resize_callback,
this);
XmMainWindowSetAreas (main_win, // main widget, children are specified
menubar, // widget to use as menu bar
NULL, // widget to use as command window
NULL, // widget for horizontal scroll bar
NULL, // widget for vertical scroll bar
frame // widget to be used for work window
);
XtRealizeWidget(shell);
// Once widget is realized (ie, associated with a created X window), we
// can bind the OpenGL rendering context to the window.
Dimension width, height;
XtVaGetValues (glxarea,XmNwidth,&width,XmNheight,&height,NULL);
WinSize_x = (G4int) width;
WinSize_y = (G4int) height;
win = XtWindow (glxarea);
glXMakeCurrent (dpy, win, cx);
}
G4OpenGLXmView::G4OpenGLXmView (G4OpenGLScene& scene):
G4VView (scene, -1),
G4OpenGLView (scene),
G4OpenGLXView (scene),
zoom_low (fVP.GetZoomFactor() / 10.0),
zoom_high (fVP.GetZoomFactor() * 10.0),
dolly_low (fVP.GetDolly() - 1000.0),
dolly_high (fVP.GetDolly() + 1000.0),
rot_sens (4.),
frameNo (0),
wob_sens (20.),
rot_sens_limit (90.),
pan_sens_limit (100.),
fov (0.0),
original_vp(fVP.GetViewpointDirection()),
fppanning_top (NULL),
fprotation_top (NULL),
fpmiscellany_top (NULL),
fpsetting_top (NULL),
fpprint_top (NULL),
fppanning_slider (NULL),
fprotation_slider (NULL),
fpzoom_slider (NULL),
fpdolly_slider (NULL)
{
WinSize_x = 100;
WinSize_y = 100;
vi_immediate = 0;
vi_stored = 0;
GetXmConnection ();
if (fViewId < 0) return;
// Try for a visual suitable for OpenGLImmediate..
// first try for a single buffered RGB window
if (vi_immediate =
glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA)) {
attributeList = snglBuf_RGBA;
doublebuffer = false;
}
if (!vi_immediate){
// next try for a double buffered RGB, but Draw to top buffer
if (vi_immediate =
glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA)) {
attributeList = dblBuf_RGBA;
doublebuffer = true;
}
}
// Now try for a visual suitable for OpenGLStored...
// Try for a double buffered RGB window
if (vi_stored = glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA)) {
attributeList = dblBuf_RGBA;
doublebuffer = true;
}
}
G4OpenGLXmView::~G4OpenGLXmView ()
{
XtDestroyWidget (shell);
G4Xt::getInstance () ->RemoveShell (shell);
/******************************
if (fprotation_top) {
delete fprotation_top;
}
if (fppanning_top) {
delete fppanning_top;
}
if (fpsetting_top) {
delete fpsetting_top;
}
if (fpmiscellany_top) {
delete fpmiscellany_top;
}
******************************/
}
#endif
@@ -0,0 +1,95 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4OpenGLXmWindowHandlingCallbacks.cc,v 2.4 1998/10/29 09:41:11 barrand Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// Andrew Walkden 16th June 1997
// G4OpenGLXmWindowHandlingCallbacks : Callback functions for
// (Motif) widgets to use.
// in handling (Xm) windows
#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
#include "G4OpenGLXmView.hh"
void G4OpenGLXmView::resize_callback (Widget w,
XtPointer clientData,
XtPointer)
{
Dimension width, height;
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
XtVaGetValues (w,
XmNwidth, &width,
XmNheight, &height,
NULL);
pView->WinSize_x = (G4int) width;
pView->WinSize_y = (G4int) height;
}
void G4OpenGLXmView::expose_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*) clientData;
Dimension width, height;
XtVaGetValues (w,
XmNwidth, &width,
XmNheight, &height,
NULL);
pView->WinSize_x = (G4int) width;
pView->WinSize_y = (G4int) height;
glXMakeCurrent (pView->dpy, XtWindow(pView->glxarea), pView->cx);
glViewport (0, 0, width, height);
pView->ClearView ();
pView->DrawView ();
}
void G4OpenGLXmView::print_callback (Widget,
XtPointer clientData,
XtPointer)
{
G4OpenGLXView* pView = (G4OpenGLXmView*) clientData;
pView->print();
}
void G4OpenGLXmView::set_print_colour_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*)clientData;
G4int choice = G4OpenGLXmView::get_int_userData (w);
pView->print_colour=(G4bool)choice;
G4cout << "Print colour set to " << pView->print_colour;
}
void G4OpenGLXmView::set_print_style_callback (Widget w,
XtPointer clientData,
XtPointer)
{
G4OpenGLXmView* pView = (G4OpenGLXmView*)clientData;
G4int choice = G4OpenGLXmView::get_int_userData (w);
pView->vectored_ps=(G4bool)choice;
G4cout << "`Produce vectored PostScript ?' set to : " << pView->print_colour;
}
#endif