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[ 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 /processes/electromagnetic/dna/utils/src/G4DNAMesh.cc (Version 11.3.0) and /processes/electromagnetic/dna/utils/src/G4DNAMesh.cc (Version 11.1.3)


  1 // *******************************************      1 // ********************************************************************
  2 // * License and Disclaimer                         2 // * License and Disclaimer                                           *
  3 // *                                                3 // *                                                                  *
  4 // * The  Geant4 software  is  copyright of th      4 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  5 // * the Geant4 Collaboration.  It is provided      5 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  6 // * conditions of the Geant4 Software License      6 // * conditions of the Geant4 Software License,  included in the file *
  7 // * LICENSE and available at  http://cern.ch/      7 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  8 // * include a list of copyright holders.           8 // * include a list of copyright holders.                             *
  9 // *                                                9 // *                                                                  *
 10 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 11 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 12 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 13 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 14 // * use.  Please see the license in the file      14 // * use.  Please see the license in the file  LICENSE  and URL above *
 15 // * for the full disclaimer and the limitatio     15 // * for the full disclaimer and the limitation of liability.         *
 16 // *                                               16 // *                                                                  *
 17 // * This  code  implementation is the result      17 // * This  code  implementation is the result of  the  scientific and *
 18 // * technical work of the GEANT4 collaboratio     18 // * technical work of the GEANT4 collaboration.                      *
 19 // * By using,  copying,  modifying or  distri     19 // * By using,  copying,  modifying or  distributing the software (or *
 20 // * any work based  on the software)  you  ag     20 // * any work based  on the software)  you  agree  to acknowledge its *
 21 // * use  in  resulting  scientific  publicati     21 // * use  in  resulting  scientific  publications,  and indicate your *
 22 // * acceptance of all terms of the Geant4 Sof     22 // * acceptance of all terms of the Geant4 Software license.          *
 23 // *******************************************     23 // ********************************************************************
 24 //                                                 24 //
 25 #include "G4DNAMesh.hh"                            25 #include "G4DNAMesh.hh"
 26 #include <algorithm>                               26 #include <algorithm>
 27 #include <ostream>                                 27 #include <ostream>
 28 #include "G4ITTrackHolder.hh"                      28 #include "G4ITTrackHolder.hh"
 29                                                    29 
 30 std::ostream& operator<<(std::ostream& stream,     30 std::ostream& operator<<(std::ostream& stream, const G4VDNAMesh::Index& rhs)
 31 {                                                  31 {
 32   stream << "{" << rhs.x << ", " << rhs.y << "     32   stream << "{" << rhs.x << ", " << rhs.y << ", " << rhs.z << "}";
 33   return stream;                                   33   return stream;
 34 }                                                  34 }
 35                                                    35 
 36 G4DNAMesh::Voxel& G4DNAMesh::GetVoxel(const In     36 G4DNAMesh::Voxel& G4DNAMesh::GetVoxel(const Index& key)
 37 {                                                  37 {
 38   auto iter = fIndexMap.find(key);                 38   auto iter = fIndexMap.find(key);
 39   if(iter == fIndexMap.end())                      39   if(iter == fIndexMap.end())
 40   {                                                40   {
 41     auto box = GetBoundingBox(key);                41     auto box = GetBoundingBox(key);
 42     Data mapList;                                  42     Data mapList;
 43     G4DNAMesh::Voxel& voxel =                      43     G4DNAMesh::Voxel& voxel =
 44       fVoxelVector.emplace_back(std::make_tupl     44       fVoxelVector.emplace_back(std::make_tuple(key, box, std::move(mapList)));
 45     fIndexMap[key] = G4int(fVoxelVector.size()     45     fIndexMap[key] = G4int(fVoxelVector.size() - 1);
 46     return voxel;                                  46     return voxel;
 47   }                                                47   }
 48                                                <<  48   else
 49   auto index = fIndexMap[key];                 <<  49   {
 50   return fVoxelVector[index];                  <<  50     auto index = fIndexMap[key];
                                                   >>  51     return fVoxelVector[index];
                                                   >>  52   }
 51 }                                                  53 }
 52                                                    54 
 53 G4DNAMesh::G4DNAMesh(const G4DNABoundingBox& b     55 G4DNAMesh::G4DNAMesh(const G4DNABoundingBox& boundingBox, G4int pixel)
 54   : fpBoundingMesh(&boundingBox)                   56   : fpBoundingMesh(&boundingBox)
 55   , fResolution((2 * boundingBox.halfSideLengt     57   , fResolution((2 * boundingBox.halfSideLengthInY() / pixel))
 56 {}                                                 58 {}
 57                                                    59 
 58 G4DNAMesh::~G4DNAMesh() { Reset(); }               60 G4DNAMesh::~G4DNAMesh() { Reset(); }
 59                                                    61 
 60 G4DNAMesh::Data& G4DNAMesh::GetVoxelMapList(co     62 G4DNAMesh::Data& G4DNAMesh::GetVoxelMapList(const Index& key)
 61 {                                                  63 {
 62   auto& pVoxel = GetVoxel(key);                    64   auto& pVoxel = GetVoxel(key);
 63   return std::get<2>(pVoxel);                      65   return std::get<2>(pVoxel);
 64 }                                                  66 }
 65                                                    67 
 66 void G4DNAMesh::PrintMesh()                        68 void G4DNAMesh::PrintMesh()
 67 {                                                  69 {
 68   G4cout << "*********PrintMesh::Size : " << f     70   G4cout << "*********PrintMesh::Size : " << fVoxelVector.size() << G4endl;
 69   for(const auto& iter : fVoxelVector)             71   for(const auto& iter : fVoxelVector)
 70   {                                                72   {
 71     auto data = std::get<2>(iter);                 73     auto data = std::get<2>(iter);
 72     G4cout << "Index : " << std::get<0>(iter)      74     G4cout << "Index : " << std::get<0>(iter)
 73            << " number of type : " << std::get     75            << " number of type : " << std::get<2>(iter).size() << G4endl;
 74     for(const auto& it : data)                     76     for(const auto& it : data)
 75     {                                              77     {
 76       G4cout << "_____________" << it.first->G     78       G4cout << "_____________" << it.first->GetName() << " : " << it.second
 77              << G4endl;                            79              << G4endl;
 78     }                                              80     }
 79     G4cout << G4endl;                              81     G4cout << G4endl;
 80   }                                                82   }
 81   G4cout << G4endl;                                83   G4cout << G4endl;
 82 }                                                  84 }
 83                                                    85 
 84 G4int G4DNAMesh::GetNumberOfType(G4DNAMesh::Mo     86 G4int G4DNAMesh::GetNumberOfType(G4DNAMesh::MolType type) const
 85 {                                                  87 {
 86   G4int output = 0;                                88   G4int output = 0;
 87                                                    89 
 88   for(const auto& iter : fVoxelVector)             90   for(const auto& iter : fVoxelVector)
 89   {                                                91   {
 90     auto data = std::get<2>(iter);                 92     auto data = std::get<2>(iter);
 91     auto it   = data.find(type);                   93     auto it   = data.find(type);
 92     if(it != data.end())                           94     if(it != data.end())
 93     {                                              95     {
 94       output += it->second;                        96       output += it->second;
 95     }                                              97     }
 96   }                                                98   }
 97   return output;                                   99   return output;
 98 }                                                 100 }
 99                                                   101 
100 void G4DNAMesh::PrintVoxel(const Index& index)    102 void G4DNAMesh::PrintVoxel(const Index& index)
101 {                                                 103 {
102   G4cout << "*********PrintVoxel::";              104   G4cout << "*********PrintVoxel::";
103   G4cout << " index : " << index                  105   G4cout << " index : " << index
104          << " number of type : " << this->GetV    106          << " number of type : " << this->GetVoxelMapList(index).size()
105          << G4endl;                               107          << G4endl;
106                                                   108 
107   for(const auto& it : this->GetVoxelMapList(i    109   for(const auto& it : this->GetVoxelMapList(index))
108   {                                               110   {
109     G4cout << "_____________" << it.first->Get    111     G4cout << "_____________" << it.first->GetName() << " : " << it.second
110            << G4endl;                             112            << G4endl;
111   }                                               113   }
112   G4cout << G4endl;                               114   G4cout << G4endl;
113 }                                                 115 }
114                                                   116 
115 void G4DNAMesh::InitializeVoxel(const Index& i    117 void G4DNAMesh::InitializeVoxel(const Index& index, Data&& mapList)
116 {                                                 118 {
117   auto& pVoxel        = GetVoxel(index);          119   auto& pVoxel        = GetVoxel(index);
118   std::get<2>(pVoxel) = std::move(mapList);       120   std::get<2>(pVoxel) = std::move(mapList);
119 }                                                 121 }
120                                                   122 
121 G4DNABoundingBox G4DNAMesh::GetBoundingBox(con    123 G4DNABoundingBox G4DNAMesh::GetBoundingBox(const Index& index)
122 {                                                 124 {
123   auto xlo = fpBoundingMesh->Getxlo() + index.    125   auto xlo = fpBoundingMesh->Getxlo() + index.x * fResolution;
124   auto ylo = fpBoundingMesh->Getylo() + index.    126   auto ylo = fpBoundingMesh->Getylo() + index.y * fResolution;
125   auto zlo = fpBoundingMesh->Getzlo() + index.    127   auto zlo = fpBoundingMesh->Getzlo() + index.z * fResolution;
126   auto xhi = fpBoundingMesh->Getxlo() + (index    128   auto xhi = fpBoundingMesh->Getxlo() + (index.x + 1) * fResolution;
127   auto yhi = fpBoundingMesh->Getylo() + (index    129   auto yhi = fpBoundingMesh->Getylo() + (index.y + 1) * fResolution;
128   auto zhi = fpBoundingMesh->Getzlo() + (index    130   auto zhi = fpBoundingMesh->Getzlo() + (index.z + 1) * fResolution;
129   return G4DNABoundingBox({ xhi, xlo, yhi, ylo    131   return G4DNABoundingBox({ xhi, xlo, yhi, ylo, zhi, zlo });
130 }                                                 132 }
131                                                   133 
132 void G4DNAMesh::Reset()                           134 void G4DNAMesh::Reset()
133 {                                                 135 {
134   fIndexMap.clear();                              136   fIndexMap.clear();
135   fVoxelVector.clear();                           137   fVoxelVector.clear();
136 }                                                 138 }
137                                                   139 
138 const G4DNABoundingBox& G4DNAMesh::GetBounding    140 const G4DNABoundingBox& G4DNAMesh::GetBoundingBox() const
139 {                                                 141 {
140   return *fpBoundingMesh;                         142   return *fpBoundingMesh;
141 }                                                 143 }
142                                                   144 
143 std::vector<G4DNAMesh::Index>  // array is bet    145 std::vector<G4DNAMesh::Index>  // array is better ?
144 G4DNAMesh::FindNeighboringVoxels(const Index&     146 G4DNAMesh::FindNeighboringVoxels(const Index& index) const
145 {                                                 147 {
146   std::vector<Index> neighbors;                   148   std::vector<Index> neighbors;
147   neighbors.reserve(6);                           149   neighbors.reserve(6);
148   auto xMax = (G4int) (std::floor(                150   auto xMax = (G4int) (std::floor(
149     (fpBoundingMesh->Getxhi() - fpBoundingMesh    151     (fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
150   auto yMax = (G4int) (std::floor(                152   auto yMax = (G4int) (std::floor(
151     (fpBoundingMesh->Getyhi() - fpBoundingMesh    153     (fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
152   auto zMax = (G4int) (std::floor(                154   auto zMax = (G4int) (std::floor(
153     (fpBoundingMesh->Getzhi() - fpBoundingMesh    155     (fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
154                                                   156 
155   if(index.x - 1 >= 0)                            157   if(index.x - 1 >= 0)
156   {                                               158   {
157     neighbors.emplace_back(index.x - 1, index. << 159     neighbors.push_back(Index(index.x - 1, index.y, index.z));
158   }                                               160   }
159   if(index.y - 1 >= 0)                            161   if(index.y - 1 >= 0)
160   {                                               162   {
161     neighbors.emplace_back(index.x, index.y -  << 163     neighbors.push_back(Index(index.x, index.y - 1, index.z));
162   }                                               164   }
163   if(index.z - 1 >= 0)                            165   if(index.z - 1 >= 0)
164   {                                               166   {
165     neighbors.emplace_back(index.x, index.y, i << 167     neighbors.push_back(Index(index.x, index.y, index.z - 1));
166   }                                               168   }
167   if(index.x + 1 < xMax)                          169   if(index.x + 1 < xMax)
168   {                                               170   {
169     neighbors.emplace_back(index.x + 1, index. << 171     neighbors.push_back(Index(index.x + 1, index.y, index.z));
170   }                                               172   }
171   if(index.y + 1 < yMax)                          173   if(index.y + 1 < yMax)
172   {                                               174   {
173     neighbors.emplace_back(index.x, index.y +  << 175     neighbors.push_back(Index(index.x, index.y + 1, index.z));
174   }                                               176   }
175   if(index.z + 1 < zMax)                          177   if(index.z + 1 < zMax)
176   {                                               178   {
177     neighbors.emplace_back(index.x, index.y, i << 179     neighbors.push_back(Index(index.x, index.y, index.z + 1));
178   }                                               180   }
179                                                   181 
180   return neighbors;                               182   return neighbors;
181 }                                                 183 }
182                                                   184 
183 G4double G4DNAMesh::GetResolution() const { re    185 G4double G4DNAMesh::GetResolution() const { return fResolution; }
184                                                   186 
185 G4DNAMesh::Index G4DNAMesh::GetIndex(const G4T    187 G4DNAMesh::Index G4DNAMesh::GetIndex(const G4ThreeVector& position) const
186 {                                                 188 {
187   if(!fpBoundingMesh->contains(position))         189   if(!fpBoundingMesh->contains(position))
188   {                                               190   {
189     G4ExceptionDescription exceptionDescriptio    191     G4ExceptionDescription exceptionDescription;
190     exceptionDescription << "the position: " <    192     exceptionDescription << "the position: " << position
191                          << " is not in the bo    193                          << " is not in the box : " << *fpBoundingMesh;
192     G4Exception("G4DNAMesh::GetKey", "G4DNAMes    194     G4Exception("G4DNAMesh::GetKey", "G4DNAMesh010", FatalErrorInArgument,
193                 exceptionDescription);            195                 exceptionDescription);
194   }                                               196   }
195                                                   197 
196   G4int dx =                                      198   G4int dx =
197     std::floor((position.x() - fpBoundingMesh-    199     std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
198   G4int dy =                                      200   G4int dy =
199     std::floor((position.y() - fpBoundingMesh-    201     std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
200   G4int dz =                                      202   G4int dz =
201     std::floor((position.z() - fpBoundingMesh-    203     std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
202   if(dx < 0 || dy < 0 || dz < 0)                  204   if(dx < 0 || dy < 0 || dz < 0)
203   {                                               205   {
204     G4ExceptionDescription exceptionDescriptio    206     G4ExceptionDescription exceptionDescription;
205     exceptionDescription << "the old index: "     207     exceptionDescription << "the old index: " << position
206                          << "  to new index :     208                          << "  to new index : " << Index(dx, dx, dx);
207     G4Exception("G4DNAMesh::CheckIndex", "G4DN    209     G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh015", FatalErrorInArgument,
208                 exceptionDescription);            210                 exceptionDescription);
209   }                                               211   }
210   return Index{ dx, dy, dz };                     212   return Index{ dx, dy, dz };
211 }                                                 213 }
212                                                   214 
213 G4VDNAMesh::Index G4DNAMesh::ConvertIndex(cons    215 G4VDNAMesh::Index G4DNAMesh::ConvertIndex(const Index& index,
214                                           cons    216                                           const G4int& pixels) const
215 {                                                 217 {
216   G4int xmax = std::floor(                        218   G4int xmax = std::floor(
217     (fpBoundingMesh->Getxhi() - fpBoundingMesh    219     (fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
218   G4int ymax = std::floor(                        220   G4int ymax = std::floor(
219     (fpBoundingMesh->Getyhi() - fpBoundingMesh    221     (fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
220   G4int zmax = std::floor(                        222   G4int zmax = std::floor(
221     (fpBoundingMesh->Getzhi() - fpBoundingMesh    223     (fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution);
222   auto dx = (G4int) (index.x * pixels / xmax);    224   auto dx = (G4int) (index.x * pixels / xmax);
223   auto dy = (G4int) (index.y * pixels / ymax);    225   auto dy = (G4int) (index.y * pixels / ymax);
224   auto dz = (G4int) (index.z * pixels / zmax);    226   auto dz = (G4int) (index.z * pixels / zmax);
225   if(dx < 0 || dy < 0 || dz < 0)                  227   if(dx < 0 || dy < 0 || dz < 0)
226   {                                               228   {
227     G4ExceptionDescription exceptionDescriptio    229     G4ExceptionDescription exceptionDescription;
228     exceptionDescription << "the old index: "     230     exceptionDescription << "the old index: " << index
229                          << "  to new index :     231                          << "  to new index : " << Index(dx, dx, dx);
230     G4Exception("G4DNAMesh::CheckIndex", "G4DN    232     G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh013", FatalErrorInArgument,
231                 exceptionDescription);            233                 exceptionDescription);
232   }                                               234   }
233   return Index{ dx, dy, dz };                     235   return Index{ dx, dy, dz };
234 }                                                 236 }
235                                                   237