00001
00002
00003 #include "VisGeant4/VisG4Transients/interface/VisSoG4Trajectories.h"
00004 #include <Inventor/actions/SoGetBoundingBoxAction.h>
00005 #include <Inventor/actions/SoGLRenderAction.h>
00006 #include <Inventor/elements/SoGLLazyElement.h>
00007
00008
00009
00010 #include <G4RunManager.hh>
00011 #include <G4Trajectory.hh>
00012
00013 #ifdef WIN32
00014 # include <windows.h>
00015 #endif
00016 #ifdef __APPLE__
00017 # include <OpenGL/gl.h>
00018 #else
00019 # include <GL/gl.h>
00020 #endif
00021
00022
00023
00024 #define MINIMUM(a,b) ((a)<(b)?a:b)
00025 #define MAXIMUM(a,b) ((a)>(b)?a:b)
00026 #define DRAW_TRAJ_POINT(traj,i) \
00027 do { \
00028 G4TrajectoryPoint *tp = (G4TrajectoryPoint*) ((traj)->GetPoint (i));\
00029 G4ThreeVector pos = tp->GetPosition (); \
00030 glVertex3f (pos.x () / m, pos.y () / m, pos.z () / m); \
00031 } while (0)
00032
00033
00034
00035
00036
00037
00038
00039 SO_NODE_SOURCE (VisSoG4Trajectories);
00040
00041
00042
00043
00044
00045 void
00046 VisSoG4Trajectories::initClass (void)
00047 {
00048 SO_NODE_INIT_CLASS (VisSoG4Trajectories, SoShape, "Shape");
00049 }
00050
00051 VisSoG4Trajectories::VisSoG4Trajectories (void)
00052 {
00053 SO_NODE_CONSTRUCTOR (VisSoG4Trajectories);
00054 SO_NODE_ADD_FIELD (on, (FALSE));
00055 SO_NODE_ADD_FIELD (flush, (NONE));
00056
00057 SO_NODE_DEFINE_ENUM_VALUE (Flush, NONE);
00058 SO_NODE_DEFINE_ENUM_VALUE (Flush, STEP);
00059 SO_NODE_DEFINE_ENUM_VALUE (Flush, TRAJECTORY);
00060 SO_NODE_DEFINE_ENUM_VALUE (Flush, ALL);
00061
00062 SO_NODE_SET_SF_ENUM_TYPE (flush,Flush);
00063 }
00064
00065 VisSoG4Trajectories::~VisSoG4Trajectories (void)
00066 {}
00067
00068 void
00069 VisSoG4Trajectories::computeBBox (SoAction *, SbBox3f &box, SbVec3f ¢er)
00070 {
00071 if (G4RunManager *runManager = G4RunManager::GetRunManager ())
00072 if (const G4Event *event = runManager->GetCurrentEvent ())
00073 if (G4TrajectoryContainer *trajectories
00074 = event->GetTrajectoryContainer ())
00075 {
00076 for (int count = 0; count < trajectories->entries (); count++)
00077 {
00078 G4Trajectory *t = static_cast<G4Trajectory *>
00079 ((*trajectories) [count]);
00080 for (int i = 0; i < t->GetPointEntries (); i++)
00081 {
00082 G4ThreeVector pos =
00083 ((G4TrajectoryPoint *) t->GetPoint (i))
00084 ->GetPosition ();
00085
00086 box.extendBy (SbVec3f (pos.x () / m,
00087 pos.y () / m,
00088 pos.z () / m));
00089 }
00090 center = box.getCenter ();
00091 }
00092 }
00093 }
00094
00095 void
00096 VisSoG4Trajectories::touch (void)
00097 { on.touch(); }
00098
00099 void
00100 VisSoG4Trajectories::GLRender (SoGLRenderAction *action)
00101 {
00102 if (on.getValue () == FALSE || ! shouldGLRender (action))
00103 return;
00104
00105 SoState *state = action->getState ();
00106 state->push ();
00107 SoLazyElement::setColorMaterial (state, true);
00108 SoGLLazyElement::sendNoMaterial (state);
00109
00110 if (G4RunManager *runManager = G4RunManager::GetRunManager ())
00111 if (const G4Event *event = runManager->GetCurrentEvent ())
00112 if (G4TrajectoryContainer *trajectories
00113 = event->GetTrajectoryContainer ())
00114 {
00115 glDisable (GL_LIGHTING);
00116 glColor3f (1,0,0);
00117
00118 Flush flushing = (Flush) flush.getValue();
00119
00120 for (int count = 0; count < trajectories->entries (); count++)
00121 {
00122 G4Trajectory *t = static_cast<G4Trajectory *>
00123 ((*trajectories) [count]);
00124
00125 if (t->GetPointEntries () == 1)
00126 {
00127 glBegin (GL_POINTS);
00128 DRAW_TRAJ_POINT (t, 0);
00129 glEnd ();
00130 glFlush ();
00131 }
00132 else if (flushing == STEP)
00133 {
00134 for (int i = 0; i < t->GetPointEntries ()-1; i++)
00135 {
00136 glBegin (GL_LINES);
00137 DRAW_TRAJ_POINT (t, i);
00138 DRAW_TRAJ_POINT (t, i+1);
00139 glEnd ();
00140 glFlush ();
00141 }
00142 }
00143 else
00144 {
00145 glBegin (GL_LINES);
00146 for (int i = 0; i < t->GetPointEntries ()-1; i++)
00147 {
00148 DRAW_TRAJ_POINT (t, i);
00149 DRAW_TRAJ_POINT (t, i+1);
00150 }
00151 glEnd ();
00152
00153 if (flushing == TRAJECTORY)
00154 glFlush ();
00155 }
00156
00157 }
00158
00159 if (flushing == ALL)
00160 glFlush ();
00161
00162 glEnable (GL_LIGHTING);
00163 }
00164
00165 ((SoGLLazyElement *) SoLazyElement::getInstance (state))
00166 ->reset (state, SoLazyElement::DIFFUSE_MASK
00167 | SoLazyElement::LIGHT_MODEL_MASK);
00168 state->pop ();
00169 }
00170
00171 void
00172 VisSoG4Trajectories::generatePrimitives (SoAction *)
00173 {
00174 if (on.getValue () == FALSE)
00175 return;
00176
00177
00178 }