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

#include <G4DAWNFILEViewer.hh>

+ Inheritance diagram for G4DAWNFILEViewer:

Public Member Functions

 G4DAWNFILEViewer (G4DAWNFILESceneHandler &scene, const G4String &name="")
 
virtual ~G4DAWNFILEViewer ()
 
void SetView ()
 
void ClearView ()
 
void DrawView ()
 
void ShowView ()
 
void SendViewParameters ()
 
const char * GetG4PrimViewer ()
 
const char * GetG4PrimViewerInvocation ()
 
const char * GetPSViewer ()
 
void SendDrawingStyleToDAWNGUI (std::ostream &out)
 
- Public Member Functions inherited from G4VViewer
 G4VViewer (G4VSceneHandler &, G4int id, const G4String &name="")
 
virtual ~G4VViewer ()
 
virtual void Initialise ()
 
virtual void ResetView ()
 
virtual void SetView ()=0
 
virtual void ClearView ()=0
 
virtual void DrawView ()=0
 
void RefreshView ()
 
virtual void ShowView ()
 
virtual void FinishView ()
 
std::vector< G4ThreeVectorComputeFlyThrough (G4Vector3D *)
 
const G4StringGetName () const
 
const G4StringGetShortName () const
 
void SetName (const G4String &)
 
G4int GetViewId () const
 
G4VSceneHandlerGetSceneHandler () const
 
const G4ViewParametersGetViewParameters () const
 
const G4ViewParametersGetDefaultViewParameters () const
 
G4double GetKernelVisitElapsedTimeSeconds () const
 
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers () const
 
void SetViewParameters (const G4ViewParameters &vp)
 
void SetDefaultViewParameters (const G4ViewParameters &vp)
 
const G4VisAttributesGetApplicableVisAttributes (const G4VisAttributes *) const
 
void SetNeedKernelVisit (G4bool need)
 
void NeedKernelVisit ()
 
void ProcessView ()
 

Additional Inherited Members

