gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
XRayBeam.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, 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 
35 #ifndef __XRayBeam_h
36 #define __XRayBeam_h
37 
38 
67 //******************************************************************************
68 // Include
69 //******************************************************************************
70 #ifndef __gVirtualXRayConfig_h
72 #endif
73 
74 #include <vector>
75 #include <string>
76 #include <iostream>
77 
78 #ifdef HAS_PythonLibs
79 #include <Python.h>
80 #endif
81 
82 
83 #ifndef __Types_h
84 #include "gVirtualXRay/Types.h"
85 #endif
86 
87 #ifndef __SpectrumRecord_h
89 #endif
90 
91 
92 #include <memory>
93 #include <mutex>
94 
95 //******************************************************************************
96 // namespace
97 //******************************************************************************
98 namespace gVirtualXRay {
99 
100 
101 //==============================================================================
107 //==============================================================================
108 class XRayBeam
109 //------------------------------------------------------------------------------
110 {
111 //******************************************************************************
112 public:
113  //--------------------------------------------------------------------------
115  //--------------------------------------------------------------------------
116  XRayBeam();
117 
118 
119  //--------------------------------------------------------------------------
121  //--------------------------------------------------------------------------
122  ~XRayBeam();
123 
124 
125  //--------------------------------------------------------------------------
127  //--------------------------------------------------------------------------
128  void clear();
129 
130 
131  //--------------------------------------------------------------------------
133  //--------------------------------------------------------------------------
134  void clearSpectrumOnly();
135 
136 
137  //--------------------------------------------------------------------------
139 
147  //--------------------------------------------------------------------------
148  bool addChannel(const RATIONAL_NUMBER& aNumberOfPhotons,
149  const RATIONAL_NUMBER& anIncidentEnergy);
150 
151 
152  //--------------------------------------------------------------------------
154 
161  //--------------------------------------------------------------------------
162  void initialise(const char* aFileName,
163  const RATIONAL_NUMBER& aUnit,
164  unsigned int aMergeChannelFlag = 1);
165 
166 
167  //--------------------------------------------------------------------------
169 
172  //--------------------------------------------------------------------------
173  void initialise(const RATIONAL_NUMBER& anIncidentEnergy);
174 
175 
176  //--------------------------------------------------------------------------
178  //--------------------------------------------------------------------------
179  void normalise();
180 
181 
182  //--------------------------------------------------------------------------
184 
187  //--------------------------------------------------------------------------
188  void setBinTotalEnergyCutoff(const RATIONAL_NUMBER& aThreshold);
189 
190 
191  //--------------------------------------------------------------------------
193 
196  //--------------------------------------------------------------------------
197  unsigned int getEnergyChannelNumber();
198 
199 
200  //--------------------------------------------------------------------------
202 
206  //--------------------------------------------------------------------------
207  const SpectrumRecord& getEnergyChannel(unsigned int anID);
208 
209 
210  //--------------------------------------------------------------------------
212 
215  //--------------------------------------------------------------------------
217 
218 
219  //--------------------------------------------------------------------------
221  //--------------------------------------------------------------------------
222  void enablePoissonNoise();
223 
224 
225  //--------------------------------------------------------------------------
227  //--------------------------------------------------------------------------
228  void disablePoissonNoise();
229 
230 
231  //--------------------------------------------------------------------------
233 
236  //--------------------------------------------------------------------------
237  void setNumberOfPhotons(RATIONAL_NUMBER aNumberOfPhotons);
238 
239 
240  //--------------------------------------------------------------------------
242 
245  //--------------------------------------------------------------------------
247 
248 
249  //--------------------------------------------------------------------------
251 
254  //--------------------------------------------------------------------------
255  void usePoissonNoise(bool aFlag);
256 
257 
258  //--------------------------------------------------------------------------
260 
263  //--------------------------------------------------------------------------
264  bool usePoissonNoise() const;
265 
266 
267  //--------------------------------------------------------------------------
269  //--------------------------------------------------------------------------
270  void sort();
271 
272 
273  void setPhotonCountingBands(RATIONAL_NUMBER aMinEnergy,
274  RATIONAL_NUMBER aMaxEnergy,
275  unsigned int aNumberOfBands);
276 
277 
278  unsigned int getNumberOfPhotonCountingBands();
279  void activatePhotonCountingBand(unsigned int aBand);
281  const std::vector<RATIONAL_NUMBER>& getPhotonCountingBands();
282 
283  void setVoltage(const RATIONAL_NUMBER& aVoltage);
284  void setmAs(const RATIONAL_NUMBER& an_mAs);
285  void setTubeAngle(const RATIONAL_NUMBER& anAngle);
286  RATIONAL_NUMBER getVoltage() const;
287  RATIONAL_NUMBER getmAs() const;
289  void clearFiltration();
290  void setFiltration(const std::vector<std::pair<unsigned int, RATIONAL_NUMBER> >& aSetOfFilters);
291  void addFilter(const std::string& aMaterial, const double& aThickness);
292  void addFilter(unsigned int aMaterial, const double& aThickness);
293  const std::vector<std::pair<unsigned int, RATIONAL_NUMBER> >& getFiltration() const;
294  bool hasSpekpy();
295  bool hasXpecgen();
296  void useSpekpy();
297  void useXpecgen();
298  bool usingSpekpy() const;
299  bool usingXpecgen() const;
300 
301 
302 //******************************************************************************
303 protected:
305  std::string getInterpretor() const;
306 
308  std::vector<SpectrumRecord> m_beam_spectrum;
309 
310 
314 
315 
317 
318 
320 
322  std::vector<std::vector<SpectrumRecord> > m_beam_spectrum_for_photon_count_detector;
323  std::vector<RATIONAL_NUMBER> m_photon_count_bands;
324 
327  RATIONAL_NUMBER m_mAs; // Not currently in use
328  std::vector<std::pair<unsigned int, RATIONAL_NUMBER> > m_filtration;
332 };
333 
334 
335 } // namespace gVirtualXRay
336 
337 
338 //******************************************************************************
339 #include "XRayBeam.inl"
340 
341 
342 #endif // __XRayBeam_h
void setPhotonCountingBands(RATIONAL_NUMBER aMinEnergy, RATIONAL_NUMBER aMaxEnergy, unsigned int aNumberOfBands)
RATIONAL_NUMBER getVoltage() const
Definition: XRayBeam.inl:405
void setTubeAngle(const RATIONAL_NUMBER &anAngle)
Definition: XRayBeam.inl:437
unsigned int getNumberOfPhotonCountingBands()
Definition: XRayBeam.inl:338
void normalise()
Normalise the number of photons so that the total incident energy is 1.0.
RATIONAL_NUMBER getNumberOfPhotons()
Accessor on the total number of photons per pixel when Poisson noise is enable.
Definition: XRayBeam.inl:304
std::vector< std::pair< unsigned int, RATIONAL_NUMBER > > m_filtration
Definition: XRayBeam.h:328
RATIONAL_NUMBER m_number_of_photons_per_pixel
Definition: XRayBeam.h:319
~XRayBeam()
Destructor.
Definition: XRayBeam.inl:123
XRayBeam is a class to handle the X-Ray beam. The beam spectrum is discretised into energy channels...
Definition: XRayBeam.h:108
Type declarations.
const std::vector< std::pair< unsigned int, RATIONAL_NUMBER > > & getFiltration() const
Definition: XRayBeam.inl:532
SpectrumRecord is a class to handle a record of the X-Ray beam, i.e. an energy bin (number of photons...
void setmAs(const RATIONAL_NUMBER &an_mAs)
Definition: XRayBeam.inl:413
Class to manage X-Ray beams. The beam spectrum is discretised into energy channels.
void setVoltage(const RATIONAL_NUMBER &aVoltage)
Definition: XRayBeam.inl:389
bool usingXpecgen() const
Definition: XRayBeam.inl:642
std::string getInterpretor() const
bool usePoissonNoise() const
Check if Poisson noise for the energy fluence is enable or disable.
Definition: XRayBeam.inl:322
bool addChannel(const RATIONAL_NUMBER &aNumberOfPhotons, const RATIONAL_NUMBER &anIncidentEnergy)
Add an energy channel to the beam.
Definition: XRayBeam.inl:161
void enablePoissonNoise()
Enable Poisson noise for the energy fluence.
Definition: XRayBeam.inl:264
RATIONAL_NUMBER m_voltage
Definition: XRayBeam.h:325
void initialise(const char *aFileName, const RATIONAL_NUMBER &aUnit, unsigned int aMergeChannelFlag=1)
Initialise the X-ray beam specturm with a polychromatic spectrum.
void sort()
Sort the spectrum in ascending energy.
Definition: XRayBeam.inl:330
void addFilter(const std::string &aMaterial, const double &aThickness)
Definition: XRayBeam.inl:493
RATIONAL_NUMBER getmAs() const
Definition: XRayBeam.inl:429
RATIONAL_NUMBER m_bin_total_energy_lower_threshold
Definition: XRayBeam.h:313
std::vector< RATIONAL_NUMBER > m_photon_count_bands
Definition: XRayBeam.h:323
void setNumberOfPhotons(RATIONAL_NUMBER aNumberOfPhotons)
Set the total number of photons per pixel when Poisson noise is enable.
Definition: XRayBeam.inl:280
RATIONAL_NUMBER getTubeAngle() const
Definition: XRayBeam.inl:453
RATIONAL_NUMBER m_mAs
Definition: XRayBeam.h:327
std::vector< SpectrumRecord > m_beam_spectrum
Set of photon bins.
Definition: XRayBeam.h:308
float RATIONAL_NUMBER
Type of data used to store real numbers.
Definition: Types.h:107
void clear()
Remove all the energy channels from the beam and all its parameters.
Definition: XRayBeam.inl:131
void clearSpectrumOnly()
Remove all the energy channels from the beam.
Definition: XRayBeam.inl:147
void disablePoissonNoise()
Disable Poisson noise for the energy fluence.
Definition: XRayBeam.inl:272
RATIONAL_NUMBER getTotalEnergy()
Accessor on a total energy of the beam.
Definition: XRayBeam.inl:245
const std::vector< RATIONAL_NUMBER > & getPhotonCountingBands()
Definition: XRayBeam.inl:379
XRayBeam()
Default constructor.
Definition: XRayBeam.inl:105
const SpectrumRecord & getEnergyChannel(unsigned int anID)
Accessor on a given energy bin.
Definition: XRayBeam.inl:230
void setFiltration(const std::vector< std::pair< unsigned int, RATIONAL_NUMBER > > &aSetOfFilters)
Definition: XRayBeam.inl:477
Class to manage a record of the X-Ray beam, i.e. an energy bin (number of photons, energy of the photons in the bin).
void activatePhotonCountingBand(unsigned int aBand)
Definition: XRayBeam.inl:348
unsigned int getEnergyChannelNumber()
Accessor on the number of bins in the spectrum.
Definition: XRayBeam.inl:220
void setBinTotalEnergyCutoff(const RATIONAL_NUMBER &aThreshold)
Set a threshold to discard energy bins with a tiny amount of energy.
Definition: XRayBeam.inl:212
bool m_need_to_update_tube_spectrum
Definition: XRayBeam.h:331
RATIONAL_NUMBER m_tube_angle_in_degrees
Definition: XRayBeam.h:326
bool usingSpekpy() const
Definition: XRayBeam.inl:634
std::vector< std::vector< SpectrumRecord > > m_beam_spectrum_for_photon_count_detector
Set of photon bins.
Definition: XRayBeam.h:322