33 #include "dcmtk/dcmdata/dcdeftag.h"
62 std::vector<G4String> wl;
68 if( wl[0] ==
":COMPRESSION" ) {
71 }
else if( wl[0] ==
":FILE" ) {
75 }
else if( wl[0] ==
":FILE_OUT" ) {
78 }
else if( wl[0] ==
":MATE_DENS" ) {
81 }
else if( wl[0] ==
":MATE" ) {
84 }
else if( wl[0] ==
":CT2D" ) {
91 G4String(
"UNKNOWN TAG IN FILE "+wl[0]).c_str());
105 if( wl.size() != vsizeTh ) {
107 for(
size_t ii = 0; ii < wl.size(); ii++){
114 (
"Wrong number of columns in line " +
std::to_string(wl.size()) +
" <> "
131 if( ! (dfile.loadFile(fileName.c_str())).good() ) {
135 (
"Error reading file " + fileName).c_str());
137 DcmDataset* dset = dfile.getDataset();
140 if( !dset->findAndGetOFString(DCM_Modality,dModality).good() ) {
144 " Have not read Modality");
147 if( dModality ==
"CT" ) {
153 }
else if( dModality ==
"RTSTRUCT" ) {
159 }
else if( dModality ==
"RTPLAN" ) {
165 }
else if( dModality ==
"PT" ) {
176 (
G4String(
"File is not of type CT or RTSTRUCT or RTPLAN, but: ")
177 + dModality).c_str());
189 "Trying to add a Material with :MATE and another with :MATE_DENS, check your input file");
202 "Trying to add a Material with :MATE and another with :MATE_DENS, check your input file");
223 "No :CT2D line in input file");
225 std::map<G4int,G4double>::const_iterator ite =
theCT2Density.begin();
226 G4int minHval = (*ite).first;
227 if(
G4int(Hval) < minHval ) {
231 (
"Hval value too small, change input file "+
std::to_string(Hval) +
" < "
236 G4int maxHval = (*ite).first;
237 if(
G4int(Hval) > maxHval ) {
241 (
"Hval value too big, change CT2Density.dat file "+
std::to_string(Hval) +
" > "
250 std::map<G4int,G4double>::const_iterator itePrev = ite; itePrev--;
252 deltaCT = (*ite).first - (*itePrev).first;
253 deltaDensity = (*ite).second - (*itePrev).second;
256 density = (*ite).second - (((*ite).first-Hval)*deltaDensity/deltaCT );
274 std::map<G4double,G4String>::iterator ite =
theMaterials.upper_bound(Hval);
280 (
"Hounsfiled value too big, change input file "+
std::to_string(Hval) +
" > "
284 size_t dist = std::distance(
theMaterials.begin(), ite );
297 G4Exception(
"DicomFileMgr::GetMaterialIndexByDensity",
300 (
"Density too big, change input file "+
std::to_string(density) +
" > "
317 "No :FILE of type CT in input file");
347 G4cout <<
" DicomFileMgr::Checking CT slices: " << nSlices <<
G4endl;
349 G4bool uniformSliceThickness =
true;
353 mdct::const_iterator ite =
theCTFiles.begin();
365 if(uniformSliceThickness) {
372 mdct::iterator ite1 = ite0; ite1++;
373 mdct::iterator ite2 = ite1; ite2++;
374 for(; ite2 !=
theCTFiles.end(); ++ite0, ++ite1, ++ite2) {
382 G4double real_distance = real_up_distance + real_down_distance;
385 if(std::fabs(real_distance - stated_distance) > 1.
E-9) {
386 unsigned int sliceNum = std::distance(
theCTFiles.begin(),ite1);
387 G4cerr <<
"\tDicomFileMgr::CheckCTSlices - Slice Distance Error in slice [" << sliceNum
388 <<
"]: Distance between this slice and slices up and down = "
390 <<
" <> Slice width = " << stated_distance
393 <<
" DIFFERENCE= " << real_distance - stated_distance
395 G4cerr <<
"!! WARNING: Geant4 will reset slice width so that it extends between "
396 <<
"lower and upper slice " <<
G4endl;
405 if(uniformSliceThickness) {
409 if(static_cast<unsigned int>(std::distance(
theCTFiles.begin(),ite2)+1)==
414 if(uniformSliceThickness) {
428 G4cout <<
" DicomFileMgr::Checking PET slices: " << nSlices <<
G4endl;
430 G4bool uniformSliceThickness =
true;
446 if(uniformSliceThickness) {
453 mdpet::iterator ite1 = ite0; ite1++;
454 mdpet::iterator ite2 = ite1; ite2++;
455 for(; ite2 !=
thePETFiles.end(); ++ite0, ++ite1, ++ite2) {
463 G4double real_distance = real_up_distance + real_down_distance;
466 if(std::fabs(real_distance - stated_distance) > 1.
E-9) {
467 unsigned int sliceNum = std::distance(
thePETFiles.begin(),ite1);
468 G4cerr <<
"\tDicomFileMgr::CheckPETSlices - Slice Distance Error in slice [" << sliceNum
469 <<
"]: Distance between this slice and slices up and down = "
471 <<
" <> Slice width = " << stated_distance
474 <<
" DIFFERENCE= " << real_distance - stated_distance
476 G4cerr <<
"!! WARNING: Geant4 will reset slice width so that it extends between "
477 <<
"lower and upper slice " <<
G4endl;
486 if(uniformSliceThickness) {
490 if(static_cast<unsigned int>(std::distance(
thePETFiles.begin(),ite2)+1)==
495 if(uniformSliceThickness) {
510 mdct::const_iterator ite =
theCTFiles.begin();
512 (*ite).second->BuildMaterials();
522 (*ite).second->BuildActivities();
530 mdct::const_iterator ite =
theCTFiles.begin();
534 (*theCTFileAll) += *((*ite).second);
547 (*thePETFileAll) += *((*ite).second);
555 G4cout <<
" DicomFileMgr::Dumping To Text File " <<
G4endl;
561 std::map<G4double,G4String>::const_iterator ite;
564 fout << ii <<
" \"" << (*ite).second <<
"\"" << std::endl;
568 std::map<G4double,G4String>::const_iterator ite;
571 fout << ii <<
" \"" << (*ite).second <<
"\"" << std::endl;
577 (*itect).second->DumpMateIDsToTextFile(fout);
580 (*itect).second->DumpDensitiesToTextFile(fout);
583 (*itect).second->BuildStructureIDs();
584 (*itect).second->DumpStructureIDsToTextFile(fout);
588 for(
size_t i1 = 0; i1 < dfs.size(); i1++ ){
589 std::vector<DicomROI*> rois = dfs[i1]->GetROIs();
590 for(
size_t i2 = 0; i2 < rois.size(); i2++ ){
591 fout << rois[i2]->GetNumber()+1 <<
" \"" << rois[i2]->GetName() <<
"\"" <<
G4endl;
601 (*itect).second->DumpActivitiesToTextFile(fout);