Geant4  10.03
G4VRML1SceneHandlerFunc.icc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4VRML1SceneHandlerFunc.icc 101714 2016-11-22 08:53:13Z gcosmo $
28 //
29 // G4VRML1SceneHandlerFunc.icc
30 // Satoshi Tanaka & Yasuhide Sawada
31 
32 #include <CLHEP/Units/SystemOfUnits.h>
33 
34 #include "G4VisManager.hh"
35 
36 //#define DEBUG_SCENE_FUNC
37 
38 // MACRO
39 #define ADDTHIS_WITH_NAME(Solid) \
40  fCurrentDEF = #Solid "_" + Solid.GetName(); \
41  RequestPrimitives(Solid); \
42  fCurrentDEF = "";
43 
44 // End of MACRO
45 
46 void G4VRML1SCENEHANDLER::AddSolid(const G4Trd& trd)
47 {
48 #if defined DEBUG_SCENE_FUNC
49  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
50  G4cout << "***** AddSolid trd" << "\n" ;
51 #endif
52  VRMLBeginModeling () ;
53  ADDTHIS_WITH_NAME(trd)
54 }
55 
56 void G4VRML1SCENEHANDLER::AddSolid(const G4Trap& trap)
57 {
58 #if defined DEBUG_SCENE_FUNC
59  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
60  G4cout << "***** AddSolid trap" << "\n" ;
61 #endif
62  VRMLBeginModeling () ;
63  ADDTHIS_WITH_NAME(trap)
64 }
65 
66 void G4VRML1SCENEHANDLER::AddSolid(const G4Para& para)
67 {
68 #if defined DEBUG_SCENE_FUNC
69  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
70  G4cout << "***** AddSolid para" << "\n" ;
71 #endif
72  VRMLBeginModeling () ;
73  ADDTHIS_WITH_NAME(para)
74 }
75 
76 void G4VRML1SCENEHANDLER::AddSolid(const G4Torus& torus )
77 {
78 #if defined DEBUG_SCENE_FUNC
79  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
80  G4cout << "***** AddSolid torus" << "\n" ;
81 #endif
82  VRMLBeginModeling () ;
83  ADDTHIS_WITH_NAME(torus)
84 }
85 
86 
87 void G4VRML1SCENEHANDLER::AddSolid(const G4VSolid& vsolid)
88 {
89 #if defined DEBUG_SCENE_FUNC
90  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
91  G4cout << "***** AddSolid vsolid" << "\n" ;
92 #endif
93  VRMLBeginModeling () ;
94  ADDTHIS_WITH_NAME(vsolid)
95 }
96 
97 void G4VRML1SCENEHANDLER::AddSolid(const G4Tubs& tubs)
98 {
99 #if defined DEBUG_SCENE_FUNC
100  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
101  G4cout << "***** AddSolid tubs" << "\n" ;
102 #endif
103  VRMLBeginModeling () ;
104 
105  // set current name
106  fCurrentDEF = "tubs_" + tubs.GetName();
107 
108  // Get data
109  const G4double R = tubs.GetOuterRadius(); // outside radius
110  const G4double r = tubs.GetInnerRadius(); // inside radius
111  const G4double dz = tubs.GetZHalfLength(); // half length in z
112  const G4double dp = tubs.GetDeltaPhiAngle(); // angle interval
113 
114  // Send data
115  if ( r == 0.0 && dp >= 360. * CLHEP::deg ) {
116  // Send a built-in VRML node (Cylinder)
117  fDest << "Separator {" << "\n";
118  SendMatrixTransformNode( fObjectTransformation );
119 
120  fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
121  SendMaterialNode();
122  SendCylinderNode(R, dz * 2);
123  fDest << "\t" << "}" << "\n"; // DEF Separator
124  fDest << "}" << "\n"; // Separator
125  } else {
126  // call AddPrimitive(Polyhedron)
127  RequestPrimitives(tubs);
128  }
129 
130  // reset current name to null
131  fCurrentDEF = "";
132 }
133 
134 
135 void G4VRML1SCENEHANDLER::AddSolid(const G4Cons& cons)
136 {
137 #if defined DEBUG_SCENE_FUNC
138  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
139  G4cout << "***** AddSolid cons" << "\n" ;
140 #endif
141  VRMLBeginModeling () ;
142 
143  // set current name
144  fCurrentDEF = "cons_" + cons.GetName();
145 
146  // Get data
147  const G4double r1 = cons.GetInnerRadiusMinusZ(); // inside radius at -dz
148  const G4double R1 = cons.GetOuterRadiusMinusZ(); // outside radius at -dz
149  const G4double r2 = cons.GetInnerRadiusPlusZ(); // inside radius at +dz
150  const G4double R2 = cons.GetOuterRadiusPlusZ(); // outside radius at +dz
151  const G4double dz = cons.GetZHalfLength(); // half length in z
152  //const G4double sp = cons.GetStartPhiAngle(); // starting angle
153  const G4double dp = cons.GetDeltaPhiAngle(); // angle width
154 
155  // Send data
156  if ( r1 == 0.0 && r2 == 0.0 && R1 == R2 && dp >= 360. * CLHEP::deg) {
157  // Send a built-in VRML node (Cylinder)
158  fDest << "Separator {" << "\n";
159  SendMatrixTransformNode( fObjectTransformation );
160 
161  fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
162  SendMaterialNode();
163  SendCylinderNode(R1, dz * 2);
164  fDest << "\t" << "}" << "\n"; // DEF Separator
165  fDest << "}" << "\n"; // Separator
166  } else {
167  // call AddPrimitive(Polyhedron)
168  RequestPrimitives(cons);
169  }
170 
171  // reset current name to null
172  fCurrentDEF = "";
173 }
174 
175 void G4VRML1SCENEHANDLER::AddSolid(const G4Box& box)
176 {
177 #if defined DEBUG_SCENE_FUNC
178  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
179  G4cout << "***** AddSolid box" << "\n" ;
180 #endif
181  VRMLBeginModeling () ;
182 
183  // set current name
184  fCurrentDEF = "box_" + box.GetName();
185 
186  // Send a built-in VRML node (Cube)
187  fDest << "Separator {" << "\n";
188 
189  //fDest << "\t" << "renderCulling ON" << "\n";
190  SendMatrixTransformNode( fObjectTransformation );
191 
192  fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
193  SendMaterialNode();
194  SendCubeNode(box.GetXHalfLength() * 2, box.GetYHalfLength() * 2, box.GetZHalfLength() * 2);
195  fDest << "\t" << "}" << "\n"; // DEF Separator
196 
197  fDest << "}" << "\n"; // Separator
198 
199  // reset current name to null
200  fCurrentDEF = "";
201 }
202 
203 
204 void G4VRML1SCENEHANDLER::AddSolid(const G4Sphere& sphere)
205 {
206 #if defined DEBUG_SCENE_FUNC
207  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
208  G4cout << "***** AddSolid sphere" << "\n" ;
209 #endif
210  VRMLBeginModeling () ;
211 
212  // set current name
213  fCurrentDEF = "sphere_" + sphere.GetName();
214 
215  // Get data
216  G4double dphi = sphere.GetDeltaPhiAngle () ;
217  G4double dtheta = sphere.GetDeltaThetaAngle() ;
218  G4double rmax = sphere.GetOuterRadius () ;
219  G4double rmin = sphere.GetInnerRadius () ;
220 
221  // Send data
222  if ( (dphi >= 360. * CLHEP::deg) && (dtheta >= 180. * CLHEP::deg) && (rmin == 0.0) ) {
223  // Send a built-in VRML node (Sphere)
224  fDest << "Separator {" << "\n";
225  SendMatrixTransformNode( fObjectTransformation );
226 
227  fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
228  SendMaterialNode();
229  SendSphereNode( rmax );
230  fDest << "\t" << "}" << "\n"; // DEF Separator
231  fDest << "}" << "\n"; // Separator
232  } else {
233  // call AddPrimitive(Polyhedron)
234  RequestPrimitives( sphere );
235  }
236 
237  // reset current name to null
238  fCurrentDEF = "";
239 }
240 
241 void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyline& polyline)
242 {
243 #if defined DEBUG_SCENE_FUNC
244  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
245  G4cout << "***** AddPrimitive polyline" << "\n" ;
246 #endif
247  if (fProcessing2D) {
248  static G4bool warned = false;
249  if (!warned) {
250  warned = true;
251  G4Exception
252  ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Polyline&)",
253  "VRML-1001", JustWarning,
254  "2D polylines not implemented. Ignored.");
255  }
256  return;
257  }
258 
259  VRMLBeginModeling () ;
260 
261  fDest << "Separator {" << "\n";
262 
263  SendMatrixTransformNode (fObjectTransformation );
264 
265  SendMaterialNode( polyline.GetVisAttributes() );
266 
267  fDest << "\t" << "Coordinate3 {" << "\n";
268  fDest << "\t\t" << "point [" << "\n";
269  G4int e, i;
270  for (i = 0, e = polyline.size(); e; i++, e--) {
271  fDest << "\t\t\t";
272  fDest << polyline[i].x() << " ";
273  fDest << polyline[i].y() << " ";
274  fDest << polyline[i].z() << "," << "\n";
275  }
276  fDest << "\t\t" << "]" << "\n";
277  fDest << "\t" << "}" << "\n"; // Coordinate3
278 
279  fDest << "\t" << "IndexedLineSet {" << "\n";
280  fDest << "\t\t" << "coordIndex [";
281  for (i = 0, e = polyline.size(); e; i++, e--) {
282  if (i % 10 == 0)
283  fDest << "\n" << "\t\t\t";
284  fDest << i << ", ";
285  }
286  fDest << "-1" << "\n";
287  fDest << "\t\t" << "]" << "\n";
288  fDest << "\t" << "}" << "\n"; // IndexedLineSet
289 
290  fDest << "}" << "\n"; // Separator
291 }
292 
293 void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron)
294 {
295 #if defined DEBUG_SCENE_FUNC
296  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
297  G4cout << "***** AddPrimitive(G4Polyhedron)" << "\n";
298 #endif
299 
300  if (polyhedron.GetNoFacets() == 0) return;
301 
302  if (fProcessing2D) {
303  static G4bool warned = false;
304  if (!warned) {
305  warned = true;
306  G4Exception
307  ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Polyhedron&)",
308  "VRML-1002", JustWarning,
309  "2D polyhedra not implemented. Ignored.");
310  }
311  return;
312  }
313 
314  VRMLBeginModeling () ;
315 
316  fDest << "Separator {" << "\n";
317 
318  SendMatrixTransformNode( fObjectTransformation );
319 
320  fDest << "\t";
321  if (fCurrentDEF != "")
322  fDest << "DEF " << fCurrentDEF << " ";
323 
324  fDest << "Separator {" << "\n";
325 
326  //fDest << "\t\t" << "renderCulling ON" << "\n";
327 
328  fDest << "\t\t" << "ShapeHints {" << "\n";
329  fDest << "\t\t\t" << "vertexOrdering COUNTERCLOCKWISE" << "\n";
330  fDest << "\t\t\t" << "shapeType SOLID" << "\n";
331  fDest << "\t\t\t" << "faceType CONVEX" << "\n";
332  fDest << "\t\t" << "}" << "\n";
333 
334  SendMaterialNode();
335 
336  fDest << "\t\t" << "Coordinate3 {" << "\n";
337  fDest << "\t\t\t" << "point [" << "\n";
338  G4int i, j;
339  for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) {
340  G4Point3D point = polyhedron.GetVertex(i);
341  fDest << "\t\t\t\t";
342  fDest << point.x() << " ";
343  fDest << point.y() << " ";
344  fDest << point.z() << "," << "\n";
345  }
346  fDest << "\t\t\t" << "]" << "\n";
347  fDest << "\t\t" << "}" << "\n"; // Coordinate3
348 
349  fDest << "\t\t" << "IndexedFaceSet {" << "\n";
350  fDest << "\t\t\t" << "coordIndex [" << "\n";
351 
352  // facet loop
353  G4int f;
354  for (f = polyhedron.GetNoFacets(); f; f--) {
355 
356  // edge loop
357  G4bool notLastEdge;
358  G4int index = -1, edgeFlag = 1;
359  fDest << "\t\t\t\t";
360  do {
361  notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
362  fDest << index - 1 << ", ";
363  } while (notLastEdge);
364  fDest << "-1," << "\n";
365  }
366  fDest << "\t\t\t" << "]" << "\n";
367  fDest << "\t\t" << "}" << "\n"; // IndexFaceSet
368 
369  fDest << "\t" << "}" << "\n"; // (DEF) Separator
370  fDest << "}" << "\n"; // Separator
371 
372 }
373 
374 void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& )
375 {
376 #if defined DEBUG_SCENE_FUNC
377  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
378  G4cout << "***** AddPrimitive text" << "\n" ;
379 #endif
380  /*** You might need this
381  if (fProcessing2D) {
382  static G4bool warned = false;
383  if (!warned) {
384  warned = true;
385  G4Exception
386  ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Text&)",
387  "VRML-1003", JustWarning,
388  "2D text not implemented. Ignored.");
389  }
390  return;
391  }
392  ***/
393 
394  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
395  G4cout <<
396  "***** void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& text )"
397  " not implemented yet."
398  << "\n";
399 
400  VRMLBeginModeling () ;
401 }
402 
403 void G4VRML1SCENEHANDLER::AddPrimitive( const G4Circle& circle )
404 {
405 #if defined DEBUG_SCENE_FUNC
406  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
407  G4cout << "***** AddPrimitive circle" << "\n" ;
408 #endif
409 
410  if (fProcessing2D) {
411  static G4bool warned = false;
412  if (!warned) {
413  warned = true;
414  G4Exception
415  ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Circle&)",
416  "VRML-1004", JustWarning,
417  "2D circles not implemented. Ignored.");
418  }
419  return;
420  }
421 
422  VRMLBeginModeling () ;
423 
424  // begin sending a mark
425  fDest << "Separator {" << "\n";
426 
427  // send color
428  SendMarkerColor ( circle ) ;
429 
430  // position
431  SendMarkerWorldPosition ( circle ) ;
432 
433  // Calc size
434  G4double size = GetMarkerHalfSize ( circle );
435 
436  // send shape with size
437  fDest << "\t" << "Sphere {" << "\n";
438  fDest << "\t\t" << "radius " << size << "\n";
439  fDest << "\t" << "}" << "\n";
440 
441  // end sending a mark
442  fDest << "}" << "\n"; // Separator
443 }
444 
445 
446 void G4VRML1SCENEHANDLER::AddPrimitive(const G4Square& square)
447 {
448 #if defined DEBUG_SCENE_FUNC
449  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
450  G4cout << "***** AddPrimitive square" << "\n" ;
451 #endif
452 
453  if (fProcessing2D) {
454  static G4bool warned = false;
455  if (!warned) {
456  warned = true;
457  G4Exception
458  ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Square&)",
459  "VRML-1005", JustWarning,
460  "2D squares not implemented. Ignored.");
461  }
462  return;
463  }
464 
465  VRMLBeginModeling () ;
466 
467  // begin sending a mark
468  fDest << "Separator {" << "\n";
469 
470  // send color
471  SendMarkerColor ( square );
472 
473  // position
474  SendMarkerWorldPosition ( square );
475 
476  // Calc size
477  G4double size = GetMarkerHalfSize ( square );
478  size *= 2.;
479 
480  // send shape with size
481  fDest << "\t" << "Cube {" << "\n";
482  fDest << "\t\t" << "width " << size << "\n";
483  fDest << "\t\t" << "height " << size << "\n";
484  fDest << "\t\t" << "depth " << size << "\n";
485  fDest << "\t" << "}" << "\n";
486 
487  // end sending a mark
488  fDest << "}" << "\n"; // Separator
489 }
490 
491 void G4VRML1SCENEHANDLER::BeginModeling()
492 {
493 #if defined DEBUG_SCENE_FUNC
494  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
495  G4cout << "***** BeginModeling " << "\n" ;
496 #endif
497  G4VSceneHandler::BeginModeling();
498 }
499 
500 void G4VRML1SCENEHANDLER::EndModeling()
501 {
502 #if defined DEBUG_SCENE_FUNC
503  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
504  G4cout << "***** EndModeling " << "\n" ;
505 #endif
506  G4VSceneHandler::EndModeling();
507 }
508 
509 void G4VRML1SCENEHANDLER::BeginPrimitives(const G4Transform3D& objectTransformation)
510 {
511  G4VSceneHandler::BeginPrimitives (objectTransformation);
512 #if defined DEBUG_SCENE_FUNC
513  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
514  G4cout << "***** BeginPrimitives " << "\n" ;
515 #endif
516  VRMLBeginModeling();
517 }
518 
519 void G4VRML1SCENEHANDLER::EndPrimitives()
520 {
521 #if defined DEBUG_SCENE_FUNC
522  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
523  G4cout << "***** EndPrimitives " << "\n" ;
524 #endif
525  G4VSceneHandler::EndPrimitives();
526 }
527 
528 void G4VRML1SCENEHANDLER::SendMaterialNode( const G4VisAttributes* pVA )
529 {
530 // const double TRANSPARENCY = 0.9 ;
531  const double TRANSPARENCY = 0.5 ;
532 
533  if (!pVA)
534  return;
535 
536  const G4Color& color = pVA->GetColor();
537 
538  fDest << "\t\t" << "Material {" << "\n";
539 
540  if (pVA->IsForceDrawingStyle() &&
541  (pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe)) {
542  fDest << "\t\t\t" << "transparency " << TRANSPARENCY << "\n";
543  }
544 
545  fDest << "\t\t\t" << "diffuseColor";
546  fDest << " " << color.GetRed();
547  fDest << " " << color.GetGreen();
548  fDest << " " << color.GetBlue();
549  fDest << "\n";
550  fDest << "\t\t" << "}" << "\n";
551 }
552 
553 
554 void G4VRML1SCENEHANDLER::SendMaterialNode()
555 {
556  SendMaterialNode
557  ( fpViewer->GetApplicableVisAttributes (fpVisAttribs) );
558 }
559 
560 
561 void G4VRML1SCENEHANDLER::SendMatrixTransformNode(const G4Transform3D& trans)
562 {
563  G4Point3D B (0.0, 0.0, 0.0);
564 
565  G4Point3D x1 (1.0, 0.0, 0.0);
566  G4Point3D y1 (0.0, 1.0, 0.0);
567 
568  G4Vector3D e1 (1.0, 0.0, 0.0);
569  G4Vector3D e2 (0.0, 1.0, 0.0);
570  G4Vector3D e3 (0.0, 0.0, 1.0);
571 
572  //----- transformed origin of body coord
573  B.transform(trans);
574 
575  //----- transformed base vectors of body coord
576  x1.transform(trans);
577  e1 = x1 - B;
578 
579  y1.transform(trans);
580  e2 = y1 - B;
581 
582  e3 = e1.cross(e2);
583 
584  e1 = e1.unit(); // normalize again for accuracy
585  e2 = e2.unit(); //
586  e3 = e3.unit(); //
587 
588  fDest << "\t" << "MatrixTransform {" << "\n";
589  fDest << "\t\t" << "matrix ";
590  fDest << e1.x() << " " << e1.y() << " " << e1.z() << " 0 ";
591  fDest << e2.x() << " " << e2.y() << " " << e2.z() << " 0 ";
592  fDest << e3.x() << " " << e3.y() << " " << e3.z() << " 0 ";
593  fDest << B.x() << " " << B.y() << " " << B.z() << " 1" << "\n";
594  fDest << "\t" << "}" << "\n";
595 }
596 
597 void G4VRML1SCENEHANDLER::SendCubeNode(G4double w, G4double h, G4double d)
598 {
599  fDest << "\t\t" << "Cube {" << "\n";
600  fDest << "\t\t\t" << "width " << w << "\n";
601  fDest << "\t\t\t" << "height " << h << "\n";
602  fDest << "\t\t\t" << "depth " << d << "\n";
603  fDest << "\t\t" << "}" << "\n";
604 }
605 
606 void G4VRML1SCENEHANDLER::SendCylinderNode(G4double R, G4double h)
607 {
608  fDest << "\t\t" << "Transform {" << "\n";
609  fDest << "\t\t\t" << "rotation 1 0 0 " << (90. * CLHEP::deg) << "\n";
610  fDest << "\t\t" << "}" << "\n";
611 
612  fDest << "\t\t" << "Cylinder {" << "\n";
613  fDest << "\t\t\t" << "radius " << R << "\n";
614  fDest << "\t\t\t" << "height " << h << "\n";
615  fDest << "\t\t" << "}" << "\n";
616 }
617 
618 void G4VRML1SCENEHANDLER::SendSphereNode(G4double R)
619 {
620  fDest << "\t\t" << "Sphere {" << "\n";
621  fDest << "\t\t\t" << "radius " << R << "\n";
622  fDest << "\t\t" << "}" << "\n";
623 }
624 
625 void G4VRML1SCENEHANDLER::VRMLBeginModeling()
626 {
627  if (!IS_CONNECTED ) {
628 #if defined DEBUG_SCENE_FUNC
629  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
630  G4cout << "***** VRMLBeginModeling() (started)" << "\n" ;
631 #endif
632  this->connectPort();
633  fDest << "#VRML V1.0 ascii" << "\n";
634  fDest << "# Generated by VRML 1.0 driver of GEANT4\n" << "\n";
635  }
636 }
637 
638 void G4VRML1SCENEHANDLER::VRMLEndModeling()
639 {
640  if ( IS_CONNECTED ) {
641 #if defined DEBUG_SCENE_FUNC
642  if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
643  G4cout << "***** VRMLEndModeling() (started)" << "\n" ;
644 #endif
645 
646  fDest << "#End of file." << "\n";
647  this->closePort();
648  }
649 }
650 
651 void G4VRML1SCENEHANDLER::SendMarkerColor ( const G4VMarker& marker )
652 {
653  fpVisAttribs = marker.GetVisAttributes();
654  const G4Color& color = GetColor();
655 
656  fDest << "\t" << "Material {" << "\n";
657  fDest << "\t\t";
658  fDest << "ambientColor [] ";
659  fDest << "specularColor [] ";
660  fDest << "\t\t" << "diffuseColor";
661  fDest << " " << color.GetRed();
662  fDest << " " << color.GetGreen();
663  fDest << " " << color.GetBlue();
664  fDest << "\n";
665  fDest << "\t\t" << "emissiveColor";
666  fDest << " " << color.GetRed();
667  fDest << " " << color.GetGreen();
668  fDest << " " << color.GetBlue();
669  fDest << "\n";
670  fDest << "\t" << "}" << "\n";
671 }
672 
673 void
674 G4VRML1SCENEHANDLER::SendMarkerWorldPosition ( const G4VMarker& mark )
675 {
676  G4Point3D point = mark.GetPosition();
677 
678  SendMatrixTransformNode( fObjectTransformation );
679 
680  fDest << "\t\t" << "Transform {" << "\n";
681  fDest << "\t\t\t" << "translation ";
682  fDest << point.x() << " " << point.y() << " " << point.z() << "\n";
683  fDest << "\t\t" << "}" << "\n" ;
684 }
685 
686 
687 G4double G4VRML1SCENEHANDLER::GetMarkerHalfSize ( const G4VMarker& mark )
688 {
689  //----- return value ( marker radius in 3d units)
690  G4double size = 1.0 ; // initialization
691 
692  //----- parameters to calculate 3d size from 2d size
693  const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels
694  double zoom_factor = fpViewer->GetViewParameters().GetZoomFactor() ;
695  if ( zoom_factor <= 0.0 ) { zoom_factor = 1.0 ; }
696  double extent_radius_3d = GetScene()->GetExtent().GetExtentRadius() ;
697  if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; }
698 
699  //----- get marker radius in 3D units
700  if ( mark.GetWorldSize() > 0.0 ) {
701  // get mark radius in 3D units
702  size = 0.5 * mark.GetWorldSize() ;
703 
704  } else if ( mark.GetScreenSize() > 0.0 ) {
705  // local
706  double mark_radius_2d = 0.5 * mark.GetScreenSize() ;
707 
708  // get mark radius in 3D units
709  size \
710  = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
711  size *= zoom_factor ;
712 
713  } else {
714  // local
715  double mark_radius_2d \
716  = fpViewer->GetViewParameters().GetDefaultMarker().GetScreenSize();
717  mark_radius_2d *= 0.1 ; // Magic number?
718 
719  // get mark radius in 3D units
720  size \
721  = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
722  size *= zoom_factor ;
723  }
724 
725  //----- global rescaling
726  size *= fpViewer->GetViewParameters().GetGlobalMarkerScale();
727 
728  //----- return size
729  return size ;
730 
731 }
732 
733 void G4VRML1SCENEHANDLER::ClearTransientStore()
734 {
735  // This is typically called after an update and before drawing hits
736  // of the next event. To simulate the clearing of "transients"
737  // (hits, etc.) the detector is redrawn...
738  if (fpViewer) {
739  fpViewer -> SetView ();
740  fpViewer -> ClearView ();
741  fpViewer -> DrawView ();
742  }
743 }
744 
745 
746 // #undef ADDTHIS_WITH_NAME(Solid)
747 // #undef MAKE_NAME(Solid)
748 // End of file.