gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
XRayRenderer.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 __XRayRenderer_h
36 #define __XRayRenderer_h
37 
38 
92 //******************************************************************************
93 // Include
94 //******************************************************************************
95 #ifndef __gVirtualXRayConfig_h
97 #endif
98 
99 #include <vector>
100 #include <map>
101 #include <string>
102 #include <memory>
103 
104 #ifdef HAS_GSL
105 #include <gsl/gsl_rng.h>
106 #include <gsl/gsl_randist.h>
107 #else
108 #include <random>
109 #endif
110 
111 #ifndef __Image_h
112 #include "gVirtualXRay/Image.h"
113 #endif
114 
115 #ifndef __Sinogram_h
116 #include "gVirtualXRay/Sinogram.h"
117 #endif
118 
119 #ifndef __SceneGraphNode_h
121 #endif
122 
123 #ifndef __PolygonMesh_h
125 #endif
126 
127 #ifndef __XRayDetector_h
129 #endif
130 
131 #ifndef __XRayBeam_h
132 #include "gVirtualXRay/XRayBeam.h"
133 #endif
134 
135 #ifndef __Shader_h
136 #include "gVirtualXRay/Shader.h"
137 #endif
138 
139 #ifndef __AttenuationCoefficient_h
141 #endif
142 
143 #ifndef __VBO_h
144 #include "gVirtualXRay/VBO.h"
145 #endif
146 
147 
148 //******************************************************************************
149 // Definitions
150 //******************************************************************************
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
155 
157 
158 //******************************************************************************
159 // Class definition
160 //******************************************************************************
161 class FramebufferObject;
162 
163 
164 //******************************************************************************
165 // namespace
166 //******************************************************************************
167 namespace gVirtualXRay {
168 
169 
170 //==============================================================================
175 //==============================================================================
177 //------------------------------------------------------------------------------
178 {
179 //******************************************************************************
180 public:
182 
183 
184  //--------------------------------------------------------------------------
186  //--------------------------------------------------------------------------
187  typedef enum ComputingModeTag
188  {
194  } ComputingMode;
195 
196 
197  //--------------------------------------------------------------------------
199  //--------------------------------------------------------------------------
200  XRayRenderer();
201 
202 
203  //--------------------------------------------------------------------------
205  //--------------------------------------------------------------------------
206  ~XRayRenderer();
207 
208 
209  //--------------------------------------------------------------------------
211 
220  //--------------------------------------------------------------------------
221  void initialise(ComputingMode aComputingMode,
222  int anInternalTextureFormat,
223  const XRayDetector* apDetector,
224  const XRayBeam* apBeamSpectrum);
225 
226 
227  //--------------------------------------------------------------------------
230  //--------------------------------------------------------------------------
231  void release();
232 
233 
234  //--------------------------------------------------------------------------
236 
239  //--------------------------------------------------------------------------
240  bool isReady() const;
241 
242 
243  //--------------------------------------------------------------------------
245 
248  //--------------------------------------------------------------------------
250 
251 
252  //--------------------------------------------------------------------------
254 
257  //--------------------------------------------------------------------------
258  void addInnerSurface(const SceneGraphNode* apSurface);
259 
260 
261  //--------------------------------------------------------------------------
263 
266  //--------------------------------------------------------------------------
267  void addOuterSurface(const SceneGraphNode* apSurface);
268 
269 
270  //--------------------------------------------------------------------------
272 
275  //--------------------------------------------------------------------------
276  void addInnerSurface(const PolygonMesh* apSurface);
277 
278 
279  //--------------------------------------------------------------------------
281 
284  //--------------------------------------------------------------------------
285  void addOuterSurface(const PolygonMesh* apSurface);
286 
287 
288  //--------------------------------------------------------------------------
290 
294  //--------------------------------------------------------------------------
295  bool isInnerSurface(const SceneGraphNode* apNode);
296 
297 
298  //--------------------------------------------------------------------------
300 
304  //--------------------------------------------------------------------------
305  bool isOuterSurface(const SceneGraphNode* apNode);
306 
307 
308  //--------------------------------------------------------------------------
310  //--------------------------------------------------------------------------
311  void removeInnerSurfaces();
312 
313 
314  //--------------------------------------------------------------------------
316  //--------------------------------------------------------------------------
317  void removeOuterSurface();
318 
319 
320  //--------------------------------------------------------------------------
322 
336  //--------------------------------------------------------------------------
337  void computeLBuffer(SceneGraphNode& anObject,
338  const VEC3& aXRaySourceDetectorTranslation,
339  const MATRIX4& aModellingTransformationMatrix,
340  bool aGPUStateConservationFlag = true);
341 
342 
343  //--------------------------------------------------------------------------
345 
359  //--------------------------------------------------------------------------
360  void computeLBuffer(PolygonMesh& anObject,
361  const VEC3& aXRaySourceDetectorTranslation,
362  const MATRIX4& aModellingTransformationMatrix,
363  bool aGPUStateConservationFlag = true);
364 
365 
366  //--------------------------------------------------------------------------
368 
376  //--------------------------------------------------------------------------
377  void computeImage(const MATRIX4& aModellingTransformationMatrix,
378  bool anIntegrateEnergyFlag = true);
379 
380 
381  //--------------------------------------------------------------------------
383 
388  //--------------------------------------------------------------------------
389  void printFBO(unsigned int aFBOID,
390  const char* aFileName,
391  bool useCompression = false);
392 
393 
394  //--------------------------------------------------------------------------
396 
401  //--------------------------------------------------------------------------
402  void printFBO(unsigned int aFBOID,
403  const std::string& aFileName,
404  bool useCompression = false);
405 
406 
407  //--------------------------------------------------------------------------
409 
414  //--------------------------------------------------------------------------
415  void print2DTexture(unsigned int aTextureID,
416  const char* aFileName,
417  bool useCompression = false);
418 
419 
420  //--------------------------------------------------------------------------
422 
427  //--------------------------------------------------------------------------
428  void print2DTexture(unsigned int aTextureID,
429  const std::string& aFileName,
430  bool useCompression = false);
431 
432 
433  //--------------------------------------------------------------------------
435 
439  //--------------------------------------------------------------------------
440  void printLBuffer(const char* aFileName, bool useCompression = false);
441 
442 
443  //--------------------------------------------------------------------------
445 
449  //--------------------------------------------------------------------------
450  void printLBuffer(const std::string& aFileName, bool useCompression = false);
451 
452 
453  //--------------------------------------------------------------------------
455 
459  //--------------------------------------------------------------------------
460  void printCumulatedLBuffer(const char* aFileName, bool useCompression = false);
461 
462 
463  //--------------------------------------------------------------------------
465 
469  //--------------------------------------------------------------------------
470  void printCumulatedLBuffer(const std::string& aFileName, bool useCompression = false);
471 
472 
473  //--------------------------------------------------------------------------
475 
479  //--------------------------------------------------------------------------
480  void printSumMuxDx(const char* aFileName, bool useCompression = false);
481 
482 
483  //--------------------------------------------------------------------------
485 
489  //--------------------------------------------------------------------------
490  void printSumMuxDx(const std::string& aFileName, bool useCompression = false);
491 
492 
493  //--------------------------------------------------------------------------
495 
499  //--------------------------------------------------------------------------
500  void printEnergyFluence(const char* aFileName, bool useCompression = false);
501 
502 
503  //--------------------------------------------------------------------------
505 
509  //--------------------------------------------------------------------------
510  void printEnergyFluence(const std::string& aFileName, bool useCompression = false);
511 
512 
513  //--------------------------------------------------------------------------
516 
520  //--------------------------------------------------------------------------
521  void printXRayImage(const char* aFileName, bool useCompression = false);
522 
523 
524  //--------------------------------------------------------------------------
527 
531  //--------------------------------------------------------------------------
532  void printXRayImage(const std::string& aFileName, bool useCompression = false);
533 
534 
535  //--------------------------------------------------------------------------
537 
540  //--------------------------------------------------------------------------
541  RATIONAL_NUMBER* getFBO(unsigned int aFBOID);
542 
543 
544  //--------------------------------------------------------------------------
546 
550  //--------------------------------------------------------------------------
551  GLuint getFboId(unsigned int aFBOID);
552 
553 
554  //--------------------------------------------------------------------------
556 
560  //--------------------------------------------------------------------------
561  GLuint getTextureId(unsigned int aTextureID);
562 
563 
564  //--------------------------------------------------------------------------
566 
569  //--------------------------------------------------------------------------
570  RATIONAL_NUMBER* get2DTexture(unsigned int aTextureID);
571 
572 
573  //--------------------------------------------------------------------------
575 
578  //--------------------------------------------------------------------------
579  void display2DTexture(unsigned int aTextureID);
580 
581 
582  //--------------------------------------------------------------------------
584  //--------------------------------------------------------------------------
585  unsigned int getID2DTexture();
586 
587 
588  //--------------------------------------------------------------------------
590  //--------------------------------------------------------------------------
591  void displayLBuffer();
592 
593 
594  //--------------------------------------------------------------------------
596  //--------------------------------------------------------------------------
597  void displayEnergyFluence();
598 
599 
600  //--------------------------------------------------------------------------
603  //--------------------------------------------------------------------------
604  void displayXRayImage();
605 
606 
607  //--------------------------------------------------------------------------
609  //--------------------------------------------------------------------------
610  void getEnergyFluenceMinMax();
611 
612 
613  //--------------------------------------------------------------------------
618 
626  //--------------------------------------------------------------------------
627  void display(bool useNormalisation,
628  bool useLogScale,
629  bool usePowerLaw,
630  double shift = 0.0,
631  double scale = 1.0,
632  double gamma = (1.0 / 2.5));
633 
634 
635  //--------------------------------------------------------------------------
638 
642  //--------------------------------------------------------------------------
644  const RATIONAL_NUMBER& anIncidentEnergy);
645 
646 
647  //--------------------------------------------------------------------------
650 
654  //--------------------------------------------------------------------------
656  const RATIONAL_NUMBER& anIncidentEnergy);
657 
658 
659  //--------------------------------------------------------------------------
661 
667  //--------------------------------------------------------------------------
669  const RATIONAL_NUMBER& mu_water);
670 
671 
672  //--------------------------------------------------------------------------
674 
679  //--------------------------------------------------------------------------
681  const RATIONAL_NUMBER& anEnergy);
682 
683 
684  //--------------------------------------------------------------------------
686 
691  //--------------------------------------------------------------------------
693  const RATIONAL_NUMBER& anEnergy);
694 
695 
696  //--------------------------------------------------------------------------
698 
702  //--------------------------------------------------------------------------
704 
705 
706  //--------------------------------------------------------------------------
708 
713  //--------------------------------------------------------------------------
714  static RATIONAL_NUMBER getElementMu(const char* anElementSymbol,
715  const RATIONAL_NUMBER& anEnergy);
716 
717 
718  //--------------------------------------------------------------------------
720 
725  //--------------------------------------------------------------------------
726  RATIONAL_NUMBER getElementMassAttenuation(const char* anElementSymbol,
727  const RATIONAL_NUMBER& anEnergy);
728 
729 
730  //--------------------------------------------------------------------------
732 
736  //--------------------------------------------------------------------------
737  RATIONAL_NUMBER getElementDensity(const char* anElementSymbol);
738 
739 
740  //--------------------------------------------------------------------------
742 
746  //--------------------------------------------------------------------------
747  void useNegativeFilteringFlag(bool aFlag = true);
748 
749 
750  //--------------------------------------------------------------------------
752 
756  //--------------------------------------------------------------------------
757  bool getNegativeFilteringFlag() const;
758 
759 
760  //--------------------------------------------------------------------------
762 
765  //--------------------------------------------------------------------------
766  void printMuWaterTable(std::ostream& anOutputStream);
767 
768 
769  //--------------------------------------------------------------------------
772 
775  //--------------------------------------------------------------------------
776  unsigned int getNumberOfInnerSurfaces() const;
777 
778 
779  //--------------------------------------------------------------------------
783 
786  //--------------------------------------------------------------------------
787  unsigned int getNumberOfOuterSurfaces() const;
788 
789 
790  //--------------------------------------------------------------------------
793 
796  //--------------------------------------------------------------------------
797  void displayInnerSurface(unsigned int anIndex) const;
798 
799 
800  //--------------------------------------------------------------------------
803  //--------------------------------------------------------------------------
804  void displayOuterSurface() const;
805 
806 
807  //--------------------------------------------------------------------------
810 
813  //--------------------------------------------------------------------------
815 
816 
817  //--------------------------------------------------------------------------
820 
823  //--------------------------------------------------------------------------
825 
826 
827  void computeSinogram(MATRIX4& aModellingTransformationMatrix,
828  VEC3 aRotationCenter = VEC3(),
829  unsigned int aNumberOfAngle = 180,
830  RATIONAL_NUMBER anAngleOffset = 1.0);
831 
832 
833  void printSinogram(const char* aFileName, bool useCompression = false);
834  void printSinogram(const std::string& aFileName, bool useCompression = false);
835 
836 
839 
840 
841  const PixelType* getSinogramRawData() const;
842 
843 
844  void computeProjectionSet(MATRIX4& aModellingTransformationMatrix,
845  VEC3 aRotationCenter = VEC3(),
846  unsigned int aNumberOfAngle = 180,
847  RATIONAL_NUMBER anAngleOffset = 1.0);
848 
849 
850 
851  //--------------------------------------------------------------------------
853 
871  //--------------------------------------------------------------------------
872  void computeCTAcquisition(const std::string& aProjectionOutputPath,
873  const std::string& aScreenshotOutputPath,
874  unsigned int aNumberOfProjections,
875  const RATIONAL_NUMBER& aFirstAngle,
876  bool anIncludeLastAngleFlag,
877  const RATIONAL_NUMBER& aLastAngle,
878  unsigned int aNumberOfWhiteImagesInFlatField,
879  const VEC3& aPositionOfCentreOfRotation,
880  const VEC3& aAxisOfRotation,
881  bool anIntegrateEnergyFlag = true,
882  unsigned int aVerboseLevel = 0);
883 
884 
885  //--------------------------------------------------------------------------
888 
891  //--------------------------------------------------------------------------
892  const std::string& getProjectionOutputPathCT() const;
893 
894 
895  //--------------------------------------------------------------------------
898 
901  //--------------------------------------------------------------------------
902  const std::string& getScreenshotOutputPathCT() const;
903 
904 
905  //--------------------------------------------------------------------------
908 
911  //--------------------------------------------------------------------------
912  unsigned int getNumberOfProjectionsCT() const;
913 
914 
915  //--------------------------------------------------------------------------
919 
922  //--------------------------------------------------------------------------
923  unsigned int getOptimalNumberOfProjectionsCT() const;
924 
925 
926  //--------------------------------------------------------------------------
928 
931  //--------------------------------------------------------------------------
933 
934 
935  //--------------------------------------------------------------------------
937 
940  //--------------------------------------------------------------------------
942 
943 
944  //--------------------------------------------------------------------------
947 
950  //--------------------------------------------------------------------------
951  bool getIncludeLastAngleFlagCT() const;
952 
953 
954  //--------------------------------------------------------------------------
958 
961  //--------------------------------------------------------------------------
962  unsigned int getWhiteImagesInFlatFieldCT() const;
963 
964 
965  //--------------------------------------------------------------------------
968 
971  //--------------------------------------------------------------------------
972  const VEC3& getCentreOfRotationPositionCT() const;
973 
974 
975  //--------------------------------------------------------------------------
978 
981  //--------------------------------------------------------------------------
982  const VEC3& getRotationAxisCT() const;
983 
984 
985  //--------------------------------------------------------------------------
988 
991  //--------------------------------------------------------------------------
992  const std::vector<RATIONAL_NUMBER>& getAngleSetCT() const;
993 
994 
995  void printProjectionSet(const char* aFileName, bool useCompression = false);
996  void printProjectionSet(const std::string& aFileName, bool useCompression = false);
997 
998 
1001 
1002 
1004 
1005 
1006  // const Image<XRayRenderer::PixelType>& getEnergyFluence() const;
1008 
1009 
1011 
1012 
1015 
1016 
1019 
1020 
1021  const PixelType* getLBufferRawData();
1022 
1023  //--------------------------------------------------------------------------
1025 
1028  //--------------------------------------------------------------------------
1029  const XRayBeam* getXRayBeam( ) const;
1030 
1031 
1032  //--------------------------------------------------------------------------
1034  //--------------------------------------------------------------------------
1036 
1037 
1038  //--------------------------------------------------------------------------
1040  //--------------------------------------------------------------------------
1042 
1043 
1044  //--------------------------------------------------------------------------
1046  //--------------------------------------------------------------------------
1048 
1049 
1050  //--------------------------------------------------------------------------
1052  //--------------------------------------------------------------------------
1054 
1055 
1056  //--------------------------------------------------------------------------
1058  //--------------------------------------------------------------------------
1060 
1061 
1062  //--------------------------------------------------------------------------
1064  //--------------------------------------------------------------------------
1066 
1067 
1068  //--------------------------------------------------------------------------
1070  //--------------------------------------------------------------------------
1072 
1073 
1074  //--------------------------------------------------------------------------
1076  //--------------------------------------------------------------------------
1078 
1079 
1080  void useArtifactFilteringOnGPU(bool aFlag);
1081  void useArtifactFilteringOnCPU(bool aFlag);
1082 
1083  void useArtefactFilteringOnGPU(bool aFlag);
1084  void useArtefactFilteringOnCPU(bool aFlag);
1085 
1086  bool useArtifactFilteringOnGPU() const;
1087  bool useArtifactFilteringOnCPU() const;
1088 
1089  bool useArtefactFilteringOnGPU() const;
1090  bool useArtefactFilteringOnCPU() const;
1091 
1092  //--------------------------------------------------------------------------
1094 
1097  //--------------------------------------------------------------------------
1098  unsigned int getMaxRadiusLbufferArtefactFilter() const;
1099 
1100 
1101  //--------------------------------------------------------------------------
1103 
1106  //--------------------------------------------------------------------------
1107  void setMaxRadiusLbufferArtefactFilter(unsigned int aRadius);
1108 
1109 
1110  //--------------------------------------------------------------------------
1112  //--------------------------------------------------------------------------
1114 
1115 
1116  //--------------------------------------------------------------------------
1118 
1123  //--------------------------------------------------------------------------
1124  Image<float> getWhiteImage(bool anIntegrateEnergyFlag = true);
1125 
1126 
1127  const std::vector<VEC3>& getSourcePositionSet() const;
1128  const std::vector<VEC3>& getDetectorPositionSet() const;
1129  const std::vector<VEC3>& getDetectorRightVectorSet() const;
1130  const std::vector<VEC3>& getDetectorUpVectorSet() const;
1131 
1132 
1133 //******************************************************************************
1134 protected:
1135  //--------------------------------------------------------------------------
1137 
1145  //--------------------------------------------------------------------------
1146  void computeImageUsingOpenGL(const MATRIX4& aModellingTransformationMatrix,
1147  bool anIntegrateEnergyFlag = true);
1148 
1149 
1150  //--------------------------------------------------------------------------
1152 
1160  //--------------------------------------------------------------------------
1161  void computeImageUsingOpenMP(const MATRIX4& aModellingTransformationMatrix,
1162  bool anIntegrateEnergyFlag = true);
1163 
1164 
1165  //--------------------------------------------------------------------------
1167  //--------------------------------------------------------------------------
1168  static void loadMuWater();
1169 
1170 
1171  //--------------------------------------------------------------------------
1174  //--------------------------------------------------------------------------
1175  void checkGPUCapabilities();
1176 
1177 
1178  //--------------------------------------------------------------------------
1180  //--------------------------------------------------------------------------
1181  void initShaders();
1182 
1183 
1184  //--------------------------------------------------------------------------
1186  //--------------------------------------------------------------------------
1187  void createFBOs();
1188 
1189 
1190  //--------------------------------------------------------------------------
1192  //--------------------------------------------------------------------------
1193  void deleteFBOs();
1194 
1195 
1196  //--------------------------------------------------------------------------
1198 
1201  //--------------------------------------------------------------------------
1202  void createPBO(unsigned int& aPBO);
1203 
1204 
1205  //--------------------------------------------------------------------------
1207 
1210  //--------------------------------------------------------------------------
1211  void deletePBO(unsigned int& aPBO);
1212 
1213 
1214  //--------------------------------------------------------------------------
1216  //--------------------------------------------------------------------------
1217  void initialisePBOs();
1218 
1219 
1220  //--------------------------------------------------------------------------
1222 
1227  //--------------------------------------------------------------------------
1228  void init2DTextures(int anInternalTextureFormat);
1229 
1230 
1231  //--------------------------------------------------------------------------
1233 
1238  //--------------------------------------------------------------------------
1239  void init3DData(int anInternalTextureFormat);
1240 
1241 
1242  //--------------------------------------------------------------------------
1244 
1249  //--------------------------------------------------------------------------
1250  void init2DFBO(unsigned int aFBOIndex,
1251  unsigned int aColourTextureIndex,
1252  unsigned int aZBufferTextureIndex = 0);
1253 
1254 
1255  //--------------------------------------------------------------------------
1257  //--------------------------------------------------------------------------
1258  void init3DFBOs();
1259 
1260 
1261  //--------------------------------------------------------------------------
1263 
1269  //--------------------------------------------------------------------------
1270  void create2DTexture(unsigned int* apTextureID,
1271  int anInternalTextureFormat,
1272  int aType);
1273 
1274 
1275  //--------------------------------------------------------------------------
1277 
1280  //--------------------------------------------------------------------------
1281  void reset2DBuffer(unsigned int aFrameBuffer);
1282 
1283 
1284  //--------------------------------------------------------------------------
1286  //--------------------------------------------------------------------------
1287  void resetLBuffer();
1288 
1289 
1290  //--------------------------------------------------------------------------
1292  //--------------------------------------------------------------------------
1293  void resetEnergyFluence();
1294 
1295 
1296  //--------------------------------------------------------------------------
1298  //--------------------------------------------------------------------------
1299  void resetSumMuxDx();
1300 
1301 
1302  //--------------------------------------------------------------------------
1304 
1318  //--------------------------------------------------------------------------
1319  void computeInnerSurfaceLBuffer(PolygonMesh& anObject,
1320  const VEC3& aXRaySourceSampleOffset,
1321  const MATRIX4& aModellingTransformationMatrix,
1322  bool aGPUStateConservationFlag);
1323 
1324  //--------------------------------------------------------------------------
1326 
1334  //--------------------------------------------------------------------------
1335  void computeOuterSurfaceLBuffer(PolygonMesh& anObject,
1336  const VEC3& aXRaySourceSampleOffset,
1337  const MATRIX4& aModellingTransformationMatrix);
1338 
1339 
1340  //--------------------------------------------------------------------------
1343 
1350  //--------------------------------------------------------------------------
1351  void updateCumulatedLBuffers(unsigned int anObjectID);
1352 
1353 
1354  //--------------------------------------------------------------------------
1357 
1361  //--------------------------------------------------------------------------
1362  void computeSumMUxDx(int anObjectID,
1363  const PhotonCrossSection& aPhotonCrossSection);
1364 
1365 
1366  //--------------------------------------------------------------------------
1368 
1372  //--------------------------------------------------------------------------
1373  void computeIntegratedEnergy(bool anIntegrateEnergyFlag);
1374 
1375 
1376  //--------------------------------------------------------------------------
1378 
1384  //--------------------------------------------------------------------------
1385  void cleanLBuffer(const RATIONAL_NUMBER& aCutoffDistance);
1386 
1387 
1388  //--------------------------------------------------------------------------
1390  //--------------------------------------------------------------------------
1391  void updateVBO();
1392 
1393 
1394  void preComputeLBuffer(GLint* apViewport, const VEC3& aXRaySourceSampleOffset);
1395  void postComputeLBuffer(const GLint* apViewport, RATIONAL_NUMBER aDiagonal);
1396 
1398 
1399 
1400  //--------------------------------------------------------------------------
1402 
1405  //--------------------------------------------------------------------------
1406  void addPoissonNoise(Image<PixelType>& anImage);
1407 
1408 
1411 
1412 
1415 
1416 
1418  std::vector<SceneGraphNode*> m_p_inner_surface_set;
1419 
1420 
1423 
1424 
1425  std::vector<SceneGraphNode*> m_p_internal_data_storage;
1426 
1427 
1428  std::vector<std::vector<SceneGraphNode*> > m_p_surface_per_material_set;
1430 
1431 
1434 
1435 
1437  std::vector<unsigned int> m_p_pbo_set;
1438 
1439 
1441  std::vector<unsigned int> m_p_texture_name_set;
1442 
1443 
1445  std::vector<Shader> m_shader_set;
1446 
1447 
1450 
1451 
1453  static std::vector<AttenuationCoefficient> m_mu_water_set;
1454 
1455 
1457  std::vector<FramebufferObject*> m_p_fbo_set;
1458 
1459 
1462 
1463 
1466 
1467 
1470 
1471 
1474 
1475 
1478 
1479 
1482 
1483 
1486 
1487 
1490 
1491 
1494 
1495 
1499 
1500 
1503 
1504 
1507 
1508 
1511 
1512 
1514 #if __cplusplus < 199711L
1515  std::auto_ptr<VBO> m_detector_temporary_geometry;
1516 #else
1517  std::unique_ptr<VBO> m_detector_temporary_geometry;
1518 #endif
1519 
1520  unsigned int m_zbuffer_texture_id;
1521 
1522  unsigned int m_precision;
1523 
1524 
1525  #ifdef HAS_GSL
1526  gsl_rng* m_p_gsl_rng;
1527  gsl_rng** m_pp_gsl_rng;
1528  #else
1529  std::default_random_engine* m_p_random_number_generator;
1530  #endif
1531 
1533 
1536 
1540 
1542 
1545 
1546  std::vector<VEC3> m_source_positions_set;
1547  std::vector<VEC3> m_detector_positions_set;
1548  std::vector<VEC3> m_detector_right_vector_set;
1549  std::vector<VEC3> m_detector_up_vector_set;
1550 
1551  std::vector<RATIONAL_NUMBER> m_CT_angle_set;
1552 };
1553 
1554 
1555 } // namespace gVirtualXRay
1556 
1557 
1558 //******************************************************************************
1559 #include "XRayRenderer.inl"
1560 
1561 
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...
Definition: XRayBeam.h:108
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
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.
Definition: XRayRenderer.h:176
Computation using OpenGL.
Definition: XRayRenderer.h:189
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
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.
Definition: XRayRenderer.h:181
ComputingMode
Type to store the computation engine (OpenGL, CUDA, OpenCL, etc.).
Definition: XRayRenderer.h:187
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.
Definition: Vec3.h:88
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.
Definition: Image.h:94
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.
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 enableArtifactFilteringOnCPU()
Enable artefact filtering on CPU.
XRayDetector is a class to handle a X-ray detector.
Definition: XRayDetector.h:122
bool m_l_buffer_empty
Flag use for lazy evaluation of the L-Buffer.
Computation using CUDA.
Definition: XRayRenderer.h:191
std::vector< RATIONAL_NUMBER > m_CT_angle_set
PolygonMesh is a class to handle polygon (triangles) meshes.
Definition: PolygonMesh.h:114
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.
Definition: Image.h:92
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.
Definition: Types.h:107
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.
Definition: Types.h:115
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.
Definition: XRayRenderer.h:193
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.
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.
void init2DTextures(int anInternalTextureFormat)
Initialise the 2D textures.
Computation using OpenCL.
Definition: XRayRenderer.h:192
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.
XRayBeam * m_p_xray_beam
The X-ray beam.
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.
Definition: Matrix4x4.h:89
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.
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.
Definition: XRayRenderer.h:190
std::vector< VEC3 > m_detector_positions_set
void preComputeLBuffer(GLint *apViewport, const VEC3 &aXRaySourceSampleOffset)