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()) +
" <> "
115 + std::to_string(vsizeTh)).c_str());
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) +
" < "
232 + std::to_string(minHval)).c_str());
236 G4int maxHval = (*ite).first;
237 if(
G4int(Hval) > maxHval ) {
241 (
"Hval value too big, change CT2Density.dat file "+std::to_string(Hval) +
" > "
242 + std::to_string(maxHval)).c_str());
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 );
262 G4String(
"@@@ Error negative density = " + std::to_string(density) +
" from HV = "
263 + std::to_string(Hval)).c_str());
274 std::map<G4double,G4String>::iterator ite =
theMaterials.upper_bound(Hval);
280 (
"Hounsfiled value too big, change input file "+std::to_string(Hval) +
" > "
281 + std::to_string((*ite).first)).c_str());
284 size_t dist = std::distance(
theMaterials.begin(), ite );
297 G4Exception(
"DicomFileMgr::GetMaterialIndexByDensity",
300 (
"Density too big, change input file "+std::to_string(density) +
" > "
301 + std::to_string((*ite).first)).c_str());
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);
void SetMaxZ(const G4double &val)
static G4double ConvertToDouble(const char *st)
void BuildPETActivities()
void SetMinZ(const G4double &val)
G4int theStructureNMaxROI
static DicomFileMgr * GetInstance()
static DicomFileMgr * theInstance
void SetCompression(G4String fComp)
size_t GetMaterialIndex(G4double Hval)
std::map< G4double, G4String > theMaterialsDensity
void Convert(G4String fFileName)
DicomFilePET * thePETFileAll
void AddMaterialDensity(std::vector< G4String > data)
static G4int ConvertToInt(const char *st)
size_t GetMaterialIndexByDensity(G4double density)
static G4tgrFileIn & GetInstance(const G4String &name)
std::map< G4double, G4String > theMaterials
std::vector< DicomFileStructure * > GetStructFiles() const
void SetFileName(G4String fName)
void AddFile(G4String fComp)
G4GLOB_DLL std::ostream G4cerr
void DumpHeaderToTextFile(std::ofstream &fout)
G4double Hounsfield2density(Uint32 Hval)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void AddCT2Density(std::vector< G4String > data)
std::map< G4int, G4double > theCT2Density
const G4double & GetLocation() const
G4GLOB_DLL std::ostream G4cout
std::vector< DicomFileStructure * > theStructFiles
std::vector< DicomFilePlan * > thePlanFiles
void AddMaterial(std::vector< G4String > data)
G4int GetWordsInLine(std::vector< G4String > &wl)
void CheckNColumns(std::vector< G4String > wl, size_t vsizeTh)
DicomFileCT * theCTFileAll