Geant4-11
Public Member Functions | Protected Attributes
G4RTXScanner Class Reference

#include <G4RTXScanner.hh>

Inheritance diagram for G4RTXScanner:
G4VRTScanner

Public Member Functions

virtual G4bool Coords (G4int &iRow, G4int &iColumn)
 
virtual void Draw (unsigned char red, unsigned char green, unsigned char blue)
 
 G4RTXScanner ()
 
virtual const G4StringGetGSName () const
 
virtual const G4StringGetGSNickname () const
 
G4bool GetXWindow (const G4String &name, G4ViewParameters &)
 
virtual void Initialize (G4int nRow, G4int nColumn)
 
virtual ~G4RTXScanner ()
 

Protected Attributes

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

Detailed Description

Definition at line 46 of file G4RTXScanner.hh.

Constructor & Destructor Documentation

◆ G4RTXScanner()

G4RTXScanner::G4RTXScanner ( )

Definition at line 45 of file G4RTXScanner.cc.

45 :
47 ,theIRow(0), theIColumn(0)
48 ,display(0), win(0), scmap(0)
49{
50 theGSName = "RayTracerX";
51 theGSNickname = "RayTracerX";
52}
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

References theGSName, and theGSNickname.

◆ ~G4RTXScanner()

G4RTXScanner::~G4RTXScanner ( )
virtual

Definition at line 54 of file G4RTXScanner.cc.

54{}

Member Function Documentation

◆ Coords()

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

Implements G4VRTScanner.

Definition at line 77 of file G4RTXScanner.cc.

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

References theIColumn, theIRow, theNColumn, theNRow, and theStep.

◆ Draw()

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

Reimplemented from G4VRTScanner.

Definition at line 216 of file G4RTXScanner.cc.

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

References display, gc, scmap, theIColumn, theIRow, theStep, and win.

◆ GetGSName()

const G4String & G4RTXScanner::GetGSName ( ) const
virtual

Implements G4VRTScanner.

Definition at line 56 of file G4RTXScanner.cc.

57{return theGSName;}

References theGSName.

◆ GetGSNickname()

const G4String & G4RTXScanner::GetGSNickname ( ) const
virtual

Implements G4VRTScanner.

Definition at line 59 of file G4RTXScanner.cc.

60{return theGSNickname;}

References theGSNickname.

◆ GetXWindow()

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

Definition at line 109 of file G4RTXScanner.cc.

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

References display, G4cerr, G4cout, G4endl, G4RayTracerXScannerWaitForNotify(), gc, G4ViewParameters::GetXGeometryString(), G4InuclParticleNames::name(), scmap, Status(), and win.

Referenced by G4RayTracerXViewer::Initialise().

◆ Initialize()

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

Implements G4VRTScanner.

Definition at line 62 of file G4RTXScanner.cc.

62 {
63 theNRow = nRow;
64 theNColumn = nColumn;
65 G4int nMax = std::max (nRow, nColumn);
66 theStep = 1;
67 if (nMax > 3) {
68 for (;;) {
69 theStep *= 3;
70 if (theStep > nMax) break;
71 }
72 }
73 theIRow = theStep / 2;
75}
T max(const T t1, const T t2)
brief Return the largest of the two arguments

References G4INCL::Math::max(), theIColumn, theIRow, theNColumn, theNRow, and theStep.

Field 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: