2 // ********************************************************************
3 // * License and Disclaimer *
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. *
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. *
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 // ********************************************************************
27 // $Id: G4FRSceneFunc.icc 101714 2016-11-22 08:53:13Z gcosmo $
30 #include <CLHEP/Units/PhysicalConstants.h>
32 #include "G4VisManager.hh"
33 #include "G4PhysicalVolumeModel.hh"
34 #include "G4LogicalVolume.hh"
36 //========== AddPrimitive() functions ==========//
39 void G4FRSCENEHANDLER::AddPrimitive (const G4Polyline& polyline)
41 #if defined DEBUG_FR_SCENE
42 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
43 G4cout << "***** AddPrimitive\n";
46 static G4bool warned = false;
50 ("G4FRSCENEHANDLER::AddPrimitive (const G4Polyline&)",
51 "dawn0001", JustWarning,
52 "2D polylines not implemented. Ignored.");
56 //----- Initialize Fukui Renderer IF NECESSARY
59 //----- local working variables
60 G4int nPoints = polyline.size ();
62 const G4VisAttributes* pVA =
63 fpViewer->GetApplicableVisAttributes ( polyline.GetVisAttributes() );
65 //----- skip drawing invisible primitive
67 if( !(pVA->IsVisible()) ) { return ; }
71 if(!SendVisAttributes( pVA ) ) {
72 SendStr( FR_COLOR_RGB_RED ); // color
75 //----- send coordinates to Fukui Renderer
76 SendTransformedCoordinates();
78 //----- send beginning of polyline
79 SendStr( FR_POLYLINE );
81 //----- vertices on polyline
82 for ( i = 0; i < nPoints; i++ ) {
83 SendStrDouble3( FR_PL_VERTEX , \
89 //----- send ending of polyline
90 SendStr( FR_END_POLYLINE );
92 } // G4FRSCENEHANDLER::AddPrimitive (polyline)
96 void G4FRSCENEHANDLER::AddPrimitive ( const G4Text& text )
99 #if defined DEBUG_FR_SCENE
100 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
101 G4cout << "***** AddPrimitive( G4Text )\n";
103 //----- Initialize DAWN IF NECESSARY
107 const G4Color& color = GetTextColor (text) ;
108 SendStrDouble3( FR_COLOR_RGB ,
113 //----- send body coordinates
114 SendTransformedCoordinates();
117 MarkerSizeType size_type;
118 G4double fontsize = GetMarkerDiameter( text , size_type );
120 //----- Calc position
121 const G4Point3D& position = text.GetPosition () ;
124 G4double x_offset = text.GetXOffset();
125 G4double y_offset = text.GetYOffset();
127 //----- get string to be visualized and Calc its length
128 const char* vis_text = text.GetText();
129 const int STR_LENGTH = strlen ( vis_text );
131 //----- create buffer and copy the string there
132 int MAX_STR_LENGTH = COMMAND_BUF_SIZE - 100 ;
133 if ( MAX_STR_LENGTH <= 0 ) {
134 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
135 G4cout << "ERROR (FukuiRenderer) : Not enough buffer size for data transferring." << G4endl;
136 G4cout << " G4Text Visualization is aborted" << G4endl;
140 char* buf = new char [ (MAX_STR_LENGTH + 1) ] ;
141 if ( MAX_STR_LENGTH >= STR_LENGTH ) {
142 strcpy ( buf, vis_text ) ;
144 strncpy ( buf, vis_text, MAX_STR_LENGTH ) ;
147 //----- select string command for 3D drawing
148 char text_command[32];
151 strcpy ( text_command, FR_MARK_TEXT_2D );
155 strcpy ( text_command, FR_MARK_TEXT_2DS );
159 //----- Send string command
161 // Map -1<x<1, -1<y<1 to 10<x<200, 53<y<243
162 G4double x_mm = 95. * position.x() + 105.;
163 G4double y_mm = 95. * position.y() + 148.;
164 SendStrDouble3Str( FR_TEXT_2DS,
169 SendStrDouble6Str( text_command, \
170 position.x() , position.y() , position.z(),
171 fontsize , x_offset , y_offset ,
175 //----- delete buffer
178 } // G4FRSCENEHANDLER::AddPrimitive ( text )
182 void G4FRSCENEHANDLER::AddPrimitive ( const G4Circle& mark_circle )
185 #if defined DEBUG_FR_SCENE
186 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
187 G4cout << "***** AddPrimitive( G4Circle )\n";
190 static G4bool warned = false;
194 ("G4FRSCENEHANDLER::AddPrimitive (const G4Circle&)",
195 "dawn0002", JustWarning,
196 "2D circles not implemented. Ignored.");
200 //----- Initialize Fukui Renderer IF NECESSARY
204 fpVisAttribs = mark_circle.GetVisAttributes();
205 const G4Color& color = GetColor () ;
206 SendStrDouble3( FR_COLOR_RGB ,
211 //----- send body coordinates
212 SendTransformedCoordinates();
214 //----- Calc position
215 const G4Point3D& position = mark_circle.GetPosition () ;
218 MarkerSizeType size_type;
219 G4double size = GetMarkerRadius( mark_circle , size_type );
224 SendStrDouble4( FR_MARK_CIRCLE_2D, \
225 position.x() , position.y() , position.z(), size );
229 SendStrDouble4( FR_MARK_CIRCLE_2DS, \
230 position.x() , position.y() , position.z(), size );
234 } // G4FRSCENEHANDLER::AddPrimitive ( mark_circle )
238 void G4FRSCENEHANDLER::AddPrimitive (const G4Square& mark_square )
241 #if defined DEBUG_FR_SCENE
242 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
243 G4cout << "***** AddPrimitive( G4Square )\n";
246 static G4bool warned = false;
250 ("G4FRSCENEHANDLER::AddPrimitive (const G4Square&)",
251 "dawn0003", JustWarning,
252 "2D squares not implemented. Ignored.");
256 //----- Initialize Fukui Renderer IF NECESSARY
260 fpVisAttribs = mark_square.GetVisAttributes();
261 const G4Color& color = GetColor () ;
262 SendStrDouble3( FR_COLOR_RGB ,
267 //----- send body coordinates
268 SendTransformedCoordinates();
270 //----- Calc position
271 const G4Point3D& position = mark_square.GetPosition () ;
274 MarkerSizeType size_type;
275 G4double size = GetMarkerRadius( mark_square , size_type );
280 SendStrDouble4( FR_MARK_SQUARE_2D, \
281 position.x() , position.y() , position.z(), size );
285 SendStrDouble4( FR_MARK_SQUARE_2DS, \
286 position.x() , position.y() , position.z(), size );
290 } // G4FRSCENEHANDLER::AddPrimitive ( mark_square )
293 //----- Add polyhedron
294 void G4FRSCENEHANDLER::AddPrimitive ( const G4Polyhedron& polyhedron )
297 #if defined DEBUG_FR_SCENE
298 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
299 G4cout << "***** AddPrimitive( G4Polyhedron )\n";
302 static G4bool warned = false;
306 ("G4FRSCENEHANDLER::AddPrimitive (const G4Polyhedron&)",
307 "dawn0004", JustWarning,
308 "2D polyhedrons not implemented. Ignored.");
313 if (polyhedron.GetNoFacets() == 0) return;
315 //----- Initialize Fukui Renderer IF NECESSARY
319 if(!SendVisAttributes( fpViewer->GetApplicableVisAttributes
320 (polyhedron.GetVisAttributes() ) ) ) {
321 SendStr( FR_COLOR_RGB_RED ); // color
325 SendTransformedCoordinates();
329 //---------- (1) Declare beginning of Brep data
330 SendStr(FR_POLYHEDRON);
332 //---------- (2) Vertex block
333 for (G4int i = 1, j = polyhedron.GetNoVertices(); j; j--, i++){
334 G4Point3D point = polyhedron.GetVertex(i);
335 SendStrDouble3( FR_VERTEX, point.x (), point.y (), point.z ());
338 //---------- (3) Facet block
339 for (G4int f = polyhedron.GetNoFacets(); f; f--){
341 G4int index = -1; // initialization
343 //G4int preedgeFlag = 1; Not used - comment out to prevent warnings (JA).
344 G4int work[4], i = 0;
346 //preedgeFlag = edgeFlag; Not used - comment out to prevent warnings (JA).
347 notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
349 }while (notLastEdge);
352 SendStrInt3(FR_FACET, work[0], work[1], work[2] );
355 SendStrInt4(FR_FACET, work[0], work[1], work[2], work[3] );
358 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
360 "ERROR G4FRSCENEHANDLER::AddPrimitive(G4Polyhedron)\n";
361 G4PhysicalVolumeModel* pPVModel =
362 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
364 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
366 "Volume " << pPVModel->GetCurrentPV()->GetName() <<
367 ", Solid " << pPVModel->GetCurrentLV()->GetSolid()->GetName() <<
368 " (" << pPVModel->GetCurrentLV()->GetSolid()->GetEntityType();
370 "\nG4Polyhedron facet with " << i << " edges" << G4endl;
375 //---------- (4) Declare ending of Brep data
376 SendStr(FR_END_POLYHEDRON);
378 } // G4FRSCENEHANDLER::AddPrimitive (polyhedron)
382 void G4FRSCENEHANDLER::SendNdiv ( void )
384 //////////////////////////////////////////////////
385 //#if defined DEBUG_FR_SCENE
386 // G4cout << "***** SendNdiv() (/Ndiv)" << G4endl;
388 //////////////////////////////////////////////////
391 G4int num_division = FR_DEFALUT_NDIV_VALUE ;
393 //----- number used for dividing a curved surface, Ndiv
394 // if ( GetModel() ) { ?? Why test for model. Can be zero. JA ??
395 const G4VisAttributes* pVisAttribs =
396 fpViewer -> GetApplicableVisAttributes (fpVisAttribs);
397 num_division = GetNoOfSides(pVisAttribs);
399 #if defined DEBUG_FR_SCENE
400 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
401 G4cout << "WARNING: GetNoOfSides() failed. " ;
402 G4cout << "The default value " << num_division ;
403 G4cout << " is assigned." << G4endl;
408 //---------- Error recovery for too small Ndiv
409 num_division = ( num_division < 3 ? 3 : num_division );
411 //////////////////////////////////////////////////
412 //#if defined DEBUG_FR_SCENE
413 // G4cout << "Ndiv = " << num_division << G4endl;
415 //////////////////////////////////////////////////
417 //----- Send resultant Ndiv
418 this->SendStrInt( FR_NDIV, num_division );
424 void G4FRSCENEHANDLER::FREndModeling ()
427 #if defined DEBUG_FR_SCENE
428 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
429 G4cout << "***** FREndModeling (called)" << G4endl;
431 if( FRIsInModeling() ) {
433 #if defined DEBUG_FR_SCENE
434 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
435 G4cout << "***** FREndModeling (started) " ;
436 G4cout << "(/EndModeling, /DrawAll, /CloseDevice)" << G4endl;
440 SendStr( "#--------------------" );
443 SendStr( FR_END_MODELING );
446 SendStr( FR_DRAW_ALL );
449 SendStr( FR_CLOSE_DEVICE );
451 //----- End saving data to g4.prim
455 FRflag_in_modeling = false ;
461 void G4FRSCENEHANDLER::BeginPrimitives (const G4Transform3D& objectTransformation)
463 #if defined DEBUG_FR_SCENE
464 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
465 G4cout << "***** BeginPrimitives \n";
470 G4VSceneHandler::BeginPrimitives (objectTransformation);
475 void G4FRSCENEHANDLER::EndPrimitives ()
477 #if defined DEBUG_FR_SCENE
478 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
479 G4cout << "***** EndPrimitives \n";
481 G4VSceneHandler::EndPrimitives ();
485 //========== AddSolid() functions ==========//
488 void G4FRSCENEHANDLER::AddSolid( const G4Box& box )
490 #if defined DEBUG_FR_SCENE
491 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
492 G4cout << "***** AddSolid ( box )\n";
495 //----- skip drawing invisible primitive
496 if( !IsVisible() ) { return ; }
498 //----- Initialize Fukui Renderer IF NECESSARY
508 if(!SendVisAttributes
509 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
510 SendStr( FR_COLOR_RGB_GREEN ); // color
513 //----- parameters (half lengths of box)
514 G4double dx = box.GetXHalfLength ();
515 G4double dy = box.GetYHalfLength ();
516 G4double dz = box.GetZHalfLength ();
518 //----- send coordinates to Fukui Renderer
519 SendTransformedCoordinates();
521 //----- send box to Fukui Renderer
522 SendStrDouble3( FR_BOX, dx, dy, dz );
524 } // void G4FRSCENEHANDLER::AddSolid( const G4Box& box )
529 G4FRSCENEHANDLER::AddSolid( const G4Tubs& tubes )
531 #if defined DEBUG_FR_SCENE
532 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
533 G4cout << "***** AddSolid ( tubes )\n";
535 //----- skip drawing invisible primitive
536 if( !IsVisible() ) { return ; }
538 //----- Initialize Fukui Renderer IF NECESSARY
548 if(!SendVisAttributes
549 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
550 SendStr( FR_COLOR_RGB_BLUE ); // color
554 const G4double R = tubes.GetOuterRadius() ; // outside radius
555 const G4double r = tubes.GetInnerRadius() ; // inside radius
556 const G4double dz = tubes.GetZHalfLength() ; // half length in z
557 const G4double sphi = tubes.GetStartPhiAngle() ; // starting angle
558 const G4double dphi = tubes.GetDeltaPhiAngle() ; // angle width
560 //----- send coordinates to Fukui Renderer
561 SendTransformedCoordinates();
563 //----- send tubes to Fukui Renderer
564 SendStrDouble5( FR_TUBS, r, R, dz , sphi, dphi );
566 } // void G4FRSCENEHANDLER::AddSolid( const G4Tubs& )
572 G4FRSCENEHANDLER::AddSolid( const G4Cons& cons )
574 #if defined DEBUG_FR_SCENE
575 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
576 G4cout << "***** AddSolid ( cons )\n";
578 //----- skip drawing invisible primitive
579 if( !IsVisible() ) { return ; }
581 //----- Initialize Fukui Renderer IF NECESSARY
591 if(!SendVisAttributes
592 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
593 SendStr( FR_COLOR_RGB_CYAN ); // color
597 const G4double r1 = cons.GetInnerRadiusMinusZ() ; // inside radius at -dz
598 const G4double R1 = cons.GetOuterRadiusMinusZ() ; // outside radius at -dz
599 const G4double r2 = cons.GetInnerRadiusPlusZ() ; // inside radius at +dz
600 const G4double R2 = cons.GetOuterRadiusPlusZ() ; // outside radius at +dz
601 const G4double dz = cons.GetZHalfLength () ; // half length in z
602 const G4double sphi = cons.GetStartPhiAngle() ; // starting angle
603 const G4double dphi = cons.GetDeltaPhiAngle() ; // angle width
605 //----- send coordinates to Fukui Renderer
606 SendTransformedCoordinates();
608 //----- send cons to Fukui Renderer
609 SendStrDouble7( FR_CONS, r1, R1, r2, R2, dz , sphi, dphi );
611 }// G4FRSCENEHANDLER::AddSolid( cons )
615 void G4FRSCENEHANDLER::AddSolid ( const G4Trd& trd )
617 #if defined DEBUG_FR_SCENE
618 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
619 G4cout << "***** AddSolid ( trd )\n";
622 //----- skip drawing invisible primitive
623 if( !IsVisible() ) { return ; }
625 //----- Initialize Fukui Renderer IF NECESSARY
635 if(!SendVisAttributes
636 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
637 SendStr( FR_COLOR_RGB_MAGENTA ); // color
641 G4double dx1 = trd.GetXHalfLength1 ();
642 G4double dx2 = trd.GetXHalfLength2 ();
643 G4double dy1 = trd.GetYHalfLength1 ();
644 G4double dy2 = trd.GetYHalfLength2 ();
645 G4double dz = trd.GetZHalfLength ();
647 //----- send coordinates to Fukui Renderer
648 SendTransformedCoordinates();
650 //----- send trd to Fukui Renderer
651 SendStrDouble5( FR_TRD, dx1, dx2, dy1, dy2, dz );
653 } // G4FRSCENEHANDLER::AddSolid ( trd )
657 void G4FRSCENEHANDLER::AddSolid ( const G4Sphere& sphere )
659 #if defined DEBUG_FR_SCENE
660 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
661 G4cout << "***** AddSolid ( sphere )\n";
663 //----- skip drawing invisible primitive
664 if( !IsVisible() ) { return ; }
666 //----- Initialize Fukui Renderer IF NECESSARY
676 if(!SendVisAttributes
677 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
678 SendStr( FR_COLOR_RGB_YELLOW ); // color
682 // const G4double rmin = sphere.GetInnerRadius();
683 const G4double rmax = sphere.GetOuterRadius();
684 // const G4double sphi = sphere.GetStartPhiAngle();
685 const G4double dphi = sphere.GetDeltaPhiAngle();
686 // const G4double stheta = sphere.GetStartThetaAngle();
687 const G4double dtheta = sphere.GetDeltaThetaAngle();
689 //----- send coordinates to Fukui Renderer
690 SendTransformedCoordinates();
692 //----- send sphere to Fukui Renderer
693 const G4double PI_minus = 0.9999 * CLHEP::pi ;
694 const G4double PI2_minus = 1.9999 * CLHEP::pi ;
695 if( dphi > PI2_minus && dtheta > PI_minus ) {
697 SendStrDouble ( FR_SPHERE, rmax );
700 //----- call AddPrimitives( G4Polyhedron )
701 //...... For sphere "segment",
702 //...... G4Polyhedron is used for visualization.
703 //...... Visualization attributes and
704 //...... local coordinates are resent and overwritten.
705 G4VSceneHandler::AddSolid( sphere ) ;
707 ////////////////////////////////////////////////////////////////
708 // //----- sphere segment
709 // SendStrDouble6( FR_SPHERE_SEG, rmin, rmax, stheta, dtheta, sphi, dphi );
710 ////////////////////////////////////////////////////////////////
714 } // G4FRSCENEHANDLER::AddSolid ( sphere )
718 void G4FRSCENEHANDLER::AddSolid (const G4Para& para)
720 #if defined DEBUG_FR_SCENE
721 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
722 G4cout << "***** AddSolid ( para )\n";
725 //----- skip drawing invisible primitive
726 if( !IsVisible() ) { return ; }
728 //----- Initialize Fukui Renderer IF NECESSARY
738 if(!SendVisAttributes
739 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
740 SendStr( FR_COLOR_RGB_RED ); // color
744 const G4double epsilon = 1.0e-5 ;
746 //----- parameters preprocessing
747 G4double cosTheta = para.GetSymAxis().z() ;
748 if( cosTheta < epsilon ) {
749 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
750 G4cout << "WARNING from FukuiRenderer (DAWN) driver:" << G4endl;
751 G4cout << " Invalid parameter for parallelepiped." << G4endl;
752 G4cout << " Drawing is skipped." << G4endl;
756 G4double tanTheta_cosPhi_cosTheta = para.GetSymAxis().x() ;
757 G4double tanTheta_sinPhi_cosTheta = para.GetSymAxis().y() ;
760 G4double dx = para.GetXHalfLength ();
761 G4double dy = para.GetYHalfLength ();
762 G4double dz = para.GetZHalfLength ();
763 G4double tanAlpha = para.GetTanAlpha();
764 G4double tanTheta_cosPhi = tanTheta_cosPhi_cosTheta / cosTheta ;
765 G4double tanTheta_sinPhi = tanTheta_sinPhi_cosTheta / cosTheta ;
767 //----- send coordinates to Fukui Renderer
768 SendTransformedCoordinates();
770 //----- send data to Fukui Renderer
771 SendStrDouble6 ( FR_PARA, dx, dy, dz, tanAlpha, tanTheta_cosPhi, tanTheta_sinPhi );
773 } // G4FRSCENEHANDLER::AddSolid ( para )
777 void G4FRSCENEHANDLER::AddSolid (const G4Trap& trap)
779 #if defined DEBUG_FR_SCENE
780 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
781 G4cout << "***** AddSolid ( trap )\n";
784 //----- skip drawing invisible primitive
785 if( !IsVisible() ) { return ; }
787 //----- Initialize Fukui Renderer IF NECESSARY
797 if(!SendVisAttributes
798 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
799 SendStr( FR_COLOR_RGB_GREEN ); // color
803 const G4double epsilon = 1.0e-5 ;
805 //----- parameters preprocessing
806 G4double cosTheta = trap.GetSymAxis().z() ;
807 if( cosTheta < epsilon ) {
808 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
809 G4cout << "WARNING from FukuiRenderer (DAWN) driver:" << G4endl;
810 G4cout << " Invalid parameter for trap, 1" << G4endl;
811 G4cout << " Drawing is skipped." << G4endl;
816 G4double nx = trap.GetSymAxis().x() ;
817 G4double ny = trap.GetSymAxis().y() ;
819 //----- parameters (half lengths of box)
820 G4double dz = trap.GetZHalfLength ();
821 G4double theta = std::acos( cosTheta ) ;
823 if ( ny==0. && nx ==0.) {
824 phi = 0.; // std::atan2(0.,0.) gives undefined value of phi
826 phi = std::atan2( ny, nx ) ; if( phi < 0. ) { phi += CLHEP::twopi ; }
827 // -PI < std::atan() < PI
829 /////////////////////////////////////////////////
830 // G4double phi = std::atan2( ny, nx ) ;
831 // if( phi < 0.0 ) { phi += CLHEP::twopi ; }
832 // // -PI < std::atan() < PI
833 /////////////////////////////////////////////////
835 G4double h1 = trap.GetYHalfLength1 ();
836 G4double bl1 = trap.GetXHalfLength1 ();
837 G4double tl1 = trap.GetXHalfLength2 ();
838 G4double alpha1 = std::atan( trap.GetTanAlpha1()) ;
839 G4double h2 = trap.GetYHalfLength2 ();
840 G4double bl2 = trap.GetXHalfLength3 ();
841 G4double tl2 = trap.GetXHalfLength4 ();
842 G4double alpha2 = std::atan( trap.GetTanAlpha2()) ;
844 //----- send coordinates to Fukui Renderer
845 SendTransformedCoordinates();
847 //----- Change sign of alpha for compatibility
848 // with the DAWN format
849 G4double alpha_sign = -1.0 ;
850 alpha1 *= alpha_sign ; alpha2 *= alpha_sign ;
852 //----- send box to Fukui Renderer
853 SendStrDouble11( FR_TRAP ,
866 } // G4FRSCENEHANDLER::AddSolid (const G4Trap& trap)
871 G4FRSCENEHANDLER::AddSolid( const G4Torus& torus )
873 #if defined DEBUG_FR_SCENE
874 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
875 G4cout << "***** AddSolid ( torus )\n";
877 //----- skip drawing invisible primitive
878 if( !IsVisible() ) { return ; }
880 //----- Initialize Fukui Renderer IF NECESSARY
890 if(!SendVisAttributes
891 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
892 SendStr( FR_COLOR_RGB_BLUE ); // color
896 const G4double r = torus.GetRmin() ;
897 const G4double R = torus.GetRmax() ;
898 const G4double t = torus.GetRtor() ;
899 const G4double sphi = torus.GetSPhi() ;
900 const G4double dphi = torus.GetDPhi() ;
902 //----- send coordinates to Fukui Renderer
903 SendTransformedCoordinates();
905 //----- send torus to Fukui Renderer
906 SendStrDouble5( FR_TORUS, r, R, t , sphi, dphi );
908 } // void G4FRSCENEHANDLER::AddSolid( const G4Torus& )
912 //----- Add a shape which is not treated above
913 void G4FRSCENEHANDLER::AddSolid ( const G4VSolid& solid )
915 //----- skip drawing invisible primitive
916 if( !IsVisible() ) { return ; }
918 //----- Initialize Fukui Renderer IF NECESSARY
927 //----- Send a primitive
928 G4VSceneHandler::AddSolid( solid ) ;
930 } //G4FRSCENEHANDLER::AddSolid ( const G4VSolid& )
935 G4FRSCENEHANDLER::SendVisAttributes ( const G4VisAttributes* pAV )
938 // Have a look at G4VSceneHandler::GetDrawingStyle (const G4Visible&). (John)
940 G4bool status = true ; // initialization
941 const G4double ALPHA_MIN = 0.001 ; // min of alpha factor of color
944 // No attribute is given.
945 // Do nothing. Status is "fail".
949 // Send attributes. Status is "success".
951 const G4Color& color = pAV->GetColor();
952 SendStrDouble3( FR_COLOR_RGB,
956 if ( color.GetAlpha() < ALPHA_MIN ) {
957 SendStr( FR_FORCE_WIREFRAME_ON ) ;
959 else if ( pAV->IsForceDrawingStyle () &&
960 (pAV->GetForcedDrawingStyle () == G4VisAttributes::wireframe)) {
961 SendStr( FR_FORCE_WIREFRAME_ON ) ;
963 SendStr( FR_FORCE_WIREFRAME_OFF ) ;
969 } // G4FRSCENEHANDLER::SendVisAttributes ()
973 G4bool G4FRSCENEHANDLER::IsVisible()
976 G4bool visibility = true ;
979 const G4VisAttributes* pVisAttribs =
980 fpViewer->GetApplicableVisAttributes( fpVisAttribs );
983 if( ( getenv( FR_ENV_CULL_INVISIBLE_OBJECTS ) != NULL ) && \
984 ( strcmp( getenv( FR_ENV_CULL_INVISIBLE_OBJECTS ),"0" ) ) && \
987 visibility = pVisAttribs->IsVisible();
993 } // G4FRSCENEHANDLER::IsVisible()
997 void G4FRSCENEHANDLER::SendBoundingBox( void )
999 #if defined DEBUG_FR_SCENE
1000 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1001 G4cout << "***** SendBoundingBox () (/BoundingBox)" << G4endl;
1004 //----- (1A) CALC bounding box of the bounding sphere
1005 const G4VisExtent& extent = GetScene()->GetExtent();
1006 const G4Point3D& center = extent.GetExtentCenter();
1007 const G4double radius = extent.GetExtentRadius();
1009 G4double xmin = center.x() - radius ;
1010 G4double ymin = center.y() - radius ;
1011 G4double zmin = center.z() - radius ;
1013 G4double xmax = center.x() + radius ;
1014 G4double ymax = center.y() + radius ;
1015 G4double zmax = center.z() + radius ;
1017 ////////////////////////////////////////////
1018 // G4double xmin = extent.GetXmin ();
1019 // G4double ymin = extent.GetYmin ();
1020 // G4double zmin = extent.GetZmin ();
1021 // G4double xmax = extent.GetXmax ();
1022 // G4double ymax = extent.GetYmax ();
1023 // G4double zmax = extent.GetZmax ();
1024 ////////////////////////////////////////////
1026 //----- (1B) SEND bounding box
1027 SendStrDouble6( FR_BOUNDING_BOX,
1031 } // G4FRSCENEHANDLER::SendBoundingBox()
1036 G4FRSCENEHANDLER::SendTransformedCoordinates()
1039 G4Point3D zero ( 0.0 , 0.0 , 0.0 );
1040 G4Point3D x1 ( 1.0 , 0.0 , 0.0 );
1041 G4Point3D y1 ( 0.0 , 1.0 , 0.0 );
1042 G4Vector3D x_unit_vec( 1.0 , 0.0 , 0.0 );
1043 G4Vector3D y_unit_vec( 0.0 , 1.0 , 0.0 );
1045 //----- transformed origin
1046 zero.transform( fObjectTransformation );
1048 //----- transformed base vectors
1049 x1.transform( fObjectTransformation );
1050 x_unit_vec = x1 - zero ;
1051 y1.transform( fObjectTransformation );
1052 y_unit_vec = y1 - zero ;
1054 //----- send transformed origin
1055 SendStrDouble3( FR_ORIGIN , (zero.x()), (zero.y()), (zero.z()) ) ;
1057 //----- send transformed base vectors
1058 SendStrDouble6( FR_BASE_VECTOR , \
1059 (x_unit_vec.x()), (x_unit_vec.y()), (x_unit_vec.z()) , \
1060 (y_unit_vec.x()), (y_unit_vec.y()), (y_unit_vec.z()) ) ;
1062 } // G4FRSCENEHANDLER::SendTransformedCoordinates()
1066 void G4FRSCENEHANDLER::SendPhysVolName ( void )
1072 const G4VModel* pv_model = GetModel();
1073 if (!pv_model) { return ; }
1075 G4PhysicalVolumeModel* pPVModel =
1076 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1077 if (!pPVModel) { return ; }
1079 // Current Physical volume name
1080 G4String pv_name = pPVModel->GetCurrentTag() ;
1082 // Current depth of volume
1083 G4int cur_depth = pPVModel->GetCurrentDepth() ;
1085 // Make a string to be sent
1086 // e.g. experimental_Hall.1, where "1" is the copy number
1087 G4String name_comment ( FR_PHYSICAL_VOLUME_NAME );
1088 name_comment += " " ;
1090 for ( i = 0 ; i < cur_depth; i++) {
1092 name_comment += " " ;
1094 name_comment += pv_name ;
1096 // Send physical volume name
1097 SendStr ( "#--------------------" );
1098 SendStr ( name_comment );
1100 } // G4FRSCENEHANDLER::SendPhysVolName ()
1104 void G4FRSCENEHANDLER::SendStr( const char* char_string )
1106 fPrimDest.SendLine( char_string );
1111 void G4FRSCENEHANDLER::SendStrInt( const char* char_string ,
1114 //----- make command char_string and send
1116 char* command = new char [ COMMAND_BUF_SIZE ];
1118 num_char = sprintf( command, "%s %d", char_string , ival ) ;
1119 if( num_char < 0 ) {
1120 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1121 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt(), 1\n" ;
1125 } // G4FRSCENEHANDLER::SendStrInt()
1130 G4FRSCENEHANDLER::SendStrInt3( const char* char_string ,
1135 //----- make command char_string and send
1137 char* command = new char [ COMMAND_BUF_SIZE ];
1140 sprintf( command, "%s %d %d %d", char_string , ival1, ival2, ival3 ) ;
1142 if( num_char < 0 ) {
1143 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1144 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt3(), 1\n" ;
1149 } // G4FRSCENEHANDLER::SendStrInt3()
1154 G4FRSCENEHANDLER::SendStrInt4( const char* char_string ,
1160 //----- make command char_string and send
1162 char* command = new char [ COMMAND_BUF_SIZE ];
1165 sprintf( command, "%s %d %d %d %d", char_string , ival1, ival2, ival3, ival4 ) ;
1167 if( num_char < 0 ) {
1168 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1169 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt4(), 1\n" ;
1174 } // G4FRSCENEHANDLER::SendStrInt4()
1177 void G4FRSCENEHANDLER::SendStrDouble( const char* char_string ,
1180 //----- make command char_string and send
1182 char* command = new char [ COMMAND_BUF_SIZE ];
1184 num_char = sprintf( command, "%s %*.*g", \
1186 fPrec2, fPrec, dval ) ;
1187 if( num_char < 0 ) {
1188 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1189 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble(), 1\n" ;
1194 } // G4FRSCENEHANDLER::SendStrDouble()
1199 G4FRSCENEHANDLER::SendStrDouble2( const char* char_string ,
1203 //----- make command char_string and send
1205 char* command = new char [ COMMAND_BUF_SIZE ];
1207 num_char = sprintf( command, "%s %*.*g %*.*g", char_string , \
1208 fPrec2, fPrec, dval1, \
1209 fPrec2, fPrec, dval2 ) ;
1210 if( num_char < 0 ) {
1211 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1212 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble2(), 1\n" ;
1217 } // G4FRSCENEHANDLER::SendStrDouble2()
1222 G4FRSCENEHANDLER::SendStrDouble3( const char* char_string ,
1227 //----- make command char_string and send
1229 char* command = new char [ COMMAND_BUF_SIZE ];
1231 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g", \
1233 fPrec2, fPrec, dval1, \
1234 fPrec2, fPrec, dval2, \
1235 fPrec2, fPrec, dval3 ) ;
1236 if( num_char < 0 ) {
1237 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1238 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble3(), 1\n" ;
1243 } // G4FRSCENEHANDLER::SendStrDouble3()
1248 G4FRSCENEHANDLER::SendStrDouble4( const char* char_string ,
1254 //----- make command char_string and send
1256 char* command = new char [ COMMAND_BUF_SIZE ];
1258 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g", \
1260 fPrec2, fPrec, dval1, \
1261 fPrec2, fPrec, dval2, \
1262 fPrec2, fPrec, dval3, \
1263 fPrec2, fPrec, dval4) ;
1264 if( num_char < 0 ) {
1265 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1266 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble4(), 1\n" ;
1271 } // G4FRSCENEHANDLER::SendStrDouble4()
1276 G4FRSCENEHANDLER::SendStrDouble5( const char* char_string ,
1283 //----- make command char_string and send
1285 char* command = new char [ COMMAND_BUF_SIZE ];
1287 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g", \
1289 fPrec2, fPrec, dval1, \
1290 fPrec2, fPrec, dval2, \
1291 fPrec2, fPrec, dval3, \
1292 fPrec2, fPrec, dval4, \
1293 fPrec2, fPrec, dval5 ) ;
1294 if( num_char < 0 ) {
1295 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1296 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble5(), 1\n" ;
1301 } // G4FRSCENEHANDLER::SendStrDouble5()
1306 G4FRSCENEHANDLER::SendStrDouble6( const char* char_string ,
1314 //----- make command char_string and send
1316 char* command = new char [ COMMAND_BUF_SIZE ];
1318 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g", \
1320 fPrec2, fPrec, dval1, \
1321 fPrec2, fPrec, dval2, \
1322 fPrec2, fPrec, dval3, \
1323 fPrec2, fPrec, dval4, \
1324 fPrec2, fPrec, dval5, \
1325 fPrec2, fPrec, dval6 ) ;
1326 if( num_char < 0 ) {
1327 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1328 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble6(), 1\n" ;
1333 } // G4FRSCENEHANDLER::SendStrDouble6()
1338 G4FRSCENEHANDLER::SendStrDouble7( const char* char_string ,
1347 //----- make command char_string and send
1349 char* command = new char [ COMMAND_BUF_SIZE ];
1351 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g", \
1353 fPrec2, fPrec, dval1,\
1354 fPrec2, fPrec, dval2,\
1355 fPrec2, fPrec, dval3,\
1356 fPrec2, fPrec, dval4,\
1357 fPrec2, fPrec, dval5,\
1358 fPrec2, fPrec, dval6,\
1359 fPrec2, fPrec, dval7 ) ;
1360 if( num_char < 0 ) {
1361 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1362 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble7(), 1\n" ;
1367 } // G4FRSCENEHANDLER::SendStrDouble7()
1372 G4FRSCENEHANDLER::SendStrDouble11( const char* char_string ,
1385 //----- make command char_string and send
1387 char* command = new char [ COMMAND_BUF_SIZE ];
1389 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g", \
1391 fPrec2, fPrec, dval1, \
1392 fPrec2, fPrec, dval2, \
1393 fPrec2, fPrec, dval3, \
1394 fPrec2, fPrec, dval4, \
1395 fPrec2, fPrec, dval5, \
1396 fPrec2, fPrec, dval6, \
1397 fPrec2, fPrec, dval7, \
1398 fPrec2, fPrec, dval8, \
1399 fPrec2, fPrec, dval9, \
1400 fPrec2, fPrec, dval10,\
1401 fPrec2, fPrec, dval11 ) ;
1402 if( num_char < 0 ) {
1403 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1404 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble11(), 1\n" ;
1409 } // G4FRSCENEHANDLER::SendStrDouble11()
1414 G4FRSCENEHANDLER::SendIntDouble3( G4int ival ,
1419 //----- make command char_string and send
1421 char* command = new char [ COMMAND_BUF_SIZE ];
1423 num_char = sprintf( command, "%d %*.*g %*.*g %*.*g", \
1425 fPrec2, fPrec, dval1, \
1426 fPrec2, fPrec, dval2, \
1427 fPrec2, fPrec, dval3 ) ;
1428 if( num_char < 0 ) {
1429 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1430 G4cout << "ERROR G4FRSCENEHANDLER::SendIntDouble3(),1\n" ;
1438 G4FRSCENEHANDLER::SendInt3Str( G4int ival1 ,
1441 const char* char_string )
1443 //----- make command char_string and send
1445 char* command = new char [ COMMAND_BUF_SIZE ];
1447 num_char = sprintf( command, "%d %d %d %s", \
1448 ival1, ival2, ival3, char_string ) ;
1449 if( num_char < 0 ) {
1450 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1451 G4cout << "ERROR G4FRSCENEHANDLER::SendInt3Str(),1\n" ;
1459 G4FRSCENEHANDLER::SendInt4Str( G4int ival1 ,
1463 const char* char_string )
1465 //----- make command char_string and send
1467 char* command = new char [ COMMAND_BUF_SIZE ];
1469 num_char = sprintf( command, "%d %d %d %d %s", \
1470 ival1, ival2, ival3, ival4, char_string ) ;
1471 if( num_char < 0 ) {
1472 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1473 G4cout << "ERROR G4FRSCENEHANDLER::SendInt4Str(),1\n" ;
1481 G4FRSCENEHANDLER::SendStrDouble3Str( const char* char_string1 ,
1485 const char* char_string2 )
1487 //----- make command char_string and send
1489 char* command = new char [ COMMAND_BUF_SIZE ];
1491 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %s", \
1493 fPrec2, fPrec, dval1 , \
1494 fPrec2, fPrec, dval2 , \
1495 fPrec2, fPrec, dval3 , \
1497 if( num_char < 0 ) {
1498 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1499 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble6Str(), 1\n" ;
1509 G4FRSCENEHANDLER::SendStrDouble6Str( const char* char_string1 ,
1516 const char* char_string2 )
1518 //----- make command char_string and send
1520 char* command = new char [ COMMAND_BUF_SIZE ];
1522 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %s", \
1524 fPrec2, fPrec, dval1 , \
1525 fPrec2, fPrec, dval2 , \
1526 fPrec2, fPrec, dval3 , \
1527 fPrec2, fPrec, dval4 , \
1528 fPrec2, fPrec, dval5 , \
1529 fPrec2, fPrec, dval6, \
1531 if( num_char < 0 ) {
1532 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1533 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble6Str(), 1\n" ;
1542 void G4FRSCENEHANDLER::SendInt( G4int val )
1544 //----- make command char_string and send
1546 char* command = new char [ COMMAND_BUF_SIZE ];
1548 num_char = sprintf( command, "%d", val ) ;
1549 if( num_char < 0 ) {
1550 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1551 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt(), 1\n" ;
1555 } // G4FRSCENEHANDLER::SendStrInt()
1559 void G4FRSCENEHANDLER::SendDouble( G4double val )
1561 //----- make command char_string and send
1563 char* command = new char [ COMMAND_BUF_SIZE ];
1565 num_char = sprintf( command, "%*.*g", fPrec2, fPrec, val ) ;
1566 if( num_char < 0 ) {
1567 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1568 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt(), 1\n" ;
1572 } // G4FRSCENEHANDLER::SendStrInt()
1575 void G4FRSCENEHANDLER::ClearTransientStore()
1577 // This is typically called after an update and before drawing hits
1578 // of the next event. To simulate the clearing of "transients"
1579 // (hits, etc.) the detector is redrawn...
1581 fpViewer -> SetView ();
1582 fpViewer -> ClearView ();
1583 fpViewer -> DrawView ();