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 77479 2013-11-25 10:01:22Z 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 const G4Color& color = GetColor (mark_circle) ;
205 SendStrDouble3( FR_COLOR_RGB ,
210 //----- send body coordinates
211 SendTransformedCoordinates();
213 //----- Calc position
214 const G4Point3D& position = mark_circle.GetPosition () ;
217 MarkerSizeType size_type;
218 G4double size = GetMarkerRadius( mark_circle , size_type );
223 SendStrDouble4( FR_MARK_CIRCLE_2D, \
224 position.x() , position.y() , position.z(), size );
228 SendStrDouble4( FR_MARK_CIRCLE_2DS, \
229 position.x() , position.y() , position.z(), size );
233 } // G4FRSCENEHANDLER::AddPrimitive ( mark_circle )
237 void G4FRSCENEHANDLER::AddPrimitive (const G4Square& mark_square )
240 #if defined DEBUG_FR_SCENE
241 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
242 G4cout << "***** AddPrimitive( G4Square )\n";
245 static G4bool warned = false;
249 ("G4FRSCENEHANDLER::AddPrimitive (const G4Square&)",
250 "dawn0003", JustWarning,
251 "2D squares not implemented. Ignored.");
255 //----- Initialize Fukui Renderer IF NECESSARY
259 const G4Color& color = GetColor (mark_square) ;
260 SendStrDouble3( FR_COLOR_RGB ,
265 //----- send body coordinates
266 SendTransformedCoordinates();
268 //----- Calc position
269 const G4Point3D& position = mark_square.GetPosition () ;
272 MarkerSizeType size_type;
273 G4double size = GetMarkerRadius( mark_square , size_type );
278 SendStrDouble4( FR_MARK_SQUARE_2D, \
279 position.x() , position.y() , position.z(), size );
283 SendStrDouble4( FR_MARK_SQUARE_2DS, \
284 position.x() , position.y() , position.z(), size );
288 } // G4FRSCENEHANDLER::AddPrimitive ( mark_square )
291 //----- Add polyhedron
292 void G4FRSCENEHANDLER::AddPrimitive ( const G4Polyhedron& polyhedron )
295 #if defined DEBUG_FR_SCENE
296 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
297 G4cout << "***** AddPrimitive( G4Polyhedron )\n";
300 static G4bool warned = false;
304 ("G4FRSCENEHANDLER::AddPrimitive (const G4Polyhedron&)",
305 "dawn0004", JustWarning,
306 "2D polyhedrons not implemented. Ignored.");
311 if (polyhedron.GetNoFacets() == 0) return;
313 //----- Initialize Fukui Renderer IF NECESSARY
317 if(!SendVisAttributes( fpViewer->GetApplicableVisAttributes
318 (polyhedron.GetVisAttributes() ) ) ) {
319 SendStr( FR_COLOR_RGB_RED ); // color
323 SendTransformedCoordinates();
327 //---------- (1) Declare beginning of Brep data
328 SendStr(FR_POLYHEDRON);
330 //---------- (2) Vertex block
331 for (G4int i = 1, j = polyhedron.GetNoVertices(); j; j--, i++){
332 G4Point3D point = polyhedron.GetVertex(i);
333 SendStrDouble3( FR_VERTEX, point.x (), point.y (), point.z ());
336 //---------- (3) Facet block
337 for (G4int f = polyhedron.GetNoFacets(); f; f--){
339 G4int index = -1; // initialization
341 //G4int preedgeFlag = 1; Not used - comment out to prevent warnings (JA).
342 G4int work[4], i = 0;
344 //preedgeFlag = edgeFlag; Not used - comment out to prevent warnings (JA).
345 notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
347 }while (notLastEdge);
350 SendStrInt3(FR_FACET, work[0], work[1], work[2] );
353 SendStrInt4(FR_FACET, work[0], work[1], work[2], work[3] );
356 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
358 "ERROR G4FRSCENEHANDLER::AddPrimitive(G4Polyhedron)\n";
359 G4PhysicalVolumeModel* pPVModel =
360 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
362 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
364 "Volume " << pPVModel->GetCurrentPV()->GetName() <<
365 ", Solid " << pPVModel->GetCurrentLV()->GetSolid()->GetName() <<
366 " (" << pPVModel->GetCurrentLV()->GetSolid()->GetEntityType();
368 "\nG4Polyhedron facet with " << i << " edges" << G4endl;
373 //---------- (4) Declare ending of Brep data
374 SendStr(FR_END_POLYHEDRON);
376 } // G4FRSCENEHANDLER::AddPrimitive (polyhedron)
380 void G4FRSCENEHANDLER::SendNdiv ( void )
382 //////////////////////////////////////////////////
383 //#if defined DEBUG_FR_SCENE
384 // G4cout << "***** SendNdiv() (/Ndiv)" << G4endl;
386 //////////////////////////////////////////////////
389 G4int num_division = FR_DEFALUT_NDIV_VALUE ;
391 //----- number used for dividing a curved surface, Ndiv
392 // if ( GetModel() ) { ?? Why test for model. Can be zero. JA ??
393 const G4VisAttributes* pVisAttribs =
394 fpViewer -> GetApplicableVisAttributes (fpVisAttribs);
395 num_division = GetNoOfSides(pVisAttribs);
397 #if defined DEBUG_FR_SCENE
398 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
399 G4cout << "WARNING: GetNoOfSides() failed. " ;
400 G4cout << "The default value " << num_division ;
401 G4cout << " is assigned." << G4endl;
406 //---------- Error recovery for too small Ndiv
407 num_division = ( num_division < 3 ? 3 : num_division );
409 //////////////////////////////////////////////////
410 //#if defined DEBUG_FR_SCENE
411 // G4cout << "Ndiv = " << num_division << G4endl;
413 //////////////////////////////////////////////////
415 //----- Send resultant Ndiv
416 this->SendStrInt( FR_NDIV, num_division );
422 void G4FRSCENEHANDLER::FREndModeling ()
425 #if defined DEBUG_FR_SCENE
426 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
427 G4cout << "***** FREndModeling (called)" << G4endl;
429 if( FRIsInModeling() ) {
431 #if defined DEBUG_FR_SCENE
432 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
433 G4cout << "***** FREndModeling (started) " ;
434 G4cout << "(/EndModeling, /DrawAll, /CloseDevice)" << G4endl;
438 SendStr( "#--------------------" );
441 SendStr( FR_END_MODELING );
444 SendStr( FR_DRAW_ALL );
447 SendStr( FR_CLOSE_DEVICE );
449 //----- End saving data to g4.prim
453 FRflag_in_modeling = false ;
459 void G4FRSCENEHANDLER::BeginPrimitives (const G4Transform3D& objectTransformation)
461 #if defined DEBUG_FR_SCENE
462 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
463 G4cout << "***** BeginPrimitives \n";
468 G4VSceneHandler::BeginPrimitives (objectTransformation);
473 void G4FRSCENEHANDLER::EndPrimitives ()
475 #if defined DEBUG_FR_SCENE
476 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
477 G4cout << "***** EndPrimitives \n";
479 G4VSceneHandler::EndPrimitives ();
483 //========== AddSolid() functions ==========//
486 void G4FRSCENEHANDLER::AddSolid( const G4Box& box )
488 #if defined DEBUG_FR_SCENE
489 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
490 G4cout << "***** AddSolid ( box )\n";
492 //----- skip drawing invisible primitive
493 if( !IsVisible() ) { return ; }
495 //----- Initialize Fukui Renderer IF NECESSARY
505 if(!SendVisAttributes
506 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
507 SendStr( FR_COLOR_RGB_GREEN ); // color
510 //----- parameters (half lengths of box)
511 G4double dx = box.GetXHalfLength ();
512 G4double dy = box.GetYHalfLength ();
513 G4double dz = box.GetZHalfLength ();
515 //----- send coordinates to Fukui Renderer
516 SendTransformedCoordinates();
518 //----- send box to Fukui Renderer
519 SendStrDouble3( FR_BOX, dx, dy, dz );
521 } // void G4FRSCENEHANDLER::AddSolid( const G4Box& box )
526 G4FRSCENEHANDLER::AddSolid( const G4Tubs& tubes )
528 #if defined DEBUG_FR_SCENE
529 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
530 G4cout << "***** AddSolid ( tubes )\n";
532 //----- skip drawing invisible primitive
533 if( !IsVisible() ) { return ; }
535 //----- Initialize Fukui Renderer IF NECESSARY
545 if(!SendVisAttributes
546 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
547 SendStr( FR_COLOR_RGB_BLUE ); // color
551 const G4double R = tubes.GetOuterRadius() ; // outside radius
552 const G4double r = tubes.GetInnerRadius() ; // inside radius
553 const G4double dz = tubes.GetZHalfLength() ; // half length in z
554 const G4double sphi = tubes.GetStartPhiAngle() ; // starting angle
555 const G4double dphi = tubes.GetDeltaPhiAngle() ; // angle width
557 //----- send coordinates to Fukui Renderer
558 SendTransformedCoordinates();
560 //----- send tubes to Fukui Renderer
561 SendStrDouble5( FR_TUBS, r, R, dz , sphi, dphi );
563 } // void G4FRSCENEHANDLER::AddSolid( const G4Tubs& )
569 G4FRSCENEHANDLER::AddSolid( const G4Cons& cons )
571 #if defined DEBUG_FR_SCENE
572 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
573 G4cout << "***** AddSolid ( cons )\n";
575 //----- skip drawing invisible primitive
576 if( !IsVisible() ) { return ; }
578 //----- Initialize Fukui Renderer IF NECESSARY
588 if(!SendVisAttributes
589 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
590 SendStr( FR_COLOR_RGB_CYAN ); // color
594 const G4double r1 = cons.GetInnerRadiusMinusZ() ; // inside radius at -dz
595 const G4double R1 = cons.GetOuterRadiusMinusZ() ; // outside radius at -dz
596 const G4double r2 = cons.GetInnerRadiusPlusZ() ; // inside radius at +dz
597 const G4double R2 = cons.GetOuterRadiusPlusZ() ; // outside radius at +dz
598 const G4double dz = cons.GetZHalfLength () ; // half length in z
599 const G4double sphi = cons.GetStartPhiAngle() ; // starting angle
600 const G4double dphi = cons.GetDeltaPhiAngle() ; // angle width
602 //----- send coordinates to Fukui Renderer
603 SendTransformedCoordinates();
605 //----- send cons to Fukui Renderer
606 SendStrDouble7( FR_CONS, r1, R1, r2, R2, dz , sphi, dphi );
608 }// G4FRSCENEHANDLER::AddSolid( cons )
612 void G4FRSCENEHANDLER::AddSolid ( const G4Trd& trd )
614 #if defined DEBUG_FR_SCENE
615 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
616 G4cout << "***** AddSolid ( trd )\n";
619 //----- skip drawing invisible primitive
620 if( !IsVisible() ) { return ; }
622 //----- Initialize Fukui Renderer IF NECESSARY
632 if(!SendVisAttributes
633 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
634 SendStr( FR_COLOR_RGB_MAGENTA ); // color
638 G4double dx1 = trd.GetXHalfLength1 ();
639 G4double dx2 = trd.GetXHalfLength2 ();
640 G4double dy1 = trd.GetYHalfLength1 ();
641 G4double dy2 = trd.GetYHalfLength2 ();
642 G4double dz = trd.GetZHalfLength ();
644 //----- send coordinates to Fukui Renderer
645 SendTransformedCoordinates();
647 //----- send trd to Fukui Renderer
648 SendStrDouble5( FR_TRD, dx1, dx2, dy1, dy2, dz );
650 } // G4FRSCENEHANDLER::AddSolid ( trd )
654 void G4FRSCENEHANDLER::AddSolid ( const G4Sphere& sphere )
656 #if defined DEBUG_FR_SCENE
657 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
658 G4cout << "***** AddSolid ( sphere )\n";
660 //----- skip drawing invisible primitive
661 if( !IsVisible() ) { return ; }
663 //----- Initialize Fukui Renderer IF NECESSARY
673 if(!SendVisAttributes
674 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
675 SendStr( FR_COLOR_RGB_YELLOW ); // color
679 // const G4double rmin = sphere.GetInnerRadius();
680 const G4double rmax = sphere.GetOuterRadius();
681 // const G4double sphi = sphere.GetStartPhiAngle();
682 const G4double dphi = sphere.GetDeltaPhiAngle();
683 // const G4double stheta = sphere.GetStartThetaAngle();
684 const G4double dtheta = sphere.GetDeltaThetaAngle();
686 //----- send coordinates to Fukui Renderer
687 SendTransformedCoordinates();
689 //----- send sphere to Fukui Renderer
690 const G4double PI_minus = 0.9999 * CLHEP::pi ;
691 const G4double PI2_minus = 1.9999 * CLHEP::pi ;
692 if( dphi > PI2_minus && dtheta > PI_minus ) {
694 SendStrDouble ( FR_SPHERE, rmax );
697 //----- call AddPrimitives( G4Polyhedron )
698 //...... For sphere "segment",
699 //...... G4Polyhedron is used for visualization.
700 //...... Visualization attributes and
701 //...... local coordinates are resent and overwritten.
702 G4VSceneHandler::AddSolid( sphere ) ;
704 ////////////////////////////////////////////////////////////////
705 // //----- sphere segment
706 // SendStrDouble6( FR_SPHERE_SEG, rmin, rmax, stheta, dtheta, sphi, dphi );
707 ////////////////////////////////////////////////////////////////
711 } // G4FRSCENEHANDLER::AddSolid ( sphere )
715 void G4FRSCENEHANDLER::AddSolid (const G4Para& para)
717 #if defined DEBUG_FR_SCENE
718 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
719 G4cout << "***** AddSolid ( para )\n";
722 //----- skip drawing invisible primitive
723 if( !IsVisible() ) { return ; }
725 //----- Initialize Fukui Renderer IF NECESSARY
735 if(!SendVisAttributes
736 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
737 SendStr( FR_COLOR_RGB_RED ); // color
741 const G4double epsilon = 1.0e-5 ;
743 //----- parameters preprocessing
744 G4double cosTheta = para.GetSymAxis().z() ;
745 if( cosTheta < epsilon ) {
746 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
747 G4cout << "WARNING from FukuiRenderer (DAWN) driver:" << G4endl;
748 G4cout << " Invalid parameter for parallelepiped." << G4endl;
749 G4cout << " Drawing is skipped." << G4endl;
753 G4double tanTheta_cosPhi_cosTheta = para.GetSymAxis().x() ;
754 G4double tanTheta_sinPhi_cosTheta = para.GetSymAxis().y() ;
757 G4double dx = para.GetXHalfLength ();
758 G4double dy = para.GetYHalfLength ();
759 G4double dz = para.GetZHalfLength ();
760 G4double tanAlpha = para.GetTanAlpha();
761 G4double tanTheta_cosPhi = tanTheta_cosPhi_cosTheta / cosTheta ;
762 G4double tanTheta_sinPhi = tanTheta_sinPhi_cosTheta / cosTheta ;
764 //----- send coordinates to Fukui Renderer
765 SendTransformedCoordinates();
767 //----- send data to Fukui Renderer
768 SendStrDouble6 ( FR_PARA, dx, dy, dz, tanAlpha, tanTheta_cosPhi, tanTheta_sinPhi );
770 } // G4FRSCENEHANDLER::AddSolid ( para )
774 void G4FRSCENEHANDLER::AddSolid (const G4Trap& trap)
776 #if defined DEBUG_FR_SCENE
777 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
778 G4cout << "***** AddSolid ( trap )\n";
781 //----- skip drawing invisible primitive
782 if( !IsVisible() ) { return ; }
784 //----- Initialize Fukui Renderer IF NECESSARY
794 if(!SendVisAttributes
795 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
796 SendStr( FR_COLOR_RGB_GREEN ); // color
800 const G4double epsilon = 1.0e-5 ;
802 //----- parameters preprocessing
803 G4double cosTheta = trap.GetSymAxis().z() ;
804 if( cosTheta < epsilon ) {
805 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
806 G4cout << "WARNING from FukuiRenderer (DAWN) driver:" << G4endl;
807 G4cout << " Invalid parameter for trap, 1" << G4endl;
808 G4cout << " Drawing is skipped." << G4endl;
813 G4double nx = trap.GetSymAxis().x() ;
814 G4double ny = trap.GetSymAxis().y() ;
816 //----- parameters (half lengths of box)
817 G4double dz = trap.GetZHalfLength ();
818 G4double theta = std::acos( cosTheta ) ;
820 if ( ny==0. && nx ==0.) {
821 phi = 0.; // std::atan2(0.,0.) gives undefined value of phi
823 phi = std::atan2( ny, nx ) ; if( phi < 0. ) { phi += CLHEP::twopi ; }
824 // -PI < std::atan() < PI
826 /////////////////////////////////////////////////
827 // G4double phi = std::atan2( ny, nx ) ;
828 // if( phi < 0.0 ) { phi += CLHEP::twopi ; }
829 // // -PI < std::atan() < PI
830 /////////////////////////////////////////////////
832 G4double h1 = trap.GetYHalfLength1 ();
833 G4double bl1 = trap.GetXHalfLength1 ();
834 G4double tl1 = trap.GetXHalfLength2 ();
835 G4double alpha1 = std::atan( trap.GetTanAlpha1()) ;
836 G4double h2 = trap.GetYHalfLength2 ();
837 G4double bl2 = trap.GetXHalfLength3 ();
838 G4double tl2 = trap.GetXHalfLength4 ();
839 G4double alpha2 = std::atan( trap.GetTanAlpha2()) ;
841 //----- send coordinates to Fukui Renderer
842 SendTransformedCoordinates();
844 //----- Change sign of alpha for compatibility
845 // with the DAWN format
846 G4double alpha_sign = -1.0 ;
847 alpha1 *= alpha_sign ; alpha2 *= alpha_sign ;
849 //----- send box to Fukui Renderer
850 SendStrDouble11( FR_TRAP ,
863 } // G4FRSCENEHANDLER::AddSolid (const G4Trap& trap)
868 G4FRSCENEHANDLER::AddSolid( const G4Torus& torus )
870 #if defined DEBUG_FR_SCENE
871 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
872 G4cout << "***** AddSolid ( torus )\n";
874 //----- skip drawing invisible primitive
875 if( !IsVisible() ) { return ; }
877 //----- Initialize Fukui Renderer IF NECESSARY
887 if(!SendVisAttributes
888 ( fpViewer->GetApplicableVisAttributes( fpVisAttribs ) ) ) {
889 SendStr( FR_COLOR_RGB_BLUE ); // color
893 const G4double r = torus.GetRmin() ;
894 const G4double R = torus.GetRmax() ;
895 const G4double t = torus.GetRtor() ;
896 const G4double sphi = torus.GetSPhi() ;
897 const G4double dphi = torus.GetDPhi() ;
899 //----- send coordinates to Fukui Renderer
900 SendTransformedCoordinates();
902 //----- send torus to Fukui Renderer
903 SendStrDouble5( FR_TORUS, r, R, t , sphi, dphi );
905 } // void G4FRSCENEHANDLER::AddSolid( const G4Torus& )
909 //----- Add a shape which is not treated above
910 void G4FRSCENEHANDLER::AddSolid ( const G4VSolid& solid )
912 //----- skip drawing invisible primitive
913 if( !IsVisible() ) { return ; }
915 //----- Initialize Fukui Renderer IF NECESSARY
924 //----- Send a primitive
925 G4VSceneHandler::AddSolid( solid ) ;
927 } //G4FRSCENEHANDLER::AddSolid ( const G4VSolid& )
932 G4FRSCENEHANDLER::SendVisAttributes ( const G4VisAttributes* pAV )
935 // Have a look at G4VSceneHandler::GetDrawingStyle (const G4Visible&). (John)
937 G4bool status = true ; // initialization
938 const G4double ALPHA_MIN = 0.001 ; // min of alpha factor of color
941 // No attribute is given.
942 // Do nothing. Status is "fail".
946 // Send attributes. Status is "success".
948 const G4Color& color = pAV->GetColor();
949 SendStrDouble3( FR_COLOR_RGB,
953 if ( color.GetAlpha() < ALPHA_MIN ) {
954 SendStr( FR_FORCE_WIREFRAME_ON ) ;
956 else if ( pAV->IsForceDrawingStyle () &&
957 (pAV->GetForcedDrawingStyle () == G4VisAttributes::wireframe)) {
958 SendStr( FR_FORCE_WIREFRAME_ON ) ;
960 SendStr( FR_FORCE_WIREFRAME_OFF ) ;
966 } // G4FRSCENEHANDLER::SendVisAttributes ()
970 G4bool G4FRSCENEHANDLER::IsVisible()
973 G4bool visibility = true ;
976 const G4VisAttributes* pVisAttribs =
977 fpViewer->GetApplicableVisAttributes( fpVisAttribs );
980 if( ( getenv( FR_ENV_CULL_INVISIBLE_OBJECTS ) != NULL ) && \
981 ( strcmp( getenv( FR_ENV_CULL_INVISIBLE_OBJECTS ),"0" ) ) && \
984 visibility = pVisAttribs->IsVisible();
990 } // G4FRSCENEHANDLER::IsVisible()
994 void G4FRSCENEHANDLER::SendBoundingBox( void )
996 #if defined DEBUG_FR_SCENE
997 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
998 G4cout << "***** SendBoundingBox () (/BoundingBox)" << G4endl;
1001 //----- (1A) CALC bounding box of the bounding sphere
1002 const G4VisExtent& extent = GetScene()->GetExtent();
1003 const G4Point3D& center = extent.GetExtentCenter();
1004 const G4double radius = extent.GetExtentRadius();
1006 G4double xmin = center.x() - radius ;
1007 G4double ymin = center.y() - radius ;
1008 G4double zmin = center.z() - radius ;
1010 G4double xmax = center.x() + radius ;
1011 G4double ymax = center.y() + radius ;
1012 G4double zmax = center.z() + radius ;
1014 ////////////////////////////////////////////
1015 // G4double xmin = extent.GetXmin ();
1016 // G4double ymin = extent.GetYmin ();
1017 // G4double zmin = extent.GetZmin ();
1018 // G4double xmax = extent.GetXmax ();
1019 // G4double ymax = extent.GetYmax ();
1020 // G4double zmax = extent.GetZmax ();
1021 ////////////////////////////////////////////
1023 //----- (1B) SEND bounding box
1024 SendStrDouble6( FR_BOUNDING_BOX,
1028 } // G4FRSCENEHANDLER::SendBoundingBox()
1033 G4FRSCENEHANDLER::SendTransformedCoordinates()
1036 G4Point3D zero ( 0.0 , 0.0 , 0.0 );
1037 G4Point3D x1 ( 1.0 , 0.0 , 0.0 );
1038 G4Point3D y1 ( 0.0 , 1.0 , 0.0 );
1039 G4Vector3D x_unit_vec( 1.0 , 0.0 , 0.0 );
1040 G4Vector3D y_unit_vec( 0.0 , 1.0 , 0.0 );
1042 //----- transformed origin
1043 zero.transform( fObjectTransformation );
1045 //----- transformed base vectors
1046 x1.transform( fObjectTransformation );
1047 x_unit_vec = x1 - zero ;
1048 y1.transform( fObjectTransformation );
1049 y_unit_vec = y1 - zero ;
1051 //----- send transformed origin
1052 SendStrDouble3( FR_ORIGIN , (zero.x()), (zero.y()), (zero.z()) ) ;
1054 //----- send transformed base vectors
1055 SendStrDouble6( FR_BASE_VECTOR , \
1056 (x_unit_vec.x()), (x_unit_vec.y()), (x_unit_vec.z()) , \
1057 (y_unit_vec.x()), (y_unit_vec.y()), (y_unit_vec.z()) ) ;
1059 } // G4FRSCENEHANDLER::SendTransformedCoordinates()
1063 void G4FRSCENEHANDLER::SendPhysVolName ( void )
1069 const G4VModel* pv_model = GetModel();
1070 if (!pv_model) { return ; }
1072 G4PhysicalVolumeModel* pPVModel =
1073 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1074 if (!pPVModel) { return ; }
1076 // Current Physical volume name
1077 G4String pv_name = pPVModel->GetCurrentTag() ;
1079 // Current depth of volume
1080 G4int cur_depth = pPVModel->GetCurrentDepth() ;
1082 // Make a string to be sent
1083 // e.g. experimental_Hall.1, where "1" is the copy number
1084 G4String name_comment ( FR_PHYSICAL_VOLUME_NAME );
1085 name_comment += " " ;
1087 for ( i = 0 ; i < cur_depth; i++) {
1089 name_comment += " " ;
1091 name_comment += pv_name ;
1093 // Send physical volume name
1094 SendStr ( "#--------------------" );
1095 SendStr ( name_comment );
1097 } // G4FRSCENEHANDLER::SendPhysVolName ()
1101 void G4FRSCENEHANDLER::SendStr( const char* char_string )
1103 fPrimDest.SendLine( char_string );
1108 void G4FRSCENEHANDLER::SendStrInt( const char* char_string ,
1111 //----- make command char_string and send
1113 char* command = new char [ COMMAND_BUF_SIZE ];
1115 num_char = sprintf( command, "%s %d", char_string , ival ) ;
1116 if( num_char < 0 ) {
1117 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1118 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt(), 1\n" ;
1122 } // G4FRSCENEHANDLER::SendStrInt()
1127 G4FRSCENEHANDLER::SendStrInt3( const char* char_string ,
1132 //----- make command char_string and send
1134 char* command = new char [ COMMAND_BUF_SIZE ];
1137 sprintf( command, "%s %d %d %d", char_string , ival1, ival2, ival3 ) ;
1139 if( num_char < 0 ) {
1140 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1141 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt3(), 1\n" ;
1146 } // G4FRSCENEHANDLER::SendStrInt3()
1151 G4FRSCENEHANDLER::SendStrInt4( const char* char_string ,
1157 //----- make command char_string and send
1159 char* command = new char [ COMMAND_BUF_SIZE ];
1162 sprintf( command, "%s %d %d %d %d", char_string , ival1, ival2, ival3, ival4 ) ;
1164 if( num_char < 0 ) {
1165 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1166 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt4(), 1\n" ;
1171 } // G4FRSCENEHANDLER::SendStrInt4()
1174 void G4FRSCENEHANDLER::SendStrDouble( const char* char_string ,
1177 //----- make command char_string and send
1179 char* command = new char [ COMMAND_BUF_SIZE ];
1181 num_char = sprintf( command, "%s %*.*g", \
1183 fPrec2, fPrec, dval ) ;
1184 if( num_char < 0 ) {
1185 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1186 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble(), 1\n" ;
1191 } // G4FRSCENEHANDLER::SendStrDouble()
1196 G4FRSCENEHANDLER::SendStrDouble2( const char* char_string ,
1200 //----- make command char_string and send
1202 char* command = new char [ COMMAND_BUF_SIZE ];
1204 num_char = sprintf( command, "%s %*.*g %*.*g", char_string , \
1205 fPrec2, fPrec, dval1, \
1206 fPrec2, fPrec, dval2 ) ;
1207 if( num_char < 0 ) {
1208 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1209 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble2(), 1\n" ;
1214 } // G4FRSCENEHANDLER::SendStrDouble2()
1219 G4FRSCENEHANDLER::SendStrDouble3( const char* char_string ,
1224 //----- make command char_string and send
1226 char* command = new char [ COMMAND_BUF_SIZE ];
1228 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g", \
1230 fPrec2, fPrec, dval1, \
1231 fPrec2, fPrec, dval2, \
1232 fPrec2, fPrec, dval3 ) ;
1233 if( num_char < 0 ) {
1234 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1235 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble3(), 1\n" ;
1240 } // G4FRSCENEHANDLER::SendStrDouble3()
1245 G4FRSCENEHANDLER::SendStrDouble4( const char* char_string ,
1251 //----- make command char_string and send
1253 char* command = new char [ COMMAND_BUF_SIZE ];
1255 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g", \
1257 fPrec2, fPrec, dval1, \
1258 fPrec2, fPrec, dval2, \
1259 fPrec2, fPrec, dval3, \
1260 fPrec2, fPrec, dval4) ;
1261 if( num_char < 0 ) {
1262 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1263 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble4(), 1\n" ;
1268 } // G4FRSCENEHANDLER::SendStrDouble4()
1273 G4FRSCENEHANDLER::SendStrDouble5( const char* char_string ,
1280 //----- make command char_string and send
1282 char* command = new char [ COMMAND_BUF_SIZE ];
1284 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g", \
1286 fPrec2, fPrec, dval1, \
1287 fPrec2, fPrec, dval2, \
1288 fPrec2, fPrec, dval3, \
1289 fPrec2, fPrec, dval4, \
1290 fPrec2, fPrec, dval5 ) ;
1291 if( num_char < 0 ) {
1292 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1293 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble5(), 1\n" ;
1298 } // G4FRSCENEHANDLER::SendStrDouble5()
1303 G4FRSCENEHANDLER::SendStrDouble6( const char* char_string ,
1311 //----- make command char_string and send
1313 char* command = new char [ COMMAND_BUF_SIZE ];
1315 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g", \
1317 fPrec2, fPrec, dval1, \
1318 fPrec2, fPrec, dval2, \
1319 fPrec2, fPrec, dval3, \
1320 fPrec2, fPrec, dval4, \
1321 fPrec2, fPrec, dval5, \
1322 fPrec2, fPrec, dval6 ) ;
1323 if( num_char < 0 ) {
1324 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1325 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble6(), 1\n" ;
1330 } // G4FRSCENEHANDLER::SendStrDouble6()
1335 G4FRSCENEHANDLER::SendStrDouble7( const char* char_string ,
1344 //----- make command char_string and send
1346 char* command = new char [ COMMAND_BUF_SIZE ];
1348 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g", \
1350 fPrec2, fPrec, dval1,\
1351 fPrec2, fPrec, dval2,\
1352 fPrec2, fPrec, dval3,\
1353 fPrec2, fPrec, dval4,\
1354 fPrec2, fPrec, dval5,\
1355 fPrec2, fPrec, dval6,\
1356 fPrec2, fPrec, dval7 ) ;
1357 if( num_char < 0 ) {
1358 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1359 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble7(), 1\n" ;
1364 } // G4FRSCENEHANDLER::SendStrDouble7()
1369 G4FRSCENEHANDLER::SendStrDouble11( const char* char_string ,
1382 //----- make command char_string and send
1384 char* command = new char [ COMMAND_BUF_SIZE ];
1386 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g", \
1388 fPrec2, fPrec, dval1, \
1389 fPrec2, fPrec, dval2, \
1390 fPrec2, fPrec, dval3, \
1391 fPrec2, fPrec, dval4, \
1392 fPrec2, fPrec, dval5, \
1393 fPrec2, fPrec, dval6, \
1394 fPrec2, fPrec, dval7, \
1395 fPrec2, fPrec, dval8, \
1396 fPrec2, fPrec, dval9, \
1397 fPrec2, fPrec, dval10,\
1398 fPrec2, fPrec, dval11 ) ;
1399 if( num_char < 0 ) {
1400 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1401 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble11(), 1\n" ;
1406 } // G4FRSCENEHANDLER::SendStrDouble11()
1411 G4FRSCENEHANDLER::SendIntDouble3( G4int ival ,
1416 //----- make command char_string and send
1418 char* command = new char [ COMMAND_BUF_SIZE ];
1420 num_char = sprintf( command, "%d %*.*g %*.*g %*.*g", \
1422 fPrec2, fPrec, dval1, \
1423 fPrec2, fPrec, dval2, \
1424 fPrec2, fPrec, dval3 ) ;
1425 if( num_char < 0 ) {
1426 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1427 G4cout << "ERROR G4FRSCENEHANDLER::SendIntDouble3(),1\n" ;
1435 G4FRSCENEHANDLER::SendInt3Str( G4int ival1 ,
1438 const char* char_string )
1440 //----- make command char_string and send
1442 char* command = new char [ COMMAND_BUF_SIZE ];
1444 num_char = sprintf( command, "%d %d %d %s", \
1445 ival1, ival2, ival3, char_string ) ;
1446 if( num_char < 0 ) {
1447 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1448 G4cout << "ERROR G4FRSCENEHANDLER::SendInt3Str(),1\n" ;
1456 G4FRSCENEHANDLER::SendInt4Str( G4int ival1 ,
1460 const char* char_string )
1462 //----- make command char_string and send
1464 char* command = new char [ COMMAND_BUF_SIZE ];
1466 num_char = sprintf( command, "%d %d %d %d %s", \
1467 ival1, ival2, ival3, ival4, char_string ) ;
1468 if( num_char < 0 ) {
1469 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1470 G4cout << "ERROR G4FRSCENEHANDLER::SendInt4Str(),1\n" ;
1478 G4FRSCENEHANDLER::SendStrDouble3Str( const char* char_string1 ,
1482 const char* char_string2 )
1484 //----- make command char_string and send
1486 char* command = new char [ COMMAND_BUF_SIZE ];
1488 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %s", \
1490 fPrec2, fPrec, dval1 , \
1491 fPrec2, fPrec, dval2 , \
1492 fPrec2, fPrec, dval3 , \
1494 if( num_char < 0 ) {
1495 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1496 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble6Str(), 1\n" ;
1506 G4FRSCENEHANDLER::SendStrDouble6Str( const char* char_string1 ,
1513 const char* char_string2 )
1515 //----- make command char_string and send
1517 char* command = new char [ COMMAND_BUF_SIZE ];
1519 num_char = sprintf( command, "%s %*.*g %*.*g %*.*g %*.*g %*.*g %*.*g %s", \
1521 fPrec2, fPrec, dval1 , \
1522 fPrec2, fPrec, dval2 , \
1523 fPrec2, fPrec, dval3 , \
1524 fPrec2, fPrec, dval4 , \
1525 fPrec2, fPrec, dval5 , \
1526 fPrec2, fPrec, dval6, \
1528 if( num_char < 0 ) {
1529 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1530 G4cout << "ERROR G4FRSCENEHANDLER::SendStrDouble6Str(), 1\n" ;
1539 void G4FRSCENEHANDLER::SendInt( G4int val )
1541 //----- make command char_string and send
1543 char* command = new char [ COMMAND_BUF_SIZE ];
1545 num_char = sprintf( command, "%d", val ) ;
1546 if( num_char < 0 ) {
1547 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1548 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt(), 1\n" ;
1552 } // G4FRSCENEHANDLER::SendStrInt()
1556 void G4FRSCENEHANDLER::SendDouble( G4double val )
1558 //----- make command char_string and send
1560 char* command = new char [ COMMAND_BUF_SIZE ];
1562 num_char = sprintf( command, "%*.*g", fPrec2, fPrec, val ) ;
1563 if( num_char < 0 ) {
1564 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
1565 G4cout << "ERROR G4FRSCENEHANDLER::SendStrInt(), 1\n" ;
1569 } // G4FRSCENEHANDLER::SendStrInt()
1572 void G4FRSCENEHANDLER::ClearTransientStore()
1574 // This is typically called after an update and before drawing hits
1575 // of the next event. To simulate the clearing of "transients"
1576 // (hits, etc.) the detector is redrawn...
1578 fpViewer -> SetView ();
1579 fpViewer -> ClearView ();
1580 fpViewer -> DrawView ();