113 G4int G4GMocrenFileSceneHandler::kSceneIdCount = 0;
126 kMessenger(messenger),
128 kbSetModalityVoxelSize(false),
129 kbModelingTrajectory(false),
131 kFlagInModeling(false),
132 kFlagSaving_g4_gdd(false),
133 kFlagParameterization(0),
134 kFlagProcessedInteractiveScorer(false) {
137 if(std::getenv(
"G4GMocrenFile_DEST_DIR") == NULL) {
138 kGddDestDir[0] =
'\0';
144 const char * env = std::getenv(
"G4GMocrenFile_DEST_DIR");
145 int len = std::strlen(env);
147 G4Exception(
"G4GMocrenFileSceneHandler::G4GMocrenFileSceneHandler(*)",
149 "Invalid length of string set in G4GMocrenFile_DEST_DIR");
151 std::strncpy(kGddDestDir, env, len+1);
158 if ( std::getenv(
"G4GMocrenFile_MAX_FILE_NUM" ) != NULL ) {
159 char * pcFileNum = getenv(
"G4GMocrenFile_MAX_FILE_NUM");
161 std::strncpy(c10FileNum, pcFileNum, 10);
162 kMaxFileNum = std::atoi(c10FileNum);
167 if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; }
169 InitializeParameters();
185 if(kgMocrenIO != NULL)
delete kgMocrenIO;
190 void G4GMocrenFileSceneHandler::InitializeParameters() {
192 kbSetModalityVoxelSize =
false;
194 for(
G4int i = 0; i < 3; i++) {
195 kModalitySize[i] = 0;
196 kNestedVolumeDimension[i] = 0;
197 kNestedVolumeDirAxis[i] = -1;
208 const G4int MAX_FILE_INDEX = kMaxFileNum - 1 ;
211 std::strncpy(kGddFileName, kGddDestDir, std::strlen(kGddDestDir)+1);
217 static G4int currentNumber = 0;
218 for(
G4int i = currentNumber ; i < kMaxFileNum ; i++) {
221 if( i == MAX_FILE_INDEX )
224 G4cout <<
"===========================================" <<
G4endl;
225 G4cout <<
"WARNING MESSAGE from GMocrenFile driver: " <<
G4endl;
226 G4cout <<
" This file name is the final one in the " <<
G4endl;
227 G4cout <<
" automatic updation of the output file name." <<
G4endl;
228 G4cout <<
" You may overwrite existing files, i.e. " <<
G4endl;
230 G4cout <<
"===========================================" <<
G4endl;
235 std::ostringstream filename;
238 << std::setw(2) << std::setfill(
'0') << i <<
".wrl";
239 strncpy(kGddFileName,filename.str().c_str(),
sizeof(kGddFileName));
242 std::ifstream fin(kGddFileName);
244 G4cout <<
"FILEOPEN: " << i <<
" : " << kGddFileName << fin.fail()
258 G4cout <<
"======================================================================" <<
G4endl;
260 G4cout <<
"Destination directory (current dir if NULL): " << kGddDestDir <<
G4endl;
261 G4cout <<
"Maximum number of files in the destination directory: " << kMaxFileNum <<
G4endl;
263 G4cout <<
" * The maximum number is customizable as: " <<
G4endl;
264 G4cout <<
" % setenv G4GMocrenFile_MAX_FILE_NUM number " <<
G4endl;
265 G4cout <<
" * The destination directory is customizable as:" <<
G4endl;
266 G4cout <<
" % setenv G4GMocrenFile_DEST_DIR dir_name/ " <<
G4endl;
267 G4cout <<
" ** Do not forget \"/\" at the end of the dir_name, e.g. \"./tmp/\"." <<
G4endl;
271 G4cout <<
"======================================================================" <<
G4endl;
285 G4cout <<
"***** (started) " ;
290 kFlagSaving_g4_gdd =
true;
298 std::vector<G4float> map;
300 for(
G4int i = minmax[0]; i <= minmax[1]; i++) {
336 std::vector<Detector>::iterator itr = kDetectors.begin();
337 for(; itr != kDetectors.end(); itr++) {
342 kNestedHitsList.clear();
343 kNestedVolumeNames.clear();
355 G4cout <<
"***** (started) (close "
356 << kGddFileName <<
")" <<
G4endl;
358 if(kGddDest) kGddDest.close();
359 kFlagSaving_g4_gdd =
false;
361 std::map<Index3D, G4float>::iterator itr = kNestedModality.begin();
362 G4int xmax=0, ymax=0, zmax=0;
363 for(; itr != kNestedModality.end(); itr++) {
364 if(itr->first.x > xmax) xmax = itr->first.x;
365 if(itr->first.y > ymax) ymax = itr->first.y;
366 if(itr->first.z > zmax) zmax = itr->first.z;
369 kModalitySize[0] = xmax+1;
370 kModalitySize[1] = ymax+1;
371 kModalitySize[2] = zmax+1;
373 if(
GFDEBUG)
G4cout <<
"gMocren-file driver : modality size : "
374 << kModalitySize[0] <<
" x "
375 << kModalitySize[1] <<
" x "
376 << kModalitySize[2] <<
G4endl;
378 G4int nxy = kModalitySize[0]*kModalitySize[1];
380 for(
G4int z = 0;
z < kModalitySize[2];
z++) {
381 short * modality =
new short[nxy];
382 for(
G4int y = 0; y < kModalitySize[1]; y++) {
383 for(
G4int x = 0;
x < kModalitySize[0];
x++) {
387 G4int ixy =
x + y*kModalitySize[0];
389 itr = kNestedModality.find(idx);
390 if(itr != kNestedModality.end()) {
394 modality[ixy] = -1024;
403 size_t nhits = kNestedHitsList.size();
406 std::map<Index3D, G4double>::iterator hitsItr;
407 std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr = kNestedHitsList.begin();
409 for(
G4int n = 0; hitsListItr != kNestedHitsList.end(); hitsListItr++,
n++) {
416 for(
G4int z = 0 ;
z < kModalitySize[2];
z++) {
418 for(
G4int y = 0; y < kModalitySize[1]; y++) {
419 for(
G4int x = 0;
x < kModalitySize[0];
x++) {
421 G4int ixy =
x + y*kModalitySize[0];
423 hitsItr = hitsListItr->second.find(idx);
424 if(hitsItr != hitsListItr->second.end()) {
426 values[ixy] = hitsItr->second;
430 if(values[ixy] < minmax[0]) minmax[0] = values[ixy];
431 if(values[ixy] > minmax[1]) minmax[1] = values[ixy];
438 if(minmax[0] < 0) lower = minmax[0];
439 G4double scale = (minmax[1]-lower)/25000.;
453 std::vector<G4float *> tracks;
454 unsigned char colors[3];
456 tracks.push_back(trk);
458 G4ThreeVector orig(0.,0.,0), xa(2000.,0.,0.), ya(0.,2000.,0.), za(0.,0.,2000.);
467 for(
G4int i = 0; i < 3; i++) trk[i] = orig[i];
468 for(
G4int i = 0; i < 3; i++) trk[i+3] = xa[i];
469 colors[0] = 255; colors[1] = 0; colors[2] = 0;
470 kgMocrenIO->
addTrack(tracks, colors);
472 for(
G4int i = 0; i < 3; i++) trk[i+3] = ya[i];
473 colors[0] = 0; colors[1] = 255; colors[2] = 0;
474 kgMocrenIO->
addTrack(tracks, colors);
476 for(
G4int i = 0; i < 3; i++) trk[i+3] = za[i];
477 colors[0] = 0; colors[1] = 0; colors[2] = 255;
478 kgMocrenIO->
addTrack(tracks, colors);
486 std::vector<G4float> transformObjects;
487 for(
G4int i = 0; i < 3; i++) {
489 transformObjects.push_back((kVolumeSize[i]/2. - kVoxelDimension[i]/2.));
513 G4cout <<
"***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" <<
G4endl;
518 kFlagInModeling = true ;
527 std::vector<G4Scene::Model>::iterator itr = vmodel.begin();
528 for(; itr != vmodel.end(); itr++) {
529 G4cout <<
" IIIIII model name: " << itr->fpModel->GetGlobalTag() <<
G4endl;
545 static G4bool warned =
false;
549 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)",
551 "2D polylines not implemented. Ignored.");
559 static G4int numTrajectories = 0;
563 if(kbModelingTrajectory) {
568 (
"G4VSceneHandler::AddCompound(const G4Polyline&)",
578 std::vector<G4float *> trajectory;
579 if(polyline.size() < 2)
return;
580 G4Polyline::const_iterator preitr = polyline.begin();
581 G4Polyline::const_iterator postitr = preitr; postitr++;
582 for(; postitr != polyline.end(); preitr++, postitr++) {
586 G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z());
590 stepPts[0] = prePts.
x();
591 stepPts[1] = prePts.y();
592 stepPts[2] = prePts.z();
593 stepPts[3] = postPts.x();
594 stepPts[4] = postPts.y();
595 stepPts[5] = postPts.z();
596 trajectory.push_back(stepPts);
600 << stepPts[0] <<
", "
601 << stepPts[1] <<
", "
602 << stepPts[2] <<
") - ("
603 << stepPts[3] <<
", "
604 << stepPts[4] <<
", "
605 << stepPts[5] <<
")" <<
G4endl;
611 unsigned char trkcolor[3];
612 trkcolor[0] = (
unsigned char)(color.
GetRed()*255);
613 trkcolor[1] = (
unsigned char)(color.
GetGreen()*255);
614 trkcolor[2] = (
unsigned char)(color.
GetBlue()*255);
622 kgMocrenIO->
addTrack(trajectory, trkcolor);
634 static G4bool warned =
false;
638 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)",
640 "2D text not implemented. Ignored.");
665 static G4bool warned =
false;
669 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)",
671 "2D circles not implemented. Ignored.");
694 static G4bool warned =
false;
698 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)",
700 "2D squares not implemented. Ignored.");
720 G4cout <<
"***** AddPrimitive( G4Polyhedron )" <<
G4endl;
726 static G4bool warned =
false;
730 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)",
732 "2D polyhedra not implemented. Ignored.");
742 G4bool notLastEdge =
true;
753 }
while (notLastEdge);
764 "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" <<
G4endl;
775 "\nG4Polyhedron facet with " << i <<
" edges" <<
G4endl;
794 G4cout <<
"***** GFEndModeling (started) " ;
795 G4cout <<
"(/EndModeling, /DrawAll, /CloseDevice)" <<
G4endl;
802 kFlagInModeling = false ;
841 G4cout <<
"G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
845 if( !IsVisible() ) { return ; }
861 for(
G4int i = 0; i < 12; i++) {
864 G4cout <<
" (" << v1.
x() <<
", "
869 << v2.
z() <<
") [" << next <<
"]"
880 if(kFlagParameterization != 2) {
885 if(pScBox != NULL) bMesh =
true;
886 if(bMesh) kFlagParameterization = 2;
888 << volName <<
" - " << bMesh <<
G4endl;
893 if (!pv_model) { return ; }
896 if (!pPVModel) { return ; }
908 G4cout <<
" density : " << dens <<
" [g/cm3]" <<
G4endl;
927 G4cout <<
"kVolumeTrans3D: " << trans1 << G4endl << rot1 <<
G4endl;
929 kVolumeTrans3D = kVolumeTrans3D*trot;
938 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
941 G4int dirAxis[3] = {-1,-1,-1};
942 G4int nDaughters[3] = {0,0,0};
946 nDaughters[0] = nReplicas;
948 case kXAxis: dirAxis[0] = 0;
break;
949 case kYAxis: dirAxis[0] = 1;
break;
950 case kZAxis: dirAxis[0] = 2;
break;
952 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
955 kNestedVolumeNames.push_back(pv[0]->
GetName());
958 <<
" # : " << nDaughters[0] <<
G4endl;
962 if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
963 G4cout <<
"# of daughters : "
974 if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) {
975 kFlagParameterization = 1;
980 if(kFlagParameterization == 0) {
985 nDaughters[1] = nReplicas;
987 case kXAxis: dirAxis[1] = 0;
break;
988 case kYAxis: dirAxis[1] = 1;
break;
989 case kZAxis: dirAxis[1] = 2;
break;
991 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
994 kNestedVolumeNames.push_back(pv[1]->
GetName());
997 <<
" # : " << nDaughters[1]<<
G4endl;
1003 kNestedVolumeNames.push_back(pv[2]->
GetName());
1006 <<
" # : " << nDaughters[2] <<
G4endl;
1008 if(nDaughters[2] > 1) {
1011 if(nestPara == NULL)
1012 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1021 G4cout << trans0 <<
" - " << trans1 <<
" - " << diff <<
G4endl;
1023 if(diff.
x() != 0.) dirAxis[2] = 0;
1024 else if(diff.
y() != 0.) dirAxis[2] = 1;
1025 else if(diff.
z() != 0.) dirAxis[2] = 2;
1027 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1028 "gMocren0009",
FatalException,
"Unexpected nested parameterisation");
1033 for(
G4int i = 0; i < 3; i++) {
1034 kNestedVolumeDimension[i] = nDaughters[i];
1036 kNestedVolumeDirAxis[i] = dirAxis[i];
1044 if(nestPara != NULL) {
1045 G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.};
1046 for(
G4int n0 = 0; n0 < nDaughters[0]; n0++) {
1047 for(
G4int n1 = 0; n1 < nDaughters[1]; n1++) {
1048 for(
G4int n2 = 0; n2 < nDaughters[2]; n2++) {
1052 G4cout <<
" retrieve volume : copy # : " << n0
1053 <<
", " << n1 <<
", " << n2 <<
G4endl;
1059 G4cout <<
" density :" << dens <<
" [g/cm3]" <<
G4endl;
1066 if(n0 != 0 || n1 != 0 || n2 != 0) {
1067 for(
G4int i = 0; i < 3; i++) {
1068 if(xyz[i] != prexyz[i])
1069 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1079 idx[dirAxis[0]] = n0;
1080 idx[dirAxis[1]] = n1;
1081 idx[dirAxis[2]] = n2;
1082 Index3D i3d(idx[0],idx[1],idx[2]);
1083 kNestedModality[i3d] = dens;
1085 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1086 <<
" density: " << dens <<
G4endl;
1088 for(
G4int i = 0; i < 3; i++) prexyz[i] = xyz[i];
1097 if(!kbSetModalityVoxelSize) {
1099 static_cast<G4float>(2*xyz[1]),
1100 static_cast<G4float>(2*xyz[2])};
1102 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1103 kbSetModalityVoxelSize =
true;
1109 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1123 G4cout <<
" physical volume node id : "
1124 <<
"size: " << npvp <<
", PV name: ";
1125 for(
G4int i = 0; i < npvp; i++) {
1128 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised()
1130 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated();
1131 if(pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) {
1133 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested();
1136 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo();
1145 G4Box * pbox =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1150 G4cout <<
" mother size ["
1151 << pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1153 << pareDims[0] <<
" x "
1154 << pareDims[1] <<
" x "
1155 << pareDims[2] <<
" [mm3]"
1159 G4Box * boxP =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1164 G4cout <<
" parameterised volume? ["
1165 << pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName()
1167 << paraDims[0] <<
" x "
1168 << paraDims[1] <<
" x "
1169 << paraDims[2] <<
" [mm3] : "
1170 <<
G4int(pareDims[0]/paraDims[0]) <<
" x "
1171 <<
G4int(pareDims[1]/paraDims[1]) <<
" x "
1175 <<
" isn't a G4Box." <<
G4endl;
1181 }
else if(kFlagParameterization == 1) {
1186 if(phantomPara == NULL) {
1187 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1193 kNestedVolumeDimension[0] = phantomPara->
GetNoVoxelX();
1194 kNestedVolumeDimension[1] = phantomPara->
GetNoVoxelY();
1195 kNestedVolumeDimension[2] = phantomPara->
GetNoVoxelZ();
1196 kNestedVolumeDirAxis[0] = 0;
1197 kNestedVolumeDirAxis[1] = 1;
1198 kNestedVolumeDirAxis[2] = 2;
1201 G4int nX = kNestedVolumeDimension[0];
1202 G4int nXY = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
1204 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1205 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1206 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1208 G4int repNo = n0 + n1*nX + n2*nXY;
1214 idx[kNestedVolumeDirAxis[0]] = n0;
1215 idx[kNestedVolumeDirAxis[1]] = n1;
1216 idx[kNestedVolumeDirAxis[2]] = n2;
1217 Index3D i3d(idx[0],idx[1],idx[2]);
1218 kNestedModality[i3d] = dens;
1221 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1222 <<
" density: " << dens <<
G4endl;
1233 if(!kbSetModalityVoxelSize) {
1238 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1239 kbSetModalityVoxelSize =
true;
1247 if(!kFlagProcessedInteractiveScorer) {
1264 kNestedVolumeDimension[0] = nVoxels[2];
1265 kNestedVolumeDimension[1] = nVoxels[1];
1266 kNestedVolumeDimension[2] = nVoxels[0];
1267 kNestedVolumeDirAxis[0] = 2;
1268 kNestedVolumeDirAxis[1] = 1;
1269 kNestedVolumeDirAxis[2] = 0;
1272 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1273 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1274 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1279 idx[kNestedVolumeDirAxis[0]] = n0;
1280 idx[kNestedVolumeDirAxis[1]] = n1;
1281 idx[kNestedVolumeDirAxis[2]] = n2;
1282 Index3D i3d(idx[0],idx[1],idx[2]);
1283 kNestedModality[i3d] = dens;
1291 G4cout <<
"Interactive Scorer : size - "
1292 << boxSize.
x()/
cm <<
" x "
1293 << boxSize.
y()/
cm <<
" x "
1294 << boxSize.
z()/
cm <<
" [cm3]" <<
G4endl;
1295 G4cout <<
"Interactive Scorer : # voxels - "
1296 << nVoxels[0] <<
" x "
1297 << nVoxels[1] <<
" x "
1300 kVolumeSize.
set(boxSize.
x()*2,
1305 if(!kbSetModalityVoxelSize) {
1307 static_cast<G4float>(boxSize.
y()*2/nVoxels[1]),
1308 static_cast<G4float>(boxSize.
z()*2/nVoxels[2])};
1311 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1312 kbSetModalityVoxelSize =
true;
1322 kVolumeTrans3D = kVolumeTrans3D*sbtranslate;
1330 kVolumeTrans3D = kVolumeTrans3D*sbrotate;
1342 kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ;
1347 kFlagProcessedInteractiveScorer =
true;
1360 if(kFlagParameterization == 0) {
1379 if(volName == box.
GetName()) {
1383 std::vector<G4String>::iterator itr = kNestedVolumeNames.begin();
1384 for(; itr != kNestedVolumeNames.end(); itr++) {
1390 }
else if(kFlagParameterization == 1) {
1401 if(volDSolidName == box.
GetName()) {
1405 }
else if(kFlagParameterization == 2) {
1410 if(bAddDet) AddDetector(box);
1424 if( !IsVisible() ) { return ; }
1439 for(
G4int i = 0; i < nv; i++) {
1448 if (!pv_model) { return ; }
1451 if (!pPVModel) { return ; }
1467 if( !IsVisible() ) { return ; }
1486 if( !IsVisible() ) { return ; }
1504 if( !IsVisible() ) { return ; }
1510 AddDetector(sphere);
1522 if( !IsVisible() ) { return ; }
1540 if( !IsVisible() ) { return ; }
1559 if( !IsVisible() ) { return ; }
1575 if( !IsVisible() ) { return ; }
1595 kbModelingTrajectory =
true;
1600 G4cout <<
" ::AddCompound(const G4VTrajectory&) >>>>>>>>> " <<
G4endl;
1604 (
"G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1618 for(
G4int i = 0; i < nPnt; i++) {
1626 kbModelingTrajectory =
false;
1648 std::vector<G4String> hitNames = kMessenger.
getHitNames();
1650 std::vector<G4String>::iterator itr = hitNames.begin();
1651 for(; itr != hitNames.end(); itr++)
1652 G4cout <<
" hit name : " << *itr << G4endl;
1659 G4bool bid[3] = {
false,
false,
false};
1662 std::vector<G4AttValue>::iterator itr;
1664 for(itr = attval->begin(); itr != attval->end(); itr++) {
1665 std::string stmp = itr->GetValue();
1666 std::istringstream sval(stmp.c_str());
1668 if(itr->GetName() ==
G4String(
"XID")) {
1673 if(itr->GetName() ==
G4String(
"YID")) {
1678 if(itr->GetName() ==
G4String(
"ZID")) {
1687 if(bid[0] && bid[1] && bid[2]) {
1690 G4cout <<
" Hit : index(" <<
id.x <<
", " <<
id.y <<
", "
1691 <<
id.z <<
")" <<
G4endl;
1694 for(itr = attval->begin(); itr != attval->end(); itr++) {
1695 for(
G4int i = 0; i < nhitname; i++) {
1696 if(itr->GetName() == hitNames[i]) {
1698 std::string stmp = itr->GetValue();
1699 std::istringstream sval(stmp.c_str());
1702 sval >> value >> unit;
1704 std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr;
1705 kNestedHitsListItr = kNestedHitsList.find(hitNames[i]);
1706 if(kNestedHitsListItr != kNestedHitsList.end()) {
1709 kNestedHitsListItr->second[id] =
value;
1711 std::map<Index3D, G4double> hits;
1712 hits.insert(std::map<Index3D, G4double>::value_type(
id, value));
1713 kNestedHitsList[hitNames[i]] = hits;
1718 G4cout <<
" : " << hitNames[i] <<
" -> " << value
1719 <<
" [" << unit <<
"]" <<
G4endl;
1724 G4Exception(
"G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)",
1740 G4cout <<
" ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " <<
G4endl;
1744 G4int nhitname = (
G4int)hitScorerNames.size();
1762 std::map<G4int, G4double*> * map = hits.
GetMap();
1763 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1764 for(; itr != map->end(); itr++) {
1765 GetNestedVolumeIndex(itr->first, idx);
1766 Index3D id(idx[0], idx[1], idx[2]);
1768 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1769 nestedHitsListItr = kNestedHitsList.find(scorername);
1770 if(nestedHitsListItr != kNestedHitsList.end()) {
1771 nestedHitsListItr->second[id] = *(itr->second);
1773 std::map<Index3D, G4double> hit;
1774 hit.insert(std::map<Index3D, G4double>::value_type(
id, *(itr->second)));
1775 kNestedHitsList[scorername] = hit;
1786 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1788 for(
G4int i = 0; i < nhitname; i++)
1789 if(scorername == hitScorerNames[i])
1790 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1793 << kNestedVolumeDimension[0] <<
" x "
1794 << kNestedVolumeDimension[1] <<
" x "
1795 << kNestedVolumeDimension[2] <<
G4endl;
1798 std::map<G4int, G4double*> * map = hits.
GetMap();
1799 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1800 for(; itr != map->end(); itr++) {
1801 GetNestedVolumeIndex(itr->first,
id);
1802 G4cout <<
"[" << itr->first <<
"] "
1803 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1804 << *(itr->second) <<
", ";
1812 G4cout <<
" ::AddCompound(const std::map<G4int, G4StatDouble*> &) >>>>>>>>> " <<
G4endl;
1816 G4int nhitname = (
G4int)hitScorerNames.size();
1834 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1835 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1836 for(; itr != map->end(); itr++) {
1837 GetNestedVolumeIndex(itr->first, idx);
1838 Index3D id(idx[0], idx[1], idx[2]);
1840 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1841 nestedHitsListItr = kNestedHitsList.find(scorername);
1842 if(nestedHitsListItr != kNestedHitsList.end()) {
1843 nestedHitsListItr->second[id] = itr->second->sum_wx();
1845 std::map<Index3D, G4double> hit;
1846 hit.insert(std::map<Index3D, G4double>::value_type(
id, itr->second->sum_wx()));
1847 kNestedHitsList[scorername] = hit;
1858 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1860 for(
G4int i = 0; i < nhitname; i++)
1861 if(scorername == hitScorerNames[i])
1862 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1865 << kNestedVolumeDimension[0] <<
" x "
1866 << kNestedVolumeDimension[1] <<
" x "
1867 << kNestedVolumeDimension[2] <<
G4endl;
1870 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1871 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1872 for(; itr != map->end(); itr++) {
1873 GetNestedVolumeIndex(itr->first,
id);
1874 G4cout <<
"[" << itr->first <<
"] "
1875 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1876 << itr->second->sum_wx() <<
", ";
1883 G4bool G4GMocrenFileSceneHandler::IsVisible()
1886 G4bool visibility = true ;
1914 void G4GMocrenFileSceneHandler::AddDetector(
const G4VSolid & solid) {
1919 detector.name = solid.
GetName();
1921 G4cout <<
"0 Detector name : " << detector.name <<
G4endl;
1924 if (!pv_model) { return ; }
1927 if (!pPVModel) { return ; }
1930 std::vector<G4float *> dedges;
1932 detector.polyhedron = poly;
1936 unsigned char uccolor[3] = {30, 30, 30};
1939 uccolor[0] = (
unsigned char)(color.
GetRed()*255);
1940 uccolor[1] = (
unsigned char)(color.
GetGreen()*255);
1941 uccolor[2] = (
unsigned char)(color.
GetBlue()*255);
1945 for(
G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i];
1947 kDetectors.push_back(detector);
1950 G4cout <<
"0 color: (" << (
G4int)uccolor[0] <<
", "
1951 << (
G4int)uccolor[1] << ", " << (
G4int)uccolor[2] << ")"
1960 std::vector<Detector>::iterator itr = kDetectors.begin();
1962 for(; itr != kDetectors.end(); itr++) {
1970 std::vector<G4float *> dedges;
1982 if(!(poly->
GetNextEdge(v1, v2, next))) bnext =
false;
1984 edge[0] = v1.
x()/
mm;
1985 edge[1] = v1.
y()/
mm;
1986 edge[2] = v1.
z()/
mm;
1987 edge[3] = v2.
x()/
mm;
1988 edge[4] = v2.
y()/
mm;
1989 edge[5] = v2.
z()/
mm;
1990 dedges.push_back(edge);
1995 unsigned char uccolor[3] = {itr->color[0],
1999 kgMocrenIO->
addDetector(detname, dedges, uccolor);
2000 for(
G4int i = 0; i < nedges; i++) {
2001 delete [] dedges[i];
2006 G4cout <<
" color: (" << (
G4int)uccolor[0] <<
", "
2007 << (
G4int)uccolor[1] << ", " << (
G4int)uccolor[2] << ")"
2014 if(kNestedVolumeDimension[0] == 0 ||
2015 kNestedVolumeDimension[1] == 0 ||
2016 kNestedVolumeDimension[2] == 0) {
2017 for(
G4int i = 0; i < 3; i++) _idx3d[i] = 0;
2022 if(kFlagParameterization == 0) {
2024 G4int plane = kNestedVolumeDimension[2]*kNestedVolumeDimension[1];
2025 G4int line = kNestedVolumeDimension[2];
2037 _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane;
2038 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2039 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line;
2066 G4int plane = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
2067 G4int line = kNestedVolumeDimension[0];
2068 _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane;
2069 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2070 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line;
2078 G4GMocrenFileSceneHandler::Detector::Detector()
2080 color[0] = color[1] = color[2] = 255;
2082 G4GMocrenFileSceneHandler::Detector::~Detector() {
2083 if(!polyhedron)
delete polyhedron;
2085 void G4GMocrenFileSceneHandler::Detector::clear() {
2087 if(!polyhedron)
delete polyhedron;
2088 color[0] = color[1] = color[2] = 255;
2093 G4GMocrenFileSceneHandler::Index3D::Index3D()
2094 :
x(0), y(0),
z(0) {
2098 G4GMocrenFileSceneHandler::Index3D::Index3D(
const Index3D & _index3D)
2099 :
x(_index3D.
x), y(_index3D.y),
z(_index3D.
z) {
2109 G4GMocrenFileSceneHandler::Index3D::Index3D(
G4int _x,
G4int _y,
G4int _z)
2110 :
x(_x), y(_y),
z(_z) {
2114 if(
z < static_cast<Index3D>(_right).
z) {
2116 }
else if(z == _right.z) {
2117 if(y < static_cast<Index3D>(_right).y)
return true;
2118 else if(y == _right.y)
2119 if(
x < static_cast<Index3D>(_right).
x)
return true;
2124 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
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
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
bool operator<(const CexmcAngularRange &left, const CexmcAngularRange &right)
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)