Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // 28 // 29 // Created: Mar. 31, 2009 Akinori Kimura 29 // Created: Mar. 31, 2009 Akinori Kimura 30 // Sep. 22, 2009 Akinori Kimura : m 30 // Sep. 22, 2009 Akinori Kimura : modify and fix code to support 31 // Pr 31 // PrimitiveScorers and clean up 32 // 32 // 33 // GMocrenFile scene handler 33 // GMocrenFile scene handler 34 34 35 35 36 //----- header files 36 //----- header files 37 #include <fstream> 37 #include <fstream> 38 #include <cstdlib> 38 #include <cstdlib> 39 #include <cstring> 39 #include <cstring> 40 #include <sstream> 40 #include <sstream> 41 #include <sstream> 41 #include <sstream> 42 #include <iomanip> 42 #include <iomanip> 43 43 44 #include "globals.hh" 44 #include "globals.hh" 45 #include "G4VisManager.hh" 45 #include "G4VisManager.hh" 46 46 47 #include "G4GMocrenFile.hh" 47 #include "G4GMocrenFile.hh" 48 #include "G4GMocrenFileSceneHandler.hh" 48 #include "G4GMocrenFileSceneHandler.hh" 49 #include "G4GMocrenFileViewer.hh" 49 #include "G4GMocrenFileViewer.hh" 50 #include "G4Point3D.hh" 50 #include "G4Point3D.hh" 51 #include "G4VisAttributes.hh" 51 #include "G4VisAttributes.hh" 52 #include "G4Scene.hh" 52 #include "G4Scene.hh" 53 #include "G4Transform3D.hh" 53 #include "G4Transform3D.hh" 54 #include "G4Polyhedron.hh" 54 #include "G4Polyhedron.hh" 55 #include "G4Box.hh" 55 #include "G4Box.hh" 56 #include "G4Cons.hh" 56 #include "G4Cons.hh" 57 #include "G4Polyline.hh" 57 #include "G4Polyline.hh" 58 #include "G4Trd.hh" 58 #include "G4Trd.hh" 59 #include "G4Tubs.hh" 59 #include "G4Tubs.hh" 60 #include "G4Trap.hh" 60 #include "G4Trap.hh" 61 #include "G4Torus.hh" 61 #include "G4Torus.hh" 62 #include "G4Sphere.hh" 62 #include "G4Sphere.hh" 63 #include "G4Para.hh" 63 #include "G4Para.hh" 64 #include "G4Text.hh" 64 #include "G4Text.hh" 65 #include "G4Circle.hh" 65 #include "G4Circle.hh" 66 #include "G4Square.hh" 66 #include "G4Square.hh" 67 #include "G4VPhysicalVolume.hh" 67 #include "G4VPhysicalVolume.hh" 68 #include "G4PhysicalVolumeModel.hh" 68 #include "G4PhysicalVolumeModel.hh" 69 #include "G4LogicalVolume.hh" 69 #include "G4LogicalVolume.hh" 70 #include "G4Material.hh" 70 #include "G4Material.hh" 71 71 72 #include "G4VPVParameterisation.hh" 72 #include "G4VPVParameterisation.hh" 73 #include "G4VVolumeMaterialScanner.hh" 73 #include "G4VVolumeMaterialScanner.hh" 74 #include "G4VisTrajContext.hh" 74 #include "G4VisTrajContext.hh" 75 #include "G4TrajectoriesModel.hh" 75 #include "G4TrajectoriesModel.hh" 76 #include "G4VTrajectoryModel.hh" 76 #include "G4VTrajectoryModel.hh" 77 #include "G4TrajectoryDrawByCharge.hh" 77 #include "G4TrajectoryDrawByCharge.hh" 78 #include "G4HitsModel.hh" 78 #include "G4HitsModel.hh" 79 #include "G4GMocrenMessenger.hh" 79 #include "G4GMocrenMessenger.hh" 80 //#include "G4PSHitsModel.hh" 80 //#include "G4PSHitsModel.hh" 81 #include "G4GMocrenIO.hh" 81 #include "G4GMocrenIO.hh" 82 #include "G4VNestedParameterisation.hh" 82 #include "G4VNestedParameterisation.hh" 83 #include "G4GMocrenTouchable.hh" 83 #include "G4GMocrenTouchable.hh" 84 #include "G4GMocrenFileCTtoDensityMap.hh" 84 #include "G4GMocrenFileCTtoDensityMap.hh" 85 #include "G4PhantomParameterisation.hh" 85 #include "G4PhantomParameterisation.hh" >> 86 #include "G4PhysicalVolumeSearchScene.hh" 86 87 87 #include "G4ScoringManager.hh" 88 #include "G4ScoringManager.hh" 88 #include "G4ScoringBox.hh" 89 #include "G4ScoringBox.hh" 89 90 90 #include "G4PhysicalConstants.hh" 91 #include "G4PhysicalConstants.hh" 91 #include "G4SystemOfUnits.hh" 92 #include "G4SystemOfUnits.hh" 92 93 93 #include <utility> << 94 << 95 //----- constants 94 //----- constants 96 const char GDD_FILE_HEADER [] = "g4_"; 95 const char GDD_FILE_HEADER [] = "g4_"; 97 const char DEFAULT_GDD_FILE_NAME[] = "g4_00.g 96 const char DEFAULT_GDD_FILE_NAME[] = "g4_00.gdd"; 98 97 99 const G4int FR_MAX_FILE_NUM = 100 ; 98 const G4int FR_MAX_FILE_NUM = 100 ; 100 const G4int MAX_NUM_TRAJECTORIES = 100000; 99 const G4int MAX_NUM_TRAJECTORIES = 100000; 101 100 102 //-- for a debugging 101 //-- for a debugging 103 const G4bool GFDEBUG = false; 102 const G4bool GFDEBUG = false; 104 const G4bool GFDEBUG_TRK = false;//true; 103 const G4bool GFDEBUG_TRK = false;//true; 105 const G4bool GFDEBUG_HIT = false;//true; 104 const G4bool GFDEBUG_HIT = false;//true; 106 const G4bool GFDEBUG_DIGI = false;//true; 105 const G4bool GFDEBUG_DIGI = false;//true; 107 const G4int GFDEBUG_DET = 0; // 0: false 106 const G4int GFDEBUG_DET = 0; // 0: false 108 107 109 ////////////////////// 108 ////////////////////// 110 // static variables // 109 // static variables // 111 ////////////////////// 110 ////////////////////// 112 111 113 //----- static variables 112 //----- static variables 114 G4int G4GMocrenFileSceneHandler::kSceneIdCount 113 G4int G4GMocrenFileSceneHandler::kSceneIdCount = 0; 115 114 116 /////////////////////////// 115 /////////////////////////// 117 // Driver-dependent part // 116 // Driver-dependent part // 118 /////////////////////////// 117 /////////////////////////// 119 118 120 119 121 //----- G4GMocrenFileSceneHandler, constructor 120 //----- G4GMocrenFileSceneHandler, constructor 122 G4GMocrenFileSceneHandler::G4GMocrenFileSceneH 121 G4GMocrenFileSceneHandler::G4GMocrenFileSceneHandler(G4GMocrenFile& system, 123 G4GMocrenMessenger & messenge 122 G4GMocrenMessenger & messenger, 124 const G4String& name) 123 const G4String& name) 125 : G4VSceneHandler(system, kSceneIdCount++, n 124 : G4VSceneHandler(system, kSceneIdCount++, name), 126 kSystem(system), 125 kSystem(system), 127 kMessenger(messenger), 126 kMessenger(messenger), 128 kgMocrenIO(new G4GMocrenIO()), 127 kgMocrenIO(new G4GMocrenIO()), 129 kbSetModalityVoxelSize(false), 128 kbSetModalityVoxelSize(false), 130 kbModelingTrajectory(false), 129 kbModelingTrajectory(false), 131 // kGddDest(0), 130 // kGddDest(0), 132 kFlagInModeling(false), 131 kFlagInModeling(false), 133 kFlagSaving_g4_gdd(false), 132 kFlagSaving_g4_gdd(false), 134 kFlagParameterization(0), 133 kFlagParameterization(0), 135 kFlagProcessedInteractiveScorer(false) { 134 kFlagProcessedInteractiveScorer(false) { 136 135 137 // g4.gdd filename and its directory 136 // g4.gdd filename and its directory 138 if(std::getenv("G4GMocrenFile_DEST_DIR") == 137 if(std::getenv("G4GMocrenFile_DEST_DIR") == NULL) { 139 kGddDestDir[0] = '\0'; 138 kGddDestDir[0] = '\0'; 140 //std::strcpy(kGddDestDir , ""); 139 //std::strcpy(kGddDestDir , ""); // output dir 141 //std::strcpy(kGddFileName, DEFAULT_GDD_FI 140 //std::strcpy(kGddFileName, DEFAULT_GDD_FILE_NAME); // filename 142 std::strncpy(kGddFileName, DEFAULT_GDD_FIL 141 std::strncpy(kGddFileName, DEFAULT_GDD_FILE_NAME, 143 std::strlen(DEFAULT_GDD_FILE_NAME)+1); 142 std::strlen(DEFAULT_GDD_FILE_NAME)+1); // filename 144 } else { 143 } else { 145 const char * env = std::getenv("G4GMocrenF 144 const char * env = std::getenv("G4GMocrenFile_DEST_DIR"); 146 G4int len = (G4int)std::strlen(env); << 145 int len = std::strlen(env); 147 if(len > 256) { 146 if(len > 256) { 148 G4Exception("G4GMocrenFileSceneHandler:: 147 G4Exception("G4GMocrenFileSceneHandler::G4GMocrenFileSceneHandler(*)", 149 "gMocren1000", FatalExceptio 148 "gMocren1000", FatalException, 150 "Invalid length of string se 149 "Invalid length of string set in G4GMocrenFile_DEST_DIR"); 151 } 150 } 152 std::strncpy(kGddDestDir, env, len+1); // 151 std::strncpy(kGddDestDir, env, len+1); // output dir 153 std::strncpy(kGddFileName, DEFAULT_GDD_FIL 152 std::strncpy(kGddFileName, DEFAULT_GDD_FILE_NAME, 154 std::strlen(DEFAULT_GDD_FILE_ 153 std::strlen(DEFAULT_GDD_FILE_NAME)+1); // filename 155 } 154 } 156 155 157 // maximum number of g4.gdd files in the des 156 // maximum number of g4.gdd files in the dest directory 158 kMaxFileNum = FR_MAX_FILE_NUM ; // initializ 157 kMaxFileNum = FR_MAX_FILE_NUM ; // initialization 159 if ( std::getenv( "G4GMocrenFile_MAX_FILE_NU 158 if ( std::getenv( "G4GMocrenFile_MAX_FILE_NUM" ) != NULL ) { 160 char * pcFileNum = std::getenv("G4GMocrenF 159 char * pcFileNum = std::getenv("G4GMocrenFile_MAX_FILE_NUM"); 161 char c10FileNum[10]; 160 char c10FileNum[10]; 162 std::strncpy(c10FileNum, pcFileNum, 9); 161 std::strncpy(c10FileNum, pcFileNum, 9); 163 c10FileNum[9] = '\0'; 162 c10FileNum[9] = '\0'; 164 kMaxFileNum = std::atoi(c10FileNum); 163 kMaxFileNum = std::atoi(c10FileNum); 165 164 166 } else { 165 } else { 167 kMaxFileNum = FR_MAX_FILE_NUM ; 166 kMaxFileNum = FR_MAX_FILE_NUM ; 168 } 167 } 169 if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; } 168 if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; } 170 169 171 InitializeParameters(); 170 InitializeParameters(); 172 171 173 } 172 } 174 173 175 174 176 //----- G4GMocrenFileSceneHandler, destructor 175 //----- G4GMocrenFileSceneHandler, destructor 177 G4GMocrenFileSceneHandler::~G4GMocrenFileScene 176 G4GMocrenFileSceneHandler::~G4GMocrenFileSceneHandler () 178 { 177 { 179 if(GFDEBUG || G4VisManager::GetVerbosity() > 178 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 180 G4cout << "***** ~G4GMocrenFileSceneHand 179 G4cout << "***** ~G4GMocrenFileSceneHandler" << G4endl; 181 180 182 if(kGddDest) { 181 if(kGddDest) { 183 //----- End of modeling 182 //----- End of modeling 184 // close g4.gdd 183 // close g4.gdd 185 GFEndModeling(); 184 GFEndModeling(); 186 } 185 } 187 if(kgMocrenIO != NULL) delete kgMocrenIO; 186 if(kgMocrenIO != NULL) delete kgMocrenIO; 188 187 189 } 188 } 190 189 191 //----- initialize all parameters 190 //----- initialize all parameters 192 void G4GMocrenFileSceneHandler::InitializePara 191 void G4GMocrenFileSceneHandler::InitializeParameters() { 193 192 194 kbSetModalityVoxelSize = false; 193 kbSetModalityVoxelSize = false; 195 194 196 for(G4int i = 0; i < 3; i++) { 195 for(G4int i = 0; i < 3; i++) { 197 kModalitySize[i] = 0; 196 kModalitySize[i] = 0; 198 kNestedVolumeDimension[i] = 0; 197 kNestedVolumeDimension[i] = 0; 199 kNestedVolumeDirAxis[i] = -1; 198 kNestedVolumeDirAxis[i] = -1; 200 } 199 } 201 200 202 // delete kgMocrenIO; 201 // delete kgMocrenIO; 203 202 204 } 203 } 205 204 206 //----- 205 //----- 207 void G4GMocrenFileSceneHandler::SetGddFileName 206 void G4GMocrenFileSceneHandler::SetGddFileName() 208 { 207 { 209 // g4_00.gdd, g4_01.gdd, ..., g4_MAX_FILE_IN 208 // g4_00.gdd, g4_01.gdd, ..., g4_MAX_FILE_INDEX.gdd 210 const G4int MAX_FILE_INDEX = kMaxFileNum - 1 209 const G4int MAX_FILE_INDEX = kMaxFileNum - 1 ; 211 210 212 // dest directory (null if no environmental 211 // dest directory (null if no environmental variables is set) 213 std::strncpy(kGddFileName, kGddDestDir, size 212 std::strncpy(kGddFileName, kGddDestDir, sizeof(kGddFileName)-1); 214 kGddFileName[sizeof(kGddFileName)-1] = '\0'; 213 kGddFileName[sizeof(kGddFileName)-1] = '\0'; 215 214 216 // create full path name (default) 215 // create full path name (default) 217 std::strncat ( kGddFileName, DEFAULT_GDD_FIL 216 std::strncat ( kGddFileName, DEFAULT_GDD_FILE_NAME, 218 sizeof(kGddFileName) - std::st 217 sizeof(kGddFileName) - std::strlen(kGddFileName) - 1); 219 218 220 // Automatic updation of file names 219 // Automatic updation of file names 221 static G4int currentNumber = 0; 220 static G4int currentNumber = 0; 222 for( G4int i = currentNumber ; i < kMaxFileN 221 for( G4int i = currentNumber ; i < kMaxFileNum ; i++) { 223 222 224 // Message in the final execution 223 // Message in the final execution 225 if( i == MAX_FILE_INDEX ) 224 if( i == MAX_FILE_INDEX ) 226 { 225 { 227 if (G4VisManager::GetVerbosity() >= G4VisMan 226 if (G4VisManager::GetVerbosity() >= G4VisManager::warnings) { 228 G4cout << "=============================== 227 G4cout << "===========================================" << G4endl; 229 G4cout << "WARNING MESSAGE from GMocrenFil 228 G4cout << "WARNING MESSAGE from GMocrenFile driver: " << G4endl; 230 G4cout << " This file name is the final o 229 G4cout << " This file name is the final one in the " << G4endl; 231 G4cout << " automatic updation of the out 230 G4cout << " automatic updation of the output file name." << G4endl; 232 G4cout << " You may overwrite existing fi 231 G4cout << " You may overwrite existing files, i.e. " << G4endl; 233 G4cout << " g4_XX.gdd." << G4endl; 232 G4cout << " g4_XX.gdd." << G4endl; 234 G4cout << "=============================== 233 G4cout << "===========================================" << G4endl; 235 } 234 } 236 } 235 } 237 236 238 // re-determine file name as G4GMocrenFile 237 // re-determine file name as G4GMocrenFile_DEST_DIR/g4_XX.gdd 239 std::ostringstream filename; 238 std::ostringstream filename; 240 filename 239 filename 241 << kGddDestDir << GDD_FILE_HEADER 240 << kGddDestDir << GDD_FILE_HEADER 242 << std::setw(2) << std::setfill('0') << i 241 << std::setw(2) << std::setfill('0') << i << ".wrl"; 243 strncpy(kGddFileName,filename.str().c_str( 242 strncpy(kGddFileName,filename.str().c_str(),sizeof(kGddFileName)-1); 244 kGddFileName[sizeof(kGddFileName)-1] = '\0 243 kGddFileName[sizeof(kGddFileName)-1] = '\0'; 245 244 246 // check validity of the file name 245 // check validity of the file name 247 std::ifstream fin(kGddFileName); 246 std::ifstream fin(kGddFileName); 248 if(GFDEBUG) 247 if(GFDEBUG) 249 G4cout << "FILEOPEN: " << i << " : " << 248 G4cout << "FILEOPEN: " << i << " : " << kGddFileName << fin.fail() 250 << G4endl; 249 << G4endl; 251 if(!fin) { 250 if(!fin) { 252 // new file 251 // new file 253 fin.close(); 252 fin.close(); 254 currentNumber = i+1; 253 currentNumber = i+1; 255 break; 254 break; 256 } else { 255 } else { 257 // already exists (try next) 256 // already exists (try next) 258 fin.close(); 257 fin.close(); 259 } 258 } 260 259 261 } // for 260 } // for 262 261 263 G4cout << "================================= 262 G4cout << "======================================================================" << G4endl; 264 G4cout << "Output file: " << kGddFileName 263 G4cout << "Output file: " << kGddFileName << G4endl; 265 G4cout << "Destination directory (current di 264 G4cout << "Destination directory (current dir if NULL): " << kGddDestDir << G4endl; 266 G4cout << "Maximum number of files in the de 265 G4cout << "Maximum number of files in the destination directory: " << kMaxFileNum << G4endl; 267 G4cout << "Note:" << G4endl; 266 G4cout << "Note:" << G4endl; 268 G4cout << " * The maximum number is customi 267 G4cout << " * The maximum number is customizable as: " << G4endl; 269 G4cout << " % setenv G4GMocrenFile_MAX 268 G4cout << " % setenv G4GMocrenFile_MAX_FILE_NUM number " << G4endl; 270 G4cout << " * The destination directory is 269 G4cout << " * The destination directory is customizable as:" << G4endl; 271 G4cout << " % setenv G4GMocrenFile_DES 270 G4cout << " % setenv G4GMocrenFile_DEST_DIR dir_name/ " << G4endl; 272 G4cout << " ** Do not forget \"/\" at th 271 G4cout << " ** Do not forget \"/\" at the end of the dir_name, e.g. \"./tmp/\"." << G4endl; 273 //G4cout << " dir_name, e.g. \"./tmp/ 272 //G4cout << " dir_name, e.g. \"./tmp/\"." << G4endl; 274 G4cout << G4endl; 273 G4cout << G4endl; 275 G4cout << "Maximum number of trajectories is 274 G4cout << "Maximum number of trajectories is set to " << MAX_NUM_TRAJECTORIES << "."<< G4endl; 276 G4cout << "================================= 275 G4cout << "======================================================================" << G4endl; 277 276 278 } // G4GMocrenFileSceneHandler::SetGddFileName 277 } // G4GMocrenFileSceneHandler::SetGddFileName() 279 278 280 279 281 //----- 280 //----- 282 void G4GMocrenFileSceneHandler::BeginSavingGd 281 void G4GMocrenFileSceneHandler::BeginSavingGdd( void ) 283 { 282 { 284 if(GFDEBUG || G4VisManager::GetVerbosity() > 283 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 285 G4cout << "***** BeginSavingGdd (called) 284 G4cout << "***** BeginSavingGdd (called)" << G4endl; 286 285 287 if( !IsSavingGdd() ) { 286 if( !IsSavingGdd() ) { 288 287 289 if(GFDEBUG || G4VisManager::GetVerbosity() 288 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) { 290 G4cout << "***** (star 289 G4cout << "***** (started) " ; 291 G4cout << "(open g4.gdd, ##)" << G4endl 290 G4cout << "(open g4.gdd, ##)" << G4endl; 292 } 291 } 293 292 294 SetGddFileName() ; // result set to kGddFi 293 SetGddFileName() ; // result set to kGddFileName 295 kFlagSaving_g4_gdd = true; 294 kFlagSaving_g4_gdd = true; 296 295 297 296 298 G4GMocrenFileCTtoDensityMap ctdens; 297 G4GMocrenFileCTtoDensityMap ctdens; 299 short minmax[2]; 298 short minmax[2]; 300 minmax[0] = ctdens.GetMinCT(); 299 minmax[0] = ctdens.GetMinCT(); 301 minmax[1] = ctdens.GetMaxCT(); 300 minmax[1] = ctdens.GetMaxCT(); 302 kgMocrenIO->setModalityImageMinMax(minmax) 301 kgMocrenIO->setModalityImageMinMax(minmax); 303 std::vector<G4float> map; 302 std::vector<G4float> map; 304 G4float dens; 303 G4float dens; 305 for(G4int i = minmax[0]; i <= minmax[1]; i 304 for(G4int i = minmax[0]; i <= minmax[1]; i++) { 306 dens = ctdens.GetDensity(i); 305 dens = ctdens.GetDensity(i); 307 map.push_back(dens); 306 map.push_back(dens); 308 } 307 } 309 kgMocrenIO->setModalityImageDensityMap(map 308 kgMocrenIO->setModalityImageDensityMap(map); 310 309 311 /* 310 /* 312 G4String fname = "modality-map.dat"; 311 G4String fname = "modality-map.dat"; 313 std::ifstream ifile(fname); 312 std::ifstream ifile(fname); 314 if(ifile) { 313 if(ifile) { 315 short minmax[2]; 314 short minmax[2]; 316 ifile >> minmax[0] >> minmax[1]; 315 ifile >> minmax[0] >> minmax[1]; 317 kgMocrenIO->setModalityImageMinMax(minma 316 kgMocrenIO->setModalityImageMinMax(minmax); 318 std::vector<G4float> map; 317 std::vector<G4float> map; 319 G4float dens; 318 G4float dens; 320 for(G4int i = minmax[0]; i <= minmax[1]; 319 for(G4int i = minmax[0]; i <= minmax[1]; i++) { 321 ifile >> dens; 320 ifile >> dens; 322 map.push_back(dens); 321 map.push_back(dens); 323 } 322 } 324 kgMocrenIO->setModalityImageDensityMap(m 323 kgMocrenIO->setModalityImageDensityMap(map); 325 324 326 } else { 325 } else { 327 G4cout << "cann't open the file : " << f 326 G4cout << "cann't open the file : " << fname << G4endl; 328 } 327 } 329 */ 328 */ 330 329 331 // mesh size 330 // mesh size 332 //kMessenger.getNoVoxels(kModalitySize[0], 331 //kMessenger.getNoVoxels(kModalitySize[0], kModalitySize[1], kModalitySize[2]); 333 //kgMocrenIO->setModalityImageSize(kModali 332 //kgMocrenIO->setModalityImageSize(kModalitySize); 334 333 335 // initializations 334 // initializations 336 //kgMocrenIO->clearModalityImage(); 335 //kgMocrenIO->clearModalityImage(); 337 kgMocrenIO->clearDoseDistAll(); 336 kgMocrenIO->clearDoseDistAll(); 338 kgMocrenIO->clearROIAll(); 337 kgMocrenIO->clearROIAll(); 339 kgMocrenIO->clearTracks(); 338 kgMocrenIO->clearTracks(); 340 kgMocrenIO->clearDetector(); 339 kgMocrenIO->clearDetector(); 341 std::vector<Detector>::iterator itr = kDet 340 std::vector<Detector>::iterator itr = kDetectors.begin(); 342 for(; itr != kDetectors.end(); itr++) { 341 for(; itr != kDetectors.end(); itr++) { 343 itr->clear(); 342 itr->clear(); 344 } 343 } 345 kDetectors.clear(); 344 kDetectors.clear(); 346 345 347 kNestedHitsList.clear(); 346 kNestedHitsList.clear(); 348 kNestedVolumeNames.clear(); 347 kNestedVolumeNames.clear(); 349 348 350 } 349 } 351 } 350 } 352 351 353 void G4GMocrenFileSceneHandler::EndSavingGdd 352 void G4GMocrenFileSceneHandler::EndSavingGdd ( void ) 354 { 353 { 355 if(GFDEBUG || G4VisManager::GetVerbosity() > 354 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 356 G4cout << "***** EndSavingGdd (called)" << 355 G4cout << "***** EndSavingGdd (called)" << G4endl; 357 356 358 if(IsSavingGdd()) { 357 if(IsSavingGdd()) { 359 if(GFDEBUG || G4VisManager::GetVerbosity() 358 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 360 G4cout << "***** (starte 359 G4cout << "***** (started) (close " 361 << kGddFileName << ")" << G4endl; 360 << kGddFileName << ")" << G4endl; 362 361 363 if(kGddDest) kGddDest.close(); 362 if(kGddDest) kGddDest.close(); 364 kFlagSaving_g4_gdd = false; 363 kFlagSaving_g4_gdd = false; 365 364 366 std::map<Index3D, G4float>::iterator itr = 365 std::map<Index3D, G4float>::iterator itr = kNestedModality.begin(); 367 G4int xmax=0, ymax=0, zmax=0; 366 G4int xmax=0, ymax=0, zmax=0; 368 for(; itr != kNestedModality.end(); itr++) 367 for(; itr != kNestedModality.end(); itr++) { 369 if(itr->first.x > xmax) xmax = itr->firs 368 if(itr->first.x > xmax) xmax = itr->first.x; 370 if(itr->first.y > ymax) ymax = itr->firs 369 if(itr->first.y > ymax) ymax = itr->first.y; 371 if(itr->first.z > zmax) zmax = itr->firs 370 if(itr->first.z > zmax) zmax = itr->first.z; 372 } 371 } 373 // mesh size 372 // mesh size 374 kModalitySize[0] = xmax+1; 373 kModalitySize[0] = xmax+1; 375 kModalitySize[1] = ymax+1; 374 kModalitySize[1] = ymax+1; 376 kModalitySize[2] = zmax+1; 375 kModalitySize[2] = zmax+1; 377 kgMocrenIO->setModalityImageSize(kModality 376 kgMocrenIO->setModalityImageSize(kModalitySize); 378 if(GFDEBUG) G4cout << "gMocren-file driver 377 if(GFDEBUG) G4cout << "gMocren-file driver : modality size : " 379 << kModalitySize[0] << " x " 378 << kModalitySize[0] << " x " 380 << kModalitySize[1] << " x " 379 << kModalitySize[1] << " x " 381 << kModalitySize[2] << G4endl; 380 << kModalitySize[2] << G4endl; 382 381 383 G4int nxy = kModalitySize[0]*kModalitySize 382 G4int nxy = kModalitySize[0]*kModalitySize[1]; 384 //std::map<G4int, G4float>::iterator itr; 383 //std::map<G4int, G4float>::iterator itr; 385 for(G4int z = 0; z < kModalitySize[2]; z++ 384 for(G4int z = 0; z < kModalitySize[2]; z++) { 386 short * modality = new short[nxy]; 385 short * modality = new short[nxy]; 387 for(G4int y = 0; y < kModalitySize[1]; y 386 for(G4int y = 0; y < kModalitySize[1]; y++) { 388 for(G4int x = 0; x < kModalitySize[0]; x++) 387 for(G4int x = 0; x < kModalitySize[0]; x++) { 389 //for(G4int x = kModalitySize[0]-1; x >= 0 388 //for(G4int x = kModalitySize[0]-1; x >= 0 ; x--) { 390 //G4int ixy = x + (kModalitySize[1]-y-1)*k 389 //G4int ixy = x + (kModalitySize[1]-y-1)*kModalitySize[0]; 391 390 392 G4int ixy = x + y*kModalitySize[0]; 391 G4int ixy = x + y*kModalitySize[0]; 393 Index3D idx(x,y,z); 392 Index3D idx(x,y,z); 394 itr = kNestedModality.find(idx); 393 itr = kNestedModality.find(idx); 395 if(itr != kNestedModality.end()) { 394 if(itr != kNestedModality.end()) { 396 395 397 modality[ixy] = kgMocrenIO->convertDensi 396 modality[ixy] = kgMocrenIO->convertDensityToHU(itr->second); 398 } else { 397 } else { 399 modality[ixy] = -1024; 398 modality[ixy] = -1024; 400 } 399 } 401 400 402 } 401 } 403 } 402 } 404 kgMocrenIO->setModalityImage(modality); 403 kgMocrenIO->setModalityImage(modality); 405 } 404 } 406 405 407 //-- dose 406 //-- dose 408 size_t nhits = kNestedHitsList.size(); 407 size_t nhits = kNestedHitsList.size(); 409 if(GFDEBUG) G4cout << "gMocren-file driver 408 if(GFDEBUG) G4cout << "gMocren-file driver : # hits = " << nhits << G4endl; 410 409 411 std::map<Index3D, G4double>::iterator hits 410 std::map<Index3D, G4double>::iterator hitsItr; 412 std::map<G4String, std::map<Index3D, G4dou 411 std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr = kNestedHitsList.begin(); 413 412 414 for(G4int n = 0; hitsListItr != kNestedHit 413 for(G4int n = 0; hitsListItr != kNestedHitsList.end(); hitsListItr++, n++) { 415 414 416 kgMocrenIO->newDoseDist(); 415 kgMocrenIO->newDoseDist(); 417 kgMocrenIO->setDoseDistName(hitsListItr- 416 kgMocrenIO->setDoseDistName(hitsListItr->first, n); 418 kgMocrenIO->setDoseDistSize(kModalitySiz 417 kgMocrenIO->setDoseDistSize(kModalitySize, n); 419 418 420 G4double minmax[2] = {DBL_MAX, -DBL_MAX} 419 G4double minmax[2] = {DBL_MAX, -DBL_MAX}; 421 for(G4int z = 0 ; z < kModalitySize[2]; 420 for(G4int z = 0 ; z < kModalitySize[2]; z++) { 422 G4double * values = new G4double[nxy]; 421 G4double * values = new G4double[nxy]; 423 for(G4int y = 0; y < kModalitySize[1]; y++) 422 for(G4int y = 0; y < kModalitySize[1]; y++) { 424 for(G4int x = 0; x < kModalitySize[0]; x++ 423 for(G4int x = 0; x < kModalitySize[0]; x++) { 425 424 426 G4int ixy = x + y*kModalitySize[0]; 425 G4int ixy = x + y*kModalitySize[0]; 427 Index3D idx(x,y,z); 426 Index3D idx(x,y,z); 428 hitsItr = hitsListItr->second.find(idx); 427 hitsItr = hitsListItr->second.find(idx); 429 if(hitsItr != hitsListItr->second.end()) 428 if(hitsItr != hitsListItr->second.end()) { 430 429 431 values[ixy] = hitsItr->second; 430 values[ixy] = hitsItr->second; 432 } else { 431 } else { 433 values[ixy] = 0.; 432 values[ixy] = 0.; 434 } 433 } 435 if(values[ixy] < minmax[0]) minmax[0] = 434 if(values[ixy] < minmax[0]) minmax[0] = values[ixy]; 436 if(values[ixy] > minmax[1]) minmax[1] = 435 if(values[ixy] > minmax[1]) minmax[1] = values[ixy]; 437 } 436 } 438 } 437 } 439 kgMocrenIO->setDoseDist(values, n); 438 kgMocrenIO->setDoseDist(values, n); 440 } 439 } 441 kgMocrenIO->setDoseDistMinMax(minmax, n) 440 kgMocrenIO->setDoseDistMinMax(minmax, n); 442 G4double lower = 0.; 441 G4double lower = 0.; 443 if(minmax[0] < 0) lower = minmax[0]; 442 if(minmax[0] < 0) lower = minmax[0]; 444 G4double scale = (minmax[1]-lower)/25000 443 G4double scale = (minmax[1]-lower)/25000.; 445 kgMocrenIO->setDoseDistScale(scale, n); 444 kgMocrenIO->setDoseDistScale(scale, n); 446 G4String sunit("unit?"); //temporarily 445 G4String sunit("unit?"); //temporarily 447 kgMocrenIO->setDoseDistUnit(sunit, n); 446 kgMocrenIO->setDoseDistUnit(sunit, n); 448 } 447 } 449 448 450 449 451 //-- draw axes 450 //-- draw axes 452 if(false) {//true,false 451 if(false) {//true,false 453 G4ThreeVector trans; 452 G4ThreeVector trans; 454 G4RotationMatrix rot; 453 G4RotationMatrix rot; 455 trans = kVolumeTrans3D.getTranslation(); 454 trans = kVolumeTrans3D.getTranslation(); 456 rot = kVolumeTrans3D.getRotation().inver 455 rot = kVolumeTrans3D.getRotation().inverse(); 457 // x 456 // x 458 std::vector<G4float *> tracks; 457 std::vector<G4float *> tracks; 459 unsigned char colors[3]; 458 unsigned char colors[3]; 460 G4float * trk = new G4float[6]; 459 G4float * trk = new G4float[6]; 461 tracks.push_back(trk); 460 tracks.push_back(trk); 462 461 463 G4ThreeVector orig(0.,0.,0), xa(2000.,0. 462 G4ThreeVector orig(0.,0.,0), xa(2000.,0.,0.), ya(0.,2000.,0.), za(0.,0.,2000.); 464 orig -= trans; 463 orig -= trans; 465 orig.transform(rot); 464 orig.transform(rot); 466 xa -= trans; 465 xa -= trans; 467 xa.transform(rot); 466 xa.transform(rot); 468 ya -= trans; 467 ya -= trans; 469 ya.transform(rot); 468 ya.transform(rot); 470 za -= trans; 469 za -= trans; 471 za.transform(rot); 470 za.transform(rot); 472 for(G4int i = 0; i < 3; i++) trk[i] = or 471 for(G4int i = 0; i < 3; i++) trk[i] = orig[i]; 473 for(G4int i = 0; i < 3; i++) trk[i+3] = 472 for(G4int i = 0; i < 3; i++) trk[i+3] = xa[i]; 474 colors[0] = 255; colors[1] = 0; colors[2 473 colors[0] = 255; colors[1] = 0; colors[2] = 0; 475 kgMocrenIO->addTrack(tracks, colors); 474 kgMocrenIO->addTrack(tracks, colors); 476 // y 475 // y 477 for(G4int i = 0; i < 3; i++) trk[i+3] = 476 for(G4int i = 0; i < 3; i++) trk[i+3] = ya[i]; 478 colors[0] = 0; colors[1] = 255; colors[2 477 colors[0] = 0; colors[1] = 255; colors[2] = 0; 479 kgMocrenIO->addTrack(tracks, colors); 478 kgMocrenIO->addTrack(tracks, colors); 480 // z 479 // z 481 for(G4int i = 0; i < 3; i++) trk[i+3] = 480 for(G4int i = 0; i < 3; i++) trk[i+3] = za[i]; 482 colors[0] = 0; colors[1] = 0; colors[2] 481 colors[0] = 0; colors[1] = 0; colors[2] = 255; 483 kgMocrenIO->addTrack(tracks, colors); 482 kgMocrenIO->addTrack(tracks, colors); 484 } 483 } 485 484 486 //-- detector 485 //-- detector 487 ExtractDetector(); 486 ExtractDetector(); 488 487 489 488 490 if(GFDEBUG_DET) G4cout << ">>>>>>>>>>>>>>> 489 if(GFDEBUG_DET) G4cout << ">>>>>>>>>>>>>>>>>>>>>> ("; 491 std::vector<G4float> transformObjects; 490 std::vector<G4float> transformObjects; 492 for(G4int i = 0; i < 3; i++) { 491 for(G4int i = 0; i < 3; i++) { 493 // need to check!! 492 // need to check!! 494 transformObjects.push_back((kVolumeSize[ 493 transformObjects.push_back((kVolumeSize[i]/2. - kVoxelDimension[i]/2.)); 495 if(GFDEBUG_DET) G4cout << transformObjec 494 if(GFDEBUG_DET) G4cout << transformObjects[i] << ", "; 496 } 495 } 497 if(GFDEBUG_DET) G4cout << ")" << G4endl; 496 if(GFDEBUG_DET) G4cout << ")" << G4endl; 498 497 499 498 500 kgMocrenIO->translateTracks(transformObjec 499 kgMocrenIO->translateTracks(transformObjects); 501 kgMocrenIO->translateDetector(transformObj 500 kgMocrenIO->translateDetector(transformObjects); 502 501 503 // store 502 // store 504 kgMocrenIO->storeData(kGddFileName); 503 kgMocrenIO->storeData(kGddFileName); 505 } 504 } 506 505 507 } 506 } 508 507 509 508 510 //----- 509 //----- 511 void G4GMocrenFileSceneHandler::GFBeginModelin 510 void G4GMocrenFileSceneHandler::GFBeginModeling( void ) 512 { 511 { 513 G4VSceneHandler::BeginModeling(); 512 G4VSceneHandler::BeginModeling(); 514 513 515 if( !GFIsInModeling() ) { 514 if( !GFIsInModeling() ) { 516 515 517 if(GFDEBUG || G4VisManager::GetVerbosity() 516 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 518 G4cout << "***** G4GMocrenFileSceneHandl 517 G4cout << "***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" << G4endl; 519 518 520 //----- Send saving command and heading co 519 //----- Send saving command and heading comment 521 BeginSavingGdd(); 520 BeginSavingGdd(); 522 521 523 kFlagInModeling = true ; 522 kFlagInModeling = true ; 524 523 525 // These models are entrusted to user comm 524 // These models are entrusted to user commands /vis/scene/add/psHits or hits 526 //GetScene()->AddEndOfEventModel(new G4PSH 525 //GetScene()->AddEndOfEventModel(new G4PSHitsModel()); 527 //GetScene()->AddEndOfRunModel(new G4PSHit 526 //GetScene()->AddEndOfRunModel(new G4PSHitsModel()); 528 //scene->AddEndOfEventModel(new G4HitsMode 527 //scene->AddEndOfEventModel(new G4HitsModel()); 529 if(GFDEBUG_HIT) { 528 if(GFDEBUG_HIT) { 530 G4Scene * scene = GetScene(); 529 G4Scene * scene = GetScene(); 531 std::vector<G4Scene::Model> vmodel = sce 530 std::vector<G4Scene::Model> vmodel = scene->GetEndOfEventModelList(); 532 std::vector<G4Scene::Model>::iterator it 531 std::vector<G4Scene::Model>::iterator itr = vmodel.begin(); 533 for(; itr != vmodel.end(); itr++) { 532 for(; itr != vmodel.end(); itr++) { 534 G4cout << " IIIIII model name: " << it 533 G4cout << " IIIIII model name: " << itr->fpModel->GetGlobalTag() << G4endl; 535 } 534 } 536 } 535 } 537 } 536 } 538 } 537 } 539 538 540 539 541 //========== AddPrimitive() functions ======== 540 //========== AddPrimitive() functions ==========// 542 541 543 //----- Add polyline 542 //----- Add polyline 544 void G4GMocrenFileSceneHandler::AddPrimitive ( 543 void G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline& polyline) 545 { 544 { 546 if(GFDEBUG || G4VisManager::GetVerbosity() > 545 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 547 G4cout << "***** AddPrimitive" << G4endl; 546 G4cout << "***** AddPrimitive" << G4endl; 548 547 549 if (fProcessing2D) { 548 if (fProcessing2D) { 550 static G4bool warned = false; 549 static G4bool warned = false; 551 if (!warned) { 550 if (!warned) { 552 warned = true; 551 warned = true; 553 G4Exception 552 G4Exception 554 ("G4GMocrenFileSceneHandler::AddPrimitive (c 553 ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)", 555 "gMocren1001", JustWarning, 554 "gMocren1001", JustWarning, 556 "2D polylines not implemented. Ignored."); 555 "2D polylines not implemented. Ignored."); 557 } 556 } 558 return; 557 return; 559 } 558 } 560 559 561 //----- Initialize if necessary 560 //----- Initialize if necessary 562 GFBeginModeling(); 561 GFBeginModeling(); 563 562 564 static G4int numTrajectories = 0; 563 static G4int numTrajectories = 0; 565 if(numTrajectories >= MAX_NUM_TRAJECTORIES) 564 if(numTrajectories >= MAX_NUM_TRAJECTORIES) return; 566 565 567 // draw trajectories 566 // draw trajectories 568 if(kbModelingTrajectory) { 567 if(kbModelingTrajectory) { 569 568 570 G4TrajectoriesModel * pTrModel = dynamic_c 569 G4TrajectoriesModel * pTrModel = dynamic_cast<G4TrajectoriesModel*>(fpModel); 571 if (!pTrModel) { 570 if (!pTrModel) { 572 G4Exception 571 G4Exception 573 ("G4VSceneHandler::AddCompound(const G4Polyl 572 ("G4VSceneHandler::AddCompound(const G4Polyline&)", 574 "gMocren0002", FatalException, "Not a G4Tra 573 "gMocren0002", FatalException, "Not a G4TrajectoriesModel."); 575 } 574 } 576 575 577 G4ThreeVector trans; 576 G4ThreeVector trans; 578 G4RotationMatrix rot; 577 G4RotationMatrix rot; 579 trans = kVolumeTrans3D.getTranslation(); 578 trans = kVolumeTrans3D.getTranslation(); 580 rot = kVolumeTrans3D.getRotation().inverse 579 rot = kVolumeTrans3D.getRotation().inverse(); 581 580 582 if(GFDEBUG_TRK) G4cout << " trajectory p 581 if(GFDEBUG_TRK) G4cout << " trajectory points : " << G4endl; 583 std::vector<G4float *> trajectory; 582 std::vector<G4float *> trajectory; 584 if(polyline.size() < 2) return; 583 if(polyline.size() < 2) return; 585 G4Polyline::const_iterator preitr = polyli 584 G4Polyline::const_iterator preitr = polyline.begin(); 586 G4Polyline::const_iterator postitr = preit 585 G4Polyline::const_iterator postitr = preitr; postitr++; 587 for(; postitr != polyline.end(); preitr++, 586 for(; postitr != polyline.end(); preitr++, postitr++) { 588 G4ThreeVector prePts(preitr->x(), preitr 587 G4ThreeVector prePts(preitr->x(), preitr->y(), preitr->z()); 589 prePts -= trans; 588 prePts -= trans; 590 prePts.transform(rot); 589 prePts.transform(rot); 591 G4ThreeVector postPts(postitr->x(), post 590 G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z()); 592 postPts -= trans; 591 postPts -= trans; 593 postPts.transform(rot); 592 postPts.transform(rot); 594 G4float * stepPts = new G4float[6]; 593 G4float * stepPts = new G4float[6]; 595 stepPts[0] = prePts.x(); 594 stepPts[0] = prePts.x(); 596 stepPts[1] = prePts.y(); 595 stepPts[1] = prePts.y(); 597 stepPts[2] = prePts.z(); 596 stepPts[2] = prePts.z(); 598 stepPts[3] = postPts.x(); 597 stepPts[3] = postPts.x(); 599 stepPts[4] = postPts.y(); 598 stepPts[4] = postPts.y(); 600 stepPts[5] = postPts.z(); 599 stepPts[5] = postPts.z(); 601 trajectory.push_back(stepPts); 600 trajectory.push_back(stepPts); 602 601 603 if(GFDEBUG_TRK) { 602 if(GFDEBUG_TRK) { 604 G4cout << " (" 603 G4cout << " (" 605 << stepPts[0] << ", " 604 << stepPts[0] << ", " 606 << stepPts[1] << ", " 605 << stepPts[1] << ", " 607 << stepPts[2] << ") - (" 606 << stepPts[2] << ") - (" 608 << stepPts[3] << ", " 607 << stepPts[3] << ", " 609 << stepPts[4] << ", " 608 << stepPts[4] << ", " 610 << stepPts[5] << ")" << G4endl; 609 << stepPts[5] << ")" << G4endl; 611 } 610 } 612 } 611 } 613 612 614 const G4VisAttributes * att = polyline.Get 613 const G4VisAttributes * att = polyline.GetVisAttributes(); 615 G4Color color = att->GetColor(); 614 G4Color color = att->GetColor(); 616 unsigned char trkcolor[3]; 615 unsigned char trkcolor[3]; 617 trkcolor[0] = (unsigned char)(color.GetRed 616 trkcolor[0] = (unsigned char)(color.GetRed()*255); 618 trkcolor[1] = (unsigned char)(color.GetGre 617 trkcolor[1] = (unsigned char)(color.GetGreen()*255); 619 trkcolor[2] = (unsigned char)(color.GetBlu 618 trkcolor[2] = (unsigned char)(color.GetBlue()*255); 620 if(GFDEBUG_TRK) { 619 if(GFDEBUG_TRK) { 621 G4cout << " color : [" 620 G4cout << " color : [" 622 << color.GetRed() << ", " 621 << color.GetRed() << ", " 623 << color.GetGreen() << ", " 622 << color.GetGreen() << ", " 624 << color.GetBlue() << "]" << G4endl; 623 << color.GetBlue() << "]" << G4endl; 625 } 624 } 626 625 627 kgMocrenIO->addTrack(trajectory, trkcolor) 626 kgMocrenIO->addTrack(trajectory, trkcolor); 628 627 629 numTrajectories++; 628 numTrajectories++; 630 } 629 } 631 630 632 } // G4GMocrenFileSceneHandler::AddPrimitive ( 631 } // G4GMocrenFileSceneHandler::AddPrimitive (polyline) 633 632 634 633 635 //----- Add text 634 //----- Add text 636 void G4GMocrenFileSceneHandler::AddPrimitive ( 635 void G4GMocrenFileSceneHandler::AddPrimitive ( const G4Text& text ) 637 { 636 { 638 if (fProcessing2D) { 637 if (fProcessing2D) { 639 static G4bool warned = false; 638 static G4bool warned = false; 640 if (!warned) { 639 if (!warned) { 641 warned = true; 640 warned = true; 642 G4Exception 641 G4Exception 643 ("G4GMocrenFileSceneHandler::AddPrimitive (c 642 ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)", 644 "gMocren1002", JustWarning, 643 "gMocren1002", JustWarning, 645 "2D text not implemented. Ignored."); 644 "2D text not implemented. Ignored."); 646 } 645 } 647 return; 646 return; 648 } 647 } 649 648 650 // to avoid a warning in the compile process 649 // to avoid a warning in the compile process 651 G4Text dummytext = text; 650 G4Text dummytext = text; 652 651 653 //----- 652 //----- 654 if(GFDEBUG || G4VisManager::GetVerbosity() > 653 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 655 G4cout << "***** AddPrimitive( G4Text )" < 654 G4cout << "***** AddPrimitive( G4Text )" << G4endl; 656 655 657 //----- Initialize IF NECESSARY 656 //----- Initialize IF NECESSARY 658 GFBeginModeling(); 657 GFBeginModeling(); 659 658 660 } // G4GMocrenFileSceneHandler::AddPrimitive ( 659 } // G4GMocrenFileSceneHandler::AddPrimitive ( text ) 661 660 662 661 663 //----- Add circle 662 //----- Add circle 664 void G4GMocrenFileSceneHandler::AddPrimitive ( 663 void G4GMocrenFileSceneHandler::AddPrimitive ( const G4Circle& mark_circle ) 665 { 664 { 666 // to avoid a warning in the compile process 665 // to avoid a warning in the compile process 667 G4Circle dummycircle = mark_circle; 666 G4Circle dummycircle = mark_circle; 668 667 669 if (fProcessing2D) { 668 if (fProcessing2D) { 670 static G4bool warned = false; 669 static G4bool warned = false; 671 if (!warned) { 670 if (!warned) { 672 warned = true; 671 warned = true; 673 G4Exception 672 G4Exception 674 ("G4GMocrenFileSceneHandler::AddPrimitive (c 673 ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)", 675 "gMocren1003", JustWarning, 674 "gMocren1003", JustWarning, 676 "2D circles not implemented. Ignored."); 675 "2D circles not implemented. Ignored."); 677 } 676 } 678 return; 677 return; 679 } 678 } 680 679 681 //----- 680 //----- 682 if(GFDEBUG || G4VisManager::GetVerbosity() > 681 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 683 G4cout << "***** AddPrimitive( G4Circle )" 682 G4cout << "***** AddPrimitive( G4Circle )" << G4endl; 684 683 685 //----- Initialize IF NECESSARY 684 //----- Initialize IF NECESSARY 686 GFBeginModeling(); 685 GFBeginModeling(); 687 686 688 687 689 } // G4GMocrenFileSceneHandler::AddPrimitive ( 688 } // G4GMocrenFileSceneHandler::AddPrimitive ( mark_circle ) 690 689 691 690 692 //----- Add square 691 //----- Add square 693 void G4GMocrenFileSceneHandler::AddPrimitive ( 692 void G4GMocrenFileSceneHandler::AddPrimitive (const G4Square& mark_square ) 694 { 693 { 695 // to avoid a warning in the compile process 694 // to avoid a warning in the compile process 696 G4Square dummysquare = mark_square; 695 G4Square dummysquare = mark_square; 697 696 698 if (fProcessing2D) { 697 if (fProcessing2D) { 699 static G4bool warned = false; 698 static G4bool warned = false; 700 if (!warned) { 699 if (!warned) { 701 warned = true; 700 warned = true; 702 G4Exception 701 G4Exception 703 ("G4GMocrenFileSceneHandler::AddPrimitive (c 702 ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)", 704 "gMocren1004", JustWarning, 703 "gMocren1004", JustWarning, 705 "2D squares not implemented. Ignored."); 704 "2D squares not implemented. Ignored."); 706 } 705 } 707 return; 706 return; 708 } 707 } 709 708 710 //----- 709 //----- 711 if(GFDEBUG || G4VisManager::GetVerbosity() > 710 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 712 G4cout << "***** AddPrimitive( G4Square )" 711 G4cout << "***** AddPrimitive( G4Square )" << G4endl; 713 712 714 //----- Initialize if necessary 713 //----- Initialize if necessary 715 GFBeginModeling(); 714 GFBeginModeling(); 716 715 717 } // G4GMocrenFileSceneHandler::AddPrimitive ( 716 } // G4GMocrenFileSceneHandler::AddPrimitive ( mark_square ) 718 717 719 718 720 //----- Add polyhedron 719 //----- Add polyhedron 721 void G4GMocrenFileSceneHandler::AddPrimitive ( 720 void G4GMocrenFileSceneHandler::AddPrimitive ( const G4Polyhedron& polyhedron ) 722 { 721 { 723 //----- 722 //----- 724 if(GFDEBUG || G4VisManager::GetVerbosity() > 723 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 725 G4cout << "***** AddPrimitive( G4Polyhedro 724 G4cout << "***** AddPrimitive( G4Polyhedron )" << G4endl; 726 725 727 726 728 if (polyhedron.GetNoFacets() == 0) return; 727 if (polyhedron.GetNoFacets() == 0) return; 729 728 730 if (fProcessing2D) { 729 if (fProcessing2D) { 731 static G4bool warned = false; 730 static G4bool warned = false; 732 if (!warned) { 731 if (!warned) { 733 warned = true; 732 warned = true; 734 G4Exception 733 G4Exception 735 ("G4GMocrenFileSceneHandler::AddPrimitive (c 734 ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)", 736 "gMocren1005", JustWarning, 735 "gMocren1005", JustWarning, 737 "2D polyhedra not implemented. Ignored."); 736 "2D polyhedra not implemented. Ignored."); 738 } 737 } 739 return; 738 return; 740 } 739 } 741 740 742 //----- Initialize if necessary 741 //----- Initialize if necessary 743 GFBeginModeling(); 742 GFBeginModeling(); 744 743 745 //---------- (3) Facet block 744 //---------- (3) Facet block 746 for (G4int f = polyhedron.GetNoFacets(); f; 745 for (G4int f = polyhedron.GetNoFacets(); f; f--){ 747 G4bool notLastEdge = true; 746 G4bool notLastEdge = true; 748 G4int index = -1; // initialization 747 G4int index = -1; // initialization 749 G4int edgeFlag = 1; 748 G4int edgeFlag = 1; 750 //G4int preedgeFlag = 1; 749 //G4int preedgeFlag = 1; 751 //G4int work[4], i = 0; 750 //G4int work[4], i = 0; 752 G4int i = 0; 751 G4int i = 0; 753 do { 752 do { 754 //preedgeFlag = edgeFlag; 753 //preedgeFlag = edgeFlag; 755 notLastEdge = polyhedron.GetNextVertexIn 754 notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag); 756 //work[i++] = index; 755 //work[i++] = index; 757 i++; 756 i++; 758 }while (notLastEdge); 757 }while (notLastEdge); 759 switch (i){ 758 switch (i){ 760 case 3: 759 case 3: 761 //SendStrInt3(FR_FACET, work[0], work[1] 760 //SendStrInt3(FR_FACET, work[0], work[1], work[2] ); 762 break; 761 break; 763 case 4: 762 case 4: 764 //SendStrInt4(FR_FACET, work[0], work[1] 763 //SendStrInt4(FR_FACET, work[0], work[1], work[2], work[3] ); 765 break; 764 break; 766 default: 765 default: 767 if(GFDEBUG || G4VisManager::GetVerbosity 766 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 768 G4cout << 767 G4cout << 769 "ERROR G4GMocrenFileSceneHandler::AddPrimi 768 "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" << G4endl; 770 G4PhysicalVolumeModel* pPVModel = 769 G4PhysicalVolumeModel* pPVModel = 771 dynamic_cast<G4PhysicalVolumeModel*>(f 770 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 772 if (pPVModel) 771 if (pPVModel) 773 if(G4VisManager::GetVerbosity() >= G4VisMana 772 if(G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 774 G4cout << "Volume " << pPVModel->GetCurren 773 G4cout << "Volume " << pPVModel->GetCurrentPV()->GetName() << 775 ", Solid " << pPVModel->GetCurrentLV()-> 774 ", Solid " << pPVModel->GetCurrentLV()->GetSolid()->GetName() << 776 " (" << pPVModel->GetCurrentLV()->GetSol 775 " (" << pPVModel->GetCurrentLV()->GetSolid()->GetEntityType(); 777 776 778 if(G4VisManager::GetVerbosity() >= G4Vis 777 if(G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 779 G4cout << 778 G4cout << 780 "\nG4Polyhedron facet with " << i << " edg 779 "\nG4Polyhedron facet with " << i << " edges" << G4endl; 781 } 780 } 782 } 781 } 783 782 784 } // G4GMocrenFileSceneHandler::AddPrimitive ( 783 } // G4GMocrenFileSceneHandler::AddPrimitive (polyhedron) 785 784 786 785 787 //----- 786 //----- 788 void G4GMocrenFileSceneHandler::GFEndModeling 787 void G4GMocrenFileSceneHandler::GFEndModeling () 789 { 788 { 790 G4VSceneHandler::EndModeling(); 789 G4VSceneHandler::EndModeling(); 791 790 792 //----- 791 //----- 793 if(GFDEBUG || G4VisManager::GetVerbosity() > 792 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 794 G4cout << "***** GFEndModeling (called)" < 793 G4cout << "***** GFEndModeling (called)" << G4endl; 795 794 796 if( GFIsInModeling() ) { 795 if( GFIsInModeling() ) { 797 796 798 if(GFDEBUG || G4VisManager::GetVerbosity() 797 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) { 799 G4cout << "***** GFEndModeling (started) 798 G4cout << "***** GFEndModeling (started) " ; 800 G4cout << "(/EndModeling, /DrawAll, /Clo 799 G4cout << "(/EndModeling, /DrawAll, /CloseDevice)" << G4endl; 801 } 800 } 802 801 803 //----- End saving data to g4.gdd 802 //----- End saving data to g4.gdd 804 EndSavingGdd() ; 803 EndSavingGdd() ; 805 804 806 //------ Reset flag 805 //------ Reset flag 807 kFlagInModeling = false ; 806 kFlagInModeling = false ; 808 807 809 } 808 } 810 809 811 } 810 } 812 811 813 812 814 //----- 813 //----- 815 void G4GMocrenFileSceneHandler::BeginPrimitive 814 void G4GMocrenFileSceneHandler::BeginPrimitives (const G4Transform3D& objectTransformation) 816 { 815 { 817 if(GFDEBUG || G4VisManager::GetVerbosity() > 816 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 818 G4cout << "***** BeginPrimitives " << G4en 817 G4cout << "***** BeginPrimitives " << G4endl; 819 818 820 GFBeginModeling(); 819 GFBeginModeling(); 821 820 822 G4VSceneHandler::BeginPrimitives (objectTran 821 G4VSceneHandler::BeginPrimitives (objectTransformation); 823 822 824 } 823 } 825 824 826 825 827 //----- 826 //----- 828 void G4GMocrenFileSceneHandler::EndPrimitives 827 void G4GMocrenFileSceneHandler::EndPrimitives () 829 { 828 { 830 if(GFDEBUG || G4VisManager::GetVerbosity() > 829 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 831 G4cout << "***** EndPrimitives " << G4endl 830 G4cout << "***** EndPrimitives " << G4endl; 832 831 833 G4VSceneHandler::EndPrimitives (); 832 G4VSceneHandler::EndPrimitives (); 834 } 833 } 835 834 836 835 837 //========== AddSolid() functions ==========// 836 //========== AddSolid() functions ==========// 838 837 839 //----- Add box 838 //----- Add box 840 void G4GMocrenFileSceneHandler::AddSolid( cons 839 void G4GMocrenFileSceneHandler::AddSolid( const G4Box& box ) 841 { 840 { 842 if(GFDEBUG || G4VisManager::GetVerbosity() > 841 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 843 G4cout << "***** AddSolid ( box )" << G4en 842 G4cout << "***** AddSolid ( box )" << G4endl; 844 843 845 if(GFDEBUG_DET > 0) 844 if(GFDEBUG_DET > 0) 846 G4cout << "G4GMocrenFileSceneHandler::AddS 845 G4cout << "G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : " 847 << box.GetName() << G4endl; 846 << box.GetName() << G4endl; 848 847 849 //----- skip drawing invisible primitive 848 //----- skip drawing invisible primitive 850 if( !IsVisible() ) { return ; } 849 if( !IsVisible() ) { return ; } 851 850 852 //----- Initialize if necessary 851 //----- Initialize if necessary 853 GFBeginModeling(); 852 GFBeginModeling(); 854 853 855 854 856 //-- 855 //-- 857 if(GFDEBUG_DET > 1) { 856 if(GFDEBUG_DET > 1) { 858 G4cout << "-------" << G4endl; 857 G4cout << "-------" << G4endl; 859 G4cout << " " << box.GetName() << G4end 858 G4cout << " " << box.GetName() << G4endl; 860 G4Polyhedron * poly = box.CreatePolyhedron 859 G4Polyhedron * poly = box.CreatePolyhedron(); 861 poly->Transform(fObjectTransformation); 860 poly->Transform(fObjectTransformation); 862 //G4int nv = poly->GetNoVertices(); 861 //G4int nv = poly->GetNoVertices(); 863 G4Point3D v1, v2; 862 G4Point3D v1, v2; 864 G4int next; 863 G4int next; 865 //while(1) { // next flag isn't functional 864 //while(1) { // next flag isn't functional. 866 for(G4int i = 0; i < 12; i++) { // # of ed 865 for(G4int i = 0; i < 12; i++) { // # of edges is 12. 867 poly->GetNextEdge(v1, v2, next); 866 poly->GetNextEdge(v1, v2, next); 868 if(next == 0) break; 867 if(next == 0) break; 869 G4cout << " (" << v1.x() << ", " 868 G4cout << " (" << v1.x() << ", " 870 << v1.y() << ", " 869 << v1.y() << ", " 871 << v1.z() << ") - (" 870 << v1.z() << ") - (" 872 << v2.x() << ", " 871 << v2.x() << ", " 873 << v2.y() << ", " 872 << v2.y() << ", " 874 << v2.z() << ") [" << next << "]" 873 << v2.z() << ") [" << next << "]" 875 << G4endl; 874 << G4endl; 876 } 875 } 877 delete poly; 876 delete poly; 878 } 877 } 879 878 880 879 881 // the volume name set by /vis/gMocren/setVo 880 // the volume name set by /vis/gMocren/setVolumeName 882 G4String volName = kMessenger.getVolumeName( 881 G4String volName = kMessenger.getVolumeName(); 883 882 884 883 885 if(kFlagParameterization != 2) { 884 if(kFlagParameterization != 2) { 886 G4ScoringManager * pScrMan = G4ScoringMana 885 G4ScoringManager * pScrMan = G4ScoringManager::GetScoringManager(); 887 if(pScrMan) { 886 if(pScrMan) { 888 G4ScoringBox * pScBox = dynamic_cast<G4S 887 G4ScoringBox * pScBox = dynamic_cast<G4ScoringBox*>(pScrMan->FindMesh(volName)); 889 G4bool bMesh = false; 888 G4bool bMesh = false; 890 if(pScBox != NULL) bMesh = true; 889 if(pScBox != NULL) bMesh = true; 891 if(bMesh) kFlagParameterization = 2; 890 if(bMesh) kFlagParameterization = 2; 892 if(GFDEBUG_DET > 0) G4cout << " G4Scor 891 if(GFDEBUG_DET > 0) G4cout << " G4ScoringManager::FindMesh() : " 893 << volName << " - " << bMesh << G4endl 892 << volName << " - " << bMesh << G4endl; 894 } 893 } 895 } 894 } 896 895 897 const G4VModel* pv_model = GetModel(); 896 const G4VModel* pv_model = GetModel(); 898 if (!pv_model) { return ; } 897 if (!pv_model) { return ; } 899 G4PhysicalVolumeModel* pPVModel = 898 G4PhysicalVolumeModel* pPVModel = 900 dynamic_cast<G4PhysicalVolumeModel*>(fpModel 899 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 901 if (!pPVModel) { return ; } 900 if (!pPVModel) { return ; } 902 901 903 902 904 //-- debug information 903 //-- debug information 905 if(GFDEBUG_DET > 0) { 904 if(GFDEBUG_DET > 0) { 906 G4Material * mat = pPVModel->GetCurrentMat 905 G4Material * mat = pPVModel->GetCurrentMaterial(); 907 G4String name = mat->GetName(); 906 G4String name = mat->GetName(); 908 G4double dens = mat->GetDensity()/(g/cm3); 907 G4double dens = mat->GetDensity()/(g/cm3); 909 G4int copyNo = pPVModel->GetCurrentPV()->G 908 G4int copyNo = pPVModel->GetCurrentPV()->GetCopyNo(); 910 G4int depth = pPVModel->GetCurrentDepth(); 909 G4int depth = pPVModel->GetCurrentDepth(); 911 G4cout << " copy no.: " << copyNo << G4 910 G4cout << " copy no.: " << copyNo << G4endl; 912 G4cout << " depth : " << depth << G4e 911 G4cout << " depth : " << depth << G4endl; 913 G4cout << " density : " << dens << " [g 912 G4cout << " density : " << dens << " [g/cm3]" << G4endl; 914 G4cout << " location: " << pPVModel->Ge 913 G4cout << " location: " << pPVModel->GetCurrentPV()->GetObjectTranslation() << G4endl; 915 G4cout << " Multiplicity : " << 914 G4cout << " Multiplicity : " << pPVModel->GetCurrentPV()->GetMultiplicity() << G4endl; 916 G4cout << " Is replicated? : " << 915 G4cout << " Is replicated? : " << pPVModel->GetCurrentPV()->IsReplicated() << G4endl; 917 G4cout << " Is parameterised? : " << 916 G4cout << " Is parameterised? : " << pPVModel->GetCurrentPV()->IsParameterised() << G4endl; 918 G4cout << " top phys. vol. name : " << 917 G4cout << " top phys. vol. name : " << pPVModel->GetTopPhysicalVolume()->GetName() << G4endl; 919 } 918 } 920 919 921 //-- check the parameterised volume 920 //-- check the parameterised volume 922 if(box.GetName() == volName) { 921 if(box.GetName() == volName) { 923 922 924 kVolumeTrans3D = fObjectTransformation; 923 kVolumeTrans3D = fObjectTransformation; 925 // coordination system correction for gMoc 924 // coordination system correction for gMocren 926 G4ThreeVector raxis(1., 0., 0.), dummy(0., 925 G4ThreeVector raxis(1., 0., 0.), dummy(0.,0.,0.); 927 G4RotationMatrix rot(raxis, pi*rad); 926 G4RotationMatrix rot(raxis, pi*rad); 928 G4Transform3D trot(rot, dummy); 927 G4Transform3D trot(rot, dummy); 929 if(GFDEBUG_DET) { 928 if(GFDEBUG_DET) { 930 G4ThreeVector trans1 = kVolumeTrans3D.ge 929 G4ThreeVector trans1 = kVolumeTrans3D.getTranslation(); 931 G4RotationMatrix rot1 = kVolumeTrans3D.g 930 G4RotationMatrix rot1 = kVolumeTrans3D.getRotation().inverse(); 932 G4cout << "kVolumeTrans3D: " << trans1 < 931 G4cout << "kVolumeTrans3D: " << trans1 << G4endl << rot1 << G4endl; 933 } 932 } 934 kVolumeTrans3D = kVolumeTrans3D*trot; 933 kVolumeTrans3D = kVolumeTrans3D*trot; 935 if(GFDEBUG_DET) G4cout << " Parameterised 934 if(GFDEBUG_DET) G4cout << " Parameterised volume : " << box.GetName() << G4endl; 936 935 937 936 938 937 939 // 938 // 940 G4VPhysicalVolume * pv[3] = {0,0,0}; 939 G4VPhysicalVolume * pv[3] = {0,0,0}; 941 pv[0] = pPVModel->GetCurrentPV()->GetLogic 940 pv[0] = pPVModel->GetCurrentPV()->GetLogicalVolume()->GetDaughter(0); 942 if(!pv[0]) { 941 if(!pv[0]) { 943 G4Exception("G4GMocrenFileSceneHandler:: 942 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 944 "gMocren0003", FatalExceptio 943 "gMocren0003", FatalException, "Unexpected volume."); 945 } 944 } 946 G4int dirAxis[3] = {-1,-1,-1}; 945 G4int dirAxis[3] = {-1,-1,-1}; 947 G4int nDaughters[3] = {0,0,0}; 946 G4int nDaughters[3] = {0,0,0}; 948 947 949 EAxis axis; G4int nReplicas; G4double widt 948 EAxis axis; G4int nReplicas; G4double width; G4double offset; G4bool consuming; 950 pv[0]->GetReplicationData(axis, nReplicas, 949 pv[0]->GetReplicationData(axis, nReplicas, width, offset, consuming); 951 nDaughters[0] = nReplicas; 950 nDaughters[0] = nReplicas; 952 switch(axis) { 951 switch(axis) { 953 case kXAxis: dirAxis[0] = 0; break; 952 case kXAxis: dirAxis[0] = 0; break; 954 case kYAxis: dirAxis[0] = 1; break; 953 case kYAxis: dirAxis[0] = 1; break; 955 case kZAxis: dirAxis[0] = 2; break; 954 case kZAxis: dirAxis[0] = 2; break; 956 default: 955 default: 957 G4Exception("G4GMocrenFileSceneHandler 956 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 958 "gMocren0004", FatalExcept 957 "gMocren0004", FatalException, "Error."); 959 } 958 } 960 kNestedVolumeNames.push_back(pv[0]->GetNam 959 kNestedVolumeNames.push_back(pv[0]->GetName()); 961 if(GFDEBUG_DET) 960 if(GFDEBUG_DET) 962 G4cout << " daughter name : " << 961 G4cout << " daughter name : " << pv[0]->GetName() 963 << " # : " << nDaughters[0] << G4endl 962 << " # : " << nDaughters[0] << G4endl; 964 963 965 // 964 // 966 if(GFDEBUG_DET) { 965 if(GFDEBUG_DET) { 967 if(pv[0]->GetLogicalVolume()->GetNoDaugh 966 if(pv[0]->GetLogicalVolume()->GetNoDaughters()) { 968 G4cout << "# of daughters : " 967 G4cout << "# of daughters : " 969 << pv[0]->GetLogicalVolume()->GetNoDa 968 << pv[0]->GetLogicalVolume()->GetNoDaughters() << G4endl; 970 } else { 969 } else { 971 //G4Exception("G4GMocrenFileSceneHandl 970 //G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 972 // "gMocren0005", FatalException, 971 // "gMocren0005", FatalException, "Error."); 973 } 972 } 974 } 973 } 975 974 976 // check whether nested or regular paramet 975 // check whether nested or regular parameterization 977 if(GFDEBUG_DET) G4cout << "# of daughters 976 if(GFDEBUG_DET) G4cout << "# of daughters : " 978 << pv[0]->GetLogicalVolume()->GetNoDa 977 << pv[0]->GetLogicalVolume()->GetNoDaughters() << G4endl; 979 if(pv[0]->GetLogicalVolume()->GetNoDaughte 978 if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) { 980 kFlagParameterization = 1; 979 kFlagParameterization = 1; 981 //G4Exception("G4GMocrenFileSceneHandler 980 //G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 982 // "gMocren0006", FatalException, " 981 // "gMocren0006", FatalException, "Error."); 983 } 982 } 984 983 985 if(kFlagParameterization == 0) { 984 if(kFlagParameterization == 0) { 986 985 987 pv[1] = pv[0]->GetLogicalVolume()->GetDa 986 pv[1] = pv[0]->GetLogicalVolume()->GetDaughter(0); 988 if(pv[1]) { 987 if(pv[1]) { 989 pv[1]->GetReplicationData(axis, nRepli 988 pv[1]->GetReplicationData(axis, nReplicas, width, offset, consuming); 990 nDaughters[1] = nReplicas; 989 nDaughters[1] = nReplicas; 991 switch(axis) { 990 switch(axis) { 992 case kXAxis: dirAxis[1] = 0; break; 991 case kXAxis: dirAxis[1] = 0; break; 993 case kYAxis: dirAxis[1] = 1; break; 992 case kYAxis: dirAxis[1] = 1; break; 994 case kZAxis: dirAxis[1] = 2; break; 993 case kZAxis: dirAxis[1] = 2; break; 995 default: 994 default: 996 G4Exception("G4GMocrenFileSceneHan 995 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 997 "gMocren0007", FatalEx 996 "gMocren0007", FatalException, "Error."); 998 } 997 } 999 kNestedVolumeNames.push_back(pv[1]->Ge 998 kNestedVolumeNames.push_back(pv[1]->GetName()); 1000 if(GFDEBUG_DET) 999 if(GFDEBUG_DET) 1001 G4cout << " sub-daughter nam 1000 G4cout << " sub-daughter name : " << pv[1]->GetName() 1002 << " # : " << nDaughters[1]<< G4e 1001 << " # : " << nDaughters[1]<< G4endl; 1003 1002 1004 // 1003 // 1005 pv[2] = pv[1]->GetLogicalVolume()->Ge 1004 pv[2] = pv[1]->GetLogicalVolume()->GetDaughter(0); 1006 if(pv[2]) { 1005 if(pv[2]) { 1007 nDaughters[2] = pv[2]->GetMultiplic 1006 nDaughters[2] = pv[2]->GetMultiplicity(); 1008 kNestedVolumeNames.push_back(pv[2]- 1007 kNestedVolumeNames.push_back(pv[2]->GetName()); 1009 if(GFDEBUG_DET) 1008 if(GFDEBUG_DET) 1010 G4cout << " sub-sub-daught 1009 G4cout << " sub-sub-daughter name : " << pv[2]->GetName() 1011 << " # : " << nDaughters[2] << 1010 << " # : " << nDaughters[2] << G4endl; 1012 1011 1013 if(nDaughters[2] > 1) { 1012 if(nDaughters[2] > 1) { 1014 G4VNestedParameterisation * nestP 1013 G4VNestedParameterisation * nestPara 1015 = dynamic_cast<G4VNestedParameter 1014 = dynamic_cast<G4VNestedParameterisation*>(pv[2]->GetParameterisation()); 1016 if(nestPara == NULL) 1015 if(nestPara == NULL) 1017 G4Exception("G4GMocrenFileScene 1016 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 1018 "gMocren0008", Fata 1017 "gMocren0008", FatalException, "Non-nested parameterisation"); 1019 1018 1020 nestPara->ComputeTransformation(0 1019 nestPara->ComputeTransformation(0, pv[2]); 1021 G4ThreeVector trans0 = pv[2]->Get 1020 G4ThreeVector trans0 = pv[2]->GetObjectTranslation(); 1022 nestPara->ComputeTransformation(1 1021 nestPara->ComputeTransformation(1, pv[2]); 1023 G4ThreeVector trans1 = pv[2]->Get 1022 G4ThreeVector trans1 = pv[2]->GetObjectTranslation(); 1024 G4ThreeVector diff(trans0 - trans 1023 G4ThreeVector diff(trans0 - trans1); 1025 if(GFDEBUG_DET) 1024 if(GFDEBUG_DET) 1026 G4cout << trans0 << " - " << tr 1025 G4cout << trans0 << " - " << trans1 << " - " << diff << G4endl; 1027 1026 1028 if(diff.x() != 0.) dirAxis[2] = 0 1027 if(diff.x() != 0.) dirAxis[2] = 0; 1029 else if(diff.y() != 0.) dirAxis[2 1028 else if(diff.y() != 0.) dirAxis[2] = 1; 1030 else if(diff.z() != 0.) dirAxis[2 1029 else if(diff.z() != 0.) dirAxis[2] = 2; 1031 else 1030 else 1032 G4Exception("G4GMocrenFileScene 1031 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 1033 "gMocren0009", Fata 1032 "gMocren0009", FatalException, "Unexpected nested parameterisation"); 1034 } 1033 } 1035 } 1034 } 1036 } 1035 } 1037 1036 1038 for(G4int i = 0; i < 3; i++) { 1037 for(G4int i = 0; i < 3; i++) { 1039 kNestedVolumeDimension[i] = nDaughter 1038 kNestedVolumeDimension[i] = nDaughters[i]; 1040 //kNestedVolumeDimension[i] = nDaught 1039 //kNestedVolumeDimension[i] = nDaughters[dirAxis[i]]; 1041 kNestedVolumeDirAxis[i] = dirAxis[i]; 1040 kNestedVolumeDirAxis[i] = dirAxis[i]; 1042 } 1041 } 1043 //G4cout << "@@@@@@@@@ " 1042 //G4cout << "@@@@@@@@@ " 1044 // << dirAxis[0] << ", " << dirAx 1043 // << dirAxis[0] << ", " << dirAxis[1] << ", " << dirAxis[2] << G4endl; 1045 1044 1046 // get densities 1045 // get densities 1047 G4VNestedParameterisation * nestPara 1046 G4VNestedParameterisation * nestPara 1048 = dynamic_cast<G4VNestedParameterisatio 1047 = dynamic_cast<G4VNestedParameterisation*>(pv[2]->GetParameterisation()); 1049 if(nestPara != NULL) { 1048 if(nestPara != NULL) { 1050 G4double prexyz[3] = {0.,0.,0.}, xyz[ 1049 G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.}; 1051 for(G4int n0 = 0; n0 < nDaughters[0]; 1050 for(G4int n0 = 0; n0 < nDaughters[0]; n0++) { 1052 for(G4int n1 = 0; n1 < nDaughters[1 1051 for(G4int n1 = 0; n1 < nDaughters[1]; n1++) { 1053 for(G4int n2 = 0; n2 < nDaughters 1052 for(G4int n2 = 0; n2 < nDaughters[2]; n2++) { 1054 1053 1055 G4GMocrenTouchable * touch = ne 1054 G4GMocrenTouchable * touch = new G4GMocrenTouchable(n1, n0); 1056 if(GFDEBUG_DET) 1055 if(GFDEBUG_DET) 1057 G4cout << " retrieve volume 1056 G4cout << " retrieve volume : copy # : " << n0 1058 << ", " << n1 << ", " << n2 < 1057 << ", " << n1 << ", " << n2 << G4endl; 1059 G4Material * mat = nestPara->Co 1058 G4Material * mat = nestPara->ComputeMaterial(pv[2], n2, touch); 1060 delete touch; 1059 delete touch; 1061 G4double dens = mat->GetDensity 1060 G4double dens = mat->GetDensity()/(g/cm3); 1062 1061 1063 if(GFDEBUG_DET) 1062 if(GFDEBUG_DET) 1064 G4cout << " density 1063 G4cout << " density :" << dens << " [g/cm3]" << G4endl; 1065 1064 1066 G4Box tbox(box); 1065 G4Box tbox(box); 1067 nestPara->ComputeDimensions(tbo 1066 nestPara->ComputeDimensions(tbox, n2, pv[2]); 1068 xyz[0] = tbox.GetXHalfLength()/ 1067 xyz[0] = tbox.GetXHalfLength()/mm; 1069 xyz[1] = tbox.GetYHalfLength()/ 1068 xyz[1] = tbox.GetYHalfLength()/mm; 1070 xyz[2] = tbox.GetZHalfLength()/ 1069 xyz[2] = tbox.GetZHalfLength()/mm; 1071 if(n0 != 0 || n1 != 0 || n2 != 1070 if(n0 != 0 || n1 != 0 || n2 != 0) { 1072 for(G4int i = 0; i < 3; i++) 1071 for(G4int i = 0; i < 3; i++) { 1073 if(xyz[i] != prexyz[i]) 1072 if(xyz[i] != prexyz[i]) 1074 G4Exception("G4GMocrenFil 1073 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 1075 "gMocren0010" 1074 "gMocren0010", FatalException, "Unsupported parameterisation"); 1076 } 1075 } 1077 } 1076 } 1078 if(GFDEBUG_DET) 1077 if(GFDEBUG_DET) 1079 G4cout << " size 1078 G4cout << " size : " << tbox.GetXHalfLength()/mm << " x " 1080 << tbox.GetYHalfLength()/mm < 1079 << tbox.GetYHalfLength()/mm << " x " 1081 << tbox.GetZHalfLength()/mm < 1080 << tbox.GetZHalfLength()/mm << " [mm3]" << G4endl; 1082 1081 1083 G4int idx[3]; 1082 G4int idx[3]; 1084 idx[dirAxis[0]] = n0; 1083 idx[dirAxis[0]] = n0; 1085 idx[dirAxis[1]] = n1; 1084 idx[dirAxis[1]] = n1; 1086 idx[dirAxis[2]] = n2; 1085 idx[dirAxis[2]] = n2; 1087 Index3D i3d(idx[0],idx[1],idx[2 1086 Index3D i3d(idx[0],idx[1],idx[2]); 1088 kNestedModality[i3d] = dens; 1087 kNestedModality[i3d] = dens; 1089 if(GFDEBUG_DET) 1088 if(GFDEBUG_DET) 1090 G4cout << " index: " << idx[0 1089 G4cout << " index: " << idx[0] << ", " << idx[1] << ", " << idx[2] 1091 << " density: " << dens << G 1090 << " density: " << dens << G4endl; 1092 1091 1093 for(G4int i = 0; i < 3; i++) pr 1092 for(G4int i = 0; i < 3; i++) prexyz[i] = xyz[i]; 1094 } 1093 } 1095 } 1094 } 1096 } 1095 } 1097 1096 1098 kVolumeSize.set(box.GetXHalfLength()* 1097 kVolumeSize.set(box.GetXHalfLength()*2/mm, 1099 box.GetYHalfLength()* 1098 box.GetYHalfLength()*2/mm, 1100 box.GetZHalfLength()* 1099 box.GetZHalfLength()*2/mm); 1101 // mesh size 1100 // mesh size 1102 if(!kbSetModalityVoxelSize) { 1101 if(!kbSetModalityVoxelSize) { 1103 G4float spacing[3] = {static_cast<G 1102 G4float spacing[3] = {static_cast<G4float>(2*xyz[0]), 1104 static_cast<G4float>(2*xyz[1]), 1103 static_cast<G4float>(2*xyz[1]), 1105 static_cast<G4float>(2*xyz[2])}; 1104 static_cast<G4float>(2*xyz[2])}; 1106 kgMocrenIO->setVoxelSpacing(spacing 1105 kgMocrenIO->setVoxelSpacing(spacing); 1107 kVoxelDimension.set(spacing[0], spa 1106 kVoxelDimension.set(spacing[0], spacing[1], spacing[2]); 1108 kbSetModalityVoxelSize = true; 1107 kbSetModalityVoxelSize = true; 1109 } 1108 } 1110 1109 1111 } else { 1110 } else { 1112 if(GFDEBUG_DET) 1111 if(GFDEBUG_DET) 1113 G4cout << pv[2]->GetName() << G4end 1112 G4cout << pv[2]->GetName() << G4endl; 1114 G4Exception("G4GMocrenFileSceneHandle 1113 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 1115 "gMocren0011", FatalExcep 1114 "gMocren0011", FatalException, "Non-nested parameterisation"); 1116 } 1115 } 1117 1116 1118 1117 1119 1118 1120 //-- debug 1119 //-- debug 1121 if(GFDEBUG_DET > 1) { 1120 if(GFDEBUG_DET > 1) { 1122 if(pPVModel->GetCurrentPV()->IsParame 1121 if(pPVModel->GetCurrentPV()->IsParameterised()) { 1123 G4VPVParameterisation * para = pPVM 1122 G4VPVParameterisation * para = pPVModel->GetCurrentPV()->GetParameterisation(); 1124 G4cout << " Is nested parameterisat 1123 G4cout << " Is nested parameterisation? : " << para->IsNested() << G4endl; 1125 1124 1126 1125 1127 G4int npvp = pPVModel->GetDrawnPVPa 1126 G4int npvp = pPVModel->GetDrawnPVPath().size(); 1128 G4cout << " physical volume nod 1127 G4cout << " physical volume node id : " 1129 << "size: " << npvp << ", PV name: 1128 << "size: " << npvp << ", PV name: "; 1130 for(G4int i = 0; i < npvp; i++) { 1129 for(G4int i = 0; i < npvp; i++) { 1131 G4cout << pPVModel->GetDrawnPVPat 1130 G4cout << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetName() 1132 << " [param:" 1131 << " [param:" 1133 << pPVModel->GetDrawnPVPath()[i]. 1132 << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised() 1134 << ",rep:" 1133 << ",rep:" 1135 << pPVModel->GetDrawnPVPath()[i]. 1134 << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated(); 1136 if(pPVModel->GetDrawnPVPath()[i]. 1135 if(pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) { 1137 G4cout << ",nest:" 1136 G4cout << ",nest:" 1138 << pPVModel->GetDrawnPVPath()[i 1137 << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested(); 1139 } 1138 } 1140 G4cout << ",copyno:" 1139 G4cout << ",copyno:" 1141 << pPVModel->GetDrawnPVPath()[i]. 1140 << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo(); 1142 G4cout << "] - "; 1141 G4cout << "] - "; 1143 } 1142 } 1144 G4cout << G4endl; 1143 G4cout << G4endl; 1145 1144 1146 1145 1147 pPVModel->GetCurrentPV()->GetReplic 1146 pPVModel->GetCurrentPV()->GetReplicationData(axis, nReplicas, width, offset, consuming); 1148 G4cout << " # replicas : " << n 1147 G4cout << " # replicas : " << nReplicas << G4endl; 1149 G4double pareDims[3] = {0.,0.,0.}; 1148 G4double pareDims[3] = {0.,0.,0.}; 1150 G4Box * pbox = dynamic_cast<G4Box * 1149 G4Box * pbox = dynamic_cast<G4Box *>(pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid()); 1151 if(pbox) { 1150 if(pbox) { 1152 pareDims[0] = 2.*pbox->GetXHalfLe 1151 pareDims[0] = 2.*pbox->GetXHalfLength()*mm; 1153 pareDims[1] = 2.*pbox->GetYHalfLe 1152 pareDims[1] = 2.*pbox->GetYHalfLength()*mm; 1154 pareDims[2] = 2.*pbox->GetZHalfLe 1153 pareDims[2] = 2.*pbox->GetZHalfLength()*mm; 1155 G4cout << " mother size [" 1154 G4cout << " mother size [" 1156 << pPVModel->GetDrawnPVPath()[npv 1155 << pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName() 1157 << "] : " 1156 << "] : " 1158 << pareDims[0] << " x " 1157 << pareDims[0] << " x " 1159 << pareDims[1] << " x " 1158 << pareDims[1] << " x " 1160 << pareDims[2] << " [mm3]" 1159 << pareDims[2] << " [mm3]" 1161 << G4endl; 1160 << G4endl; 1162 } 1161 } 1163 G4double paraDims[3]; 1162 G4double paraDims[3]; 1164 G4Box * boxP = dynamic_cast<G4Box * 1163 G4Box * boxP = dynamic_cast<G4Box *>(pPVModel->GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid()); 1165 if(boxP) { 1164 if(boxP) { 1166 paraDims[0] = 2.*boxP->GetXHalfLe 1165 paraDims[0] = 2.*boxP->GetXHalfLength()*mm; 1167 paraDims[1] = 2.*boxP->GetYHalfLe 1166 paraDims[1] = 2.*boxP->GetYHalfLength()*mm; 1168 paraDims[2] = 2.*boxP->GetZHalfLe 1167 paraDims[2] = 2.*boxP->GetZHalfLength()*mm; 1169 G4cout << " parameterised vol 1168 G4cout << " parameterised volume? [" 1170 << pPVModel->GetDrawnPVPath()[npv 1169 << pPVModel->GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName() 1171 << "] : " 1170 << "] : " 1172 << paraDims[0] << " x " 1171 << paraDims[0] << " x " 1173 << paraDims[1] << " x " 1172 << paraDims[1] << " x " 1174 << paraDims[2] << " [mm3] : " 1173 << paraDims[2] << " [mm3] : " 1175 << G4int(pareDims[0]/paraDims[0]) 1174 << G4int(pareDims[0]/paraDims[0]) << " x " 1176 << G4int(pareDims[1]/paraDims[1]) 1175 << G4int(pareDims[1]/paraDims[1]) << " x " 1177 << G4int(pareDims[2]/paraDims[2]) 1176 << G4int(pareDims[2]/paraDims[2]) << G4endl; 1178 } else { 1177 } else { 1179 G4cout << pPVModel->GetDrawnPVPat 1178 G4cout << pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName() 1180 << " isn't a G4Box." << G4endl; 1179 << " isn't a G4Box." << G4endl; 1181 } 1180 } 1182 } 1181 } 1183 } 1182 } 1184 1183 1185 1184 1186 } else if(kFlagParameterization == 1) { / 1185 } else if(kFlagParameterization == 1) { // G4PhantomParameterisation based geom. construnction 1187 1186 1188 // get the dimension of the parameteriz 1187 // get the dimension of the parameterized patient geometry 1189 G4PhantomParameterisation * phantomPara 1188 G4PhantomParameterisation * phantomPara 1190 = dynamic_cast<G4PhantomParameterisatio 1189 = dynamic_cast<G4PhantomParameterisation*>(pv[0]->GetParameterisation()); 1191 if(phantomPara == NULL) { 1190 if(phantomPara == NULL) { 1192 G4Exception("G4GMocrenFileSceneHandle 1191 G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )", 1193 "gMocren0012", FatalExcep 1192 "gMocren0012", FatalException, "no G4PhantomParameterisation"); 1194 } else { 1193 } else { 1195 ; 1194 ; 1196 } 1195 } 1197 1196 1198 kNestedVolumeDimension[0] = (G4int)phan << 1197 kNestedVolumeDimension[0] = phantomPara->GetNoVoxelsX(); 1199 kNestedVolumeDimension[1] = (G4int)phan << 1198 kNestedVolumeDimension[1] = phantomPara->GetNoVoxelsY(); 1200 kNestedVolumeDimension[2] = (G4int)phan << 1199 kNestedVolumeDimension[2] = phantomPara->GetNoVoxelsZ(); 1201 kNestedVolumeDirAxis[0] = 0; 1200 kNestedVolumeDirAxis[0] = 0; 1202 kNestedVolumeDirAxis[1] = 1; 1201 kNestedVolumeDirAxis[1] = 1; 1203 kNestedVolumeDirAxis[2] = 2; 1202 kNestedVolumeDirAxis[2] = 2; 1204 1203 1205 // get densities of the parameterized p 1204 // get densities of the parameterized patient geometry 1206 G4int nX = kNestedVolumeDimension[0]; 1205 G4int nX = kNestedVolumeDimension[0]; 1207 G4int nXY = kNestedVolumeDimension[0]*k 1206 G4int nXY = kNestedVolumeDimension[0]*kNestedVolumeDimension[1]; 1208 1207 1209 for(G4int n0 = 0; n0 < kNestedVolumeDim 1208 for(G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) { 1210 for(G4int n1 = 0; n1 < kNestedVolumeD 1209 for(G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) { 1211 for(G4int n2 = 0; n2 < kNestedVolum 1210 for(G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) { 1212 1211 1213 G4int repNo = n0 + n1*nX + n2*nXY 1212 G4int repNo = n0 + n1*nX + n2*nXY; 1214 G4Material * mat = phantomPara->C 1213 G4Material * mat = phantomPara->ComputeMaterial(repNo, pv[0]); 1215 G4double dens = mat->GetDensity() 1214 G4double dens = mat->GetDensity()/(g/cm3); 1216 1215 1217 1216 1218 G4int idx[3]; 1217 G4int idx[3]; 1219 idx[kNestedVolumeDirAxis[0]] = n0 1218 idx[kNestedVolumeDirAxis[0]] = n0; 1220 idx[kNestedVolumeDirAxis[1]] = n1 1219 idx[kNestedVolumeDirAxis[1]] = n1; 1221 idx[kNestedVolumeDirAxis[2]] = n2 1220 idx[kNestedVolumeDirAxis[2]] = n2; 1222 Index3D i3d(idx[0],idx[1],idx[2]) 1221 Index3D i3d(idx[0],idx[1],idx[2]); 1223 kNestedModality[i3d] = dens; 1222 kNestedModality[i3d] = dens; 1224 1223 1225 if(GFDEBUG_DET) 1224 if(GFDEBUG_DET) 1226 G4cout << " index: " << idx[0] 1225 G4cout << " index: " << idx[0] << ", " << idx[1] << ", " << idx[2] 1227 << " density: " << dens << G4e 1226 << " density: " << dens << G4endl; 1228 1227 1229 } 1228 } 1230 } 1229 } 1231 } 1230 } 1232 1231 1233 kVolumeSize.set(box.GetXHalfLength()*2/ 1232 kVolumeSize.set(box.GetXHalfLength()*2/mm, 1234 box.GetYHalfLength()*2/ 1233 box.GetYHalfLength()*2/mm, 1235 box.GetZHalfLength()*2/ 1234 box.GetZHalfLength()*2/mm); 1236 1235 1237 // mesh size 1236 // mesh size 1238 if(!kbSetModalityVoxelSize) { 1237 if(!kbSetModalityVoxelSize) { 1239 G4float spacing[3] = {static_cast<G4f 1238 G4float spacing[3] = {static_cast<G4float>(2*phantomPara->GetVoxelHalfX()), 1240 static_cast<G4float>(2*phantomPara- 1239 static_cast<G4float>(2*phantomPara->GetVoxelHalfY()), 1241 static_cast<G4float>(2*phantomPara- 1240 static_cast<G4float>(2*phantomPara->GetVoxelHalfZ())}; 1242 kgMocrenIO->setVoxelSpacing(spacing); 1241 kgMocrenIO->setVoxelSpacing(spacing); 1243 kVoxelDimension.set(spacing[0], spaci 1242 kVoxelDimension.set(spacing[0], spacing[1], spacing[2]); 1244 kbSetModalityVoxelSize = true; 1243 kbSetModalityVoxelSize = true; 1245 } 1244 } 1246 } 1245 } 1247 1246 1248 } // if(box.GetName() == volName) 1247 } // if(box.GetName() == volName) 1249 1248 1250 1249 1251 // processing geometry construction based o 1250 // processing geometry construction based on the interactive PS 1252 if(!kFlagProcessedInteractiveScorer) { 1251 if(!kFlagProcessedInteractiveScorer) { 1253 1252 1254 1253 1255 // get the dimension of the geometry defi 1254 // get the dimension of the geometry defined in G4VScoringMesh 1256 G4ScoringManager * pScrMan = G4ScoringMan 1255 G4ScoringManager * pScrMan = G4ScoringManager::GetScoringManager(); 1257 //if(!pScrMan) return; 1256 //if(!pScrMan) return; 1258 if(pScrMan) { 1257 if(pScrMan) { 1259 G4ScoringBox * scoringBox 1258 G4ScoringBox * scoringBox 1260 = dynamic_cast<G4ScoringBox*>(pScrMan->Fi 1259 = dynamic_cast<G4ScoringBox*>(pScrMan->FindMesh(volName)); 1261 //if(scoringBox == NULL) return; 1260 //if(scoringBox == NULL) return; 1262 if(scoringBox) { 1261 if(scoringBox) { 1263 1262 1264 1263 1265 1264 1266 G4int nVoxels[3]; 1265 G4int nVoxels[3]; 1267 scoringBox->GetNumberOfSegments(nVoxels); 1266 scoringBox->GetNumberOfSegments(nVoxels); 1268 // this order depends on the G4ScoringBox 1267 // this order depends on the G4ScoringBox 1269 kNestedVolumeDimension[0] = nVoxels[2]; 1268 kNestedVolumeDimension[0] = nVoxels[2]; 1270 kNestedVolumeDimension[1] = nVoxels[1]; 1269 kNestedVolumeDimension[1] = nVoxels[1]; 1271 kNestedVolumeDimension[2] = nVoxels[0]; 1270 kNestedVolumeDimension[2] = nVoxels[0]; 1272 kNestedVolumeDirAxis[0] = 2; 1271 kNestedVolumeDirAxis[0] = 2; 1273 kNestedVolumeDirAxis[1] = 1; 1272 kNestedVolumeDirAxis[1] = 1; 1274 kNestedVolumeDirAxis[2] = 0; 1273 kNestedVolumeDirAxis[2] = 0; 1275 1274 1276 // get densities of the parameterized pat 1275 // get densities of the parameterized patient geometry 1277 for(G4int n0 = 0; n0 < kNestedVolumeDimen 1276 for(G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) { 1278 for(G4int n1 = 0; n1 < kNestedVolumeDim 1277 for(G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) { 1279 for(G4int n2 = 0; n2 < kNestedVolumeD 1278 for(G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) { 1280 1279 1281 G4double dens = 0.*(g/cm3); 1280 G4double dens = 0.*(g/cm3); 1282 1281 1283 G4int idx[3]; 1282 G4int idx[3]; 1284 idx[kNestedVolumeDirAxis[0]] = n0; 1283 idx[kNestedVolumeDirAxis[0]] = n0; 1285 idx[kNestedVolumeDirAxis[1]] = n1; 1284 idx[kNestedVolumeDirAxis[1]] = n1; 1286 idx[kNestedVolumeDirAxis[2]] = n2; 1285 idx[kNestedVolumeDirAxis[2]] = n2; 1287 Index3D i3d(idx[0],idx[1],idx[2]); 1286 Index3D i3d(idx[0],idx[1],idx[2]); 1288 kNestedModality[i3d] = dens; 1287 kNestedModality[i3d] = dens; 1289 1288 1290 } 1289 } 1291 } 1290 } 1292 } 1291 } 1293 1292 1294 G4ThreeVector boxSize = scoringBox->GetSi 1293 G4ThreeVector boxSize = scoringBox->GetSize(); 1295 if(GFDEBUG_DET > 1) { 1294 if(GFDEBUG_DET > 1) { 1296 G4cout << "Interactive Scorer : size - 1295 G4cout << "Interactive Scorer : size - " 1297 << boxSize.x()/cm << " x " 1296 << boxSize.x()/cm << " x " 1298 << boxSize.y()/cm << " x " 1297 << boxSize.y()/cm << " x " 1299 << boxSize.z()/cm << " [cm3]" << G4end 1298 << boxSize.z()/cm << " [cm3]" << G4endl; 1300 G4cout << "Interactive Scorer : # voxel 1299 G4cout << "Interactive Scorer : # voxels - " 1301 << nVoxels[0] << " x " 1300 << nVoxels[0] << " x " 1302 << nVoxels[1] << " x " 1301 << nVoxels[1] << " x " 1303 << nVoxels[2] << G4endl; 1302 << nVoxels[2] << G4endl; 1304 } 1303 } 1305 kVolumeSize.set(boxSize.x()*2, 1304 kVolumeSize.set(boxSize.x()*2, 1306 boxSize.y()*2, 1305 boxSize.y()*2, 1307 boxSize.z()*2); 1306 boxSize.z()*2); 1308 1307 1309 // mesh size 1308 // mesh size 1310 if(!kbSetModalityVoxelSize) { 1309 if(!kbSetModalityVoxelSize) { 1311 G4float spacing[3] = {static_cast<G4flo 1310 G4float spacing[3] = {static_cast<G4float>(boxSize.x()*2/nVoxels[0]), 1312 static_cast<G4float>(boxSize.y()*2/nV 1311 static_cast<G4float>(boxSize.y()*2/nVoxels[1]), 1313 static_cast<G4float>(boxSize.z()*2/nV 1312 static_cast<G4float>(boxSize.z()*2/nVoxels[2])}; 1314 1313 1315 kgMocrenIO->setVoxelSpacing(spacing); 1314 kgMocrenIO->setVoxelSpacing(spacing); 1316 kVoxelDimension.set(spacing[0], spacing 1315 kVoxelDimension.set(spacing[0], spacing[1], spacing[2]); 1317 kbSetModalityVoxelSize = true; 1316 kbSetModalityVoxelSize = true; 1318 1317 1319 } 1318 } 1320 1319 1321 1320 1322 kVolumeTrans3D = fObjectTransformation; 1321 kVolumeTrans3D = fObjectTransformation; 1323 1322 1324 // translation for the scoring mesh 1323 // translation for the scoring mesh 1325 G4ThreeVector sbth = scoringBox->GetTrans 1324 G4ThreeVector sbth = scoringBox->GetTranslation(); 1326 G4Translate3D sbtranslate(sbth); 1325 G4Translate3D sbtranslate(sbth); 1327 kVolumeTrans3D = kVolumeTrans3D*sbtransla 1326 kVolumeTrans3D = kVolumeTrans3D*sbtranslate; 1328 1327 1329 // rotation matrix for the scoring mesh 1328 // rotation matrix for the scoring mesh 1330 G4RotationMatrix sbrm; 1329 G4RotationMatrix sbrm; 1331 sbrm = scoringBox->GetRotationMatrix(); 1330 sbrm = scoringBox->GetRotationMatrix(); 1332 if(!sbrm.isIdentity()) { 1331 if(!sbrm.isIdentity()) { 1333 G4ThreeVector sbdummy(0.,0.,0.); 1332 G4ThreeVector sbdummy(0.,0.,0.); 1334 G4Transform3D sbrotate(sbrm.inverse(), 1333 G4Transform3D sbrotate(sbrm.inverse(), sbdummy); 1335 kVolumeTrans3D = kVolumeTrans3D*sbrotat 1334 kVolumeTrans3D = kVolumeTrans3D*sbrotate; 1336 } 1335 } 1337 1336 1338 1337 1339 // coordination system correction for gMo 1338 // coordination system correction for gMocren 1340 G4ThreeVector raxisY(0., 1., 0.), dummyY( 1339 G4ThreeVector raxisY(0., 1., 0.), dummyY(0.,0.,0.); 1341 G4RotationMatrix rotY(raxisY, pi*rad); 1340 G4RotationMatrix rotY(raxisY, pi*rad); 1342 G4Transform3D trotY(rotY, dummyY); 1341 G4Transform3D trotY(rotY, dummyY); 1343 G4ThreeVector raxisZ(0., 0., 1.), dummyZ( 1342 G4ThreeVector raxisZ(0., 0., 1.), dummyZ(0.,0.,0.); 1344 G4RotationMatrix rotZ(raxisZ, pi*rad); 1343 G4RotationMatrix rotZ(raxisZ, pi*rad); 1345 G4Transform3D trotZ(rotZ, dummyZ); 1344 G4Transform3D trotZ(rotZ, dummyZ); 1346 1345 1347 kVolumeTrans3D = kVolumeTrans3D*trotY*tro 1346 kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ; 1348 1347 1349 } 1348 } 1350 } 1349 } 1351 // 1350 // 1352 kFlagProcessedInteractiveScorer = true; 1351 kFlagProcessedInteractiveScorer = true; 1353 } 1352 } 1354 1353 1355 1354 1356 static G4VPhysicalVolume * volPV = NULL; 1355 static G4VPhysicalVolume * volPV = NULL; 1357 if(pPVModel->GetCurrentPV()->GetName() == v 1356 if(pPVModel->GetCurrentPV()->GetName() == volName) { 1358 volPV = pPVModel->GetCurrentPV(); 1357 volPV = pPVModel->GetCurrentPV(); 1359 } 1358 } 1360 1359 1361 //-- add detectors 1360 //-- add detectors 1362 G4bool bAddDet = true; 1361 G4bool bAddDet = true; 1363 if(!kMessenger.getDrawVolumeGrid()) { 1362 if(!kMessenger.getDrawVolumeGrid()) { 1364 1363 1365 if(kFlagParameterization == 0) { // neste 1364 if(kFlagParameterization == 0) { // nested parameterisation 1366 /* 1365 /* 1367 G4String volDSolidName; 1366 G4String volDSolidName; 1368 if(volPV) { 1367 if(volPV) { 1369 G4int nDaughter = volPV->GetLogicalVo 1368 G4int nDaughter = volPV->GetLogicalVolume()->GetNoDaughters(); 1370 G4VPhysicalVolume * volDPV = NULL; 1369 G4VPhysicalVolume * volDPV = NULL; 1371 if(nDaughter > 0) volDPV = volPV->Get 1370 if(nDaughter > 0) volDPV = volPV->GetLogicalVolume()->GetDaughter(0); 1372 if(volDPV) { 1371 if(volDPV) { 1373 nDaughter = volDPV->GetLogicalVolum 1372 nDaughter = volDPV->GetLogicalVolume()->GetNoDaughters(); 1374 if(nDaughter > 0) 1373 if(nDaughter > 0) 1375 volDSolidName = volDPV->GetLogica 1374 volDSolidName = volDPV->GetLogicalVolume()->GetDaughter(0) 1376 ->GetLogicalVolume 1375 ->GetLogicalVolume()->GetSolid()->GetName(); 1377 } 1376 } 1378 } 1377 } 1379 */ 1378 */ 1380 1379 1381 //std::cout << "Parameterization volume 1380 //std::cout << "Parameterization volume: " << volName << " - " 1382 // << box.GetName() << std::en 1381 // << box.GetName() << std::endl; 1383 1382 1384 if(volName == box.GetName()) { 1383 if(volName == box.GetName()) { 1385 bAddDet = false; 1384 bAddDet = false; 1386 } 1385 } 1387 1386 1388 std::vector<G4String>::iterator itr = k 1387 std::vector<G4String>::iterator itr = kNestedVolumeNames.begin(); 1389 for(; itr != kNestedVolumeNames.end(); 1388 for(; itr != kNestedVolumeNames.end(); itr++) { 1390 if(*itr == box.GetName()) { 1389 if(*itr == box.GetName()) { 1391 bAddDet = false; 1390 bAddDet = false; 1392 break; 1391 break; 1393 } 1392 } 1394 } 1393 } 1395 } else if(kFlagParameterization == 1) { / 1394 } else if(kFlagParameterization == 1) { // phantom paramemterisation 1396 1395 1397 G4String volDSolidName; 1396 G4String volDSolidName; 1398 if(volPV) { 1397 if(volPV) { 1399 volDSolidName = volPV->GetLogicalVolu 1398 volDSolidName = volPV->GetLogicalVolume()->GetDaughter(0) 1400 ->GetLogicalVolume()- 1399 ->GetLogicalVolume()->GetSolid()->GetName(); 1401 } 1400 } 1402 1401 1403 //std::cout << "Phantom Parameterizatio 1402 //std::cout << "Phantom Parameterization volume: " << volDSolidName 1404 // << " - " << box.GetName() < 1403 // << " - " << box.GetName() << std::endl; 1405 1404 1406 if(volDSolidName == box.GetName()) { 1405 if(volDSolidName == box.GetName()) { 1407 bAddDet = false; 1406 bAddDet = false; 1408 } 1407 } 1409 1408 1410 } else if(kFlagParameterization == 2) { / 1409 } else if(kFlagParameterization == 2) { // interactive primitive scorer 1411 //std::cout << "Regular Parameterizatio 1410 //std::cout << "Regular Parameterization volume: " << box.GetName() << std::endl; 1412 } 1411 } 1413 1412 1414 } 1413 } 1415 if(bAddDet) AddDetector(box); 1414 if(bAddDet) AddDetector(box); 1416 1415 1417 1416 1418 } // void G4GMocrenFileSceneHandler::AddSolid 1417 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Box& box ) 1419 1418 1420 1419 1421 //----- Add tubes 1420 //----- Add tubes 1422 void 1421 void 1423 G4GMocrenFileSceneHandler::AddSolid( const G4 1422 G4GMocrenFileSceneHandler::AddSolid( const G4Tubs& tubes ) 1424 { 1423 { 1425 if(GFDEBUG || G4VisManager::GetVerbosity() 1424 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1426 G4cout << "***** AddSolid ( tubes )" << G 1425 G4cout << "***** AddSolid ( tubes )" << G4endl; 1427 1426 1428 //----- skip drawing invisible primitive 1427 //----- skip drawing invisible primitive 1429 if( !IsVisible() ) { return ; } 1428 if( !IsVisible() ) { return ; } 1430 1429 1431 //----- Initialize if necessary 1430 //----- Initialize if necessary 1432 GFBeginModeling(); 1431 GFBeginModeling(); 1433 1432 1434 // 1433 // 1435 AddDetector(tubes); 1434 AddDetector(tubes); 1436 1435 1437 1436 1438 // for a debug 1437 // for a debug 1439 if(GFDEBUG_DET > 0) { 1438 if(GFDEBUG_DET > 0) { 1440 G4cout << "-------" << G4endl; 1439 G4cout << "-------" << G4endl; 1441 G4cout << " " << tubes.GetName() << G4 1440 G4cout << " " << tubes.GetName() << G4endl; 1442 G4Polyhedron * poly = tubes.CreatePolyhed 1441 G4Polyhedron * poly = tubes.CreatePolyhedron(); 1443 G4int nv = poly->GetNoVertices(); 1442 G4int nv = poly->GetNoVertices(); 1444 for(G4int i = 0; i < nv; i++) { 1443 for(G4int i = 0; i < nv; i++) { 1445 G4cout << " (" << poly->GetVertex(i) 1444 G4cout << " (" << poly->GetVertex(i).x() << ", " 1446 << poly->GetVertex(i).y() << ", " 1445 << poly->GetVertex(i).y() << ", " 1447 << poly->GetVertex(i).z() << ")" << G4 1446 << poly->GetVertex(i).z() << ")" << G4endl; 1448 } 1447 } 1449 delete poly; 1448 delete poly; 1450 } 1449 } 1451 1450 1452 const G4VModel* pv_model = GetModel(); 1451 const G4VModel* pv_model = GetModel(); 1453 if (!pv_model) { return ; } 1452 if (!pv_model) { return ; } 1454 G4PhysicalVolumeModel* pPVModel = 1453 G4PhysicalVolumeModel* pPVModel = 1455 dynamic_cast<G4PhysicalVolumeModel*>(fpMo 1454 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 1456 if (!pPVModel) { return ; } 1455 if (!pPVModel) { return ; } 1457 G4Material * mat = pPVModel->GetCurrentMate 1456 G4Material * mat = pPVModel->GetCurrentMaterial(); 1458 G4String name = mat->GetName(); 1457 G4String name = mat->GetName(); 1459 1458 1460 } // void G4GMocrenFileSceneHandler::AddSolid 1459 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Tubs& ) 1461 1460 1462 1461 1463 1462 1464 //----- Add cons 1463 //----- Add cons 1465 void 1464 void 1466 G4GMocrenFileSceneHandler::AddSolid( const G4 1465 G4GMocrenFileSceneHandler::AddSolid( const G4Cons& cons ) 1467 { 1466 { 1468 if(GFDEBUG || G4VisManager::GetVerbosity() 1467 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1469 G4cout << "***** AddSolid ( cons )" << G4 1468 G4cout << "***** AddSolid ( cons )" << G4endl; 1470 1469 1471 //----- skip drawing invisible primitive 1470 //----- skip drawing invisible primitive 1472 if( !IsVisible() ) { return ; } 1471 if( !IsVisible() ) { return ; } 1473 1472 1474 //----- Initialize if necessary 1473 //----- Initialize if necessary 1475 GFBeginModeling(); 1474 GFBeginModeling(); 1476 1475 1477 // 1476 // 1478 AddDetector(cons); 1477 AddDetector(cons); 1479 1478 1480 }// G4GMocrenFileSceneHandler::AddSolid( cons 1479 }// G4GMocrenFileSceneHandler::AddSolid( cons ) 1481 1480 1482 1481 1483 //----- Add trd 1482 //----- Add trd 1484 void G4GMocrenFileSceneHandler::AddSolid ( co 1483 void G4GMocrenFileSceneHandler::AddSolid ( const G4Trd& trd ) 1485 { 1484 { 1486 if(GFDEBUG || G4VisManager::GetVerbosity() 1485 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1487 G4cout << "***** AddSolid ( trd )" << G4e 1486 G4cout << "***** AddSolid ( trd )" << G4endl; 1488 1487 1489 1488 1490 //----- skip drawing invisible primitive 1489 //----- skip drawing invisible primitive 1491 if( !IsVisible() ) { return ; } 1490 if( !IsVisible() ) { return ; } 1492 1491 1493 //----- Initialize if necessary 1492 //----- Initialize if necessary 1494 GFBeginModeling(); 1493 GFBeginModeling(); 1495 1494 1496 // 1495 // 1497 AddDetector(trd); 1496 AddDetector(trd); 1498 1497 1499 } // G4GMocrenFileSceneHandler::AddSolid ( tr 1498 } // G4GMocrenFileSceneHandler::AddSolid ( trd ) 1500 1499 1501 1500 1502 //----- Add sphere 1501 //----- Add sphere 1503 void G4GMocrenFileSceneHandler::AddSolid ( co 1502 void G4GMocrenFileSceneHandler::AddSolid ( const G4Sphere& sphere ) 1504 { 1503 { 1505 if(GFDEBUG || G4VisManager::GetVerbosity() 1504 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1506 G4cout << "***** AddSolid ( sphere )" << 1505 G4cout << "***** AddSolid ( sphere )" << G4endl; 1507 1506 1508 //----- skip drawing invisible primitive 1507 //----- skip drawing invisible primitive 1509 if( !IsVisible() ) { return ; } 1508 if( !IsVisible() ) { return ; } 1510 1509 1511 //----- Initialize if necessary 1510 //----- Initialize if necessary 1512 GFBeginModeling(); 1511 GFBeginModeling(); 1513 1512 1514 // 1513 // 1515 AddDetector(sphere); 1514 AddDetector(sphere); 1516 1515 1517 } // G4GMocrenFileSceneHandler::AddSolid ( sp 1516 } // G4GMocrenFileSceneHandler::AddSolid ( sphere ) 1518 1517 1519 1518 1520 //----- Add para 1519 //----- Add para 1521 void G4GMocrenFileSceneHandler::AddSolid (con 1520 void G4GMocrenFileSceneHandler::AddSolid (const G4Para& para) 1522 { 1521 { 1523 if(GFDEBUG || G4VisManager::GetVerbosity() 1522 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1524 G4cout << "***** AddSolid ( para )" << G4 1523 G4cout << "***** AddSolid ( para )" << G4endl; 1525 1524 1526 //----- skip drawing invisible primitive 1525 //----- skip drawing invisible primitive 1527 if( !IsVisible() ) { return ; } 1526 if( !IsVisible() ) { return ; } 1528 1527 1529 //----- Initialize if necessary 1528 //----- Initialize if necessary 1530 GFBeginModeling(); 1529 GFBeginModeling(); 1531 1530 1532 // 1531 // 1533 AddDetector(para); 1532 AddDetector(para); 1534 1533 1535 } // G4GMocrenFileSceneHandler::AddSolid ( pa 1534 } // G4GMocrenFileSceneHandler::AddSolid ( para ) 1536 1535 1537 1536 1538 //----- Add trap 1537 //----- Add trap 1539 void G4GMocrenFileSceneHandler::AddSolid (con 1538 void G4GMocrenFileSceneHandler::AddSolid (const G4Trap& trap) 1540 { 1539 { 1541 if(GFDEBUG || G4VisManager::GetVerbosity() 1540 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1542 G4cout << "***** AddSolid ( trap )" << G4 1541 G4cout << "***** AddSolid ( trap )" << G4endl; 1543 1542 1544 //----- skip drawing invisible primitive 1543 //----- skip drawing invisible primitive 1545 if( !IsVisible() ) { return ; } 1544 if( !IsVisible() ) { return ; } 1546 1545 1547 //----- Initialize if necessary 1546 //----- Initialize if necessary 1548 GFBeginModeling(); 1547 GFBeginModeling(); 1549 1548 1550 // 1549 // 1551 AddDetector(trap); 1550 AddDetector(trap); 1552 1551 1553 } // G4GMocrenFileSceneHandler::AddSolid (con 1552 } // G4GMocrenFileSceneHandler::AddSolid (const G4Trap& trap) 1554 1553 1555 1554 1556 //----- Add torus 1555 //----- Add torus 1557 void 1556 void 1558 G4GMocrenFileSceneHandler::AddSolid( const G4 1557 G4GMocrenFileSceneHandler::AddSolid( const G4Torus& torus ) 1559 { 1558 { 1560 if(GFDEBUG || G4VisManager::GetVerbosity() 1559 if(GFDEBUG || G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 1561 G4cout << "***** AddSolid ( torus )" << G 1560 G4cout << "***** AddSolid ( torus )" << G4endl; 1562 1561 1563 //----- skip drawing invisible primitive 1562 //----- skip drawing invisible primitive 1564 if( !IsVisible() ) { return ; } 1563 if( !IsVisible() ) { return ; } 1565 1564 1566 //----- Initialize if necessary 1565 //----- Initialize if necessary 1567 GFBeginModeling(); 1566 GFBeginModeling(); 1568 1567 1569 // 1568 // 1570 AddDetector(torus); 1569 AddDetector(torus); 1571 1570 1572 } // void G4GMocrenFileSceneHandler::AddSolid 1571 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Torus& ) 1573 1572 1574 1573 1575 1574 1576 //----- Add a shape which is not treated abov 1575 //----- Add a shape which is not treated above 1577 void G4GMocrenFileSceneHandler::AddSolid ( co 1576 void G4GMocrenFileSceneHandler::AddSolid ( const G4VSolid& solid ) 1578 { 1577 { 1579 //----- skip drawing invisible primitive 1578 //----- skip drawing invisible primitive 1580 if( !IsVisible() ) { return ; } 1579 if( !IsVisible() ) { return ; } 1581 1580 1582 //----- Initialize if necessary 1581 //----- Initialize if necessary 1583 GFBeginModeling(); 1582 GFBeginModeling(); 1584 1583 1585 // 1584 // 1586 AddDetector(solid); 1585 AddDetector(solid); 1587 1586 1588 //----- Send a primitive 1587 //----- Send a primitive 1589 G4VSceneHandler::AddSolid( solid ) ; 1588 G4VSceneHandler::AddSolid( solid ) ; 1590 1589 1591 } //G4GMocrenFileSceneHandler::AddSolid ( con 1590 } //G4GMocrenFileSceneHandler::AddSolid ( const G4VSolid& ) 1592 1591 1593 #include "G4TrajectoriesModel.hh" 1592 #include "G4TrajectoriesModel.hh" 1594 #include "G4VTrajectory.hh" 1593 #include "G4VTrajectory.hh" 1595 #include "G4VTrajectoryPoint.hh" 1594 #include "G4VTrajectoryPoint.hh" 1596 1595 1597 //----- Add a trajectory 1596 //----- Add a trajectory 1598 void G4GMocrenFileSceneHandler::AddCompound(c 1597 void G4GMocrenFileSceneHandler::AddCompound(const G4VTrajectory & traj) { 1599 1598 1600 kbModelingTrajectory = true; 1599 kbModelingTrajectory = true; 1601 1600 1602 G4VSceneHandler::AddCompound(traj); 1601 G4VSceneHandler::AddCompound(traj); 1603 1602 1604 if(GFDEBUG_TRK) { 1603 if(GFDEBUG_TRK) { 1605 G4cout << " ::AddCompound(const G4VTrajec 1604 G4cout << " ::AddCompound(const G4VTrajectory&) >>>>>>>>> " << G4endl; 1606 G4TrajectoriesModel * pTrModel = dynamic_ 1605 G4TrajectoriesModel * pTrModel = dynamic_cast<G4TrajectoriesModel*>(fpModel); 1607 if (!pTrModel) { 1606 if (!pTrModel) { 1608 G4Exception 1607 G4Exception 1609 ("G4VSceneHandler::AddCompound(const G4VTra 1608 ("G4VSceneHandler::AddCompound(const G4VTrajectory&)", 1610 "gMocren0013", FatalException, "Not a G4Tr 1609 "gMocren0013", FatalException, "Not a G4TrajectoriesModel."); 1611 } else { 1610 } else { 1612 traj.DrawTrajectory(); 1611 traj.DrawTrajectory(); 1613 1612 1614 const G4VTrajectory * trj = pTrModel->G 1613 const G4VTrajectory * trj = pTrModel->GetCurrentTrajectory(); 1615 G4cout << "------ track" << G4endl; 1614 G4cout << "------ track" << G4endl; 1616 G4cout << " name: " << trj->GetP 1615 G4cout << " name: " << trj->GetParticleName() << G4endl; 1617 G4cout << " id: " << trj->GetT 1616 G4cout << " id: " << trj->GetTrackID() << G4endl; 1618 G4cout << " charge: " << trj->GetC 1617 G4cout << " charge: " << trj->GetCharge() << G4endl; 1619 G4cout << " momentum: " << trj->GetI 1618 G4cout << " momentum: " << trj->GetInitialMomentum() << G4endl; 1620 1619 1621 G4int nPnt = trj->GetPointEntries(); 1620 G4int nPnt = trj->GetPointEntries(); 1622 G4cout << " point: "; 1621 G4cout << " point: "; 1623 for(G4int i = 0; i < nPnt; i++) { 1622 for(G4int i = 0; i < nPnt; i++) { 1624 G4cout << trj->GetPoint(i)->GetPosition() < 1623 G4cout << trj->GetPoint(i)->GetPosition() << ", "; 1625 } 1624 } 1626 G4cout << G4endl; 1625 G4cout << G4endl; 1627 } 1626 } 1628 G4cout << G4endl; 1627 G4cout << G4endl; 1629 } 1628 } 1630 1629 1631 kbModelingTrajectory = false; 1630 kbModelingTrajectory = false; 1632 } 1631 } 1633 1632 1634 #include <vector> 1633 #include <vector> 1635 #include "G4VHit.hh" 1634 #include "G4VHit.hh" 1636 #include "G4AttValue.hh" 1635 #include "G4AttValue.hh" 1637 //----- Add a hit 1636 //----- Add a hit 1638 void G4GMocrenFileSceneHandler::AddCompound( 1637 void G4GMocrenFileSceneHandler::AddCompound( const G4VHit & hit) { 1639 if(GFDEBUG_HIT) G4cout << " ::AddCompound(c 1638 if(GFDEBUG_HIT) G4cout << " ::AddCompound(const G4VHit&) >>>>>>>>> " << G4endl; 1640 1639 1641 G4VSceneHandler::AddCompound(hit); 1640 G4VSceneHandler::AddCompound(hit); 1642 1641 1643 /* 1642 /* 1644 const std::map<G4String, G4AttDef> * map 1643 const std::map<G4String, G4AttDef> * map = hit.GetAttDefs(); 1645 if(!map) return; 1644 if(!map) return; 1646 std::map<G4String, G4AttDef>::const_itera 1645 std::map<G4String, G4AttDef>::const_iterator itr = map->begin(); 1647 for(; itr != map->end(); itr++) { 1646 for(; itr != map->end(); itr++) { 1648 G4cout << itr->first << " : " << itr->sec 1647 G4cout << itr->first << " : " << itr->second.GetName() 1649 << " , " << itr->second.GetDesc() << G4en 1648 << " , " << itr->second.GetDesc() << G4endl; 1650 } 1649 } 1651 */ 1650 */ 1652 1651 1653 std::vector<G4String> hitNames = kMessenger 1652 std::vector<G4String> hitNames = kMessenger.getHitNames(); 1654 if(GFDEBUG_HIT) { 1653 if(GFDEBUG_HIT) { 1655 std::vector<G4String>::iterator itr = hit 1654 std::vector<G4String>::iterator itr = hitNames.begin(); 1656 for(; itr != hitNames.end(); itr++) 1655 for(; itr != hitNames.end(); itr++) 1657 G4cout << " hit name : " << *itr << G4 1656 G4cout << " hit name : " << *itr << G4endl; 1658 } 1657 } 1659 1658 1660 std::vector<G4AttValue> * attval = hit.Crea 1659 std::vector<G4AttValue> * attval = hit.CreateAttValues(); 1661 if(!attval) {G4cout << "0 empty " << G4endl 1660 if(!attval) {G4cout << "0 empty " << G4endl;} 1662 else { 1661 else { 1663 1662 1664 G4bool bid[3] = {false, false, false}; 1663 G4bool bid[3] = {false, false, false}; 1665 Index3D id; 1664 Index3D id; 1666 1665 1667 std::vector<G4AttValue>::iterator itr; 1666 std::vector<G4AttValue>::iterator itr; 1668 // First, get IDs 1667 // First, get IDs 1669 for(itr = attval->begin(); itr != attval- 1668 for(itr = attval->begin(); itr != attval->end(); itr++) { 1670 std::string stmp = itr->GetValue(); 1669 std::string stmp = itr->GetValue(); 1671 std::istringstream sval(stmp.c_str()); 1670 std::istringstream sval(stmp.c_str()); 1672 1671 1673 if(itr->GetName() == G4String("XID")) { 1672 if(itr->GetName() == G4String("XID")) { 1674 sval >> id.x; 1673 sval >> id.x; 1675 bid[0] = true; 1674 bid[0] = true; 1676 continue; 1675 continue; 1677 } 1676 } 1678 if(itr->GetName() == G4String("YID")) { 1677 if(itr->GetName() == G4String("YID")) { 1679 sval >> id.y; 1678 sval >> id.y; 1680 bid[1] = true; 1679 bid[1] = true; 1681 continue; 1680 continue; 1682 } 1681 } 1683 if(itr->GetName() == G4String("ZID")) { 1682 if(itr->GetName() == G4String("ZID")) { 1684 sval >> id.z; 1683 sval >> id.z; 1685 bid[2] = true; 1684 bid[2] = true; 1686 continue; 1685 continue; 1687 } 1686 } 1688 } 1687 } 1689 1688 1690 G4int nhitname = (G4int)hitNames.size(); 1689 G4int nhitname = (G4int)hitNames.size(); 1691 1690 1692 if(bid[0] && bid[1] && bid[2]) { 1691 if(bid[0] && bid[1] && bid[2]) { 1693 1692 1694 if(GFDEBUG_HIT) 1693 if(GFDEBUG_HIT) 1695 G4cout << " Hit : index(" << id.x << ", " < 1694 G4cout << " Hit : index(" << id.x << ", " << id.y << ", " 1696 << id.z << ")" << G4endl; 1695 << id.z << ")" << G4endl; 1697 1696 1698 // Get attributes 1697 // Get attributes 1699 for(itr = attval->begin(); itr != attva 1698 for(itr = attval->begin(); itr != attval->end(); itr++) { 1700 for(G4int i = 0; i < nhitname; i++) { 1699 for(G4int i = 0; i < nhitname; i++) { 1701 if(itr->GetName() == hitNames[i]) { 1700 if(itr->GetName() == hitNames[i]) { 1702 1701 1703 std::string stmp = itr->GetValue(); 1702 std::string stmp = itr->GetValue(); 1704 std::istringstream sval(stmp.c_str()); 1703 std::istringstream sval(stmp.c_str()); 1705 G4double value; 1704 G4double value; 1706 G4String unit; 1705 G4String unit; 1707 sval >> value >> unit; 1706 sval >> value >> unit; 1708 1707 1709 std::map<G4String, std::map<Index3D, G4 1708 std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr; 1710 kNestedHitsListItr = kNestedHitsList.fi 1709 kNestedHitsListItr = kNestedHitsList.find(hitNames[i]); 1711 if(kNestedHitsListItr != kNestedHitsLis 1710 if(kNestedHitsListItr != kNestedHitsList.end()) { 1712 //fTempNestedHits = &kNestedHitsListI 1711 //fTempNestedHits = &kNestedHitsListItr->second; 1713 //(*fTempNestedHits)[id] = value; 1712 //(*fTempNestedHits)[id] = value; 1714 kNestedHitsListItr->second[id] = valu 1713 kNestedHitsListItr->second[id] = value; 1715 } else { 1714 } else { 1716 std::map<Index3D, G4double> hits; 1715 std::map<Index3D, G4double> hits; 1717 hits.insert(std::map<Index3D, G4doubl 1716 hits.insert(std::map<Index3D, G4double>::value_type(id, value)); 1718 kNestedHitsList[hitNames[i]] = std::m << 1717 kNestedHitsList[hitNames[i]] = hits; 1719 } 1718 } 1720 1719 1721 1720 1722 if(GFDEBUG_HIT) 1721 if(GFDEBUG_HIT) 1723 G4cout << " : " << hitNames[i] << 1722 G4cout << " : " << hitNames[i] << " -> " << value 1724 << " [" << unit << "]" << G4endl; 1723 << " [" << unit << "]" << G4endl; 1725 } 1724 } 1726 } 1725 } 1727 } 1726 } 1728 } else { 1727 } else { 1729 G4Exception("G4GMocrenFileSceneHandler: 1728 G4Exception("G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)", 1730 "gMocren0014", FatalException, "Error") 1729 "gMocren0014", FatalException, "Error"); 1731 } 1730 } 1732 1731 1733 delete attval; 1732 delete attval; 1734 } 1733 } 1735 1734 1736 } 1735 } 1737 1736 1738 void G4GMocrenFileSceneHandler::AddCompound( 1737 void G4GMocrenFileSceneHandler::AddCompound( const G4VDigi & digi) { 1739 if(GFDEBUG_DIGI) G4cout << " ::AddCompound( 1738 if(GFDEBUG_DIGI) G4cout << " ::AddCompound(const G4VDigi&) >>>>>>>>> " << G4endl; 1740 G4VSceneHandler::AddCompound(digi); 1739 G4VSceneHandler::AddCompound(digi); 1741 } 1740 } 1742 1741 1743 void G4GMocrenFileSceneHandler::AddCompound(c 1742 void G4GMocrenFileSceneHandler::AddCompound(const G4THitsMap<G4double> & hits) { 1744 if(GFDEBUG_HIT) 1743 if(GFDEBUG_HIT) 1745 G4cout << " ::AddCompound(const std::map< 1744 G4cout << " ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " << G4endl; 1746 1745 1747 1746 1748 std::vector<G4String> hitScorerNames = kMes 1747 std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames(); 1749 G4int nhitname = (G4int)hitScorerNames.size 1748 G4int nhitname = (G4int)hitScorerNames.size(); 1750 G4String scorername = static_cast<G4VHitsCo 1749 G4String scorername = static_cast<G4VHitsCollection>(hits).GetName(); 1751 1750 1752 //-- --// 1751 //-- --// 1753 /* 1752 /* 1754 std::vector<G4String> hitScorerNames = kMes 1753 std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames(); 1755 if(GFDEBUG_HIT) { 1754 if(GFDEBUG_HIT) { 1756 std::vector<G4String>::iterator itr = hit 1755 std::vector<G4String>::iterator itr = hitScorerNames.begin(); 1757 for(; itr != hitScorerNames.end(); itr++) 1756 for(; itr != hitScorerNames.end(); itr++) 1758 G4cout << " PS name : " << *itr << G4e 1757 G4cout << " PS name : " << *itr << G4endl; 1759 } 1758 } 1760 */ 1759 */ 1761 1760 1762 { // Scope bracket to avoid compiler messa 1761 { // Scope bracket to avoid compiler messages about shadowing (JA). 1763 //for(G4int i = 0; i < nhitname; i++) { 1762 //for(G4int i = 0; i < nhitname; i++) { // this selection trusts 1764 //if(scorername == hitScorerNames[i]) { 1763 //if(scorername == hitScorerNames[i]) { // thea command /vis/scene/add/psHits hit_name. 1765 1764 1766 G4int idx[3]; 1765 G4int idx[3]; 1767 std::map<G4int, G4double*> * map = hits 1766 std::map<G4int, G4double*> * map = hits.GetMap(); 1768 std::map<G4int, G4double*>::const_itera 1767 std::map<G4int, G4double*>::const_iterator itr = map->begin(); 1769 for(; itr != map->end(); itr++) { 1768 for(; itr != map->end(); itr++) { 1770 GetNestedVolumeIndex(itr->first, idx); 1769 GetNestedVolumeIndex(itr->first, idx); 1771 Index3D id(idx[0], idx[1], idx[2]); 1770 Index3D id(idx[0], idx[1], idx[2]); 1772 1771 1773 std::map<G4String, std::map<Index3D, G4doub 1772 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr; 1774 nestedHitsListItr = kNestedHitsList.find(sc 1773 nestedHitsListItr = kNestedHitsList.find(scorername); 1775 if(nestedHitsListItr != kNestedHitsList.end 1774 if(nestedHitsListItr != kNestedHitsList.end()) { 1776 nestedHitsListItr->second[id] = *(itr->se 1775 nestedHitsListItr->second[id] = *(itr->second); 1777 } else { 1776 } else { 1778 std::map<Index3D, G4double> hit; 1777 std::map<Index3D, G4double> hit; 1779 hit.insert(std::map<Index3D, G4double>::v 1778 hit.insert(std::map<Index3D, G4double>::value_type(id, *(itr->second))); 1780 kNestedHitsList[scorername] = std::move(h << 1779 kNestedHitsList[scorername] = hit; 1781 } 1780 } 1782 } 1781 } 1783 1782 1784 //break; 1783 //break; 1785 //} 1784 //} 1786 //} 1785 //} 1787 } 1786 } 1788 1787 1789 if(GFDEBUG_HIT) { 1788 if(GFDEBUG_HIT) { 1790 G4String meshname = static_cast<G4VHitsCo 1789 G4String meshname = static_cast<G4VHitsCollection>(hits).GetSDname(); 1791 G4cout << " >>>>> " << meshname << 1790 G4cout << " >>>>> " << meshname << " : " << scorername << G4endl; 1792 1791 1793 for(G4int i = 0; i < nhitname; i++) 1792 for(G4int i = 0; i < nhitname; i++) 1794 if(scorername == hitScorerNames[i]) 1793 if(scorername == hitScorerNames[i]) 1795 G4cout << " !!!! Hit scorer !!!! " << 1794 G4cout << " !!!! Hit scorer !!!! " << scorername << G4endl; 1796 1795 1797 G4cout << " dimension: " 1796 G4cout << " dimension: " 1798 << kNestedVolumeDimension[0] << " x " 1797 << kNestedVolumeDimension[0] << " x " 1799 << kNestedVolumeDimension[1] << " x " 1798 << kNestedVolumeDimension[1] << " x " 1800 << kNestedVolumeDimension[2] << G4endl; 1799 << kNestedVolumeDimension[2] << G4endl; 1801 1800 1802 G4int id[3]; 1801 G4int id[3]; 1803 std::map<G4int, G4double*> * map = hits.G 1802 std::map<G4int, G4double*> * map = hits.GetMap(); 1804 std::map<G4int, G4double*>::const_iterato 1803 std::map<G4int, G4double*>::const_iterator itr = map->begin(); 1805 for(; itr != map->end(); itr++) { 1804 for(; itr != map->end(); itr++) { 1806 GetNestedVolumeIndex(itr->first, id); 1805 GetNestedVolumeIndex(itr->first, id); 1807 G4cout << "[" << itr->first << "] " 1806 G4cout << "[" << itr->first << "] " 1808 << "("<< id[0] << "," << id[1] << "," 1807 << "("<< id[0] << "," << id[1] << "," << id[2] << ")" 1809 << *(itr->second) << ", "; 1808 << *(itr->second) << ", "; 1810 } 1809 } 1811 G4cout << G4endl; 1810 G4cout << G4endl; 1812 } 1811 } 1813 } 1812 } 1814 1813 1815 void G4GMocrenFileSceneHandler::AddCompound(c 1814 void G4GMocrenFileSceneHandler::AddCompound(const G4THitsMap<G4StatDouble> & hits) { 1816 if(GFDEBUG_HIT) 1815 if(GFDEBUG_HIT) 1817 G4cout << " ::AddCompound(const std::map< 1816 G4cout << " ::AddCompound(const std::map<G4int, G4StatDouble*> &) >>>>>>>>> " << G4endl; 1818 1817 1819 1818 1820 std::vector<G4String> hitScorerNames = kMes 1819 std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames(); 1821 G4int nhitname = (G4int)hitScorerNames.size 1820 G4int nhitname = (G4int)hitScorerNames.size(); 1822 G4String scorername = static_cast<G4VHitsCo 1821 G4String scorername = static_cast<G4VHitsCollection>(hits).GetName(); 1823 1822 1824 //-- --// 1823 //-- --// 1825 /* 1824 /* 1826 std::vector<G4String> hitScorerNames = kMes 1825 std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames(); 1827 if(GFDEBUG_HIT) { 1826 if(GFDEBUG_HIT) { 1828 std::vector<G4String>::iterator itr = hit 1827 std::vector<G4String>::iterator itr = hitScorerNames.begin(); 1829 for(; itr != hitScorerNames.end(); itr++) 1828 for(; itr != hitScorerNames.end(); itr++) 1830 G4cout << " PS name : " << *itr << G4e 1829 G4cout << " PS name : " << *itr << G4endl; 1831 } 1830 } 1832 */ 1831 */ 1833 1832 1834 { // Scope bracket to avoid compiler messa 1833 { // Scope bracket to avoid compiler messages about shadowing (JA). 1835 //for(G4int i = 0; i < nhitname; i++) { 1834 //for(G4int i = 0; i < nhitname; i++) { // this selection trusts 1836 //if(scorername == hitScorerNames[i]) { 1835 //if(scorername == hitScorerNames[i]) { // thea command /vis/scene/add/psHits hit_name. 1837 1836 1838 G4int idx[3]; 1837 G4int idx[3]; 1839 std::map<G4int, G4StatDouble*> * map = 1838 std::map<G4int, G4StatDouble*> * map = hits.GetMap(); 1840 std::map<G4int, G4StatDouble*>::const_i 1839 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin(); 1841 for(; itr != map->end(); itr++) { 1840 for(; itr != map->end(); itr++) { 1842 GetNestedVolumeIndex(itr->first, idx); 1841 GetNestedVolumeIndex(itr->first, idx); 1843 Index3D id(idx[0], idx[1], idx[2]); 1842 Index3D id(idx[0], idx[1], idx[2]); 1844 1843 1845 std::map<G4String, std::map<Index3D, G4doub 1844 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr; 1846 nestedHitsListItr = kNestedHitsList.find(sc 1845 nestedHitsListItr = kNestedHitsList.find(scorername); 1847 if(nestedHitsListItr != kNestedHitsList.end 1846 if(nestedHitsListItr != kNestedHitsList.end()) { 1848 nestedHitsListItr->second[id] = itr->seco 1847 nestedHitsListItr->second[id] = itr->second->sum_wx(); 1849 } else { 1848 } else { 1850 std::map<Index3D, G4double> hit; 1849 std::map<Index3D, G4double> hit; 1851 hit.insert(std::map<Index3D, G4double>::v 1850 hit.insert(std::map<Index3D, G4double>::value_type(id, itr->second->sum_wx())); 1852 kNestedHitsList[scorername] = std::move(h << 1851 kNestedHitsList[scorername] = hit; 1853 } 1852 } 1854 } 1853 } 1855 1854 1856 //break; 1855 //break; 1857 //} 1856 //} 1858 //} 1857 //} 1859 } 1858 } 1860 1859 1861 if(GFDEBUG_HIT) { 1860 if(GFDEBUG_HIT) { 1862 G4String meshname = static_cast<G4VHitsCo 1861 G4String meshname = static_cast<G4VHitsCollection>(hits).GetSDname(); 1863 G4cout << " >>>>> " << meshname << 1862 G4cout << " >>>>> " << meshname << " : " << scorername << G4endl; 1864 1863 1865 for(G4int i = 0; i < nhitname; i++) 1864 for(G4int i = 0; i < nhitname; i++) 1866 if(scorername == hitScorerNames[i]) 1865 if(scorername == hitScorerNames[i]) 1867 G4cout << " !!!! Hit scorer !!!! " << 1866 G4cout << " !!!! Hit scorer !!!! " << scorername << G4endl; 1868 1867 1869 G4cout << " dimension: " 1868 G4cout << " dimension: " 1870 << kNestedVolumeDimension[0] << " x " 1869 << kNestedVolumeDimension[0] << " x " 1871 << kNestedVolumeDimension[1] << " x " 1870 << kNestedVolumeDimension[1] << " x " 1872 << kNestedVolumeDimension[2] << G4endl; 1871 << kNestedVolumeDimension[2] << G4endl; 1873 1872 1874 G4int id[3]; 1873 G4int id[3]; 1875 std::map<G4int, G4StatDouble*> * map = hi 1874 std::map<G4int, G4StatDouble*> * map = hits.GetMap(); 1876 std::map<G4int, G4StatDouble*>::const_ite 1875 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin(); 1877 for(; itr != map->end(); itr++) { 1876 for(; itr != map->end(); itr++) { 1878 GetNestedVolumeIndex(itr->first, id); 1877 GetNestedVolumeIndex(itr->first, id); 1879 G4cout << "[" << itr->first << "] " 1878 G4cout << "[" << itr->first << "] " 1880 << "("<< id[0] << "," << id[1] << "," 1879 << "("<< id[0] << "," << id[1] << "," << id[2] << ")" 1881 << itr->second->sum_wx() << ", "; 1880 << itr->second->sum_wx() << ", "; 1882 } 1881 } 1883 G4cout << G4endl; 1882 G4cout << G4endl; 1884 } 1883 } 1885 } 1884 } 1886 1885 1887 //----- 1886 //----- 1888 G4bool G4GMocrenFileSceneHandler::IsVisible() 1887 G4bool G4GMocrenFileSceneHandler::IsVisible() 1889 { 1888 { 1890 //----- 1889 //----- 1891 G4bool visibility = true ; 1890 G4bool visibility = true ; 1892 1891 1893 const G4VisAttributes* pVisAttribs = 1892 const G4VisAttributes* pVisAttribs = 1894 fpViewer->GetApplicableVisAttributes( fpV 1893 fpViewer->GetApplicableVisAttributes( fpVisAttribs ); 1895 1894 1896 if(pVisAttribs) { 1895 if(pVisAttribs) { 1897 visibility = pVisAttribs->IsVisible(); 1896 visibility = pVisAttribs->IsVisible(); 1898 } 1897 } 1899 1898 1900 return visibility ; 1899 return visibility ; 1901 1900 1902 } // G4GMocrenFileSceneHandler::IsVisible() 1901 } // G4GMocrenFileSceneHandler::IsVisible() 1903 1902 1904 1903 1905 //----- 1904 //----- 1906 void G4GMocrenFileSceneHandler::ClearTransien 1905 void G4GMocrenFileSceneHandler::ClearTransientStore() 1907 { 1906 { 1908 // This is typically called after an update 1907 // This is typically called after an update and before drawing hits 1909 // of the next event. To simulate the clea 1908 // of the next event. To simulate the clearing of "transients" 1910 // (hits, etc.) the detector is redrawn... 1909 // (hits, etc.) the detector is redrawn... 1911 if (fpViewer) { 1910 if (fpViewer) { 1912 fpViewer -> SetView (); 1911 fpViewer -> SetView (); 1913 fpViewer -> ClearView (); 1912 fpViewer -> ClearView (); 1914 fpViewer -> DrawView (); 1913 fpViewer -> DrawView (); 1915 } 1914 } 1916 } 1915 } 1917 1916 1918 //----- 1917 //----- 1919 void G4GMocrenFileSceneHandler::AddDetector(c 1918 void G4GMocrenFileSceneHandler::AddDetector(const G4VSolid & solid) { 1920 1919 1921 Detector detector; 1920 Detector detector; 1922 1921 1923 // detector name 1922 // detector name 1924 detector.name = solid.GetName(); 1923 detector.name = solid.GetName(); 1925 if(GFDEBUG_DET > 1) 1924 if(GFDEBUG_DET > 1) 1926 G4cout << "0 Detector name : " << detecto 1925 G4cout << "0 Detector name : " << detector.name << G4endl; 1927 1926 1928 const G4VModel* pv_model = GetModel(); 1927 const G4VModel* pv_model = GetModel(); 1929 if (!pv_model) { return ; } 1928 if (!pv_model) { return ; } 1930 G4PhysicalVolumeModel* pPVModel = 1929 G4PhysicalVolumeModel* pPVModel = 1931 dynamic_cast<G4PhysicalVolumeModel*>(fpMo 1930 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 1932 if (!pPVModel) { return ; } 1931 if (!pPVModel) { return ; } 1933 1932 1934 // edge points of the detector 1933 // edge points of the detector 1935 std::vector<G4float *> dedges; 1934 std::vector<G4float *> dedges; 1936 G4Polyhedron * poly = solid.CreatePolyhedro 1935 G4Polyhedron * poly = solid.CreatePolyhedron(); 1937 detector.polyhedron = poly; 1936 detector.polyhedron = poly; 1938 detector.transform3D = fObjectTransformatio 1937 detector.transform3D = fObjectTransformation; 1939 1938 1940 // retrieve color 1939 // retrieve color 1941 unsigned char uccolor[3] = {30, 30, 30}; 1940 unsigned char uccolor[3] = {30, 30, 30}; 1942 if(pPVModel->GetCurrentLV()->GetVisAttribut 1941 if(pPVModel->GetCurrentLV()->GetVisAttributes()) { 1943 G4Color color = pPVModel->GetCurrentLV()- 1942 G4Color color = pPVModel->GetCurrentLV()->GetVisAttributes()->GetColor(); 1944 uccolor[0] = (unsigned char)(color.GetRed 1943 uccolor[0] = (unsigned char)(color.GetRed()*255); 1945 uccolor[1] = (unsigned char)(color.GetGre 1944 uccolor[1] = (unsigned char)(color.GetGreen()*255); 1946 uccolor[2] = (unsigned char)(color.GetBlu 1945 uccolor[2] = (unsigned char)(color.GetBlue()*255); 1947 //if(uccolor[0] < 2 && uccolor[1] < 2 && 1946 //if(uccolor[0] < 2 && uccolor[1] < 2 && uccolor[2] < 2) 1948 //uccolor[0] = uccolor[1] = uccolor[2] = 1947 //uccolor[0] = uccolor[1] = uccolor[2] = 30; // dark grey 1949 } 1948 } 1950 for(G4int i = 0; i < 3; i++) detector.color 1949 for(G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i]; 1951 // 1950 // 1952 kDetectors.push_back(detector); 1951 kDetectors.push_back(detector); 1953 1952 1954 if(GFDEBUG_DET > 1) { 1953 if(GFDEBUG_DET > 1) { 1955 G4cout << "0 color: (" << (G4int)uc 1954 G4cout << "0 color: (" << (G4int)uccolor[0] << ", " 1956 << (G4int)uccolor[1] << ", " << (G4int)u 1955 << (G4int)uccolor[1] << ", " << (G4int)uccolor[2] << ")" 1957 << G4endl; 1956 << G4endl; 1958 } 1957 } 1959 1958 1960 } 1959 } 1961 1960 1962 //----- 1961 //----- 1963 void G4GMocrenFileSceneHandler::ExtractDetect 1962 void G4GMocrenFileSceneHandler::ExtractDetector() { 1964 1963 1965 std::vector<Detector>::iterator itr = kDete 1964 std::vector<Detector>::iterator itr = kDetectors.begin(); 1966 1965 1967 for(; itr != kDetectors.end(); itr++) { 1966 for(; itr != kDetectors.end(); itr++) { 1968 1967 1969 // detector name 1968 // detector name 1970 G4String detname = itr->name; 1969 G4String detname = itr->name; 1971 if(GFDEBUG_DET > 1) 1970 if(GFDEBUG_DET > 1) 1972 G4cout << "Detector name : " << detname 1971 G4cout << "Detector name : " << detname << G4endl; 1973 1972 1974 // edge points of the detector 1973 // edge points of the detector 1975 std::vector<G4float *> dedges; 1974 std::vector<G4float *> dedges; 1976 G4Polyhedron * poly = itr->polyhedron; 1975 G4Polyhedron * poly = itr->polyhedron; 1977 poly->Transform(itr->transform3D); 1976 poly->Transform(itr->transform3D); 1978 G4Transform3D invVolTrans = kVolumeTrans3 1977 G4Transform3D invVolTrans = kVolumeTrans3D.inverse(); 1979 poly->Transform(invVolTrans); 1978 poly->Transform(invVolTrans); 1980 1979 1981 G4Point3D v1, v2; 1980 G4Point3D v1, v2; 1982 G4bool bnext = true; 1981 G4bool bnext = true; 1983 G4int next; 1982 G4int next; 1984 G4int nedges = 0; 1983 G4int nedges = 0; 1985 // 1984 // 1986 while(bnext) { 1985 while(bnext) { 1987 if(!(poly->GetNextEdge(v1, v2, next))) 1986 if(!(poly->GetNextEdge(v1, v2, next))) bnext =false; 1988 G4float * edge = new G4float[6]; 1987 G4float * edge = new G4float[6]; 1989 edge[0] = v1.x()/mm; 1988 edge[0] = v1.x()/mm; 1990 edge[1] = v1.y()/mm; 1989 edge[1] = v1.y()/mm; 1991 edge[2] = v1.z()/mm; 1990 edge[2] = v1.z()/mm; 1992 edge[3] = v2.x()/mm; 1991 edge[3] = v2.x()/mm; 1993 edge[4] = v2.y()/mm; 1992 edge[4] = v2.y()/mm; 1994 edge[5] = v2.z()/mm; 1993 edge[5] = v2.z()/mm; 1995 dedges.push_back(edge); 1994 dedges.push_back(edge); 1996 nedges++; 1995 nedges++; 1997 } 1996 } 1998 //delete poly; 1997 //delete poly; 1999 // detector color 1998 // detector color 2000 unsigned char uccolor[3] = {itr->color[0] 1999 unsigned char uccolor[3] = {itr->color[0], 2001 itr->color[1], 2000 itr->color[1], 2002 itr->color[2]}; 2001 itr->color[2]}; 2003 // 2002 // 2004 kgMocrenIO->addDetector(detname, dedges, 2003 kgMocrenIO->addDetector(detname, dedges, uccolor); 2005 for(G4int i = 0; i < nedges; i++) { // # 2004 for(G4int i = 0; i < nedges; i++) { // # of edges is 12. 2006 delete [] dedges[i]; 2005 delete [] dedges[i]; 2007 } 2006 } 2008 dedges.clear(); 2007 dedges.clear(); 2009 2008 2010 if(GFDEBUG_DET > 1) { 2009 if(GFDEBUG_DET > 1) { 2011 G4cout << " color: (" << (G4int)uc 2010 G4cout << " color: (" << (G4int)uccolor[0] << ", " 2012 << (G4int)uccolor[1] << ", " << (G4int 2011 << (G4int)uccolor[1] << ", " << (G4int)uccolor[2] << ")" 2013 << G4endl; 2012 << G4endl; 2014 } 2013 } 2015 } 2014 } 2016 } 2015 } 2017 2016 2018 void G4GMocrenFileSceneHandler::GetNestedVolu 2017 void G4GMocrenFileSceneHandler::GetNestedVolumeIndex(G4int _idx, G4int _idx3d[3]) { 2019 if(kNestedVolumeDimension[0] == 0 || 2018 if(kNestedVolumeDimension[0] == 0 || 2020 kNestedVolumeDimension[1] == 0 || 2019 kNestedVolumeDimension[1] == 0 || 2021 kNestedVolumeDimension[2] == 0) { 2020 kNestedVolumeDimension[2] == 0) { 2022 for(G4int i = 0; i < 3; i++) _idx3d[i] = 2021 for(G4int i = 0; i < 3; i++) _idx3d[i] = 0; 2023 return; 2022 return; 2024 } 2023 } 2025 2024 2026 2025 2027 if(kFlagParameterization == 0) { 2026 if(kFlagParameterization == 0) { 2028 2027 2029 G4int plane = kNestedVolumeDimension[2]*k 2028 G4int plane = kNestedVolumeDimension[2]*kNestedVolumeDimension[1]; 2030 G4int line = kNestedVolumeDimension[2]; 2029 G4int line = kNestedVolumeDimension[2]; 2031 2030 2032 /* 2031 /* 2033 G4int idx3d[3]; 2032 G4int idx3d[3]; 2034 idx3d[0] = _idx/plane; 2033 idx3d[0] = _idx/plane; 2035 idx3d[1] = (_idx%plane)/line; 2034 idx3d[1] = (_idx%plane)/line; 2036 idx3d[2] = (_idx%plane)%line; 2035 idx3d[2] = (_idx%plane)%line; 2037 _idx3d[0] = idx3d[kNestedVolumeDirAxis[0]]; 2036 _idx3d[0] = idx3d[kNestedVolumeDirAxis[0]]; 2038 _idx3d[1] = idx3d[kNestedVolumeDirAxis[1]]; 2037 _idx3d[1] = idx3d[kNestedVolumeDirAxis[1]]; 2039 _idx3d[2] = idx3d[kNestedVolumeDirAxis[2]]; 2038 _idx3d[2] = idx3d[kNestedVolumeDirAxis[2]]; 2040 */ 2039 */ 2041 2040 2042 _idx3d[kNestedVolumeDirAxis[0]] = _idx/pl 2041 _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane; 2043 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%p 2042 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line; 2044 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%p 2043 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line; 2045 2044 2046 2045 2047 2046 2048 /* 2047 /* 2049 2048 2050 G4cout << "G4GMocrenFileSceneHandler::GetNe 2049 G4cout << "G4GMocrenFileSceneHandler::GetNestedVolumeIndex : " << G4endl; 2051 G4cout << "(depi, depj, depk) : " 2050 G4cout << "(depi, depj, depk) : " 2052 << kNestedVolumeDirAxis[0] << ", " 2051 << kNestedVolumeDirAxis[0] << ", " 2053 << kNestedVolumeDirAxis[1] << ", " 2052 << kNestedVolumeDirAxis[1] << ", " 2054 << kNestedVolumeDirAxis[2] << G4endl; 2053 << kNestedVolumeDirAxis[2] << G4endl; 2055 G4cout << "(ni, nj, nk) :" 2054 G4cout << "(ni, nj, nk) :" 2056 << kNestedVolumeDimension[0] << ", " 2055 << kNestedVolumeDimension[0] << ", " 2057 << kNestedVolumeDimension[1] << ", " 2056 << kNestedVolumeDimension[1] << ", " 2058 << kNestedVolumeDimension[2] << " - " << G 2057 << kNestedVolumeDimension[2] << " - " << G4endl; 2059 2058 2060 G4cout << " _idx = " << _idx << " : plane 2059 G4cout << " _idx = " << _idx << " : plane = " 2061 << plane << " , line = " << line << G4en 2060 << plane << " , line = " << line << G4endl; 2062 G4cout << "(idx,idy,idz) + " << _idx3d[0] < 2061 G4cout << "(idx,idy,idz) + " << _idx3d[0] << ", " 2063 << _idx3d[1] << ", " << _idx3d[2] << " + " 2062 << _idx3d[1] << ", " << _idx3d[2] << " + " << G4endl; 2064 2063 2065 */ 2064 */ 2066 2065 2067 2066 2068 2067 2069 } else { 2068 } else { 2070 2069 2071 G4int plane = kNestedVolumeDimension[0]*k 2070 G4int plane = kNestedVolumeDimension[0]*kNestedVolumeDimension[1]; 2072 G4int line = kNestedVolumeDimension[0]; 2071 G4int line = kNestedVolumeDimension[0]; 2073 _idx3d[kNestedVolumeDirAxis[2]] = _idx/pl 2072 _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane; 2074 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%p 2073 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line; 2075 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%p 2074 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line; 2076 2075 2077 } 2076 } 2078 2077 2079 } 2078 } 2080 2079 2081 2080 2082 //-- --// 2081 //-- --// 2083 G4GMocrenFileSceneHandler::Detector::Detector 2082 G4GMocrenFileSceneHandler::Detector::Detector() 2084 : polyhedron(0) { 2083 : polyhedron(0) { 2085 color[0] = color[1] = color[2] = 255; 2084 color[0] = color[1] = color[2] = 255; 2086 } 2085 } 2087 G4GMocrenFileSceneHandler::Detector::~Detecto 2086 G4GMocrenFileSceneHandler::Detector::~Detector() { 2088 if(!polyhedron) delete polyhedron; 2087 if(!polyhedron) delete polyhedron; 2089 } 2088 } 2090 void G4GMocrenFileSceneHandler::Detector::cle 2089 void G4GMocrenFileSceneHandler::Detector::clear() { 2091 name.clear(); 2090 name.clear(); 2092 if(!polyhedron) delete polyhedron; 2091 if(!polyhedron) delete polyhedron; 2093 color[0] = color[1] = color[2] = 255; 2092 color[0] = color[1] = color[2] = 255; 2094 transform3D = G4Transform3D::Identity; 2093 transform3D = G4Transform3D::Identity; 2095 } 2094 } 2096 2095 2097 //-- --// 2096 //-- --// 2098 G4GMocrenFileSceneHandler::Index3D::Index3D() 2097 G4GMocrenFileSceneHandler::Index3D::Index3D() 2099 : x(0), y(0), z(0) { 2098 : x(0), y(0), z(0) { 2100 ; 2099 ; 2101 } 2100 } 2102 2101 2103 G4GMocrenFileSceneHandler::Index3D::Index3D(c 2102 G4GMocrenFileSceneHandler::Index3D::Index3D(const Index3D & _index3D) 2104 : x(_index3D.x), y(_index3D.y), z(_index3D. 2103 : x(_index3D.x), y(_index3D.y), z(_index3D.z) { 2105 //: x(_index3D.X()), 2104 //: x(_index3D.X()), 2106 //y(_index3D.Y()), 2105 //y(_index3D.Y()), 2107 //z(_index3D.Z()) { 2106 //z(_index3D.Z()) { 2108 // : x(static_cast<Index3D>(_index3D).x), 2107 // : x(static_cast<Index3D>(_index3D).x), 2109 // y(static_cast<Index3D>(_index3D).y), 2108 // y(static_cast<Index3D>(_index3D).y), 2110 // z(static_cast<Index3D>(_index3D).z) { 2109 // z(static_cast<Index3D>(_index3D).z) { 2111 ; 2110 ; 2112 } 2111 } 2113 2112 2114 G4GMocrenFileSceneHandler::Index3D::Index3D(G 2113 G4GMocrenFileSceneHandler::Index3D::Index3D(G4int _x, G4int _y, G4int _z) 2115 : x(_x), y(_y), z(_z) { 2114 : x(_x), y(_y), z(_z) { 2116 ; 2115 ; 2117 } 2116 } 2118 G4bool G4GMocrenFileSceneHandler::Index3D::op 2117 G4bool G4GMocrenFileSceneHandler::Index3D::operator < (const Index3D & _right) const { 2119 if(z < static_cast<Index3D>(_right).z) { 2118 if(z < static_cast<Index3D>(_right).z) { 2120 return true; 2119 return true; 2121 } else if(z == _right.z) { 2120 } else if(z == _right.z) { 2122 if(y < static_cast<Index3D>(_right).y) re 2121 if(y < static_cast<Index3D>(_right).y) return true; 2123 else if(y == _right.y) 2122 else if(y == _right.y) 2124 if(x < static_cast<Index3D>(_right).x) 2123 if(x < static_cast<Index3D>(_right).x) return true; 2125 } 2124 } 2126 return false; 2125 return false; 2127 } 2126 } 2128 G4bool G4GMocrenFileSceneHandler::Index3D::op 2127 G4bool G4GMocrenFileSceneHandler::Index3D::operator == (const Index3D & _right) const { 2129 if(z == _right.z && y == _right.y && x == _ 2128 if(z == _right.z && y == _right.y && x == _right.x) return true; 2130 return false; 2129 return false; 2131 } 2130 } 2132 2131