112G4int G4GMocrenFileSceneHandler::kSceneIdCount = 0;
125 kMessenger(messenger),
127 kbSetModalityVoxelSize(false),
128 kbModelingTrajectory(false),
130 kFlagInModeling(false),
131 kFlagSaving_g4_gdd(false),
132 kFlagParameterization(0),
133 kFlagProcessedInteractiveScorer(false) {
136 if(std::getenv(
"G4GMocrenFile_DEST_DIR") == NULL) {
137 kGddDestDir[0] =
'\0';
143 const char * env = std::getenv(
"G4GMocrenFile_DEST_DIR");
146 G4Exception(
"G4GMocrenFileSceneHandler::G4GMocrenFileSceneHandler(*)",
148 "Invalid length of string set in G4GMocrenFile_DEST_DIR");
150 std::strncpy(kGddDestDir, env, len+1);
157 if ( std::getenv(
"G4GMocrenFile_MAX_FILE_NUM" ) != NULL ) {
158 char * pcFileNum = std::getenv(
"G4GMocrenFile_MAX_FILE_NUM");
160 std::strncpy(c10FileNum, pcFileNum, 9);
161 c10FileNum[9] =
'\0';
162 kMaxFileNum = std::atoi(c10FileNum);
167 if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; }
169 InitializeParameters();
185 if(kgMocrenIO != NULL)
delete kgMocrenIO;
190void 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,
sizeof(kGddFileName)-1);
212 kGddFileName[
sizeof(kGddFileName)-1] =
'\0';
216 sizeof(kGddFileName) - std::strlen(kGddFileName) - 1);
219 static G4int currentNumber = 0;
220 for(
G4int i = currentNumber ; i < kMaxFileNum ; i++) {
223 if( i == MAX_FILE_INDEX )
226 G4cout <<
"===========================================" <<
G4endl;
227 G4cout <<
"WARNING MESSAGE from GMocrenFile driver: " <<
G4endl;
228 G4cout <<
" This file name is the final one in the " <<
G4endl;
229 G4cout <<
" automatic updation of the output file name." <<
G4endl;
230 G4cout <<
" You may overwrite existing files, i.e. " <<
G4endl;
232 G4cout <<
"===========================================" <<
G4endl;
237 std::ostringstream filename;
240 << std::setw(2) << std::setfill(
'0') << i <<
".wrl";
241 strncpy(kGddFileName,filename.str().c_str(),
sizeof(kGddFileName)-1);
242 kGddFileName[
sizeof(kGddFileName)-1] =
'\0';
245 std::ifstream fin(kGddFileName);
247 G4cout <<
"FILEOPEN: " << i <<
" : " << kGddFileName << fin.fail()
261 G4cout <<
"======================================================================" <<
G4endl;
263 G4cout <<
"Destination directory (current dir if NULL): " << kGddDestDir <<
G4endl;
264 G4cout <<
"Maximum number of files in the destination directory: " << kMaxFileNum <<
G4endl;
266 G4cout <<
" * The maximum number is customizable as: " <<
G4endl;
267 G4cout <<
" % setenv G4GMocrenFile_MAX_FILE_NUM number " <<
G4endl;
268 G4cout <<
" * The destination directory is customizable as:" <<
G4endl;
269 G4cout <<
" % setenv G4GMocrenFile_DEST_DIR dir_name/ " <<
G4endl;
270 G4cout <<
" ** Do not forget \"/\" at the end of the dir_name, e.g. \"./tmp/\"." <<
G4endl;
274 G4cout <<
"======================================================================" <<
G4endl;
288 G4cout <<
"***** (started) " ;
293 kFlagSaving_g4_gdd =
true;
301 std::vector<G4float> map;
303 for(
G4int i = minmax[0]; i <= minmax[1]; i++) {
339 std::vector<Detector>::iterator itr = kDetectors.begin();
340 for(; itr != kDetectors.end(); itr++) {
345 kNestedHitsList.clear();
346 kNestedVolumeNames.clear();
358 G4cout <<
"***** (started) (close "
359 << kGddFileName <<
")" <<
G4endl;
361 if(kGddDest) kGddDest.close();
362 kFlagSaving_g4_gdd =
false;
364 std::map<Index3D, G4float>::iterator itr = kNestedModality.begin();
365 G4int xmax=0, ymax=0, zmax=0;
366 for(; itr != kNestedModality.end(); itr++) {
367 if(itr->first.x > xmax) xmax = itr->first.x;
368 if(itr->first.y > ymax) ymax = itr->first.y;
369 if(itr->first.z > zmax) zmax = itr->first.z;
372 kModalitySize[0] = xmax+1;
373 kModalitySize[1] = ymax+1;
374 kModalitySize[2] = zmax+1;
376 if(
GFDEBUG)
G4cout <<
"gMocren-file driver : modality size : "
377 << kModalitySize[0] <<
" x "
378 << kModalitySize[1] <<
" x "
379 << kModalitySize[2] <<
G4endl;
381 G4int nxy = kModalitySize[0]*kModalitySize[1];
383 for(
G4int z = 0; z < kModalitySize[2]; z++) {
384 short * modality =
new short[nxy];
385 for(
G4int y = 0; y < kModalitySize[1]; y++) {
386 for(
G4int x = 0; x < kModalitySize[0]; x++) {
390 G4int ixy = x + y*kModalitySize[0];
392 itr = kNestedModality.find(idx);
393 if(itr != kNestedModality.end()) {
397 modality[ixy] = -1024;
406 size_t nhits = kNestedHitsList.size();
409 std::map<Index3D, G4double>::iterator hitsItr;
410 std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr = kNestedHitsList.begin();
412 for(
G4int n = 0; hitsListItr != kNestedHitsList.end(); hitsListItr++, n++) {
419 for(
G4int z = 0 ; z < kModalitySize[2]; z++) {
421 for(
G4int y = 0; y < kModalitySize[1]; y++) {
422 for(
G4int x = 0; x < kModalitySize[0]; x++) {
424 G4int ixy = x + y*kModalitySize[0];
426 hitsItr = hitsListItr->second.find(idx);
427 if(hitsItr != hitsListItr->second.end()) {
429 values[ixy] = hitsItr->second;
433 if(values[ixy] < minmax[0]) minmax[0] = values[ixy];
434 if(values[ixy] > minmax[1]) minmax[1] = values[ixy];
441 if(minmax[0] < 0) lower = minmax[0];
442 G4double scale = (minmax[1]-lower)/25000.;
456 std::vector<G4float *> tracks;
457 unsigned char colors[3];
459 tracks.push_back(trk);
461 G4ThreeVector orig(0.,0.,0), xa(2000.,0.,0.), ya(0.,2000.,0.), za(0.,0.,2000.);
470 for(
G4int i = 0; i < 3; i++) trk[i] = orig[i];
471 for(
G4int i = 0; i < 3; i++) trk[i+3] = xa[i];
472 colors[0] = 255; colors[1] = 0; colors[2] = 0;
473 kgMocrenIO->
addTrack(tracks, colors);
475 for(
G4int i = 0; i < 3; i++) trk[i+3] = ya[i];
476 colors[0] = 0; colors[1] = 255; colors[2] = 0;
477 kgMocrenIO->
addTrack(tracks, colors);
479 for(
G4int i = 0; i < 3; i++) trk[i+3] = za[i];
480 colors[0] = 0; colors[1] = 0; colors[2] = 255;
481 kgMocrenIO->
addTrack(tracks, colors);
489 std::vector<G4float> transformObjects;
490 for(
G4int i = 0; i < 3; i++) {
492 transformObjects.push_back((kVolumeSize[i]/2. - kVoxelDimension[i]/2.));
516 G4cout <<
"***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" <<
G4endl;
521 kFlagInModeling = true ;
530 std::vector<G4Scene::Model>::iterator itr = vmodel.begin();
531 for(; itr != vmodel.end(); itr++) {
532 G4cout <<
" IIIIII model name: " << itr->fpModel->GetGlobalTag() <<
G4endl;
548 static G4bool warned =
false;
552 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)",
554 "2D polylines not implemented. Ignored.");
562 static G4int numTrajectories = 0;
566 if(kbModelingTrajectory) {
571 (
"G4VSceneHandler::AddCompound(const G4Polyline&)",
581 std::vector<G4float *> trajectory;
582 if(polyline.size() < 2)
return;
583 G4Polyline::const_iterator preitr = polyline.begin();
584 G4Polyline::const_iterator postitr = preitr; postitr++;
585 for(; postitr != polyline.end(); preitr++, postitr++) {
589 G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z());
593 stepPts[0] = prePts.
x();
594 stepPts[1] = prePts.
y();
595 stepPts[2] = prePts.
z();
596 stepPts[3] = postPts.
x();
597 stepPts[4] = postPts.
y();
598 stepPts[5] = postPts.
z();
599 trajectory.push_back(stepPts);
603 << stepPts[0] <<
", "
604 << stepPts[1] <<
", "
605 << stepPts[2] <<
") - ("
606 << stepPts[3] <<
", "
607 << stepPts[4] <<
", "
608 << stepPts[5] <<
")" <<
G4endl;
614 unsigned char trkcolor[3];
615 trkcolor[0] = (
unsigned char)(color.
GetRed()*255);
616 trkcolor[1] = (
unsigned char)(color.
GetGreen()*255);
617 trkcolor[2] = (
unsigned char)(color.
GetBlue()*255);
625 kgMocrenIO->
addTrack(trajectory, trkcolor);
637 static G4bool warned =
false;
641 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)",
643 "2D text not implemented. Ignored.");
668 static G4bool warned =
false;
672 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)",
674 "2D circles not implemented. Ignored.");
697 static G4bool warned =
false;
701 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)",
703 "2D squares not implemented. Ignored.");
723 G4cout <<
"***** AddPrimitive( G4Polyhedron )" <<
G4endl;
729 static G4bool warned =
false;
733 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)",
735 "2D polyhedra not implemented. Ignored.");
745 G4bool notLastEdge =
true;
756 }
while (notLastEdge);
767 "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" <<
G4endl;
778 "\nG4Polyhedron facet with " << i <<
" edges" <<
G4endl;
797 G4cout <<
"***** GFEndModeling (started) " ;
798 G4cout <<
"(/EndModeling, /DrawAll, /CloseDevice)" <<
G4endl;
805 kFlagInModeling = false ;
844 G4cout <<
"G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
848 if( !IsVisible() ) { return ; }
864 for(
G4int i = 0; i < 12; i++) {
867 G4cout <<
" (" << v1.
x() <<
", "
872 << v2.
z() <<
") [" << next <<
"]"
883 if(kFlagParameterization != 2) {
888 if(pScBox != NULL) bMesh =
true;
889 if(bMesh) kFlagParameterization = 2;
891 << volName <<
" - " << bMesh <<
G4endl;
896 if (!pv_model) { return ; }
899 if (!pPVModel) { return ; }
911 G4cout <<
" density : " << dens <<
" [g/cm3]" <<
G4endl;
932 kVolumeTrans3D = kVolumeTrans3D*trot;
941 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
944 G4int dirAxis[3] = {-1,-1,-1};
945 G4int nDaughters[3] = {0,0,0};
949 nDaughters[0] = nReplicas;
951 case kXAxis: dirAxis[0] = 0;
break;
952 case kYAxis: dirAxis[0] = 1;
break;
953 case kZAxis: dirAxis[0] = 2;
break;
955 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
958 kNestedVolumeNames.push_back(pv[0]->
GetName());
961 <<
" # : " << nDaughters[0] <<
G4endl;
965 if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
966 G4cout <<
"# of daughters : "
977 if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) {
978 kFlagParameterization = 1;
983 if(kFlagParameterization == 0) {
988 nDaughters[1] = nReplicas;
990 case kXAxis: dirAxis[1] = 0;
break;
991 case kYAxis: dirAxis[1] = 1;
break;
992 case kZAxis: dirAxis[1] = 2;
break;
994 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
997 kNestedVolumeNames.push_back(pv[1]->
GetName());
1000 <<
" # : " << nDaughters[1]<<
G4endl;
1006 kNestedVolumeNames.push_back(pv[2]->
GetName());
1009 <<
" # : " << nDaughters[2] <<
G4endl;
1011 if(nDaughters[2] > 1) {
1014 if(nestPara == NULL)
1015 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1024 G4cout << trans0 <<
" - " << trans1 <<
" - " << diff <<
G4endl;
1026 if(diff.
x() != 0.) dirAxis[2] = 0;
1027 else if(diff.
y() != 0.) dirAxis[2] = 1;
1028 else if(diff.
z() != 0.) dirAxis[2] = 2;
1030 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1031 "gMocren0009",
FatalException,
"Unexpected nested parameterisation");
1036 for(
G4int i = 0; i < 3; i++) {
1037 kNestedVolumeDimension[i] = nDaughters[i];
1039 kNestedVolumeDirAxis[i] = dirAxis[i];
1047 if(nestPara != NULL) {
1048 G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.};
1049 for(
G4int n0 = 0; n0 < nDaughters[0]; n0++) {
1050 for(
G4int n1 = 0; n1 < nDaughters[1]; n1++) {
1051 for(
G4int n2 = 0; n2 < nDaughters[2]; n2++) {
1055 G4cout <<
" retrieve volume : copy # : " << n0
1056 <<
", " << n1 <<
", " << n2 <<
G4endl;
1062 G4cout <<
" density :" << dens <<
" [g/cm3]" <<
G4endl;
1069 if(n0 != 0 || n1 != 0 || n2 != 0) {
1070 for(
G4int i = 0; i < 3; i++) {
1071 if(xyz[i] != prexyz[i])
1072 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1082 idx[dirAxis[0]] = n0;
1083 idx[dirAxis[1]] = n1;
1084 idx[dirAxis[2]] = n2;
1085 Index3D i3d(idx[0],idx[1],idx[2]);
1086 kNestedModality[i3d] = dens;
1088 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1089 <<
" density: " << dens <<
G4endl;
1091 for(
G4int i = 0; i < 3; i++) prexyz[i] = xyz[i];
1100 if(!kbSetModalityVoxelSize) {
1102 static_cast<G4float>(2*xyz[1]),
1103 static_cast<G4float>(2*xyz[2])};
1105 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1106 kbSetModalityVoxelSize =
true;
1112 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1126 G4cout <<
" physical volume node id : "
1127 <<
"size: " << npvp <<
", PV name: ";
1128 for(
G4int i = 0; i < npvp; i++) {
1131 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised()
1133 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated();
1134 if(pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) {
1136 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested();
1139 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo();
1148 G4Box * pbox =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1153 G4cout <<
" mother size ["
1154 << pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1156 << pareDims[0] <<
" x "
1157 << pareDims[1] <<
" x "
1158 << pareDims[2] <<
" [mm3]"
1162 G4Box * boxP =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1167 G4cout <<
" parameterised volume? ["
1168 << pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName()
1170 << paraDims[0] <<
" x "
1171 << paraDims[1] <<
" x "
1172 << paraDims[2] <<
" [mm3] : "
1173 <<
G4int(pareDims[0]/paraDims[0]) <<
" x "
1174 <<
G4int(pareDims[1]/paraDims[1]) <<
" x "
1178 <<
" isn't a G4Box." <<
G4endl;
1184 }
else if(kFlagParameterization == 1) {
1189 if(phantomPara == NULL) {
1190 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1199 kNestedVolumeDirAxis[0] = 0;
1200 kNestedVolumeDirAxis[1] = 1;
1201 kNestedVolumeDirAxis[2] = 2;
1204 G4int nX = kNestedVolumeDimension[0];
1205 G4int nXY = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
1207 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1208 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1209 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1211 G4int repNo = n0 + n1*nX + n2*nXY;
1217 idx[kNestedVolumeDirAxis[0]] = n0;
1218 idx[kNestedVolumeDirAxis[1]] = n1;
1219 idx[kNestedVolumeDirAxis[2]] = n2;
1220 Index3D i3d(idx[0],idx[1],idx[2]);
1221 kNestedModality[i3d] = dens;
1224 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1225 <<
" density: " << dens <<
G4endl;
1236 if(!kbSetModalityVoxelSize) {
1241 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1242 kbSetModalityVoxelSize =
true;
1250 if(!kFlagProcessedInteractiveScorer) {
1267 kNestedVolumeDimension[0] = nVoxels[2];
1268 kNestedVolumeDimension[1] = nVoxels[1];
1269 kNestedVolumeDimension[2] = nVoxels[0];
1270 kNestedVolumeDirAxis[0] = 2;
1271 kNestedVolumeDirAxis[1] = 1;
1272 kNestedVolumeDirAxis[2] = 0;
1275 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1276 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1277 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1282 idx[kNestedVolumeDirAxis[0]] = n0;
1283 idx[kNestedVolumeDirAxis[1]] = n1;
1284 idx[kNestedVolumeDirAxis[2]] = n2;
1285 Index3D i3d(idx[0],idx[1],idx[2]);
1286 kNestedModality[i3d] = dens;
1294 G4cout <<
"Interactive Scorer : size - "
1295 << boxSize.
x()/cm <<
" x "
1296 << boxSize.
y()/cm <<
" x "
1297 << boxSize.
z()/cm <<
" [cm3]" <<
G4endl;
1298 G4cout <<
"Interactive Scorer : # voxels - "
1299 << nVoxels[0] <<
" x "
1300 << nVoxels[1] <<
" x "
1303 kVolumeSize.
set(boxSize.
x()*2,
1308 if(!kbSetModalityVoxelSize) {
1310 static_cast<G4float>(boxSize.
y()*2/nVoxels[1]),
1311 static_cast<G4float>(boxSize.
z()*2/nVoxels[2])};
1314 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1315 kbSetModalityVoxelSize =
true;
1325 kVolumeTrans3D = kVolumeTrans3D*sbtranslate;
1333 kVolumeTrans3D = kVolumeTrans3D*sbrotate;
1345 kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ;
1350 kFlagProcessedInteractiveScorer =
true;
1363 if(kFlagParameterization == 0) {
1382 if(volName == box.
GetName()) {
1386 std::vector<G4String>::iterator itr = kNestedVolumeNames.begin();
1387 for(; itr != kNestedVolumeNames.end(); itr++) {
1393 }
else if(kFlagParameterization == 1) {
1404 if(volDSolidName == box.
GetName()) {
1408 }
else if(kFlagParameterization == 2) {
1413 if(bAddDet) AddDetector(box);
1427 if( !IsVisible() ) { return ; }
1442 for(
G4int i = 0; i < nv; i++) {
1451 if (!pv_model) { return ; }
1454 if (!pPVModel) { return ; }
1470 if( !IsVisible() ) { return ; }
1489 if( !IsVisible() ) { return ; }
1507 if( !IsVisible() ) { return ; }
1513 AddDetector(sphere);
1525 if( !IsVisible() ) { return ; }
1543 if( !IsVisible() ) { return ; }
1562 if( !IsVisible() ) { return ; }
1578 if( !IsVisible() ) { return ; }
1598 kbModelingTrajectory =
true;
1603 G4cout <<
" ::AddCompound(const G4VTrajectory&) >>>>>>>>> " <<
G4endl;
1607 (
"G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1621 for(
G4int i = 0; i < nPnt; i++) {
1629 kbModelingTrajectory =
false;
1651 std::vector<G4String> hitNames = kMessenger.
getHitNames();
1653 std::vector<G4String>::iterator itr = hitNames.begin();
1654 for(; itr != hitNames.end(); itr++)
1662 G4bool bid[3] = {
false,
false,
false};
1665 std::vector<G4AttValue>::iterator itr;
1667 for(itr = attval->begin(); itr != attval->end(); itr++) {
1668 std::string stmp = itr->GetValue();
1669 std::istringstream sval(stmp.c_str());
1671 if(itr->GetName() ==
G4String(
"XID")) {
1676 if(itr->GetName() ==
G4String(
"YID")) {
1681 if(itr->GetName() ==
G4String(
"ZID")) {
1690 if(bid[0] && bid[1] && bid[2]) {
1693 G4cout <<
" Hit : index(" <<
id.x <<
", " <<
id.y <<
", "
1694 <<
id.z <<
")" <<
G4endl;
1697 for(itr = attval->begin(); itr != attval->end(); itr++) {
1698 for(
G4int i = 0; i < nhitname; i++) {
1699 if(itr->GetName() == hitNames[i]) {
1701 std::string stmp = itr->GetValue();
1702 std::istringstream sval(stmp.c_str());
1705 sval >> value >> unit;
1707 std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr;
1708 kNestedHitsListItr = kNestedHitsList.find(hitNames[i]);
1709 if(kNestedHitsListItr != kNestedHitsList.end()) {
1712 kNestedHitsListItr->second[id] = value;
1714 std::map<Index3D, G4double> hits;
1715 hits.insert(std::map<Index3D, G4double>::value_type(
id, value));
1716 kNestedHitsList[hitNames[i]] = hits;
1721 G4cout <<
" : " << hitNames[i] <<
" -> " << value
1722 <<
" [" << unit <<
"]" <<
G4endl;
1727 G4Exception(
"G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)",
1743 G4cout <<
" ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " <<
G4endl;
1747 G4int nhitname = (
G4int)hitScorerNames.size();
1765 std::map<G4int, G4double*> * map = hits.
GetMap();
1766 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1767 for(; itr != map->end(); itr++) {
1768 GetNestedVolumeIndex(itr->first, idx);
1769 Index3D id(idx[0], idx[1], idx[2]);
1771 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1772 nestedHitsListItr = kNestedHitsList.find(scorername);
1773 if(nestedHitsListItr != kNestedHitsList.end()) {
1774 nestedHitsListItr->second[id] = *(itr->second);
1776 std::map<Index3D, G4double> hit;
1777 hit.insert(std::map<Index3D, G4double>::value_type(
id, *(itr->second)));
1778 kNestedHitsList[scorername] = hit;
1789 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1791 for(
G4int i = 0; i < nhitname; i++)
1792 if(scorername == hitScorerNames[i])
1793 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1796 << kNestedVolumeDimension[0] <<
" x "
1797 << kNestedVolumeDimension[1] <<
" x "
1798 << kNestedVolumeDimension[2] <<
G4endl;
1801 std::map<G4int, G4double*> * map = hits.
GetMap();
1802 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1803 for(; itr != map->end(); itr++) {
1804 GetNestedVolumeIndex(itr->first,
id);
1805 G4cout <<
"[" << itr->first <<
"] "
1806 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1807 << *(itr->second) <<
", ";
1815 G4cout <<
" ::AddCompound(const std::map<G4int, G4StatDouble*> &) >>>>>>>>> " <<
G4endl;
1819 G4int nhitname = (
G4int)hitScorerNames.size();
1837 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1838 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1839 for(; itr != map->end(); itr++) {
1840 GetNestedVolumeIndex(itr->first, idx);
1841 Index3D id(idx[0], idx[1], idx[2]);
1843 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1844 nestedHitsListItr = kNestedHitsList.find(scorername);
1845 if(nestedHitsListItr != kNestedHitsList.end()) {
1846 nestedHitsListItr->second[id] = itr->second->sum_wx();
1848 std::map<Index3D, G4double> hit;
1849 hit.insert(std::map<Index3D, G4double>::value_type(
id, itr->second->sum_wx()));
1850 kNestedHitsList[scorername] = hit;
1861 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1863 for(
G4int i = 0; i < nhitname; i++)
1864 if(scorername == hitScorerNames[i])
1865 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1868 << kNestedVolumeDimension[0] <<
" x "
1869 << kNestedVolumeDimension[1] <<
" x "
1870 << kNestedVolumeDimension[2] <<
G4endl;
1873 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1874 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1875 for(; itr != map->end(); itr++) {
1876 GetNestedVolumeIndex(itr->first,
id);
1877 G4cout <<
"[" << itr->first <<
"] "
1878 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1879 << itr->second->sum_wx() <<
", ";
1886G4bool G4GMocrenFileSceneHandler::IsVisible()
1889 G4bool visibility = true ;
1917void G4GMocrenFileSceneHandler::AddDetector(
const G4VSolid & solid) {
1922 detector.name = solid.
GetName();
1924 G4cout <<
"0 Detector name : " << detector.name <<
G4endl;
1927 if (!pv_model) { return ; }
1930 if (!pPVModel) { return ; }
1933 std::vector<G4float *> dedges;
1935 detector.polyhedron = poly;
1939 unsigned char uccolor[3] = {30, 30, 30};
1942 uccolor[0] = (
unsigned char)(color.
GetRed()*255);
1943 uccolor[1] = (
unsigned char)(color.
GetGreen()*255);
1944 uccolor[2] = (
unsigned char)(color.
GetBlue()*255);
1948 for(
G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i];
1950 kDetectors.push_back(detector);
1953 G4cout <<
"0 color: (" << (
G4int)uccolor[0] <<
", "
1954 << (
G4int)uccolor[1] <<
", " << (
G4int)uccolor[2] <<
")"
1961void G4GMocrenFileSceneHandler::ExtractDetector() {
1963 std::vector<Detector>::iterator itr = kDetectors.begin();
1965 for(; itr != kDetectors.end(); itr++) {
1973 std::vector<G4float *> dedges;
1985 if(!(poly->
GetNextEdge(v1, v2, next))) bnext =
false;
1987 edge[0] = v1.
x()/mm;
1988 edge[1] = v1.
y()/mm;
1989 edge[2] = v1.
z()/mm;
1990 edge[3] = v2.
x()/mm;
1991 edge[4] = v2.
y()/mm;
1992 edge[5] = v2.
z()/mm;
1993 dedges.push_back(edge);
1998 unsigned char uccolor[3] = {itr->color[0],
2002 kgMocrenIO->
addDetector(detname, dedges, uccolor);
2003 for(
G4int i = 0; i < nedges; i++) {
2004 delete [] dedges[i];
2009 G4cout <<
" color: (" << (
G4int)uccolor[0] <<
", "
2010 << (
G4int)uccolor[1] <<
", " << (
G4int)uccolor[2] <<
")"
2016void G4GMocrenFileSceneHandler::GetNestedVolumeIndex(
G4int _idx,
G4int _idx3d[3]) {
2017 if(kNestedVolumeDimension[0] == 0 ||
2018 kNestedVolumeDimension[1] == 0 ||
2019 kNestedVolumeDimension[2] == 0) {
2020 for(
G4int i = 0; i < 3; i++) _idx3d[i] = 0;
2025 if(kFlagParameterization == 0) {
2027 G4int plane = kNestedVolumeDimension[2]*kNestedVolumeDimension[1];
2028 G4int line = kNestedVolumeDimension[2];
2040 _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane;
2041 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2042 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line;
2069 G4int plane = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
2070 G4int line = kNestedVolumeDimension[0];
2071 _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane;
2072 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2073 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line;
2081G4GMocrenFileSceneHandler::Detector::Detector()
2083 color[0] = color[1] = color[2] = 255;
2085G4GMocrenFileSceneHandler::Detector::~Detector() {
2086 if(!polyhedron)
delete polyhedron;
2088void G4GMocrenFileSceneHandler::Detector::clear() {
2090 if(!polyhedron)
delete polyhedron;
2091 color[0] = color[1] = color[2] = 255;
2096G4GMocrenFileSceneHandler::Index3D::Index3D()
2097 : x(0), y(0), z(0) {
2101G4GMocrenFileSceneHandler::Index3D::Index3D(
const Index3D & _index3D)
2102 : x(_index3D.x), y(_index3D.y), z(_index3D.z) {
2112G4GMocrenFileSceneHandler::Index3D::Index3D(
G4int _x,
G4int _y,
G4int _z)
2113 : x(_x), y(_y), z(_z) {
2116G4bool G4GMocrenFileSceneHandler::Index3D::operator < (
const Index3D & _right)
const {
2117 if(z <
static_cast<Index3D
>(_right).z) {
2119 }
else if(z == _right.z) {
2120 if(y <
static_cast<Index3D
>(_right).y)
return true;
2121 else if(y == _right.y)
2122 if(x <
static_cast<Index3D
>(_right).x)
return true;
2126G4bool G4GMocrenFileSceneHandler::Index3D::operator == (
const Index3D & _right)
const {
2127 if(z == _right.z && y == _right.y && x == _right.x)
return true;
const int FR_MAX_FILE_NUM
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
const G4bool GFDEBUG_DIGI
const G4int FR_MAX_FILE_NUM
const char GDD_FILE_HEADER[]
const char DEFAULT_GDD_FILE_NAME[]
const G4int MAX_NUM_TRAJECTORIES
G4GLOB_DLL std::ostream G4cout
Hep3Vector & transform(const HepRotation &)
void set(double x, double y, double z)
HepRotation inverse() const
G4double GetYHalfLength() const
G4Polyhedron * CreatePolyhedron() const override
G4double GetZHalfLength() const
G4double GetXHalfLength() const
G4double GetGreen() const
G4double GetDensity(G4int &_ct) const
G4GMocrenFileSceneHandler(G4GMocrenFile &system, G4GMocrenMessenger &messenger, const G4String &name="")
void AddCompound(const G4VTrajectory &traj)
void BeginSavingGdd(void)
void ClearTransientStore()
void AddSolid(const G4Box &box)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
virtual void EndPrimitives()
virtual ~G4GMocrenFileSceneHandler()
void AddPrimitive(const G4Polyline &line)
void setModalityImageSize(int _size[3])
void setDoseDistUnit(std::string &_unit, int _num=0)
short convertDensityToHU(float &_dens)
void setDoseDistMinMax(short _minmax[2], int _num=0)
void setDoseDistScale(double &_scale, int _num=0)
void setModalityImageDensityMap(std::vector< float > &_map)
void translateDetector(std::vector< float > &_translate)
void setVoxelSpacing(float _spacing[3])
void setDoseDistName(std::string _name, int _num=0)
bool storeData(char *_filename)
void setModalityImage(short *_image)
void setDoseDistSize(int _size[3], int _num=0)
void setModalityImageMinMax(short _minmax[2])
void addDetector(std::string &_name, std::vector< float * > &_det, unsigned char _color[3])
void setDoseDist(double *_image, int _num=0)
void translateTracks(std::vector< float > &_translateo)
void addTrack(float *_tracks)
virtual std::vector< G4String > getHitNames()
virtual std::vector< G4String > getHitScorerNames()
virtual G4bool getDrawVolumeGrid()
virtual G4String getVolumeName()
G4VSolid * GetSolid() const
const G4VisAttributes * GetVisAttributes() const
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
G4double GetDensity() const
const G4String & GetName() const
G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=nullptr) override
G4double GetVoxelHalfZ() const
std::size_t GetNoVoxelsX() const
G4double GetVoxelHalfY() const
G4double GetVoxelHalfX() const
std::size_t GetNoVoxelsZ() const
std::size_t GetNoVoxelsY() const
const std::vector< G4PhysicalVolumeNodeID > & GetDrawnPVPath() const
G4VPhysicalVolume * GetCurrentPV() const
G4LogicalVolume * GetCurrentLV() const
G4VPhysicalVolume * GetTopPhysicalVolume() const
G4Material * GetCurrentMaterial() const
G4int GetCurrentDepth() const
const std::vector< Model > & GetEndOfEventModelList() const
static G4ScoringManager * GetScoringManager()
G4VScoringMesh * FindMesh(G4VHitsCollection *map)
const G4VTrajectory * GetCurrentTrajectory() const
G4Polyhedron * CreatePolyhedron() const override
virtual std::vector< G4AttValue > * CreateAttValues() const
void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const override=0
void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const override
virtual G4Material * ComputeMaterial(G4VPhysicalVolume *currentVol, const G4int repNo, const G4VTouchable *parentTouch=nullptr)=0
virtual G4bool IsNested() const
virtual G4bool IsReplicated() const =0
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetMultiplicity() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
virtual G4VPVParameterisation * GetParameterisation() const =0
G4ThreeVector GetObjectTranslation() const
virtual G4bool IsParameterised() const =0
virtual void BeginModeling()
G4VModel * GetModel() const
G4Scene * GetScene() const
G4Transform3D fObjectTransformation
virtual void EndPrimitives()
virtual void EndModeling()
const G4String & GetName() const
const G4VisAttributes * fpVisAttribs
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())
virtual void AddSolid(const G4Box &)
virtual void AddCompound(const G4VTrajectory &)
G4ThreeVector GetTranslation() const
G4ThreeVector GetSize() const
void GetNumberOfSegments(G4int nSegment[3])
G4RotationMatrix GetRotationMatrix() const
virtual G4Polyhedron * CreatePolyhedron() const
virtual G4GeometryType GetEntityType() const =0
virtual const G4ThreeVector GetPosition() const =0
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
virtual G4int GetPointEntries() const =0
virtual G4String GetParticleName() const =0
virtual G4int GetTrackID() const =0
virtual G4ThreeVector GetInitialMomentum() const =0
virtual G4double GetCharge() const =0
virtual void DrawTrajectory() const
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
const G4Color & GetColor() const
static Verbosity GetVerbosity()
const G4VisAttributes * GetVisAttributes() const
G4Point3D GetVertex(G4int index) const
HepPolyhedron & Transform(const G4Transform3D &t)
G4int GetNoFacets() const
G4bool GetNextVertexIndex(G4int &index, G4int &edgeFlag) const
G4int GetNoVertices() const
G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const
const char * name(G4int ptype)