Import Geant4 0.0.0 source tree
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# $Id: GNUmakefile,v 2.4 1998/11/25 16:19:32 allison Exp $
|
||||
|
||||
name := G4Ray
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
include $(G4INSTALL)/config/G4VIS_BUILD.gmk
|
||||
include $(G4INSTALL)/config/interactivity.gmk
|
||||
|
||||
CPPFLAGS += -I$(G4BASE)/visualization/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/visualization/modeling/include
|
||||
CPPFLAGS += -I$(G4BASE)/global/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/global/HEPRandom/include
|
||||
CPPFLAGS += -I$(G4BASE)/global/HEPGeometry/include
|
||||
CPPFLAGS += -I$(G4BASE)/geometry/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/geometry/volumes/include
|
||||
CPPFLAGS += -I$(G4BASE)/geometry/solids/CSG/include
|
||||
CPPFLAGS += -I$(G4BASE)/event/include
|
||||
CPPFLAGS += -I$(G4BASE)/processes/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/processes/electromagnetic/utils/include
|
||||
CPPFLAGS += -I$(G4BASE)/materials/include
|
||||
CPPFLAGS += -I$(G4BASE)/particles/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/graphics_reps/include
|
||||
CPPFLAGS += -I$(G4BASE)/intercoms/include
|
||||
CPPFLAGS += -I$(G4BASE)/tracking/include
|
||||
CPPFLAGS += -I$(G4BASE)/track/include
|
||||
CPPFLAGS += -I$(G4BASE)/digits+hits/detector/include
|
||||
CPPFLAGS += -I$(G4BASE)/digits+hits/hits/include
|
||||
CPPFLAGS += -I$(G4BASE)/digits+hits/digits/include
|
||||
CPPFLAGS += -I$(G4BASE)/run/include
|
||||
|
||||
CPPFLAGS += $(X11FLAGS)
|
||||
|
||||
include $(G4INSTALL)/config/common.gmk
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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: G4OwnColormapXView.hh,v 2.1 1998/10/23 17:58:21 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// John Allison 1st June 1997
|
||||
// Loosely based on G4OpenGLXView by Andrew Walkden 7th February 1997
|
||||
// G4OwnColormapXView : Class to provide X Windows with its own colormap
|
||||
// for a GEANT4 view. The derived view must define the colormap.
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#ifndef G4OWNCOLORMAPXVIEW_HH
|
||||
#define G4OWNCOLORMAPXVIEW_HH
|
||||
|
||||
#include "G4VView.hh"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
class G4VScene;
|
||||
|
||||
class G4OwnColormapXView: virtual public G4VView {
|
||||
|
||||
public:
|
||||
G4OwnColormapXView (G4VScene& scene);
|
||||
~G4OwnColormapXView ();
|
||||
void ClearView ();
|
||||
void FinishView ();
|
||||
|
||||
protected:
|
||||
char* fcharViewName;
|
||||
Display* fpDisplay;
|
||||
int fScreen;
|
||||
int fDepth;
|
||||
G4String fVisualName;
|
||||
G4bool fTrueColor;
|
||||
Visual* fpVisual;
|
||||
int fMapEntries;
|
||||
Window fRootW;
|
||||
int fRedShift;
|
||||
int fGreenShift;
|
||||
int fBlueShift;
|
||||
float fRedMax;
|
||||
float fGreenMax;
|
||||
float fBlueMax;
|
||||
Colormap fColormap;
|
||||
XWindowAttributes fRootWA;
|
||||
GC fGC;
|
||||
XSetWindowAttributes fSWA;
|
||||
Window fWindow;
|
||||
XTextProperty fWindowName;
|
||||
XTextProperty fIconName;
|
||||
XSizeHints* fSize_hints;
|
||||
XWMHints* fWM_hints;
|
||||
XClassHint* fClass_hints;
|
||||
XWindowAttributes fWA;
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
Pixmap fIcon_pixmap;
|
||||
XEvent fEvent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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: G4RayMessenger.hh,v 2.2 1998/07/12 03:44:31 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// GEANT4 Ray tracing Messenger - John Allison 5th June 1997
|
||||
|
||||
#ifndef G4RAYMESSENGER_HH
|
||||
#define G4RAYMESSENGER_HH
|
||||
|
||||
#include "G4UImessenger.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4RayX;
|
||||
class G4RayScene;
|
||||
class G4RayView;
|
||||
|
||||
class G4UIcommand;
|
||||
|
||||
class G4RayMessenger: public G4UImessenger {
|
||||
public:
|
||||
G4RayMessenger ();
|
||||
~G4RayMessenger ();
|
||||
void SetNewValue (G4UIcommand* command, G4String newValues);
|
||||
G4String GetCurrentValue (G4UIcommand* command);
|
||||
void RegisterScene (G4RayScene* pScene);
|
||||
void RegisterView (G4RayView* pView);
|
||||
private:
|
||||
G4RayScene* fpScene;
|
||||
G4RayView* fpView;
|
||||
G4UIcommand* fpVisRayCommandDirectory;
|
||||
G4UIcommand* fpResolutionCommand;
|
||||
};
|
||||
|
||||
#include "G4RayMessenger.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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: G4RayMessenger.icc,v 2.0 1998/07/02 16:42:42 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// GEANT4 Ray tracing Messenger - John Allison 5th June 1997
|
||||
|
||||
inline void G4RayMessenger::RegisterScene (G4RayScene* pScene) {
|
||||
fpScene = pScene;
|
||||
}
|
||||
|
||||
inline void G4RayMessenger::RegisterView (G4RayView* pView) {
|
||||
fpView = pView;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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: G4RayPrimaryGeneratorAction.hh,v 2.1 1998/07/12 03:09:19 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#ifndef G4RayPrimaryGeneratorAction_h
|
||||
#define G4RayPrimaryGeneratorAction_h 1
|
||||
|
||||
#include "G4VUserPrimaryGeneratorAction.hh"
|
||||
|
||||
class G4ParticleGun;
|
||||
class G4Event;
|
||||
|
||||
class G4RayPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
|
||||
{
|
||||
public:
|
||||
G4RayPrimaryGeneratorAction();
|
||||
~G4RayPrimaryGeneratorAction();
|
||||
|
||||
public:
|
||||
void GeneratePrimaries(G4Event* anEvent);
|
||||
G4ParticleGun* GetParticleGun();
|
||||
|
||||
private:
|
||||
G4ParticleGun* particleGun;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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: G4RayScene.hh,v 2.2 1998/11/06 13:41:50 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing scene.
|
||||
|
||||
#ifndef G4RAYSCENE_HH
|
||||
#define G4RAYSCENE_HH
|
||||
|
||||
#include "G4VScene.hh"
|
||||
|
||||
class G4RayScene: public G4VScene {
|
||||
|
||||
public:
|
||||
G4RayScene (G4VGraphicsSystem& system, const G4String& name = "");
|
||||
~G4RayScene ();
|
||||
static G4int GetSceneCount ();
|
||||
|
||||
// The following functions don't make sense for G4Ray...
|
||||
void AddPrimitive (const G4Polyline&);
|
||||
void AddPrimitive (const G4Text&);
|
||||
void AddPrimitive (const G4Circle&);
|
||||
void AddPrimitive (const G4Square&);
|
||||
void AddPrimitive (const G4Polymarker&);
|
||||
void AddPrimitive (const G4Polyhedron&);
|
||||
void AddPrimitive (const G4NURBS&);
|
||||
void AddThis (const G4Box&);
|
||||
void AddThis (const G4Cons&);
|
||||
void AddThis (const G4Tubs&);
|
||||
void AddThis (const G4Trd&);
|
||||
void AddThis (const G4Trap&);
|
||||
void AddThis (const G4Sphere&);
|
||||
void AddThis (const G4Para&);
|
||||
void AddThis (const G4Torus&);
|
||||
void AddThis (const G4VSolid&);
|
||||
|
||||
private:
|
||||
static G4int fSceneIdCount; // static counter for Ray scenes.
|
||||
static G4int fSceneCount; // No. of extanct scenes.
|
||||
};
|
||||
|
||||
#include "G4RayScene.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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: G4RayScene.icc,v 2.1 1998/08/07 08:17:02 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing scene.
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Box& box) {
|
||||
G4VScene::AddThis (box);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Cons& cons) {
|
||||
G4VScene::AddThis (cons);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Tubs& tubs) {
|
||||
G4VScene::AddThis (tubs);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Trd& trd) {
|
||||
G4VScene::AddThis (trd);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Trap& trap) {
|
||||
G4VScene::AddThis (trap);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Sphere& sphere) {
|
||||
G4VScene::AddThis (sphere);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Para& para) {
|
||||
G4VScene::AddThis (para);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4Torus& torus) {
|
||||
G4VScene::AddThis (torus);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddThis (const G4VSolid& vsolid) {
|
||||
G4VScene::AddThis (vsolid);
|
||||
}
|
||||
|
||||
inline void G4RayScene::AddPrimitive (const G4Polymarker& polymarker) {
|
||||
G4VScene::AddPrimitive (polymarker);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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: G4RaySteppingAction.hh,v 2.0 1998/07/02 16:42:50 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// 16/Apr/1997 J. Allison: For visualization/test/test19.
|
||||
// moved here and renamed 14/April/1997
|
||||
|
||||
#ifndef MYSTEPPINGACTION_HH
|
||||
#define MYSTEPPINGACTION_HH
|
||||
|
||||
#include "G4UserSteppingAction.hh"
|
||||
#include "G4Normal3D.hh"
|
||||
|
||||
class G4RaySteppingAction: public G4UserSteppingAction {
|
||||
public:
|
||||
G4RaySteppingAction();
|
||||
void UserSteppingAction();
|
||||
G4bool WeHaveContact () const {return weHaveContact;}
|
||||
G4Normal3D GetSurfaceNormal () const {return normal;}
|
||||
const G4VisAttributes* GetVisAttributes () const {return pVisAttribs;}
|
||||
G4VPhysicalVolume* GetPhysicalVolume () const {return pVPV;}
|
||||
G4LogicalVolume* GetLogicalVolume () const {return pLV;}
|
||||
G4VSolid* GetSolid () const {return pSol;}
|
||||
private:
|
||||
G4bool weHaveContact;
|
||||
G4Normal3D normal;
|
||||
const G4VisAttributes* pVisAttribs;
|
||||
G4VPhysicalVolume* pVPV;
|
||||
G4LogicalVolume* pLV;
|
||||
G4VSolid* pSol;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,168 @@
|
||||
// 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: G4RayView.hh,v 2.2 1998/11/06 13:41:51 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing view.
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4RaySteppingAction.hh"
|
||||
#include "G4RayPrimaryGeneratorAction.hh"
|
||||
|
||||
|
||||
#ifndef G4RAYVIEW_HH
|
||||
#define G4RAYVIEW_HH
|
||||
|
||||
#include "G4VView.hh"
|
||||
#include "G4Colour.hh"
|
||||
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
|
||||
#include <rw/tvordvec.h>
|
||||
#include <rw/tvhdict.h>
|
||||
|
||||
class G4RayScene;
|
||||
class G4RaySteppingAction;
|
||||
|
||||
class G4RayColourCell {
|
||||
public:
|
||||
G4RayColourCell (): red (0), green (0), blue (0), nHits (0) {}
|
||||
G4RayColourCell (float rr, float gg, float bb, G4int ii):
|
||||
red (rr), green (gg), blue (bb), nHits (ii) {}
|
||||
float red, green, blue;
|
||||
G4int nHits; // No. of ray hits using this colour.
|
||||
G4bool operator == (const G4RayColourCell& h) const {
|
||||
return this == &h;
|
||||
}
|
||||
};
|
||||
|
||||
class G4RayCoordinate {
|
||||
public:
|
||||
G4RayCoordinate (): coord (0) {}
|
||||
G4RayCoordinate (G4double x, G4double y):
|
||||
coord (((unsigned int) (0x7fff * (x + 1.0))) |
|
||||
((unsigned int) (0x7fff * (1.0 - y)) << 16)) {}
|
||||
// Assumes -1.0 <= x, y <= 1.0. Assigns 16 bits each.
|
||||
unsigned int coord;
|
||||
G4bool operator == (const G4RayCoordinate& c) const {
|
||||
return coord == c.coord;
|
||||
}
|
||||
};
|
||||
|
||||
class G4RayHitColour {
|
||||
public:
|
||||
G4RayHitColour (): colour (0) {}
|
||||
G4RayHitColour (float r, float g, float b):
|
||||
colour ((((unsigned int) (0x3ff * r)) << 20) |
|
||||
(((unsigned int) (0x3ff * g)) << 10) |
|
||||
((unsigned int) (0x3ff * b))) {}
|
||||
// Assumes 0.0 <= r, g, b <= 1.0. Assigns 10 bits each.
|
||||
unsigned int colour;
|
||||
G4bool operator == (const G4RayHitColour& h) const {
|
||||
return colour == h.colour;
|
||||
}
|
||||
float GetRed () {return (float ((colour >> 20) )) / 0x3ff;}
|
||||
float GetGreen () {return (float ((colour >> 10) & 0x3ff)) / 0x3ff;}
|
||||
float GetBlue () {return (float ((colour ) & 0x3ff)) / 0x3ff;}
|
||||
};
|
||||
|
||||
class G4RayView: virtual public G4VView {
|
||||
|
||||
public:
|
||||
|
||||
G4RayView (G4RayScene& scene, const G4String& name = "");
|
||||
|
||||
~G4RayView();
|
||||
|
||||
G4double GetResolution () const;
|
||||
|
||||
void SetResolution (G4double resolution);
|
||||
|
||||
protected:
|
||||
|
||||
void SetView ();
|
||||
|
||||
void InitialiseImage ();
|
||||
|
||||
void TriggerRedraw ();
|
||||
|
||||
G4bool Scan (int& i, int& j, int& k,
|
||||
float& red, float& green, float& blue,
|
||||
int& iPixVal);
|
||||
// Iterate over window, return false when finished. Return i, j,
|
||||
// and k which define a coloured Square of side k whose upper left
|
||||
// corner is (i, j). Note origin is at upper left corner of window
|
||||
// - X and PostScript convention. iPixVal is the pixel value for
|
||||
// this colour, i.e., the key in fRayHitColourIndex.
|
||||
|
||||
// The following static members define an image. They are static so
|
||||
// that (a) there is only ever one of them (they can take a lot of
|
||||
// memory) and (b) any object of the class or its descendants can
|
||||
// access it. It is *not* cleared by ClearView (). It is only
|
||||
// cleared by a change of view parameters and some other crucial
|
||||
// parameters. It can be progressively refined by multiple calls to
|
||||
// DrawView.
|
||||
static G4ViewParameters fImageViewParameters;
|
||||
static G4double fInitialResolution;
|
||||
static G4double fRequestedResolution;
|
||||
static G4double fCurrentResolution;
|
||||
static G4float fMaxMinColourSeparation;
|
||||
static G4int fImageWidth, fImageHeight;
|
||||
static G4int fMaxImageMapEntries;
|
||||
static G4bool fImageMapRejigged;
|
||||
static G4bool fTriggerRescan;
|
||||
static G4int fWaitLimit; // Waits between refresh.
|
||||
static G4int fWaitCount;
|
||||
static RWTValOrderedVector <G4RayColourCell> fRayHitColourMap;
|
||||
static RWTValHashDictionary <G4RayCoordinate, G4RayHitColour> fRayHits;
|
||||
static unsigned int RayCoordHash (const G4RayCoordinate& rayCoord);
|
||||
static RWTValHashDictionary <G4RayHitColour, G4int> fRayHitColourIndex;
|
||||
static unsigned int RayColourHash (const G4RayHitColour& rayColour);
|
||||
|
||||
private:
|
||||
void Trace (G4double x, G4double y, float& red, float& green, float& blue);
|
||||
// Trace the ray from (x, y) in screen coordinates (-1 <= x,y <= 1)
|
||||
// and fill colour.
|
||||
|
||||
void CompactColour (G4bool Print);
|
||||
|
||||
float ColourSeparation (float ri, float gi, float bi,
|
||||
float rj, float gj, float bj);
|
||||
|
||||
static void ChangePixVals (const G4RayHitColour& colour,
|
||||
G4int& index, void* ij);
|
||||
|
||||
static void DecrementPixVals (const G4RayHitColour& colour,
|
||||
G4int& index, void* ij);
|
||||
|
||||
static void PrintPixVals (const G4RayHitColour& colour,
|
||||
G4int& index, void* ij);
|
||||
|
||||
G4RayScene& fScene; // Graphics Scene for this view.
|
||||
|
||||
G4Vector3D fXprime;
|
||||
G4Vector3D fYprime;
|
||||
|
||||
G4Point3D fCenterofscreen;
|
||||
G4Point3D fCamerapoint;
|
||||
|
||||
G4RunManager* fG4RayRunManager ;
|
||||
G4RaySteppingAction* fG4RaySteppingAction;
|
||||
G4RayPrimaryGeneratorAction* fG4RayGenerator;
|
||||
|
||||
G4ParticleGun * fG4RayGun ;
|
||||
|
||||
G4VPhysicalVolume * fpWorld;
|
||||
|
||||
};
|
||||
|
||||
#include "G4RayView.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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: G4RayView.icc,v 2.0 1998/07/02 16:42:54 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing view.
|
||||
|
||||
inline G4double G4RayView::GetResolution () const {
|
||||
return fRequestedResolution;
|
||||
}
|
||||
|
||||
inline void G4RayView::SetResolution (G4double resolution) {
|
||||
fRequestedResolution = resolution;
|
||||
}
|
||||
|
||||
inline unsigned int G4RayView::RayCoordHash
|
||||
(const G4RayCoordinate& rayCoord) {
|
||||
return rayCoord.coord;
|
||||
}
|
||||
|
||||
inline unsigned int G4RayView::RayColourHash
|
||||
(const G4RayHitColour& rayColour) {
|
||||
return rayColour.colour;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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: G4RayX.hh,v 2.1 1998/11/06 13:41:52 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing graphics system factory.
|
||||
|
||||
#if defined (G4VIS_BUILD_RAYX_DRIVER) || defined (G4VIS_USE_RAYX)
|
||||
|
||||
#ifndef G4RAYX_HH
|
||||
#define G4RAYX_HH
|
||||
|
||||
#include "G4VGraphicsSystem.hh"
|
||||
|
||||
class G4RayXMessenger;
|
||||
|
||||
class G4RayX: public G4VGraphicsSystem {
|
||||
public:
|
||||
G4RayX ();
|
||||
~G4RayX ();
|
||||
G4VScene* CreateScene (const G4String& name = "");
|
||||
G4VView* CreateView (G4VScene&, const G4String& name = "");
|
||||
private:
|
||||
static G4int fInstances;
|
||||
G4RayXMessenger* fpMessenger; // Pointer to messenger.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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: G4RayXMessenger.hh,v 2.2 1998/07/12 03:44:33 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// GEANT4 Ray tracing for X windows Messenger - John Allison 5th June 1997
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#ifndef G4RAYXMESSENGER_HH
|
||||
#define G4RAYXMESSENGER_HH
|
||||
|
||||
#include "G4RayMessenger.hh"
|
||||
|
||||
class G4RayX;
|
||||
class G4UIcommand;
|
||||
|
||||
class G4RayXMessenger: public G4RayMessenger {
|
||||
public:
|
||||
G4RayXMessenger (G4RayX* pRayX);
|
||||
~G4RayXMessenger ();
|
||||
void SetNewValue (G4UIcommand* command, G4String newValues);
|
||||
G4String GetCurrentValue (G4UIcommand* command);
|
||||
private:
|
||||
G4RayX* fpRayX;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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: G4RayXView.hh,v 2.1 1998/11/06 13:41:53 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing X window view.
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#ifndef G4RAYXVIEW_HH
|
||||
#define G4RAYXVIEW_HH
|
||||
|
||||
#include "G4RayView.hh"
|
||||
#include "G4OwnColormapXView.hh"
|
||||
|
||||
class G4RayScene;
|
||||
|
||||
class G4RayXView: public G4RayView, public G4OwnColormapXView {
|
||||
|
||||
public:
|
||||
G4RayXView (G4RayScene& scene, const G4String& name = "");
|
||||
void DrawView ();
|
||||
|
||||
private:
|
||||
int ncells;
|
||||
/*****************************
|
||||
// An RGB map for now
|
||||
int red_max;
|
||||
int green_max;
|
||||
int blue_max;
|
||||
int red_mult;
|
||||
int green_mult;
|
||||
int blue_mult;
|
||||
********************************/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,245 @@
|
||||
// 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: G4OwnColormapXView.cc,v 2.4 1998/10/23 17:58:22 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// John Allison 1st June 1997
|
||||
// Loosely based on G4OpenGLXView by Andrew Walkden 7th February 1997
|
||||
// G4OwnColormapXView : Class to provide X Windows with its own colormap
|
||||
// for a GEANT4 view. The derived view must define the colormap.
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#include "G4OwnColormapXView.hh"
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <iomanip.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NewString(str) \
|
||||
((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
|
||||
|
||||
static Bool WaitForNotify (Display* d, XEvent* e, char* arg) {
|
||||
return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
|
||||
}
|
||||
|
||||
G4OwnColormapXView::G4OwnColormapXView (G4VScene& scene):
|
||||
G4VView (scene, -1),
|
||||
fRedShift (0),
|
||||
fGreenShift (0),
|
||||
fBlueShift (0),
|
||||
fRedMax (1),
|
||||
fGreenMax (1),
|
||||
fBlueMax (1)
|
||||
{
|
||||
fpDisplay = XOpenDisplay (0);
|
||||
if (!fpDisplay) {
|
||||
G4cerr << "G4OwnColormapXView::G4OwnColormapXView couldn't open display." << endl;
|
||||
fViewId = -1; // This flags an error.
|
||||
return;
|
||||
}
|
||||
|
||||
fScreen = XDefaultScreen (fpDisplay);
|
||||
|
||||
fDepth = XDefaultDepth (fpDisplay, fScreen);
|
||||
if (fDepth < 8) {
|
||||
G4cerr << "G4OwnColormapXView::G4OwnColormapXView: too few pixel"
|
||||
"\nplanes - need at least 8 for own colormap." << endl;
|
||||
fViewId = -1; // This flags an error.
|
||||
return;
|
||||
}
|
||||
|
||||
XVisualInfo vinfo;
|
||||
if (XMatchVisualInfo (fpDisplay, fScreen, fDepth, PseudoColor, &vinfo)) {
|
||||
G4cout << "G4OwnColormapXView::G4OwnColormapXView: PseudoColor." << endl;
|
||||
fVisualName = "PseudoColor";
|
||||
fTrueColor = false;
|
||||
}
|
||||
else if
|
||||
(XMatchVisualInfo (fpDisplay, fScreen, fDepth, DirectColor, &vinfo)) {
|
||||
G4cout << "G4OwnColormapXView::G4OwnColormapXView: DirectColor." << endl;
|
||||
fVisualName = "DirectColor";
|
||||
fTrueColor = false;
|
||||
}
|
||||
else if
|
||||
(XMatchVisualInfo (fpDisplay, fScreen, fDepth, TrueColor, &vinfo)) {
|
||||
G4cout << "G4OwnColormapXView::G4OwnColormapXView: TrueColor." << endl;
|
||||
fVisualName = "TrueColor";
|
||||
fTrueColor = true;
|
||||
}
|
||||
else {
|
||||
G4cerr << "G4OwnColormapXView::G4OwnColormapXView: neither a PseudoColor nor"
|
||||
"\na DirectColor nor a TrueColor visual - needs to be one of these"
|
||||
"\nfor own colormap."
|
||||
<< endl;
|
||||
fViewId = -1; // This flags an error.
|
||||
return;
|
||||
}
|
||||
|
||||
fpVisual = vinfo.visual;
|
||||
if (!fpVisual) {
|
||||
G4cerr << "G4OwnColormapXView::G4OwnColormapXView couldn't get a visual."
|
||||
<< endl;
|
||||
fViewId = -1; // This flags an error.
|
||||
return;
|
||||
}
|
||||
|
||||
fMapEntries = fpVisual -> map_entries;
|
||||
|
||||
fRootW = XRootWindow (fpDisplay, fScreen);
|
||||
|
||||
if (fTrueColor) {
|
||||
// Set up parameters for masks etc.
|
||||
unsigned long oneBit;
|
||||
oneBit = 1;
|
||||
while (!(fpVisual->red_mask & oneBit)) {oneBit <<= 1; fRedShift++;}
|
||||
while (fpVisual->red_mask & oneBit) {oneBit <<= 1; fRedMax *= 2.;}
|
||||
fRedMax -= 1.;
|
||||
oneBit = 1;
|
||||
while (!(fpVisual->green_mask & oneBit)) {oneBit <<= 1; fGreenShift++;}
|
||||
while (fpVisual->green_mask & oneBit) {oneBit <<= 1; fGreenMax *= 2.;}
|
||||
fGreenMax -= 1.;
|
||||
oneBit = 1;
|
||||
while (!(fpVisual->blue_mask & oneBit)) {oneBit <<= 1; fBlueShift++;}
|
||||
while (fpVisual->blue_mask & oneBit) {oneBit <<= 1; fBlueMax *= 2.;}
|
||||
fBlueMax -= 1.;
|
||||
}
|
||||
else {
|
||||
// Own colour map.
|
||||
fColormap = XCreateColormap (fpDisplay, fRootW, fpVisual, AllocAll);
|
||||
if (!fColormap || fColormap == XDefaultColormap (fpDisplay, fScreen)) {
|
||||
G4cerr << "G4OwnColormapXView::G4OwnColormapXView failed to create"
|
||||
"\na own Colormap." << endl;
|
||||
fViewId = -1; // This flags an error.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fGC = XDefaultGC (fpDisplay, fScreen); // Graphics Context for XDraw...
|
||||
|
||||
XGetWindowAttributes (fpDisplay, fRootW, &fRootWA); // Get root window atts.
|
||||
|
||||
//Choose a preferred window size.
|
||||
G4int requestWinSize_x;
|
||||
G4int requestWinSize_y;
|
||||
if (fRootWA.width > fRootWA.height) {
|
||||
requestWinSize_x = (fRootWA.height)/2;
|
||||
requestWinSize_y = (fRootWA.height)/2;
|
||||
}
|
||||
else {
|
||||
requestWinSize_x = (fRootWA.width)/2;
|
||||
requestWinSize_y = (fRootWA.width)/2;
|
||||
}
|
||||
if (requestWinSize_x < fVP.GetWindowSizeHintX ())
|
||||
requestWinSize_x = fVP.GetWindowSizeHintX ();
|
||||
if (requestWinSize_y < fVP.GetWindowSizeHintY ())
|
||||
requestWinSize_y = fVP.GetWindowSizeHintY ();
|
||||
|
||||
// Choose an origin (the window manager will ignore it!)
|
||||
G4int x_origin;
|
||||
G4int y_origin;
|
||||
x_origin = fRootWA.x;
|
||||
y_origin = fRootWA.y;
|
||||
|
||||
if (!fTrueColor) {
|
||||
fSWA.colormap = fColormap;
|
||||
}
|
||||
fSWA.background_pixel = 0;
|
||||
fSWA.border_pixel = 0;
|
||||
fSWA.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
|
||||
fSWA.backing_store = WhenMapped;
|
||||
unsigned int mask = CWBackPixel | CWBorderPixel |
|
||||
CWEventMask | CWBackingStore;
|
||||
if (!fTrueColor) mask = mask | CWColormap;
|
||||
fWindow = XCreateWindow (fpDisplay, fRootW, x_origin,
|
||||
y_origin, requestWinSize_x, requestWinSize_y, 0,
|
||||
fDepth, InputOutput, fpVisual,
|
||||
mask,
|
||||
&fSWA);
|
||||
|
||||
G4cout << "Window name: " << fName << endl;
|
||||
fcharViewName = new char [100];
|
||||
strncpy (fcharViewName, fName, 100);
|
||||
XStringListToTextProperty (&fcharViewName, 1, &fWindowName);
|
||||
XStringListToTextProperty (&fcharViewName, 1, &fIconName);
|
||||
|
||||
fSize_hints = XAllocSizeHints();
|
||||
fSize_hints -> flags = PPosition | PSize | PMinSize;
|
||||
fSize_hints -> min_width = 300;
|
||||
fSize_hints -> min_height = 300;
|
||||
|
||||
fWM_hints = XAllocWMHints();
|
||||
fWM_hints -> initial_state = NormalState;
|
||||
fWM_hints -> input = True;
|
||||
fWM_hints -> icon_pixmap = fIcon_pixmap;
|
||||
fWM_hints -> flags = StateHint | IconPixmapHint | InputHint;
|
||||
|
||||
fClass_hints = XAllocClassHint();
|
||||
fClass_hints -> res_name = NewString("G4SimpleX");
|
||||
fClass_hints -> res_class = NewString("G4SimpleX");
|
||||
|
||||
XSetWMProperties (fpDisplay, fWindow, &fWindowName, &fIconName, 0, 0,
|
||||
fSize_hints, fWM_hints, fClass_hints);
|
||||
|
||||
// request X to Draw window on screen.
|
||||
XMapWindow (fpDisplay, fWindow);
|
||||
|
||||
// Wait for window to appear (wait for an "expose" event).
|
||||
XIfEvent (fpDisplay, &fEvent, WaitForNotify, (char*) fWindow);
|
||||
|
||||
XGetWindowAttributes (fpDisplay, fWindow, &fWA);
|
||||
fWidth = fWA.width;
|
||||
fHeight = fWA.height;
|
||||
G4cout << "G4OwnColormapXView instantiated."
|
||||
"\n A simple X window of visual type "
|
||||
<< fVisualName
|
||||
<< ",\n size " << fWidth << 'x' << fHeight << ", depth " << fDepth;
|
||||
if (fTrueColor) {
|
||||
G4cout << "\nRed shift : " << setw(2) << fRedShift
|
||||
<< ", red max : " << fRedMax;
|
||||
G4cout << "\nGreen shift: " << setw(2) << fGreenShift
|
||||
<< ", green max: " << fGreenMax;
|
||||
G4cout << "\nBlue shift : " << setw(2) << fBlueShift
|
||||
<< ", blue max : " << fBlueMax;
|
||||
}
|
||||
else {
|
||||
G4cout << ",\n with " << fMapEntries << " colormap entries";
|
||||
}
|
||||
G4cout << ", has been opened." << endl;
|
||||
}
|
||||
|
||||
G4OwnColormapXView::~G4OwnColormapXView () {
|
||||
if (fViewId >= 0) {
|
||||
XFree (fSize_hints);
|
||||
XFree (fWM_hints);
|
||||
if(fClass_hints -> res_name!=NULL) free(fClass_hints -> res_name);
|
||||
if(fClass_hints -> res_class!=NULL) free(fClass_hints -> res_class);
|
||||
XFree (fClass_hints);
|
||||
//Close a window from here
|
||||
XUnmapWindow (fpDisplay, fWindow);
|
||||
XDestroyWindow (fpDisplay, fWindow);
|
||||
}
|
||||
if (fpDisplay) {
|
||||
XFlush (fpDisplay);
|
||||
XCloseDisplay (fpDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
void G4OwnColormapXView::ClearView () {
|
||||
XClearWindow (fpDisplay, fWindow);
|
||||
}
|
||||
|
||||
void G4OwnColormapXView::FinishView () {
|
||||
XFlush (fpDisplay);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,85 @@
|
||||
// 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: G4RayMessenger.cc,v 2.4 1998/07/13 17:11:10 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// GEANT4 Ray tracing for X windows Messenger - John Allison 5th June 1997
|
||||
|
||||
#include "G4RayMessenger.hh"
|
||||
|
||||
#include "G4RayScene.hh"
|
||||
#include "G4RayView.hh"
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIparameter.hh"
|
||||
|
||||
G4RayMessenger::G4RayMessenger ():
|
||||
fpScene (0),
|
||||
fpView (0)
|
||||
{
|
||||
G4UIcommand* command;
|
||||
G4UIparameter* param;
|
||||
|
||||
///////////////////////////////////////////////// /vis~/ray/... ////
|
||||
//vis \hline
|
||||
//vis /vis~/ray/ &&
|
||||
//vis ...menu of ray tracing commands. \\%
|
||||
command = new G4UIcommand ("/vis~/ray/", this);
|
||||
command -> SetGuidance ("GEANT4 Ray Tracing");
|
||||
fpVisRayCommandDirectory = command;
|
||||
|
||||
///////////////////////////////////////////////// /vis~/ray/resolution ////
|
||||
//vis \hline
|
||||
//vis /vis~/ray/resolution/ & resolution &
|
||||
//vis Set resolution in pixels. A resolution less than 1 causes
|
||||
//vis over-sampling which improves the appearance and avoids random
|
||||
//vis spots and staircase effects (aliasing). \\%
|
||||
command = new G4UIcommand ("/vis~/ray/resolution", this);
|
||||
command -> SetGuidance
|
||||
("Set resolution in pixels. A resolution less than 1 causes"
|
||||
"\nover-sampling which improves the appearance and avoids random"
|
||||
"\nspots and staircase effects (aliasing)."
|
||||
);
|
||||
param = new G4UIparameter ("resolution", 'd', true);
|
||||
param -> SetDefaultValue (-1);
|
||||
command -> SetParameter (param);
|
||||
fpResolutionCommand = command;
|
||||
}
|
||||
|
||||
G4RayMessenger::~G4RayMessenger () {
|
||||
delete fpResolutionCommand;
|
||||
delete fpVisRayCommandDirectory;
|
||||
}
|
||||
|
||||
void G4RayMessenger::SetNewValue (G4UIcommand* command, G4String newValues)
|
||||
{
|
||||
///////////////////////////////////////////////// /vis~/ray/resolution ////
|
||||
if (command == fpResolutionCommand) {
|
||||
G4double resolution;
|
||||
const char* t = newValues;
|
||||
istrstream is ((char*)t); is >> resolution;
|
||||
if (resolution < 0) {
|
||||
G4cout << "Resolution is currently "
|
||||
<< fpView -> GetResolution ()
|
||||
<< "\nSupply required resolution as argument."
|
||||
<< endl;
|
||||
}
|
||||
else {
|
||||
fpView -> SetResolution (resolution);
|
||||
G4cout << "Resolution is now "
|
||||
<< fpView -> GetResolution ()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
G4String G4RayMessenger::GetCurrentValue (G4UIcommand* command) {
|
||||
return "";
|
||||
}
|
||||
@@ -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: G4RayPrimaryGeneratorAction.cc,v 2.2 1998/08/05 12:53:43 barrand Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#include "G4RayPrimaryGeneratorAction.hh"
|
||||
|
||||
#include "G4Event.hh"
|
||||
#include "G4ParticleGun.hh"
|
||||
#include "G4ParticleTable.hh"
|
||||
#include "G4ParticleDefinition.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
G4RayPrimaryGeneratorAction::G4RayPrimaryGeneratorAction()
|
||||
{
|
||||
G4int n_particle = 1;
|
||||
particleGun = new G4ParticleGun(n_particle);
|
||||
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
||||
G4String particleName;
|
||||
G4ParticleDefinition* particle
|
||||
= particleTable->FindParticle(particleName="geantino");
|
||||
particleGun->SetParticleDefinition(particle);
|
||||
|
||||
particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,1.,0.));
|
||||
particleGun->SetParticleEnergy(100.*GeV);
|
||||
particleGun->SetParticlePosition(G4ThreeVector(0.*cm,-300.*cm,0.*cm));
|
||||
}
|
||||
|
||||
G4RayPrimaryGeneratorAction::~G4RayPrimaryGeneratorAction()
|
||||
{
|
||||
delete particleGun;
|
||||
}
|
||||
|
||||
void G4RayPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
|
||||
{
|
||||
/***************************** Moved to constructor.
|
||||
*************************** Change with ParticleGunMessenger.
|
||||
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
||||
G4String particleName;
|
||||
G4ParticleDefinition* particle
|
||||
= particleTable->FindParticle(particleName="geantino");
|
||||
particleGun->SetParticleDefinition(particle);
|
||||
|
||||
particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,1.,0.));
|
||||
particleGun->SetParticleEnergy(100.*GeV);
|
||||
particleGun->SetParticlePosition(G4ThreeVector(0.*cm,-300.*cm,0.*cm));
|
||||
********************************/
|
||||
particleGun->GeneratePrimaryVertex(anEvent);
|
||||
}
|
||||
|
||||
G4ParticleGun* G4RayPrimaryGeneratorAction::GetParticleGun()
|
||||
{
|
||||
return particleGun;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// 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: G4RayScene.cc,v 2.3 1998/11/06 13:41:55 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing scene.
|
||||
|
||||
#include "G4RayScene.hh"
|
||||
|
||||
G4RayScene::G4RayScene (G4VGraphicsSystem& system,
|
||||
const G4String& name):
|
||||
G4VScene (system, fSceneIdCount++, name)
|
||||
{
|
||||
fSceneCount++;
|
||||
}
|
||||
|
||||
G4RayScene::~G4RayScene ()
|
||||
{
|
||||
fSceneCount--;
|
||||
}
|
||||
|
||||
G4int G4RayScene::GetSceneCount () {
|
||||
return fSceneCount;
|
||||
}
|
||||
|
||||
void G4RayScene::AddPrimitive (const G4Polyline&) {
|
||||
static G4bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
G4cout << "***WARNING***" << endl;
|
||||
G4cout << " void G4RayScene::AddPrimitive (const G4Polyline&) called."
|
||||
<< " \nG4Ray cannot handle polylines."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayScene::AddPrimitive (const G4Text&) {
|
||||
static G4bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
G4cout << "***WARNING***" << endl;
|
||||
G4cout << " void G4RayScene::AddPrimitive (const G4Text&) called."
|
||||
<< " \nG4Ray cannot handle text."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayScene::AddPrimitive (const G4Circle&) {
|
||||
static G4bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
G4cout << "***WARNING***" << endl;
|
||||
G4cout << " void G4RayScene::AddPrimitive (const G4Circle&) called."
|
||||
<< " \nG4Ray cannot handle markers."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayScene::AddPrimitive (const G4Square&) {
|
||||
static G4bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
G4cout << "***WARNING***" << endl;
|
||||
G4cout << " void G4RayScene::AddPrimitive (const G4Square&) called."
|
||||
<< " \nG4Ray cannot handle markers."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayScene::AddPrimitive (const G4Polyhedron&) {
|
||||
static G4bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
G4cout << "***WARNING***" << endl;
|
||||
G4cout << "void G4RayScene::AddPrimitive (const G4Polyhedron&) called."
|
||||
<< " \nG4Ray cannot handle polyhedra."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayScene::AddPrimitive (const G4NURBS&) {
|
||||
static G4bool warned = false;
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
G4cout << "***WARNING***" << endl;
|
||||
G4cout << "void G4RayScene::AddPrimitive (const G4NURBS&) called."
|
||||
<< " \nG4Ray cannot handle NURBS."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
G4int G4RayScene::fSceneIdCount = 0;
|
||||
|
||||
G4int G4RayScene::fSceneCount = 0;
|
||||
@@ -0,0 +1,109 @@
|
||||
// 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: G4RaySteppingAction.cc,v 2.1 1998/07/13 17:11:12 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// 16/Apr/1997 J. Allison: For visualization/test/test19.
|
||||
|
||||
#include "G4RaySteppingAction.hh"
|
||||
|
||||
#include "G4SteppingManager.hh"
|
||||
#include "G4ParticleDefinition.hh"
|
||||
#include "G4VVisManager.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Colour.hh"
|
||||
#include "G4Polyline.hh"
|
||||
#include "G4Point3D.hh"
|
||||
#include "G4Vector3D.hh"
|
||||
|
||||
G4RaySteppingAction::G4RaySteppingAction() : weHaveContact(false), pVisAttribs(0){}
|
||||
|
||||
void G4RaySteppingAction::UserSteppingAction() {
|
||||
|
||||
G4Step* piStep = GetSteppingManager () -> GetStep ();
|
||||
// G4cout <<"G4Step* piStep: "<< (void *) piStep << endl;
|
||||
|
||||
G4Track* pTrack = piStep -> GetTrack();
|
||||
//G4cout << "G4Track* pTrack: "<<(void *) pTrack << endl;
|
||||
|
||||
pVPV = pTrack -> GetNextVolume();
|
||||
//G4cout << "G4VPhysicalVolume* pVPV: "<<(void *) pVPV << endl;
|
||||
|
||||
if (pVPV) {
|
||||
|
||||
weHaveContact = true;
|
||||
|
||||
pLV = pVPV -> GetLogicalVolume();
|
||||
//G4cout <<"G4LogicalVolume* pLV: "<< (void *) pLV << endl;
|
||||
|
||||
pSol = pLV -> GetSolid();
|
||||
//G4cout <<"G4VSolid* pSol: "<< (void *) pSol << endl;
|
||||
|
||||
G4Point3D point = piStep -> GetPostStepPoint () -> GetPosition ();
|
||||
//G4cout << "Point: " << point << endl;
|
||||
|
||||
G4Vector3D translation = pVPV -> GetTranslation();
|
||||
G4RotationMatrix* rotation = pVPV -> GetRotation();
|
||||
if (rotation) {
|
||||
point.transform(G4Transform3D(*rotation, -translation));
|
||||
}
|
||||
else {
|
||||
point.transform(G4Translate3D(-translation));
|
||||
}
|
||||
//G4cout << "Point after transformation: " << point << endl;
|
||||
|
||||
normal = pSol -> SurfaceNormal(point);
|
||||
//G4cout << "normal: " << normal << endl;
|
||||
|
||||
pVisAttribs = pLV -> GetVisAttributes ();
|
||||
//G4cout << "Vis attributes: " << *pVisAttribs << endl;
|
||||
}
|
||||
else {
|
||||
weHaveContact = false;
|
||||
}
|
||||
|
||||
pTrack -> SetTrackStatus(fStopAndKill);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,783 @@
|
||||
// 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: G4RayView.cc,v 2.9 1998/11/06 13:41:56 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing view.
|
||||
|
||||
#include "G4RayView.hh"
|
||||
|
||||
#include "G4RayScene.hh"
|
||||
|
||||
#include "G4ParticleGun.hh"
|
||||
#include "G4TransportationManager.hh"
|
||||
#include "geomdefs.hh"
|
||||
|
||||
#include "G4VSolid.hh"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifdef GNU_GCC
|
||||
template class RWTValHashDictionary <G4RayCoordinate, G4RayHitColour>;
|
||||
template class RWTValHashDictionary <G4RayHitColour, G4int>;
|
||||
#endif
|
||||
|
||||
G4RayView::G4RayView (G4RayScene& scene, const G4String& name):
|
||||
G4VView (scene, -1, name),
|
||||
fScene (scene),
|
||||
fpWorld (0)
|
||||
{
|
||||
//RUN MANAGER
|
||||
fG4RayRunManager = new G4RunManager;
|
||||
|
||||
//G4RaySteppingAction
|
||||
fG4RaySteppingAction = new G4RaySteppingAction;
|
||||
|
||||
//Gun
|
||||
fG4RayGenerator = new G4RayPrimaryGeneratorAction;
|
||||
|
||||
fG4RayRunManager -> SetUserAction ( fG4RayGenerator );
|
||||
fG4RayRunManager -> SetUserAction ( fG4RaySteppingAction);
|
||||
|
||||
fG4RayGun = fG4RayGenerator -> GetParticleGun();
|
||||
}
|
||||
|
||||
G4RayView::~G4RayView(){
|
||||
|
||||
delete fG4RayRunManager;
|
||||
// Note: G4RunManager deletes userPrimaryGeneratorAction, what we
|
||||
// have called fG4RayGenerator). And G4SteppingManager deletes
|
||||
// fUserSteppingAction, what we have called fG4RaySteppingAction
|
||||
|
||||
}
|
||||
|
||||
void G4RayView::SetView () {
|
||||
|
||||
fpWorld = G4TransportationManager::GetTransportationManager ()
|
||||
-> GetNavigatorForTracking () -> GetWorldVolume ();
|
||||
|
||||
// We need to know the world so we can be sure to start traceing inside.
|
||||
|
||||
if (!fpWorld) {
|
||||
G4Exception ("G4RayView::SetView: no world established yet!");
|
||||
}
|
||||
|
||||
// VECTORS
|
||||
|
||||
const G4Vector3D& viewvector = fVP.GetViewpointDirection().unit();
|
||||
// view vector on the line from the target point to the eye-- view
|
||||
// point direction
|
||||
|
||||
const G4Vector3D& upvector = fVP.GetUpVector().unit(); // the up vector of the volume
|
||||
|
||||
const G4Vector3D& lightDirection = fVP.GetActualLightpointDirection().unit();
|
||||
// vector of incident light
|
||||
|
||||
|
||||
// DOUBLES
|
||||
G4double radius = fScene.GetSceneData ().GetExtent ().GetExtentRadius ();
|
||||
//radius of the bounding sphere.
|
||||
|
||||
G4double cameradistance = fVP.GetCameraDistance (radius);
|
||||
// from the center of the bounding sphere to the camera.
|
||||
|
||||
G4double johnsneardistance = fVP.GetNearDistance (cameradistance, radius);
|
||||
|
||||
G4double halfheight = fVP.GetFrontHalfHeight (johnsneardistance, radius);
|
||||
// half the size of the front view plane (screen)
|
||||
|
||||
// xprime ,yprime, zprime define the screen coordinate system.
|
||||
G4Vector3D zprime = viewvector.unit();
|
||||
G4Vector3D xprime = (upvector.cross(viewvector)).unit();
|
||||
G4Vector3D yprime = (zprime.cross(xprime)).unit();
|
||||
// Make xprime and yprime have lengths equal to halfheight so that
|
||||
// they can be multplied by a screen coordinate in the range -1 to
|
||||
// +1.
|
||||
fXprime = halfheight * xprime;
|
||||
fYprime = halfheight * yprime;
|
||||
|
||||
|
||||
// POINTS
|
||||
const G4Point3D& centeroftarget = fVP.GetCurrentTargetPoint ();// the center of target
|
||||
|
||||
|
||||
//fCenterofscreen = centeroftarget + radius * viewvector.unit();
|
||||
fCamerapoint = centeroftarget + cameradistance * viewvector.unit();
|
||||
fCenterofscreen = fCamerapoint - johnsneardistance * viewvector.unit();
|
||||
|
||||
G4cout << " The viewvector is : " << viewvector<<endl;
|
||||
G4cout << " The lightDirection is : " << lightDirection << endl;
|
||||
G4cout << " The cameraDistance is: " << cameradistance << endl;
|
||||
G4cout << " fCamerapoint is : " << fCamerapoint << endl;
|
||||
G4cout << " fCenterofscreen is : " << fCenterofscreen << endl;
|
||||
G4cout << " centeroftarget is : " << centeroftarget << endl;
|
||||
|
||||
}
|
||||
|
||||
G4ViewParameters G4RayView::fImageViewParameters;
|
||||
G4double G4RayView::fInitialResolution = 27.;
|
||||
G4double G4RayView::fRequestedResolution = 27.;
|
||||
G4double G4RayView::fCurrentResolution = 27.;
|
||||
G4float G4RayView::fMaxMinColourSeparation = 0.;
|
||||
G4int G4RayView::fImageWidth = 0;
|
||||
G4int G4RayView::fImageHeight = 0;
|
||||
G4int G4RayView::fMaxImageMapEntries = 0;
|
||||
G4bool G4RayView::fImageMapRejigged = true;
|
||||
G4bool G4RayView::fTriggerRescan = true;
|
||||
G4int G4RayView::fWaitLimit = 200;
|
||||
G4int G4RayView::fWaitCount = 200;
|
||||
|
||||
RWTValOrderedVector <G4RayColourCell>
|
||||
G4RayView::fRayHitColourMap (256);
|
||||
|
||||
RWTValHashDictionary <G4RayCoordinate, G4RayHitColour>
|
||||
G4RayView::fRayHits (G4RayView::RayCoordHash, 1000);
|
||||
|
||||
RWTValHashDictionary <G4RayHitColour, G4int>
|
||||
G4RayView::fRayHitColourIndex (G4RayView::RayColourHash, 1000);
|
||||
|
||||
void G4RayView::InitialiseImage () {
|
||||
fRayHitColourMap.clear ();
|
||||
fRayHits.clear ();
|
||||
fMaxMinColourSeparation = 0.;
|
||||
fInitialResolution = 27;
|
||||
fCurrentResolution = fInitialResolution;
|
||||
fRequestedResolution = fInitialResolution;
|
||||
G4cout << "Requested resolution reset to " << fRequestedResolution << endl;
|
||||
fWaitLimit = 200;
|
||||
G4cout << "Wait limit reset to: " << fWaitLimit
|
||||
<< "\n(e.g, display refreshed every this many rays traced.)"
|
||||
<< endl;
|
||||
TriggerRedraw ();
|
||||
}
|
||||
|
||||
void G4RayView::TriggerRedraw () {
|
||||
fImageMapRejigged = true;
|
||||
fTriggerRescan = true;
|
||||
fWaitCount = fWaitLimit;
|
||||
}
|
||||
|
||||
G4bool G4RayView::Scan (int& i, int& j, int& k,
|
||||
float& red, float& green, float& blue,
|
||||
int& iPixVal) {
|
||||
|
||||
static G4bool Done = true;
|
||||
static G4bool nearlyDone;
|
||||
static G4double cellSize;
|
||||
static G4int requestedNoOfRays;
|
||||
static G4int doneCount;
|
||||
static G4int u, v;
|
||||
|
||||
|
||||
if (Done) { // Assume called anew.
|
||||
if (fRequestedResolution < 1.0) {
|
||||
G4cout <<
|
||||
"Over-sampling not implemented - resetting requested resolution to 1."
|
||||
<< endl;
|
||||
fRequestedResolution = 1.;
|
||||
}
|
||||
Done = false;
|
||||
nearlyDone = false;
|
||||
requestedNoOfRays = (int)
|
||||
((((fImageWidth - 1) / fRequestedResolution) + 1) *
|
||||
(((fImageHeight - 1) / fRequestedResolution) + 1));
|
||||
doneCount = 1;
|
||||
cellSize = fInitialResolution;
|
||||
u = v = 0;
|
||||
if (fCurrentResolution >= 3 * fRequestedResolution) {
|
||||
G4cout << "Resizing Ray Hits Dictionaries - " << requestedNoOfRays
|
||||
<< " buckets." << endl;
|
||||
fRayHits.resize (requestedNoOfRays);
|
||||
fRayHitColourIndex.resize (requestedNoOfRays);
|
||||
G4cout << "Continuing..." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (fTriggerRescan) {
|
||||
fTriggerRescan = false;
|
||||
cellSize = 3 * cellSize;
|
||||
u = v = 0;
|
||||
}
|
||||
|
||||
if (fRayHitColourMap.entries () >= fMaxImageMapEntries) {
|
||||
static int count = 0;
|
||||
if (count++ < 10 || count % 10 == 0) {
|
||||
G4cout << "G4RayView::Scan: compacting colour map - count = "
|
||||
<< count << endl;
|
||||
}
|
||||
CompactColour (false);
|
||||
if (fRayHitColourMap.entries () >= fMaxImageMapEntries) {
|
||||
G4Exception ("G4RayView::Scan: compaction failure!");
|
||||
}
|
||||
fImageMapRejigged = true;
|
||||
}
|
||||
|
||||
i = u;
|
||||
j = v;
|
||||
k = int (cellSize);
|
||||
|
||||
G4double x = 2. * (G4double (i + cellSize / 2) / fImageWidth - 0.5);
|
||||
G4double y = 2. * (0.5 - G4double (j + cellSize / 2) / fImageHeight);
|
||||
if (x > 1.0) x = 1.0;
|
||||
if (y < -1.0) y = -1.0;
|
||||
|
||||
G4RayCoordinate rayCoord (x, y);
|
||||
G4RayHitColour rayHitColour;
|
||||
if (fRayHits.findValue (rayCoord, rayHitColour)) {
|
||||
iPixVal = fRayHitColourIndex [rayHitColour]; // Old pixval.
|
||||
red = rayHitColour.GetRed ();
|
||||
green = rayHitColour.GetGreen ();
|
||||
blue = rayHitColour.GetBlue ();
|
||||
//G4cout << "G4RayView::Scan: " << x << ", " << y << " already traced."
|
||||
// " Pixval = " << iPixVal
|
||||
// << endl;
|
||||
}
|
||||
else {
|
||||
// Initiate a new ray.
|
||||
Trace (x, y, red, green, blue);
|
||||
doneCount++;
|
||||
int ii;
|
||||
for (ii = 0; ii < fRayHitColourMap.entries (); ii++) {
|
||||
G4RayColourCell& colourCell = fRayHitColourMap [ii];
|
||||
if (ColourSeparation
|
||||
(red, green, blue,
|
||||
colourCell.red, colourCell.green, colourCell.blue) < 0.01) {
|
||||
break; // ...if there's a close-match.
|
||||
}
|
||||
}
|
||||
iPixVal = ii; // If no close-match found, ii = no. of entries, which
|
||||
// will be no. of entries - 1 after append.
|
||||
if (iPixVal == fRayHitColourMap.entries ())
|
||||
fRayHitColourMap.append (G4RayColourCell (red, green, blue, 1));
|
||||
rayHitColour = G4RayHitColour (red, green, blue);
|
||||
fRayHits.insertKeyAndValue (rayCoord, rayHitColour);
|
||||
fRayHitColourIndex.insertKeyAndValue (rayHitColour, iPixVal);
|
||||
}
|
||||
|
||||
//G4cout << "G4RayView::Scan: Draw x,y,r,g,b,i,j,k,iPixVal: "
|
||||
// << x << ' ' << y << ' ' << red << ' ' << green << ' ' << blue << ' '
|
||||
// << i << ' ' << j << ' ' << k << ' ' << iPixVal
|
||||
// << endl;
|
||||
|
||||
if (!(doneCount % fWaitLimit) && !nearlyDone) {
|
||||
doneCount = 1;
|
||||
G4cout << "G4RayView::Scan: "
|
||||
<< (int) ((100. * (fImageWidth * v + u)) /
|
||||
(fImageWidth * fImageHeight))
|
||||
<< "% Done at cell-size "
|
||||
<< cellSize
|
||||
<< endl;
|
||||
}
|
||||
|
||||
u += int (cellSize);
|
||||
|
||||
if (u >= fImageWidth) {
|
||||
u = 0;
|
||||
v += int (cellSize);
|
||||
}
|
||||
|
||||
if (v >= fImageHeight) {
|
||||
u = v = 0;
|
||||
cellSize = cellSize / 3; // Next size down.
|
||||
}
|
||||
|
||||
if ((cellSize < fRequestedResolution
|
||||
|| 3 * cellSize < 1.)
|
||||
// The above line can be removed when over-sampling implemented.
|
||||
&& !nearlyDone
|
||||
) {
|
||||
G4cout << "G4RayView::Scan: final redraw." << endl;
|
||||
nearlyDone = true;
|
||||
cellSize = 3 * cellSize;
|
||||
u = v = 0;
|
||||
TriggerRedraw ();
|
||||
}
|
||||
|
||||
if ((cellSize < fRequestedResolution
|
||||
|| 3 * cellSize < 1.)
|
||||
// The above line can be removed when over-sampling implemented.
|
||||
&& nearlyDone
|
||||
) {
|
||||
fCurrentResolution = 3 * cellSize;
|
||||
G4cout << "G4RayView::Scan: requested resolution = "
|
||||
<< fRequestedResolution
|
||||
<< ", achieved\nresolution = "
|
||||
<< fCurrentResolution << " (always a Power of 3).";
|
||||
G4cout << "\nNo. of ray hits = " << fRayHits.entries ();
|
||||
G4cout << "\nNo. of ray Hit colours = " << fRayHitColourIndex.entries ();
|
||||
G4cout << "\nNo. of colourmap entries = " << fRayHitColourMap.entries ();
|
||||
fWaitLimit = 3 * fWaitLimit;
|
||||
G4cout << "\nWait limit increased to: " << fWaitLimit
|
||||
<< "\n(e.g, display refreshed every this many rays traced.)";
|
||||
if (fRequestedResolution < 1.) {
|
||||
G4cout << "\nOver-sampling (resolution < 1.) not implemented.";
|
||||
}
|
||||
G4cout << "\nYou can continue as follows:"
|
||||
"\n/vis~/ray/resolution " << cellSize
|
||||
<< "\n/vis~/draw/current"
|
||||
"\n(It may take some time - 10 Times longer than so far!!!"
|
||||
"\nMoreover, it will use about another "
|
||||
<< 30 * (((fImageWidth - 1) / cellSize) + 1) *
|
||||
(((fImageHeight - 1) / cellSize) + 1) * 1.e-6
|
||||
<< " MB of memory to Store the image.)";
|
||||
G4cout << endl;
|
||||
Done = true;
|
||||
}
|
||||
|
||||
return !Done;
|
||||
}
|
||||
|
||||
void G4RayView::CompactColour (G4bool Print) {
|
||||
|
||||
G4int i;
|
||||
G4int j;
|
||||
|
||||
RWTValOrderedVector <G4RayColourCell>& cmap = fRayHitColourMap;
|
||||
|
||||
G4double minColourSeparation = 2.;
|
||||
// i.e, bigger than possible in the colour cube.
|
||||
for (i = 0; i < cmap.entries (); i++) {
|
||||
G4RayColourCell& celli = fRayHitColourMap [i];
|
||||
for (j = i + 1; j < cmap.entries (); j++) {
|
||||
G4RayColourCell& cellj = fRayHitColourMap [j];
|
||||
float colourSeparation = ColourSeparation
|
||||
(celli.red, celli.green, celli.blue,
|
||||
cellj.red, cellj.green, cellj.blue);
|
||||
if (minColourSeparation > colourSeparation) {
|
||||
minColourSeparation = colourSeparation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fMaxMinColourSeparation < minColourSeparation) {
|
||||
fMaxMinColourSeparation = minColourSeparation;
|
||||
G4cout << "G4RayView::CompactColour: minColourSeparation has peaked at "
|
||||
<< minColourSeparation << endl;
|
||||
}
|
||||
|
||||
if (minColourSeparation > 0.125) {
|
||||
G4cerr << "G4RayView::CompactColour: WARNING: minimum colour separation"
|
||||
"\nis greater than 0.125, the separation of R/G/B 3/3/2!" << endl;
|
||||
}
|
||||
|
||||
G4int foundi;
|
||||
G4int foundij [2];
|
||||
RWTValOrderedVector <G4int> foundjs;
|
||||
G4int jj;
|
||||
|
||||
// Process all pairs with colour separation < compaction * minimum.
|
||||
const float compaction = 1.5;
|
||||
do {
|
||||
foundi = -1;
|
||||
for (i = 0; i < cmap.entries (); i++) {
|
||||
G4RayColourCell& celli = fRayHitColourMap [i];
|
||||
for (j = i + 1; j < cmap.entries (); j++) {
|
||||
G4RayColourCell& cellj = fRayHitColourMap [j];
|
||||
float colourSeparation = ColourSeparation
|
||||
(celli.red, celli.green, celli.blue,
|
||||
cellj.red, cellj.green, cellj.blue);
|
||||
if (colourSeparation < compaction * minColourSeparation) {
|
||||
if (foundi < 0) {
|
||||
foundi = i;
|
||||
foundjs.clear ();
|
||||
foundjs.append (i); // First entry is the i value.
|
||||
}
|
||||
foundjs.append (j);
|
||||
}
|
||||
}
|
||||
if (foundi >= 0) break;
|
||||
}
|
||||
|
||||
if (foundi >= 0) {
|
||||
|
||||
if (Print) {
|
||||
G4cout << "G4RayView::CompactColour: foundjs:";
|
||||
for (jj = 0; jj < foundjs.entries (); jj++) {
|
||||
G4cout << ' ' << foundjs [jj];
|
||||
}
|
||||
G4int iii = 0;
|
||||
G4cout << "\nG4RayView::CompactColour: (colour, index) before:";
|
||||
fRayHitColourIndex.applyToKeyAndValue (PrintPixVals, (void *) &iii);
|
||||
}
|
||||
|
||||
// Change all ray hits with pix val j to pix val i.
|
||||
fRayHitColourIndex.applyToKeyAndValue (ChangePixVals, (void *) &foundjs);
|
||||
// Decrement pix vals of all ray hits with pix val j + 1 and and above.
|
||||
for (jj = foundjs.entries (); jj-- > 1;) { // ...in reverse order so
|
||||
// that decrements are applied in the correct order.
|
||||
G4int jjj = foundjs [jj];
|
||||
fRayHitColourIndex.applyToKeyAndValue
|
||||
(DecrementPixVals, (void *) &jjj);
|
||||
}
|
||||
|
||||
// Recalculate colour map and remove redundant entries.
|
||||
G4RayColourCell& celli = fRayHitColourMap [foundi];
|
||||
for (jj = foundjs.entries (); jj-- > 1;) { // ...in reverse order so
|
||||
// that we can safely remove colour cells.
|
||||
G4int jjj = foundjs [jj];
|
||||
G4RayColourCell& cellj = fRayHitColourMap [jjj];
|
||||
// Recompute colour of cell.
|
||||
G4int N = (celli.nHits + cellj.nHits);
|
||||
celli.red = (celli.nHits * celli.red
|
||||
+ cellj.nHits * cellj.red) / N;
|
||||
celli.green = (celli.nHits * celli.green
|
||||
+ cellj.nHits * cellj.green) / N;
|
||||
celli.blue = (celli.nHits * celli.blue
|
||||
+ cellj.nHits * cellj.blue) / N;
|
||||
celli.nHits = N;
|
||||
// Finally, remove the redundant cells.
|
||||
if (Print) G4cout << "Removing " << jjj << endl;
|
||||
fRayHitColourMap.removeAt (jjj);
|
||||
}
|
||||
|
||||
if (Print) {
|
||||
G4int iii = 0;
|
||||
G4cout << "\nG4RayView::CompactColour: (colour, index) after:";
|
||||
fRayHitColourIndex.applyToKeyAndValue (PrintPixVals, (void *) &iii);
|
||||
G4cout << endl;
|
||||
}
|
||||
|
||||
}
|
||||
} while (foundi >=0);
|
||||
|
||||
if (Print) {
|
||||
G4cout << "G4RayView::CompactColour: map compressed to "
|
||||
<< fRayHitColourMap.entries ()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
float G4RayView::ColourSeparation (float ri, float gi, float bi,
|
||||
float rj, float gj, float bj) {
|
||||
float sep = abs (rj -ri);
|
||||
float sepg = abs (gj - gi);
|
||||
if (sep < sepg) sep = sepg;
|
||||
float sepb = abs (bj - bi) / 2.;
|
||||
if (sep < sepb) sep = sepb;
|
||||
return sep;
|
||||
}
|
||||
|
||||
void G4RayView::ChangePixVals (const G4RayHitColour& colour,
|
||||
G4int& index, void* pfjs) {
|
||||
|
||||
RWTValOrderedVector <G4int>* pfoundjs = (RWTValOrderedVector <G4int>*) pfjs;
|
||||
G4int i = (*pfoundjs) [0];
|
||||
|
||||
// Change all ray Hit colours with index j to index i.
|
||||
for (int jj = 1; jj < (*pfoundjs).entries (); jj++) {
|
||||
G4int j = (*pfoundjs) [jj];
|
||||
if (index == j) {
|
||||
//G4cout << "G4RayView::ChangePixVal: ray Hit colour index changed from "
|
||||
// << index;
|
||||
index = i;
|
||||
//G4cout << " to " << index << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayView::DecrementPixVals (const G4RayHitColour& colour,
|
||||
G4int& index, void* pjjj) {
|
||||
G4int jjj = * (G4int*) pjjj;
|
||||
// Decrement indices all ray Hit colours with index jjj + 1 and above.
|
||||
if (index > jjj) {
|
||||
//G4cout << index << " decremented." << endl;
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
void G4RayView::PrintPixVals (const G4RayHitColour& colour,
|
||||
G4int& index, void* pjjj) {
|
||||
G4cout << ' '
|
||||
//<< '(' << colour.colour << ','
|
||||
<< index
|
||||
//<< ')'
|
||||
;
|
||||
}
|
||||
|
||||
void G4RayView::Trace (G4double x, G4double y,
|
||||
float& red, float& green, float& blue) {
|
||||
|
||||
// Colour
|
||||
G4Colour colour; // The colour of the object
|
||||
G4double Ip = 0.6 ; // incident light intensity
|
||||
G4double Id = 0.9 ; // reflected light intensity
|
||||
G4double Ia = 0.2; // ambient light intensity
|
||||
G4double I; // total intensity
|
||||
G4double intrinsicred; // intrinsic colour of the object
|
||||
G4double intrinsicgreen; // given in red green
|
||||
G4double intrinsicblue; // and blue
|
||||
G4double outsideDistance;
|
||||
|
||||
|
||||
G4Point3D newPoint;
|
||||
|
||||
G4double Dot; // Dot product of the normal vector of surface
|
||||
// with the normalized vector of incident light
|
||||
G4double reflectionDot; // Dot product of the normal vector of reflection
|
||||
// with the normal vector of angle of viewing
|
||||
G4Vector3D rayDirection; //unit vector, the ray direction.
|
||||
G4Point3D rayPosition; // position of ray on the front view plane
|
||||
|
||||
G4Vector3D roughrayDirection; // the vector from camera to
|
||||
//the point on screen
|
||||
G4Vector3D reflightDirection; // vector of reflection light
|
||||
G4Vector3D screenvector; // vector on the front view plane pointing from
|
||||
// the center of screen to a given point on screen
|
||||
|
||||
const G4Vector3D& viewvector = fVP.GetViewpointDirection().unit();
|
||||
// view vector on the line from the target point to the eye-- view
|
||||
// point direction
|
||||
|
||||
const G4Vector3D& lightDirection = fVP.GetActualLightpointDirection().unit();
|
||||
// vector of incident light
|
||||
|
||||
|
||||
|
||||
EInside whereisit;
|
||||
|
||||
screenvector = fXprime * x + fYprime * y;
|
||||
rayPosition = fCenterofscreen + screenvector;
|
||||
|
||||
if (fVP.GetFieldHalfAngle() == 0 ) {
|
||||
rayDirection = - viewvector.unit();
|
||||
}
|
||||
else {
|
||||
roughrayDirection = rayPosition - fCamerapoint;
|
||||
rayDirection = roughrayDirection.unit();
|
||||
}
|
||||
|
||||
// Default - black.
|
||||
I = 0;
|
||||
|
||||
// Check if rayPosition is in the world.
|
||||
outsideDistance = kInfinity;
|
||||
whereisit = fpWorld -> GetLogicalVolume() -> GetSolid()->Inside(rayPosition);
|
||||
if (whereisit == kInside) {
|
||||
outsideDistance = 0.;
|
||||
}
|
||||
else { // It's outside the world, so move it inside.
|
||||
outsideDistance = fpWorld -> GetLogicalVolume() ->
|
||||
GetSolid()-> DistanceToIn(rayPosition,rayDirection);
|
||||
if ( outsideDistance != kInfinity) {
|
||||
rayPosition = rayPosition + outsideDistance * rayDirection;
|
||||
}
|
||||
}
|
||||
|
||||
if (outsideDistance != kInfinity) {
|
||||
|
||||
fG4RayGun -> SetParticlePosition(rayPosition);
|
||||
fG4RayGun -> SetParticleMomentumDirection(rayDirection);
|
||||
|
||||
fG4RayRunManager -> BeamOn(1);
|
||||
|
||||
if (fG4RaySteppingAction -> WeHaveContact ()) {
|
||||
|
||||
// Store these in the scene so we can use culling algorithms.
|
||||
// Not figured out how to do this yet.
|
||||
// Certainly we don't need to Store these in the scene now
|
||||
// culling is Done in the modeling category.
|
||||
// Rethink this.
|
||||
//fScene.SetWorkingPhysicalVolume
|
||||
//(fG4RaySteppingAction -> GetPhysicalVolume ());
|
||||
//fScene.SetWorkingLogicalVolume
|
||||
//(fG4RaySteppingAction -> GetLogicalVolume ());
|
||||
//fScene.SetWorkingSolid (fG4RaySteppingAction -> GetSolid ());
|
||||
const G4VisAttributes* pVA =
|
||||
fG4RaySteppingAction -> GetVisAttributes();
|
||||
pVA = GetApplicableVisAttributes (pVA);
|
||||
//fScene.SetWorkingVisAttributes (pVA);
|
||||
|
||||
/**** if (!fScene.IsThisCulled ()) ****/ {
|
||||
|
||||
G4Normal3D normal = fG4RaySteppingAction -> GetSurfaceNormal ();
|
||||
|
||||
// Return colour of the object
|
||||
colour = pVA -> GetColour();
|
||||
intrinsicred = colour.GetRed();
|
||||
intrinsicgreen = colour.GetGreen();
|
||||
intrinsicblue = colour.GetBlue();
|
||||
|
||||
//G4cout << "The intrnsic red colour is: " << red << endl;
|
||||
//G4cout << "The intrinsic green colour is: " << green << endl;
|
||||
//G4cout << "The intrinsic blue colour is: " << blue << endl;
|
||||
|
||||
// Calculate Intencity.
|
||||
Dot = normal.unit() * lightDirection.unit();
|
||||
reflightDirection = 2.0 * Dot * normal.unit() - lightDirection.unit();
|
||||
reflectionDot = viewvector.unit() * reflightDirection.unit();
|
||||
|
||||
if (Dot < 0) Dot = 0;
|
||||
if (reflectionDot < 0) reflectionDot = 0;
|
||||
I = Ia + Ip * Dot ; //+ Id * pow(reflectionDot,90);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/*************
|
||||
else {
|
||||
|
||||
outsideDistance = fpWorld -> GetLogicalVolume() -> GetSolid()-> DistanceToIn(rayPosition,rayDirection);
|
||||
if ( outsideDistance == kInfinity) {I=0;}
|
||||
|
||||
else{
|
||||
newPoint = rayPosition + outsideDistance * rayDirection;
|
||||
|
||||
fG4RayGun -> SetParticlePosition(newPoint);
|
||||
fG4RayGun -> SetParticleMomentumDirection(rayDirection);
|
||||
|
||||
fG4RayRunManager -> BeamOn(1);
|
||||
|
||||
if (fG4RaySteppingAction -> WeHaveContact ()) {
|
||||
|
||||
// Store these in the scene so we can use culling algorithms.
|
||||
fScene.SetWorkingPhysicalVolume
|
||||
(fG4RaySteppingAction -> GetPhysicalVolume ());
|
||||
fScene.SetWorkingLogicalVolume
|
||||
(fG4RaySteppingAction -> GetLogicalVolume ());
|
||||
fScene.SetWorkingSolid (fG4RaySteppingAction -> GetSolid ());
|
||||
const G4VisAttributes* pVA =
|
||||
fG4RaySteppingAction -> GetVisAttributes();
|
||||
pVA = GetApplicableVisAttributes (pVA);
|
||||
fScene.SetWorkingVisAttributes (pVA);
|
||||
|
||||
if (!fScene.IsThisCulled ()) {
|
||||
|
||||
G4Normal3D normal = fG4RaySteppingAction -> GetSurfaceNormal ();
|
||||
|
||||
// Return colour of the object
|
||||
colour = pVA -> GetColour();
|
||||
intrinsicred = colour.GetRed();
|
||||
intrinsicgreen = colour.GetGreen();
|
||||
intrinsicblue = colour.GetBlue();
|
||||
|
||||
//G4cout << "The intrnsic red colour is: " << red << endl;
|
||||
//G4cout << "The intrinsic green colour is: " << green << endl;
|
||||
//G4cout << "The intrinsic blue colour is: " << blue << endl;
|
||||
|
||||
// Calculate Intencity.
|
||||
Dot = normal.unit() * lightDirection.unit();
|
||||
reflightDirection =
|
||||
2.0 * Dot * normal.unit() - lightDirection.unit();
|
||||
reflectionDot = viewvector.unit() * reflightDirection.unit();
|
||||
|
||||
if (Dot < 0) Dot = 0;
|
||||
if (reflectionDot < 0) reflectionDot = 0;
|
||||
I = Ia + Ip * Dot ; //+ Id * pow(reflectionDot,90);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
**********************/
|
||||
|
||||
// G4cout << " Intensity : " << I << endl;
|
||||
|
||||
red = intrinsicred * I ;
|
||||
green = intrinsicgreen * I ;
|
||||
blue = intrinsicblue * I;
|
||||
if (I > 0.) {
|
||||
G4double specular = Id * pow(reflectionDot,10);
|
||||
red += specular;
|
||||
green += specular;
|
||||
blue += specular;
|
||||
}
|
||||
|
||||
/****************************************************************
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// A very testing pallette...
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
if (x < -0.8) {
|
||||
red = (y + 1.) / 2.;
|
||||
green = 0;
|
||||
blue = 0;
|
||||
}
|
||||
else if (x < -0.6) {
|
||||
red = 0;
|
||||
green = (y + 1.) / 2.;
|
||||
blue = 0;
|
||||
}
|
||||
else if (x < -0.4) {
|
||||
red = 0;
|
||||
green = 0;
|
||||
blue = (y + 1.) / 2.;
|
||||
}
|
||||
else if (x < -0.2) {
|
||||
red = 0;
|
||||
green = (y + 1.) / 2.;
|
||||
blue = (y + 1.) / 2.;
|
||||
}
|
||||
else if (x < 0.) {
|
||||
red = (y + 1.) / 2.;
|
||||
green = 0;
|
||||
blue = (y + 1.) / 2.;
|
||||
}
|
||||
else if (x < 0.2) {
|
||||
red = (y + 1.) / 2.;
|
||||
green = (y + 1.) / 2.;
|
||||
blue = 0.;
|
||||
}
|
||||
else if (x < 0.4) {
|
||||
red = (y + 1.) / 2.;
|
||||
green = (y + 1.) / 2.;
|
||||
blue = (y + 1.) / 2.;
|
||||
}
|
||||
else {
|
||||
red = pow (sin (y), 2);
|
||||
green = pow (cos (y), 2);
|
||||
blue = x * x;
|
||||
}
|
||||
|
||||
***********************************/
|
||||
/**********************************
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// A shiny red sphere...
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
const G4double size (0.5);
|
||||
const G4Point3D centre;
|
||||
const G4double ambient (0.2);
|
||||
const G4Vector3D viewpointDirection (0.0, 0.0, 1.0);
|
||||
const G4Vector3D lightpointDirection = G4Vector3D (1.0, 1.0, 1.0).unit ();
|
||||
G4double p = sqrt (pow (x - centre.x (), 2) + pow (y - centre.y (), 2));
|
||||
if (p > 0.5) {
|
||||
red = green = blue = 0.;
|
||||
}
|
||||
else {
|
||||
G4double z = sqrt (pow (size,2) - pow (p, 2));
|
||||
G4Vector3D radiusVector (x, y, z);
|
||||
G4double brightness = radiusVector.unit () * lightpointDirection;
|
||||
if (brightness < 0.0) brightness = 0.0;
|
||||
G4Vector3D reflightDirection =
|
||||
2.0 * brightness * radiusVector.unit () - lightpointDirection;
|
||||
G4double reflectionDot =
|
||||
viewpointDirection.unit() * reflightDirection.unit();
|
||||
if (reflectionDot < 0) reflectionDot = 0;
|
||||
G4double specular = pow (reflectionDot, 10);
|
||||
red = ambient + (1.0 - ambient) * brightness;
|
||||
red += specular;
|
||||
green += specular;
|
||||
blue += specular;
|
||||
}
|
||||
|
||||
**************************/
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Always check...
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
if (red < 0.) red = 0.;
|
||||
if (green < 0.) green = 0.;
|
||||
if (blue < 0.) blue = 0.;
|
||||
if (red > 1.) red = 1.;
|
||||
if (green > 1.) green = 1.;
|
||||
if (blue > 1.) blue = 1.;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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: G4RayX.cc,v 2.2 1998/11/06 13:41:57 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing graphics system factory.
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#include "G4RayX.hh"
|
||||
|
||||
#include "G4VisFeaturesOfRay.hh"
|
||||
#include "G4RayXMessenger.hh"
|
||||
#include "G4RayScene.hh"
|
||||
#include "G4RayXView.hh"
|
||||
|
||||
G4RayX::G4RayX ():
|
||||
G4VGraphicsSystem ("G4RayX",
|
||||
"RayX",
|
||||
G4VisFeaturesOfRayX (),
|
||||
G4VGraphicsSystem::twoD) {
|
||||
if (fInstances >= 1) {
|
||||
G4Exception ("An attempt to instantiate a second G4RayX object.");
|
||||
}
|
||||
fInstances++;
|
||||
// Instantiate my messenger.
|
||||
fpMessenger = new G4RayXMessenger (this);
|
||||
}
|
||||
|
||||
G4RayX::~G4RayX () {
|
||||
delete fpMessenger;
|
||||
fInstances--;
|
||||
}
|
||||
|
||||
G4VScene* G4RayX::CreateScene (const G4String& name) {
|
||||
G4RayScene* pRayScene = new G4RayScene (*this, name);
|
||||
G4VScene* pScene = pRayScene;
|
||||
G4cout << G4RayScene::GetSceneCount ()
|
||||
<< ' ' << fName << " scenes extanct." << endl;
|
||||
fpMessenger -> RegisterScene ((G4RayScene*) pScene);
|
||||
return pScene;
|
||||
}
|
||||
|
||||
G4VView* G4RayX::CreateView (G4VScene& scene, const G4String& name) {
|
||||
G4RayView* pRayXView = new G4RayXView ((G4RayScene&) scene, name);
|
||||
G4VView* pView = pRayXView;
|
||||
if (pView) {
|
||||
if (pView -> GetViewId () < 0) {
|
||||
G4cerr << "Error flagged by negative view id in G4RayXView creation."
|
||||
"\nDestroying view and returning null pointer."
|
||||
<<endl;
|
||||
delete pView;
|
||||
pView = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
G4cerr << "Null pointer on new G4RayXView." << endl;
|
||||
}
|
||||
fpMessenger -> RegisterView (pRayXView);
|
||||
return pView;
|
||||
}
|
||||
|
||||
G4int G4RayX::fInstances = 0;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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: G4RayXMessenger.cc,v 2.4 1998/07/16 01:57:32 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// GEANT4 Ray tracing for X windows Messenger - John Allison 5th June 1997
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#include "G4RayXMessenger.hh"
|
||||
|
||||
#include "G4RayX.hh"
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIparameter.hh"
|
||||
|
||||
G4RayXMessenger::G4RayXMessenger (G4RayX* pRayX):
|
||||
fpRayX (pRayX)
|
||||
{
|
||||
G4UIcommand* command;
|
||||
G4UIparameter* param;
|
||||
|
||||
///////////////////////////////////////////////// /vis~/ray/X... ////
|
||||
//vis \hline
|
||||
//vis /vis~/ray/X... &&
|
||||
//vis ...any X-special commands for ray tracing... \\%
|
||||
//command = new G4UIcommand ("/vis~/ray/X...", this);
|
||||
//command -> SetGuidance ("...any X-special commands for ray tracing...");
|
||||
}
|
||||
|
||||
G4RayXMessenger::~G4RayXMessenger () {}
|
||||
|
||||
void G4RayXMessenger::SetNewValue (G4UIcommand* command, G4String newValues)
|
||||
{
|
||||
G4RayMessenger::SetNewValue (command, newValues);
|
||||
}
|
||||
|
||||
G4String G4RayXMessenger::GetCurrentValue (G4UIcommand* command) {
|
||||
return "";
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,196 @@
|
||||
// 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: G4RayXView.cc,v 2.2 1998/11/06 13:41:58 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Nikos Savvas 1st June 1997
|
||||
// GEANT4 Ray Tracing view.
|
||||
|
||||
#ifdef G4VIS_BUILD_RAYX_DRIVER
|
||||
|
||||
#include "G4RayXView.hh"
|
||||
|
||||
#include "G4RayScene.hh"
|
||||
|
||||
G4RayXView::G4RayXView (G4RayScene& scene, const G4String& name):
|
||||
G4RayView (scene),
|
||||
G4OwnColormapXView (scene),
|
||||
G4VView (scene, scene.IncrementViewCount (), name) {
|
||||
|
||||
if (fViewId < 0) return; // Traps possible error in base class creation.
|
||||
|
||||
if (fTrueColor) {
|
||||
fMaxImageMapEntries = 256; // make a 256 colour map anyway.
|
||||
}
|
||||
|
||||
if (fMapEntries != 256 ) {
|
||||
G4cerr << "G4RayXView::G4RayXView: no of colormap entries is " << ncells
|
||||
<< "\nWe cannot deal with this case for ray tracing yet."
|
||||
<< endl;
|
||||
fViewId = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
/************************************
|
||||
// Fill 3x3x2 colormap.
|
||||
// (In future, I'll write something to evolve the colormap on the fly.
|
||||
if (fMapEntries != 256 ) {
|
||||
G4cerr << "G4RayXView::G4RayXView: no of colormap entries is " << ncells
|
||||
<< "\nWe cannot deal with this case for ray tracing yet."
|
||||
<< endl;
|
||||
fViewId = -1;
|
||||
return;
|
||||
}
|
||||
XColor* cells = new XColor [fMapEntries];
|
||||
red_max = 7;
|
||||
green_max = 7;
|
||||
blue_max = 4;
|
||||
int red_max_1 = red_max + 1;
|
||||
int green_max_1 = green_max + 1;
|
||||
int blue_max_1 = blue_max + 1;
|
||||
float red_scale = 65535 * (float (red_max_1) / red_max);
|
||||
float green_scale = 65535 * (float (green_max_1) / green_max);
|
||||
float blue_scale = 65535 * (float (blue_max_1) / blue_max);
|
||||
red_mult = 32;
|
||||
green_mult = 4;
|
||||
blue_mult = 1;
|
||||
for (int iPixel = 0; iPixel < ncells; iPixel++) {
|
||||
cells [iPixel].pixel = iPixel;
|
||||
cells [iPixel].red = (short unsigned int)
|
||||
(red_scale * ((iPixel / red_mult) % red_max_1));
|
||||
cells [iPixel].green = (short unsigned int)
|
||||
(green_scale * ((iPixel / green_mult) % green_max_1));
|
||||
cells [iPixel].blue = (short unsigned int)
|
||||
(blue_scale * ((iPixel / blue_mult) % blue_max_1));
|
||||
cells [iPixel].flags = DoRed | DoGreen | DoBlue;
|
||||
}
|
||||
XStoreColors (fpDisplay, fColormap, cells, ncells);
|
||||
************************************/
|
||||
}
|
||||
|
||||
void G4RayXView::DrawView () {
|
||||
|
||||
// If view parameters have changed, start again from scratch.
|
||||
// But if not, be smart, and start from private map, depending on
|
||||
// the value of resolution.
|
||||
|
||||
SetView ();
|
||||
|
||||
// Decide whether to initialise image...
|
||||
if (fImageViewParameters != fVP ||
|
||||
fMaxImageMapEntries != fMapEntries ||
|
||||
fImageWidth != fWidth ||
|
||||
fImageHeight != fHeight) { // Clear and reset image stores.
|
||||
G4cout
|
||||
<< "G4RayXView::DrawView: image re-initialised because...\n ";
|
||||
if (fImageViewParameters != fVP)
|
||||
G4cout << "view parameters, ";
|
||||
if (fMaxImageMapEntries != fMapEntries)
|
||||
G4cout << "no. of entries in colormap, ";
|
||||
if (fImageWidth != fWidth)
|
||||
G4cout << "width, ";
|
||||
if (fImageHeight != fHeight)
|
||||
G4cout << " height, ";
|
||||
G4cout << "changed." << endl;
|
||||
// Reset above parameters...
|
||||
fImageViewParameters = fVP;
|
||||
fMaxImageMapEntries = fMapEntries;
|
||||
fImageWidth = fWidth;
|
||||
fImageHeight = fHeight;
|
||||
// Now things that need initialising...
|
||||
InitialiseImage ();
|
||||
}
|
||||
// Now things that need resetting for every Draw.
|
||||
TriggerRedraw ();
|
||||
|
||||
XGCValues xgcValues;
|
||||
XColor cell;
|
||||
XColor* cells = new XColor [fMapEntries];
|
||||
|
||||
int i, j, k, iPixVal;
|
||||
float red, green, blue;
|
||||
// Square of side k whose upper left corner is (i, j). The above
|
||||
// are set by the function Scan, inherited from G4RayView. You
|
||||
// don't have to use it - you can call Trace, also inherited from
|
||||
// G4RayView, directly. iPixVal is the pixel value for this colour,
|
||||
// i.e., the key in fRayHitColourIndex.
|
||||
while (Scan (i, j, k, red, green, blue, iPixVal)) {
|
||||
|
||||
if(fTrueColor) {
|
||||
unsigned long int trueColorPixval =
|
||||
((unsigned long int) (red * fRedMax)) << fRedShift |
|
||||
((unsigned long int) (green * fGreenMax)) << fGreenShift |
|
||||
((unsigned long int) (blue * fBlueMax)) << fBlueShift;
|
||||
xgcValues.foreground = trueColorPixval;
|
||||
XChangeGC (fpDisplay, fGC, GCForeground, &xgcValues);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
G4int nCells = fRayHitColourMap.entries ();
|
||||
if (nCells > fMapEntries) {
|
||||
G4Exception ("G4RayXView::DrawView: fRayHitColourMap overflow!!!");
|
||||
}
|
||||
|
||||
if (fImageMapRejigged && ++fWaitCount > fWaitLimit) {
|
||||
// Note: ++fWaitCount only executed if fImageMapRejigged is true.
|
||||
fWaitCount = 0;
|
||||
fImageMapRejigged = false;
|
||||
fTriggerRescan = true;
|
||||
//G4cout << "G4RayXView::DrawView: remaking whole colormap." << endl;
|
||||
for (int iCells = 0; iCells < nCells; iCells++) {
|
||||
cells [iCells].pixel = iCells;
|
||||
cells [iCells].red = (short unsigned int)
|
||||
(65535 * fRayHitColourMap (iCells).red);
|
||||
cells [iCells].green = (short unsigned int)
|
||||
(65535 * fRayHitColourMap (iCells).green);
|
||||
cells [iCells].blue = (short unsigned int)
|
||||
(65535 * fRayHitColourMap (iCells).blue);
|
||||
cells [iCells].flags = DoRed | DoGreen | DoBlue;
|
||||
}
|
||||
XStoreColors (fpDisplay, fColormap, cells, nCells);
|
||||
}
|
||||
else {
|
||||
if (iPixVal == nCells - 1) {
|
||||
// Just do the last one, the latest addition.
|
||||
cell.pixel = iPixVal;
|
||||
cell.red = (short unsigned int)
|
||||
(65535 * fRayHitColourMap (iPixVal).red);
|
||||
cell.green = (short unsigned int)
|
||||
(65535 * fRayHitColourMap (iPixVal).green);
|
||||
cell.blue = (short unsigned int)
|
||||
(65535 * fRayHitColourMap (iPixVal).blue);
|
||||
cell.flags = DoRed | DoGreen | DoBlue;
|
||||
XStoreColor (fpDisplay, fColormap, &cell);
|
||||
}
|
||||
// (Otherwise assume an old pixel value is being used,
|
||||
// i.e., do nothing.)
|
||||
}
|
||||
|
||||
XSetForeground (fpDisplay, fGC, iPixVal);
|
||||
}
|
||||
|
||||
if (k <= 1) {
|
||||
XDrawPoint (fpDisplay, fWindow, fGC, i, j);
|
||||
}
|
||||
else {
|
||||
XFillRectangle (fpDisplay, fWindow, fGC, i, j, k, k);
|
||||
}
|
||||
|
||||
XFlush (fpDisplay);
|
||||
|
||||
//for (int ii = 0; ii < 1000000; ii++); //?? 1000000 = about 0.5 secs!!
|
||||
}
|
||||
|
||||
delete cells;
|
||||
|
||||
FinishView ();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user