Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file medical/DICOM/src/DicomNestedPhantom 27 /// \brief Implementation of the DicomNestedPh 28 // 29 // 30 31 #include "DicomNestedPhantomParameterisation.h 32 33 #include "DicomHandler.hh" 34 35 #include "G4Box.hh" 36 #include "G4LogicalVolume.hh" 37 #include "G4Material.hh" 38 #include "G4ThreeVector.hh" 39 #include "G4VPhysicalVolume.hh" 40 #include "G4VTouchable.hh" 41 #include "G4VVisManager.hh" 42 #include "G4VisAttributes.hh" 43 44 //....oooOO0OOooo........oooOO0OOooo........oo 45 46 G4String DicomNestedPhantomParameterisation::f 47 DicomHandler::GetDicomDataPath() + "/ColourM 48 49 //....oooOO0OOooo........oooOO0OOooo........oo 50 DicomNestedPhantomParameterisation::DicomNeste 51 const G4ThreeVector& voxelSize, std::vector< 52 G4String colorfile) 53 : // G4VNestedParameterisation(), 54 fdX(voxelSize.x()), 55 fdY(voxelSize.y()), 56 fdZ(voxelSize.z()), 57 fnX(fnX_), 58 fnY(fnY_), 59 fnZ(fnZ_), 60 fMaterials(mat), 61 fMaterialIndices(0) 62 { 63 ReadColourData(colorfile); 64 } 65 66 //....oooOO0OOooo........oooOO0OOooo........oo 67 DicomNestedPhantomParameterisation::~DicomNest 68 69 //....oooOO0OOooo........oooOO0OOooo........oo 70 void DicomNestedPhantomParameterisation::ReadC 71 { 72 //----- Add a G4VisAttributes for materials 73 G4VisAttributes* blankAtt = new G4VisAttribu 74 blankAtt->SetVisibility(FALSE); 75 fColours["Default"] = blankAtt; 76 77 std::ifstream fin(colourFile.c_str()); 78 G4int nMate; 79 G4String mateName; 80 G4double cred, cgreen, cblue, copacity; 81 fin >> nMate; 82 for (G4int ii = 0; ii < nMate; ii++) { 83 fin >> mateName; 84 if (fin.eof()) break; 85 fin >> cred >> cgreen >> cblue >> copacity 86 G4Colour colour(cred, cgreen, cblue, copac 87 G4VisAttributes* visAtt = new G4VisAttribu 88 visAtt->SetVisibility(true); 89 fColours[mateName] = visAtt; 90 fColours2[ii] = new G4VisAttributes(*visAt 91 } 92 } 93 94 //....oooOO0OOooo........oooOO0OOooo........oo 95 void DicomNestedPhantomParameterisation::SetNo 96 97 { 98 fnX = nx; 99 fnY = ny; 100 fnZ = nz; 101 } 102 103 //....oooOO0OOooo........oooOO0OOooo........oo 104 G4Material* DicomNestedPhantomParameterisation 105 106 107 { 108 // protection for initialization and vis at 109 // 110 if (parentTouch == nullptr) return fMaterial 111 112 // Copy number of voxels. 113 // Copy number of X and Y are obtained from 114 // Copy nymber of Z is the copy number of cu 115 G4int ix = parentTouch->GetReplicaNumber(0); 116 G4int iy = parentTouch->GetReplicaNumber(1); 117 118 G4int copyID = ix + fnX * iy + fnX * fnY * i 119 120 std::size_t matIndex = GetMaterialIndex(copy 121 G4Material* mate = fMaterials[matIndex]; 122 123 if (G4VVisManager::GetConcreteInstance() && 124 G4String mateName = fMaterials.at(matIndex 125 std::string::size_type iuu = mateName.find 126 if (iuu != std::string::npos) mateName = m 127 128 if (0 < fColours.count(mateName)) 129 physVol->GetLogicalVolume()->SetVisAttri 130 else { 131 bool found = false; 132 for (const auto& itr : fColours) { 133 G4String mat_color = itr.first; 134 auto len = mat_color.length(); 135 if (mateName.find(mat_color) == 0 && m 136 physVol->GetLogicalVolume()->SetVisA 137 found = true; 138 } 139 if (found) break; 140 } 141 if (!found) { 142 static uintmax_t n = 0; 143 if (n++ < 100) 144 G4cout << "Unknown material name " < 145 if (fColours2.find(matIndex) != fColou 146 physVol->GetLogicalVolume()->SetVisA 147 else 148 physVol->GetLogicalVolume()->SetVisA 149 } 150 } 151 physVol->GetLogicalVolume()->SetMaterial(m 152 } 153 154 return mate; 155 } 156 157 //....oooOO0OOooo........oooOO0OOooo........oo 158 unsigned int DicomNestedPhantomParameterisatio 159 { 160 // return *(fMaterialIndices+copyNo); 161 return unsigned(fMaterialIndices[copyNo]); 162 } 163 164 //....oooOO0OOooo........oooOO0OOooo........oo 165 // Number of Materials 166 // Material scanner is required for preparing 167 // starting simulation, so that G4 has to know 168 // 169 G4int DicomNestedPhantomParameterisation::GetN 170 { 171 return G4int(fMaterials.size()); 172 } 173 174 //....oooOO0OOooo........oooOO0OOooo........oo 175 // 176 // GetMaterial 177 // This is needed for material scanner and re 178 // 179 G4Material* DicomNestedPhantomParameterisation 180 { 181 return fMaterials[i]; 182 } 183 184 // 185 // Transformation of voxels. 186 // 187 void DicomNestedPhantomParameterisation::Compu 188 189 { 190 // Position of voxels. 191 // x and y positions are already defined in 192 // replicated volume. Here only we need to d 193 physVol->SetTranslation( 194 G4ThreeVector(0., 0., (2. * static_cast<do 195 } 196 197 //....oooOO0OOooo........oooOO0OOooo........oo 198 // 199 // Dimensions are always same in this RE02 exa 200 // 201 void DicomNestedPhantomParameterisation::Compu 202 203 { 204 box.SetXHalfLength(fdX); 205 box.SetYHalfLength(fdY); 206 box.SetZHalfLength(fdZ); 207 } 208