gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
PhotonCrossSection.inl
Go to the documentation of this file.
1 /*
2 
3  Copyright (c) 2018, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4  http://www.fpvidal.net/
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification,
8  are permitted provided that the following conditions are met:
9 
10  1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13  2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation and/or
15  other materials provided with the distribution.
16 
17  3. Neither the name of the Bangor University nor the names of its contributors
18  may be used to endorse or promote products derived from this software without
19  specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32  */
33 
34 
63 //******************************************************************************
64 // Include
65 //******************************************************************************
66 #include <string>
67 
68 
69 //******************************************************************************
70 // defines
71 //******************************************************************************
72 
73 
74 //******************************************************************************
75 // namespace
76 //******************************************************************************
77 namespace gVirtualXRay {
78 
79 
80 inline std::ostream& operator<<(std::ostream& anOuputStream,
81  const PhotonCrossSection& anInstance)
82 {
83  anOuputStream << "m_use_HU: " << anInstance.m_use_HU << std::endl;
84  anOuputStream << "m_use_element: " << anInstance.m_use_element << std::endl;
85  anOuputStream << "m_use_mixture: " << anInstance.m_use_mixture << std::endl;
86  anOuputStream << "m_use_element: " << anInstance.m_use_element << std::endl;
87  anOuputStream << "m_use_mass_attenuation_coefficient: " << anInstance.m_use_mass_attenuation_coefficient << std::endl;
88  anOuputStream << "m_use_linear_attenuation_coefficient: " << anInstance.m_use_linear_attenuation_coefficient << std::endl;
89 
90  anOuputStream << "m_HU: " << anInstance.m_HU << std::endl;
91  anOuputStream << "m_Z_number: " << anInstance.m_Z_number << std::endl;
92  anOuputStream << "m_mass_attenuation_coefficient: " << anInstance.m_mass_attenuation_coefficient << std::endl;
93  anOuputStream << "m_linear_attenuation_coefficient: " << anInstance.m_linear_attenuation_coefficient << std::endl;
94  anOuputStream << "m_mixture: " << anInstance.m_mixture << std::endl;
95  anOuputStream << "m_density: " << anInstance.getDensity() << std::endl;
96  anOuputStream << "m_label: " << anInstance.m_label << std::endl;
97 
98  return anOuputStream;
99 }
100 
101 
102 //--------------------------------------------------
104 //--------------------------------------------------
105  m_use_HU(false),
106  m_use_element(false),
107  m_use_mixture(false),
108  m_use_mass_attenuation_coefficient(false),
109  m_use_linear_attenuation_coefficient(false),
110  m_HU(0),
111  m_Z_number(0),
112  m_mass_attenuation_coefficient(0.0),
113  m_linear_attenuation_coefficient(0.0),
114  m_density(-1.0)
115 //--------------------------------------------------
116 {}
117 
118 
119 //-------------------------------------------------------------------------------------
120 inline PhotonCrossSection::PhotonCrossSection(unsigned short Z):
121 //-------------------------------------------------------------------------------------
122  m_use_HU(false),
123  m_use_element(true),
124  m_use_mixture(false),
125  m_use_mass_attenuation_coefficient(false),
126  m_use_linear_attenuation_coefficient(false),
127  m_HU(0),
128  m_Z_number(Z),
129  m_mass_attenuation_coefficient(0.0),
130  m_linear_attenuation_coefficient(0.0),
131  m_density(-1.0),
132  m_label(std::string("Element: ") + ElementSet::getInstance().getElement(Z).getName())
133 //-------------------------------------------------------------------------------------
134 {
135 }
136 
137 
138 //-------------------------------------------------------------------------------------
139 inline PhotonCrossSection::PhotonCrossSection(const std::map<int, double>& aWeightSet):
140 //-------------------------------------------------------------------------------------
141  m_use_HU(false),
142  m_use_element(false),
143  m_use_mixture(true),
144  m_use_mass_attenuation_coefficient(false),
145  m_use_linear_attenuation_coefficient(false),
146  m_HU(0),
147  m_Z_number(0),
148  m_mass_attenuation_coefficient(0.0),
149  m_linear_attenuation_coefficient(0.0),
150  m_mixture(aWeightSet),
151  m_density(-1.0),
152  m_label(std::string("Mixture: ") + m_mixture.getLabel())
153 //-------------------------------------------------------------------------------------
154 {
155 }
156 
157 
158 //---------------------------------------------------------------------------------------------
159 inline PhotonCrossSection::PhotonCrossSection(const std::map<std::string, double>& aWeightSet):
160 //---------------------------------------------------------------------------------------------
161  m_use_HU(false),
162  m_use_element(false),
163  m_use_mixture(true),
164  m_use_mass_attenuation_coefficient(false),
165  m_use_linear_attenuation_coefficient(false),
166  m_HU(0),
167  m_Z_number(0),
168  m_mass_attenuation_coefficient(0.0),
169  m_linear_attenuation_coefficient(0.0),
170  m_mixture(aWeightSet),
171  m_density(-1.0),
172  m_label(std::string("Mixture: ") + m_mixture.getLabel())
173 //---------------------------------------------------------------------------------------------
174 {
175 }
176 
177 
178 //---------------------------------------------------------------------
180 //---------------------------------------------------------------------
181  m_use_HU(false),
182  m_use_element(false),
183  m_use_mixture(true),
184  m_use_mass_attenuation_coefficient(false),
185  m_use_linear_attenuation_coefficient(false),
186  m_HU(0),
187  m_Z_number(0),
188  m_mass_attenuation_coefficient(0.0),
189  m_linear_attenuation_coefficient(0.0),
190  m_mixture(aMixture),
191  m_density(-1.0),
192  m_label(std::string("Mixture: ") + m_mixture.getLabel())
193 //---------------------------------------------------------------------
194 {}
195 
196 
197 //-------------------------------------
199 //-------------------------------------
200 {
201  m_use_HU = false;
202  m_use_element = false;
203  m_use_mixture = false;
206 
207  m_density = -1.0;
208  m_label.clear();
209 }
210 
211 
212 //---------------------------------------------
213 inline void PhotonCrossSection::useHU(short HU)
214 //---------------------------------------------
215 {
216  reset();
217  m_use_HU = true;
218  m_HU = HU;
219 
220  m_label = "HU: ";
221  m_label += std::to_string(HU);
222 }
223 
224 
225 //---------------------------------------------------------
227 //---------------------------------------------------------
228 {
229  useHU(HU);
230 }
231 
232 
233 //----------------------------------------------------------
235 //----------------------------------------------------------
236 {
237  useHU(HU);
238 }
239 
240 
241 
242 //-----------------------------------------------------------------
243 inline void PhotonCrossSection::useMixture(const Mixture& aMixture)
244 //-----------------------------------------------------------------
245 {
246  reset();
247  m_use_mixture = true;
248  m_mixture = aMixture;
249 
250  m_label = "Mixture: ";
252 }
253 
254 
255 //-------------------------------------------------------------------------------
256 inline void PhotonCrossSection::useMixture(const std::map<int, double>& aMixture)
257 //-------------------------------------------------------------------------------
258 {
259  reset();
260  m_use_mixture = true;
261  m_mixture.setMixture(aMixture);
262 
263  m_label = "Mixture: ";
265 }
266 
267 
268 //---------------------------------------------------------------------------------------
269 inline void PhotonCrossSection::useMixture(const std::map<std::string, double>& aMixture)
270 //---------------------------------------------------------------------------------------
271 {
272  reset();
273  m_use_mixture = true;
274  m_mixture.setMixture(aMixture);
275 
276  m_label = "Mixture: ";
278 }
279 
280 
281 //--------------------------------------------------------------------------------
283 //--------------------------------------------------------------------------------
284 {
285  reset();
287  m_mass_attenuation_coefficient = aCoefficient;
288 
289  m_label = "mu/rho: ";
290  m_label += std::to_string(aCoefficient);
291 }
292 
293 
294 //----------------------------------------------------------------------------------
296 //----------------------------------------------------------------------------------
297 {
298  reset();
299  double inv_cm = 1.0 / cm;
300 
302  m_linear_attenuation_coefficient = aCoefficient;
303 
304 
305  m_label = "mu: ";
306  m_label += std::to_string(aCoefficient / inv_cm);
307  m_label += " cm-1";
308 }
309 
310 
311 //-------------------------------------------
312 inline bool PhotonCrossSection::useHU() const
313 //-------------------------------------------
314 {
315  return m_use_HU;
316 }
317 
318 
319 //-------------------------------------------------------
321 //-------------------------------------------------------
322 {
323  return m_use_HU;
324 }
325 
326 
327 //--------------------------------------------------------
329 //--------------------------------------------------------
330 {
331  return m_use_HU;
332 }
333 
334 
335 //------------------------------------------------
337 //------------------------------------------------
338 {
339  return m_use_element;
340 }
341 
342 
343 //------------------------------------------------
345 //------------------------------------------------
346 {
347  return m_use_mixture;
348 }
349 
350 
351 //-------------------------------------------------------------------
353 //-------------------------------------------------------------------
354 {
356 }
357 
358 
359 //---------------------------------------------------------------------
361 //---------------------------------------------------------------------
362 {
364 }
365 
366 
367 //---------------------------------------------------------
368 inline void PhotonCrossSection::setDensity(double aDensity)
369 //---------------------------------------------------------
370 {
371  m_density = aDensity;
372 }
373 
374 
375 //------------------------------------------------------------
376 inline double PhotonCrossSection::getMu(double anEnergy) const
377 //------------------------------------------------------------
378 {
379  return (getLinearAttenuationCoefficient(anEnergy));
380 }
381 
382 
383 //------------------------------------------------------------
384 inline const std::string& PhotonCrossSection::getLabel() const
385 //------------------------------------------------------------
386 {
387  return (m_label);
388 }
389 
390 
391 //-----------------------------------------------------------------------------------
392 inline bool PhotonCrossSection::operator!=(const PhotonCrossSection& aTestData) const
393 //-----------------------------------------------------------------------------------
394 {
395  return (!((*this) == aTestData));
396 }
397 
398 
399 //--------------------------------------------------------
400 inline std::string PhotonCrossSection::getCompound() const
401 //--------------------------------------------------------
402 {
403  std::string composition;
404  std::string prefix("Compound: ");
405  size_t prefix_length(prefix.length());
406 
407  std::cout << m_label.length() << "\t" << prefix_length << std::endl;
408  if (m_label.length() < prefix_length)
409  {
410  std::cout << m_label.substr(0, prefix_length) << " == " << prefix << " ? " << int(m_label.substr(0, prefix_length) == prefix) << std::endl;
411  if (m_label.substr(0, prefix_length) == prefix)
412  {
413  composition = m_label.substr(prefix_length, m_label.length() - prefix_length);
414  std::cout << composition << std::endl;
415  }
416  }
417 
418  throw "NOT WORKING YET";
419  return composition;
420 }
421 
422 
423 //----------------------------------------------------------------------
424 inline std::vector<int> PhotonCrossSection::getMixtureElementSet() const
425 //----------------------------------------------------------------------
426 {
427  std::vector<int> return_value;
428 
429  if (m_use_mixture)
430  {
431  for (const auto& ite : m_mixture.getWeightSet())
432  {
433  return_value.push_back(ite.first);
434  }
435  }
436 
437  return return_value;
438 }
439 
440 
441 //------------------------------------------------------------------------
442 inline std::vector<double> PhotonCrossSection::getMixtureWeightSet() const
443 //------------------------------------------------------------------------
444 {
445  std::vector<double> return_value;
446 
447  if (m_use_mixture)
448  {
449  for (const auto& ite : m_mixture.getWeightSet())
450  {
451  return_value.push_back(ite.second);
452  }
453  }
454 
455  return return_value;
456 }
457 
458 
459 } // namespace gVirtualXRay
std::vector< int > getMixtureElementSet() const
Accessor on the element Z number set of the mixture of the polygon mesh.
STL namespace.
ElementSet is a class to manage a table of elements in material.
Definition: ElementSet.h:116
std::string getCompound() const
Accessor on the compound description of the polygon mesh.
const std::string & getLabel() const
bool operator!=(const PhotonCrossSection &aTestData) const
PhotonCrossSection is a class to manage photon cross sections of elements, compounds and mixtures...
const double cm
centimeter
Definition: Units.h:106
std::ostream & operator<<(std::ostream &anOutputSream, const gVirtualXRay::AtomicElement &anElement)
operator <<
void setMixture(const std::map< int, double > &aWeightSet)
Definition: Mixture.inl:145
std::vector< double > getMixtureWeightSet() const
Accessor on the element weight set of the mixture of the polygon mesh.
const std::string & getLabel() const
Definition: Mixture.inl:250
Mixture is a class to manage a mixture (e.g. Ti90Al6V4).
Definition: Mixture.h:101
const std::map< int, double > & getWeightSet() const
Definition: Mixture.inl:279
double getMu(double anEnergy) const