Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RTXScanner Class Reference

#include <G4RTXScanner.hh>

+ Inheritance diagram for G4RTXScanner:

Public Member Functions

 G4RTXScanner ()
 
virtual ~G4RTXScanner ()
 
virtual const G4StringGetGSName () const
 
virtual const G4StringGetGSNickname () const
 
virtual void Initialize (G4int nRow, G4int nColumn)
 
virtual G4bool Coords (G4int &iRow, G4int &iColumn)
 
virtual void Draw (unsigned char red, unsigned char green, unsigned char blue)
 
G4bool GetXWindow (const G4String &name, G4ViewParameters &)
 
- Public Member Functions inherited from G4VRTScanner
 G4VRTScanner ()
 
virtual ~G4VRTScanner ()
 
virtual const G4StringGetGSName () const =0
 
virtual const G4StringGetGSNickname () const =0
 
virtual void Initialize (G4int nRow, G4int nColumn)=0
 
virtual G4bool Coords (G4int &iRow, G4int &iColumn)=0
 
virtual void Draw (unsigned char red, unsigned char green, unsigned char blue)
 

Protected Attributes

G4String theGSName
 
G4String theGSNickname
 
G4int theNRow
 
G4int theNColumn
 
G4int theStep
 
G4int theIRow
 
G4int theIColumn
 
Display * display
 
Window win
 
GC gc
 
XStandardColormap * scmap
 

Detailed Description

Definition at line 46 of file G4RTXScanner.hh.

Constructor & Destructor Documentation

◆ G4RTXScanner()

G4RTXScanner::G4RTXScanner ( )

Definition at line 47 of file G4RTXScanner.cc.

47 :
49 ,theIRow(0), theIColumn(0)
50 ,display(0), win(0), scmap(0)
51{
52 theGSName = "RayTracerX";
53 theGSNickname = "RayTracerX";
54}
XStandardColormap * scmap
Definition: G4RTXScanner.hh:84
G4String theGSNickname
Definition: G4RTXScanner.hh:78
G4int theIColumn
Definition: G4RTXScanner.hh:79
G4String theGSName
Definition: G4RTXScanner.hh:78
G4int theNColumn
Definition: G4RTXScanner.hh:79
Display * display
Definition: G4RTXScanner.hh:81

◆ ~G4RTXScanner()

G4RTXScanner::~G4RTXScanner ( )
virtual

Definition at line 56 of file G4RTXScanner.cc.

56{}

Member Function Documentation

◆ Coords()

G4bool G4RTXScanner::Coords ( G4int iRow,
G4int iColumn 
)
virtual

Implements G4VRTScanner.

Definition at line 79 of file G4RTXScanner.cc.

80{
81 // Increment column...
83
84 // Skip coordinates covered in the previous scan...
85 if ((theIColumn + (3 * theStep) / 2 + 1)%(3 * theStep) == 0 &&
86 (theIRow + (3 * theStep) / 2 + 1)%(3 * theStep) == 0)
88
89 // If necessary, increment row...
90 if (theIColumn >= theNColumn) {
91 theIColumn = theStep / 2;
93 }
94
95 // Return if finished...
96 if (theIRow >= theNRow && theStep <= 1) return false;
97
98 // Start next scan if necessary...
99 if (theIRow >= theNRow) {
100 theStep /= 3;
101 theIRow = theStep / 2;
102 theIColumn = theStep / 2;
103 }
104
105 // Return current row and column...
106 iRow = theIRow;
107 iColumn = theIColumn;
108 return true;
109}

◆ Draw()

void G4RTXScanner::Draw ( unsigned char  red,
unsigned char  green,
unsigned char  blue 
)
virtual

Reimplemented from G4VRTScanner.

Definition at line 218 of file G4RTXScanner.cc.

