[834] | 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: G4VRML1SceneHandlerFunc.icc,v 1.16 2006/06/29 21:26:03 gunter Exp $ |
---|
[944] | 28 | // GEANT4 tag $Name: $ |
---|
[834] | 29 | // |
---|
| 30 | // G4VRML1SceneHandlerFunc.icc |
---|
| 31 | // Satoshi Tanaka & Yasuhide Sawada |
---|
| 32 | |
---|
| 33 | //#define DEBUG_SCENE_FUNC |
---|
| 34 | |
---|
| 35 | // MACRO |
---|
| 36 | #define ADDTHIS_WITH_NAME(Solid) \ |
---|
| 37 | fCurrentDEF = #Solid "_" + Solid.GetName(); \ |
---|
| 38 | RequestPrimitives(Solid); \ |
---|
| 39 | fCurrentDEF = ""; |
---|
| 40 | |
---|
| 41 | // End of MACRO |
---|
| 42 | |
---|
| 43 | void G4VRML1SCENEHANDLER::AddSolid(const G4Trd& trd) |
---|
| 44 | { |
---|
| 45 | #if defined DEBUG_SCENE_FUNC |
---|
| 46 | G4cerr << "***** AddSolid trd" << "\n" ; |
---|
| 47 | #endif |
---|
| 48 | VRMLBeginModeling () ; |
---|
| 49 | ADDTHIS_WITH_NAME(trd) |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void G4VRML1SCENEHANDLER::AddSolid(const G4Trap& trap) |
---|
| 53 | { |
---|
| 54 | #if defined DEBUG_SCENE_FUNC |
---|
| 55 | G4cerr << "***** AddSolid trap" << "\n" ; |
---|
| 56 | #endif |
---|
| 57 | VRMLBeginModeling () ; |
---|
| 58 | ADDTHIS_WITH_NAME(trap) |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void G4VRML1SCENEHANDLER::AddSolid(const G4Para& para) |
---|
| 62 | { |
---|
| 63 | #if defined DEBUG_SCENE_FUNC |
---|
| 64 | G4cerr << "***** AddSolid para" << "\n" ; |
---|
| 65 | #endif |
---|
| 66 | VRMLBeginModeling () ; |
---|
| 67 | ADDTHIS_WITH_NAME(para) |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void G4VRML1SCENEHANDLER::AddSolid(const G4Torus& torus ) |
---|
| 71 | { |
---|
| 72 | #if defined DEBUG_SCENE_FUNC |
---|
| 73 | G4cerr << "***** AddSolid torus" << "\n" ; |
---|
| 74 | #endif |
---|
| 75 | VRMLBeginModeling () ; |
---|
| 76 | ADDTHIS_WITH_NAME(torus) |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | void G4VRML1SCENEHANDLER::AddSolid(const G4VSolid& vsolid) |
---|
| 81 | { |
---|
| 82 | #if defined DEBUG_SCENE_FUNC |
---|
| 83 | G4cerr << "***** AddSolid vsolid" << "\n" ; |
---|
| 84 | #endif |
---|
| 85 | VRMLBeginModeling () ; |
---|
| 86 | ADDTHIS_WITH_NAME(vsolid) |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void G4VRML1SCENEHANDLER::AddSolid(const G4Tubs& tubs) |
---|
| 90 | { |
---|
| 91 | #if defined DEBUG_SCENE_FUNC |
---|
| 92 | G4cerr << "***** AddSolid tubs" << "\n" ; |
---|
| 93 | #endif |
---|
| 94 | VRMLBeginModeling () ; |
---|
| 95 | |
---|
| 96 | // set current name |
---|
| 97 | fCurrentDEF = "tubs_" + tubs.GetName(); |
---|
| 98 | |
---|
| 99 | // Get data |
---|
| 100 | const G4double R = tubs.GetRMax(); // outside radius |
---|
| 101 | const G4double r = tubs.GetRMin(); // inside radius |
---|
| 102 | const G4double dz = tubs.GetDz(); // half length in z |
---|
| 103 | const G4double dp = tubs.GetDPhi(); // angle interval |
---|
| 104 | |
---|
| 105 | // Send data |
---|
| 106 | if ( r == 0.0 && dp >= 360. * deg ) { |
---|
| 107 | // Send a built-in VRML node (Cylinder) |
---|
| 108 | fDest << "Separator {" << "\n"; |
---|
| 109 | SendMatrixTransformNode( fpObjectTransformation ); |
---|
| 110 | |
---|
| 111 | fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n"; |
---|
| 112 | SendMaterialNode(); |
---|
| 113 | SendCylinderNode(R, dz * 2); |
---|
| 114 | fDest << "\t" << "}" << "\n"; // DEF Separator |
---|
| 115 | fDest << "}" << "\n"; // Separator |
---|
| 116 | } else { |
---|
| 117 | // call AddPrimitive(Polyhedron) |
---|
| 118 | RequestPrimitives(tubs); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // reset current name to null |
---|
| 122 | fCurrentDEF = ""; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | void G4VRML1SCENEHANDLER::AddSolid(const G4Cons& cons) |
---|
| 127 | { |
---|
| 128 | #if defined DEBUG_SCENE_FUNC |
---|
| 129 | G4cerr << "***** AddSolid cons" << "\n" ; |
---|
| 130 | #endif |
---|
| 131 | VRMLBeginModeling () ; |
---|
| 132 | |
---|
| 133 | // set current name |
---|
| 134 | fCurrentDEF = "cons_" + cons.GetName(); |
---|
| 135 | |
---|
| 136 | // Get data |
---|
| 137 | const G4double r1 = cons.GetRmin1(); // inside radius at -dz |
---|
| 138 | const G4double R1 = cons.GetRmax1(); // outside radius at -dz |
---|
| 139 | const G4double r2 = cons.GetRmin2(); // inside radius at +dz |
---|
| 140 | const G4double R2 = cons.GetRmax2(); // outside radius at +dz |
---|
| 141 | const G4double dz = cons.GetDz(); // half length in z |
---|
| 142 | //const G4double sp = cons.GetSPhi(); // starting angle |
---|
| 143 | const G4double dp = cons.GetDPhi(); // angle width |
---|
| 144 | |
---|
| 145 | // Send data |
---|
| 146 | if ( r1 == 0.0 && r2 == 0.0 && R1 == R2 && dp >= 360. * deg) { |
---|
| 147 | // Send a built-in VRML node (Cylinder) |
---|
| 148 | fDest << "Separator {" << "\n"; |
---|
| 149 | SendMatrixTransformNode( fpObjectTransformation ); |
---|
| 150 | |
---|
| 151 | fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n"; |
---|
| 152 | SendMaterialNode(); |
---|
| 153 | SendCylinderNode(R1, dz * 2); |
---|
| 154 | fDest << "\t" << "}" << "\n"; // DEF Separator |
---|
| 155 | fDest << "}" << "\n"; // Separator |
---|
| 156 | } else { |
---|
| 157 | // call AddPrimitive(Polyhedron) |
---|
| 158 | RequestPrimitives(cons); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // reset current name to null |
---|
| 162 | fCurrentDEF = ""; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | void G4VRML1SCENEHANDLER::AddSolid(const G4Box& box) |
---|
| 166 | { |
---|
| 167 | #if defined DEBUG_SCENE_FUNC |
---|
| 168 | G4cerr << "***** AddSolid box" << "\n" ; |
---|
| 169 | #endif |
---|
| 170 | VRMLBeginModeling () ; |
---|
| 171 | |
---|
| 172 | // set current name |
---|
| 173 | fCurrentDEF = "box_" + box.GetName(); |
---|
| 174 | |
---|
| 175 | // Send a built-in VRML node (Cube) |
---|
| 176 | fDest << "Separator {" << "\n"; |
---|
| 177 | |
---|
| 178 | //fDest << "\t" << "renderCulling ON" << "\n"; |
---|
| 179 | SendMatrixTransformNode( fpObjectTransformation ); |
---|
| 180 | |
---|
| 181 | fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n"; |
---|
| 182 | SendMaterialNode(); |
---|
| 183 | SendCubeNode(box.GetXHalfLength() * 2, box.GetYHalfLength() * 2, box.GetZHalfLength() * 2); |
---|
| 184 | fDest << "\t" << "}" << "\n"; // DEF Separator |
---|
| 185 | |
---|
| 186 | fDest << "}" << "\n"; // Separator |
---|
| 187 | |
---|
| 188 | // reset current name to null |
---|
| 189 | fCurrentDEF = ""; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | void G4VRML1SCENEHANDLER::AddSolid(const G4Sphere& sphere) |
---|
| 194 | { |
---|
| 195 | #if defined DEBUG_SCENE_FUNC |
---|
| 196 | G4cerr << "***** AddSolid sphere" << "\n" ; |
---|
| 197 | #endif |
---|
| 198 | VRMLBeginModeling () ; |
---|
| 199 | |
---|
| 200 | // set current name |
---|
| 201 | fCurrentDEF = "sphere_" + sphere.GetName(); |
---|
| 202 | |
---|
| 203 | // Get data |
---|
| 204 | G4double dphi = sphere.GetDPhi () ; |
---|
| 205 | G4double dtheta = sphere.GetDTheta() ; |
---|
| 206 | G4double rmax = sphere.GetRmax () ; |
---|
| 207 | G4double rmin = sphere.GetRmin () ; |
---|
| 208 | |
---|
| 209 | // Send data |
---|
| 210 | if ( (dphi >= 360. * deg) && (dtheta >= 180. * deg) && (rmin == 0.0) ) { |
---|
| 211 | // Send a built-in VRML node (Sphere) |
---|
| 212 | fDest << "Separator {" << "\n"; |
---|
| 213 | SendMatrixTransformNode( fpObjectTransformation ); |
---|
| 214 | |
---|
| 215 | fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n"; |
---|
| 216 | SendMaterialNode(); |
---|
| 217 | SendSphereNode( rmax ); |
---|
| 218 | fDest << "\t" << "}" << "\n"; // DEF Separator |
---|
| 219 | fDest << "}" << "\n"; // Separator |
---|
| 220 | } else { |
---|
| 221 | // call AddPrimitive(Polyhedron) |
---|
| 222 | RequestPrimitives( sphere ); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | // reset current name to null |
---|
| 226 | fCurrentDEF = ""; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyline& polyline) |
---|
| 230 | { |
---|
| 231 | #if defined DEBUG_SCENE_FUNC |
---|
| 232 | G4cerr << "***** AddPrimitive polyline" << "\n" ; |
---|
| 233 | #endif |
---|
| 234 | VRMLBeginModeling () ; |
---|
| 235 | |
---|
| 236 | fDest << "Separator {" << "\n"; |
---|
| 237 | |
---|
| 238 | SendMatrixTransformNode (fpObjectTransformation ); |
---|
| 239 | |
---|
| 240 | SendMaterialNode( polyline.GetVisAttributes() ); |
---|
| 241 | |
---|
| 242 | fDest << "\t" << "Coordinate3 {" << "\n"; |
---|
| 243 | fDest << "\t\t" << "point [" << "\n"; |
---|
| 244 | G4int e, i; |
---|
| 245 | for (i = 0, e = polyline.size(); e; i++, e--) { |
---|
| 246 | fDest << "\t\t\t"; |
---|
| 247 | fDest << polyline[i].x() << " "; |
---|
| 248 | fDest << polyline[i].y() << " "; |
---|
| 249 | fDest << polyline[i].z() << "," << "\n"; |
---|
| 250 | } |
---|
| 251 | fDest << "\t\t" << "]" << "\n"; |
---|
| 252 | fDest << "\t" << "}" << "\n"; // Coordinate3 |
---|
| 253 | |
---|
| 254 | fDest << "\t" << "IndexedLineSet {" << "\n"; |
---|
| 255 | fDest << "\t\t" << "coordIndex ["; |
---|
| 256 | for (i = 0, e = polyline.size(); e; i++, e--) { |
---|
| 257 | if (i % 10 == 0) |
---|
| 258 | fDest << "\n" << "\t\t\t"; |
---|
| 259 | fDest << i << ", "; |
---|
| 260 | } |
---|
| 261 | fDest << "-1" << "\n"; |
---|
| 262 | fDest << "\t\t" << "]" << "\n"; |
---|
| 263 | fDest << "\t" << "}" << "\n"; // IndexedLineSet |
---|
| 264 | |
---|
| 265 | fDest << "}" << "\n"; // Separator |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron) |
---|
| 269 | { |
---|
| 270 | #if defined DEBUG_SCENE_FUNC |
---|
| 271 | G4cerr << "***** AddPrimitive(G4Polyhedron)" << "\n"; |
---|
| 272 | #endif |
---|
| 273 | |
---|
| 274 | if (polyhedron.GetNoFacets() == 0) return; |
---|
| 275 | |
---|
| 276 | VRMLBeginModeling () ; |
---|
| 277 | |
---|
| 278 | fDest << "Separator {" << "\n"; |
---|
| 279 | |
---|
| 280 | SendMatrixTransformNode( fpObjectTransformation ); |
---|
| 281 | |
---|
| 282 | fDest << "\t"; |
---|
| 283 | if (fCurrentDEF != "") |
---|
| 284 | fDest << "DEF " << fCurrentDEF << " "; |
---|
| 285 | |
---|
| 286 | fDest << "Separator {" << "\n"; |
---|
| 287 | |
---|
| 288 | //fDest << "\t\t" << "renderCulling ON" << "\n"; |
---|
| 289 | |
---|
| 290 | fDest << "\t\t" << "ShapeHints {" << "\n"; |
---|
| 291 | fDest << "\t\t\t" << "vertexOrdering COUNTERCLOCKWISE" << "\n"; |
---|
| 292 | fDest << "\t\t\t" << "shapeType SOLID" << "\n"; |
---|
| 293 | fDest << "\t\t\t" << "faceType CONVEX" << "\n"; |
---|
| 294 | fDest << "\t\t" << "}" << "\n"; |
---|
| 295 | |
---|
| 296 | SendMaterialNode(); |
---|
| 297 | |
---|
| 298 | fDest << "\t\t" << "Coordinate3 {" << "\n"; |
---|
| 299 | fDest << "\t\t\t" << "point [" << "\n"; |
---|
| 300 | G4int i, j; |
---|
| 301 | for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) { |
---|
| 302 | G4Point3D point = polyhedron.GetVertex(i); |
---|
| 303 | fDest << "\t\t\t\t"; |
---|
| 304 | fDest << point.x() << " "; |
---|
| 305 | fDest << point.y() << " "; |
---|
| 306 | fDest << point.z() << "," << "\n"; |
---|
| 307 | } |
---|
| 308 | fDest << "\t\t\t" << "]" << "\n"; |
---|
| 309 | fDest << "\t\t" << "}" << "\n"; // Coordinate3 |
---|
| 310 | |
---|
| 311 | fDest << "\t\t" << "IndexedFaceSet {" << "\n"; |
---|
| 312 | fDest << "\t\t\t" << "coordIndex [" << "\n"; |
---|
| 313 | |
---|
| 314 | // facet loop |
---|
| 315 | G4int f; |
---|
| 316 | for (f = polyhedron.GetNoFacets(); f; f--) { |
---|
| 317 | |
---|
| 318 | // edge loop |
---|
| 319 | G4bool notLastEdge; |
---|
| 320 | G4int index = -1, edgeFlag = 1; |
---|
| 321 | fDest << "\t\t\t\t"; |
---|
| 322 | do { |
---|
| 323 | notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag); |
---|
| 324 | fDest << index - 1 << ", "; |
---|
| 325 | } while (notLastEdge); |
---|
| 326 | fDest << "-1," << "\n"; |
---|
| 327 | } |
---|
| 328 | fDest << "\t\t\t" << "]" << "\n"; |
---|
| 329 | fDest << "\t\t" << "}" << "\n"; // IndexFaceSet |
---|
| 330 | |
---|
| 331 | fDest << "\t" << "}" << "\n"; // (DEF) Separator |
---|
| 332 | fDest << "}" << "\n"; // Separator |
---|
| 333 | |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | void G4VRML1SCENEHANDLER::AddPrimitive(const G4NURBS&) |
---|
| 338 | { |
---|
| 339 | #if defined DEBUG_SCENE_FUNC |
---|
| 340 | G4cerr << "***** AddPrimitive nurbs" << "\n" ; |
---|
| 341 | #endif |
---|
| 342 | G4cerr << "G4VRML1File::AddPrimitive(G4NURBS&): not implemented. " << "\n" ; |
---|
| 343 | VRMLBeginModeling () ; |
---|
| 344 | |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& ) |
---|
| 348 | { |
---|
| 349 | #if defined DEBUG_SCENE_FUNC |
---|
| 350 | G4cerr << "***** AddPrimitive text" << "\n" ; |
---|
| 351 | #endif |
---|
| 352 | G4cerr << |
---|
| 353 | "***** void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& text )" |
---|
| 354 | " not implemented yet." |
---|
| 355 | << "\n"; |
---|
| 356 | |
---|
| 357 | VRMLBeginModeling () ; |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | void G4VRML1SCENEHANDLER::AddPrimitive( const G4Circle& circle ) |
---|
| 361 | { |
---|
| 362 | #if defined DEBUG_SCENE_FUNC |
---|
| 363 | G4cerr << "***** AddPrimitive circle" << "\n" ; |
---|
| 364 | #endif |
---|
| 365 | |
---|
| 366 | VRMLBeginModeling () ; |
---|
| 367 | |
---|
| 368 | // begin sending a mark |
---|
| 369 | fDest << "Separator {" << "\n"; |
---|
| 370 | |
---|
| 371 | // send color |
---|
| 372 | SendMarkerColor ( circle ) ; |
---|
| 373 | |
---|
| 374 | // position |
---|
| 375 | SendMarkerWorldPosition ( circle ) ; |
---|
| 376 | |
---|
| 377 | // Calc size |
---|
| 378 | G4double size = GetMarkerHalfSize ( circle ); |
---|
| 379 | |
---|
| 380 | // send shape with size |
---|
| 381 | fDest << "\t" << "Sphere {" << "\n"; |
---|
| 382 | fDest << "\t\t" << "radius " << size << "\n"; |
---|
| 383 | fDest << "\t" << "}" << "\n"; |
---|
| 384 | |
---|
| 385 | // end sending a mark |
---|
| 386 | fDest << "}" << "\n"; // Separator |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | void G4VRML1SCENEHANDLER::AddPrimitive(const G4Square& square) |
---|
| 391 | { |
---|
| 392 | #if defined DEBUG_SCENE_FUNC |
---|
| 393 | G4cerr << "***** AddPrimitive square" << "\n" ; |
---|
| 394 | #endif |
---|
| 395 | |
---|
| 396 | VRMLBeginModeling () ; |
---|
| 397 | |
---|
| 398 | // begin sending a mark |
---|
| 399 | fDest << "Separator {" << "\n"; |
---|
| 400 | |
---|
| 401 | // send color |
---|
| 402 | SendMarkerColor ( square ); |
---|
| 403 | |
---|
| 404 | // position |
---|
| 405 | SendMarkerWorldPosition ( square ); |
---|
| 406 | |
---|
| 407 | // Calc size |
---|
| 408 | G4double size = GetMarkerHalfSize ( square ); |
---|
| 409 | size *= 2.; |
---|
| 410 | |
---|
| 411 | // send shape with size |
---|
| 412 | fDest << "\t" << "Cube {" << "\n"; |
---|
| 413 | fDest << "\t\t" << "width " << size << "\n"; |
---|
| 414 | fDest << "\t\t" << "height " << size << "\n"; |
---|
| 415 | fDest << "\t\t" << "depth " << size << "\n"; |
---|
| 416 | fDest << "\t" << "}" << "\n"; |
---|
| 417 | |
---|
| 418 | // end sending a mark |
---|
| 419 | fDest << "}" << "\n"; // Separator |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | void G4VRML1SCENEHANDLER::BeginModeling() |
---|
| 423 | { |
---|
| 424 | #if defined DEBUG_SCENE_FUNC |
---|
| 425 | G4cerr << "***** BeginModeling " << "\n" ; |
---|
| 426 | #endif |
---|
| 427 | G4VSceneHandler::BeginModeling(); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | void G4VRML1SCENEHANDLER::EndModeling() |
---|
| 431 | { |
---|
| 432 | #if defined DEBUG_SCENE_FUNC |
---|
| 433 | G4cerr << "***** EndModeling " << "\n" ; |
---|
| 434 | #endif |
---|
| 435 | G4VSceneHandler::EndModeling(); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | void G4VRML1SCENEHANDLER::BeginPrimitives(const G4Transform3D& objectTransformation) |
---|
| 439 | { |
---|
| 440 | G4VSceneHandler::BeginPrimitives (objectTransformation); |
---|
| 441 | fpObjectTransformation = &objectTransformation; |
---|
| 442 | #if defined DEBUG_SCENE_FUNC |
---|
| 443 | G4cerr << "***** BeginPrimitives " << "\n" ; |
---|
| 444 | #endif |
---|
| 445 | VRMLBeginModeling(); |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | void G4VRML1SCENEHANDLER::EndPrimitives() |
---|
| 449 | { |
---|
| 450 | #if defined DEBUG_SCENE_FUNC |
---|
| 451 | G4cerr << "***** EndPrimitives " << "\n" ; |
---|
| 452 | #endif |
---|
| 453 | G4VSceneHandler::EndPrimitives(); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | void G4VRML1SCENEHANDLER::SendMaterialNode( const G4VisAttributes* pVA ) |
---|
| 457 | { |
---|
| 458 | // const double TRANSPARENCY = 0.9 ; |
---|
| 459 | const double TRANSPARENCY = 0.5 ; |
---|
| 460 | |
---|
| 461 | if (!pVA) |
---|
| 462 | return; |
---|
| 463 | |
---|
| 464 | const G4Color& color = pVA->GetColor(); |
---|
| 465 | |
---|
| 466 | fDest << "\t\t" << "Material {" << "\n"; |
---|
| 467 | |
---|
| 468 | if (pVA->IsForceDrawingStyle() && |
---|
| 469 | (pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe)) { |
---|
| 470 | fDest << "\t\t\t" << "transparency " << TRANSPARENCY << "\n"; |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | fDest << "\t\t\t" << "diffuseColor"; |
---|
| 474 | fDest << " " << color.GetRed(); |
---|
| 475 | fDest << " " << color.GetGreen(); |
---|
| 476 | fDest << " " << color.GetBlue(); |
---|
| 477 | fDest << "\n"; |
---|
| 478 | fDest << "\t\t" << "}" << "\n"; |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | |
---|
| 482 | void G4VRML1SCENEHANDLER::SendMaterialNode() |
---|
| 483 | { |
---|
| 484 | SendMaterialNode |
---|
| 485 | ( fpViewer->GetApplicableVisAttributes (fpVisAttribs) ); |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | void G4VRML1SCENEHANDLER::SendMatrixTransformNode(const G4Transform3D *trans) |
---|
| 490 | { |
---|
| 491 | G4Point3D B (0.0, 0.0, 0.0); |
---|
| 492 | |
---|
| 493 | G4Point3D x1 (1.0, 0.0, 0.0); |
---|
| 494 | G4Point3D y1 (0.0, 1.0, 0.0); |
---|
| 495 | |
---|
| 496 | G4Vector3D e1 (1.0, 0.0, 0.0); |
---|
| 497 | G4Vector3D e2 (0.0, 1.0, 0.0); |
---|
| 498 | G4Vector3D e3 (0.0, 0.0, 1.0); |
---|
| 499 | |
---|
| 500 | //----- transformed origin of body coord |
---|
| 501 | B.transform(*trans); |
---|
| 502 | |
---|
| 503 | //----- transformed base vectors of body coord |
---|
| 504 | x1.transform(*trans); |
---|
| 505 | e1 = x1 - B; |
---|
| 506 | |
---|
| 507 | y1.transform(*trans); |
---|
| 508 | e2 = y1 - B; |
---|
| 509 | |
---|
| 510 | e3 = e1.cross(e2); |
---|
| 511 | |
---|
| 512 | e1 = e1.unit(); // normalize again for accuracy |
---|
| 513 | e2 = e2.unit(); // |
---|
| 514 | e3 = e3.unit(); // |
---|
| 515 | |
---|
| 516 | fDest << "\t" << "MatrixTransform {" << "\n"; |
---|
| 517 | fDest << "\t\t" << "matrix "; |
---|
| 518 | fDest << e1.x() << " " << e1.y() << " " << e1.z() << " 0 "; |
---|
| 519 | fDest << e2.x() << " " << e2.y() << " " << e2.z() << " 0 "; |
---|
| 520 | fDest << e3.x() << " " << e3.y() << " " << e3.z() << " 0 "; |
---|
| 521 | fDest << B.x() << " " << B.y() << " " << B.z() << " 1" << "\n"; |
---|
| 522 | fDest << "\t" << "}" << "\n"; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | void G4VRML1SCENEHANDLER::SendCubeNode(G4double w, G4double h, G4double d) |
---|
| 526 | { |
---|
| 527 | fDest << "\t\t" << "Cube {" << "\n"; |
---|
| 528 | fDest << "\t\t\t" << "width " << w << "\n"; |
---|
| 529 | fDest << "\t\t\t" << "height " << h << "\n"; |
---|
| 530 | fDest << "\t\t\t" << "depth " << d << "\n"; |
---|
| 531 | fDest << "\t\t" << "}" << "\n"; |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | void G4VRML1SCENEHANDLER::SendCylinderNode(G4double R, G4double h) |
---|
| 535 | { |
---|
| 536 | fDest << "\t\t" << "Transform {" << "\n"; |
---|
| 537 | fDest << "\t\t\t" << "rotation 1 0 0 " << (90. * deg) << "\n"; |
---|
| 538 | fDest << "\t\t" << "}" << "\n"; |
---|
| 539 | |
---|
| 540 | fDest << "\t\t" << "Cylinder {" << "\n"; |
---|
| 541 | fDest << "\t\t\t" << "radius " << R << "\n"; |
---|
| 542 | fDest << "\t\t\t" << "height " << h << "\n"; |
---|
| 543 | fDest << "\t\t" << "}" << "\n"; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | void G4VRML1SCENEHANDLER::SendSphereNode(G4double R) |
---|
| 547 | { |
---|
| 548 | fDest << "\t\t" << "Sphere {" << "\n"; |
---|
| 549 | fDest << "\t\t\t" << "radius " << R << "\n"; |
---|
| 550 | fDest << "\t\t" << "}" << "\n"; |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | void G4VRML1SCENEHANDLER::VRMLBeginModeling() |
---|
| 554 | { |
---|
| 555 | if (!IS_CONNECTED ) { |
---|
| 556 | #if defined DEBUG_SCENE_FUNC |
---|
| 557 | G4cerr << "***** VRMLBeginModeling() (started)" << "\n" ; |
---|
| 558 | #endif |
---|
| 559 | this->connectPort(); |
---|
| 560 | fDest << "#VRML V1.0 ascii" << "\n"; |
---|
| 561 | fDest << "# Generated by VRML 1.0 driver of GEANT4\n" << "\n"; |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | void G4VRML1SCENEHANDLER::VRMLEndModeling() |
---|
| 566 | { |
---|
| 567 | if ( IS_CONNECTED ) { |
---|
| 568 | #if defined DEBUG_SCENE_FUNC |
---|
| 569 | G4cerr << "***** VRMLEndModeling() (started)" << "\n" ; |
---|
| 570 | #endif |
---|
| 571 | |
---|
| 572 | fDest << "#End of file." << "\n"; |
---|
| 573 | this->closePort(); |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | void G4VRML1SCENEHANDLER::SendMarkerColor ( const G4VMarker& mark ) |
---|
| 578 | { |
---|
| 579 | const G4Color& color = GetColor( mark ); |
---|
| 580 | |
---|
| 581 | fDest << "\t" << "Material {" << "\n"; |
---|
| 582 | fDest << "\t\t"; |
---|
| 583 | fDest << "ambientColor [] "; |
---|
| 584 | fDest << "specularColor [] "; |
---|
| 585 | fDest << "\t\t" << "diffuseColor"; |
---|
| 586 | fDest << " " << color.GetRed(); |
---|
| 587 | fDest << " " << color.GetGreen(); |
---|
| 588 | fDest << " " << color.GetBlue(); |
---|
| 589 | fDest << "\n"; |
---|
| 590 | fDest << "\t\t" << "emissiveColor"; |
---|
| 591 | fDest << " " << color.GetRed(); |
---|
| 592 | fDest << " " << color.GetGreen(); |
---|
| 593 | fDest << " " << color.GetBlue(); |
---|
| 594 | fDest << "\n"; |
---|
| 595 | fDest << "\t" << "}" << "\n"; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | void |
---|
| 599 | G4VRML1SCENEHANDLER::SendMarkerWorldPosition ( const G4VMarker& mark ) |
---|
| 600 | { |
---|
| 601 | G4Point3D point = mark.GetPosition(); |
---|
| 602 | |
---|
| 603 | SendMatrixTransformNode( fpObjectTransformation ); |
---|
| 604 | |
---|
| 605 | fDest << "\t\t" << "Transform {" << "\n"; |
---|
| 606 | fDest << "\t\t\t" << "translation "; |
---|
| 607 | fDest << point.x() << " " << point.y() << " " << point.z() << "\n"; |
---|
| 608 | fDest << "\t\t" << "}" << "\n" ; |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | |
---|
| 612 | G4double G4VRML1SCENEHANDLER::GetMarkerHalfSize ( const G4VMarker& mark ) |
---|
| 613 | { |
---|
| 614 | //----- return value ( marker radius in 3d units) |
---|
| 615 | G4double size = 1.0 ; // initialization |
---|
| 616 | |
---|
| 617 | //----- parameters to calculate 3d size from 2d size |
---|
| 618 | const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels |
---|
| 619 | double zoom_factor = fpViewer->GetViewParameters().GetZoomFactor() ; |
---|
| 620 | if ( zoom_factor <= 0.0 ) { zoom_factor = 1.0 ; } |
---|
| 621 | double extent_radius_3d = GetScene()->GetExtent().GetExtentRadius() ; |
---|
| 622 | if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; } |
---|
| 623 | |
---|
| 624 | //----- get marker radius in 3D units |
---|
| 625 | if ( mark.GetWorldSize() > 0.0 ) { |
---|
| 626 | // get mark radius in 3D units |
---|
| 627 | size = 0.5 * mark.GetWorldSize() ; |
---|
| 628 | |
---|
| 629 | } else if ( mark.GetScreenSize() > 0.0 ) { |
---|
| 630 | // local |
---|
| 631 | double mark_radius_2d = 0.5 * mark.GetScreenSize() ; |
---|
| 632 | |
---|
| 633 | // get mark radius in 3D units |
---|
| 634 | size \ |
---|
| 635 | = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D ); |
---|
| 636 | size *= zoom_factor ; |
---|
| 637 | |
---|
| 638 | } else { |
---|
| 639 | // local |
---|
| 640 | double mark_radius_2d \ |
---|
| 641 | = fpViewer->GetViewParameters().GetDefaultMarker().GetScreenSize(); |
---|
| 642 | mark_radius_2d *= 0.1 ; // Magic number? |
---|
| 643 | |
---|
| 644 | // get mark radius in 3D units |
---|
| 645 | size \ |
---|
| 646 | = extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D ); |
---|
| 647 | size *= zoom_factor ; |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | //----- global rescaling |
---|
| 651 | size *= fpViewer->GetViewParameters().GetGlobalMarkerScale(); |
---|
| 652 | |
---|
| 653 | //----- return size |
---|
| 654 | return size ; |
---|
| 655 | |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | void G4VRML1SCENEHANDLER::ClearTransientStore() |
---|
| 659 | { |
---|
| 660 | G4VSceneHandler::ClearTransientStore (); |
---|
| 661 | // This is typically called after an update and before drawing hits |
---|
| 662 | // of the next event. To simulate the clearing of "transients" |
---|
| 663 | // (hits, etc.) the detector is redrawn... |
---|
| 664 | if (fpViewer) { |
---|
| 665 | fpViewer -> SetView (); |
---|
| 666 | fpViewer -> ClearView (); |
---|
| 667 | fpViewer -> DrawView (); |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | |
---|
| 672 | // #undef ADDTHIS_WITH_NAME(Solid) |
---|
| 673 | // #undef MAKE_NAME(Solid) |
---|
| 674 | // End of file. |
---|