- Protected Member Functions inherited from G4VViewer
void SetTouchable (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
 
void TouchableSetVisibility (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
 
void TouchableSetColour (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
 
- Protected Attributes inherited from G4VViewer
G4VSceneHandlerfSceneHandler
 
G4int fViewId
 
G4String fName
 
G4String fShortName
 
G4ViewParameters fVP
 
G4ViewParameters fDefaultVP
 
G4double fKernelVisitElapsedTimeSeconds = 999.
 
G4bool fNeedKernelVisit
 

Detailed Description

Definition at line 39 of file G4DAWNFILEViewer.hh.

Constructor & Destructor Documentation

◆ G4DAWNFILEViewer()

G4DAWNFILEViewer::G4DAWNFILEViewer ( G4DAWNFILESceneHandler scene,
const G4String name = "" 
)

Definition at line 59 of file G4DAWNFILEViewer.cc.

61 : G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
62 , fSceneHandler(sceneHandler)
63{
64 // Set a g4.prim-file viewer
65 strcpy(fG4PrimViewer, "dawn");
66 if(std::getenv("G4DAWNFILE_VIEWER") != NULL)
67 {
68 strcpy(fG4PrimViewer, std::getenv("G4DAWNFILE_VIEWER"));
69 }
70
71 // string for viewer invocation
72 if(!strcmp(fG4PrimViewer, "NONE"))
73 {
74 strcpy(fG4PrimViewerInvocation, "");
75 }
76 else
77 {
78 strcpy(fG4PrimViewerInvocation, fG4PrimViewer);
79 strcat(fG4PrimViewerInvocation, " ");
80 strcat(fG4PrimViewerInvocation, fSceneHandler.GetG4PrimFileName());
81 }
82
83 // Set a PostScript Viewer
84 // strcpy( fPSViewer, "ghostview" );
85 strcpy(fPSViewer, "gv");
86 if(std::getenv("G4DAWNFILE_PS_VIEWER") != NULL)
87 {
88 strcpy(fPSViewer, std::getenv("G4DAWNFILE_PS_VIEWER"));
89 }
90}

◆ ~G4DAWNFILEViewer()

G4DAWNFILEViewer::~G4DAWNFILEViewer ( )
virtual

Definition at line 93 of file G4DAWNFILEViewer.cc.

93{}

Member Function Documentation

◆ ClearView()

void G4DAWNFILEViewer::ClearView ( void  )
virtual

Implements G4VViewer.

Definition at line 107 of file G4DAWNFILEViewer.cc.

108{
109#if defined DEBUG_FR_VIEW
111 G4cout << "***** G4DAWNFILEViewer::ClearView (): No effects " << G4endl;
112#endif
113 if(fSceneHandler.fPrimDest.IsOpen())
114 {
115 fSceneHandler.fPrimDest.Close();
116 // Re-open with same filename...
117 fSceneHandler.fPrimDest.Open(fSceneHandler.fG4PrimFileName);
118 fSceneHandler.SendStr(FR_G4_PRIM_HEADER);
119 fSceneHandler.FRflag_in_modeling = false;
120 fSceneHandler.FRBeginModeling();
121 }
122}
const char FR_G4_PRIM_HEADER[]
Definition: G4FRConst.hh:37
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void SendStr(const char *char_string)
void Open(const char *filename)
Definition: G4FRofstream.hh:68
G4bool IsOpen()
Definition: G4FRofstream.hh:55
static Verbosity GetVerbosity()

◆ DrawView()

void G4DAWNFILEViewer::DrawView ( )
virtual

Implements G4VViewer.

Definition at line 125 of file G4DAWNFILEViewer.cc.

126{
127#if defined DEBUG_FR_VIEW
129 G4cout << "***** G4DAWNFILEViewer::DrawView () " << G4endl;
130#endif
131 //-----
132 fSceneHandler.FRBeginModeling();
133
134 //----- Always visit G4 kernel
136
137 //----- Draw
138 ProcessView();
139
140} // G4DAWNFILEViewer::DrawView ()
void ProcessView()
Definition: G4VViewer.cc:107
void NeedKernelVisit()
Definition: G4VViewer.cc:80

◆ GetG4PrimViewer()

const char * G4DAWNFILEViewer::GetG4PrimViewer ( )
inline

Definition at line 64 of file G4DAWNFILEViewer.hh.

64{ return fG4PrimViewer; }

◆ GetG4PrimViewerInvocation()

const char * G4DAWNFILEViewer::GetG4PrimViewerInvocation ( )
inline

Definition at line 65 of file G4DAWNFILEViewer.hh.

65{ return fG4PrimViewerInvocation; }

Referenced by ShowView().

◆ GetPSViewer()

const char * G4DAWNFILEViewer::GetPSViewer ( )
inline

Definition at line 66 of file G4DAWNFILEViewer.hh.

66{ return fPSViewer; }

Referenced by SendViewParameters().

◆ SendDrawingStyleToDAWNGUI()

void G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI ( std::ostream &  out)

Definition at line 205 of file G4DAWNFILEViewer.cc.

206{
207 ///////////////////////
208 //#if defined DEBUG_FR_VIEW
209 // G4cout << "***** G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI()" << G4endl;
210 //#endif
211 //////////////////////
212
213 G4int style = fVP.GetDrawingStyle();
214
215 enum
216 {
217 FR_WIREFRAME_STYLE = 1,
218 FR_WF_STORED_STYLE = 2,
219 FR_HID_STYLE = 3,
220 FR_HID2_STYLE = 4,
221 FR_HID3_STYLE = 5,
222 FR_DRAWING_MODE_END_STYLE = 6
223 };
224
225 switch(style)
226 {
228 out << FR_WIREFRAME_STYLE << G4endl;
229 break;
231 out << FR_HID2_STYLE << G4endl; // LINE
232 break;
235 out << FR_HID_STYLE << G4endl; // SURFACE
236 break;
237 default:
238 out << FR_WIREFRAME_STYLE << G4endl;
239 break;
240 }
241
242} // G4DAWNFILEViewer::SendDrawingStyle()
int G4int
Definition: G4Types.hh:85
G4ViewParameters fVP
Definition: G4VViewer.hh:220
DrawingStyle GetDrawingStyle() const

Referenced by SendViewParameters().

◆ SendViewParameters()

void G4DAWNFILEViewer::SendViewParameters ( )

Definition at line 245 of file G4DAWNFILEViewer.cc.

246{
247 // Calculates view representation based on extent of object being
248 // viewed and (initial) direction of camera. (Note: it can change
249 // later due to user interaction via visualization system's GUI.)
250
251#if defined DEBUG_FR_VIEW
253 {
254 G4cout << "***** G4DAWNFILEViewer::SendViewParameters() ";
255 G4cout << "(GUI parameters)" << G4endl;
256 }
257#endif
258
259 //----- Magic number to decide camera distance automatically
260 const G4double HOW_FAR = 1000.0; // to define "infinity"
261 const G4double MIN_HALF_ANGLE = 0.01;
262 const G4double MAX_HALF_ANGLE = 0.499 * pi;
263
264 //----- CALC camera distance
265 //..... Note: Camera cannot enter inside object
266 G4double camera_distance;
267 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
268
269 G4double half_view_angle = std::fabs(fVP.GetFieldHalfAngle());
270 if(half_view_angle > MAX_HALF_ANGLE)
271 {
272 half_view_angle = MAX_HALF_ANGLE;
273 }
274
275 if(half_view_angle < MIN_HALF_ANGLE)
276 {
277 //----- infinity (or ortho projection)
278 camera_distance = radius * HOW_FAR;
279 }
280 else
281 {
282 //----- Calc camera distance from half view angle
283 camera_distance = radius / std::sin(half_view_angle);
284 camera_distance -= fVP.GetDolly();
285 }
286
287 if(camera_distance < radius)
288 {
290 {
291 G4cout << "WARNING from DAWNFILE driver:" << G4endl;
292 G4cout << " Camera cannot enter inside objects" << G4endl;
293 }
294 camera_distance = radius;
295 }
296
297 //----- CALC camera direction
298 const G4Vector3D& camera_direction = fVP.GetViewpointDirection().unit();
299 const G4double v_angle = (180.0 / pi) * camera_direction.theta();
300 const G4double h_angle = (180.0 / pi) * camera_direction.phi();
301
302 //########### Generation of the file .DAWN.history for DAWN GUI
303 //-----
304 std::ofstream gui_out(".DAWN_1.history");
305
306 // ######### P1
307
308 //----- camera position
309 gui_out << camera_distance << G4endl;
310 gui_out << v_angle << G4endl;
311 gui_out << h_angle << G4endl;
312 gui_out << "0" << G4endl; // auto target
313
314 //----- target point
315 const G4Point3D& target_point =
316 fSceneHandler.GetScene()->GetStandardTargetPoint() +
318 gui_out << target_point.x() << G4endl;
319 gui_out << target_point.y() << G4endl;
320 gui_out << target_point.z() << G4endl;
321
322 //----- Magnification
323 const G4double zoom_factor = fVP.GetZoomFactor();
324 if(half_view_angle < MIN_HALF_ANGLE)
325 {
326 gui_out << zoom_factor << G4endl;
327 }
328 else
329 {
330 const G4double FR_HALF_SCREEN_SIZE = 0.5;
331 G4double focal_distance = FR_HALF_SCREEN_SIZE / std::tan(half_view_angle);
332 focal_distance *= zoom_factor;
333
334 gui_out << "fd" << focal_distance << G4endl;
335 }
336 SendDrawingStyleToDAWNGUI(gui_out); // gui_out, viewing mode
337 gui_out << "0.001" << G4endl; // 3D Tolerance
338 gui_out << "0" << G4endl; // not display parameters
339
340 // ######### P2
341 gui_out << 1 << G4endl; // Source light
342 gui_out << 1 << G4endl;
343 gui_out << 1 << G4endl;
344 gui_out << 0.5 << G4endl; // Ambient light
345 gui_out << 0.5 << G4endl;
346 gui_out << 0.5 << G4endl;
347 gui_out << 19.0 << G4endl; // Light direction (Polar)
348 gui_out << 71.0 << G4endl; // Light direction (Azimuthal)
349
350 // ######### P3
351 gui_out << 0.1 << G4endl; // Real edge width
352 gui_out << 0.1 << G4endl; // outline width
353 gui_out << 0.1 << G4endl; // aux edge width
354 gui_out << 3 << G4endl; // aux edge style
355 gui_out << 70.0 << G4endl; // aux-edge threshold angle
356 gui_out << 0.1 << G4endl; // line width
357 gui_out << 0 << G4endl; // haloing
358 gui_out << 1 << G4endl; // Dashed edged for back faces
359
360 //######### P4
361 //----- drawing device
362 // enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
363 if(((std::getenv(FR_ENV_MULTI_WINDOW) != NULL) &&
364 (strcmp(std::getenv(FR_ENV_MULTI_WINDOW), "0"))) ||
365 ((std::getenv(FR_ENV_MULTI_WINDOW2) != NULL) &&
366 (strcmp(std::getenv(FR_ENV_MULTI_WINDOW2), "0"))))
367 {
368 gui_out << 2 << G4endl; // OpenWindow
369 }
370 else
371 {
372 gui_out << 1 << G4endl; // Invoke PS viewer
373 }
374
375 gui_out << GetPSViewer() << G4endl; // PS viewer
376 gui_out << 1 << G4endl; // Do not add showpage
377 gui_out << 0 << G4endl; // Non-append mode
378
379 gui_out.close();
380 //########### end of generating file .DAWN.history
381}
const char FR_ENV_MULTI_WINDOW2[]
const char FR_ENV_MULTI_WINDOW[]
double G4double
Definition: G4Types.hh:83
void SendDrawingStyleToDAWNGUI(std::ostream &out)
const char * GetPSViewer()
const G4VisExtent & GetExtent() const
const G4Point3D & GetStandardTargetPoint() const
G4Scene * GetScene() const
const G4Vector3D & GetViewpointDirection() const
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFieldHalfAngle() const
G4double GetZoomFactor() const
G4double GetDolly() const
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
BasicVector3D< T > unit() const
const G4double pi

Referenced by ShowView().

◆ SetView()

void G4DAWNFILEViewer::SetView ( )
virtual

Implements G4VViewer.

Definition at line 96 of file G4DAWNFILEViewer.cc.

97{
98#if defined DEBUG_FR_VIEW
100 G4cout << "***** G4DAWNFILEViewer::SetView(): No effects" << G4endl;
101#endif
102 // Do nothing, since DAWN is running as a different process.
103 // SendViewParameters () will do this job instead.
104}

◆ ShowView()

void G4DAWNFILEViewer::ShowView ( void  )
virtual

Reimplemented from G4VViewer.

Definition at line 143 of file G4DAWNFILEViewer.cc.

144{
145#if defined DEBUG_FR_VIEW
147 G4cout << "***** G4DAWNFILEViewer::ShowView () " << G4endl;
148#endif
149
150 if(fSceneHandler.FRIsInModeling())
151 {
152 //----- End of modeling
153 // !EndModeling, !DrawAll, !CloseDevice,
154 // close g4.prim
155 fSceneHandler.FREndModeling();
156
157 //----- Output DAWN GUI file
159
160 //----- string for viewer invocation
161 if(!strcmp(fG4PrimViewer, "NONE"))
162 {
163 strcpy(fG4PrimViewerInvocation, "");
164 }
165 else
166 {
167 strcpy(fG4PrimViewerInvocation, fG4PrimViewer);
168 strcat(fG4PrimViewerInvocation, " ");
169 strcat(fG4PrimViewerInvocation, fSceneHandler.GetG4PrimFileName());
170 }
171
172 //----- Invoke DAWN
173 G4cout << G4endl;
174 if(false == G4FRofstream::DoesFileExist(fSceneHandler.GetG4PrimFileName()))
175 {
176 G4cout << "ERROR: Failed to generate file ";
177 G4cout << fSceneHandler.GetG4PrimFileName() << G4endl;
178 }
179 else if(strcmp(GetG4PrimViewerInvocation(), ""))
180 {
181 G4cout << "File " << fSceneHandler.GetG4PrimFileName();
182 G4cout << " is generated." << G4endl;
184 int iErr = system(GetG4PrimViewerInvocation());
185 if(iErr != 0)
186 {
188 ed << "Error " << iErr << " when calling system with \""
189 << GetG4PrimViewerInvocation() << "\".";
190 G4Exception("G4DAWNFILEViewer::ShowView()", "dawn0005", JustWarning,
191 ed);
192 }
193 }
194 else
195 { // no view, i.e., only file generation
196 G4cout << "File " << fSceneHandler.GetG4PrimFileName();
197 G4cout << " is generated." << G4endl;
198 G4cout << "No viewer is invoked." << G4endl;
199 }
200 }
201
202} // G4DAWNFILEViewer::ShowView()
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
const char * GetG4PrimViewerInvocation()
static G4bool DoesFileExist(const char *filename)
Definition: G4FRofstream.hh:94

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