Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DicomFilePET.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 #include "DicomFilePET.hh"
27 #include "DicomFileStructure.hh"
28 #include "DicomROI.hh"
29 
30 #include "G4GeometryTolerance.hh"
31 
32 #include "dcmtk/dcmdata/dcfilefo.h"
33 #include "dcmtk/dcmdata/dcdeftag.h"
34 #include "dcmtk/dcmdata/dcpixel.h"
35 #include "dcmtk/dcmdata/dcpxitem.h"
36 #include "dcmtk/dcmdata/dcpixseq.h"
37 #include "dcmtk/dcmrt/drtimage.h"
38 
39 #include <set>
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 {
44 }
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 {
49 }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 {
54  G4int fCompress = theFileMgr->GetCompression();
55  if( fNoVoxelX%fCompress != 0 || fNoVoxelY%fCompress != 0 ) {
56  G4Exception("DicompFileMgr.:BuildMaterials",
57  "DFC004",
59  ("Compression factor = " + std::to_string(fCompress)
60  + " has to be a divisor of Number of voxels X = " + std::to_string(fNoVoxelX)
61  + " and Y " + std::to_string(fNoVoxelY)).c_str());
62  }
63 
64  // if( DicomVerb(debugVerb) ) G4cout << " BuildMaterials " << fFileName << G4endl;
65  double meanHV = 0.;
66  for( int ir = 0; ir < fNoVoxelY; ir += fCompress ) {
67  for( int ic = 0; ic < fNoVoxelX; ic += fCompress ) {
68  meanHV = 0.;
69  int isumrMax = std::min(ir+fCompress,fNoVoxelY);
70  int isumcMax = std::min(ic+fCompress,fNoVoxelX);
71  for( int isumr = ir; isumr < isumrMax; isumr ++ ) {
72  for( int isumc = ic; isumc < isumcMax; isumc ++ ) {
73  meanHV += fHounsfieldV[isumc+isumr*fNoVoxelX];
74  }
75  }
76  meanHV /= (isumrMax-ir)*(isumcMax-ic);
77  fActivities.push_back(meanHV);
78  }
79  }
80 
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 void DicomFilePET::DumpActivitiesToTextFile(std::ofstream& fout)
85 {
86  G4int fCompress = theFileMgr->GetCompression();
87  if( DicomFileMgr::verbose >= warningVerb ) G4cout << fLocation << " DumpDensitiesToTextFile "
88  << fFileName << " " << fActivities.size() << G4endl;
89 
90  G4int copyNo = 0;
91  for( int ir = 0; ir < fNoVoxelY/fCompress; ir++ ) {
92  for( int ic = 0; ic < fNoVoxelX/fCompress; ic++ ) {
93  fout << fActivities[ic+ir*fNoVoxelX/fCompress];
94  if( ic != fNoVoxelX/fCompress-1) fout << " ";
95  if( copyNo%8 == 7 ) fout << G4endl;
96  copyNo++;
97  }
98  if( copyNo%8 != 0 ) fout << G4endl;
99  }
100 
101 }
102 
G4int GetCompression() const
Definition: DicomFileMgr.hh:91
void BuildActivities()
Definition: DicomFilePET.cc:52
int G4int
Definition: G4Types.hh:78
G4String fFileName
Definition: DicomVFile.hh:55
G4GLOB_DLL std::ostream G4cout
std::vector< int > fHounsfieldV
static int verbose
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
DicomFileMgr * theFileMgr
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
#define G4endl
Definition: G4ios.hh:61
void DumpActivitiesToTextFile(std::ofstream &fout)
Definition: DicomFilePET.cc:84