G4VRML1SceneHandlerFunc.icc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // G4VRML1SceneHandlerFunc.icc
00030 // Satoshi Tanaka & Yasuhide Sawada
00031 
00032 #include <CLHEP/Units/SystemOfUnits.h>
00033 
00034 #include "G4VisManager.hh"
00035 
00036 //#define DEBUG_SCENE_FUNC
00037 
00038 // MACRO
00039 #define ADDTHIS_WITH_NAME(Solid)        \
00040         fCurrentDEF = #Solid "_" + Solid.GetName(); \
00041         RequestPrimitives(Solid); \
00042         fCurrentDEF = "";
00043 
00044 // End of MACRO
00045 
00046 void G4VRML1SCENEHANDLER::AddSolid(const G4Trd& trd)
00047 {
00048 #if defined DEBUG_SCENE_FUNC
00049   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00050         G4cout << "***** AddSolid trd" << "\n" ;
00051 #endif
00052         VRMLBeginModeling () ;
00053         ADDTHIS_WITH_NAME(trd)
00054 }
00055 
00056 void G4VRML1SCENEHANDLER::AddSolid(const G4Trap& trap)
00057 {
00058 #if defined DEBUG_SCENE_FUNC
00059   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00060         G4cout << "***** AddSolid trap" << "\n" ;
00061 #endif
00062         VRMLBeginModeling () ;
00063         ADDTHIS_WITH_NAME(trap)
00064 }
00065 
00066 void G4VRML1SCENEHANDLER::AddSolid(const G4Para& para)
00067 {
00068 #if defined DEBUG_SCENE_FUNC
00069   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00070         G4cout << "***** AddSolid para" << "\n" ;
00071 #endif
00072         VRMLBeginModeling () ;
00073         ADDTHIS_WITH_NAME(para)
00074 }
00075 
00076 void G4VRML1SCENEHANDLER::AddSolid(const G4Torus& torus )
00077 {
00078 #if defined DEBUG_SCENE_FUNC
00079   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00080         G4cout << "***** AddSolid torus" << "\n" ;
00081 #endif
00082         VRMLBeginModeling () ;
00083         ADDTHIS_WITH_NAME(torus)
00084 }
00085 
00086 
00087 void G4VRML1SCENEHANDLER::AddSolid(const G4VSolid& vsolid)
00088 {
00089 #if defined DEBUG_SCENE_FUNC
00090   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00091         G4cout << "***** AddSolid vsolid" << "\n" ;
00092 #endif
00093         VRMLBeginModeling () ;
00094         ADDTHIS_WITH_NAME(vsolid)
00095 }
00096 
00097 void G4VRML1SCENEHANDLER::AddSolid(const G4Tubs& tubs)
00098 {
00099 #if defined DEBUG_SCENE_FUNC
00100   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00101         G4cout << "***** AddSolid tubs" << "\n" ;
00102 #endif
00103         VRMLBeginModeling () ;
00104 
00105         // set current name
00106         fCurrentDEF = "tubs_" + tubs.GetName();
00107 
00108         // Get data
00109         const G4double R  = tubs.GetRMax(); // outside radius
00110         const G4double r  = tubs.GetRMin(); // inside radius
00111         const G4double dz = tubs.GetDz();   // half length in z
00112         const G4double dp = tubs.GetDPhi(); // angle interval
00113 
00114         // Send data
00115         if ( r == 0.0 && dp >= 360. * CLHEP::deg ) {
00116                 // Send a built-in VRML node (Cylinder)
00117                 fDest << "Separator {" << "\n";
00118                 SendMatrixTransformNode( fObjectTransformation );
00119 
00120                 fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
00121                 SendMaterialNode();
00122                 SendCylinderNode(R, dz * 2);
00123                 fDest << "\t" << "}" << "\n"; // DEF Separator
00124                 fDest << "}" << "\n"; // Separator
00125         } else {
00126                 // call AddPrimitive(Polyhedron)
00127                 RequestPrimitives(tubs); 
00128         }
00129 
00130         // reset current name to null
00131         fCurrentDEF = "";
00132 }
00133 
00134 
00135 void G4VRML1SCENEHANDLER::AddSolid(const G4Cons& cons)
00136 {
00137 #if defined DEBUG_SCENE_FUNC
00138   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00139         G4cout << "***** AddSolid cons" << "\n" ;
00140 #endif
00141         VRMLBeginModeling () ;
00142 
00143         // set current name
00144         fCurrentDEF = "cons_" + cons.GetName();
00145 
00146         // Get data
00147         const G4double r1 = cons.GetRmin1(); // inside radius  at -dz
00148         const G4double R1 = cons.GetRmax1(); // outside radius at -dz
00149         const G4double r2 = cons.GetRmin2(); // inside radius  at +dz
00150         const G4double R2 = cons.GetRmax2(); // outside radius at +dz
00151         const G4double dz = cons.GetDz();    // half length in z
00152         //const G4double sp = cons.GetSPhi();  // starting angle
00153         const G4double dp = cons.GetDPhi();  // angle width
00154 
00155         // Send data
00156         if ( r1 == 0.0 && r2 == 0.0 && R1 == R2 && dp >= 360. * CLHEP::deg) {
00157                 // Send a built-in VRML node (Cylinder)
00158                 fDest << "Separator {" << "\n";
00159                 SendMatrixTransformNode( fObjectTransformation );
00160 
00161                 fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
00162                 SendMaterialNode();
00163                 SendCylinderNode(R1, dz * 2);
00164                 fDest << "\t" << "}" << "\n"; // DEF Separator
00165                 fDest << "}" << "\n"; // Separator
00166         } else {
00167                 // call AddPrimitive(Polyhedron)
00168                 RequestPrimitives(cons); 
00169         }
00170 
00171         // reset current name to null
00172         fCurrentDEF = "";
00173 }
00174 
00175 void G4VRML1SCENEHANDLER::AddSolid(const G4Box& box)
00176 {
00177 #if defined DEBUG_SCENE_FUNC
00178   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00179         G4cout << "***** AddSolid box" << "\n" ;
00180 #endif
00181         VRMLBeginModeling () ;
00182 
00183         // set current name
00184         fCurrentDEF = "box_" + box.GetName();
00185 
00186         // Send a built-in VRML node (Cube)
00187         fDest << "Separator {" << "\n";
00188 
00189         //fDest << "\t" << "renderCulling ON" << "\n";
00190         SendMatrixTransformNode( fObjectTransformation );
00191 
00192         fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
00193         SendMaterialNode();
00194         SendCubeNode(box.GetXHalfLength() * 2, box.GetYHalfLength() * 2, box.GetZHalfLength() * 2);
00195         fDest << "\t" << "}" << "\n"; // DEF Separator
00196 
00197         fDest << "}" << "\n"; // Separator
00198 
00199         // reset current name to null
00200         fCurrentDEF = "";
00201 }
00202 
00203 
00204 void G4VRML1SCENEHANDLER::AddSolid(const G4Sphere& sphere)
00205 {
00206 #if defined DEBUG_SCENE_FUNC
00207   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00208         G4cout << "***** AddSolid sphere" << "\n" ;
00209 #endif
00210         VRMLBeginModeling () ;
00211 
00212         // set current name
00213         fCurrentDEF = "sphere_" + sphere.GetName();
00214 
00215         // Get data
00216         G4double  dphi   = sphere.GetDPhi  () ;
00217         G4double  dtheta = sphere.GetDTheta() ;
00218         G4double  rmax   = sphere.GetRmax  () ;
00219         G4double  rmin   = sphere.GetRmin  () ;
00220 
00221         // Send data
00222         if ( (dphi >= 360. * CLHEP::deg) && (dtheta >= 180. * CLHEP::deg) && (rmin == 0.0)  ) {
00223                 // Send a built-in VRML node (Sphere)
00224                 fDest << "Separator {" << "\n";
00225                 SendMatrixTransformNode( fObjectTransformation );
00226 
00227                 fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
00228                 SendMaterialNode();
00229                 SendSphereNode( rmax );
00230                 fDest << "\t" << "}" << "\n"; // DEF Separator
00231                 fDest << "}" << "\n"; // Separator
00232         } else {
00233                         // call AddPrimitive(Polyhedron)
00234                         RequestPrimitives( sphere ); 
00235         }
00236 
00237         // reset current name to null
00238         fCurrentDEF = "";
00239 }
00240 
00241 void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyline& polyline)
00242 {
00243 #if defined DEBUG_SCENE_FUNC
00244   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00245         G4cout << "***** AddPrimitive polyline" << "\n" ;
00246 #endif 
00247         if (fProcessing2D) {
00248                 static G4bool warned = false;
00249                 if (!warned) {
00250                         warned = true;
00251                         G4Exception
00252                         ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Polyline&)",
00253                         "VRML-1001", JustWarning,
00254                         "2D polylines not implemented.  Ignored.");
00255                 }
00256                 return;
00257         }
00258 
00259         VRMLBeginModeling () ;  
00260 
00261         fDest << "Separator {" << "\n";
00262 
00263         SendMatrixTransformNode (fObjectTransformation );
00264 
00265         SendMaterialNode( polyline.GetVisAttributes() );
00266 
00267         fDest << "\t" << "Coordinate3 {" << "\n";
00268         fDest << "\t\t" << "point [" << "\n";
00269         G4int e, i;
00270         for (i = 0, e = polyline.size(); e; i++, e--) {
00271                 fDest << "\t\t\t";
00272                 fDest << polyline[i].x() << " ";
00273                 fDest << polyline[i].y() << " ";
00274                 fDest << polyline[i].z() << "," << "\n";
00275         }
00276         fDest << "\t\t" << "]" << "\n";
00277         fDest << "\t" << "}" << "\n"; // Coordinate3
00278 
00279         fDest << "\t" << "IndexedLineSet {" << "\n";
00280         fDest << "\t\t" << "coordIndex [";
00281         for (i = 0, e = polyline.size(); e; i++, e--) {
00282                 if (i % 10 == 0)
00283                         fDest << "\n" << "\t\t\t";
00284                 fDest << i << ", ";
00285         }
00286         fDest << "-1" << "\n";
00287         fDest << "\t\t" << "]" << "\n";
00288         fDest << "\t" << "}" << "\n"; // IndexedLineSet
00289 
00290         fDest << "}" << "\n"; // Separator
00291 }
00292 
00293 void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron)
00294 {
00295 #if defined DEBUG_SCENE_FUNC
00296   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00297         G4cout << "***** AddPrimitive(G4Polyhedron)" << "\n";
00298 #endif
00299 
00300         if (polyhedron.GetNoFacets() == 0) return;
00301 
00302         if (fProcessing2D) {
00303                 static G4bool warned = false;
00304                 if (!warned) {
00305                         warned = true;
00306                         G4Exception
00307                         ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Polyhedron&)",
00308                         "VRML-1002", JustWarning,
00309                         "2D polyhedra not implemented.  Ignored.");
00310                 }
00311                 return;
00312         }
00313 
00314         VRMLBeginModeling () ;
00315 
00316         fDest << "Separator {" << "\n";
00317 
00318         SendMatrixTransformNode( fObjectTransformation );
00319 
00320         fDest << "\t";
00321         if (fCurrentDEF != "")
00322                 fDest << "DEF " << fCurrentDEF << " ";
00323 
00324         fDest << "Separator {" << "\n";
00325 
00326         //fDest << "\t\t" << "renderCulling ON" << "\n";
00327 
00328         fDest << "\t\t" << "ShapeHints {" << "\n";
00329         fDest << "\t\t\t" << "vertexOrdering COUNTERCLOCKWISE" << "\n";
00330         fDest << "\t\t\t" << "shapeType SOLID" << "\n";
00331         fDest << "\t\t\t" << "faceType CONVEX" << "\n";
00332         fDest << "\t\t" << "}" << "\n";
00333 
00334         SendMaterialNode();
00335 
00336         fDest << "\t\t" << "Coordinate3 {" << "\n";
00337         fDest << "\t\t\t" << "point [" << "\n";
00338         G4int i, j;
00339         for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) {
00340                 G4Point3D point = polyhedron.GetVertex(i);
00341                 fDest << "\t\t\t\t";
00342                 fDest << point.x() << " ";
00343                 fDest << point.y() << " ";
00344                 fDest << point.z() << "," << "\n";
00345         }
00346         fDest << "\t\t\t" << "]" << "\n";
00347         fDest << "\t\t" << "}" << "\n"; // Coordinate3
00348 
00349         fDest << "\t\t" << "IndexedFaceSet {" << "\n";
00350         fDest << "\t\t\t" << "coordIndex [" << "\n";
00351 
00352         // facet loop
00353         G4int f;
00354         for (f = polyhedron.GetNoFacets(); f; f--) {
00355 
00356                 // edge loop  
00357                 G4bool notLastEdge;
00358                 G4int index = -1, edgeFlag = 1;
00359                 fDest << "\t\t\t\t";
00360                 do {
00361                         notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
00362                         fDest << index - 1 << ", ";
00363                 } while (notLastEdge);
00364                 fDest << "-1," << "\n";
00365         }
00366         fDest << "\t\t\t" << "]" << "\n";
00367         fDest << "\t\t" << "}" << "\n"; // IndexFaceSet
00368 
00369         fDest << "\t" << "}" << "\n"; // (DEF) Separator
00370         fDest << "}" << "\n"; // Separator
00371 
00372 }
00373 
00374 
00375 void G4VRML1SCENEHANDLER::AddPrimitive(const G4NURBS&)
00376 {
00377 #if defined DEBUG_SCENE_FUNC
00378   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00379         G4cout << "***** AddPrimitive nurbs" << "\n" ;
00380 #endif 
00381   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00382         G4cout << "G4VRML1File::AddPrimitive(G4NURBS&): not implemented. " << "\n" ;
00383         VRMLBeginModeling () ;
00384 
00385 }
00386 
00387 void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& ) 
00388 {
00389 #if defined DEBUG_SCENE_FUNC
00390   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00391         G4cout << "***** AddPrimitive text" << "\n" ;
00392 #endif
00393         /*** You might need this
00394         if (fProcessing2D) {
00395                 static G4bool warned = false;
00396                 if (!warned) {
00397                         warned = true;
00398                         G4Exception
00399                         ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Text&)",
00400                         "VRML-1003", JustWarning,
00401                         "2D text not implemented.  Ignored.");
00402                 }
00403                 return;
00404         }
00405         ***/
00406 
00407   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00408         G4cout <<
00409           "***** void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& text )"
00410           " not implemented yet."
00411              << "\n";
00412 
00413         VRMLBeginModeling () ;
00414 }
00415 
00416 void G4VRML1SCENEHANDLER::AddPrimitive( const G4Circle& circle ) 
00417 {
00418 #if defined DEBUG_SCENE_FUNC
00419   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00420         G4cout << "***** AddPrimitive circle" << "\n" ;
00421 #endif
00422 
00423         if (fProcessing2D) {
00424                 static G4bool warned = false;
00425                 if (!warned) {
00426                         warned = true;
00427                         G4Exception
00428                         ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Circle&)",
00429                         "VRML-1004", JustWarning,
00430                         "2D circles not implemented.  Ignored.");
00431                 }
00432                 return;
00433         }
00434 
00435         VRMLBeginModeling () ;
00436 
00437         // begin sending a mark
00438         fDest << "Separator {" << "\n";
00439 
00440         // send color 
00441         SendMarkerColor    ( circle ) ;
00442 
00443         // position 
00444         SendMarkerWorldPosition ( circle ) ;
00445 
00446         // Calc size 
00447         G4double size = GetMarkerHalfSize ( circle );
00448 
00449         // send shape with size 
00450         fDest << "\t" << "Sphere {" << "\n";
00451         fDest << "\t\t" << "radius " << size << "\n";
00452         fDest << "\t" << "}" << "\n";
00453 
00454         // end sending a mark
00455         fDest << "}" << "\n"; // Separator
00456 }
00457 
00458 
00459 void G4VRML1SCENEHANDLER::AddPrimitive(const G4Square& square)
00460 {
00461 #if defined DEBUG_SCENE_FUNC
00462   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00463         G4cout << "***** AddPrimitive square" << "\n" ;
00464 #endif
00465 
00466         if (fProcessing2D) {
00467                 static G4bool warned = false;
00468                 if (!warned) {
00469                         warned = true;
00470                         G4Exception
00471                         ("G4VRML1SCENEHANDLER::AddPrimitive (const G4Square&)",
00472                         "VRML-1005", JustWarning,
00473                         "2D squares not implemented.  Ignored.");
00474                 }
00475                 return;
00476         }
00477 
00478         VRMLBeginModeling () ;
00479 
00480         // begin sending a mark
00481         fDest << "Separator {" << "\n";
00482 
00483         // send color 
00484         SendMarkerColor    ( square );
00485 
00486         // position 
00487         SendMarkerWorldPosition ( square );
00488 
00489         // Calc size 
00490         G4double size = GetMarkerHalfSize ( square );
00491         size *= 2.;
00492 
00493         // send shape with size 
00494         fDest << "\t" << "Cube {" << "\n";
00495         fDest << "\t\t" << "width "  << size << "\n";
00496         fDest << "\t\t" << "height " << size << "\n";
00497         fDest << "\t\t" << "depth "  << size << "\n";
00498         fDest << "\t" << "}" << "\n";
00499 
00500         // end sending a mark
00501         fDest << "}" << "\n"; // Separator
00502 }
00503 
00504 void G4VRML1SCENEHANDLER::BeginModeling()
00505 {
00506 #if defined DEBUG_SCENE_FUNC
00507   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00508         G4cout << "***** BeginModeling " << "\n" ;
00509 #endif
00510         G4VSceneHandler::BeginModeling();
00511 }
00512 
00513 void G4VRML1SCENEHANDLER::EndModeling()
00514 {
00515 #if defined DEBUG_SCENE_FUNC
00516   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00517         G4cout << "***** EndModeling " << "\n" ;
00518 #endif
00519         G4VSceneHandler::EndModeling();
00520 }
00521 
00522 void G4VRML1SCENEHANDLER::BeginPrimitives(const G4Transform3D& objectTransformation)
00523 {
00524   G4VSceneHandler::BeginPrimitives (objectTransformation);
00525 #if defined DEBUG_SCENE_FUNC
00526   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00527         G4cout << "***** BeginPrimitives " << "\n" ;
00528 #endif
00529         VRMLBeginModeling();
00530 }
00531 
00532 void G4VRML1SCENEHANDLER::EndPrimitives()
00533 {
00534 #if defined DEBUG_SCENE_FUNC
00535   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00536         G4cout << "***** EndPrimitives " << "\n" ;
00537 #endif
00538   G4VSceneHandler::EndPrimitives();
00539 }
00540 
00541 void G4VRML1SCENEHANDLER::SendMaterialNode( const G4VisAttributes*  pVA )
00542 {
00543 //      const double TRANSPARENCY = 0.9 ; 
00544         const double TRANSPARENCY = 0.5 ; 
00545 
00546         if (!pVA)
00547                 return;
00548 
00549         const G4Color& color = pVA->GetColor();
00550 
00551         fDest << "\t\t" << "Material {" << "\n";
00552 
00553         if (pVA->IsForceDrawingStyle() &&
00554            (pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe)) {
00555                 fDest << "\t\t\t" << "transparency " << TRANSPARENCY << "\n";
00556         }
00557 
00558         fDest << "\t\t\t" << "diffuseColor";
00559         fDest << " " << color.GetRed();
00560         fDest << " " << color.GetGreen();
00561         fDest << " " << color.GetBlue();
00562         fDest << "\n";
00563         fDest << "\t\t" << "}" << "\n";
00564 }
00565 
00566 
00567 void G4VRML1SCENEHANDLER::SendMaterialNode()
00568 {
00569         SendMaterialNode
00570         ( fpViewer->GetApplicableVisAttributes (fpVisAttribs) );
00571 }
00572 
00573 
00574 void G4VRML1SCENEHANDLER::SendMatrixTransformNode(const G4Transform3D& trans)
00575 {
00576         G4Point3D  B  (0.0, 0.0, 0.0);
00577 
00578         G4Point3D  x1 (1.0, 0.0, 0.0);
00579         G4Point3D  y1 (0.0, 1.0, 0.0);
00580 
00581         G4Vector3D e1 (1.0, 0.0, 0.0);
00582         G4Vector3D e2 (0.0, 1.0, 0.0);
00583         G4Vector3D e3 (0.0, 0.0, 1.0);
00584 
00585                 //----- transformed origin of body coord
00586         B.transform(trans);
00587 
00588                 //----- transformed base vectors of body coord
00589         x1.transform(trans);
00590         e1 = x1 - B;
00591 
00592         y1.transform(trans);
00593         e2 = y1 - B;
00594 
00595         e3 = e1.cross(e2);
00596 
00597         e1 = e1.unit(); // normalize again for accuracy
00598         e2 = e2.unit(); //
00599         e3 = e3.unit(); //
00600 
00601         fDest << "\t" << "MatrixTransform {" << "\n";
00602         fDest << "\t\t" << "matrix ";
00603         fDest << e1.x() << " " << e1.y() << " " << e1.z() << " 0 ";
00604         fDest << e2.x() << " " << e2.y() << " " << e2.z() << " 0 ";
00605         fDest << e3.x() << " " << e3.y() << " " << e3.z() << " 0 ";
00606         fDest << B.x()  << " " << B.y()  << " " << B.z()  << " 1" << "\n";
00607         fDest << "\t" << "}" << "\n";
00608 }
00609 
00610 void G4VRML1SCENEHANDLER::SendCubeNode(G4double w, G4double h, G4double d)
00611 {
00612         fDest << "\t\t" << "Cube {" << "\n";
00613         fDest << "\t\t\t" << "width "  << w << "\n";
00614         fDest << "\t\t\t" << "height " << h << "\n";
00615         fDest << "\t\t\t" << "depth "  << d << "\n";
00616         fDest << "\t\t" << "}" << "\n";
00617 }
00618 
00619 void G4VRML1SCENEHANDLER::SendCylinderNode(G4double R, G4double h)
00620 {
00621         fDest << "\t\t" << "Transform {" << "\n";
00622         fDest << "\t\t\t" << "rotation 1 0 0 " << (90. * CLHEP::deg) << "\n";
00623         fDest << "\t\t" << "}" << "\n";
00624 
00625         fDest << "\t\t" << "Cylinder {" << "\n";
00626         fDest << "\t\t\t" << "radius " << R << "\n";
00627         fDest << "\t\t\t" << "height " << h << "\n";
00628         fDest << "\t\t" << "}" << "\n";
00629 }
00630 
00631 void G4VRML1SCENEHANDLER::SendSphereNode(G4double R)
00632 {
00633         fDest << "\t\t" << "Sphere {" << "\n";
00634         fDest << "\t\t\t" << "radius " << R << "\n";
00635         fDest << "\t\t" << "}" << "\n";
00636 }
00637 
00638 void G4VRML1SCENEHANDLER::VRMLBeginModeling()
00639 {
00640         if (!IS_CONNECTED ) {
00641 #if defined DEBUG_SCENE_FUNC
00642   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00643         G4cout << "***** VRMLBeginModeling() (started)" << "\n" ;
00644 #endif
00645                 this->connectPort();
00646                 fDest << "#VRML V1.0 ascii" << "\n";
00647                 fDest << "# Generated by VRML 1.0 driver of GEANT4\n" << "\n";
00648         }
00649 }
00650 
00651 void G4VRML1SCENEHANDLER::VRMLEndModeling()
00652 {
00653         if ( IS_CONNECTED ) {
00654 #if defined DEBUG_SCENE_FUNC
00655   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00656         G4cout << "***** VRMLEndModeling() (started)" << "\n" ;
00657 #endif
00658 
00659                 fDest << "#End of file." << "\n";
00660                 this->closePort();
00661         }
00662 }
00663 
00664 void      G4VRML1SCENEHANDLER::SendMarkerColor ( const G4VMarker& mark ) 
00665 {
00666         const G4Color& color = GetColor( mark );
00667 
00668         fDest << "\t" << "Material {" << "\n";
00669         fDest << "\t\t";
00670         fDest << "ambientColor [] ";
00671         fDest << "specularColor [] ";
00672         fDest << "\t\t" << "diffuseColor";
00673         fDest << " " << color.GetRed();
00674         fDest << " " << color.GetGreen();
00675         fDest << " " << color.GetBlue();
00676         fDest << "\n";
00677         fDest << "\t\t" << "emissiveColor";
00678         fDest << " " << color.GetRed();
00679         fDest << " " << color.GetGreen();
00680         fDest << " " << color.GetBlue();
00681         fDest << "\n";
00682         fDest << "\t" << "}" << "\n";
00683 }
00684 
00685 void      
00686 G4VRML1SCENEHANDLER::SendMarkerWorldPosition ( const G4VMarker& mark )
00687 {
00688         G4Point3D point = mark.GetPosition();
00689 
00690         SendMatrixTransformNode( fObjectTransformation );
00691 
00692         fDest << "\t\t" << "Transform {" << "\n";
00693         fDest << "\t\t\t" << "translation ";
00694         fDest << point.x() << " " << point.y() << " " << point.z() << "\n";
00695         fDest << "\t\t" << "}" << "\n" ;
00696 }
00697 
00698 
00699 G4double  G4VRML1SCENEHANDLER::GetMarkerHalfSize ( const G4VMarker& mark ) 
00700 {
00701         //----- return value ( marker radius in 3d units) 
00702         G4double size       = 1.0 ; // initialization
00703 
00704         //----- parameters to calculate 3d size from 2d size
00705         const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels
00706         double zoom_factor  = fpViewer->GetViewParameters().GetZoomFactor() ;
00707         if ( zoom_factor <=  0.0 ) { zoom_factor = 1.0 ; }
00708         double extent_radius_3d = GetScene()->GetExtent().GetExtentRadius() ;
00709         if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; } 
00710 
00711         //----- get marker radius in 3D units
00712         if        ( mark.GetWorldSize() > 0.0 ) {
00713                 // get mark radius in 3D units
00714                 size = 0.5 * mark.GetWorldSize()  ; 
00715 
00716         } else if ( mark.GetScreenSize() > 0.0 ) {
00717                 // local
00718                 double mark_radius_2d   = 0.5 * mark.GetScreenSize() ;
00719 
00720                 // get mark radius in 3D units
00721                 size \
00722                  = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
00723                 size *= zoom_factor ;
00724 
00725         } else {
00726                 // local
00727                 double mark_radius_2d \
00728                  = fpViewer->GetViewParameters().GetDefaultMarker().GetScreenSize();
00729                 mark_radius_2d *= 0.1 ; // Magic number?
00730 
00731                 // get mark radius in 3D units
00732                 size \
00733                  = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
00734                 size *= zoom_factor ;
00735         }
00736 
00737                 //----- global rescaling
00738         size *= fpViewer->GetViewParameters().GetGlobalMarkerScale(); 
00739 
00740                 //----- return size
00741         return size ;
00742 
00743 } 
00744 
00745 void G4VRML1SCENEHANDLER::ClearTransientStore() 
00746 {
00747   // This is typically called after an update and before drawing hits
00748   // of the next event.  To simulate the clearing of "transients"
00749   // (hits, etc.) the detector is redrawn...
00750   if (fpViewer) {
00751     fpViewer -> SetView ();
00752     fpViewer -> ClearView ();
00753     fpViewer -> DrawView ();
00754   }
00755 }
00756 
00757 
00758 // #undef ADDTHIS_WITH_NAME(Solid)
00759 // #undef MAKE_NAME(Solid)
00760 // End of file.

Generated on Mon May 27 17:50:21 2013 for Geant4 by  doxygen 1.4.7