Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4Scene.cc,v 1.14 2003/11/27 11:48:14 johna Exp $ >> 25 // GEANT4 tag $Name: geant4-06-00-patch-01 $ 27 // 26 // 28 // 27 // 29 // Scene data John Allison 19th July 1996. 28 // Scene data John Allison 19th July 1996. 30 29 31 #include "G4Scene.hh" 30 #include "G4Scene.hh" 32 31 33 #include "G4Vector3D.hh" 32 #include "G4Vector3D.hh" 34 #include "G4BoundingExtentScene.hh" << 33 #include "G4BoundingSphereScene.hh" 35 #include "G4VisAttributes.hh" 34 #include "G4VisAttributes.hh" 36 #include "G4PhysicalVolumeModel.hh" 35 #include "G4PhysicalVolumeModel.hh" 37 #include "G4TransportationManager.hh" 36 #include "G4TransportationManager.hh" 38 37 39 #include <set> << 40 << 41 #define G4warn G4cout << 42 << 43 G4Scene::G4Scene (const G4String& name): 38 G4Scene::G4Scene (const G4String& name): 44 fName (name), 39 fName (name), 45 fRefreshAtEndOfEvent(true), 40 fRefreshAtEndOfEvent(true), 46 fRefreshAtEndOfRun(true), << 41 fRefreshAtEndOfRun(true) 47 fMaxNumberOfKeptEvents(100) << 48 {} // Note all other data members have default 42 {} // Note all other data members have default initial values. 49 43 50 G4Scene::~G4Scene () {} 44 G4Scene::~G4Scene () {} 51 45 52 namespace { << 46 G4bool G4Scene::AddRunDurationModel (G4VModel* pModel, G4bool warn) { 53 void PrintInvalidModel(const G4VModel* model << 47 G4int i, nModels = fRunDurationModelList.size (); 54 { << 48 for (i = 0; i < nModels; i++) { 55 G4ExceptionDescription ed; << 49 if (pModel -> GetGlobalDescription () == 56 ed << "Invalid model \"" << model->GetGlob << 50 fRunDurationModelList [i] -> GetGlobalDescription ()) break; 57 << "\".\n Not included in extent calculat << 58 G4Exception << 59 ("G4Scene::CalculateExtent", << 60 "visman0201", JustWarning, ed); << 61 } << 62 } << 63 << 64 void G4Scene::CalculateExtent () << 65 { << 66 G4BoundingExtentScene boundingExtentScene; << 67 << 68 for (size_t i = 0; i < fRunDurationModelList << 69 if (fRunDurationModelList[i].fActive) { << 70 G4VModel* model = fRunDurationModelList[ << 71 if (model -> Validate()) { << 72 const G4VisExtent& thisExtent = model << 73 if (thisExtent != G4VisExtent::GetNull << 74 boundingExtentScene.AccrueBoundingEx << 75 } << 76 } else { << 77 PrintInvalidModel(model); << 78 } << 79 } << 80 } 51 } 81 << 52 if (i < nModels) { 82 for (size_t i = 0; i < fEndOfEventModelList. << 53 if (warn) { 83 if (fEndOfEventModelList[i].fActive) { << 54 G4cout << "G4Scene::AddRunDurationModel: model \"" 84 G4VModel* model = fEndOfEventModelList[i << 55 << pModel -> GetGlobalDescription () 85 if (model -> Validate()) { << 56 << "\"\n is already in the run-duration list of scene \"" 86 const G4VisExtent& thisExtent = model << 57 << fName 87 if (thisExtent != G4VisExtent::GetNull << 58 << "\"." 88 boundingExtentScene.AccrueBoundingEx << 59 << G4endl; 89 } << 90 } else { << 91 PrintInvalidModel(model); << 92 } << 93 } 60 } >> 61 return false; 94 } 62 } >> 63 fRunDurationModelList.push_back (pModel); >> 64 CalculateExtent (); >> 65 return true; >> 66 } 95 67 96 for (size_t i = 0; i < fEndOfRunModelList.si << 68 void G4Scene::CalculateExtent () { 97 if (fEndOfRunModelList[i].fActive) { << 69 G4int nModels = fRunDurationModelList.size (); 98 G4VModel* model = fEndOfRunModelList[i]. << 70 G4BoundingSphereScene boundingSphereScene; 99 if (model -> Validate()) { << 71 for (G4int i = 0; i < nModels; i++) { 100 const G4VisExtent& thisExtent = model << 72 const G4VisExtent& thisExtent = 101 if (thisExtent != G4VisExtent::GetNull << 73 fRunDurationModelList[i] -> GetExtent (); 102 boundingExtentScene.AccrueBoundingEx << 74 G4Point3D thisCentre = thisExtent.GetExtentCentre (); 103 } << 75 G4double thisRadius = thisExtent.GetExtentRadius (); 104 } else { << 76 thisCentre.transform (fRunDurationModelList[i] -> GetTransformation ()); 105 PrintInvalidModel(model); << 77 boundingSphereScene.AccrueBoundingSphere (thisCentre, thisRadius); 106 } << 107 } << 108 } 78 } 109 << 79 fExtent = boundingSphereScene.GetBoundingSphereExtent (); 110 fExtent = boundingExtentScene.GetBoundingExt << 111 fStandardTargetPoint = fExtent.GetExtentCent 80 fStandardTargetPoint = fExtent.GetExtentCentre (); 112 if (fExtent.GetExtentRadius() <= 0.) { << 113 G4Exception << 114 ("G4Scene::CalculateExtent", << 115 "visman0202", JustWarning, << 116 "Scene has no extent. Please activate or << 117 "\nThe camera needs to have something to << 118 "\nAdd a volume. (You may need \"/r << 119 "\nOr use \"/vis/scene/add/extent\" << 120 "\n\"/vis/scene/list\" to see list of mod << 121 } << 122 } 81 } 123 82 124 G4bool G4Scene::AddWorldIfEmpty (G4bool warn) 83 G4bool G4Scene::AddWorldIfEmpty (G4bool warn) { 125 G4bool successful = true; 84 G4bool successful = true; 126 if (IsEmpty ()) { 85 if (IsEmpty ()) { 127 successful = false; 86 successful = false; 128 G4VPhysicalVolume* pWorld = 87 G4VPhysicalVolume* pWorld = 129 G4TransportationManager::GetTransportati 88 G4TransportationManager::GetTransportationManager () 130 -> GetNavigatorForTracking () -> GetWorl 89 -> GetNavigatorForTracking () -> GetWorldVolume (); 131 if (pWorld) { 90 if (pWorld) { 132 const G4VisAttributes* pVisAttribs = 91 const G4VisAttributes* pVisAttribs = 133 pWorld -> GetLogicalVolume () -> GetVisAttri 92 pWorld -> GetLogicalVolume () -> GetVisAttributes (); 134 if (!pVisAttribs || pVisAttribs -> IsVis 93 if (!pVisAttribs || pVisAttribs -> IsVisible ()) { 135 if (warn) { 94 if (warn) { 136 G4warn << << 95 G4cout << 137 "Your \"world\" has no vis attributes or 96 "Your \"world\" has no vis attributes or is marked as visible." 138 "\n For a better view of the contents, 97 "\n For a better view of the contents, mark the world as" 139 " invisible, e.g.," 98 " invisible, e.g.," 140 "\n myWorldLogicalVol ->" 99 "\n myWorldLogicalVol ->" 141 " SetVisAttributes (G4VisAttributes::GetIn << 100 " SetVisAttributes (G4VisAttributes::Invisible);" 142 << G4endl; 101 << G4endl; 143 } 102 } 144 } 103 } 145 successful = AddRunDurationModel (new G4 104 successful = AddRunDurationModel (new G4PhysicalVolumeModel (pWorld)); 146 // Note: default depth and no modeling p 105 // Note: default depth and no modeling parameters. 147 if (successful) { 106 if (successful) { 148 if (warn) { 107 if (warn) { 149 G4warn << << 108 G4cout << 150 "G4Scene::AddWorldIfEmpty: The scene had n << 109 "G4Scene::AddWorldIfEmpty: The scene was empty," 151 "\n \"world\" has been added."; << 110 "\n \"world\" has been added."; 152 G4warn << G4endl; << 111 G4cout << G4endl; 153 } 112 } 154 } 113 } 155 } 114 } 156 } 115 } 157 return successful; 116 return successful; 158 } 117 } 159 118 160 G4bool G4Scene::AddRunDurationModel (G4VModel* << 161 { << 162 std::vector<Model>::const_iterator i; << 163 for (i = fRunDurationModelList.begin (); << 164 i != fRunDurationModelList.end (); ++i) << 165 if (pModel -> GetGlobalDescription () == << 166 i->fpModel->GetGlobalDescription ()) break; << 167 } << 168 if (i != fRunDurationModelList.end ()) { << 169 if (warn) { << 170 G4warn << "G4Scene::AddRunDurationModel: << 171 << pModel -> GetGlobalDescription () << 172 << "\"\n is already in the run-duration << 173 << fName << 174 << "\"." << 175 << G4endl; << 176 } << 177 return false; << 178 } << 179 fRunDurationModelList.push_back (Model(pMode << 180 CalculateExtent (); << 181 return true; << 182 } << 183 << 184 G4bool G4Scene::AddEndOfEventModel (G4VModel* 119 G4bool G4Scene::AddEndOfEventModel (G4VModel* pModel, G4bool warn) { 185 std::size_t i, nModels = fEndOfEventModelLis << 120 G4int i, nModels = fEndOfEventModelList.size (); 186 for (i = 0; i < nModels; ++i) { << 121 for (i = 0; i < nModels; i++) { 187 if (pModel -> GetGlobalDescription () == 122 if (pModel -> GetGlobalDescription () == 188 fEndOfEventModelList[i].fpModel -> GetGlobal << 123 fEndOfEventModelList [i] -> GetGlobalDescription ()) break; 189 } 124 } 190 if (i < nModels) { 125 if (i < nModels) { >> 126 delete fEndOfEventModelList[i]; >> 127 fEndOfEventModelList[i] = pModel; 191 if (warn) { 128 if (warn) { 192 G4warn << "G4Scene::AddEndOfEventModel: << 129 G4cout << "G4Scene::AddEndOfEventModel: a model \"" 193 << pModel -> GetGlobalDescription () 130 << pModel -> GetGlobalDescription () 194 << "\"\n is already in the end-of-even << 131 << "\"\n is already in the run-duration list of scene \"" 195 << fName << "\"." << 132 << fName << >> 133 "\".\n The old model has been deleted; this new model replaces it." 196 << G4endl; 134 << G4endl; 197 } 135 } 198 return false; 136 return false; 199 } 137 } 200 fEndOfEventModelList.push_back (Model(pModel << 138 fEndOfEventModelList.push_back (pModel); 201 CalculateExtent (); << 202 return true; 139 return true; 203 } 140 } 204 141 205 G4bool G4Scene::AddEndOfRunModel (G4VModel* pM << 142 void G4Scene::Clear () { 206 std::size_t i, nModels = fEndOfRunModelList. << 143 size_t i; 207 for (i = 0; i < nModels; ++i) { << 144 for (i = 0; i < fRunDurationModelList.size(); ++i) { 208 if (pModel -> GetGlobalDescription () == << 145 delete fRunDurationModelList[i]; 209 fEndOfRunModelList[i].fpModel -> GetGlobalDe << 210 } 146 } 211 if (i < nModels) { << 147 for (i = 0; i < fEndOfEventModelList.size(); ++i) { 212 if (warn) { << 148 delete fEndOfEventModelList[i]; 213 G4warn << "G4Scene::AddEndOfRunModel: a << 214 << pModel -> GetGlobalDescription () << 215 << "\"\n is already in the end-of-run << 216 << fName << "\"." << 217 << G4endl; << 218 } << 219 return false; << 220 } 149 } 221 fEndOfRunModelList.push_back (pModel); << 222 CalculateExtent (); << 223 return true; << 224 } 150 } 225 151 226 std::ostream& operator << (std::ostream& os, c << 152 std::ostream& operator << (std::ostream& os, const G4Scene& s) { 227 153 228 size_t i; 154 size_t i; 229 155 230 os << "Scene data:"; 156 os << "Scene data:"; 231 157 232 os << "\n Run-duration model list:"; 158 os << "\n Run-duration model list:"; 233 if (scene.fRunDurationModelList.size () == 0 << 159 for (i = 0; i < s.fRunDurationModelList.size (); i++) { 234 os << " none"; << 160 os << "\n " << *(s.fRunDurationModelList[i]); 235 } << 236 for (i = 0; i < scene.fRunDurationModelList. << 237 if (scene.fRunDurationModelList[i].fActive << 238 else os << "\n Inactive: "; << 239 os << *(scene.fRunDurationModelList[i].fpM << 240 } 161 } 241 162 242 os << "\n End-of-event model list:"; 163 os << "\n End-of-event model list:"; 243 if (scene.fEndOfEventModelList.size () == 0) << 164 for (i = 0; i < s.fEndOfEventModelList.size (); i++) { 244 os << " none"; << 165 os << "\n " << *(s.fEndOfEventModelList[i]); 245 } << 246 for (i = 0; i < scene.fEndOfEventModelList.s << 247 if (scene.fEndOfEventModelList[i].fActive) << 248 else os << "\n Inactive: "; << 249 os << *(scene.fEndOfEventModelList[i].fpMo << 250 } << 251 << 252 os << "\n End-of-run model list:"; << 253 if (scene.fEndOfRunModelList.size () == 0) { << 254 os << " none"; << 255 } << 256 for (i = 0; i < scene.fEndOfRunModelList.siz << 257 if (scene.fEndOfRunModelList[i].fActive) o << 258 else os << "\n Inactive: "; << 259 os << *(scene.fEndOfRunModelList[i].fpMode << 260 } 166 } 261 167 262 os << "\n Overall extent or bounding box: " << 168 os << "\n Extent or bounding box: " << s.fExtent; 263 169 264 os << "\n Standard target point: " << scen << 170 os << "\n Standard target point: " << s.fStandardTargetPoint; 265 171 266 os << "\n End of event action set to \""; 172 os << "\n End of event action set to \""; 267 if (scene.fRefreshAtEndOfEvent) os << "refre << 173 if (s.fRefreshAtEndOfEvent) os << "refresh"; 268 else { << 174 else os << "accumulate"; 269 os << "accumulate (maximum number of kept << 175 os << "\""; 270 if (scene.fMaxNumberOfKeptEvents >= 0) os << 271 else os << "unlimited"; << 272 os << ")"; << 273 } << 274 176 275 os << "\n End of run action set to \""; 177 os << "\n End of run action set to \""; 276 if (scene.fRefreshAtEndOfRun) os << "refresh << 178 if (s.fRefreshAtEndOfRun) os << "refresh"; 277 else os << "accumulate"; 179 else os << "accumulate"; 278 os << "\""; 180 os << "\""; 279 181 280 return os; 182 return os; 281 } 183 } 282 184 283 G4bool G4Scene::operator != (const G4Scene& sc << 185 G4bool G4Scene::operator != (const G4Scene& s) const { 284 if ( 186 if ( 285 (fRunDurationModelList.size () != 187 (fRunDurationModelList.size () != 286 scene.fRunDurationModelList.size ()) << 188 s.fRunDurationModelList.size ()) || 287 (fEndOfEventModelList.size () != << 189 (fExtent != s.fExtent) || 288 scene.fEndOfEventModelList.size ()) << 190 !(fStandardTargetPoint == s.fStandardTargetPoint) || 289 (fEndOfRunModelList.size () != << 191 fRefreshAtEndOfEvent != s.fRefreshAtEndOfEvent || 290 scene.fEndOfRunModelList.size ()) << 192 fRefreshAtEndOfRun != s.fRefreshAtEndOfRun 291 (fExtent != scene.fExtent) << 292 !(fStandardTargetPoint == scene.fStandar << 293 fRefreshAtEndOfEvent != scene.fRefresh << 294 fRefreshAtEndOfRun != scene.fRefresh << 295 fMaxNumberOfKeptEvents != scene.fMaxNumb << 296 ) return true; 193 ) return true; 297 194 298 /* A complete comparison should, perhaps, in << 299 individual models, but it is not easy to << 300 all models. Also, it would be unfeasible << 301 implement opeerator!= if we ever get roun << 302 user-defined models. Moreover, there is << 303 objects, apart from changing fRefreshAtEn << 304 models are concerned, all you can ever do << 305 on size (above) is enough. << 306 << 307 for (size_t i = 0; i < fRunDurationModelList 195 for (size_t i = 0; i < fRunDurationModelList.size (); i++) { 308 if (fRunDurationModelList[i] != scene.fRun << 196 if (fRunDurationModelList[i] != s.fRunDurationModelList[i]) 309 return true; << 310 } << 311 << 312 for (size_t i = 0; i < fEndOfEventModelList. << 313 if (fEndOfEventModelList[i] != scene.fEndO << 314 return true; << 315 } << 316 << 317 for (size_t i = 0; i < fEndOfRunModelList.si << 318 if (fEndOfRunModelList[i] != scene.fEndOfR << 319 return true; 197 return true; 320 } 198 } 321 */ << 322 199 323 return false; 200 return false; 324 } 201 } 325 202