Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // This example is provided by the Geant4-DNA 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained us 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collabo 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 37 (2010) 4692-4708 29 // Med. Phys. 37 (2010) 4692-4708 30 // The Geant4-DNA web site is available at htt 30 // The Geant4-DNA web site is available at http://geant4-dna.org 31 // 31 // 32 // If you use this example, please cite the fo 32 // If you use this example, please cite the following publication: 33 // Rad. Prot. Dos. 133 (2009) 2-11 33 // Rad. Prot. Dos. 133 (2009) 2-11 34 34 35 #include "CellParameterisation.hh" 35 #include "CellParameterisation.hh" 36 #include "G4LogicalVolume.hh" 36 #include "G4LogicalVolume.hh" 37 #include "G4SystemOfUnits.hh" 37 #include "G4SystemOfUnits.hh" 38 38 >> 39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 40 39 // SINGLETON 41 // SINGLETON 40 CellParameterisation * CellParameterisation::g 42 CellParameterisation * CellParameterisation::gInstance = 0; 41 43 >> 44 42 CellParameterisation::CellParameterisation 45 CellParameterisation::CellParameterisation 43 (G4Material * nucleus1, G4Material * cytoplas 46 (G4Material * nucleus1, G4Material * cytoplasm1, 44 G4Material * nucleus2, G4Material * cytoplas 47 G4Material * nucleus2, G4Material * cytoplasm2, 45 G4Material * nucleus3, G4Material * cytoplas 48 G4Material * nucleus3, G4Material * cytoplasm3 46 ) 49 ) 47 { 50 { 48 fNucleusMaterial1 = nucleus1; 51 fNucleusMaterial1 = nucleus1; 49 fCytoplasmMaterial1 = cytoplasm1; 52 fCytoplasmMaterial1 = cytoplasm1; 50 fNucleusMaterial2 = nucleus2; 53 fNucleusMaterial2 = nucleus2; 51 fCytoplasmMaterial2 = cytoplasm2; 54 fCytoplasmMaterial2 = cytoplasm2; 52 fNucleusMaterial3 = nucleus3; 55 fNucleusMaterial3 = nucleus3; 53 fCytoplasmMaterial3 = cytoplasm3; 56 fCytoplasmMaterial3 = cytoplasm3; 54 57 55 G4int ncols,nlines; 58 G4int ncols,nlines; 56 G4int shiftX, shiftY, shiftZ; 59 G4int shiftX, shiftY, shiftZ; 57 G4double x,y,z,mat,den,tmp,density; 60 G4double x,y,z,mat,den,tmp,density; 58 G4double denCyto1, denCyto2, denCyto3, denN 61 G4double denCyto1, denCyto2, denCyto3, denNucl1, denNucl2, denNucl3; 59 << 60 ncols = nlines = shiftX = shiftY = shiftZ = << 61 x = y = z = mat = den = tmp = density = << 62 denCyto1 = denCyto2 = denCyto3 = denNucl1 << 63 62 64 // READ PHANTOM << 63 density=0; >> 64 denCyto1=0; >> 65 denCyto2=0; >> 66 denCyto3=0; >> 67 denNucl1=0; >> 68 denNucl2=0; >> 69 denNucl3=0; >> 70 >> 71 ncols=0; nlines=0; >> 72 >> 73 // READ PHANTOM >> 74 65 fNucleusMass = 0; 75 fNucleusMass = 0; 66 fCytoplasmMass = 0; 76 fCytoplasmMass = 0; 67 << 68 fDimCellBoxX = fDimCellBoxY = fDimCellBoxZ << 69 77 70 FILE *fMap; 78 FILE *fMap; 71 fMap = fopen("phantom.dat","r"); 79 fMap = fopen("phantom.dat","r"); 72 80 73 while (1) 81 while (1) 74 { 82 { 75 if (nlines == 0) 83 if (nlines == 0) 76 { 84 { 77 ncols = fscanf(fMap,"%i %i %i",&fPhant 85 ncols = fscanf(fMap,"%i %i %i",&fPhantomTotalPixels,&fNucleusTotalPixels,&fCytoplasmTotalPixels); 78 fMapCell = new G4ThreeVector[fPhantomTota 86 fMapCell = new G4ThreeVector[fPhantomTotalPixels]; 79 fMaterial = new G4double[fPhantomTot 87 fMaterial = new G4double[fPhantomTotalPixels]; 80 fMass = new G4double[fPhantomTot 88 fMass = new G4double[fPhantomTotalPixels]; 81 fTissueType = new G4int[fPhantomTotalP 89 fTissueType = new G4int[fPhantomTotalPixels]; 82 } 90 } 83 91 84 if (nlines == 1) 92 if (nlines == 1) 85 { 93 { 86 ncols = fscanf(fMap,"%lf %lf %lf",&fDi << 94 ncols = fscanf(fMap,"%lf %lf %lf",&fDimCellBoxX,&fDimCellBoxY,&fDimCellBoxZ); >> 95 87 fDimCellBoxX=fDimCellBoxX*micrometer; 96 fDimCellBoxX=fDimCellBoxX*micrometer; 88 fDimCellBoxY=fDimCellBoxY*micrometer; 97 fDimCellBoxY=fDimCellBoxY*micrometer; 89 fDimCellBoxZ=fDimCellBoxZ*micrometer; 98 fDimCellBoxZ=fDimCellBoxZ*micrometer; 90 } 99 } 91 100 92 // VOXEL SHIFT IN Z ASSUMED TO BE NEGATI << 101 if (nlines == 2) ncols = fscanf(fMap,"%i %i %i",&shiftX,&shiftY,&shiftZ); // VOXEL SHIFT IN Z ASSUMED TO BE NEGATIVE 93 if (nlines == 2) ncols = fscanf(fMap,"%i << 94 102 95 if (nlines == 3) ncols = fscanf(fMap,"%l 103 if (nlines == 3) ncols = fscanf(fMap,"%lf %lf %lf",&denCyto1, &denCyto2, &denCyto3); 96 104 97 if (nlines == 4) ncols = fscanf(fMap,"%l 105 if (nlines == 4) ncols = fscanf(fMap,"%lf %lf %lf",&denNucl1, &denNucl2, &denNucl3); 98 106 99 if (nlines > 4) ncols = fscanf(fMap,"%l 107 if (nlines > 4) ncols = fscanf(fMap,"%lf %lf %lf %lf %lf %lf",&x,&y,&z,&mat,&den,&tmp); 100 108 101 if (ncols < 0) break; 109 if (ncols < 0) break; 102 110 103 // VOXEL SHIFT IN ORDER TO CENTER PHANTO << 111 G4ThreeVector v(x+shiftX,y+shiftY,z-1500/(fDimCellBoxZ/micrometer)-shiftZ); // VOXEL SHIFT IN ORDER TO CENTER PHANTOM 104 G4ThreeVector v(x+shiftX,y+shiftY,z-1500 << 112 105 if (nlines>4) 113 if (nlines>4) 106 { 114 { 107 115 108 fMapCell[nlines-5]=v; 116 fMapCell[nlines-5]=v; 109 fMaterial[nlines-5]=mat; 117 fMaterial[nlines-5]=mat; 110 fMass[nlines-5]=den; 118 fMass[nlines-5]=den; 111 119 112 // fTissueType: 1 is Cytoplasm - 2 is Nucl 120 // fTissueType: 1 is Cytoplasm - 2 is Nucleus 113 121 114 if( fMaterial[nlines-5] == 2 ) // fM 122 if( fMaterial[nlines-5] == 2 ) // fMaterial 2 is nucleus 115 { 123 { 116 if( fMass[nlines-5] == 1 ) 124 if( fMass[nlines-5] == 1 ) 117 { 125 { 118 fTissueType[nlines-5]=2; 126 fTissueType[nlines-5]=2; 119 } 127 } 120 if( fMass[nlines-5] == 2 ) 128 if( fMass[nlines-5] == 2 ) 121 { 129 { 122 fTissueType[nlines-5]=2; 130 fTissueType[nlines-5]=2; 123 } 131 } 124 if( fMass[nlines-5] == 3 ) 132 if( fMass[nlines-5] == 3 ) 125 { 133 { 126 fTissueType[nlines-5]=2; 134 fTissueType[nlines-5]=2; 127 } 135 } 128 } 136 } 129 137 130 else if( fMaterial[nlines-5] == 1 ) 138 else if( fMaterial[nlines-5] == 1 ) // fMaterial 1 is cytoplasm 131 { 139 { 132 if( fMass[nlines-5] == 1 ) 140 if( fMass[nlines-5] == 1 ) 133 { 141 { 134 fTissueType[nlines-5]=1; 142 fTissueType[nlines-5]=1; 135 } 143 } 136 if( fMass[nlines-5] == 2 ) 144 if( fMass[nlines-5] == 2 ) 137 { 145 { 138 fTissueType[nlines-5]=2; 146 fTissueType[nlines-5]=2; 139 } 147 } 140 if( fMass[nlines-5] == 3 ) 148 if( fMass[nlines-5] == 3 ) 141 { 149 { 142 fTissueType[nlines-5]=1; 150 fTissueType[nlines-5]=1; 143 } 151 } 144 } 152 } 145 153 146 // 154 // 147 155 148 if (std::abs(mat-2)<1.e-30) // NUCLEUS 156 if (std::abs(mat-2)<1.e-30) // NUCLEUS 149 { 157 { 150 if (std::abs(den-1)<1.e-30) density = de 158 if (std::abs(den-1)<1.e-30) density = denNucl1*(g/cm3); 151 if (std::abs(den-2)<1.e-30) density = de 159 if (std::abs(den-2)<1.e-30) density = denNucl2*(g/cm3); 152 if (std::abs(den-3)<1.e-30) density = de 160 if (std::abs(den-3)<1.e-30) density = denNucl3*(g/cm3); 153 fNucleusMass = fNucleusMass + densit 161 fNucleusMass = fNucleusMass + density * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ ; 154 } 162 } 155 163 156 if (std::abs(mat-1)<1.e-30) // CYTOP 164 if (std::abs(mat-1)<1.e-30) // CYTOPLASM 157 { 165 { 158 if (std::abs(den-1)<1e-30) density = den 166 if (std::abs(den-1)<1e-30) density = denCyto1*(g/cm3); 159 if (std::abs(den-2)<1e-30) density = den 167 if (std::abs(den-2)<1e-30) density = denCyto2*(g/cm3); 160 if (std::abs(den-3)<1e-30) density = den 168 if (std::abs(den-3)<1e-30) density = denCyto3*(g/cm3); 161 fCytoplasmMass = fCytoplasmMass + densit 169 fCytoplasmMass = fCytoplasmMass + density * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ ; 162 } 170 } 163 171 164 } 172 } 165 173 166 nlines++; 174 nlines++; 167 } 175 } 168 fclose(fMap); 176 fclose(fMap); 169 177 170 // NUCLEUS IN GREEN 178 // NUCLEUS IN GREEN 171 179 172 fNucleusAttributes1 = new G4VisAttributes; 180 fNucleusAttributes1 = new G4VisAttributes; 173 fNucleusAttributes1->SetColour(G4Colour(0,.8 181 fNucleusAttributes1->SetColour(G4Colour(0,.8,0)); 174 fNucleusAttributes1->SetForceSolid(false); 182 fNucleusAttributes1->SetForceSolid(false); 175 183 176 fNucleusAttributes2 = new G4VisAttributes; 184 fNucleusAttributes2 = new G4VisAttributes; 177 fNucleusAttributes2->SetColour(G4Colour(0,.9 185 fNucleusAttributes2->SetColour(G4Colour(0,.9,0)); 178 fNucleusAttributes2->SetForceSolid(false); 186 fNucleusAttributes2->SetForceSolid(false); 179 187 180 fNucleusAttributes3 = new G4VisAttributes; 188 fNucleusAttributes3 = new G4VisAttributes; 181 fNucleusAttributes3->SetColour(G4Colour(0,1, 189 fNucleusAttributes3->SetColour(G4Colour(0,1,0)); 182 fNucleusAttributes3->SetForceSolid(false); 190 fNucleusAttributes3->SetForceSolid(false); 183 191 184 // CYTOPLASM IN RED 192 // CYTOPLASM IN RED 185 193 186 fCytoplasmAttributes1 = new G4VisAttributes; 194 fCytoplasmAttributes1 = new G4VisAttributes; 187 fCytoplasmAttributes1->SetColour(G4Colour(1, 195 fCytoplasmAttributes1->SetColour(G4Colour(1,0,0)); 188 fCytoplasmAttributes1->SetForceSolid(false); 196 fCytoplasmAttributes1->SetForceSolid(false); 189 197 190 fCytoplasmAttributes2 = new G4VisAttributes; 198 fCytoplasmAttributes2 = new G4VisAttributes; // nucleoli in yellow 191 fCytoplasmAttributes2->SetColour(G4Colour(1. 199 fCytoplasmAttributes2->SetColour(G4Colour(1.,1.,0)); 192 fCytoplasmAttributes2->SetForceSolid(false); 200 fCytoplasmAttributes2->SetForceSolid(false); 193 201 194 fCytoplasmAttributes3 = new G4VisAttributes; 202 fCytoplasmAttributes3 = new G4VisAttributes; 195 fCytoplasmAttributes3->SetColour(G4Colour(1, 203 fCytoplasmAttributes3->SetColour(G4Colour(1,0,0)); 196 fCytoplasmAttributes3->SetForceSolid(false); 204 fCytoplasmAttributes3->SetForceSolid(false); 197 205 198 // 206 // >> 207 199 gInstance = this; 208 gInstance = this; >> 209 200 } 210 } 201 211 >> 212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 213 202 CellParameterisation::~CellParameterisation() 214 CellParameterisation::~CellParameterisation() 203 { 215 { 204 delete[] fMapCell; 216 delete[] fMapCell; 205 delete[] fMaterial; 217 delete[] fMaterial; 206 delete[] fMass; 218 delete[] fMass; 207 delete[] fTissueType; 219 delete[] fTissueType; 208 } 220 } 209 221 >> 222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 223 210 void CellParameterisation::ComputeTransformati 224 void CellParameterisation::ComputeTransformation 211 (const G4int copyNo, G4VPhysicalVolume* physVo 225 (const G4int copyNo, G4VPhysicalVolume* physVol) const 212 { 226 { 213 G4ThreeVector origin 227 G4ThreeVector origin 214 ( 228 ( 215 fMapCell[copyNo].x()*fDimCellBoxX, 229 fMapCell[copyNo].x()*fDimCellBoxX, 216 fMapCell[copyNo].y()*fDimCellBoxY, 230 fMapCell[copyNo].y()*fDimCellBoxY, 217 fMapCell[copyNo].z()*fDimCellBoxZ 231 fMapCell[copyNo].z()*fDimCellBoxZ 218 ); 232 ); 219 233 220 physVol->SetTranslation(origin); 234 physVol->SetTranslation(origin); 221 } 235 } 222 236 >> 237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 238 223 void CellParameterisation::ComputeDimensions 239 void CellParameterisation::ComputeDimensions 224 (G4Box&, const G4int, const G4VPhysicalVolume* 240 (G4Box&, const G4int, const G4VPhysicalVolume*) const 225 {} 241 {} >> 242 >> 243 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 226 244 227 G4Material* 245 G4Material* 228 CellParameterisation::ComputeMaterial(const G4 246 CellParameterisation::ComputeMaterial(const G4int copyNo, 229 G4VPhysi 247 G4VPhysicalVolume* physVol, 230 const G4 248 const G4VTouchable*) 231 { 249 { 232 if( fMaterial[copyNo] == 2 ) // fMaterial 250 if( fMaterial[copyNo] == 2 ) // fMaterial 2 is nucleus 233 { 251 { 234 if( fMass[copyNo] == 1 ) 252 if( fMass[copyNo] == 1 ) 235 { 253 { 236 physVol->GetLogicalVolume()->SetVisAttri 254 physVol->GetLogicalVolume()->SetVisAttributes( fNucleusAttributes1 ); 237 return fNucleusMaterial1; 255 return fNucleusMaterial1; 238 } 256 } 239 if( fMass[copyNo] == 2 ) 257 if( fMass[copyNo] == 2 ) 240 { 258 { 241 physVol->GetLogicalVolume()->SetVisAttri 259 physVol->GetLogicalVolume()->SetVisAttributes( fNucleusAttributes2 ); 242 return fNucleusMaterial2; 260 return fNucleusMaterial2; 243 } 261 } 244 if( fMass[copyNo] == 3 ) 262 if( fMass[copyNo] == 3 ) 245 { 263 { 246 physVol->GetLogicalVolume()->SetVisAttri 264 physVol->GetLogicalVolume()->SetVisAttributes( fNucleusAttributes3 ); 247 return fNucleusMaterial3; 265 return fNucleusMaterial3; 248 } 266 } 249 } 267 } 250 268 251 else if( fMaterial[copyNo] == 1 ) // fMate 269 else if( fMaterial[copyNo] == 1 ) // fMaterial 1 is cytoplasm 252 { 270 { 253 if( fMass[copyNo] == 1 ) 271 if( fMass[copyNo] == 1 ) 254 { 272 { 255 physVol->GetLogicalVolume()->SetVisAttri 273 physVol->GetLogicalVolume()->SetVisAttributes( fCytoplasmAttributes1 ); 256 return fCytoplasmMaterial1; 274 return fCytoplasmMaterial1; 257 } 275 } 258 if( fMass[copyNo] == 2 ) 276 if( fMass[copyNo] == 2 ) 259 { 277 { 260 // nucleoli so taken as nucleus ! 278 // nucleoli so taken as nucleus ! 261 physVol->GetLogicalVolume()->SetVisAttri 279 physVol->GetLogicalVolume()->SetVisAttributes( fCytoplasmAttributes2 ); 262 return fCytoplasmMaterial2; 280 return fCytoplasmMaterial2; 263 } 281 } 264 if( fMass[copyNo] == 3 ) 282 if( fMass[copyNo] == 3 ) 265 { 283 { 266 physVol->GetLogicalVolume()->SetVisAttri 284 physVol->GetLogicalVolume()->SetVisAttributes( fCytoplasmAttributes3 ); 267 return fCytoplasmMaterial3; 285 return fCytoplasmMaterial3; 268 } 286 } 269 } 287 } 270 288 271 return physVol->GetLogicalVolume()->GetMat 289 return physVol->GetLogicalVolume()->GetMaterial(); 272 } 290 } 273 291