| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4VRML2SceneHandlerFunc.icc,v 1.21 2010/11/11 00:14:50 akimura Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $
|
|---|
| 29 | //
|
|---|
| 30 | // G4VRML2SceneHandlerFunc.icc
|
|---|
| 31 | // Satoshi Tanaka & Yasuhide Sawada
|
|---|
| 32 |
|
|---|
| 33 | //#define DEBUG_SCENE_FUNC
|
|---|
| 34 |
|
|---|
| 35 | #include "G4VisManager.hh"
|
|---|
| 36 |
|
|---|
| 37 | void G4VRML2SCENEHANDLER::AddSolid(const G4Trd& trd)
|
|---|
| 38 | {
|
|---|
| 39 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 40 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 41 | G4cout << "***** AddSolid trd" << "\n" ;
|
|---|
| 42 | #endif
|
|---|
| 43 | VRMLBeginModeling () ;
|
|---|
| 44 | G4VSceneHandler::AddSolid(trd);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void G4VRML2SCENEHANDLER::AddSolid(const G4Trap& trap)
|
|---|
| 48 | {
|
|---|
| 49 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 50 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 51 | G4cout << "***** AddSolid trap" << "\n" ;
|
|---|
| 52 | #endif
|
|---|
| 53 | VRMLBeginModeling () ;
|
|---|
| 54 | G4VSceneHandler::AddSolid(trap);
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | void G4VRML2SCENEHANDLER::AddSolid(const G4Para& para)
|
|---|
| 58 | {
|
|---|
| 59 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 60 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 61 | G4cout << "***** AddSolid para" << "\n" ;
|
|---|
| 62 | #endif
|
|---|
| 63 | VRMLBeginModeling () ;
|
|---|
| 64 | G4VSceneHandler::AddSolid(para);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | void G4VRML2SCENEHANDLER::AddSolid(const G4Torus& torus )
|
|---|
| 68 | {
|
|---|
| 69 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 70 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 71 | G4cout << "***** AddSolid torus" << "\n" ;
|
|---|
| 72 | #endif
|
|---|
| 73 | VRMLBeginModeling () ;
|
|---|
| 74 | G4VSceneHandler::AddSolid(torus);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | void G4VRML2SCENEHANDLER::AddSolid(const G4VSolid& vsolid)
|
|---|
| 79 | {
|
|---|
| 80 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 81 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 82 | G4cout << "***** AddSolid vsolid" << "\n" ;
|
|---|
| 83 | #endif
|
|---|
| 84 | VRMLBeginModeling () ;
|
|---|
| 85 | G4VSceneHandler::AddSolid(vsolid);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void G4VRML2SCENEHANDLER::AddSolid(const G4Tubs& tubs)
|
|---|
| 89 | {
|
|---|
| 90 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 91 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 92 | G4cout << "***** AddSolid tubs" << "\n" ;
|
|---|
| 93 | #endif
|
|---|
| 94 | VRMLBeginModeling () ;
|
|---|
| 95 | G4VSceneHandler::AddSolid(tubs) ;
|
|---|
| 96 |
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | void G4VRML2SCENEHANDLER::AddSolid(const G4Cons& cons)
|
|---|
| 101 | {
|
|---|
| 102 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 103 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 104 | G4cout << "***** AddSolid cons" << "\n" ;
|
|---|
| 105 | #endif
|
|---|
| 106 | VRMLBeginModeling () ;
|
|---|
| 107 | G4VSceneHandler::AddSolid(cons) ;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | void G4VRML2SCENEHANDLER::AddSolid(const G4Box& box)
|
|---|
| 111 | {
|
|---|
| 112 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 113 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 114 | G4cout << "***** AddSolid box" << "\n" ;
|
|---|
| 115 | #endif
|
|---|
| 116 | VRMLBeginModeling () ;
|
|---|
| 117 | G4VSceneHandler::AddSolid(box) ;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | void G4VRML2SCENEHANDLER::AddSolid(const G4Sphere& sphere)
|
|---|
| 122 | {
|
|---|
| 123 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 124 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 125 | G4cout << "***** AddSolid sphere" << "\n" ;
|
|---|
| 126 | #endif
|
|---|
| 127 | VRMLBeginModeling () ;
|
|---|
| 128 | G4VSceneHandler::AddSolid(sphere) ;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void G4VRML2SCENEHANDLER::AddPrimitive(const G4Polyline& polyline)
|
|---|
| 132 | {
|
|---|
| 133 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 134 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 135 | G4cout << "***** AddPrimitive polyline" << "\n" ;
|
|---|
| 136 | #endif
|
|---|
| 137 |
|
|---|
| 138 | VRMLBeginModeling () ;
|
|---|
| 139 |
|
|---|
| 140 | // VRML codes are generated below
|
|---|
| 141 |
|
|---|
| 142 | fDest << "#---------- POLYLINE" << "\n";
|
|---|
| 143 | fDest << "Shape {" << "\n";
|
|---|
| 144 |
|
|---|
| 145 | SendLineColor ( polyline.GetVisAttributes() );
|
|---|
| 146 |
|
|---|
| 147 | fDest << "\t" << "geometry IndexedLineSet {" << "\n";
|
|---|
| 148 |
|
|---|
| 149 | fDest << "\t\t" << "coord Coordinate {" << "\n";
|
|---|
| 150 | fDest << "\t\t\t" << "point [" << "\n";
|
|---|
| 151 | G4int e, i;
|
|---|
| 152 | for (i = 0, e = polyline.size(); e; i++, e--) {
|
|---|
| 153 |
|
|---|
| 154 | G4Point3D point = polyline[i];
|
|---|
| 155 | point.transform( *fpObjectTransformation );
|
|---|
| 156 |
|
|---|
| 157 | fDest << "\t\t\t\t";
|
|---|
| 158 | fDest << point.x() << " ";
|
|---|
| 159 | fDest << point.y() << " ";
|
|---|
| 160 | fDest << point.z() << "," << "\n";
|
|---|
| 161 |
|
|---|
| 162 | } // for
|
|---|
| 163 |
|
|---|
| 164 | fDest << "\t\t\t" << "]" << "\n"; // point
|
|---|
| 165 | fDest << "\t\t" << "}" << "\n"; // coord
|
|---|
| 166 |
|
|---|
| 167 | fDest << "\t\t" << "coordIndex [";
|
|---|
| 168 | for (i = 0, e = polyline.size(); e; i++, e--) {
|
|---|
| 169 | if (i % 10 == 0)
|
|---|
| 170 | fDest << "\n" << "\t\t\t";
|
|---|
| 171 | fDest << i << ", ";
|
|---|
| 172 | }
|
|---|
| 173 | fDest << "-1" << "\n";
|
|---|
| 174 | fDest << "\t\t" << "]" << "\n"; // coordIndex
|
|---|
| 175 | fDest << "\t" << "}" << "\n"; // geometry IndexedLineSet
|
|---|
| 176 |
|
|---|
| 177 | fDest << "}" << "\n"; // Shape
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | void G4VRML2SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron)
|
|---|
| 182 | {
|
|---|
| 183 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 184 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 185 | G4cout << "***** AddPrimitive(G4Polyhedron)" << "\n";
|
|---|
| 186 | #endif
|
|---|
| 187 |
|
|---|
| 188 | if (polyhedron.GetNoFacets() == 0) return;
|
|---|
| 189 |
|
|---|
| 190 | VRMLBeginModeling () ;
|
|---|
| 191 |
|
|---|
| 192 | // Transparency checking: If completely transparent, skip drawing
|
|---|
| 193 | if ( GetPVTransparency() > 0.99 ) { return ; }
|
|---|
| 194 |
|
|---|
| 195 | // Current Model
|
|---|
| 196 | const G4VModel* pv_model = GetModel();
|
|---|
| 197 | G4String pv_name = "No model";
|
|---|
| 198 | if (pv_model) pv_name = pv_model->GetCurrentTag() ;
|
|---|
| 199 |
|
|---|
| 200 | // VRML codes are generated below
|
|---|
| 201 |
|
|---|
| 202 | fDest << "#---------- SOLID: " << pv_name << "\n";
|
|---|
| 203 |
|
|---|
| 204 | if ( IsPVPickable() ) {
|
|---|
| 205 |
|
|---|
| 206 | fDest << "Anchor {" << "\n";
|
|---|
| 207 | fDest << " description " << "\"" << pv_name << "\"" << "\n";
|
|---|
| 208 | fDest << " url \"\" " << "\n";
|
|---|
| 209 | fDest << " children [" << "\n";
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | fDest << "\t"; fDest << "Shape {" << "\n";
|
|---|
| 213 |
|
|---|
| 214 | SendMaterialNode();
|
|---|
| 215 |
|
|---|
| 216 | fDest << "\t\t" << "geometry IndexedFaceSet {" << "\n";
|
|---|
| 217 |
|
|---|
| 218 | fDest << "\t\t\t" << "coord Coordinate {" << "\n";
|
|---|
| 219 | fDest << "\t\t\t\t" << "point [" << "\n";
|
|---|
| 220 | G4int i, j;
|
|---|
| 221 | for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) {
|
|---|
| 222 | G4Point3D point = polyhedron.GetVertex(i);
|
|---|
| 223 |
|
|---|
| 224 | point.transform( *fpObjectTransformation );
|
|---|
| 225 |
|
|---|
| 226 | fDest << "\t\t\t\t\t";
|
|---|
| 227 | fDest << point.x() << " ";
|
|---|
| 228 | fDest << point.y() << " ";
|
|---|
| 229 | fDest << point.z() << "," << "\n";
|
|---|
| 230 | }
|
|---|
| 231 | fDest << "\t\t\t\t" << "]" << "\n"; // point
|
|---|
| 232 | fDest << "\t\t\t" << "}" << "\n"; // coord
|
|---|
| 233 |
|
|---|
| 234 | fDest << "\t\t\t" << "coordIndex [" << "\n";
|
|---|
| 235 |
|
|---|
| 236 | // facet loop
|
|---|
| 237 | G4int f;
|
|---|
| 238 | for (f = polyhedron.GetNoFacets(); f; f--) {
|
|---|
| 239 |
|
|---|
| 240 | // edge loop
|
|---|
| 241 | G4bool notLastEdge;
|
|---|
| 242 | G4int index = -1, edgeFlag = 1;
|
|---|
| 243 | fDest << "\t\t\t\t";
|
|---|
| 244 | do {
|
|---|
| 245 | notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
|
|---|
| 246 | fDest << index - 1 << ", ";
|
|---|
| 247 | } while (notLastEdge);
|
|---|
| 248 | fDest << "-1," << "\n";
|
|---|
| 249 | }
|
|---|
| 250 | fDest << "\t\t\t" << "]" << "\n"; // coordIndex
|
|---|
| 251 |
|
|---|
| 252 | fDest << "\t\t\t" << "solid FALSE" << "\n"; // draw backfaces
|
|---|
| 253 |
|
|---|
| 254 | fDest << "\t\t" << "}" << "\n"; // IndexFaceSet
|
|---|
| 255 | fDest << "\t" << "}" << "\n"; // Shape
|
|---|
| 256 |
|
|---|
| 257 | if ( IsPVPickable() ) {
|
|---|
| 258 | fDest << " ]" << "\n"; // children
|
|---|
| 259 | fDest << "}" << "\n"; // Anchor
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 | void G4VRML2SCENEHANDLER::AddPrimitive(const G4NURBS&)
|
|---|
| 266 | {
|
|---|
| 267 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 268 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 269 | G4cout << "***** AddPrimitive nurbs" << "\n" ;
|
|---|
| 270 | #endif
|
|---|
| 271 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 272 | G4cout << "G4VRML2File::AddPrimitive(G4NURBS&): not implemented. " << "\n" ;
|
|---|
| 273 |
|
|---|
| 274 | VRMLBeginModeling () ;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | void G4VRML2SCENEHANDLER::AddPrimitive( const G4Text& )
|
|---|
| 278 | {
|
|---|
| 279 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 280 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 281 | G4cout << "***** AddPrimitive text" << "\n" ;
|
|---|
| 282 | #endif
|
|---|
| 283 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 284 | G4cout <<
|
|---|
| 285 | "***** void G4VRML2SCENEHANDLER::AddPrimitive( const G4Text& text )"
|
|---|
| 286 | " not implemented yet."
|
|---|
| 287 | << "\n";
|
|---|
| 288 |
|
|---|
| 289 | VRMLBeginModeling () ;
|
|---|
| 290 |
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | void G4VRML2SCENEHANDLER::AddPrimitive( const G4Circle& circle )
|
|---|
| 294 | {
|
|---|
| 295 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 296 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 297 | G4cout << "***** AddPrimitive circle" << "\n" ;
|
|---|
| 298 | #endif
|
|---|
| 299 | VRMLBeginModeling () ;
|
|---|
| 300 |
|
|---|
| 301 | // Information
|
|---|
| 302 | // const char* info = NULL ;
|
|---|
| 303 | const char* info = circle.GetInfo() ;
|
|---|
| 304 |
|
|---|
| 305 | // Position and half size of circle
|
|---|
| 306 | G4double X, Y, Z ; GetMarkerWorldPosition( circle, &X, &Y, &Z ) ;
|
|---|
| 307 | G4double radius = GetMarkerHalfSize ( circle );
|
|---|
| 308 |
|
|---|
| 309 | // VRML codes are generated below
|
|---|
| 310 | fDest << "#---------- 3D MARKER (Circle)" << "\n";
|
|---|
| 311 | fDest << "Anchor {" << "\n";
|
|---|
| 312 |
|
|---|
| 313 | if( circle.GetInfo().isNull() ) {
|
|---|
| 314 | fDest << " description " << "\"(" << X << " " ;
|
|---|
| 315 | fDest << Y << " " ;
|
|---|
| 316 | fDest << Z << ")\"" << "\n";
|
|---|
| 317 | } else {
|
|---|
| 318 | fDest << " description " << "\"" << info << "\"" << "\n";
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 | fDest << " url \"\" " << "\n";
|
|---|
| 323 |
|
|---|
| 324 | fDest << " children [" << "\n";
|
|---|
| 325 |
|
|---|
| 326 | fDest << " Transform {" << "\n";
|
|---|
| 327 |
|
|---|
| 328 | fDest << " translation ";
|
|---|
| 329 | fDest << X << " " << Y << " " << Z << "\n";
|
|---|
| 330 |
|
|---|
| 331 | fDest << " children [" << "\n";
|
|---|
| 332 |
|
|---|
| 333 | fDest << "\t" << "Shape {" << "\n";
|
|---|
| 334 |
|
|---|
| 335 | SendMarkerColor( circle );
|
|---|
| 336 |
|
|---|
| 337 | // send shape with size
|
|---|
| 338 | fDest << "\t\t" << "geometry Sphere {" << "\n";
|
|---|
| 339 | fDest << "\t\t\t" << "radius " << radius << "\n";
|
|---|
| 340 | fDest << "\t\t" << "}" << "\n";
|
|---|
| 341 |
|
|---|
| 342 | fDest << "\t" << "}" << "\n"; // Shape
|
|---|
| 343 |
|
|---|
| 344 | fDest << " ]" << "\n"; // children
|
|---|
| 345 | fDest << " }" << "\n"; // Transform
|
|---|
| 346 |
|
|---|
| 347 | fDest << " ]" << "\n"; // children
|
|---|
| 348 | fDest << "}" << "\n"; // Anchor
|
|---|
| 349 |
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | void G4VRML2SCENEHANDLER::AddPrimitive(const G4Square& square)
|
|---|
| 353 | {
|
|---|
| 354 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 355 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 356 | G4cout << "***** AddPrimitive square" << "\n" ;
|
|---|
| 357 | #endif
|
|---|
| 358 |
|
|---|
| 359 | VRMLBeginModeling () ;
|
|---|
| 360 |
|
|---|
| 361 | // Information
|
|---|
| 362 | // const char* info = NULL ;
|
|---|
| 363 | const char* info = square.GetInfo() ;
|
|---|
| 364 |
|
|---|
| 365 | // Position and size of square
|
|---|
| 366 | G4double X, Y, Z ; GetMarkerWorldPosition ( square, &X, &Y, &Z ) ;
|
|---|
| 367 | G4double radius = GetMarkerHalfSize ( square );
|
|---|
| 368 | G4double diameter = 2.0 * radius ;
|
|---|
| 369 |
|
|---|
| 370 | // VRML codes are generated below
|
|---|
| 371 | fDest << "#---------- 3D MARKER (Square)" << "\n";
|
|---|
| 372 | fDest << "Anchor {" << "\n";
|
|---|
| 373 |
|
|---|
| 374 | if( square.GetInfo().isNull() ) {
|
|---|
| 375 | fDest << " description " << "\"(" << X << " " ;
|
|---|
| 376 | fDest << Y << " " ;
|
|---|
| 377 | fDest << Z << ")\"" << "\n";
|
|---|
| 378 | } else {
|
|---|
| 379 | fDest << " description " << "\"" << info << "\"" << "\n";
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | fDest << " url \"\" " << "\n";
|
|---|
| 383 |
|
|---|
| 384 | fDest << " children [" << "\n";
|
|---|
| 385 |
|
|---|
| 386 | fDest << " Transform {" << "\n";
|
|---|
| 387 |
|
|---|
| 388 | fDest << " translation ";
|
|---|
| 389 | fDest << X << " " << Y << " " << Z << "\n";
|
|---|
| 390 |
|
|---|
| 391 | fDest << " children [" << "\n";
|
|---|
| 392 |
|
|---|
| 393 | fDest << "\t" << "Shape {" << "\n";
|
|---|
| 394 |
|
|---|
| 395 | SendMarkerColor( square );
|
|---|
| 396 |
|
|---|
| 397 | // send shape with size
|
|---|
| 398 | fDest << "\t\t" << "geometry Box {" << "\n";
|
|---|
| 399 | fDest << "\t\t\t" << "size " << diameter << " " ;
|
|---|
| 400 | fDest << diameter << " " ;
|
|---|
| 401 | fDest << diameter << "\n" ;
|
|---|
| 402 | fDest << "\t\t" << "}" << "\n";
|
|---|
| 403 |
|
|---|
| 404 | fDest << "\t" << "}" << "\n"; // Shape
|
|---|
| 405 |
|
|---|
| 406 | fDest << " ]" << "\n"; // children
|
|---|
| 407 | fDest << " }" << "\n"; // Transform
|
|---|
| 408 |
|
|---|
| 409 | fDest << " ]" << "\n"; // children
|
|---|
| 410 | fDest << "}" << "\n"; // Anchor
|
|---|
| 411 |
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | void G4VRML2SCENEHANDLER::BeginModeling()
|
|---|
| 415 | {
|
|---|
| 416 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 417 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 418 | G4cout << "***** BeginModeling" << "\n" ;
|
|---|
| 419 | #endif
|
|---|
| 420 | G4VSceneHandler::BeginModeling();
|
|---|
| 421 |
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | void G4VRML2SCENEHANDLER::EndModeling()
|
|---|
| 425 | {
|
|---|
| 426 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 427 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 428 | G4cout << "***** EndModeling " << "\n" ;
|
|---|
| 429 | #endif
|
|---|
| 430 | G4VSceneHandler::EndModeling();
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | void G4VRML2SCENEHANDLER::BeginPrimitives(const G4Transform3D& objectTransformation)
|
|---|
| 434 | {
|
|---|
| 435 | G4VSceneHandler::BeginPrimitives (objectTransformation);
|
|---|
| 436 | fpObjectTransformation = &objectTransformation;
|
|---|
| 437 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 438 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 439 | G4cout << "***** BeginPrimitives " << "\n" ;
|
|---|
| 440 | #endif
|
|---|
| 441 | VRMLBeginModeling();
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | void G4VRML2SCENEHANDLER::EndPrimitives()
|
|---|
| 445 | {
|
|---|
| 446 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 447 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 448 | G4cout << "***** EndPrimitives " << "\n" ;
|
|---|
| 449 | #endif
|
|---|
| 450 | G4VSceneHandler::EndPrimitives();
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | void G4VRML2SCENEHANDLER::SendMaterialNode( const G4VisAttributes* pVA )
|
|---|
| 454 | {
|
|---|
| 455 | // Initialization of drawing parameters
|
|---|
| 456 | G4bool flagWF = false ;
|
|---|
| 457 | G4double TRANSPARENCY = GetPVTransparency() ;
|
|---|
| 458 |
|
|---|
| 459 | // Wireframe or not
|
|---|
| 460 | const G4ViewParameters& cur_view_param = fpViewer -> GetViewParameters ();
|
|---|
| 461 | if (pVA->IsForceDrawingStyle() &&
|
|---|
| 462 | (pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe))
|
|---|
| 463 | {
|
|---|
| 464 | // wireframe style is assigned to this object
|
|---|
| 465 | flagWF = true ;
|
|---|
| 466 |
|
|---|
| 467 | } else if ( cur_view_param.GetDrawingStyle() == G4ViewParameters::wireframe )
|
|---|
| 468 | {
|
|---|
| 469 | // current viewing style is wireframe
|
|---|
| 470 | flagWF = true ;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | // VRML codes are generated below
|
|---|
| 474 | if (!pVA) {
|
|---|
| 475 |
|
|---|
| 476 | // Error recovery: Use default values of VRML browser
|
|---|
| 477 | fDest << "\t\t" ;
|
|---|
| 478 | fDest << "appearance Appearance { material Material {} }";
|
|---|
| 479 | fDest << "\n";
|
|---|
| 480 |
|
|---|
| 481 | } else {
|
|---|
| 482 |
|
|---|
| 483 | const G4Color& color = pVA->GetColor();
|
|---|
| 484 |
|
|---|
| 485 | fDest << "\t\t" << "appearance Appearance {" << "\n";
|
|---|
| 486 | fDest << "\t\t\t" << "material Material {" << "\n";
|
|---|
| 487 |
|
|---|
| 488 | // diffuse color
|
|---|
| 489 | fDest << "\t\t\t\t" << "diffuseColor ";
|
|---|
| 490 | fDest << color.GetRed() << " " ;
|
|---|
| 491 | fDest << color.GetGreen() << " " ;
|
|---|
| 492 | fDest << color.GetBlue() << "\n";
|
|---|
| 493 |
|
|---|
| 494 | // emmisive color
|
|---|
| 495 | // fDest << "\t\t\t\t" << "emissiveColor ";
|
|---|
| 496 | // fDest << color.GetRed() << " " ;
|
|---|
| 497 | // fDest << color.GetGreen() << " " ;
|
|---|
| 498 | //fDest << color.GetBlue() << "\n";
|
|---|
| 499 | //
|
|---|
| 500 |
|
|---|
| 501 | // wireframe is expressed as transparency
|
|---|
| 502 | if ( flagWF )
|
|---|
| 503 | {
|
|---|
| 504 | fDest << "\t\t\t\t" << "transparency " << TRANSPARENCY << "\n";
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | fDest << "\t\t\t" << "}" << "\n"; // material
|
|---|
| 508 | fDest << "\t\t" << "}" << "\n"; // appearance
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 | }
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 | void G4VRML2SCENEHANDLER::SendMaterialNode()
|
|---|
| 515 | {
|
|---|
| 516 | SendMaterialNode
|
|---|
| 517 | ( fpViewer->GetApplicableVisAttributes (fpVisAttribs) );
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 | void G4VRML2SCENEHANDLER::VRMLBeginModeling()
|
|---|
| 522 | {
|
|---|
| 523 | if (!IS_CONNECTED ) {
|
|---|
| 524 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 525 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 526 | G4cout << "***** VRMLBeginModeling (started)" << "\n" ;
|
|---|
| 527 | #endif
|
|---|
| 528 | this->connectPort();
|
|---|
| 529 | fDest << "#VRML V2.0 utf8" << "\n";
|
|---|
| 530 | fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n";
|
|---|
| 531 | }
|
|---|
| 532 | }
|
|---|
| 533 |
|
|---|
| 534 | void G4VRML2SCENEHANDLER::VRMLEndModeling()
|
|---|
| 535 | {
|
|---|
| 536 | if ( IS_CONNECTED ) {
|
|---|
| 537 | #if defined DEBUG_SCENE_FUNC
|
|---|
| 538 | if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
|
|---|
| 539 | G4cout << "***** VRMLEndModeling (started)" << "\n" ;
|
|---|
| 540 | #endif
|
|---|
| 541 | fDest << "#End of file." << "\n";
|
|---|
| 542 | this->closePort();
|
|---|
| 543 | }
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | void G4VRML2SCENEHANDLER::SendMarkerColor ( const G4VMarker& mark )
|
|---|
| 547 | {
|
|---|
| 548 | const G4Color& color = GetColor( mark );
|
|---|
| 549 |
|
|---|
| 550 | fDest << "\t\t" << "appearance Appearance {" << "\n";
|
|---|
| 551 | fDest << "\t\t\t" << "material Material {" << "\n";
|
|---|
| 552 | fDest << "\t\t\t\t" << "diffuseColor ";
|
|---|
| 553 | fDest << color.GetRed() << " " ;
|
|---|
| 554 | fDest << color.GetGreen() << " " ;
|
|---|
| 555 | fDest << color.GetBlue() << "\n";
|
|---|
| 556 | fDest << "\t\t\t\t" << "emissiveColor ";
|
|---|
| 557 | fDest << color.GetRed() << " " ;
|
|---|
| 558 | fDest << color.GetGreen() << " " ;
|
|---|
| 559 | fDest << color.GetBlue() << "\n";
|
|---|
| 560 | fDest << "\t\t\t" << "}" << "\n"; // material
|
|---|
| 561 | fDest << "\t\t" << "}" << "\n"; // appearance
|
|---|
| 562 |
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | void
|
|---|
| 566 | G4VRML2SCENEHANDLER::SendMarkerWorldPosition ( const G4VMarker& mark )
|
|---|
| 567 | {
|
|---|
| 568 | G4Point3D point = mark.GetPosition();
|
|---|
| 569 |
|
|---|
| 570 | point.transform( *fpObjectTransformation );
|
|---|
| 571 |
|
|---|
| 572 | fDest << " translation ";
|
|---|
| 573 | fDest << point.x() << " " << point.y() << " " << point.z() << "\n";
|
|---|
| 574 |
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | void G4VRML2SCENEHANDLER::GetMarkerWorldPosition ( const G4VMarker& mark ,
|
|---|
| 578 | double* pX ,
|
|---|
| 579 | double* pY ,
|
|---|
| 580 | double* pZ )
|
|---|
| 581 | {
|
|---|
| 582 | G4Point3D point = mark.GetPosition();
|
|---|
| 583 |
|
|---|
| 584 | point.transform( *fpObjectTransformation );
|
|---|
| 585 |
|
|---|
| 586 | *pX = point.x() ;
|
|---|
| 587 | *pY = point.y() ;
|
|---|
| 588 | *pZ = point.z() ;
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | G4double G4VRML2SCENEHANDLER::GetMarkerHalfSize ( const G4VMarker& mark )
|
|---|
| 592 | {
|
|---|
| 593 | //----- return value ( marker radius in 3d units)
|
|---|
| 594 | G4double size = 1.0 ; // initialization
|
|---|
| 595 |
|
|---|
| 596 | //----- parameters to calculate 3d size from 2d size
|
|---|
| 597 | const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels
|
|---|
| 598 | double zoom_factor = fpViewer->GetViewParameters().GetZoomFactor() ;
|
|---|
| 599 | if ( zoom_factor <= 0.0 ) { zoom_factor = 1.0 ; }
|
|---|
| 600 | double extent_radius_3d = GetScene()->GetExtent().GetExtentRadius() ;
|
|---|
| 601 | if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; }
|
|---|
| 602 |
|
|---|
| 603 | //----- get marker radius in 3D units
|
|---|
| 604 | if ( mark.GetWorldSize() > 0.0 ) {
|
|---|
| 605 |
|
|---|
| 606 | // get mark radius in 3D units
|
|---|
| 607 | size = 0.5 * mark.GetWorldSize() ;
|
|---|
| 608 |
|
|---|
| 609 | } else if ( mark.GetScreenSize() > 0.0 ) {
|
|---|
| 610 |
|
|---|
| 611 | // local
|
|---|
| 612 | double mark_radius_2d = 0.5 * mark.GetScreenSize() ;
|
|---|
| 613 |
|
|---|
| 614 | // get mark radius in 3D units
|
|---|
| 615 | size \
|
|---|
| 616 | = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
|
|---|
| 617 | size *= zoom_factor ;
|
|---|
| 618 |
|
|---|
| 619 | } else {
|
|---|
| 620 | // local
|
|---|
| 621 | double mark_radius_2d \
|
|---|
| 622 | = fpViewer->GetViewParameters().GetDefaultMarker().GetScreenSize();
|
|---|
| 623 | mark_radius_2d *= 0.1 ; // Magic number?
|
|---|
| 624 |
|
|---|
| 625 | // get mark radius in 3D units
|
|---|
| 626 | size \
|
|---|
| 627 | = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
|
|---|
| 628 | size *= zoom_factor ;
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | //----- global rescaling
|
|---|
| 632 | size *= fpViewer->GetViewParameters().GetGlobalMarkerScale();
|
|---|
| 633 |
|
|---|
| 634 | //----- return size
|
|---|
| 635 | return size ;
|
|---|
| 636 |
|
|---|
| 637 | }
|
|---|
| 638 |
|
|---|
| 639 | void G4VRML2SCENEHANDLER::SendLineColor ( const G4VisAttributes* pVA )
|
|---|
| 640 | {
|
|---|
| 641 | const G4Color& color = pVA->GetColor();
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 | fDest << "\t" << "appearance Appearance {" << "\n";
|
|---|
| 645 | fDest << "\t\t" << "material Material {" << "\n";
|
|---|
| 646 | fDest << "\t\t\t" << "diffuseColor ";
|
|---|
| 647 | fDest << color.GetRed() << " " ;
|
|---|
| 648 | fDest << color.GetGreen() << " " ;
|
|---|
| 649 | fDest << color.GetBlue() << "\n";
|
|---|
| 650 | fDest << "\t\t\t" << "emissiveColor ";
|
|---|
| 651 | fDest << color.GetRed() << " " ;
|
|---|
| 652 | fDest << color.GetGreen() << " " ;
|
|---|
| 653 | fDest << color.GetBlue() << "\n";
|
|---|
| 654 | fDest << "\t\t" << "}" << "\n"; // material
|
|---|
| 655 | fDest << "\t" << "}" << "\n"; // appearance
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | G4double G4VRML2SCENEHANDLER::SetPVTransparency ()
|
|---|
| 659 | {
|
|---|
| 660 |
|
|---|
| 661 | G4double TRANSPARENCY = 0.7 ; // initialization
|
|---|
| 662 |
|
|---|
| 663 | if( getenv( "G4VRML_TRANSPARENCY" ) != NULL ) {
|
|---|
| 664 |
|
|---|
| 665 | // get a value from the env value
|
|---|
| 666 | sscanf( getenv("G4VRML_TRANSPARENCY"), "%lg", &TRANSPARENCY ) ;
|
|---|
| 667 |
|
|---|
| 668 | // truncation
|
|---|
| 669 | TRANSPARENCY = std::fabs ( TRANSPARENCY ) ;
|
|---|
| 670 | if ( TRANSPARENCY > 1.0 ) { TRANSPARENCY = 1.0 ; }
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | fPVTransparency = TRANSPARENCY ;
|
|---|
| 674 |
|
|---|
| 675 | return fPVTransparency ;
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 | void G4VRML2SCENEHANDLER::ClearTransientStore()
|
|---|
| 680 | {
|
|---|
| 681 | G4VSceneHandler::ClearTransientStore ();
|
|---|
| 682 | // This is typically called after an update and before drawing hits
|
|---|
| 683 | // of the next event. To simulate the clearing of "transients"
|
|---|
| 684 | // (hits, etc.) the detector is redrawn...
|
|---|
| 685 | if (fpViewer) {
|
|---|
| 686 | fpViewer -> SetView ();
|
|---|
| 687 | fpViewer -> ClearView ();
|
|---|
| 688 | fpViewer -> DrawView ();
|
|---|
| 689 | }
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 | // End of file.
|
|---|