35 #ifndef __XRayRenderer_h 36 #define __XRayRenderer_h 95 #ifndef __gVirtualXRayConfig_h 105 #include <gsl/gsl_rng.h> 106 #include <gsl/gsl_randist.h> 119 #ifndef __SceneGraphNode_h 123 #ifndef __PolygonMesh_h 127 #ifndef __XRayDetector_h 139 #ifndef __AttenuationCoefficient_h 151 #define XRAY_DETECTOR_PBO_NUMBER 2 152 #define XRAY_DETECTOR_2D_TEXTURE_NUMBER 4 153 #define XRAY_DETECTOR_3D_TEXTURE_NUMBER 1 154 #define XRAY_DETECTOR_SHADER_NUMBER 7 187 typedef enum ComputingModeTag
222 int anInternalTextureFormat,
338 const VEC3& aXRaySourceDetectorTranslation,
339 const MATRIX4& aModellingTransformationMatrix,
340 bool aGPUStateConservationFlag =
true);
361 const VEC3& aXRaySourceDetectorTranslation,
362 const MATRIX4& aModellingTransformationMatrix,
363 bool aGPUStateConservationFlag =
true);
378 bool anIntegrateEnergyFlag =
true);
390 const char* aFileName,
391 bool useCompression =
false);
403 const std::string& aFileName,
404 bool useCompression =
false);
416 const char* aFileName,
417 bool useCompression =
false);
429 const std::string& aFileName,
430 bool useCompression =
false);
440 void printLBuffer(
const char* aFileName,
bool useCompression =
false);
450 void printLBuffer(
const std::string& aFileName,
bool useCompression =
false);
480 void printSumMuxDx(
const char* aFileName,
bool useCompression =
false);
490 void printSumMuxDx(
const std::string& aFileName,
bool useCompression =
false);
521 void printXRayImage(
const char* aFileName,
bool useCompression =
false);
532 void printXRayImage(
const std::string& aFileName,
bool useCompression =
false);
551 GLuint
getFboId(
unsigned int aFBOID);
627 void display(
bool useNormalisation,
632 double gamma = (1.0 / 2.5));
829 unsigned int aNumberOfAngle = 180,
833 void printSinogram(
const char* aFileName,
bool useCompression =
false);
834 void printSinogram(
const std::string& aFileName,
bool useCompression =
false);
846 unsigned int aNumberOfAngle = 180,
873 const std::string& aScreenshotOutputPath,
874 unsigned int aNumberOfProjections,
876 bool anIncludeLastAngleFlag,
878 unsigned int aNumberOfWhiteImagesInFlatField,
879 const VEC3& aPositionOfCentreOfRotation,
880 const VEC3& aAxisOfRotation,
881 bool anIntegrateEnergyFlag =
true,
882 unsigned int aVerboseLevel = 0);
1147 bool anIntegrateEnergyFlag =
true);
1162 bool anIntegrateEnergyFlag =
true);
1239 void init3DData(
int anInternalTextureFormat);
1251 unsigned int aColourTextureIndex,
1252 unsigned int aZBufferTextureIndex = 0);
1271 int anInternalTextureFormat,
1320 const VEC3& aXRaySourceSampleOffset,
1321 const MATRIX4& aModellingTransformationMatrix,
1322 bool aGPUStateConservationFlag);
1336 const VEC3& aXRaySourceSampleOffset,
1337 const MATRIX4& aModellingTransformationMatrix);
1514 #if __cplusplus < 199711L 1526 gsl_rng* m_p_gsl_rng;
1527 gsl_rng** m_pp_gsl_rng;
1562 #endif // __XRayRenderer_h void computeProjectionSet(MATRIX4 &aModellingTransformationMatrix, VEC3 aRotationCenter=VEC3(), unsigned int aNumberOfAngle=180, RATIONAL_NUMBER anAngleOffset=1.0)
void computeCTAcquisition(const std::string &aProjectionOutputPath, const std::string &aScreenshotOutputPath, unsigned int aNumberOfProjections, const RATIONAL_NUMBER &aFirstAngle, bool anIncludeLastAngleFlag, const RATIONAL_NUMBER &aLastAngle, unsigned int aNumberOfWhiteImagesInFlatField, const VEC3 &aPositionOfCentreOfRotation, const VEC3 &aAxisOfRotation, bool anIntegrateEnergyFlag=true, unsigned int aVerboseLevel=0)
Compute the X-ray projections for a CT acquisition.
unsigned int getNumberOfProjectionsCT() const
void init2DFBO(unsigned int aFBOIndex, unsigned int aColourTextureIndex, unsigned int aZBufferTextureIndex=0)
Initialise a FBO (e.g. attach textures, etc.).
void computeIntegratedEnergy(bool anIntegrateEnergyFlag)
Compute the energy fluence.
void printEnergyFluence(const char *aFileName, bool useCompression=false)
Save the current energy fluence into a file (same as printXRayImage()).
void enableArtifactFilteringOnGPU()
Enable artefact filtering on GPU.
Sinogram< PixelType > m_sinogram_image
Sinogram.
Class to manage an attenuation coefficient.
void disableArtefactFilteringOnCPU()
Disable artefact filtering on CPU.
unsigned int getNumberOfOuterSurfaces() const
void removeInnerSurfaces()
Remove the external surface from the renderer if any.
std::vector< VEC3 > m_source_positions_set
void addInnerSurface(const SceneGraphNode *apSurface)
Add a 3D object to be rendered. It will be used as an internal surface.
const std::vector< RATIONAL_NUMBER > & getAngleSetCT() const
void resetSumMuxDx()
Reset the Mu_x * D_x FBO to 0.
bool getNegativeFilteringFlag() const
Accessor on the flag control the display of the final in negative.
XRayBeam is a class to handle the X-Ray beam. The beam spectrum is discretised into energy channels...
RATIONAL_NUMBER * get2DTexture(unsigned int aTextureID)
Accessor on the raw data from a texture.
const std::vector< VEC3 > & getDetectorPositionSet() const
const Sinogram< XRayRenderer::PixelType > & getSinogram() const
const Image< XRayRenderer::PixelType > & getCumulatedLBuffer() const
void computeSinogram(MATRIX4 &aModellingTransformationMatrix, VEC3 aRotationCenter=VEC3(), unsigned int aNumberOfAngle=180, RATIONAL_NUMBER anAngleOffset=1.0)
void computeLBuffer(SceneGraphNode &anObject, const VEC3 &aXRaySourceDetectorTranslation, const MATRIX4 &aModellingTransformationMatrix, bool aGPUStateConservationFlag=true)
Compute the L-buffer of a 3D object.
static RATIONAL_NUMBER getMuFromHUAndMuWater(const RATIONAL_NUMBER &HU, const RATIONAL_NUMBER &mu_water)
Convert a Hounsfield value into a linear attenuation coefficient ( ).
Class to handle GLSL shaders.
void computeImageUsingOpenMP(const MATRIX4 &aModellingTransformationMatrix, bool anIntegrateEnergyFlag=true)
Compute the X-ray image.
const std::vector< VEC3 > & getDetectorUpVectorSet() const
bool m_use_photon_count_detector
std::vector< FramebufferObject * > m_p_fbo_set
The set of FBOs.
void reset2DBuffer(unsigned int aFrameBuffer)
Reset the value of a FBO to 0.
bool isInnerSurface(const SceneGraphNode *apNode)
Check if a given PolygonMesh is an inner surface.
XRayRenderer is a class to compute and renderer X-ray images on GPU.
Computation using OpenGL.
void printSumMuxDx(const char *aFileName, bool useCompression=false)
Save the current Mux Dx into a file.
RATIONAL_NUMBER getLastAngleCT() const
Accessor on the last angle of the CT scan acquisition simulation.
std::vector< unsigned int > m_p_pbo_set
Set of PBOs.
const PixelType * getSinogramRawData() const
void checkGPUCapabilities()
std::vector< VEC3 > m_detector_up_vector_set
void init3DFBOs()
Initialise a FBO with a 3D texture.
unsigned int m_zbuffer_texture_id
Class to handle vertex buffer objects (VBOs).
XRayRenderer()
Default constructor.
void printMuWaterTable(std::ostream &anOutputStream)
Output the talbe of attenuation coefficients of water into a data stream.
bool m_use_l_buffer_artefact_filtering_on_gpu
Flag set to true to use L-buffer artefact filtering.
RATIONAL_NUMBER m_CT_last_angle
RATIONAL_NUMBER getElementMassAttenuation(const char *anElementSymbol, const RATIONAL_NUMBER &anEnergy)
Get the mass attenuation coefficient ( ) of a chemical element.
RATIONAL_NUMBER PixelType
Pixel type.
ComputingMode
Type to store the computation engine (OpenGL, CUDA, OpenCL, etc.).
bool useArtefactFilteringOnGPU() const
void printCumulatedLBuffer(const char *aFileName, bool useCompression=false)
Save the current cumulated L-buffer into a file.
Vec3 is a template class to handle a 3D vector.
bool m_energy_fluence_empty
Flag use for lazy evaluation and blending of the energy fluence.
void addPoissonNoise(Image< PixelType > &anImage)
Use the number of photons to add the Poisson noise.
bool useArtifactFilteringOnGPU() const
RATIONAL_NUMBER m_max_value_in_simulated_xray_image
Max value in simulated X-ray image.
void print2DTexture(unsigned int aTextureID, const char *aFileName, bool useCompression=false)
Save a texture into a file.
void printFBO(unsigned int aFBOID, const char *aFileName, bool useCompression=false)
Save a FBO into a file.
void printProjectionSet(const char *aFileName, bool useCompression=false)
Sinogram is a class to reconstruct images from a sinogram.
Image< PixelType > m_temp_raw_data
The raw data of the last FBO that was loaded in the main memory.
bool getIncludeLastAngleFlagCT() const
static RATIONAL_NUMBER getElementMu(const char *anElementSymbol, const RATIONAL_NUMBER &anEnergy)
Get the linear attenuation coefficient ( ) of a chemical element.
void displayOuterSurface() const
unsigned int getNumberOfInnerSurfaces() const
Class to compute and renderer X-ray images on GPU.
void printXRayImage(const char *aFileName, bool useCompression=false)
bool useArtefactFilteringOnCPU() const
void enableArtefactFilteringOnGPU()
Enable artefact filtering on GPU.
Image< PixelType > m_sum_mux_dx_image
Sum(Mu_x * d_x)
void useNegativeFilteringFlag(bool aFlag=true)
Display the final image in negative or not.
void computeInnerSurfaceLBuffer(PolygonMesh &anObject, const VEC3 &aXRaySourceSampleOffset, const MATRIX4 &aModellingTransformationMatrix, bool aGPUStateConservationFlag)
Compute the L-buffer of an internal object.
Image< PixelType > m_projection_set
Projection set.
GLuint getFboId(unsigned int aFBOID)
Accessor on the OpenGL ID of the FBO.
unsigned int m_CT_white_images_in_flat_field
RATIONAL_NUMBER getMinPixelValue() const
RATIONAL_NUMBER getMaxPixelValue() const
void resetLBuffer()
Reset the L-buffer FBO to 0.
RATIONAL_NUMBER getTotalEnergyWithDetectorResponse() const
Accessor on a total energy of the beam when the detector response is applied.
Image< PixelType > m_cumulated_lbuffer_image
Cumulated L-buffer for all the inner surfaces.
void getEnergyFluenceMinMax()
Normalise the final result to display in OpenGL.
std::vector< std::vector< SceneGraphNode * > > m_p_surface_per_material_set
Class to reconstruct images from a sinogram.
ComputingMode m_computing_mode
The computing mode (OPENGL, CUDA, or OPENCL)
void disableArtefactFilteringOnGPU()
Disable artefact filtering on GPU.
void updateSurfacePerMaterialSet()
void enableArtifactFilteringOnCPU()
Enable artefact filtering on CPU.
XRayDetector is a class to handle a X-ray detector.
bool m_l_buffer_empty
Flag use for lazy evaluation of the L-Buffer.
std::vector< RATIONAL_NUMBER > m_CT_angle_set
PolygonMesh is a class to handle polygon (triangles) meshes.
void computeOuterSurfaceLBuffer(PolygonMesh &anObject, const VEC3 &aXRaySourceSampleOffset, const MATRIX4 &aModellingTransformationMatrix)
Compute the L-buffer of an external object.
Image< PixelType > m_energy_fluence_image
Energy fluence.
Image< XRayRenderer::PixelType > & getEnergyFluence()
Image is a class to manage a greyscale image.
unsigned int m_negative_display_flag
Flag to display the result in negative or not.
void removeOuterSurface()
Remove the internal surfaces from the renderer if any.
unsigned int getMaxRadiusLbufferArtefactFilter() const
Accessor on the max radius of the L-buffer artefact correction filter.
unsigned int getID2DTexture()
Get id 2D texture using OpenGL.
const PixelType * getLBufferRawData()
void displayEnergyFluence()
Display the energy fluence using OpenGL (same as displayXRayImage()).
float RATIONAL_NUMBER
Type of data used to store real numbers.
void deletePBO(unsigned int &aPBO)
Delete a PBO.
bool useArtifactFilteringOnCPU() const
std::auto_ptr< VBO > m_detector_temporary_geometry
The VBO used to display a rectangle corresponding to the detector.
std::string m_CT_screenshot_output_path
const std::vector< VEC3 > & getDetectorRightVectorSet() const
const PixelType * getProjectionSetRawData()
void disableArtifactFilteringOnCPU()
Disable artefact filtering on CPU.
RATIONAL_NUMBER m_min_value_in_simulated_xray_image
Min value in simulated X-ray image.
Vec3< RATIONAL_NUMBER > VEC3
Type of data used to store 3D vectors.
RATIONAL_NUMBER getFirstAngleCT() const
Accessor on the first angle of the CT scan acquisition simulation.
Class to handle a greyscale image.
const VEC3 & getCentreOfRotationPositionCT() const
Class to handle virtual X-Ray detectors.
unsigned int m_max_radius_Lbuffer_artefact_filter
Max radius of L-buffer artefact filter.
void computeImageUsingOpenGL(const MATRIX4 &aModellingTransformationMatrix, bool anIntegrateEnergyFlag=true)
Compute the X-ray image.
bool isOuterSurface(const SceneGraphNode *apNode)
Check if a given PolygonMesh is an outer surface.
const PixelType * getEnergyFluenceRawData()
void displayLBuffer()
Display the L-buffer using OpenGL.
void needUpdateSurfacePerMaterial()
If a surface changes material, it is needed update surfacepermaterial list.
bool isReady() const
Check if the renderer is ready to simulate X-ray images.
std::vector< Shader > m_shader_set
Set of shaders.
void postComputeLBuffer(const GLint *apViewport, RATIONAL_NUMBER aDiagonal)
void createFBOs()
Create the FBOs.
std::default_random_engine * m_p_random_number_generator
void displayInnerSurface(unsigned int anIndex) const
PhotonCrossSection is a class to manage photon cross sections of elements, compounds and mixtures...
void updateVBO()
Update the VBO of the geometry.
GLuint getTextureId(unsigned int aTextureID)
Accessor on the OpenGL ID of the texture.
void addOuterSurface(const SceneGraphNode *apSurface)
Add a 3D object to be rendered. It will be used as an external surface.
void display(bool useNormalisation, bool useLogScale, bool usePowerLaw, double shift=0.0, double scale=1.0, double gamma=(1.0/2.5))
const Image< XRayRenderer::PixelType > & getLBuffer() const
void initialise(ComputingMode aComputingMode, int anInternalTextureFormat, const XRayDetector *apDetector, const XRayBeam *apBeamSpectrum)
Initialise the renderer.
static RATIONAL_NUMBER getMuWaterLogLinearInterpolation(const RATIONAL_NUMBER &anIncidentEnergy)
const std::string & getProjectionOutputPathCT() const
void initShaders()
Initialise the shaders.
XRayDetector * m_p_detector
The X-ray detector.
void initialisePBOs()
Initialise the PBOs.
std::vector< VEC3 > m_detector_right_vector_set
Computation on CPU using OpenMP.
void updateCumulatedLBuffers(unsigned int anObjectID)
RATIONAL_NUMBER m_CT_first_angle
const std::string & getScreenshotOutputPathCT() const
Image< float > getWhiteImage(bool anIntegrateEnergyFlag=true)
Compute the white image (X-ray image without the object).
static RATIONAL_NUMBER getMuFromHU(const RATIONAL_NUMBER &HU, const RATIONAL_NUMBER &anEnergy)
Convert a Hounsfield value into a linear attenuation coefficient ( ).
static void loadMuWater()
Load the table of water attenuation coefficients.
void createPBO(unsigned int &aPBO)
Create a PBO.
const XRayBeam * getXRayBeam() const
Returns the actual Beam.
VEC3 m_CT_centre_of_rotation_position
unsigned int getOptimalNumberOfProjectionsCT() const
void cleanLBuffer(const RATIONAL_NUMBER &aCutoffDistance)
Clean the L-buffer, i.e. remove rendering artefacts.
SceneGraphNode * m_p_outer_surface
The 3D geometry that will wrap the ones in m_p_inner_surface_set.
Class to manage X-Ray beams. The beam spectrum is discretised into energy channels.
std::vector< unsigned int > m_p_texture_name_set
Set of textures.
void display2DTexture(unsigned int aTextureID)
Display a 2D texture using OpenGL.
Image< PixelType > m_l_buffer_image
L-buffer.
void deleteFBOs()
Delete the FBOs.
const VEC3 & getRotationAxisCT() const
void setMaxRadiusLbufferArtefactFilter(unsigned int aRadius)
Set the max radius of the L-buffer artefact correction filter.
void create2DTexture(unsigned int *apTextureID, int anInternalTextureFormat, int aType)
Create a 2D texture.
std::vector< SceneGraphNode * > m_p_inner_surface_set
Set of 3D geometries.
void init3DData(int anInternalTextureFormat)
Initialise the 3D textures.
void computeSumMUxDx(int anObjectID, const PhotonCrossSection &aPhotonCrossSection)
static RATIONAL_NUMBER getMassAttenuationFromHU(const RATIONAL_NUMBER &HU, const RATIONAL_NUMBER &anEnergy)
Convert a Hounsfield value into a mass attenuation coefficient ( ).
void disableArtifactFilteringOnGPU()
Disable artefact filtering on GPU.
bool m_surface_per_material_set_needs_update
void init2DTextures(int anInternalTextureFormat)
Initialise the 2D textures.
Computation using OpenCL.
static std::vector< AttenuationCoefficient > m_mu_water_set
The table of water energy fluence coefficients.
std::string m_CT_projection_output_path
RATIONAL_NUMBER getMuWaterLinearInterpolation(const RATIONAL_NUMBER &anIncidentEnergy)
void resetEnergyFluence()
Reset the energy fluence FBO to 0.
bool m_CT_include_last_angle_flag
XRayBeam * m_p_xray_beam
The X-ray beam.
bool m_use_l_buffer_artefact_filtering_on_cpu
Class to handle polygon (triangles) meshes.
std::vector< SceneGraphNode * > m_p_internal_data_storage
RATIONAL_NUMBER * getFBO(unsigned int aFBOID)
Accessor on the raw data from a FBO.
void printLBuffer(const char *aFileName, bool useCompression=false)
Save the current L-buffer into a file.
Matrix4x4 is a template class to handle a 4 by 4 matrix.
const Image< XRayRenderer::PixelType > & getProjectionSet() const
unsigned int getWhiteImagesInFlatFieldCT() const
RATIONAL_NUMBER getElementDensity(const char *anElementSymbol)
Get the density ( ) of a chemical element.
void computeImage(const MATRIX4 &aModellingTransformationMatrix, bool anIntegrateEnergyFlag=true)
Compute the X-ray image.
~XRayRenderer()
Destructor.
static RATIONAL_NUMBER getDensityFromHU(const RATIONAL_NUMBER &HU)
Get the density ( ) of a tissue given a Hounsfield value.
void printSinogram(const char *aFileName, bool useCompression=false)
void enableArtefactFilteringOnCPU()
Enable artefact filtering on CPU.
const std::vector< VEC3 > & getSourcePositionSet() const
Computation using Vulkan.
std::vector< VEC3 > m_detector_positions_set
void preComputeLBuffer(GLint *apViewport, const VEC3 &aXRaySourceSampleOffset)