221{
222 unsigned long pixel_value = scmap->base_pixel +
223 ((unsigned long) ((red * scmap->red_max) / 256.) * scmap->red_mult) +
224 ((unsigned long) ((green * scmap->green_max) / 256.) * scmap->green_mult) +
225 ((unsigned long) ((blue * scmap->blue_max) / 256.) * scmap->blue_mult);
226 XSetForeground(display, gc, pixel_value);
227
228 if (theStep > 1) {
229 XFillRectangle(display, win, gc,
230 theIColumn - theStep / 2,
231 theIRow - theStep / 2,
233 } else {
234 XDrawPoint(display, win, gc, theIColumn, theIRow);
235 }
236
237 XFlush(display);
238}

◆ GetGSName()

const G4String & G4RTXScanner::GetGSName ( ) const
virtual

Implements G4VRTScanner.

Definition at line 58 of file G4RTXScanner.cc.

59{return theGSName;}

◆ GetGSNickname()

const G4String & G4RTXScanner::GetGSNickname ( ) const
virtual

Implements G4VRTScanner.

Definition at line 61 of file G4RTXScanner.cc.

62{return theGSNickname;}

◆ GetXWindow()

G4bool G4RTXScanner::GetXWindow ( const G4String name,
G4ViewParameters vp 
)

Definition at line 111 of file G4RTXScanner.cc.

112{
113 display = XOpenDisplay(0); // Use display defined by DISPLAY environment.
114 if (!display) {
115 G4warn << "G4RTXScanner::Initialize(): cannot get display."
116 << G4endl;
117 return false;
118 }
119
120 int screen_num = DefaultScreen(display);
121
122 // Window size and position...
123 int xOffset = 0, yOffset = 0;
124 XSizeHints* size_hints = XAllocSizeHints();
125 unsigned int width, height;
126 const G4String& XGeometryString = vp.GetXGeometryString();
127 if (!XGeometryString.empty()) {
128 G4int geometryResultMask = XParseGeometry
129 ((char*)XGeometryString.c_str(),
130 &xOffset, &yOffset, &width, &height);
131 if (geometryResultMask & (WidthValue | HeightValue)) {
132 if (geometryResultMask & XValue) {
133 if (geometryResultMask & XNegative) {
134 xOffset = DisplayWidth(display, screen_num) + xOffset - width;
135 }
136 size_hints->flags |= PPosition;
137 size_hints->x = xOffset;
138 }
139 if (geometryResultMask & YValue) {
140 if (geometryResultMask & YNegative) {
141 yOffset = DisplayHeight(display, screen_num) + yOffset - height;
142 }
143 size_hints->flags |= PPosition;
144 size_hints->y = yOffset;
145 }
146 } else {
147 G4warn << "ERROR: Geometry string \""
148 << XGeometryString
149 << "\" invalid. Using \"600x600\"."
150 << G4endl;
151 width = 600;
152 height = 600;
153 }
154 } else {
155 G4warn << "ERROR: Geometry string \""
156 << XGeometryString
157 << "\" is empty. Using \"600x600\"."
158 << G4endl;
159 width = 600;
160 height = 600;
161 }
162 size_hints->width = width;
163 size_hints->height = height;
164 size_hints->flags |= PSize;
165
166 win = XCreateSimpleWindow
167 (display, RootWindow(display, screen_num),
168 xOffset, yOffset, width, height,
169 0, // Border width.
170 WhitePixel(display, screen_num), // Border colour.
171 BlackPixel(display, screen_num)); // Background colour.
172
173 XGCValues values;
174 gc = XCreateGC(display, win, 0, &values);
175
176 int nMaps;
177 Status status = XGetRGBColormaps
178 (display, RootWindow(display, screen_num),
179 &scmap, &nMaps, XA_RGB_BEST_MAP);
180 if (!status) {
181 system("xstdcmap -best"); // ...and try again...
182 status = XGetRGBColormaps
183 (display, RootWindow(display, screen_num),
184 &scmap, &nMaps, XA_RGB_BEST_MAP);
185 if (!status) {
186 G4warn <<
187 "G4RTXScanner::Initialize(): cannot get color map."
188 "\n Perhaps your system does not support XA_RGB_BEST_MAP."
189 << G4endl;
190 return false;
191 }
192 }
193 if (!scmap->colormap) {
194 G4warn << "G4RTXScanner::Initialize(): color map empty."
195 << G4endl;
196 return false;
197 }
198
199 XWMHints* wm_hints = XAllocWMHints();
200 XClassHint* class_hint = XAllocClassHint();
201 const char* window_name = name.c_str();
202 XTextProperty windowName;
203 XStringListToTextProperty((char**)&window_name, 1, &windowName);
204
205 XSetWMProperties(display, win, &windowName, &windowName,
206 0, 0, size_hints, wm_hints, class_hint);
207
208 XMapWindow(display, win);
209
210 // Wait for window to appear (wait for an "map notify" event).
211 XSelectInput(display, win, StructureNotifyMask);
212 XEvent event;
213 XIfEvent (display, &event, G4RayTracerXScannerWaitForNotify, (char*) win);
214
215 return true;
216}
Bool G4RayTracerXScannerWaitForNotify(Display *, XEvent *e, char *arg)
Definition: G4RTXScanner.cc:42
#define G4warn
Definition: G4Scene.cc:41
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
const G4String & GetXGeometryString() const
const char * name(G4int ptype)

Referenced by G4RayTracerXViewer::Initialise().

◆ Initialize()

void G4RTXScanner::Initialize ( G4int  nRow,
G4int  nColumn 
)
virtual

Implements G4VRTScanner.

Definition at line 64 of file G4RTXScanner.cc.

64 {
65 theNRow = nRow;
66 theNColumn = nColumn;
67 G4int nMax = std::max (nRow, nColumn);
68 theStep = 1;
69 if (nMax > 3) {
70 for (;;) {
71 theStep *= 3;
72 if (theStep > nMax) break;
73 }
74 }
75 theIRow = theStep / 2;
77}

Member Data Documentation

◆ display

Display* G4RTXScanner::display
protected

Definition at line 81 of file G4RTXScanner.hh.

Referenced by Draw(), and GetXWindow().

◆ gc

GC G4RTXScanner::gc
protected

Definition at line 83 of file G4RTXScanner.hh.

Referenced by Draw(), and GetXWindow().

◆ scmap

XStandardColormap* G4RTXScanner::scmap
protected

Definition at line 84 of file G4RTXScanner.hh.

Referenced by Draw(), and GetXWindow().

◆ theGSName

G4String G4RTXScanner::theGSName
protected

Definition at line 78 of file G4RTXScanner.hh.

Referenced by G4RTXScanner(), and GetGSName().

◆ theGSNickname

G4String G4RTXScanner::theGSNickname
protected

Definition at line 78 of file G4RTXScanner.hh.

Referenced by G4RTXScanner(), and GetGSNickname().

◆ theIColumn

G4int G4RTXScanner::theIColumn
protected

Definition at line 79 of file G4RTXScanner.hh.

Referenced by Coords(), Draw(), and Initialize().

◆ theIRow

G4int G4RTXScanner::theIRow
protected

Definition at line 79 of file G4RTXScanner.hh.

Referenced by Coords(), Draw(), and Initialize().

◆ theNColumn

G4int G4RTXScanner::theNColumn
protected

Definition at line 79 of file G4RTXScanner.hh.

Referenced by Coords(), and Initialize().

◆ theNRow

G4int G4RTXScanner::theNRow
protected

Definition at line 79 of file G4RTXScanner.hh.

Referenced by Coords(), and Initialize().

◆ theStep

G4int G4RTXScanner::theStep
protected

Definition at line 79 of file G4RTXScanner.hh.

Referenced by Coords(), Draw(), and Initialize().

◆ win

Window G4RTXScanner::win
protected

Definition at line 82 of file G4RTXScanner.hh.

Referenced by Draw(), and GetXWindow().


The documentation for this class was generated from the following files: