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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/extended/medical/DICOM/src/DicomNestedPhantomParameterisation.cc (Version 11.3.0) and /examples/extended/medical/DICOM/src/DicomNestedPhantomParameterisation.cc (Version 11.1.3)


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