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 // 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(0) // 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 G4VisAttributes* 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; << 78 << 79 for( G4int ii = 0; ii < nMate; ii++ ){ 77 for( G4int ii = 0; ii < nMate; ii++ ){ 80 fin >> mateName >> cred >> cgreen >> c 78 fin >> mateName >> cred >> cgreen >> cblue >> copacity; 81 G4Colour colour( cred, cgreen, cblue, 79 G4Colour colour( cred, cgreen, cblue, copacity ); 82 visAtt = new G4VisAttributes( colour ) << 80 G4VisAttributes* visAtt = new G4VisAttributes( colour ); 83 visAtt->SetForceSolid(true); 81 visAtt->SetForceSolid(true); 84 fColours[mateName] = visAtt; 82 fColours[mateName] = visAtt; 85 // G4cout << mateName << " colour set : 83 // G4cout << mateName << " colour set : " << colour << G4endl; 86 } 84 } 87 } 85 } 88 86 89 void ICRP110PhantomNestedParameterisation:: 87 void ICRP110PhantomNestedParameterisation:: 90 SetNoVoxel( G4int nx, G4int ny, G4int nz ) 88 SetNoVoxel( G4int nx, G4int ny, G4int nz ) 91 { 89 { 92 fnX = nx; 90 fnX = nx; 93 fnY = ny; 91 fnY = ny; 94 fnZ = nz; 92 fnZ = nz; 95 } 93 } 96 94 97 G4Material* ICRP110PhantomNestedParameterisati 95 G4Material* ICRP110PhantomNestedParameterisation:: 98 ComputeMaterial(G4VPhysicalVolume* physVol, co 96 ComputeMaterial(G4VPhysicalVolume* physVol, const G4int iz, 99 const G4VTouchable* parentTouc 97 const G4VTouchable* parentTouch) 100 { 98 { 101 // protection for initialization and vis a 99 // protection for initialization and vis at idle state 102 // 100 // 103 if(parentTouch == nullptr) 101 if(parentTouch == nullptr) 104 return fMaterials[0]; 102 return fMaterials[0]; 105 103 106 // Copy number of voxels. 104 // Copy number of voxels. 107 // Copy number of X and Y are obtained fro 105 // Copy number of X and Y are obtained from replication number. 108 // Copy number of Z is the copy number of 106 // Copy number of Z is the copy number of current voxel. 109 107 110 G4int ix = parentTouch -> GetReplicaNumber 108 G4int ix = parentTouch -> GetReplicaNumber(0); 111 G4int iy = parentTouch -> GetReplicaNumber 109 G4int iy = parentTouch -> GetReplicaNumber(1); 112 110 113 G4int copyID = ix + fnX*iy + fnX*fnY*iz; 111 G4int copyID = ix + fnX*iy + fnX*fnY*iz; 114 //G4cout << "ix: "<< ix << ", iy: " << iy 112 //G4cout << "ix: "<< ix << ", iy: " << iy << ", iz:" << iz<< G4endl; 115 //G4cout << "copyID from the Nested Param: 113 //G4cout << "copyID from the Nested Param: "<< copyID << G4endl; 116 114 117 //The copyID identifies the voxel 115 //The copyID identifies the voxel 118 std::size_t matIndex = GetMaterialIndex(co 116 std::size_t matIndex = GetMaterialIndex(copyID); 119 G4Material* mate = fMaterials[matIndex]; << 117 static G4Material* mate = nullptr; >> 118 mate = fMaterials[matIndex]; 120 119 121 if(true && physVol && G4VVisManager::GetCo 120 if(true && physVol && G4VVisManager::GetConcreteInstance()) { 122 G4String mateName = fMaterials.at(matI 121 G4String mateName = fMaterials.at(matIndex)->GetName(); 123 std::string::size_type iuu = mateName. 122 std::string::size_type iuu = mateName.find("__"); 124 123 125 if( iuu != std::string::npos ) { 124 if( iuu != std::string::npos ) { 126 mateName = mateName.substr( 0, iuu 125 mateName = mateName.substr( 0, iuu ); // Associate material 127 } 126 } 128 127 129 if(0 < fColours.count(mateName)) { 128 if(0 < fColours.count(mateName)) { 130 physVol -> GetLogicalVolume() -> 129 physVol -> GetLogicalVolume() -> 131 SetVisAttributes(fColours.find(mat 130 SetVisAttributes(fColours.find(mateName)->second); 132 } 131 } 133 else { 132 else { 134 physVol->GetLogicalVolume() -> 133 physVol->GetLogicalVolume() -> 135 SetVisAttributes(fColours.begin() 134 SetVisAttributes(fColours.begin() ->second); // Associate color 136 } 135 } 137 } 136 } 138 physVol -> GetLogicalVolume()->SetMaterial(m 137 physVol -> GetLogicalVolume()->SetMaterial(mate); 139 138 140 return mate; 139 return mate; 141 } 140 } 142 141 143 G4int ICRP110PhantomNestedParameterisation::Ge 142 G4int ICRP110PhantomNestedParameterisation::GetMaterialIndex( G4int copyNo ) const 144 { 143 { 145 return fMaterialIndices[copyNo]; 144 return fMaterialIndices[copyNo]; 146 } 145 } 147 146 148 G4int ICRP110PhantomNestedParameterisation::Ge 147 G4int ICRP110PhantomNestedParameterisation::GetNumberOfMaterials() const 149 { 148 { 150 return fMaterials.size(); 149 return fMaterials.size(); 151 } 150 } 152 151 153 G4Material* ICRP110PhantomNestedParameterisati 152 G4Material* ICRP110PhantomNestedParameterisation::GetMaterial(G4int i) const 154 { 153 { 155 return fMaterials[i]; 154 return fMaterials[i]; 156 } 155 } 157 156 158 void ICRP110PhantomNestedParameterisation:: 157 void ICRP110PhantomNestedParameterisation:: 159 ComputeTransformation(const G4int copyNo, G4VP 158 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const 160 { 159 { 161 // Position of voxels. 160 // Position of voxels. 162 // x and y positions are already defined i 161 // x and y positions are already defined in DetectorConstruction by using 163 // replicated volume. Hre we define the po 162 // replicated volume. Hre we define the position along the z axis of voxels. 164 163 165 physVol -> SetTranslation(G4ThreeVector(0. 164 physVol -> SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo) 166 165 +1.)*fdZ - fdZ*fnZ)); 167 } 166 } 168 167 169 void ICRP110PhantomNestedParameterisation:: 168 void ICRP110PhantomNestedParameterisation:: 170 ComputeDimensions( G4Box& box, const G4int, co 169 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const 171 { 170 { 172 box.SetXHalfLength(fdX); 171 box.SetXHalfLength(fdX); 173 box.SetYHalfLength(fdY); 172 box.SetYHalfLength(fdY); 174 box.SetZHalfLength(fdZ); 173 box.SetZHalfLength(fdZ); 175 } 174 } 176 175