Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DicomPhantomZSliceHeader.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 //
28 
29 #include "globals.hh"
30 #include "G4LogicalVolume.hh"
31 #include "G4MaterialTable.hh"
32 #include "G4Material.hh"
33 #include "G4GeometryTolerance.hh"
34 
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 {
40  fNoVoxelX = rhs.GetNoVoxelX();
41  fNoVoxelY = rhs.GetNoVoxelY();
42  fNoVoxelZ = rhs.GetNoVoxelZ();
43  fMinX = rhs.GetMinX();
44  fMaxX = rhs.GetMaxX();
45  fMinY = rhs.GetMinY();
46  fMaxY = rhs.GetMaxY();
47  fMinZ = rhs.GetMinZ();
48  fMaxZ = rhs.GetMaxZ();
49  fMaterialNames = rhs.GetMaterialNames();
50 
51 }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 {
56  //----- Read material indices and names
57  G4int nmate;
58  G4String mateindex;
59  G4String matename;
60  fin >> nmate;
61 #ifdef G4VERBOSE
62  G4cout << " DicomPhantomZSliceHeader reading number of materials " << nmate << G4endl;
63 #endif
64 
65  for( G4int im = 0; im < nmate; im++ ){
66  fin >> mateindex >> matename;
67 #ifdef G4VERBOSE
68  G4cout << " DicomPhantomZSliceHeader reading material " << im << " : " << mateindex << " " << matename << G4endl;
69 #endif
70 
71  if( ! CheckMaterialExists( matename ) ) {
72  G4Exception("DicomPhantomZSliceHeader::DicomPhantomZSliceHeader","A material is found in file that is not built in the C++ code",FatalErrorInArgument,matename.c_str());
73  }
74 
75  fMaterialNames.push_back(matename);
76  }
77 
78  //----- Read number of voxels
79  fin >> fNoVoxelX >> fNoVoxelY >> fNoVoxelZ;
80 #ifdef G4VERBOSE
81  G4cout << " Number of voxels " << fNoVoxelX << " " << fNoVoxelY << " " << fNoVoxelZ << G4endl;
82 #endif
83 
84  //----- Read minimal and maximal extensions (= walls of phantom)
85  fin >> fMinX >> fMaxX;
86  fin >> fMinY >> fMaxY;
87  fin >> fMinZ >> fMaxZ;
88 #ifdef G4VERBOSE
89  G4cout << " Extension in X " << fMinX << " " << fMaxX << G4endl
90  << " Extension in Y " << fMinY << " " << fMaxY << G4endl
91  << " Extension in Z " << fMinZ << " " << fMaxZ << G4endl;
92 #endif
93 
94 }
95 
96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
97 G4bool DicomPhantomZSliceHeader::CheckMaterialExists( const G4String& mateName )
98 {
99  G4bool bFound = FALSE;
100 
102  std::vector<G4Material*>::const_iterator matite;
103  for( matite = matTab->begin(); matite != matTab->end(); matite++ ) {
104  if( (*matite)->GetName() == mateName ) {
105  bFound = TRUE;
106  break;
107  }
108  }
109 
110  return bFound;
111 
112 }
113 
114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 {
117  *this = *this + rhs;
118 }
119 
120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
122 {
123  //----- Check that both slices has the same dimensions
124  if( fNoVoxelX != rhs.GetNoVoxelX()
125  || fNoVoxelY != rhs.GetNoVoxelY() ) {
126  G4cerr << "DicomPhantomZSliceHeader error adding two slice headers: !!! Different number of voxels: "
127  << " X= " << fNoVoxelX << " =? " << rhs.GetNoVoxelX()
128  << " Y= " << fNoVoxelY << " =? " << rhs.GetNoVoxelY()
129  << " Z= " << fNoVoxelZ << " =? " << rhs.GetNoVoxelZ()
130  << G4endl;
131  G4Exception("DicomPhantomZSliceHeader::DicomPhantomZSliceHeader","",FatalErrorInArgument,"");
132  }
133  //----- Check that both slices has the same extensions
134  if( fMinX != rhs.GetMinX() || fMaxX != rhs.GetMaxX()
135  || fMinY != rhs.GetMinY() || fMaxY != rhs.GetMaxY() ) {
136  G4cerr << "DicomPhantomZSliceHeader error adding two slice headers: !!! Different extensions: "
137  << " Xmin= " << fMinX << " =? " << rhs.GetMinX()
138  << " Xmax= " << fMaxX << " =? " << rhs.GetMaxX()
139  << " Ymin= " << fMinY << " =? " << rhs.GetMinY()
140  << " Ymax= " << fMaxY << " =? " << rhs.GetMaxY()
141  << G4endl;
142  G4Exception("DicomPhantomZSliceHeader::operator+","",FatalErrorInArgument,"");
143  }
144 
145  //----- Check that both slices has the same materials
146  std::vector<G4String> fMaterialNames2 = rhs.GetMaterialNames();
147  if( fMaterialNames.size() != fMaterialNames2.size() ) {
148  G4cerr << "DicomPhantomZSliceHeader error adding two slice headers: !!! Different number of materials: " << fMaterialNames.size() << " =? " << fMaterialNames2.size() << G4endl;
149  G4Exception("DicomPhantomZSliceHeader::operator+","",FatalErrorInArgument,"");
150  }
151  for( unsigned int ii = 0; ii < fMaterialNames.size(); ii++ ) {
152  if( fMaterialNames[ii] != fMaterialNames2[ii] ) {
153  G4cerr << "DicomPhantomZSliceHeader error adding two slice headers: !!! Different material number " << ii << " : " << fMaterialNames[ii] << " =? " << fMaterialNames2[ii] << G4endl;
154  G4Exception("DicomPhantomZSliceHeader::operator+","",FatalErrorInArgument,"");
155  }
156  }
157 
158  //----- Check that the slices are contiguous in Z
159  if( std::fabs( fMinZ - rhs.GetMaxZ() ) > G4GeometryTolerance::GetInstance()->GetRadialTolerance() &&
160  std::fabs( fMaxZ - rhs.GetMinZ() ) > G4GeometryTolerance::GetInstance()->GetRadialTolerance() ){
161  G4cerr << "DicomPhantomZSliceHeader error adding two slice headers: !!! Slices are not contiguous in Z "
162  << " Zmin= " << fMinZ << " & " << rhs.GetMinZ()
163  << " Zmax= " << fMaxZ << " & " << rhs.GetMaxZ()
164  << G4endl;
165  G4Exception("DicomPhantomZSliceHeader::operator+","",FatalErrorInArgument,"");
166  }
167 
168  //----- Build slice header copying first one
169  DicomPhantomZSliceHeader temp( *this );
170 
171  //----- Add data from second slice header
172  temp.SetMinZ( std::min( fMinZ, rhs.GetMinZ() ) );
173  temp.SetMaxZ( std::max( fMaxZ, rhs.GetMaxZ() ) );
174  temp.SetNoVoxelZ( fNoVoxelZ + rhs.GetNoVoxelZ() );
175 
176  return temp;
177 }