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