Geant4 11.4.0
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 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 ()

Protected Attributes

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{}
XStandardColormap * scmap
Display * display

◆ ~G4RTXScanner()

G4RTXScanner::~G4RTXScanner ( )
virtual

Definition at line 53 of file G4RTXScanner.cc.

53{}

Member Function Documentation

◆ Coords()

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

Implements G4VRTScanner.

Definition at line 70 of file G4RTXScanner.cc.

71{
72 // Increment column...
74
75 // Skip coordinates covered in the previous scan...
76 if ((theIColumn + (3 * theStep) / 2 + 1)%(3 * theStep) == 0 &&
77 (theIRow + (3 * theStep) / 2 + 1)%(3 * theStep) == 0)
79
80 // If necessary, increment row...
81 if (theIColumn >= theNColumn) {
82 theIColumn = theStep / 2;
84 }
85
86 // Return if finished...
87 if (theIRow >= theNRow && theStep <= 1) return false;
88
89 // Start next scan if necessary...
90 if (theIRow >= theNRow) {
91 theStep /= 3;
92 theIRow = theStep / 2;
93 theIColumn = theStep / 2;
94 }
95
96 // Return current row and column...
97 iRow = theIRow;
98 iColumn = theIColumn;
99 return true;
100}

◆ Draw()

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

Reimplemented from G4VRTScanner.

Definition at line 209 of file G4RTXScanner.cc.

212{
213 unsigned long pixel_value = scmap->base_pixel +
214 ((unsigned long) ((red * scmap->red_max) / 256.) * scmap->red_mult) +
215 ((unsigned long) ((green * scmap->green_max) / 256.) * scmap->green_mult) +
216 ((unsigned long) ((blue * scmap->blue_max) / 256.) * scmap->blue_mult);
217 XSetForeground(display, gc, pixel_value);
218
219 if (theStep > 1) {
220 XFillRectangle(display, win, gc,
221 theIColumn - theStep / 2,
222 theIRow - theStep / 2,
224 } else {
225 XDrawPoint(display, win, gc, theIColumn, theIRow);
226 }
227
228 XFlush(display);
229}

◆ GetXWindow()

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

Definition at line 102 of file G4RTXScanner.cc.

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

55 {
56 theNRow = nRow;
57 theNColumn = nColumn;
58 G4int nMax = std::max (nRow, nColumn);
59 theStep = 1;
60 if (nMax > 3) {
61 for (;;) {
62 theStep *= 3;
63 if (theStep > nMax) break;
64 }
65 }
66 theIRow = theStep / 2;
68}

Member Data Documentation

◆ display

Display* G4RTXScanner::display
protected

Definition at line 72 of file G4RTXScanner.hh.

Referenced by Draw(), G4RTXScanner(), and GetXWindow().

◆ gc

GC G4RTXScanner::gc
protected

Definition at line 74 of file G4RTXScanner.hh.

Referenced by Draw(), and GetXWindow().

◆ scmap

XStandardColormap* G4RTXScanner::scmap
protected

Definition at line 75 of file G4RTXScanner.hh.

Referenced by Draw(), G4RTXScanner(), and GetXWindow().

◆ theIColumn

G4int G4RTXScanner::theIColumn
protected

Definition at line 70 of file G4RTXScanner.hh.

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

◆ theIRow

G4int G4RTXScanner::theIRow
protected

Definition at line 70 of file G4RTXScanner.hh.

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

◆ theNColumn

G4int G4RTXScanner::theNColumn
protected

Definition at line 70 of file G4RTXScanner.hh.

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

◆ theNRow

G4int G4RTXScanner::theNRow
protected

Definition at line 70 of file G4RTXScanner.hh.

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

◆ theStep

G4int G4RTXScanner::theStep
protected

Definition at line 70 of file G4RTXScanner.hh.

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

◆ win

Window G4RTXScanner::win
protected

Definition at line 73 of file G4RTXScanner.hh.

Referenced by Draw(), G4RTXScanner(), and GetXWindow().


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