G4VRML2SceneHandlerFunc.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 // G4VRML2SceneHandlerFunc.icc
00030 // Satoshi Tanaka & Yasuhide Sawada
00031 
00032 //#define DEBUG_SCENE_FUNC
00033 
00034 #include "G4VisManager.hh"
00035 
00036 void G4VRML2SCENEHANDLER::AddSolid(const G4Trd& trd)
00037 {
00038 #if defined DEBUG_SCENE_FUNC
00039   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00040         G4cout << "***** AddSolid trd" << "\n" ;
00041 #endif
00042         VRMLBeginModeling () ;
00043         G4VSceneHandler::AddSolid(trd);
00044 }
00045 
00046 void G4VRML2SCENEHANDLER::AddSolid(const G4Trap& trap)
00047 {
00048 #if defined DEBUG_SCENE_FUNC
00049   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00050         G4cout << "***** AddSolid trap" << "\n" ;
00051 #endif
00052         VRMLBeginModeling () ;
00053         G4VSceneHandler::AddSolid(trap);
00054 }
00055 
00056 void G4VRML2SCENEHANDLER::AddSolid(const G4Para& para)
00057 {
00058 #if defined DEBUG_SCENE_FUNC
00059   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00060         G4cout << "***** AddSolid para" << "\n" ;
00061 #endif
00062         VRMLBeginModeling () ;
00063         G4VSceneHandler::AddSolid(para);
00064 }
00065 
00066 void G4VRML2SCENEHANDLER::AddSolid(const G4Torus& torus )
00067 {
00068 #if defined DEBUG_SCENE_FUNC
00069   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00070         G4cout << "***** AddSolid torus" << "\n" ;
00071 #endif
00072         VRMLBeginModeling () ;
00073         G4VSceneHandler::AddSolid(torus);
00074 }
00075 
00076 
00077 void G4VRML2SCENEHANDLER::AddSolid(const G4VSolid& vsolid)
00078 {
00079 #if defined DEBUG_SCENE_FUNC
00080   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00081         G4cout << "***** AddSolid vsolid" << "\n" ;
00082 #endif
00083         VRMLBeginModeling () ;
00084         G4VSceneHandler::AddSolid(vsolid);
00085 }
00086 
00087 void G4VRML2SCENEHANDLER::AddSolid(const G4Tubs& tubs)
00088 {
00089 #if defined DEBUG_SCENE_FUNC
00090   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00091         G4cout << "***** AddSolid tubs" << "\n" ;
00092 #endif
00093         VRMLBeginModeling () ;
00094         G4VSceneHandler::AddSolid(tubs) ;
00095 
00096 }
00097 
00098 
00099 void G4VRML2SCENEHANDLER::AddSolid(const G4Cons& cons)
00100 {
00101 #if defined DEBUG_SCENE_FUNC
00102   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00103         G4cout << "***** AddSolid cons" << "\n" ;
00104 #endif
00105         VRMLBeginModeling () ;
00106         G4VSceneHandler::AddSolid(cons) ;
00107 }
00108 
00109 void G4VRML2SCENEHANDLER::AddSolid(const G4Box& box)
00110 {
00111 #if defined DEBUG_SCENE_FUNC
00112   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00113         G4cout << "***** AddSolid box" << "\n" ;
00114 #endif
00115         VRMLBeginModeling () ;
00116         G4VSceneHandler::AddSolid(box) ;
00117 }
00118 
00119 
00120 void G4VRML2SCENEHANDLER::AddSolid(const G4Sphere& sphere)
00121 {
00122 #if defined DEBUG_SCENE_FUNC
00123   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00124         G4cout << "***** AddSolid sphere" << "\n" ;
00125 #endif
00126         VRMLBeginModeling () ;
00127         G4VSceneHandler::AddSolid(sphere) ;
00128 }
00129 
00130 void G4VRML2SCENEHANDLER::AddPrimitive(const G4Polyline& polyline)
00131 {
00132 #if defined DEBUG_SCENE_FUNC
00133   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00134         G4cout << "***** AddPrimitive polyline" << "\n" ;
00135 #endif 
00136 
00137         if (fProcessing2D) {
00138                 static G4bool warned = false;
00139                 if (!warned) {
00140                         warned = true;
00141                         G4Exception
00142                         ("G4VRML2SCENEHANDLER::AddPrimitive (const G4Polyline&)",
00143                         "VRML-2001", JustWarning,
00144                         "2D polylines not implemented.  Ignored.");
00145                 }
00146                 return;
00147         }
00148 
00149         VRMLBeginModeling () ;
00150 
00151         // VRML codes are generated below
00152 
00153         fDest << "#---------- POLYLINE" << "\n";
00154         fDest << "Shape {" << "\n";
00155 
00156         SendLineColor   ( polyline.GetVisAttributes() );
00157 
00158         fDest << "\t" << "geometry IndexedLineSet {" << "\n";
00159 
00160         fDest << "\t\t"   << "coord Coordinate {" << "\n";
00161         fDest << "\t\t\t" <<      "point [" << "\n";
00162         G4int e, i;
00163         for (i = 0, e = polyline.size(); e; i++, e--) {
00164 
00165                 G4Point3D point = polyline[i];
00166                 point.transform( fObjectTransformation );
00167 
00168                 fDest << "\t\t\t\t";
00169                 fDest <<                  point.x() << " ";
00170                 fDest <<                  point.y() << " ";
00171                 fDest <<                  point.z() << "," << "\n";
00172 
00173         } // for
00174 
00175         fDest << "\t\t\t" <<      "]" << "\n"; // point
00176         fDest << "\t\t"   << "}"      << "\n"; // coord
00177 
00178         fDest << "\t\t" << "coordIndex [";
00179         for (i = 0, e = polyline.size(); e; i++, e--) {
00180                 if (i % 10 == 0)
00181                         fDest << "\n" << "\t\t\t";
00182                 fDest << i << ", ";
00183         }
00184         fDest << "-1" << "\n";
00185         fDest << "\t\t" << "]"        << "\n"; // coordIndex
00186         fDest << "\t" << "}" << "\n"; // geometry IndexedLineSet
00187 
00188         fDest << "}" << "\n"; // Shape
00189 }
00190 
00191 
00192 void G4VRML2SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron)
00193 {
00194 #if defined DEBUG_SCENE_FUNC
00195   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00196         G4cout << "***** AddPrimitive(G4Polyhedron)" << "\n";
00197 #endif
00198 
00199         if (polyhedron.GetNoFacets() == 0) return;
00200 
00201         if (fProcessing2D) {
00202                 static G4bool warned = false;
00203                 if (!warned) {
00204                         warned = true;
00205                         G4Exception
00206                         ("G4VRML2SCENEHANDLER::AddPrimitive (const G4Polyhedron&)",
00207                         "VRML-2002", JustWarning,
00208                         "2D polyhedra not implemented.  Ignored.");
00209                 }
00210                 return;
00211         }
00212 
00213         VRMLBeginModeling () ;
00214 
00215         // Transparency checking: If completely transparent, skip drawing 
00216         if ( GetPVTransparency() > 0.99 ) { return ; }
00217 
00218         // Current Model
00219         const G4VModel* pv_model  = GetModel();
00220         G4String pv_name = "No model";
00221         if (pv_model) pv_name = pv_model->GetCurrentTag() ;
00222 
00223         // VRML codes are generated below
00224 
00225         fDest << "#---------- SOLID: " << pv_name << "\n";
00226 
00227         if ( IsPVPickable() ) {
00228 
00229          fDest << "Anchor {" << "\n";
00230          fDest << " description " << "\"" << pv_name << "\"" << "\n";
00231          fDest << " url \"\" " << "\n";
00232          fDest << " children [" << "\n";
00233         }
00234 
00235         fDest << "\t"; fDest << "Shape {" << "\n";
00236 
00237         SendMaterialNode();
00238 
00239         fDest << "\t\t" << "geometry IndexedFaceSet {" << "\n";
00240 
00241         fDest << "\t\t\t"   << "coord Coordinate {" << "\n";
00242         fDest << "\t\t\t\t" <<      "point [" << "\n";
00243         G4int i, j;
00244         for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) {
00245                 G4Point3D point = polyhedron.GetVertex(i);
00246 
00247                 point.transform( fObjectTransformation );
00248 
00249                 fDest << "\t\t\t\t\t";
00250                 fDest <<                   point.x() << " ";
00251                 fDest <<                   point.y() << " ";
00252                 fDest <<                   point.z() << "," << "\n";
00253         }
00254         fDest << "\t\t\t\t" <<      "]" << "\n"; // point
00255         fDest << "\t\t\t"   << "}"      << "\n"; // coord
00256 
00257         fDest << "\t\t\t"   << "coordIndex [" << "\n";
00258 
00259         // facet loop
00260         G4int f;
00261         for (f = polyhedron.GetNoFacets(); f; f--) {
00262 
00263                 // edge loop  
00264                 G4bool notLastEdge;
00265                 G4int index = -1, edgeFlag = 1;
00266                 fDest << "\t\t\t\t";
00267                 do {
00268                         notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
00269                         fDest << index - 1 << ", ";
00270                 } while (notLastEdge);
00271                 fDest << "-1," << "\n";
00272         }
00273         fDest << "\t\t\t"   << "]" << "\n"; // coordIndex
00274 
00275         fDest << "\t\t\t"   << "solid FALSE" << "\n"; // draw backfaces
00276 
00277         fDest << "\t\t" << "}"     << "\n"; // IndexFaceSet
00278         fDest << "\t" << "}"       << "\n"; // Shape
00279 
00280         if ( IsPVPickable() ) {
00281          fDest << " ]"              << "\n"; // children
00282          fDest << "}"               << "\n"; // Anchor
00283         }
00284 
00285 } 
00286 
00287 
00288 void G4VRML2SCENEHANDLER::AddPrimitive(const G4NURBS&)
00289 {
00290 #if defined DEBUG_SCENE_FUNC
00291   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00292         G4cout << "***** AddPrimitive nurbs" << "\n" ;
00293 #endif 
00294   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00295         G4cout << "G4VRML2File::AddPrimitive(G4NURBS&): not implemented. " << "\n" ;
00296 
00297         VRMLBeginModeling () ;
00298 }
00299 
00300 void G4VRML2SCENEHANDLER::AddPrimitive( const G4Text& ) 
00301 {
00302 #if defined DEBUG_SCENE_FUNC
00303   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00304         G4cout << "***** AddPrimitive text" << "\n" ;
00305 #endif
00306         /*** You might need this
00307         if (fProcessing2D) {
00308                 static G4bool warned = false;
00309                 if (!warned) {
00310                         warned = true;
00311                         G4Exception
00312                         ("G4VRML2SCENEHANDLER::AddPrimitive (const G4Text&)",
00313                         "VRML-2003", JustWarning,
00314                         "2D text not implemented.  Ignored.");
00315                 }
00316                 return;
00317         }
00318         ***/
00319 
00320   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00321         G4cout <<
00322           "***** void G4VRML2SCENEHANDLER::AddPrimitive( const G4Text& text )"
00323           " not implemented yet."
00324              << "\n";
00325 
00326         VRMLBeginModeling () ;
00327 
00328 }
00329 
00330 void G4VRML2SCENEHANDLER::AddPrimitive( const G4Circle& circle ) 
00331 {
00332 #if defined DEBUG_SCENE_FUNC
00333   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00334         G4cout << "***** AddPrimitive circle" << "\n" ;
00335 #endif
00336 
00337         if (fProcessing2D) {
00338                 static G4bool warned = false;
00339                 if (!warned) {
00340                         warned = true;
00341                         G4Exception
00342                         ("G4VRML2SCENEHANDLER::AddPrimitive (const G4Circle&)",
00343                         "VRML-2004", JustWarning,
00344                         "2D circles not implemented.  Ignored.");
00345                 }
00346                 return;
00347         }
00348 
00349         VRMLBeginModeling () ;
00350 
00351         // Information 
00352 //      const char* info = NULL ;
00353         const char* info = circle.GetInfo() ;
00354 
00355         // Position and half size of circle
00356         G4double X, Y, Z ; GetMarkerWorldPosition( circle, &X, &Y, &Z ) ;
00357         G4double radius = GetMarkerHalfSize ( circle );
00358 
00359         // VRML codes are generated below
00360         fDest << "#---------- 3D MARKER (Circle)" << "\n";
00361         fDest << "Anchor {" << "\n";
00362 
00363         if( circle.GetInfo().isNull() ) {
00364                 fDest << " description " << "\"(" <<  X <<  "  " ;
00365                 fDest <<                              Y <<  "  " ;
00366                 fDest <<                              Z <<  ")\"" << "\n";
00367         } else {
00368                 fDest << " description " << "\"" <<  info << "\"" << "\n";
00369         }
00370 
00371 
00372         fDest << " url \"\" " << "\n";
00373 
00374         fDest << " children [" << "\n";
00375 
00376         fDest << "  Transform {" << "\n";
00377 
00378         fDest << "   translation ";
00379         fDest <<      X << " " << Y << " " << Z << "\n";
00380 
00381         fDest << "   children ["   << "\n";
00382 
00383         fDest << "\t" << "Shape {" << "\n";
00384 
00385         SendMarkerColor( circle );
00386 
00387         // send shape with size 
00388         fDest << "\t\t"   << "geometry Sphere {" << "\n";
00389         fDest << "\t\t\t" <<      "radius " << radius << "\n";
00390         fDest << "\t\t"   << "}" << "\n";
00391 
00392         fDest << "\t" << "}"       << "\n"; // Shape
00393 
00394         fDest << "   ]"            << "\n"; //  children 
00395         fDest << "  }"             << "\n"; //  Transform
00396         
00397         fDest << " ]"              << "\n"; //  children
00398         fDest << "}"               << "\n"; //  Anchor
00399 
00400 }
00401 
00402 void G4VRML2SCENEHANDLER::AddPrimitive(const G4Square& square)
00403 {
00404 #if defined DEBUG_SCENE_FUNC
00405   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00406         G4cout << "***** AddPrimitive square" << "\n" ;
00407 #endif
00408 
00409         if (fProcessing2D) {
00410                 static G4bool warned = false;
00411                 if (!warned) {
00412                         warned = true;
00413                         G4Exception
00414                         ("G4VRML2SCENEHANDLER::AddPrimitive (const G4Square&)",
00415                         "VRML-2005", JustWarning,
00416                         "2D squares not implemented.  Ignored.");
00417                 }
00418                 return;
00419         }
00420 
00421         VRMLBeginModeling () ;
00422 
00423         // Information 
00424 //      const char* info = NULL ;
00425         const char* info = square.GetInfo() ;
00426 
00427         // Position and size of square 
00428         G4double X, Y, Z ; GetMarkerWorldPosition  ( square, &X, &Y, &Z ) ;
00429         G4double radius   = GetMarkerHalfSize ( square );
00430         G4double diameter = 2.0 * radius ;
00431 
00432         // VRML codes are generated below
00433         fDest << "#---------- 3D MARKER (Square)" << "\n";
00434         fDest << "Anchor {" << "\n";
00435 
00436         if( square.GetInfo().isNull() ) {
00437                 fDest << " description " << "\"(" <<  X <<  "  " ;
00438                 fDest <<                              Y <<  "  " ;
00439                 fDest <<                              Z <<  ")\"" << "\n";
00440         } else {
00441                 fDest << " description " << "\"" <<  info << "\"" << "\n";
00442         }
00443 
00444         fDest << " url \"\" " << "\n";
00445 
00446         fDest << " children [" << "\n";
00447 
00448         fDest << "  Transform {" << "\n";
00449 
00450         fDest << "   translation ";
00451         fDest <<      X << " " << Y << " " << Z << "\n";
00452 
00453         fDest << "   children ["   << "\n";
00454 
00455         fDest << "\t" << "Shape {" << "\n";
00456 
00457         SendMarkerColor( square );
00458 
00459         // send shape with size 
00460         fDest << "\t\t"   << "geometry Box {" << "\n";
00461         fDest << "\t\t\t" <<      "size "   << diameter << " "  ;
00462         fDest                               << diameter << " "  ;
00463         fDest                               << diameter << "\n" ;
00464         fDest << "\t\t"   << "}"                        << "\n";
00465 
00466         fDest << "\t" << "}"       << "\n"; //  Shape
00467 
00468         fDest << "   ]"            << "\n"; //  children 
00469         fDest << "  }"             << "\n"; //  Transform
00470         
00471         fDest << " ]"              << "\n"; //  children
00472         fDest << "}"               << "\n"; //  Anchor
00473 
00474 }
00475 
00476 void G4VRML2SCENEHANDLER::BeginModeling()
00477 {
00478 #if defined DEBUG_SCENE_FUNC
00479   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00480         G4cout << "***** BeginModeling" << "\n" ;
00481 #endif
00482         G4VSceneHandler::BeginModeling();
00483 
00484 }
00485 
00486 void G4VRML2SCENEHANDLER::EndModeling()
00487 {
00488 #if defined DEBUG_SCENE_FUNC
00489   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00490         G4cout << "***** EndModeling " << "\n" ;
00491 #endif
00492         G4VSceneHandler::EndModeling();
00493 }
00494 
00495 void G4VRML2SCENEHANDLER::BeginPrimitives(const G4Transform3D& objectTransformation)
00496 {
00497   G4VSceneHandler::BeginPrimitives (objectTransformation);
00498 #if defined DEBUG_SCENE_FUNC
00499   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00500         G4cout << "***** BeginPrimitives " << "\n" ;
00501 #endif
00502         VRMLBeginModeling(); 
00503 }
00504 
00505 void G4VRML2SCENEHANDLER::EndPrimitives()
00506 {
00507 #if defined DEBUG_SCENE_FUNC
00508   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00509         G4cout << "***** EndPrimitives " << "\n" ;
00510 #endif
00511   G4VSceneHandler::EndPrimitives();
00512 }
00513 
00514 void G4VRML2SCENEHANDLER::SendMaterialNode( const G4VisAttributes*  pVA )
00515 {
00516         // Initialization of drawing parameters         
00517         G4bool          flagWF       = false ; 
00518         G4double        TRANSPARENCY = GetPVTransparency() ;
00519 
00520         //  Wireframe or not
00521         const   G4ViewParameters& cur_view_param = fpViewer -> GetViewParameters ();
00522         if (pVA->IsForceDrawingStyle() &&
00523            (pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe)) 
00524         {
00525                 // wireframe style is assigned to this object
00526                 flagWF = true ;
00527 
00528         } else if ( cur_view_param.GetDrawingStyle() == G4ViewParameters::wireframe )   
00529         {
00530                 // current viewing style is  wireframe 
00531                 flagWF = true  ;
00532         } 
00533 
00534         // VRML codes are generated below
00535         if (!pVA) { 
00536                 
00537                 // Error recovery: Use default values of VRML browser
00538                 fDest << "\t\t" ;
00539                 fDest << "appearance Appearance { material Material {} }";
00540                 fDest << "\n";
00541                 
00542         } else {
00543 
00544                 const G4Color& color = pVA->GetColor();
00545 
00546                 fDest << "\t\t"   << "appearance Appearance {" << "\n";
00547                 fDest << "\t\t\t" <<      "material Material {" << "\n";
00548 
00549                 // diffuse color        
00550                 fDest << "\t\t\t\t" << "diffuseColor ";
00551                 fDest <<                   color.GetRed()   << " " ;
00552                 fDest <<                   color.GetGreen() << " " ;
00553                 fDest <<                   color.GetBlue()  << "\n"; 
00554 
00555                 // emmisive color       
00556                 // fDest << "\t\t\t\t" << "emissiveColor ";
00557                 // fDest <<                   color.GetRed()   << " " ;
00558                 // fDest <<                   color.GetGreen() << " " ;
00559                 //fDest <<                   color.GetBlue()  << "\n"; 
00560                 //
00561 
00562                 // wireframe is expressed as transparency
00563                 if ( flagWF ) 
00564                 {
00565                         fDest << "\t\t\t\t" << "transparency " << TRANSPARENCY << "\n";
00566                 }
00567 
00568                 fDest << "\t\t\t" <<      "}" << "\n"; // material
00569                 fDest << "\t\t"   << "}"      << "\n"; // appearance
00570         }
00571 
00572 }
00573 
00574 
00575 void G4VRML2SCENEHANDLER::SendMaterialNode()
00576 {
00577         SendMaterialNode
00578         ( fpViewer->GetApplicableVisAttributes (fpVisAttribs) );
00579 }
00580 
00581 
00582 void G4VRML2SCENEHANDLER::VRMLBeginModeling()
00583 {
00584         if (!IS_CONNECTED ) {
00585 #if defined DEBUG_SCENE_FUNC
00586   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00587         G4cout << "***** VRMLBeginModeling (started)" << "\n" ;
00588 #endif
00589                 this->connectPort();
00590                 fDest << "#VRML V2.0 utf8" << "\n";
00591                 fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n";
00592         }
00593 }
00594 
00595 void G4VRML2SCENEHANDLER::VRMLEndModeling()
00596 {
00597         if ( IS_CONNECTED ) {
00598 #if defined DEBUG_SCENE_FUNC
00599   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00600         G4cout << "***** VRMLEndModeling (started)" << "\n" ;
00601 #endif
00602                 fDest << "#End of file." << "\n";
00603                 this->closePort();
00604         }
00605 }
00606 
00607 void      G4VRML2SCENEHANDLER::SendMarkerColor ( const G4VMarker& mark ) 
00608 {
00609         const G4Color& color = GetColor( mark );
00610 
00611         fDest << "\t\t"     << "appearance Appearance {" << "\n";
00612         fDest << "\t\t\t"   <<      "material Material {" << "\n";
00613         fDest << "\t\t\t\t" <<      "diffuseColor ";
00614         fDest <<                   color.GetRed()    << " " ;
00615         fDest <<                   color.GetGreen()  << " " ;
00616         fDest <<                   color.GetBlue()   << "\n";
00617         fDest << "\t\t\t\t" <<    "emissiveColor ";
00618         fDest <<                   color.GetRed()    << " " ;
00619         fDest <<                   color.GetGreen()  << " " ;
00620         fDest <<                   color.GetBlue()   << "\n";
00621         fDest << "\t\t\t"   <<      "}"              << "\n"; // material
00622         fDest << "\t\t"     << "}"                   << "\n"; // appearance
00623 
00624 }
00625 
00626 void      
00627 G4VRML2SCENEHANDLER::SendMarkerWorldPosition ( const G4VMarker& mark )
00628 {
00629         G4Point3D point = mark.GetPosition();
00630 
00631         point.transform( fObjectTransformation );
00632 
00633         fDest << "   translation ";
00634         fDest <<      point.x() << " " << point.y() << " " << point.z() << "\n";
00635 
00636 }
00637 
00638 void  G4VRML2SCENEHANDLER::GetMarkerWorldPosition    (  const G4VMarker&  mark , 
00639                                                 double* pX             ,
00640                                                 double* pY             ,
00641                                                 double* pZ              ) 
00642 {
00643         G4Point3D point = mark.GetPosition();
00644 
00645         point.transform( fObjectTransformation );
00646 
00647         *pX = point.x() ;
00648         *pY = point.y() ;
00649         *pZ = point.z() ;
00650 }
00651 
00652 G4double  G4VRML2SCENEHANDLER::GetMarkerHalfSize ( const G4VMarker& mark ) 
00653 {
00654         //----- return value ( marker radius in 3d units) 
00655         G4double size       = 1.0 ; // initialization
00656 
00657         //----- parameters to calculate 3d size from 2d size
00658         const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels
00659         double zoom_factor  = fpViewer->GetViewParameters().GetZoomFactor() ;
00660         if ( zoom_factor <=  0.0 ) { zoom_factor = 1.0 ; }
00661         double extent_radius_3d = GetScene()->GetExtent().GetExtentRadius() ;
00662         if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; } 
00663 
00664         //----- get marker radius in 3D units
00665         if        ( mark.GetWorldSize() > 0.0 ) {
00666 
00667                 // get mark radius in 3D units
00668                 size = 0.5 * mark.GetWorldSize()  ; 
00669 
00670         } else if ( mark.GetScreenSize() > 0.0 ) {
00671 
00672                 // local
00673                 double mark_radius_2d   = 0.5 * mark.GetScreenSize() ;
00674 
00675                 // get mark radius in 3D units
00676                 size \
00677                  = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
00678                 size *= zoom_factor ;
00679 
00680         } else {
00681                 // local
00682                 double mark_radius_2d \
00683                  = fpViewer->GetViewParameters().GetDefaultMarker().GetScreenSize();
00684                 mark_radius_2d *= 0.1 ; // Magic number?
00685 
00686                 // get mark radius in 3D units
00687                 size \
00688                  = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
00689                 size *= zoom_factor ;
00690         }
00691 
00692                 //----- global rescaling
00693         size *= fpViewer->GetViewParameters().GetGlobalMarkerScale(); 
00694 
00695                 //----- return size
00696         return size ;
00697 
00698 } 
00699 
00700 void G4VRML2SCENEHANDLER::SendLineColor ( const G4VisAttributes*  pVA )
00701 {
00702         const G4Color& color = pVA->GetColor();
00703 
00704 
00705         fDest << "\t"   << "appearance Appearance {" << "\n";
00706         fDest << "\t\t" <<      "material Material {" << "\n";
00707         fDest << "\t\t\t" <<      "diffuseColor ";
00708         fDest <<                   color.GetRed()    << " " ;
00709         fDest <<                   color.GetGreen()  << " " ;
00710         fDest <<                   color.GetBlue()   << "\n";
00711         fDest << "\t\t\t" <<    "emissiveColor ";
00712         fDest <<                   color.GetRed()    << " " ;
00713         fDest <<                   color.GetGreen()  << " " ;
00714         fDest <<                   color.GetBlue()   << "\n";
00715         fDest << "\t\t" <<      "}"                  << "\n"; // material
00716         fDest << "\t"   << "}"                       << "\n"; // appearance
00717 }
00718 
00719 G4double      G4VRML2SCENEHANDLER::SetPVTransparency ()
00720 {
00721 
00722         G4double        TRANSPARENCY = 0.7   ;  // initialization
00723                                                 
00724         if( getenv( "G4VRML_TRANSPARENCY" ) != NULL ) {
00725 
00726                 // get a value from the env value
00727                 sscanf( getenv("G4VRML_TRANSPARENCY"), "%lg", &TRANSPARENCY ) ;
00728 
00729                 // truncation 
00730                 TRANSPARENCY = std::fabs ( TRANSPARENCY ) ; 
00731                 if ( TRANSPARENCY > 1.0 ) { TRANSPARENCY = 1.0 ; }
00732         } 
00733 
00734         fPVTransparency = TRANSPARENCY ;
00735 
00736         return fPVTransparency ;
00737 }
00738 
00739 
00740 void G4VRML2SCENEHANDLER::ClearTransientStore() 
00741 {
00742   // This is typically called after an update and before drawing hits
00743   // of the next event.  To simulate the clearing of "transients"
00744   // (hits, etc.) the detector is redrawn...
00745   if (fpViewer) {
00746     fpViewer -> SetView ();
00747     fpViewer -> ClearView ();
00748     fpViewer -> DrawView ();
00749   }
00750 }
00751 
00752 
00753 // End of file.

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