00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "G4XXXSGSceneHandler.hh"
00035
00036 #include "G4XXXSGViewer.hh"
00037 #include "G4PhysicalVolumeModel.hh"
00038 #include "G4LogicalVolumeModel.hh"
00039 #include "G4VPhysicalVolume.hh"
00040 #include "G4LogicalVolume.hh"
00041 #include "G4Box.hh"
00042 #include "G4Polyline.hh"
00043 #include "G4Text.hh"
00044 #include "G4Circle.hh"
00045 #include "G4Square.hh"
00046 #include "G4Polyhedron.hh"
00047 #include "G4UnitsTable.hh"
00048
00049 #include <sstream>
00050
00051 G4int G4XXXSGSceneHandler::fSceneIdCount = 0;
00052
00053
00054 G4XXXSGSceneHandler::G4XXXSGSceneHandler(G4VGraphicsSystem& system,
00055 const G4String& name):
00056 G4VSceneHandler(system, fSceneIdCount++, name)
00057 {}
00058
00059 G4XXXSGSceneHandler::~G4XXXSGSceneHandler() {}
00060
00061 #ifdef G4XXXSGDEBUG
00062
00063 void G4XXXSGSceneHandler::PrintThings() {
00064 G4cout <<
00065 " with transformation "
00066 << (void*)fpObjectTransformation;
00067 if (fpModel) {
00068 G4cout << " from " << fpModel->GetCurrentDescription()
00069 << " (tag " << fpModel->GetCurrentTag()
00070 << ')';
00071 } else {
00072 G4cout << "(not from a model)";
00073 }
00074 G4PhysicalVolumeModel* pPVModel =
00075 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00076 if (pPVModel) {
00077 G4cout <<
00078 "\n current physical volume: "
00079 << pPVModel->GetCurrentPV()->GetName() <<
00080 "\n current logical volume: "
00081
00082 << pPVModel->GetCurrentLV()->GetName() <<
00083 "\n current depth of geometry tree: "
00084 << pPVModel->GetCurrentDepth();
00085 }
00086 G4cout << G4endl;
00087 }
00088 #endif
00089
00090 void G4XXXSGSceneHandler::CreateCurrentItem(const G4String& ) {
00091
00092
00093 G4PhysicalVolumeModel* pPVModel =
00094 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00095 G4LogicalVolumeModel* pLVModel =
00096 dynamic_cast<G4LogicalVolumeModel*>(pPVModel);
00097 if (pPVModel && !pLVModel) {
00098
00099
00100
00101
00102
00103
00104
00105 typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
00106 typedef std::vector<PVNodeID> PVPath;
00107 const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath();
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 static G4int index = 0;
00138 JA::Insert(&drawnPVPath[0],drawnPVPath.size(),index++,&fSceneGraph);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 } else {
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 }
00198 }
00199
00200 void G4XXXSGSceneHandler::PreAddSolid
00201 (const G4Transform3D& objectTransformation,
00202 const G4VisAttributes& visAttribs)
00203 {
00204 G4VSceneHandler::PreAddSolid(objectTransformation, visAttribs);
00205 CreateCurrentItem(G4String("\nPreAddSolid:\n"));
00206 }
00207
00208 void G4XXXSGSceneHandler::PostAddSolid()
00209 {
00210 G4VSceneHandler::PostAddSolid();
00211 }
00212
00213 void G4XXXSGSceneHandler::BeginPrimitives
00214 (const G4Transform3D& objectTransformation)
00215 {
00216 G4VSceneHandler::BeginPrimitives(objectTransformation);
00217 }
00218
00219 void G4XXXSGSceneHandler::EndPrimitives ()
00220 {
00221 G4VSceneHandler::EndPrimitives ();
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 void G4XXXSGSceneHandler::AddSolid(const G4Box& box) {
00234 #ifdef G4XXXSGDEBUG
00235 G4cout <<
00236 "G4XXXSGSceneHandler::AddSolid(const G4Box& box) called for "
00237 << box.GetName()
00238 << G4endl;
00239 #endif
00240
00241 std::ostringstream oss;
00242 oss << "G4Box(" <<
00243 G4String
00244 (G4BestUnit
00245 (G4ThreeVector
00246 (box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()),
00247 "Length")).strip() << ')' << std::endl;
00248
00249 }
00250
00251 void G4XXXSGSceneHandler::AddPrimitive(const G4Polyline& polyline) {
00252 #ifdef G4XXXSGDEBUG
00253 G4cout <<
00254 "G4XXXSGSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
00255 << polyline
00256 << G4endl;
00257 #endif
00258
00259
00260
00261
00262 std::ostringstream oss;
00263 oss << polyline << std::endl;
00264
00265 }
00266
00267 void G4XXXSGSceneHandler::AddPrimitive(const G4Text& text) {
00268 #ifdef G4XXXSGDEBUG
00269 G4cout <<
00270 "G4XXXSGSceneHandler::AddPrimitive(const G4Text& text) called.\n"
00271 << text
00272 << G4endl;
00273 #endif
00274
00275
00276
00277
00278
00279
00280 std::ostringstream oss;
00281 oss << text << std::endl;
00282
00283 }
00284
00285 void G4XXXSGSceneHandler::AddPrimitive(const G4Circle& circle) {
00286 #ifdef G4XXXSGDEBUG
00287 G4cout <<
00288 "G4XXXSGSceneHandler::AddPrimitive(const G4Circle& circle) called.\n"
00289 << circle
00290 << G4endl;
00291 MarkerSizeType sizeType;
00292 G4double size = GetMarkerSize (circle, sizeType);
00293 switch (sizeType) {
00294 default:
00295 case screen:
00296
00297 G4cout << "screen";
00298 break;
00299 case world:
00300
00301 G4cout << "world";
00302 break;
00303 }
00304 G4cout << " size: " << size << G4endl;
00305 #endif
00306
00307
00308
00309
00310 std::ostringstream oss;
00311 oss << circle << std::endl;
00312
00313 }
00314
00315 void G4XXXSGSceneHandler::AddPrimitive(const G4Square& square) {
00316 #ifdef G4XXXSGDEBUG
00317 G4cout <<
00318 "G4XXXSGSceneHandler::AddPrimitive(const G4Square& square) called.\n"
00319 << square
00320 << G4endl;
00321 MarkerSizeType sizeType;
00322 G4double size = GetMarkerSize (square, sizeType);
00323 switch (sizeType) {
00324 default:
00325 case screen:
00326
00327 G4cout << "screen";
00328 break;
00329 case world:
00330
00331 G4cout << "world";
00332 break;
00333 }
00334 G4cout << " size: " << size << G4endl;
00335 #endif
00336
00337
00338
00339
00340 std::ostringstream oss;
00341 oss << square << std::endl;
00342
00343 }
00344
00345 void G4XXXSGSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
00346 #ifdef G4XXXSGDEBUG
00347 G4cout <<
00348 "G4XXXSGSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called.\n"
00349 << polyhedron
00350 << G4endl;
00351 #endif
00352
00353 std::ostringstream oss;
00354 oss << polyhedron;
00355
00356
00357
00358
00359
00360
00361
00362 if (polyhedron.GetNoFacets() == 0) return;
00363
00364
00365 const G4VisAttributes* pVA =
00366 fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
00367
00368
00369
00370 G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
00371
00372
00373
00374
00375
00376
00377 switch (drawing_style) {
00378 case (G4ViewParameters::hsr):
00379 {
00380 break;
00381 }
00382 case (G4ViewParameters::hlr):
00383 {
00384 break;
00385 }
00386 case (G4ViewParameters::wireframe):
00387 {
00388 break;
00389 }
00390 default:
00391 {
00392 break;
00393 }
00394 }
00395
00396
00397
00398
00399
00400
00401 }
00402
00403 void G4XXXSGSceneHandler::AddPrimitive(const G4NURBS&) {
00404 #ifdef G4XXXSGDEBUG
00405 G4cout <<
00406 "G4XXXSGSceneHandler::AddPrimitive(const G4NURBS& nurbs) called."
00407 << G4endl;
00408 #endif
00409
00410 }
00411
00412 void G4XXXSGSceneHandler::ClearStore ()
00413 {
00414 JA::Clear(&fSceneGraph);
00415 }
00416
00417 void G4XXXSGSceneHandler::ClearTransientStore ()
00418 {
00419 JA::Clear(&fSceneGraph);
00420 }
00421
00422 namespace JA {
00423
00424
00425 #include "G4VPhysicalVolume.hh"
00426
00427 void Insert(const PVNodeID* pvPath, size_t pathLength,
00428 G4int index, Node* node) {
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 G4bool found = false; size_t foundPosition = 0;
00441 for (size_t i = 0; i < node->fDaughters.size(); ++i) {
00442 PVNodeID& daughterPVNodeID = node->fDaughters[i]->fPVNodeID;
00443
00444 if (daughterPVNodeID.GetPhysicalVolume() == pvPath[0].GetPhysicalVolume() &&
00445 daughterPVNodeID.GetCopyNo() == pvPath[0].GetCopyNo()) {
00446 found = true;
00447 foundPosition = i;
00448 break;
00449 }
00450 }
00451
00452 if (pathLength == 1) {
00453 if (found) {
00454 node->fDaughters[foundPosition]->fIndex = index;
00455 } else {
00456 node->fDaughters.push_back(new Node(pvPath[0],index));
00457 }
00458
00459
00460
00461 } else {
00462 if (found) {
00463 Insert(pvPath+1,--pathLength,index,
00464 node->fDaughters[foundPosition]);
00465 } else {
00466 node->fDaughters.push_back(new Node(pvPath[0]));
00467 Insert(pvPath+1,--pathLength,index,
00468 node->fDaughters[node->fDaughters.size()-1]);
00469 }
00470 }
00471 }
00472
00473 void PrintTree(std::ostream& os, Node* node)
00474 {
00475 static G4int depth = -1;
00476 depth++;
00477 PVNodeID& thisPVNodeID = node->fPVNodeID;
00478 G4int& thisIndex = node->fIndex;
00479 const size_t& nDaughters = node->fDaughters.size();
00480 G4VPhysicalVolume* thisPhysicalVolume= thisPVNodeID.GetPhysicalVolume();
00481 if (!thisPhysicalVolume) os << "Root" << std::endl;
00482 else {
00483 for (G4int i = 0; i < depth; ++i) os << "__";
00484 os << thisPVNodeID.GetPhysicalVolume()->GetName() << ":"
00485 << thisPVNodeID.GetCopyNo() << " ("
00486 << thisIndex << ")" << std::endl;;
00487 }
00488 for (size_t i = 0; i < nDaughters; ++i) {
00489 PrintTree(os, node->fDaughters[i]);
00490 }
00491 depth--;
00492 }
00493
00494 void Clear(Node* node)
00495 {
00496 const size_t& nDaughters = node->fDaughters.size();
00497 for (size_t i = 0; i < nDaughters; ++i) {
00498 Clear(node->fDaughters[i]);
00499 delete node->fDaughters[i];
00500 }
00501 }
00502
00503 }