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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

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