gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
Mixture.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 
62 //******************************************************************************
63 // Include
64 //******************************************************************************
65 #include <cstring>
66 
67 #ifndef __ConstantValues_h
69 #endif
70 
71 #ifndef __ElementSet_h
73 #endif
74 
75 
76 //******************************************************************************
77 // namespace
78 //******************************************************************************
79 namespace gVirtualXRay {
80 
81 
82 //------------------------
84 //------------------------
85  m_molar_mass(0.0),
86  m_density(-1.0)
87 //------------------------
88 {}
89 
90 
91 //---------------------------------------------------------------
92 inline Mixture::Mixture(const std::map<int, double>& aWeightSet):
93 //---------------------------------------------------------------
94  m_molar_mass(0.0),
95  m_density(-1.0)
96 //---------------------------------------------------------------
97 {
98  m_p_weight_set = aWeightSet;
99 
101 
102  m_molar_mass = computeMolarMass();
103 
104  setLabel();
105 }
106 
107 
108 //-------------------------------------------------
109 inline Mixture::Mixture(const std::map<std::string,
110  double>& aWeightSet):
111 //-------------------------------------------------
112  m_molar_mass(0.0),
113  m_density(-1.0)
114 //-------------------------------------------------
115 {
116  setMixture(aWeightSet);
117 }
118 
119 
120 //-----------------------------------------------
121 inline Mixture::Mixture(const Mixture& aMixture):
122 //-----------------------------------------------
123  m_p_weight_set(aMixture.m_p_weight_set),
124  m_molar_mass(aMixture.m_molar_mass),
125  m_density(aMixture.m_density),
126  m_label(aMixture.m_label)
127 //-----------------------------------------------
128 {
129 }
130 
131 
132 //--------------------------
133 inline void Mixture::clear()
134 //--------------------------
135 {
136  m_label.clear();
137  m_p_weight_set.clear();
138 
139  m_molar_mass = 0.0;
140  m_density = -1.0;
141 }
142 
143 
144 //----------------------------------------------------------------------
145 inline void Mixture::setMixture(const std::map<int, double>& aWeightSet)
146 //----------------------------------------------------------------------
147 {
148  m_p_weight_set = aWeightSet;
150  m_molar_mass = computeMolarMass();
151 
152  setLabel();
153 }
154 
155 
156 //------------------------------------------------------------------------------
157 inline void Mixture::setMixture(const std::map<std::string, double>& aWeightSet)
158 //------------------------------------------------------------------------------
159 {
160  std::map<int, double> mixture;
161 
162  int balance_Z = 0;
163  double sum_weight(0.0);
164 
165  for (std::map<std::string, double>::const_iterator ite = aWeightSet.begin();
166  ite != aWeightSet.end();
167  ++ite)
168  {
169  // Retreive the Z number from the element name or symbol
170  int Z = ElementSet::getInstance().getElement(ite->first).getZ();
171 
172  // The element's weight is unknown
173  if (ite->second < -EPSILON)
174  {
175  balance_Z = Z;
176  }
177  // The element's weight is known
178  else
179  {
180  mixture[Z] = ite->second;
181  sum_weight += ite->second;
182  }
183  }
184 
185  // The wegith of one of the element is the balance of all the other weights
186  if (balance_Z)
187  {
188  // Assume the weights are given for the range [0, 100]
189  if (sum_weight > 1.0)
190  {
191  mixture[balance_Z] = 100.0 - sum_weight;
192  }
193  // Assume the weights are given for the range [0, 1]
194  else
195  {
196  mixture[balance_Z] = 1.0 - sum_weight;
197  }
198  }
199 
200  m_p_weight_set = mixture;
202  m_molar_mass = computeMolarMass();
203 
204  setLabel();
205 }
206 
207 
208 //-----------------------------------------
209 inline double Mixture::getMolarMass() const
210 //-----------------------------------------
211 {
212  return (m_molar_mass);
213 }
214 
215 
216 //----------------------------------------------
217 inline void Mixture::setDensity(double aDensity)
218 //----------------------------------------------
219 {
220  m_density = aDensity;
221 }
222 
223 
224 //---------------------------------------
225 inline double Mixture::getDensity() const
226 //---------------------------------------
227 {
228  return m_density;
229 }
230 
231 
232 //---------------------------------------------------------------------
233 inline double Mixture::getLinearAttenuationTotal(double anEnergy) const
234 //---------------------------------------------------------------------
235 {
236  return (getMassAttenuationTotal(anEnergy) *
237  (getDensity()));
238 }
239 
240 
241 //-------------------------------------------------
242 inline double Mixture::getMu(double anEnergy) const
243 //-------------------------------------------------
244 {
245  return (getLinearAttenuationTotal(anEnergy));
246 }
247 
248 
249 //-------------------------------------------------
250 inline const std::string& Mixture::getLabel() const
251 //-------------------------------------------------
252 {
253  return (m_label);
254 }
255 
256 
257 //---------------------------------------------------------
258 inline Mixture& Mixture::operator=(const Mixture& aMixture)
259 //---------------------------------------------------------
260 {
261  m_molar_mass = aMixture.m_molar_mass;
262  m_density = aMixture.m_density;
263  m_p_weight_set = aMixture.m_p_weight_set;
264  m_label = aMixture.m_label;
265 
266  return (*this);
267 }
268 
269 
270 //------------------------------------------------------------
271 inline bool Mixture::operator!=(const Mixture& aMixture) const
272 //------------------------------------------------------------
273 {
274  return (!(operator==(aMixture)));
275 }
276 
277 
278 //---------------------------------------------------------------
279 inline const std::map<int, double>& Mixture::getWeightSet() const
280 //---------------------------------------------------------------
281 {
282  return m_p_weight_set;
283 }
284 
285 
286 } // namespace gVirtualXRay/
double getMolarMass() const
Accessor on the molar mass of the material.
Definition: Mixture.inl:209
AtomicElement & getElement(unsigned short anAtomicNumber)
Get a given element.
Class to manage a table of elements in material.
bool operator!=(const Mixture &aMixture) const
Definition: Mixture.inl:271
#define EPSILON
Smallest value that can be stored with a real number.
Mixture()
Default Constructor.
Definition: Mixture.inl:83
static ElementSet & getInstance()
double getLinearAttenuationTotal(double anEnergy) const
Definition: Mixture.inl:233
void setMixture(const std::map< int, double > &aWeightSet)
Definition: Mixture.inl:145
const std::string & getLabel() const
Definition: Mixture.inl:250
double getMu(double anEnergy) const
Definition: Mixture.inl:242
Mixture & operator=(const Mixture &aMixture)
Copy operator.
Definition: Mixture.inl:258
Mixture is a class to manage a mixture (e.g. Ti90Al6V4).
Definition: Mixture.h:101
Constant values, such as the Z number of different atoms, etc.
void normaliseWeightSet()
Normalise the weight set.
double computeMolarMass()
Update the value of the molar mass of the material.
const std::map< int, double > & getWeightSet() const
Definition: Mixture.inl:279
double getDensity() const
Get the density of the material.
Definition: Mixture.inl:225
void setDensity(double aDensity)
Definition: Mixture.inl:217
unsigned short getZ() const
Accessor on the atomic number (Z) of the element.