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 /// \file medical/DICOM/src/DicomNestedPhantom 26 /// \file medical/DICOM/src/DicomNestedPhantomParameterisation.cc 27 /// \brief Implementation of the DicomNestedPh 27 /// \brief Implementation of the DicomNestedPhantomParameterisation class 28 // 28 // >> 29 // $Id: DicomNestedPhantomParameterisation.cc 106196 2017-09-19 04:19:33Z gcosmo $ 29 // 30 // 30 31 31 #include "DicomNestedPhantomParameterisation.h 32 #include "DicomNestedPhantomParameterisation.hh" 32 33 33 #include "DicomHandler.hh" << 34 #include "G4VPhysicalVolume.hh" 34 << 35 #include "G4VTouchable.hh" >> 36 #include "G4ThreeVector.hh" 35 #include "G4Box.hh" 37 #include "G4Box.hh" 36 #include "G4LogicalVolume.hh" 38 #include "G4LogicalVolume.hh" 37 #include "G4Material.hh" 39 #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 40 49 //....oooOO0OOooo........oooOO0OOooo........oo << 41 #include "G4VisAttributes.hh" 50 DicomNestedPhantomParameterisation::DicomNeste << 42 #include "G4VVisManager.hh" 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 43 69 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 void DicomNestedPhantomParameterisation::ReadC << 45 DicomNestedPhantomParameterisation:: 71 { << 46 DicomNestedPhantomParameterisation(const G4ThreeVector& voxelSize, 72 //----- Add a G4VisAttributes for materials << 47 std::vector<G4Material*>& mat, 73 G4VisAttributes* blankAtt = new G4VisAttribu << 48 G4int fnZ_, G4int fnY_, G4int fnX_) 74 blankAtt->SetVisibility(FALSE); << 49 : 75 fColours["Default"] = blankAtt; << 50 //G4VNestedParameterisation(), 76 << 51 fdX(voxelSize.x()), fdY(voxelSize.y()), fdZ(voxelSize.z()), 77 std::ifstream fin(colourFile.c_str()); << 52 fnX(fnX_), fnY(fnY_), fnZ(fnZ_), 78 G4int nMate; << 53 fMaterials(mat), 79 G4String mateName; << 54 fMaterialIndices(0) 80 G4double cred, cgreen, cblue, copacity; << 55 { 81 fin >> nMate; << 56 ReadColourData(); 82 for (G4int ii = 0; ii < nMate; ii++) { << 57 } 83 fin >> mateName; << 58 84 if (fin.eof()) break; << 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 85 fin >> cred >> cgreen >> cblue >> copacity << 60 DicomNestedPhantomParameterisation::~DicomNestedPhantomParameterisation() 86 G4Colour colour(cred, cgreen, cblue, copac << 61 { 87 G4VisAttributes* visAtt = new G4VisAttribu << 62 } 88 visAtt->SetVisibility(true); << 63 89 fColours[mateName] = visAtt; << 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 fColours2[ii] = new G4VisAttributes(*visAt << 65 void DicomNestedPhantomParameterisation::ReadColourData() 91 } << 66 { >> 67 //----- Add a G4VisAttributes for materials not defined in file; >> 68 /*G4VisAttributes* blankAtt = new G4VisAttributes; >> 69 blankAtt->SetVisibility( FALSE ); >> 70 fColours["Default"] = blankAtt; >> 71 >> 72 G4String colourFile = "ColourMap.dat"; >> 73 >> 74 //----- Read file >> 75 std::ifstream fin(colourFile.c_str()); >> 76 G4int nMate; >> 77 G4String mateName; >> 78 G4double cred, cgreen, cblue, copacity; >> 79 fin >> nMate; >> 80 for( G4int ii = 0; ii < nMate; ii++ ){ >> 81 fin >> mateName >> cred >> cgreen >> cblue >> copacity; >> 82 G4Colour colour( cred, cgreen, cblue, copacity ); >> 83 G4VisAttributes* visAtt = (copacity > 0.) ? >> 84 (new G4VisAttributes( colour )) : >> 85 (new G4VisAttributes(G4VisAttributes::GetInvisible())); >> 86 //visAtt->SetForceSolid(true); >> 87 fColours[mateName] = visAtt; >> 88 }*/ >> 89 >> 90 //----- Add a G4VisAttributes for materials not defined in file; >> 91 G4VisAttributes* blankAtt = new G4VisAttributes; >> 92 blankAtt->SetVisibility( FALSE ); >> 93 fColours["Default"] = blankAtt; >> 94 >> 95 //----- Read file >> 96 #ifdef DICOM_USE_HEAD >> 97 G4String colourFile = "DICOM_HEAD/ColourMap.dat"; >> 98 #else >> 99 G4String colourFile = "ColourMap.dat"; >> 100 #endif >> 101 >> 102 std::ifstream fin(colourFile.c_str()); >> 103 G4int nMate; >> 104 G4String mateName; >> 105 G4double cred, cgreen, cblue, copacity; >> 106 fin >> nMate; >> 107 for( G4int ii = 0; ii < nMate; ii++ ){ >> 108 fin >> mateName >> cred >> cgreen >> cblue >> copacity; >> 109 G4Colour colour( cred, cgreen, cblue, copacity ); >> 110 G4VisAttributes* visAtt = new G4VisAttributes( colour ); >> 111 //visAtt->SetForceSolid(true); >> 112 fColours[mateName] = visAtt; >> 113 } 92 } 114 } 93 115 94 //....oooOO0OOooo........oooOO0OOooo........oo 116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 95 void DicomNestedPhantomParameterisation::SetNo << 117 void DicomNestedPhantomParameterisation:: 96 << 118 SetNoVoxel( unsigned int nx, unsigned int ny, unsigned int nz ) 97 { 119 { 98 fnX = nx; 120 fnX = nx; 99 fnY = ny; 121 fnY = ny; 100 fnZ = nz; 122 fnZ = nz; 101 } 123 } 102 124 103 //....oooOO0OOooo........oooOO0OOooo........oo 125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 104 G4Material* DicomNestedPhantomParameterisation << 126 G4Material* DicomNestedPhantomParameterisation:: 105 << 127 ComputeMaterial(G4VPhysicalVolume* physVol, const G4int iz, 106 << 128 const G4VTouchable* parentTouch) 107 { << 129 { 108 // protection for initialization and vis at << 130 109 // << 131 // protection for initialization and vis at idle state 110 if (parentTouch == nullptr) return fMaterial << 132 // 111 << 133 if(parentTouch==0) return fMaterials[0]; 112 // Copy number of voxels. << 134 113 // Copy number of X and Y are obtained from << 135 // Copy number of voxels. 114 // Copy nymber of Z is the copy number of cu << 136 // Copy number of X and Y are obtained from replication number. 115 G4int ix = parentTouch->GetReplicaNumber(0); << 137 // Copy nymber of Z is the copy number of current voxel. 116 G4int iy = parentTouch->GetReplicaNumber(1); << 138 G4int ix = parentTouch->GetReplicaNumber(0); 117 << 139 G4int iy = parentTouch->GetReplicaNumber(1); 118 G4int copyID = ix + fnX * iy + fnX * fnY * i << 140 119 << 141 G4int copyID = ix + fnX*iy + fnX*fnY*iz; 120 std::size_t matIndex = GetMaterialIndex(copy << 142 121 G4Material* mate = fMaterials[matIndex]; << 143 unsigned int matIndex = GetMaterialIndex(copyID); 122 << 144 static G4Material* mate = 0; 123 if (G4VVisManager::GetConcreteInstance() && << 145 mate = fMaterials[matIndex]; 124 G4String mateName = fMaterials.at(matIndex << 146 125 std::string::size_type iuu = mateName.find << 147 if(false && physVol && G4VVisManager::GetConcreteInstance()) { 126 if (iuu != std::string::npos) mateName = m << 148 G4String mateName = fMaterials.at(matIndex)->GetName(); 127 << 149 std::string::size_type iuu = mateName.find("__"); 128 if (0 < fColours.count(mateName)) << 150 if( iuu != std::string::npos ) { 129 physVol->GetLogicalVolume()->SetVisAttri << 151 mateName = mateName.substr( 0, iuu ); 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 } 152 } 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 153 154 return mate; << 154 if(0 < fColours.count(mateName)) { >> 155 physVol->GetLogicalVolume()-> >> 156 SetVisAttributes(fColours.find(mateName)->second); >> 157 } else { >> 158 physVol->GetLogicalVolume()-> >> 159 SetVisAttributes(fColours.begin()->second); >> 160 } >> 161 } >> 162 >> 163 return mate; 155 } 164 } 156 165 157 //....oooOO0OOooo........oooOO0OOooo........oo 166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 158 unsigned int DicomNestedPhantomParameterisatio << 167 unsigned int DicomNestedPhantomParameterisation:: >> 168 GetMaterialIndex( unsigned int copyNo ) const 159 { 169 { 160 // return *(fMaterialIndices+copyNo); << 170 //return *(fMaterialIndices+copyNo); 161 return unsigned(fMaterialIndices[copyNo]); << 171 return fMaterialIndices[copyNo]; 162 } 172 } 163 173 164 //....oooOO0OOooo........oooOO0OOooo........oo 174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 // Number of Materials 175 // Number of Materials 166 // Material scanner is required for preparing 176 // Material scanner is required for preparing physics tables and so on before 167 // starting simulation, so that G4 has to know 177 // starting simulation, so that G4 has to know number of materials. 168 // 178 // 169 G4int DicomNestedPhantomParameterisation::GetN 179 G4int DicomNestedPhantomParameterisation::GetNumberOfMaterials() const 170 { 180 { 171 return G4int(fMaterials.size()); << 181 return fMaterials.size(); 172 } 182 } 173 183 174 //....oooOO0OOooo........oooOO0OOooo........oo 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 175 // 185 // 176 // GetMaterial 186 // GetMaterial 177 // This is needed for material scanner and re 187 // This is needed for material scanner and realizing geometry. 178 // 188 // 179 G4Material* DicomNestedPhantomParameterisation 189 G4Material* DicomNestedPhantomParameterisation::GetMaterial(G4int i) const 180 { 190 { 181 return fMaterials[i]; << 191 return fMaterials[i]; 182 } 192 } 183 193 184 // 194 // 185 // Transformation of voxels. 195 // Transformation of voxels. 186 // 196 // 187 void DicomNestedPhantomParameterisation::Compu << 197 void DicomNestedPhantomParameterisation:: 188 << 198 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const 189 { 199 { 190 // Position of voxels. << 200 // Position of voxels. 191 // x and y positions are already defined in << 201 // x and y positions are already defined in DetectorConstruction by using 192 // replicated volume. Here only we need to d << 202 // replicated volume. Here only we need to define is z positions of voxels. 193 physVol->SetTranslation( << 203 physVol->SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo) 194 G4ThreeVector(0., 0., (2. * static_cast<do << 204 +1.)*fdZ - fdZ*fnZ)); 195 } 205 } 196 206 197 //....oooOO0OOooo........oooOO0OOooo........oo 207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 198 // 208 // 199 // Dimensions are always same in this RE02 exa 209 // Dimensions are always same in this RE02 example. 200 // 210 // 201 void DicomNestedPhantomParameterisation::Compu << 211 void DicomNestedPhantomParameterisation:: 202 << 212 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const 203 { 213 { 204 box.SetXHalfLength(fdX); << 214 box.SetXHalfLength(fdX); 205 box.SetYHalfLength(fdY); << 215 box.SetYHalfLength(fdY); 206 box.SetZHalfLength(fdZ); << 216 box.SetZHalfLength(fdZ); 207 } 217 } 208 218