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) {
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");
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';
195 for(
G4int i = 0; i < 3; i++) {
220 static G4int currentNumber = 0;
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;
241 << std::setw(2) << std::setfill(
'0') << i <<
".wrl";
262 G4cout <<
"======================================================================" <<
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) " ;
302 std::vector<G4float> map;
304 for(
G4int i = minmax[0]; i <= minmax[1]; i++) {
340 std::vector<Detector>::iterator itr =
kDetectors.begin();
359 G4cout <<
"***** (started) (close "
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;
377 if(
GFDEBUG)
G4cout <<
"gMocren-file driver : modality size : "
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];
398 modality[ixy] = -1024;
410 std::map<Index3D, G4double>::iterator hitsItr;
411 std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr =
kNestedHitsList.begin();
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];
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;
476 for(
G4int i = 0; i < 3; i++) trk[i+3] = ya[i];
477 colors[0] = 0; colors[1] = 255; colors[2] = 0;
480 for(
G4int i = 0; i < 3; i++) trk[i+3] = za[i];
481 colors[0] = 0; colors[1] = 0; colors[2] = 255;
490 std::vector<G4float> transformObjects;
491 for(
G4int i = 0; i < 3; i++) {
517 G4cout <<
"***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" <<
G4endl;
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;
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);
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;
845 G4cout <<
"G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
865 for(
G4int i = 0; i < 12; i++) {
868 G4cout <<
" (" << v1.
x() <<
", "
873 << v2.
z() <<
") [" << next <<
"]"
889 if(pScBox != NULL) bMesh =
true;
892 << volName <<
" - " << bMesh <<
G4endl;
897 if (!pv_model) {
return ; }
900 if (!pPVModel) {
return ; }
912 G4cout <<
" density : " << dens <<
" [g/cm3]" <<
G4endl;
931 G4cout <<
"kVolumeTrans3D: " << trans1 << G4endl << rot1 <<
G4endl;
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 )",
962 <<
" # : " << nDaughters[0] <<
G4endl;
966 if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
967 G4cout <<
"# of daughters : "
978 if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 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 )",
1001 <<
" # : " << nDaughters[1]<<
G4endl;
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++) {
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++) {
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]);
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];
1103 static_cast<G4float>(2*xyz[1]),
1104 static_cast<G4float>(2*xyz[2])};
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;
1190 if(phantomPara == NULL) {
1191 G4Exception(
"G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
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;
1219 idx[kNestedVolumeDirAxis[1]] =
n1;
1220 idx[kNestedVolumeDirAxis[2]] = n2;
1221 Index3D i3d(idx[0],idx[1],idx[2]);
1225 G4cout <<
" index: " << idx[0] <<
", " << idx[1] <<
", " << idx[2]
1226 <<
" density: " << dens <<
G4endl;
1277 for(
G4int n1 = 0;
n1 < kNestedVolumeDimension[1];
n1++) {
1278 for(
G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1284 idx[kNestedVolumeDirAxis[1]] =
n1;
1285 idx[kNestedVolumeDirAxis[2]] = n2;
1286 Index3D i3d(idx[0],idx[1],idx[2]);
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 "
1311 static_cast<G4float>(boxSize.
y()*2/nVoxels[1]),
1312 static_cast<G4float>(boxSize.
z()*2/nVoxels[2])};
1383 if(volName == box.
GetName()) {
1405 if(volDSolidName == box.
GetName()) {
1443 for(
G4int i = 0; i < nv; i++) {
1452 if (!pv_model) {
return ; }
1455 if (!pPVModel) {
return ; }
1604 G4cout <<
" ::AddCompound(const G4VTrajectory&) >>>>>>>>> " <<
G4endl;
1608 (
"G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1622 for(
G4int i = 0; i < nPnt; i++) {
1654 std::vector<G4String>::iterator itr = hitNames.begin();
1655 for(; itr != hitNames.end(); itr++)
1656 G4cout <<
" hit name : " << *itr << G4endl;
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;
1713 kNestedHitsListItr->second[id] =
value;
1715 std::map<Index3D, G4double>
hits;
1716 hits.insert(std::map<Index3D, G4double>::value_type(
id, value));
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++) {
1770 Index3D id(idx[0], idx[1], idx[2]);
1772 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1775 nestedHitsListItr->second[id] = *(itr->second);
1777 std::map<Index3D, G4double> hit;
1778 hit.insert(std::map<Index3D, G4double>::value_type(
id, *(itr->second)));
1790 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1792 for(
G4int i = 0; i < nhitname; i++)
1793 if(scorername == hitScorerNames[i])
1794 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
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++) {
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++) {
1842 Index3D id(idx[0], idx[1], idx[2]);
1844 std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
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()));
1862 G4cout <<
" >>>>> " << meshname <<
" : " << scorername <<
G4endl;
1864 for(
G4int i = 0; i < nhitname; i++)
1865 if(scorername == hitScorerNames[i])
1866 G4cout <<
" !!!! Hit scorer !!!! " << scorername <<
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++) {
1878 G4cout <<
"[" << itr->first <<
"] "
1879 <<
"("<<
id[0] <<
"," <<
id[1] <<
"," <<
id[2] <<
")"
1880 << itr->second->sum_wx() <<
", ";
1928 if (!pv_model) {
return ; }
1931 if (!pPVModel) {
return ; }
1934 std::vector<G4float *> dedges;
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];
1954 G4cout <<
"0 color: (" << (
G4int)uccolor[0] <<
", "
1955 << (
G4int)uccolor[1] <<
", " << (
G4int)uccolor[2] <<
")"
1964 std::vector<Detector>::iterator itr =
kDetectors.begin();
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],
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] <<
")"
2021 for(
G4int i = 0; i < 3; i++) _idx3d[i] = 0;
2029 G4int line = kNestedVolumeDimension[2];
2042 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%
plane)/line;
2043 _idx3d[kNestedVolumeDirAxis[2]] = (_idx%
plane)%line;
2071 G4int line = kNestedVolumeDimension[0];
2073 _idx3d[kNestedVolumeDirAxis[1]] = (_idx%
plane)/line;
2074 _idx3d[kNestedVolumeDirAxis[0]] = (_idx%
plane)%line;
2087 if(!polyhedron)
delete polyhedron;
2091 if(!polyhedron)
delete polyhedron;
2098 :
x(0),
y(0),
z(0) {
2103 :
x(_index3D.
x),
y(_index3D.
y),
z(_index3D.
z) {
2114 :
x(_x),
y(_y),
z(_z) {
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;
2128 if(
z == _right.
z &&
y == _right.
y &&
x == _right.
x)
return true;