111 G4int G4GMocrenFileSceneHandler::kSceneIdCount = 0;
124 kMessenger(messenger),
126 kbSetModalityVoxelSize(false),
127 kbModelingTrajectory(false),
129 kFlagInModeling(false),
130 kFlagSaving_g4_gdd(false),
131 kFlagParameterization(0),
132 kFlagProcessedInteractiveScorer(false) {
135 if(std::getenv(
"G4GMocrenFile_DEST_DIR") == NULL) {
136 kGddDestDir[0] =
'\0';
142 const char * env = std::getenv(
"G4GMocrenFile_DEST_DIR");
143 int len = std::strlen(env);
145 G4Exception(
"G4GMocrenFileSceneHandler::G4GMocrenFileSceneHandler(*)",
147 "Invalid length of string set in G4GMocrenFile_DEST_DIR");
149 std::strncpy(kGddDestDir, env, len+1);
156 if ( std::getenv(
"G4GMocrenFile_MAX_FILE_NUM" ) != NULL ) {
157 char * pcFileNum = getenv(
"G4GMocrenFile_MAX_FILE_NUM");
159 std::strncpy(c10FileNum, pcFileNum, 10);
160 kMaxFileNum = std::atoi(c10FileNum);
165 if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; }
167 InitializeParameters();
183 if(kgMocrenIO != NULL)
delete kgMocrenIO;
188 void G4GMocrenFileSceneHandler::InitializeParameters() {
190 kbSetModalityVoxelSize =
false;
192 for(
G4int i = 0; i < 3; i++) {
193 kModalitySize[i] = 0;
194 kNestedVolumeDimension[i] = 0;
195 kNestedVolumeDirAxis[i] = -1;
206 const G4int MAX_FILE_INDEX = kMaxFileNum - 1 ;
209 std::strncpy(kGddFileName, kGddDestDir, std::strlen(kGddDestDir)+1);
215 static G4int currentNumber = 0;
216 for(
G4int i = currentNumber ; i < kMaxFileNum ; i++) {
219 if( i == MAX_FILE_INDEX )
222 G4cout <<
"===========================================" <<
G4endl;
223 G4cout <<
"WARNING MESSAGE from GMocrenFile driver: " <<
G4endl;
224 G4cout <<
" This file name is the final one in the " <<
G4endl;
225 G4cout <<
" automatic updation of the output file name." <<
G4endl;
226 G4cout <<
" You may overwrite existing files, i.e. " <<
G4endl;
228 G4cout <<
"===========================================" <<
G4endl;
233 if( i >= 0 && i <= 9 ) {
234 std::sprintf( kGddFileName,
"%s%s%s%d.gdd" , kGddDestDir,
GDD_FILE_HEADER,
"0", i );
236 std::sprintf( kGddFileName,
"%s%s%d.gdd" , kGddDestDir,
GDD_FILE_HEADER, i );
240 std::ifstream fin(kGddFileName);
242 G4cout <<
"FILEOPEN: " << i <<
" : " << kGddFileName << fin.fail()
256 G4cout <<
"======================================================================" <<
G4endl;
258 G4cout <<
"Destination directory (current dir if NULL): " << kGddDestDir <<
G4endl;
259 G4cout <<
"Maximum number of files in the destination directory: " << kMaxFileNum <<
G4endl;
261 G4cout <<
" * The maximum number is customizable as: " <<
G4endl;
262 G4cout <<
" % setenv G4GMocrenFile_MAX_FILE_NUM number " <<
G4endl;
263 G4cout <<
" * The destination directory is customizable as:" <<
G4endl;
264 G4cout <<
" % setenv G4GMocrenFile_DEST_DIR dir_name/ " <<
G4endl;
265 G4cout <<
" ** Do not forget \"/\" at the end of the dir_name, e.g. \"./tmp/\"." <<
G4endl;
269 G4cout <<
"======================================================================" <<
G4endl;
283 G4cout <<
"***** (started) " ;
288 kFlagSaving_g4_gdd =
true;
296 std::vector<G4float> map;
298 for(
G4int i = minmax[0]; i <= minmax[1]; i++) {
334 std::vector<Detector>::iterator itr = kDetectors.begin();
335 for(; itr != kDetectors.end(); itr++) {
340 kNestedHitsList.clear();
341 kNestedVolumeNames.clear();
353 G4cout <<
"***** (started) (close "
354 << kGddFileName <<
")" <<
G4endl;
356 if(kGddDest) kGddDest.close();
357 kFlagSaving_g4_gdd =
false;
359 std::map<Index3D, G4float>::iterator itr = kNestedModality.begin();
360 G4int xmax=0, ymax=0, zmax=0;
361 for(; itr != kNestedModality.end(); itr++) {
362 if(itr->first.x > xmax) xmax = itr->first.x;
363 if(itr->first.y > ymax) ymax = itr->first.y;
364 if(itr->first.z > zmax) zmax = itr->first.z;
367 kModalitySize[0] = xmax+1;
368 kModalitySize[1] = ymax+1;
369 kModalitySize[2] = zmax+1;
371 if(
GFDEBUG)
G4cout <<
"gMocren-file driver : modality size : "
372 << kModalitySize[0] <<
" x "
373 << kModalitySize[1] <<
" x "
374 << kModalitySize[2] <<
G4endl;
376 G4int nxy = kModalitySize[0]*kModalitySize[1];
378 for(
G4int z = 0; z < kModalitySize[2]; z++) {
379 short * modality =
new short[nxy];
380 for(
G4int y = 0; y < kModalitySize[1]; y++) {
381 for(
G4int x = 0; x < kModalitySize[0]; x++) {
385 G4int ixy = x + y*kModalitySize[0];
387 itr = kNestedModality.find(idx);
388 if(itr != kNestedModality.end()) {
392 modality[ixy] = -1024;
401 size_t nhits = kNestedHitsList.size();
404 std::map<Index3D, G4double>::iterator hitsItr;
405 std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr = kNestedHitsList.begin();
407 for(
G4int n = 0; hitsListItr != kNestedHitsList.end(); hitsListItr++,
n++) {
414 for(
G4int z = 0 ; z < kModalitySize[2]; z++) {
416 for(
G4int y = 0; y < kModalitySize[1]; y++) {
417 for(
G4int x = 0; x < kModalitySize[0]; x++) {
419 G4int ixy = x + y*kModalitySize[0];
421 hitsItr = hitsListItr->second.find(idx);
422 if(hitsItr != hitsListItr->second.end()) {
424 values[ixy] = hitsItr->second;
428 if(values[ixy] < minmax[0]) minmax[0] = values[ixy];
429 if(values[ixy] > minmax[1]) minmax[1] = values[ixy];
436 if(minmax[0] < 0) lower = minmax[0];
437 G4double scale = (minmax[1]-lower)/25000.;
451 std::vector<G4float *> tracks;
452 unsigned char colors[3];
454 tracks.push_back(trk);
456 G4ThreeVector orig(0.,0.,0), xa(2000.,0.,0.), ya(0.,2000.,0.), za(0.,0.,2000.);
465 for(
G4int i = 0; i < 3; i++) trk[i] = orig[i];
466 for(
G4int i = 0; i < 3; i++) trk[i+3] = xa[i];
467 colors[0] = 255; colors[1] = 0; colors[2] = 0;
468 kgMocrenIO->
addTrack(tracks, colors);
470 for(
G4int i = 0; i < 3; i++) trk[i+3] = ya[i];
471 colors[0] = 0; colors[1] = 255; colors[2] = 0;
472 kgMocrenIO->
addTrack(tracks, colors);
474 for(
G4int i = 0; i < 3; i++) trk[i+3] = za[i];
475 colors[0] = 0; colors[1] = 0; colors[2] = 255;
476 kgMocrenIO->
addTrack(tracks, colors);
484 std::vector<G4float> transformObjects;
485 for(
G4int i = 0; i < 3; i++) {
487 transformObjects.push_back((kVolumeSize[i]/2. - kVoxelDimension[i]/2.));
511 G4cout <<
"***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" <<
G4endl;
516 kFlagInModeling = true ;
525 std::vector<G4Scene::Model>::iterator itr = vmodel.begin();
526 for(; itr != vmodel.end(); itr++) {
527 G4cout <<
" IIIIII model name: " << itr->fpModel->GetGlobalTag() <<
G4endl;
543 static G4bool warned =
false;
547 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)",
549 "2D polylines not implemented. Ignored.");
557 static G4int numTrajectories = 0;
561 if(kbModelingTrajectory) {
566 (
"G4VSceneHandler::AddCompound(const G4Polyline&)",
576 std::vector<G4float *> trajectory;
577 if(polyline.size() < 2)
return;
578 G4Polyline::const_iterator preitr = polyline.begin();
579 G4Polyline::const_iterator postitr = preitr; postitr++;
580 for(; postitr != polyline.end(); preitr++, postitr++) {
584 G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z());
588 stepPts[0] = prePts.
x();
589 stepPts[1] = prePts.y();
590 stepPts[2] = prePts.z();
591 stepPts[3] = postPts.x();
592 stepPts[4] = postPts.y();
593 stepPts[5] = postPts.z();
594 trajectory.push_back(stepPts);
598 << stepPts[0] <<
", "
599 << stepPts[1] <<
", "
600 << stepPts[2] <<
") - ("
601 << stepPts[3] <<
", "
602 << stepPts[4] <<
", "
603 << stepPts[5] <<
")" <<
G4endl;
609 unsigned char trkcolor[3];
610 trkcolor[0] = (
unsigned char)(color.
GetRed()*255);
611 trkcolor[1] = (
unsigned char)(color.
GetGreen()*255);
612 trkcolor[2] = (
unsigned char)(color.
GetBlue()*255);
620 kgMocrenIO->
addTrack(trajectory, trkcolor);
632 static G4bool warned =
false;
636 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)",
638 "2D text not implemented. Ignored.");
663 static G4bool warned =
false;
667 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)",
669 "2D circles not implemented. Ignored.");
692 static G4bool warned =
false;
696 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)",
698 "2D squares not implemented. Ignored.");
718 G4cout <<
"***** AddPrimitive( G4Polyhedron )" <<
G4endl;
724 static G4bool warned =
false;
728 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)",
730 "2D polyhedra not implemented. Ignored.");
740 G4bool notLastEdge =
true;
751 }
while (notLastEdge);
762 "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" <<
G4endl;
773 "\nG4Polyhedron facet with " << i <<
" edges" <<
G4endl;
792 G4cout <<
"***** GFEndModeling (started) " ;
793 G4cout <<
"(/EndModeling, /DrawAll, /CloseDevice)" <<
G4endl;
800 kFlagInModeling = false ;
839 G4cout <<
"G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
843 if( !IsVisible() ) { return ; }
859 for(
G4int i = 0; i < 12; i++) {
862 G4cout <<
" (" << v1.
x() <<
", "
867 << v2.
z() <<
") [" << next <<
"]"
878 if(kFlagParameterization != 2) {
883 if(pScBox != NULL) bMesh =
true;
884 if(bMesh) kFlagParameterization = 2;
886 << volName <<
" - " << bMesh <<
G4endl;
891 if (!pv_model) { return ; }
894 if (!pPVModel) { return ; }
906 G4cout <<
" density : " << dens <<
" [g/cm3]" <<
G4endl;
925 G4cout <<
"kVolumeTrans3D: " << trans1 << G4endl << rot1 <<
G4endl;
927 kVolumeTrans3D = kVolumeTrans3D*trot;
936 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
939 G4int dirAxis[3] = {-1,-1,-1};
940 G4int nDaughters[3] = {0,0,0};
944 nDaughters[0] = nReplicas;
946 case kXAxis: dirAxis[0] = 0;
break;
947 case kYAxis: dirAxis[0] = 1;
break;
948 case kZAxis: dirAxis[0] = 2;
break;
950 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
953 kNestedVolumeNames.push_back(pv[0]->
GetName());
956 <<
" # : " << nDaughters[0] <<
G4endl;
960 if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
961 G4cout <<
"# of daughters : "
972 if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) {
973 kFlagParameterization = 1;
978 if(kFlagParameterization == 0) {
983 nDaughters[1] = nReplicas;
985 case kXAxis: dirAxis[1] = 0;
break;
986 case kYAxis: dirAxis[1] = 1;
break;
987 case kZAxis: dirAxis[1] = 2;
break;
989 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
992 kNestedVolumeNames.push_back(pv[1]->
GetName());
995 <<
" # : " << nDaughters[1]<<
G4endl;
1001 kNestedVolumeNames.push_back(pv[2]->
GetName());
1004 <<
" # : " << nDaughters[2] <<
G4endl;
1006 if(nDaughters[2] > 1) {
1009 if(nestPara == NULL)
1010 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1019 G4cout << trans0 <<
" - " << trans1 <<
" - " << diff <<
G4endl;
1021 if(diff.
x() != 0.) dirAxis[2] = 0;
1022 else if(diff.
y() != 0.) dirAxis[2] = 1;
1023 else if(diff.
z() != 0.) dirAxis[2] = 2;
1025 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1026 "gMocren0009",
FatalException,
"Unexpected nested parameterisation");
1031 for(
G4int i = 0; i < 3; i++) {
1032 kNestedVolumeDimension[i] = nDaughters[i];
1034 kNestedVolumeDirAxis[i] = dirAxis[i];
1042 if(nestPara != NULL) {
1043 G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.};
1044 for(
G4int n0 = 0; n0 < nDaughters[0]; n0++) {
1045 for(
G4int n1 = 0; n1 < nDaughters[1]; n1++) {
1046 for(
G4int n2 = 0; n2 < nDaughters[2]; n2++) {
1050 G4cout <<
" retrieve volume : copy # : " << n0
1051 <<
", " << n1 <<
", " << n2 <<
G4endl;
1057 G4cout <<
" density :" << dens <<
" [g/cm3]" <<
G4endl;
1064 if(n0 != 0 || n1 != 0 || n2 != 0) {
1065 for(
G4int i = 0; i < 3; i++) {
1066 if(xyz[i] != prexyz[i])
1067 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1077 idx[dirAxis[0]] = n0;
1078 idx[dirAxis[1]] = n1;
1079 idx[dirAxis[2]] = n2;
1080 Index3D i3d(idx[0],idx[1],idx[2]);
1081 kNestedModality[i3d] = dens;
1083 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1084 <<
" density: " << dens <<
G4endl;
1086 for(
G4int i = 0; i < 3; i++) prexyz[i] = xyz[i];
1095 if(!kbSetModalityVoxelSize) {
1097 static_cast<G4float>(2*xyz[1]),
1098 static_cast<G4float>(2*xyz[2])};
1100 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1101 kbSetModalityVoxelSize =
true;
1107 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1121 G4cout <<
" physical volume node id : "
1122 <<
"size: " << npvp <<
", PV name: ";
1123 for(
G4int i = 0; i < npvp; i++) {
1126 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised()
1128 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated();
1129 if(pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) {
1131 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested();
1134 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo();
1143 G4Box * pbox =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1148 G4cout <<
" mother size ["
1149 << pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1151 << pareDims[0] <<
" x "
1152 << pareDims[1] <<
" x "
1153 << pareDims[2] <<
" [mm3]"
1157 G4Box * boxP =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1162 G4cout <<
" parameterised volume? ["
1163 << pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName()
1165 << paraDims[0] <<
" x "
1166 << paraDims[1] <<
" x "
1167 << paraDims[2] <<
" [mm3] : "
1168 <<
G4int(pareDims[0]/paraDims[0]) <<
" x "
1169 <<
G4int(pareDims[1]/paraDims[1]) <<
" x "
1173 <<
" isn't a G4Box." <<
G4endl;
1179 }
else if(kFlagParameterization == 1) {
1184 if(phantomPara == NULL) {
1185 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1191 kNestedVolumeDimension[0] = phantomPara->
GetNoVoxelX();
1192 kNestedVolumeDimension[1] = phantomPara->
GetNoVoxelY();
1193 kNestedVolumeDimension[2] = phantomPara->
GetNoVoxelZ();
1194 kNestedVolumeDirAxis[0] = 0;
1195 kNestedVolumeDirAxis[1] = 1;
1196 kNestedVolumeDirAxis[2] = 2;
1199 G4int nX = kNestedVolumeDimension[0];
1200 G4int nXY = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
1202 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1203 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1204 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1206 G4int repNo = n0 + n1*nX + n2*nXY;
1212 idx[kNestedVolumeDirAxis[0]] = n0;
1213 idx[kNestedVolumeDirAxis[1]] = n1;
1214 idx[kNestedVolumeDirAxis[2]] = n2;
1215 Index3D i3d(idx[0],idx[1],idx[2]);
1216 kNestedModality[i3d] = dens;
1219 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1220 <<
" density: " << dens <<
G4endl;
1231 if(!kbSetModalityVoxelSize) {
1236 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1237 kbSetModalityVoxelSize =
true;
1245 if(!kFlagProcessedInteractiveScorer) {
1262 kNestedVolumeDimension[0] = nVoxels[2];
1263 kNestedVolumeDimension[1] = nVoxels[1];
1264 kNestedVolumeDimension[2] = nVoxels[0];
1265 kNestedVolumeDirAxis[0] = 2;
1266 kNestedVolumeDirAxis[1] = 1;
1267 kNestedVolumeDirAxis[2] = 0;
1270 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1271 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1272 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1277 idx[kNestedVolumeDirAxis[0]] = n0;
1278 idx[kNestedVolumeDirAxis[1]] = n1;
1279 idx[kNestedVolumeDirAxis[2]] = n2;
1280 Index3D i3d(idx[0],idx[1],idx[2]);
1281 kNestedModality[i3d] = dens;
1289 G4cout <<
"Interactive Scorer : size - "
1290 << boxSize.
x()/
cm <<
" x "
1291 << boxSize.
y()/
cm <<
" x "
1292 << boxSize.
z()/
cm <<
" [cm3]" <<
G4endl;
1293 G4cout <<
"Interactive Scorer : # voxels - "
1294 << nVoxels[0] <<
" x "
1295 << nVoxels[1] <<
" x "
1298 kVolumeSize.
set(boxSize.
x()*2,
1303 if(!kbSetModalityVoxelSize) {
1305 static_cast<G4float>(boxSize.
y()*2/nVoxels[1]),
1306 static_cast<G4float>(boxSize.
z()*2/nVoxels[2])};
1309 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1310 kbSetModalityVoxelSize =
true;
1320 kVolumeTrans3D = kVolumeTrans3D*sbtranslate;
1328 kVolumeTrans3D = kVolumeTrans3D*sbrotate;
1340 kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ;
1345 kFlagProcessedInteractiveScorer =
true;
1358 if(kFlagParameterization == 0) {
1377 if(volName == box.
GetName()) {
1381 std::vector<G4String>::iterator itr = kNestedVolumeNames.begin();
1382 for(; itr != kNestedVolumeNames.end(); itr++) {
1388 }
else if(kFlagParameterization == 1) {
1399 if(volDSolidName == box.
GetName()) {
1403 }
else if(kFlagParameterization == 2) {
1408 if(bAddDet) AddDetector(box);
1422 if( !IsVisible() ) { return ; }
1437 for(
G4int i = 0; i < nv; i++) {
1446 if (!pv_model) { return ; }
1449 if (!pPVModel) { return ; }
1465 if( !IsVisible() ) { return ; }
1484 if( !IsVisible() ) { return ; }
1502 if( !IsVisible() ) { return ; }
1508 AddDetector(sphere);
1520 if( !IsVisible() ) { return ; }
1538 if( !IsVisible() ) { return ; }
1557 if( !IsVisible() ) { return ; }
1573 if( !IsVisible() ) { return ; }
1593 kbModelingTrajectory =
true;
1598 G4cout <<
" ::AddCompound(const G4VTrajectory&) >>>>>>>>> " <<
G4endl;
1602 (
"G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1616 for(
G4int i = 0; i < nPnt; i++) {
1624 kbModelingTrajectory =
false;
1646 std::vector<G4String> hitNames = kMessenger.
getHitNames();
1648 std::vector<G4String>::iterator itr = hitNames.begin();
1649 for(; itr != hitNames.end(); itr++)
1650 G4cout <<
" hit name : " << *itr << G4endl;
1657 G4bool bid[3] = {
false,
false,
false};
1660 std::vector<G4AttValue>::iterator itr;
1662 for(itr = attval->begin(); itr != attval->end(); itr++) {
1663 std::string stmp = itr->GetValue();
1664 std::istringstream sval(stmp.c_str());
1666 if(itr->GetName() ==
G4String(
"XID")) {
1671 if(itr->GetName() ==
G4String(
"YID")) {
1676 if(itr->GetName() ==
G4String(
"ZID")) {
1685 if(bid[0] && bid[1] && bid[2]) {
1688 G4cout <<
" Hit : index(" <<
id.x <<
", " <<
id.y <<
", "
1689 <<
id.z <<
")" <<
G4endl;
1692 for(itr = attval->begin(); itr != attval->end(); itr++) {
1693 for(
G4int i = 0; i < nhitname; i++) {
1694 if(itr->GetName() == hitNames[i]) {
1696 std::string stmp = itr->GetValue();
1697 std::istringstream sval(stmp.c_str());
1700 sval >> value >> unit;
1702 std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr;
1703 kNestedHitsListItr = kNestedHitsList.find(hitNames[i]);
1704 if(kNestedHitsListItr != kNestedHitsList.end()) {
1707 kNestedHitsListItr->second[id] =
value;
1709 std::map<Index3D, G4double> hits;
1710 hits.insert(std::map<Index3D, G4double>::value_type(
id, value));
1711 kNestedHitsList[hitNames[i]] = hits;
1716 G4cout <<
" : " << hitNames[i] <<
" -> " << value
1717 <<
" [" << unit <<
"]" <<
G4endl;
1722 G4Exception(
"G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)",
1738 G4cout <<
" ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " <<
G4endl;
1742 G4int nhitname = (
G4int)hitScorerNames.size();
1760 std::map<G4int, G4double*> * map = hits.
GetMap();
1761 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1762 for(; itr != map->end(); itr++) {
1763 GetNestedVolumeIndex(itr->first, idx);
1764 Index3D id(idx[0], idx[1], idx[2]);
1766 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1767 nestedHitsListItr = kNestedHitsList.find(scorername);
1768 if(nestedHitsListItr != kNestedHitsList.end()) {
1769 nestedHitsListItr->second[id] = *(itr->second);
1771 std::map<Index3D, G4double> hit;
1772 hit.insert(std::map<Index3D, G4double>::value_type(
id, *(itr->second)));
1773 kNestedHitsList[scorername] = hit;
1784 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1786 for(
G4int i = 0; i < nhitname; i++)
1787 if(scorername == hitScorerNames[i])
1788 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1791 << kNestedVolumeDimension[0] <<
" x "
1792 << kNestedVolumeDimension[1] <<
" x "
1793 << kNestedVolumeDimension[2] <<
G4endl;
1796 std::map<G4int, G4double*> * map = hits.
GetMap();
1797 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1798 for(; itr != map->end(); itr++) {
1799 GetNestedVolumeIndex(itr->first,
id);
1800 G4cout <<
"[" << itr->first <<
"] "
1801 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1802 << *(itr->second) <<
", ";
1810 G4cout <<
" ::AddCompound(const std::map<G4int, G4StatDouble*> &) >>>>>>>>> " <<
G4endl;
1814 G4int nhitname = (
G4int)hitScorerNames.size();
1832 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1833 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1834 for(; itr != map->end(); itr++) {
1835 GetNestedVolumeIndex(itr->first, idx);
1836 Index3D id(idx[0], idx[1], idx[2]);
1838 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1839 nestedHitsListItr = kNestedHitsList.find(scorername);
1840 if(nestedHitsListItr != kNestedHitsList.end()) {
1841 nestedHitsListItr->second[id] = itr->second->sum_wx();
1843 std::map<Index3D, G4double> hit;
1844 hit.insert(std::map<Index3D, G4double>::value_type(
id, itr->second->sum_wx()));
1845 kNestedHitsList[scorername] = hit;
1856 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1858 for(
G4int i = 0; i < nhitname; i++)
1859 if(scorername == hitScorerNames[i])
1860 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1863 << kNestedVolumeDimension[0] <<
" x "
1864 << kNestedVolumeDimension[1] <<
" x "
1865 << kNestedVolumeDimension[2] <<
G4endl;
1868 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1869 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1870 for(; itr != map->end(); itr++) {
1871 GetNestedVolumeIndex(itr->first,
id);
1872 G4cout <<
"[" << itr->first <<
"] "
1873 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1874 << itr->second->sum_wx() <<
", ";
1881 G4bool G4GMocrenFileSceneHandler::IsVisible()
1884 G4bool visibility = true ;
1912 void G4GMocrenFileSceneHandler::AddDetector(
const G4VSolid & solid) {
1917 detector.name = solid.
GetName();
1919 G4cout <<
"0 Detector name : " << detector.name <<
G4endl;
1922 if (!pv_model) { return ; }
1925 if (!pPVModel) { return ; }
1928 std::vector<G4float *> dedges;
1930 detector.polyhedron = poly;
1934 unsigned char uccolor[3] = {30, 30, 30};
1937 uccolor[0] = (
unsigned char)(color.
GetRed()*255);
1938 uccolor[1] = (
unsigned char)(color.
GetGreen()*255);
1939 uccolor[2] = (
unsigned char)(color.
GetBlue()*255);
1943 for(
G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i];
1945 kDetectors.push_back(detector);
1948 G4cout <<
"0 color: (" << (
G4int)uccolor[0] <<
", "
1949 << (
G4int)uccolor[1] << ", " << (
G4int)uccolor[2] << ")"
1958 std::vector<Detector>::iterator itr = kDetectors.begin();
1960 for(; itr != kDetectors.end(); itr++) {
1968 std::vector<G4float *> dedges;
1980 if(!(poly->
GetNextEdge(v1, v2, next))) bnext =
false;
1982 edge[0] = v1.
x()/
mm;
1983 edge[1] = v1.
y()/
mm;
1984 edge[2] = v1.
z()/
mm;
1985 edge[3] = v2.
x()/
mm;
1986 edge[4] = v2.
y()/
mm;
1987 edge[5] = v2.
z()/
mm;
1988 dedges.push_back(edge);
1993 unsigned char uccolor[3] = {itr->color[0],
1997 kgMocrenIO->
addDetector(detname, dedges, uccolor);
1998 for(
G4int i = 0; i < nedges; i++) {
1999 delete [] dedges[i];
2004 G4cout <<
" color: (" << (
G4int)uccolor[0] <<
", "
2005 << (
G4int)uccolor[1] << ", " << (
G4int)uccolor[2] << ")"
2012 if(kNestedVolumeDimension[0] == 0 ||
2013 kNestedVolumeDimension[1] == 0 ||
2014 kNestedVolumeDimension[2] == 0) {
2015 for(
G4int i = 0; i < 3; i++) _idx3d[i] = 0;
2020 if(kFlagParameterization == 0) {
2022 G4int plane = kNestedVolumeDimension[2]*kNestedVolumeDimension[1];
2023 G4int line = kNestedVolumeDimension[2];
2035 _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane;
2036 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2037 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line;
2064 G4int plane = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
2065 G4int line = kNestedVolumeDimension[0];
2066 _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane;
2067 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2068 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line;
2076 G4GMocrenFileSceneHandler::Detector::Detector()
2078 color[0] = color[1] = color[2] = 255;
2080 G4GMocrenFileSceneHandler::Detector::~Detector() {
2081 if(!polyhedron)
delete polyhedron;
2083 void G4GMocrenFileSceneHandler::Detector::clear() {
2085 if(!polyhedron)
delete polyhedron;
2086 color[0] = color[1] = color[2] = 255;
2091 G4GMocrenFileSceneHandler::Index3D::Index3D()
2092 : x(0), y(0), z(0) {
2096 G4GMocrenFileSceneHandler::Index3D::Index3D(
const Index3D & _index3D)
2097 : x(_index3D.x), y(_index3D.y), z(_index3D.z) {
2107 G4GMocrenFileSceneHandler::Index3D::Index3D(
G4int _x,
G4int _y,
G4int _z)
2108 : x(_x), y(_y), z(_z) {
2112 if(z < static_cast<Index3D>(_right).z) {
2114 }
else if(z == _right.z) {
2115 if(y < static_cast<Index3D>(_right).y)
return true;
2116 else if(y == _right.y)
2117 if(x < static_cast<Index3D>(_right).x)
return true;
2122 if(z == _right.z && y == _right.y && x == _right.x)
return true;
void set(double x, double y, double z)
virtual G4Material * ComputeMaterial(G4VPhysicalVolume *currentVol, const G4int repNo, const G4VTouchable *parentTouch=0)=0
void AddCompound(const G4VTrajectory &traj)
G4VModel * GetModel() const
void GetNumberOfSegments(G4int nSegment[3])
bool operator==(const HepRotation &r, const HepLorentzRotation <)
short convertDensityToHU(float &_dens)
G4double GetXHalfLength() const
virtual ~G4GMocrenFileSceneHandler()
G4RotationMatrix GetRotationMatrix() const
void setDoseDistUnit(std::string &_unit, int _num=0)
virtual void AddSolid(const G4Box &)
const std::vector< Model > & GetEndOfEventModelList() const
static constexpr double mm
virtual G4bool IsNested() const
virtual void BeginModeling()
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
virtual G4bool IsReplicated() const =0
void addTrack(float *_tracks)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const
const G4String & GetName() const
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
void setDoseDistMinMax(short _minmax[2], int _num=0)
G4Material * GetCurrentMaterial() const
bool operator<(const HepRotation &r, const HepLorentzRotation <)
G4double GetDensity() const
virtual G4String getVolumeName()
G4VSolid * GetSolid() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void setModalityImageSize(int _size[3])
const G4String & GetName() const
G4Transform3D fObjectTransformation
void AddSolid(const G4Box &box)
const char DEFAULT_GDD_FILE_NAME[]
G4VScoringMesh * FindMesh(G4VHitsCollection *map)
const G4VisAttributes * GetVisAttributes() const
static constexpr double rad
static constexpr double g
void ClearTransientStore()
virtual G4GeometryType GetEntityType() const =0
const std::vector< G4PhysicalVolumeNodeID > & GetDrawnPVPath() const
HepPolyhedron & Transform(const G4Transform3D &t)
G4ThreeVector GetSize() const
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
G4int GetCurrentDepth() const
G4double GetZHalfLength() const
G4Polyhedron * CreatePolyhedron() const
size_t GetNoVoxelZ() const
HepRotation inverse() const
void translateDetector(std::vector< float > &_translate)
virtual void DrawTrajectory() const
void setDoseDist(double *_image, int _num=0)
virtual G4bool getDrawVolumeGrid()
virtual int GetPointEntries() const =0
bool storeData(char *_filename)
G4GLOB_DLL std::ostream G4cout
virtual std::vector< G4String > getHitNames()
virtual G4String GetParticleName() const =0
const XML_Char int const XML_Char * value
const G4String & GetName() const
G4Polyhedron * CreatePolyhedron() const
void BeginSavingGdd(void)
G4double GetGreen() const
G4double GetDensity(G4int &_ct) const
G4ThreeVector GetTranslation() const
static constexpr double cm
virtual G4VPVParameterisation * GetParameterisation() const =0
const char GDD_FILE_HEADER[]
virtual void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const =0
const G4VisAttributes * GetVisAttributes() const
virtual void EndModeling()
virtual void EndPrimitives()
G4double GetYHalfLength() const
void setModalityImageMinMax(short _minmax[2])
virtual G4Polyhedron * CreatePolyhedron() const
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
Hep3Vector & transform(const HepRotation &)
G4double GetVoxelHalfY() const
virtual G4double GetCharge() const =0
void setModalityImage(short *_image)
static constexpr double cm3
G4int GetNoDaughters() const
void setVoxelSpacing(float _spacing[3])
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4VPhysicalVolume * GetTopPhysicalVolume() const
virtual G4bool IsParameterised() const =0
G4int GetNoVertices() const
const G4int MAX_NUM_TRAJECTORIES
virtual std::vector< G4String > getHitScorerNames()
const int FR_MAX_FILE_NUM
const G4Color & GetColor() const
size_t GetNoVoxelY() const
virtual const G4ThreeVector GetPosition() const =0
const G4VisAttributes * fpVisAttribs
G4Scene * GetScene() const
virtual void AddCompound(const G4VTrajectory &)
G4LogicalVolume * GetLogicalVolume() const
const G4VTrajectory * GetCurrentTrajectory() const
G4double GetVoxelHalfX() const
virtual G4int GetCopyNo() const =0
virtual G4int GetTrackID() const =0
void translateTracks(std::vector< float > &_translateo)
virtual G4int GetMultiplicity() const
static Verbosity GetVerbosity()
G4bool GetNextVertexIndex(G4int &index, G4int &edgeFlag) const
void AddPrimitive(const G4Polyline &line)
virtual std::vector< G4AttValue > * CreateAttValues() const
std::map< G4int, T * > * GetMap() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
G4double GetVoxelHalfZ() const
static constexpr double pi
size_t GetNoVoxelX() const
static G4ScoringManager * GetScoringManager()
G4ThreeVector GetObjectTranslation() const
virtual G4ThreeVector GetInitialMomentum() const =0
void setDoseDistScale(double &_scale, int _num=0)
void addDetector(std::string &_name, std::vector< float * > &_det, unsigned char _color[3])
virtual void EndPrimitives()
const G4bool GFDEBUG_DIGI
void setDoseDistSize(int _size[3], int _num=0)
G4LogicalVolume * GetCurrentLV() const
G4VPhysicalVolume * GetCurrentPV() const
G4int GetNoFacets() const
void setDoseDistName(std::string _name, int _num=0)
G4Point3D GetVertex(G4int index) const
G4GMocrenFileSceneHandler(G4GMocrenFile &system, G4GMocrenMessenger &messenger, const G4String &name="")
void setModalityImageDensityMap(std::vector< float > &_map)