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 // SINGLETON 39 // SINGLETON 40 CellParameterisation * CellParameterisation::g 40 CellParameterisation * CellParameterisation::gInstance = 0; 41 41 42 CellParameterisation::CellParameterisation 42 CellParameterisation::CellParameterisation 43 (G4Material * nucleus1, G4Material * cytoplas 43 (G4Material * nucleus1, G4Material * cytoplasm1, 44 G4Material * nucleus2, G4Material * cytoplas 44 G4Material * nucleus2, G4Material * cytoplasm2, 45 G4Material * nucleus3, G4Material * cytoplas 45 G4Material * nucleus3, G4Material * cytoplasm3 46 ) 46 ) 47 { 47 { 48 fNucleusMaterial1 = nucleus1; 48 fNucleusMaterial1 = nucleus1; 49 fCytoplasmMaterial1 = cytoplasm1; 49 fCytoplasmMaterial1 = cytoplasm1; 50 fNucleusMaterial2 = nucleus2; 50 fNucleusMaterial2 = nucleus2; 51 fCytoplasmMaterial2 = cytoplasm2; 51 fCytoplasmMaterial2 = cytoplasm2; 52 fNucleusMaterial3 = nucleus3; 52 fNucleusMaterial3 = nucleus3; 53 fCytoplasmMaterial3 = cytoplasm3; 53 fCytoplasmMaterial3 = cytoplasm3; 54 54 55 G4int ncols,nlines; 55 G4int ncols,nlines; 56 G4int shiftX, shiftY, shiftZ; 56 G4int shiftX, shiftY, shiftZ; 57 G4double x,y,z,mat,den,tmp,density; 57 G4double x,y,z,mat,den,tmp,density; 58 G4double denCyto1, denCyto2, denCyto3, denN 58 G4double denCyto1, denCyto2, denCyto3, denNucl1, denNucl2, denNucl3; 59 59 60 ncols = nlines = shiftX = shiftY = shiftZ = 60 ncols = nlines = shiftX = shiftY = shiftZ = 0; 61 x = y = z = mat = den = tmp = density = 61 x = y = z = mat = den = tmp = density = 62 denCyto1 = denCyto2 = denCyto3 = denNucl1 62 denCyto1 = denCyto2 = denCyto3 = denNucl1 = denNucl2 = denNucl3 = 0.0; 63 63 64 // READ PHANTOM 64 // READ PHANTOM 65 fNucleusMass = 0; 65 fNucleusMass = 0; 66 fCytoplasmMass = 0; 66 fCytoplasmMass = 0; 67 67 68 fDimCellBoxX = fDimCellBoxY = fDimCellBoxZ 68 fDimCellBoxX = fDimCellBoxY = fDimCellBoxZ = micrometer; 69 69 70 FILE *fMap; 70 FILE *fMap; 71 fMap = fopen("phantom.dat","r"); 71 fMap = fopen("phantom.dat","r"); 72 72 73 while (1) 73 while (1) 74 { 74 { 75 if (nlines == 0) 75 if (nlines == 0) 76 { 76 { 77 ncols = fscanf(fMap,"%i %i %i",&fPhant 77 ncols = fscanf(fMap,"%i %i %i",&fPhantomTotalPixels,&fNucleusTotalPixels,&fCytoplasmTotalPixels); 78 fMapCell = new G4ThreeVector[fPhantomTota 78 fMapCell = new G4ThreeVector[fPhantomTotalPixels]; 79 fMaterial = new G4double[fPhantomTot 79 fMaterial = new G4double[fPhantomTotalPixels]; 80 fMass = new G4double[fPhantomTot 80 fMass = new G4double[fPhantomTotalPixels]; 81 fTissueType = new G4int[fPhantomTotalP 81 fTissueType = new G4int[fPhantomTotalPixels]; 82 } 82 } 83 83 84 if (nlines == 1) 84 if (nlines == 1) 85 { 85 { 86 ncols = fscanf(fMap,"%lf %lf %lf",&fDi 86 ncols = fscanf(fMap,"%lf %lf %lf",&fDimCellBoxX,&fDimCellBoxY,&fDimCellBoxZ); 87 fDimCellBoxX=fDimCellBoxX*micrometer; 87 fDimCellBoxX=fDimCellBoxX*micrometer; 88 fDimCellBoxY=fDimCellBoxY*micrometer; 88 fDimCellBoxY=fDimCellBoxY*micrometer; 89 fDimCellBoxZ=fDimCellBoxZ*micrometer; 89 fDimCellBoxZ=fDimCellBoxZ*micrometer; 90 } 90 } 91 91 92 // VOXEL SHIFT IN Z ASSUMED TO BE NEGATI 92 // VOXEL SHIFT IN Z ASSUMED TO BE NEGATIVE 93 if (nlines == 2) ncols = fscanf(fMap,"%i 93 if (nlines == 2) ncols = fscanf(fMap,"%i %i %i",&shiftX,&shiftY,&shiftZ); 94 94 95 if (nlines == 3) ncols = fscanf(fMap,"%l 95 if (nlines == 3) ncols = fscanf(fMap,"%lf %lf %lf",&denCyto1, &denCyto2, &denCyto3); 96 96 97 if (nlines == 4) ncols = fscanf(fMap,"%l 97 if (nlines == 4) ncols = fscanf(fMap,"%lf %lf %lf",&denNucl1, &denNucl2, &denNucl3); 98 98 99 if (nlines > 4) ncols = fscanf(fMap,"%l 99 if (nlines > 4) ncols = fscanf(fMap,"%lf %lf %lf %lf %lf %lf",&x,&y,&z,&mat,&den,&tmp); 100 100 101 if (ncols < 0) break; 101 if (ncols < 0) break; 102 102 103 // VOXEL SHIFT IN ORDER TO CENTER PHANTO 103 // VOXEL SHIFT IN ORDER TO CENTER PHANTOM 104 G4ThreeVector v(x+shiftX,y+shiftY,z-1500 104 G4ThreeVector v(x+shiftX,y+shiftY,z-1500/(fDimCellBoxZ/micrometer)-shiftZ); 105 if (nlines>4) 105 if (nlines>4) 106 { 106 { 107 107 108 fMapCell[nlines-5]=v; 108 fMapCell[nlines-5]=v; 109 fMaterial[nlines-5]=mat; 109 fMaterial[nlines-5]=mat; 110 fMass[nlines-5]=den; 110 fMass[nlines-5]=den; 111 111 112 // fTissueType: 1 is Cytoplasm - 2 is Nucl 112 // fTissueType: 1 is Cytoplasm - 2 is Nucleus 113 113 114 if( fMaterial[nlines-5] == 2 ) // fM 114 if( fMaterial[nlines-5] == 2 ) // fMaterial 2 is nucleus 115 { 115 { 116 if( fMass[nlines-5] == 1 ) 116 if( fMass[nlines-5] == 1 ) 117 { 117 { 118 fTissueType[nlines-5]=2; 118 fTissueType[nlines-5]=2; 119 } 119 } 120 if( fMass[nlines-5] == 2 ) 120 if( fMass[nlines-5] == 2 ) 121 { 121 { 122 fTissueType[nlines-5]=2; 122 fTissueType[nlines-5]=2; 123 } 123 } 124 if( fMass[nlines-5] == 3 ) 124 if( fMass[nlines-5] == 3 ) 125 { 125 { 126 fTissueType[nlines-5]=2; 126 fTissueType[nlines-5]=2; 127 } 127 } 128 } 128 } 129 129 130 else if( fMaterial[nlines-5] == 1 ) 130 else if( fMaterial[nlines-5] == 1 ) // fMaterial 1 is cytoplasm 131 { 131 { 132 if( fMass[nlines-5] == 1 ) 132 if( fMass[nlines-5] == 1 ) 133 { 133 { 134 fTissueType[nlines-5]=1; 134 fTissueType[nlines-5]=1; 135 } 135 } 136 if( fMass[nlines-5] == 2 ) 136 if( fMass[nlines-5] == 2 ) 137 { 137 { 138 fTissueType[nlines-5]=2; 138 fTissueType[nlines-5]=2; 139 } 139 } 140 if( fMass[nlines-5] == 3 ) 140 if( fMass[nlines-5] == 3 ) 141 { 141 { 142 fTissueType[nlines-5]=1; 142 fTissueType[nlines-5]=1; 143 } 143 } 144 } 144 } 145 145 146 // 146 // 147 147 148 if (std::abs(mat-2)<1.e-30) // NUCLEUS 148 if (std::abs(mat-2)<1.e-30) // NUCLEUS 149 { 149 { 150 if (std::abs(den-1)<1.e-30) density = de 150 if (std::abs(den-1)<1.e-30) density = denNucl1*(g/cm3); 151 if (std::abs(den-2)<1.e-30) density = de 151 if (std::abs(den-2)<1.e-30) density = denNucl2*(g/cm3); 152 if (std::abs(den-3)<1.e-30) density = de 152 if (std::abs(den-3)<1.e-30) density = denNucl3*(g/cm3); 153 fNucleusMass = fNucleusMass + densit 153 fNucleusMass = fNucleusMass + density * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ ; 154 } 154 } 155 155 156 if (std::abs(mat-1)<1.e-30) // CYTOP 156 if (std::abs(mat-1)<1.e-30) // CYTOPLASM 157 { 157 { 158 if (std::abs(den-1)<1e-30) density = den 158 if (std::abs(den-1)<1e-30) density = denCyto1*(g/cm3); 159 if (std::abs(den-2)<1e-30) density = den 159 if (std::abs(den-2)<1e-30) density = denCyto2*(g/cm3); 160 if (std::abs(den-3)<1e-30) density = den 160 if (std::abs(den-3)<1e-30) density = denCyto3*(g/cm3); 161 fCytoplasmMass = fCytoplasmMass + densit 161 fCytoplasmMass = fCytoplasmMass + density * fDimCellBoxX * fDimCellBoxY * fDimCellBoxZ ; 162 } 162 } 163 163 164 } 164 } 165 165 166 nlines++; 166 nlines++; 167 } 167 } 168 fclose(fMap); 168 fclose(fMap); 169 169 170 // NUCLEUS IN GREEN 170 // NUCLEUS IN GREEN 171 171 172 fNucleusAttributes1 = new G4VisAttributes; 172 fNucleusAttributes1 = new G4VisAttributes; 173 fNucleusAttributes1->SetColour(G4Colour(0,.8 173 fNucleusAttributes1->SetColour(G4Colour(0,.8,0)); 174 fNucleusAttributes1->SetForceSolid(false); 174 fNucleusAttributes1->SetForceSolid(false); 175 175 176 fNucleusAttributes2 = new G4VisAttributes; 176 fNucleusAttributes2 = new G4VisAttributes; 177 fNucleusAttributes2->SetColour(G4Colour(0,.9 177 fNucleusAttributes2->SetColour(G4Colour(0,.9,0)); 178 fNucleusAttributes2->SetForceSolid(false); 178 fNucleusAttributes2->SetForceSolid(false); 179 179 180 fNucleusAttributes3 = new G4VisAttributes; 180 fNucleusAttributes3 = new G4VisAttributes; 181 fNucleusAttributes3->SetColour(G4Colour(0,1, 181 fNucleusAttributes3->SetColour(G4Colour(0,1,0)); 182 fNucleusAttributes3->SetForceSolid(false); 182 fNucleusAttributes3->SetForceSolid(false); 183 183 184 // CYTOPLASM IN RED 184 // CYTOPLASM IN RED 185 185 186 fCytoplasmAttributes1 = new G4VisAttributes; 186 fCytoplasmAttributes1 = new G4VisAttributes; 187 fCytoplasmAttributes1->SetColour(G4Colour(1, 187 fCytoplasmAttributes1->SetColour(G4Colour(1,0,0)); 188 fCytoplasmAttributes1->SetForceSolid(false); 188 fCytoplasmAttributes1->SetForceSolid(false); 189 189 190 fCytoplasmAttributes2 = new G4VisAttributes; 190 fCytoplasmAttributes2 = new G4VisAttributes; // nucleoli in yellow 191 fCytoplasmAttributes2->SetColour(G4Colour(1. 191 fCytoplasmAttributes2->SetColour(G4Colour(1.,1.,0)); 192 fCytoplasmAttributes2->SetForceSolid(false); 192 fCytoplasmAttributes2->SetForceSolid(false); 193 193 194 fCytoplasmAttributes3 = new G4VisAttributes; 194 fCytoplasmAttributes3 = new G4VisAttributes; 195 fCytoplasmAttributes3->SetColour(G4Colour(1, 195 fCytoplasmAttributes3->SetColour(G4Colour(1,0,0)); 196 fCytoplasmAttributes3->SetForceSolid(false); 196 fCytoplasmAttributes3->SetForceSolid(false); 197 197 198 // 198 // 199 gInstance = this; 199 gInstance = this; 200 } 200 } 201 201 202 CellParameterisation::~CellParameterisation() 202 CellParameterisation::~CellParameterisation() 203 { 203 { 204 delete[] fMapCell; 204 delete[] fMapCell; 205 delete[] fMaterial; 205 delete[] fMaterial; 206 delete[] fMass; 206 delete[] fMass; 207 delete[] fTissueType; 207 delete[] fTissueType; 208 } 208 } 209 209 210 void CellParameterisation::ComputeTransformati 210 void CellParameterisation::ComputeTransformation 211 (const G4int copyNo, G4VPhysicalVolume* physVo 211 (const G4int copyNo, G4VPhysicalVolume* physVol) const 212 { 212 { 213 G4ThreeVector origin 213 G4ThreeVector origin 214 ( 214 ( 215 fMapCell[copyNo].x()*fDimCellBoxX, 215 fMapCell[copyNo].x()*fDimCellBoxX, 216 fMapCell[copyNo].y()*fDimCellBoxY, 216 fMapCell[copyNo].y()*fDimCellBoxY, 217 fMapCell[copyNo].z()*fDimCellBoxZ 217 fMapCell[copyNo].z()*fDimCellBoxZ 218 ); 218 ); 219 219 220 physVol->SetTranslation(origin); 220 physVol->SetTranslation(origin); 221 } 221 } 222 222 223 void CellParameterisation::ComputeDimensions 223 void CellParameterisation::ComputeDimensions 224 (G4Box&, const G4int, const G4VPhysicalVolume* 224 (G4Box&, const G4int, const G4VPhysicalVolume*) const 225 {} 225 {} 226 226 227 G4Material* 227 G4Material* 228 CellParameterisation::ComputeMaterial(const G4 228 CellParameterisation::ComputeMaterial(const G4int copyNo, 229 G4VPhysi 229 G4VPhysicalVolume* physVol, 230 const G4 230 const G4VTouchable*) 231 { 231 { 232 if( fMaterial[copyNo] == 2 ) // fMaterial 232 if( fMaterial[copyNo] == 2 ) // fMaterial 2 is nucleus 233 { 233 { 234 if( fMass[copyNo] == 1 ) 234 if( fMass[copyNo] == 1 ) 235 { 235 { 236 physVol->GetLogicalVolume()->SetVisAttri 236 physVol->GetLogicalVolume()->SetVisAttributes( fNucleusAttributes1 ); 237 return fNucleusMaterial1; 237 return fNucleusMaterial1; 238 } 238 } 239 if( fMass[copyNo] == 2 ) 239 if( fMass[copyNo] == 2 ) 240 { 240 { 241 physVol->GetLogicalVolume()->SetVisAttri 241 physVol->GetLogicalVolume()->SetVisAttributes( fNucleusAttributes2 ); 242 return fNucleusMaterial2; 242 return fNucleusMaterial2; 243 } 243 } 244 if( fMass[copyNo] == 3 ) 244 if( fMass[copyNo] == 3 ) 245 { 245 { 246 physVol->GetLogicalVolume()->SetVisAttri 246 physVol->GetLogicalVolume()->SetVisAttributes( fNucleusAttributes3 ); 247 return fNucleusMaterial3; 247 return fNucleusMaterial3; 248 } 248 } 249 } 249 } 250 250 251 else if( fMaterial[copyNo] == 1 ) // fMate 251 else if( fMaterial[copyNo] == 1 ) // fMaterial 1 is cytoplasm 252 { 252 { 253 if( fMass[copyNo] == 1 ) 253 if( fMass[copyNo] == 1 ) 254 { 254 { 255 physVol->GetLogicalVolume()->SetVisAttri 255 physVol->GetLogicalVolume()->SetVisAttributes( fCytoplasmAttributes1 ); 256 return fCytoplasmMaterial1; 256 return fCytoplasmMaterial1; 257 } 257 } 258 if( fMass[copyNo] == 2 ) 258 if( fMass[copyNo] == 2 ) 259 { 259 { 260 // nucleoli so taken as nucleus ! 260 // nucleoli so taken as nucleus ! 261 physVol->GetLogicalVolume()->SetVisAttri 261 physVol->GetLogicalVolume()->SetVisAttributes( fCytoplasmAttributes2 ); 262 return fCytoplasmMaterial2; 262 return fCytoplasmMaterial2; 263 } 263 } 264 if( fMass[copyNo] == 3 ) 264 if( fMass[copyNo] == 3 ) 265 { 265 { 266 physVol->GetLogicalVolume()->SetVisAttri 266 physVol->GetLogicalVolume()->SetVisAttributes( fCytoplasmAttributes3 ); 267 return fCytoplasmMaterial3; 267 return fCytoplasmMaterial3; 268 } 268 } 269 } 269 } 270 270 271 return physVol->GetLogicalVolume()->GetMat 271 return physVol->GetLogicalVolume()->GetMaterial(); 272 } 272 } 273 273