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 ] [ 10.4.p3 ] [ 10.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 ]

Diff markup

Differences between /examples/advanced/ICRP110_HumanPhantoms/src/ICRP110PhantomNestedParameterisation.cc (Version 11.3.0) and /examples/advanced/ICRP110_HumanPhantoms/src/ICRP110PhantomNestedParameterisation.cc (Version 11.2)


  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 // Code developed by:                              26 // Code developed by:
 27 // S.Guatelli, M. Large and A. Malaroda, Unive     27 // S.Guatelli, M. Large and A. Malaroda, University of Wollongong
 28 //                                                 28 //
 29 // Code based on the Geant4 extended example D     29 // Code based on the Geant4 extended example DICOM
 30 //                                                 30 //
 31 //                                                 31 // 
 32                                                    32 
 33 #include "ICRP110PhantomNestedParameterisation     33 #include "ICRP110PhantomNestedParameterisation.hh"
 34 #include "G4VPhysicalVolume.hh"                    34 #include "G4VPhysicalVolume.hh"
 35 #include "G4VTouchable.hh"                         35 #include "G4VTouchable.hh"
 36 #include "G4ThreeVector.hh"                        36 #include "G4ThreeVector.hh"
 37 #include "G4Box.hh"                                37 #include "G4Box.hh"
 38 #include "G4LogicalVolume.hh"                      38 #include "G4LogicalVolume.hh"
 39 #include "G4Material.hh"                           39 #include "G4Material.hh"
 40 #include "G4VisAttributes.hh"                      40 #include "G4VisAttributes.hh"
 41 #include "G4VVisManager.hh"                        41 #include "G4VVisManager.hh"
 42                                                    42 
 43 ICRP110PhantomNestedParameterisation::             43 ICRP110PhantomNestedParameterisation::
 44 ICRP110PhantomNestedParameterisation(const G4T     44 ICRP110PhantomNestedParameterisation(const G4ThreeVector& halfVoxelSize,
 45                                    std::vector     45                                    std::vector<G4Material*>& mat,
 46                                   G4int fnX_,      46                                   G4int fnX_, G4int fnY_, G4int fnZ_)
 47 :                                                  47 :
 48   fdX(halfVoxelSize.x()), fdY(halfVoxelSize.y(     48   fdX(halfVoxelSize.x()), fdY(halfVoxelSize.y()), fdZ(halfVoxelSize.z()), 
 49   fnX(fnX_), fnY(fnY_), fnZ(fnZ_), // number o     49   fnX(fnX_), fnY(fnY_), fnZ(fnZ_), // number of voxels along X, Y and Z
 50   fMaterials(mat), // vector of defined materi     50   fMaterials(mat), // vector of defined materials
 51   fMaterialIndices(nullptr) // vector which as     51   fMaterialIndices(nullptr) // vector which associates MaterialID to voxels
 52 {                                                  52 {
 53  ReadColourData();//Define the color of each m     53  ReadColourData();//Define the color of each material
 54                   // from ColourMap.dat            54                   // from ColourMap.dat
 55 }                                                  55 }
 56                                                    56 
 57 ICRP110PhantomNestedParameterisation::~ICRP110     57 ICRP110PhantomNestedParameterisation::~ICRP110PhantomNestedParameterisation()
 58 {}                                                 58 {}
 59                                                    59  
 60 void ICRP110PhantomNestedParameterisation::Rea     60 void ICRP110PhantomNestedParameterisation::ReadColourData()
 61 {                                                  61 {
 62     // By default the tissues are not visible.     62     // By default the tissues are not visible. Then
 63     // the visualisation attributes are define     63     // the visualisation attributes are defined based on 
 64     // ColourMap.dat                               64     // ColourMap.dat 
 65     auto blankAtt = new G4VisAttributes;           65     auto blankAtt = new G4VisAttributes;
 66     blankAtt->SetVisibility( FALSE );              66     blankAtt->SetVisibility( FALSE );
 67     fColours["Default"] = blankAtt;                67     fColours["Default"] = blankAtt;
 68                                                    68 
 69     G4String colourFile = "ColourMap.dat";         69     G4String colourFile = "ColourMap.dat";
 70     G4cout << "Phantom Material Colours set vi     70     G4cout << "Phantom Material Colours set via ColourMap.dat data file " << G4endl;
 71                                                    71 
 72     std::ifstream fin(colourFile.c_str());         72     std::ifstream fin(colourFile.c_str());
 73     G4int nMate;                                   73     G4int nMate;
 74     G4String mateName;                             74     G4String mateName;
 75     G4double cred, cgreen, cblue, copacity;        75     G4double cred, cgreen, cblue, copacity;
 76     fin >> nMate;                                  76     fin >> nMate;
 77     G4VisAttributes* visAtt=nullptr;               77     G4VisAttributes* visAtt=nullptr;
 78                                                    78     
 79     for( G4int ii = 0; ii < nMate; ii++ ){         79     for( G4int ii = 0; ii < nMate; ii++ ){
 80         fin >> mateName >> cred >> cgreen >> c     80         fin >> mateName >> cred >> cgreen >> cblue >> copacity;
 81         G4Colour colour( cred, cgreen, cblue,      81         G4Colour colour( cred, cgreen, cblue, copacity );
 82         visAtt = new G4VisAttributes( colour )     82         visAtt = new G4VisAttributes( colour );
 83         visAtt->SetForceSolid(true);               83         visAtt->SetForceSolid(true);
 84         fColours[mateName] = visAtt;               84         fColours[mateName] = visAtt;
 85        // G4cout << mateName << " colour set :     85        // G4cout << mateName << " colour set :  "  << colour << G4endl;
 86     }                                              86     }
 87 }                                                  87 }
 88                                                    88 
 89 void ICRP110PhantomNestedParameterisation::        89 void ICRP110PhantomNestedParameterisation::
 90 SetNoVoxel( G4int nx, G4int ny, G4int nz )         90 SetNoVoxel( G4int nx, G4int ny, G4int nz )
 91 {                                                  91 {
 92   fnX = nx;                                        92   fnX = nx;
 93   fnY = ny;                                        93   fnY = ny;
 94   fnZ = nz;                                        94   fnZ = nz;
 95 }                                                  95 }
 96                                                    96 
 97 G4Material* ICRP110PhantomNestedParameterisati     97 G4Material* ICRP110PhantomNestedParameterisation::
 98 ComputeMaterial(G4VPhysicalVolume* physVol, co     98 ComputeMaterial(G4VPhysicalVolume* physVol, const G4int iz,
 99                 const G4VTouchable* parentTouc     99                 const G4VTouchable* parentTouch)
100 {                                                 100 {
101     // protection for initialization and vis a    101     // protection for initialization and vis at idle state
102     //                                            102     //
103     if(parentTouch == nullptr)                    103     if(parentTouch == nullptr)
104         return fMaterials[0];                     104         return fMaterials[0];
105                                                   105   
106     // Copy number of voxels.                     106     // Copy number of voxels.
107     // Copy number of X and Y are obtained fro    107     // Copy number of X and Y are obtained from replication number.
108     // Copy number of Z is the copy number of     108     // Copy number of Z is the copy number of current voxel.
109                                                   109   
110     G4int ix = parentTouch -> GetReplicaNumber    110     G4int ix = parentTouch -> GetReplicaNumber(0);
111     G4int iy = parentTouch -> GetReplicaNumber    111     G4int iy = parentTouch -> GetReplicaNumber(1);
112                                                   112 
113     G4int copyID = ix + fnX*iy + fnX*fnY*iz;      113     G4int copyID = ix + fnX*iy + fnX*fnY*iz;
114     //G4cout << "ix: "<< ix << ", iy: " << iy     114     //G4cout << "ix: "<< ix << ", iy: " << iy << ", iz:" << iz<< G4endl;
115     //G4cout << "copyID from the Nested Param:    115     //G4cout << "copyID from the Nested Param: "<< copyID << G4endl;
116                                                   116     
117     //The copyID identifies the voxel             117     //The copyID identifies the voxel    
118     std::size_t matIndex = GetMaterialIndex(co    118     std::size_t matIndex = GetMaterialIndex(copyID); 
119     G4Material* mate = fMaterials[matIndex];      119     G4Material* mate = fMaterials[matIndex];
120                                                   120    
121     if(true && physVol && G4VVisManager::GetCo    121     if(true && physVol && G4VVisManager::GetConcreteInstance()) {
122         G4String mateName = fMaterials.at(matI    122         G4String mateName = fMaterials.at(matIndex)->GetName();
123         std::string::size_type iuu = mateName.    123         std::string::size_type iuu = mateName.find("__");
124                                                   124    
125         if( iuu != std::string::npos ) {          125         if( iuu != std::string::npos ) {
126             mateName = mateName.substr( 0, iuu    126             mateName = mateName.substr( 0, iuu ); // Associate material
127         }                                         127         }
128                                                   128 
129         if(0 < fColours.count(mateName)) {        129         if(0 < fColours.count(mateName)) {
130             physVol -> GetLogicalVolume() ->      130             physVol -> GetLogicalVolume() ->
131             SetVisAttributes(fColours.find(mat    131             SetVisAttributes(fColours.find(mateName)->second);
132         }                                         132         } 
133         else {                                    133         else {
134             physVol->GetLogicalVolume() ->        134             physVol->GetLogicalVolume() ->
135             SetVisAttributes(fColours.begin()     135             SetVisAttributes(fColours.begin() ->second); // Associate color
136         }                                         136         }
137     }                                             137     }
138   physVol -> GetLogicalVolume()->SetMaterial(m    138   physVol -> GetLogicalVolume()->SetMaterial(mate);
139                                                   139      
140     return mate;                                  140     return mate;
141 }                                                 141 }
142                                                   142 
143 G4int ICRP110PhantomNestedParameterisation::Ge    143 G4int ICRP110PhantomNestedParameterisation::GetMaterialIndex( G4int copyNo ) const
144 {                                                 144 {
145   return fMaterialIndices[copyNo];                145   return fMaterialIndices[copyNo];
146 }                                                 146 }
147                                                   147 
148 G4int ICRP110PhantomNestedParameterisation::Ge    148 G4int ICRP110PhantomNestedParameterisation::GetNumberOfMaterials() const
149 {                                                 149 {
150     return fMaterials.size();                     150     return fMaterials.size();
151 }                                                 151 }
152                                                   152 
153 G4Material* ICRP110PhantomNestedParameterisati    153 G4Material* ICRP110PhantomNestedParameterisation::GetMaterial(G4int i) const
154 {                                                 154 {
155     return fMaterials[i];                         155     return fMaterials[i];
156 }                                                 156 }
157                                                   157 
158 void ICRP110PhantomNestedParameterisation::       158 void ICRP110PhantomNestedParameterisation::
159 ComputeTransformation(const G4int copyNo, G4VP    159 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const
160 {                                                 160 {
161     // Position of voxels.                        161     // Position of voxels.
162     // x and y positions are already defined i    162     // x and y positions are already defined in DetectorConstruction by using
163     // replicated volume. Hre we define the po    163     // replicated volume. Hre we define the position along the z axis of voxels.
164                                                   164 
165     physVol -> SetTranslation(G4ThreeVector(0.    165     physVol -> SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo)
166                                                   166                                                 +1.)*fdZ - fdZ*fnZ)); 
167 }                                                 167 }
168                                                   168 
169 void ICRP110PhantomNestedParameterisation::       169 void ICRP110PhantomNestedParameterisation::
170 ComputeDimensions( G4Box& box, const G4int, co    170 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const
171 {                                                 171 {
172     box.SetXHalfLength(fdX);                      172     box.SetXHalfLength(fdX);
173     box.SetYHalfLength(fdY);                      173     box.SetYHalfLength(fdY);
174     box.SetZHalfLength(fdZ);                      174     box.SetZHalfLength(fdZ);
175 }                                                 175 }
176                                                   176