113G4int 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 = std::getenv(
"G4GMocrenFile_MAX_FILE_NUM");
161 std::strncpy(c10FileNum, pcFileNum, 9);
162 c10FileNum[9] =
'\0';
163 kMaxFileNum = std::atoi(c10FileNum);
168 if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; }
170 InitializeParameters();
186 if(kgMocrenIO != NULL)
delete kgMocrenIO;
191void G4GMocrenFileSceneHandler::InitializeParameters() {
193 kbSetModalityVoxelSize =
false;
195 for(
G4int i = 0; i < 3; i++) {
196 kModalitySize[i] = 0;
197 kNestedVolumeDimension[i] = 0;
198 kNestedVolumeDirAxis[i] = -1;
209 const G4int MAX_FILE_INDEX = kMaxFileNum - 1 ;
212 std::strncpy(kGddFileName, kGddDestDir,
sizeof(kGddFileName)-1);
213 kGddFileName[
sizeof(kGddFileName)-1] =
'\0';
217 sizeof(kGddFileName) - std::strlen(kGddFileName) - 1);
220 static G4int currentNumber = 0;
221 for(
G4int i = currentNumber ; i < kMaxFileNum ; i++) {
224 if( i == MAX_FILE_INDEX )
227 G4cout <<
"===========================================" <<
G4endl;
228 G4cout <<
"WARNING MESSAGE from GMocrenFile driver: " <<
G4endl;
229 G4cout <<
" This file name is the final one in the " <<
G4endl;
230 G4cout <<
" automatic updation of the output file name." <<
G4endl;
231 G4cout <<
" You may overwrite existing files, i.e. " <<
G4endl;
233 G4cout <<
"===========================================" <<
G4endl;
238 std::ostringstream filename;
241 << std::setw(2) << std::setfill(
'0') << i <<
".wrl";
242 strncpy(kGddFileName,filename.str().c_str(),
sizeof(kGddFileName)-1);
243 kGddFileName[
sizeof(kGddFileName)-1] =
'\0';
246 std::ifstream fin(kGddFileName);
248 G4cout <<
"FILEOPEN: " << i <<
" : " << kGddFileName << fin.fail()
262 G4cout <<
"======================================================================" <<
G4endl;
264 G4cout <<
"Destination directory (current dir if NULL): " << kGddDestDir <<
G4endl;
265 G4cout <<
"Maximum number of files in the destination directory: " << kMaxFileNum <<
G4endl;
267 G4cout <<
" * The maximum number is customizable as: " <<
G4endl;
268 G4cout <<
" % setenv G4GMocrenFile_MAX_FILE_NUM number " <<
G4endl;
269 G4cout <<
" * The destination directory is customizable as:" <<
G4endl;
270 G4cout <<
" % setenv G4GMocrenFile_DEST_DIR dir_name/ " <<
G4endl;
271 G4cout <<
" ** Do not forget \"/\" at the end of the dir_name, e.g. \"./tmp/\"." <<
G4endl;
275 G4cout <<
"======================================================================" <<
G4endl;
289 G4cout <<
"***** (started) " ;
294 kFlagSaving_g4_gdd =
true;
302 std::vector<G4float> map;
304 for(
G4int i = minmax[0]; i <= minmax[1]; i++) {
340 std::vector<Detector>::iterator itr = kDetectors.begin();
341 for(; itr != kDetectors.end(); itr++) {
346 kNestedHitsList.clear();
347 kNestedVolumeNames.clear();
359 G4cout <<
"***** (started) (close "
360 << kGddFileName <<
")" <<
G4endl;
362 if(kGddDest) kGddDest.close();
363 kFlagSaving_g4_gdd =
false;
365 std::map<Index3D, G4float>::iterator itr = kNestedModality.begin();
366 G4int xmax=0, ymax=0, zmax=0;
367 for(; itr != kNestedModality.end(); itr++) {
368 if(itr->first.x > xmax) xmax = itr->first.x;
369 if(itr->first.y > ymax) ymax = itr->first.y;
370 if(itr->first.z > zmax) zmax = itr->first.z;
373 kModalitySize[0] = xmax+1;
374 kModalitySize[1] = ymax+1;
375 kModalitySize[2] = zmax+1;
377 if(
GFDEBUG)
G4cout <<
"gMocren-file driver : modality size : "
378 << kModalitySize[0] <<
" x "
379 << kModalitySize[1] <<
" x "
380 << kModalitySize[2] <<
G4endl;
382 G4int nxy = kModalitySize[0]*kModalitySize[1];
384 for(
G4int z = 0; z < kModalitySize[2]; z++) {
385 short * modality =
new short[nxy];
386 for(
G4int y = 0; y < kModalitySize[1]; y++) {
387 for(
G4int x = 0; x < kModalitySize[0]; x++) {
391 G4int ixy = x + y*kModalitySize[0];
393 itr = kNestedModality.find(idx);
394 if(itr != kNestedModality.end()) {
398 modality[ixy] = -1024;
407 size_t nhits = kNestedHitsList.size();
410 std::map<Index3D, G4double>::iterator hitsItr;
411 std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr = kNestedHitsList.begin();
413 for(
G4int n = 0; hitsListItr != kNestedHitsList.end(); hitsListItr++, n++) {
420 for(
G4int z = 0 ; z < kModalitySize[2]; z++) {
422 for(
G4int y = 0; y < kModalitySize[1]; y++) {
423 for(
G4int x = 0; x < kModalitySize[0]; x++) {
425 G4int ixy = x + y*kModalitySize[0];
427 hitsItr = hitsListItr->second.find(idx);
428 if(hitsItr != hitsListItr->second.end()) {
430 values[ixy] = hitsItr->second;
434 if(values[ixy] < minmax[0]) minmax[0] = values[ixy];
435 if(values[ixy] > minmax[1]) minmax[1] = values[ixy];
442 if(minmax[0] < 0) lower = minmax[0];
443 G4double scale = (minmax[1]-lower)/25000.;
457 std::vector<G4float *> tracks;
458 unsigned char colors[3];
460 tracks.push_back(trk);
462 G4ThreeVector orig(0.,0.,0), xa(2000.,0.,0.), ya(0.,2000.,0.), za(0.,0.,2000.);
471 for(
G4int i = 0; i < 3; i++) trk[i] = orig[i];
472 for(
G4int i = 0; i < 3; i++) trk[i+3] = xa[i];
473 colors[0] = 255; colors[1] = 0; colors[2] = 0;
474 kgMocrenIO->
addTrack(tracks, colors);
476 for(
G4int i = 0; i < 3; i++) trk[i+3] = ya[i];
477 colors[0] = 0; colors[1] = 255; colors[2] = 0;
478 kgMocrenIO->
addTrack(tracks, colors);
480 for(
G4int i = 0; i < 3; i++) trk[i+3] = za[i];
481 colors[0] = 0; colors[1] = 0; colors[2] = 255;
482 kgMocrenIO->
addTrack(tracks, colors);
490 std::vector<G4float> transformObjects;
491 for(
G4int i = 0; i < 3; i++) {
493 transformObjects.push_back((kVolumeSize[i]/2. - kVoxelDimension[i]/2.));
517 G4cout <<
"***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" <<
G4endl;
522 kFlagInModeling = true ;
531 std::vector<G4Scene::Model>::iterator itr = vmodel.begin();
532 for(; itr != vmodel.end(); itr++) {
533 G4cout <<
" IIIIII model name: " << itr->fpModel->GetGlobalTag() <<
G4endl;
549 static G4bool warned =
false;
553 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)",
555 "2D polylines not implemented. Ignored.");
563 static G4int numTrajectories = 0;
567 if(kbModelingTrajectory) {
572 (
"G4VSceneHandler::AddCompound(const G4Polyline&)",
582 std::vector<G4float *> trajectory;
583 if(polyline.size() < 2)
return;
584 G4Polyline::const_iterator preitr = polyline.begin();
585 G4Polyline::const_iterator postitr = preitr; postitr++;
586 for(; postitr != polyline.end(); preitr++, postitr++) {
590 G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z());
594 stepPts[0] = prePts.
x();
595 stepPts[1] = prePts.
y();
596 stepPts[2] = prePts.
z();
597 stepPts[3] = postPts.
x();
598 stepPts[4] = postPts.
y();
599 stepPts[5] = postPts.
z();
600 trajectory.push_back(stepPts);
604 << stepPts[0] <<
", "
605 << stepPts[1] <<
", "
606 << stepPts[2] <<
") - ("
607 << stepPts[3] <<
", "
608 << stepPts[4] <<
", "
609 << stepPts[5] <<
")" <<
G4endl;
615 unsigned char trkcolor[3];
616 trkcolor[0] = (
unsigned char)(color.
GetRed()*255);
617 trkcolor[1] = (
unsigned char)(color.
GetGreen()*255);
618 trkcolor[2] = (
unsigned char)(color.
GetBlue()*255);
626 kgMocrenIO->
addTrack(trajectory, trkcolor);
638 static G4bool warned =
false;
642 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)",
644 "2D text not implemented. Ignored.");
669 static G4bool warned =
false;
673 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)",
675 "2D circles not implemented. Ignored.");
698 static G4bool warned =
false;
702 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)",
704 "2D squares not implemented. Ignored.");
724 G4cout <<
"***** AddPrimitive( G4Polyhedron )" <<
G4endl;
730 static G4bool warned =
false;
734 (
"G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)",
736 "2D polyhedra not implemented. Ignored.");
746 G4bool notLastEdge =
true;
757 }
while (notLastEdge);
768 "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" <<
G4endl;
779 "\nG4Polyhedron facet with " << i <<
" edges" <<
G4endl;
798 G4cout <<
"***** GFEndModeling (started) " ;
799 G4cout <<
"(/EndModeling, /DrawAll, /CloseDevice)" <<
G4endl;
806 kFlagInModeling = false ;
845 G4cout <<
"G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
849 if( !IsVisible() ) { return ; }
865 for(
G4int i = 0; i < 12; i++) {
868 G4cout <<
" (" << v1.
x() <<
", "
873 << v2.
z() <<
") [" << next <<
"]"
884 if(kFlagParameterization != 2) {
889 if(pScBox != NULL) bMesh =
true;
890 if(bMesh) kFlagParameterization = 2;
892 << volName <<
" - " << bMesh <<
G4endl;
897 if (!pv_model) { return ; }
900 if (!pPVModel) { return ; }
912 G4cout <<
" density : " << dens <<
" [g/cm3]" <<
G4endl;
933 kVolumeTrans3D = kVolumeTrans3D*trot;
942 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
945 G4int dirAxis[3] = {-1,-1,-1};
946 G4int nDaughters[3] = {0,0,0};
950 nDaughters[0] = nReplicas;
952 case kXAxis: dirAxis[0] = 0;
break;
953 case kYAxis: dirAxis[0] = 1;
break;
954 case kZAxis: dirAxis[0] = 2;
break;
956 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
959 kNestedVolumeNames.push_back(pv[0]->
GetName());
962 <<
" # : " << nDaughters[0] <<
G4endl;
966 if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
967 G4cout <<
"# of daughters : "
978 if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) {
979 kFlagParameterization = 1;
984 if(kFlagParameterization == 0) {
989 nDaughters[1] = nReplicas;
991 case kXAxis: dirAxis[1] = 0;
break;
992 case kYAxis: dirAxis[1] = 1;
break;
993 case kZAxis: dirAxis[1] = 2;
break;
995 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
998 kNestedVolumeNames.push_back(pv[1]->
GetName());
1001 <<
" # : " << nDaughters[1]<<
G4endl;
1007 kNestedVolumeNames.push_back(pv[2]->
GetName());
1010 <<
" # : " << nDaughters[2] <<
G4endl;
1012 if(nDaughters[2] > 1) {
1015 if(nestPara == NULL)
1016 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1025 G4cout << trans0 <<
" - " << trans1 <<
" - " << diff <<
G4endl;
1027 if(diff.
x() != 0.) dirAxis[2] = 0;
1028 else if(diff.
y() != 0.) dirAxis[2] = 1;
1029 else if(diff.
z() != 0.) dirAxis[2] = 2;
1031 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1032 "gMocren0009",
FatalException,
"Unexpected nested parameterisation");
1037 for(
G4int i = 0; i < 3; i++) {
1038 kNestedVolumeDimension[i] = nDaughters[i];
1040 kNestedVolumeDirAxis[i] = dirAxis[i];
1048 if(nestPara != NULL) {
1049 G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.};
1050 for(
G4int n0 = 0; n0 < nDaughters[0]; n0++) {
1051 for(
G4int n1 = 0; n1 < nDaughters[1]; n1++) {
1052 for(
G4int n2 = 0; n2 < nDaughters[2]; n2++) {
1056 G4cout <<
" retrieve volume : copy # : " << n0
1057 <<
", " << n1 <<
", " << n2 <<
G4endl;
1063 G4cout <<
" density :" << dens <<
" [g/cm3]" <<
G4endl;
1070 if(n0 != 0 || n1 != 0 || n2 != 0) {
1071 for(
G4int i = 0; i < 3; i++) {
1072 if(xyz[i] != prexyz[i])
1073 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1083 idx[dirAxis[0]] = n0;
1084 idx[dirAxis[1]] = n1;
1085 idx[dirAxis[2]] = n2;
1086 Index3D i3d(idx[0],idx[1],idx[2]);
1087 kNestedModality[i3d] = dens;
1089 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1090 <<
" density: " << dens <<
G4endl;
1092 for(
G4int i = 0; i < 3; i++) prexyz[i] = xyz[i];
1101 if(!kbSetModalityVoxelSize) {
1103 static_cast<G4float>(2*xyz[1]),
1104 static_cast<G4float>(2*xyz[2])};
1106 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1107 kbSetModalityVoxelSize =
true;
1113 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1127 G4cout <<
" physical volume node id : "
1128 <<
"size: " << npvp <<
", PV name: ";
1129 for(
G4int i = 0; i < npvp; i++) {
1132 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised()
1134 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated();
1135 if(pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) {
1137 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested();
1140 << pPVModel->
GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo();
1149 G4Box * pbox =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1154 G4cout <<
" mother size ["
1155 << pPVModel->
GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1157 << pareDims[0] <<
" x "
1158 << pareDims[1] <<
" x "
1159 << pareDims[2] <<
" [mm3]"
1163 G4Box * boxP =
dynamic_cast<G4Box *
>(pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1168 G4cout <<
" parameterised volume? ["
1169 << pPVModel->
GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName()
1171 << paraDims[0] <<
" x "
1172 << paraDims[1] <<
" x "
1173 << paraDims[2] <<
" [mm3] : "
1174 <<
G4int(pareDims[0]/paraDims[0]) <<
" x "
1175 <<
G4int(pareDims[1]/paraDims[1]) <<
" x "
1179 <<
" isn't a G4Box." <<
G4endl;
1185 }
else if(kFlagParameterization == 1) {
1190 if(phantomPara == NULL) {
1191 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1197 kNestedVolumeDimension[0] = phantomPara->
GetNoVoxelX();
1198 kNestedVolumeDimension[1] = phantomPara->
GetNoVoxelY();
1199 kNestedVolumeDimension[2] = phantomPara->
GetNoVoxelZ();
1200 kNestedVolumeDirAxis[0] = 0;
1201 kNestedVolumeDirAxis[1] = 1;
1202 kNestedVolumeDirAxis[2] = 2;
1205 G4int nX = kNestedVolumeDimension[0];
1206 G4int nXY = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
1208 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1209 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1210 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1212 G4int repNo = n0 + n1*nX + n2*nXY;
1218 idx[kNestedVolumeDirAxis[0]] = n0;
1219 idx[kNestedVolumeDirAxis[1]] = n1;
1220 idx[kNestedVolumeDirAxis[2]] = n2;
1221 Index3D i3d(idx[0],idx[1],idx[2]);
1222 kNestedModality[i3d] = dens;
1225 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1226 <<
" density: " << dens <<
G4endl;
1237 if(!kbSetModalityVoxelSize) {
1242 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1243 kbSetModalityVoxelSize =
true;
1251 if(!kFlagProcessedInteractiveScorer) {
1268 kNestedVolumeDimension[0] = nVoxels[2];
1269 kNestedVolumeDimension[1] = nVoxels[1];
1270 kNestedVolumeDimension[2] = nVoxels[0];
1271 kNestedVolumeDirAxis[0] = 2;
1272 kNestedVolumeDirAxis[1] = 1;
1273 kNestedVolumeDirAxis[2] = 0;
1276 for(
G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1277 for(
G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1278 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1283 idx[kNestedVolumeDirAxis[0]] = n0;
1284 idx[kNestedVolumeDirAxis[1]] = n1;
1285 idx[kNestedVolumeDirAxis[2]] = n2;
1286 Index3D i3d(idx[0],idx[1],idx[2]);
1287 kNestedModality[i3d] = dens;
1295 G4cout <<
"Interactive Scorer : size - "
1296 << boxSize.
x()/cm <<
" x "
1297 << boxSize.
y()/cm <<
" x "
1298 << boxSize.
z()/cm <<
" [cm3]" <<
G4endl;
1299 G4cout <<
"Interactive Scorer : # voxels - "
1300 << nVoxels[0] <<
" x "
1301 << nVoxels[1] <<
" x "
1304 kVolumeSize.
set(boxSize.
x()*2,
1309 if(!kbSetModalityVoxelSize) {
1311 static_cast<G4float>(boxSize.
y()*2/nVoxels[1]),
1312 static_cast<G4float>(boxSize.
z()*2/nVoxels[2])};
1315 kVoxelDimension.
set(spacing[0], spacing[1], spacing[2]);
1316 kbSetModalityVoxelSize =
true;
1326 kVolumeTrans3D = kVolumeTrans3D*sbtranslate;
1334 kVolumeTrans3D = kVolumeTrans3D*sbrotate;
1346 kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ;
1351 kFlagProcessedInteractiveScorer =
true;
1364 if(kFlagParameterization == 0) {
1383 if(volName == box.
GetName()) {
1387 std::vector<G4String>::iterator itr = kNestedVolumeNames.begin();
1388 for(; itr != kNestedVolumeNames.end(); itr++) {
1394 }
else if(kFlagParameterization == 1) {
1405 if(volDSolidName == box.
GetName()) {
1409 }
else if(kFlagParameterization == 2) {
1414 if(bAddDet) AddDetector(box);
1428 if( !IsVisible() ) { return ; }
1443 for(
G4int i = 0; i < nv; i++) {
1452 if (!pv_model) { return ; }
1455 if (!pPVModel) { return ; }
1471 if( !IsVisible() ) { return ; }
1490 if( !IsVisible() ) { return ; }
1508 if( !IsVisible() ) { return ; }
1514 AddDetector(sphere);
1526 if( !IsVisible() ) { return ; }
1544 if( !IsVisible() ) { return ; }
1563 if( !IsVisible() ) { return ; }
1579 if( !IsVisible() ) { return ; }
1599 kbModelingTrajectory =
true;
1604 G4cout <<
" ::AddCompound(const G4VTrajectory&) >>>>>>>>> " <<
G4endl;
1608 (
"G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1622 for(
G4int i = 0; i < nPnt; i++) {
1630 kbModelingTrajectory =
false;
1652 std::vector<G4String> hitNames = kMessenger.
getHitNames();
1654 std::vector<G4String>::iterator itr = hitNames.begin();
1655 for(; itr != hitNames.end(); itr++)
1663 G4bool bid[3] = {
false,
false,
false};
1666 std::vector<G4AttValue>::iterator itr;
1668 for(itr = attval->begin(); itr != attval->end(); itr++) {
1669 std::string stmp = itr->GetValue();
1670 std::istringstream sval(stmp.c_str());
1672 if(itr->GetName() ==
G4String(
"XID")) {
1677 if(itr->GetName() ==
G4String(
"YID")) {
1682 if(itr->GetName() ==
G4String(
"ZID")) {
1691 if(bid[0] && bid[1] && bid[2]) {
1694 G4cout <<
" Hit : index(" <<
id.x <<
", " <<
id.y <<
", "
1695 <<
id.z <<
")" <<
G4endl;
1698 for(itr = attval->begin(); itr != attval->end(); itr++) {
1699 for(
G4int i = 0; i < nhitname; i++) {
1700 if(itr->GetName() == hitNames[i]) {
1702 std::string stmp = itr->GetValue();
1703 std::istringstream sval(stmp.c_str());
1706 sval >> value >> unit;
1708 std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr;
1709 kNestedHitsListItr = kNestedHitsList.find(hitNames[i]);
1710 if(kNestedHitsListItr != kNestedHitsList.end()) {
1713 kNestedHitsListItr->second[id] = value;
1715 std::map<Index3D, G4double> hits;
1716 hits.insert(std::map<Index3D, G4double>::value_type(
id, value));
1717 kNestedHitsList[hitNames[i]] = hits;
1722 G4cout <<
" : " << hitNames[i] <<
" -> " << value
1723 <<
" [" << unit <<
"]" <<
G4endl;
1728 G4Exception(
"G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)",
1744 G4cout <<
" ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " <<
G4endl;
1748 G4int nhitname = (
G4int)hitScorerNames.size();
1766 std::map<G4int, G4double*> * map = hits.
GetMap();
1767 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1768 for(; itr != map->end(); itr++) {
1769 GetNestedVolumeIndex(itr->first, idx);
1770 Index3D id(idx[0], idx[1], idx[2]);
1772 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1773 nestedHitsListItr = kNestedHitsList.find(scorername);
1774 if(nestedHitsListItr != kNestedHitsList.end()) {
1775 nestedHitsListItr->second[id] = *(itr->second);
1777 std::map<Index3D, G4double> hit;
1778 hit.insert(std::map<Index3D, G4double>::value_type(
id, *(itr->second)));
1779 kNestedHitsList[scorername] = hit;
1790 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1792 for(
G4int i = 0; i < nhitname; i++)
1793 if(scorername == hitScorerNames[i])
1794 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1797 << kNestedVolumeDimension[0] <<
" x "
1798 << kNestedVolumeDimension[1] <<
" x "
1799 << kNestedVolumeDimension[2] <<
G4endl;
1802 std::map<G4int, G4double*> * map = hits.
GetMap();
1803 std::map<G4int, G4double*>::const_iterator itr = map->begin();
1804 for(; itr != map->end(); itr++) {
1805 GetNestedVolumeIndex(itr->first,
id);
1806 G4cout <<
"[" << itr->first <<
"] "
1807 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1808 << *(itr->second) <<
", ";
1816 G4cout <<
" ::AddCompound(const std::map<G4int, G4StatDouble*> &) >>>>>>>>> " <<
G4endl;
1820 G4int nhitname = (
G4int)hitScorerNames.size();
1838 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1839 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1840 for(; itr != map->end(); itr++) {
1841 GetNestedVolumeIndex(itr->first, idx);
1842 Index3D id(idx[0], idx[1], idx[2]);
1844 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1845 nestedHitsListItr = kNestedHitsList.find(scorername);
1846 if(nestedHitsListItr != kNestedHitsList.end()) {
1847 nestedHitsListItr->second[id] = itr->second->sum_wx();
1849 std::map<Index3D, G4double> hit;
1850 hit.insert(std::map<Index3D, G4double>::value_type(
id, itr->second->sum_wx()));
1851 kNestedHitsList[scorername] = hit;
1862 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1864 for(
G4int i = 0; i < nhitname; i++)
1865 if(scorername == hitScorerNames[i])
1866 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
G4endl;
1869 << kNestedVolumeDimension[0] <<
" x "
1870 << kNestedVolumeDimension[1] <<
" x "
1871 << kNestedVolumeDimension[2] <<
G4endl;
1874 std::map<G4int, G4StatDouble*> * map = hits.
GetMap();
1875 std::map<G4int, G4StatDouble*>::const_iterator itr = map->begin();
1876 for(; itr != map->end(); itr++) {
1877 GetNestedVolumeIndex(itr->first,
id);
1878 G4cout <<
"[" << itr->first <<
"] "
1879 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1880 << itr->second->sum_wx() <<
", ";
1887G4bool G4GMocrenFileSceneHandler::IsVisible()
1890 G4bool visibility = true ;
1918void G4GMocrenFileSceneHandler::AddDetector(
const G4VSolid & solid) {
1923 detector.name = solid.
GetName();
1925 G4cout <<
"0 Detector name : " << detector.name <<
G4endl;
1928 if (!pv_model) { return ; }
1931 if (!pPVModel) { return ; }
1934 std::vector<G4float *> dedges;
1936 detector.polyhedron = poly;
1940 unsigned char uccolor[3] = {30, 30, 30};
1943 uccolor[0] = (
unsigned char)(color.
GetRed()*255);
1944 uccolor[1] = (
unsigned char)(color.
GetGreen()*255);
1945 uccolor[2] = (
unsigned char)(color.
GetBlue()*255);
1949 for(
G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i];
1951 kDetectors.push_back(detector);
1954 G4cout <<
"0 color: (" << (
G4int)uccolor[0] <<
", "
1955 << (
G4int)uccolor[1] <<
", " << (
G4int)uccolor[2] <<
")"
1962void G4GMocrenFileSceneHandler::ExtractDetector() {
1964 std::vector<Detector>::iterator itr = kDetectors.begin();
1966 for(; itr != kDetectors.end(); itr++) {
1974 std::vector<G4float *> dedges;
1986 if(!(poly->
GetNextEdge(v1, v2, next))) bnext =
false;
1988 edge[0] = v1.
x()/mm;
1989 edge[1] = v1.
y()/mm;
1990 edge[2] = v1.
z()/mm;
1991 edge[3] = v2.
x()/mm;
1992 edge[4] = v2.
y()/mm;
1993 edge[5] = v2.
z()/mm;
1994 dedges.push_back(edge);
1999 unsigned char uccolor[3] = {itr->color[0],
2003 kgMocrenIO->
addDetector(detname, dedges, uccolor);
2004 for(
G4int i = 0; i < nedges; i++) {
2005 delete [] dedges[i];
2010 G4cout <<
" color: (" << (
G4int)uccolor[0] <<
", "
2011 << (
G4int)uccolor[1] <<
", " << (
G4int)uccolor[2] <<
")"
2017void G4GMocrenFileSceneHandler::GetNestedVolumeIndex(
G4int _idx,
G4int _idx3d[3]) {
2018 if(kNestedVolumeDimension[0] == 0 ||
2019 kNestedVolumeDimension[1] == 0 ||
2020 kNestedVolumeDimension[2] == 0) {
2021 for(
G4int i = 0; i < 3; i++) _idx3d[i] = 0;
2026 if(kFlagParameterization == 0) {
2028 G4int plane = kNestedVolumeDimension[2]*kNestedVolumeDimension[1];
2029 G4int line = kNestedVolumeDimension[2];
2041 _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane;
2042 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2043 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line;
2070 G4int plane = kNestedVolumeDimension[0]*kNestedVolumeDimension[1];
2071 G4int line = kNestedVolumeDimension[0];
2072 _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane;
2073 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
2074 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line;
2082G4GMocrenFileSceneHandler::Detector::Detector()
2084 color[0] = color[1] = color[2] = 255;
2086G4GMocrenFileSceneHandler::Detector::~Detector() {
2087 if(!polyhedron)
delete polyhedron;
2089void G4GMocrenFileSceneHandler::Detector::clear() {
2091 if(!polyhedron)
delete polyhedron;
2092 color[0] = color[1] = color[2] = 255;
2097G4GMocrenFileSceneHandler::Index3D::Index3D()
2098 : x(0), y(0), z(0) {
2102G4GMocrenFileSceneHandler::Index3D::Index3D(
const Index3D & _index3D)
2103 : x(_index3D.x), y(_index3D.y), z(_index3D.z) {
2113G4GMocrenFileSceneHandler::Index3D::Index3D(
G4int _x,
G4int _y,
G4int _z)
2114 : x(_x), y(_y), z(_z) {
2117G4bool G4GMocrenFileSceneHandler::Index3D::operator < (
const Index3D & _right)
const {
2118 if(z <
static_cast<Index3D
>(_right).z) {
2120 }
else if(z == _right.z) {
2121 if(y <
static_cast<Index3D
>(_right).y)
return true;
2122 else if(y == _right.y)
2123 if(x <
static_cast<Index3D
>(_right).x)
return true;
2127G4bool G4GMocrenFileSceneHandler::Index3D::operator == (
const Index3D & _right)
const {
2128 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
G4double GetZHalfLength() const
G4double GetXHalfLength() const
G4Polyhedron * CreatePolyhedron() 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
size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4double GetDensity() const
const G4String & GetName() const
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=nullptr)
size_t GetNoVoxelY() const
G4double GetVoxelHalfZ() const
G4double GetVoxelHalfY() const
G4double GetVoxelHalfX() const
size_t GetNoVoxelZ() const
size_t GetNoVoxelX() 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
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
virtual void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const =0
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)