1.3.49
 
Loading...
Searching...
No Matches
RadiationModel.h
Go to the documentation of this file.
1
16#ifndef RADIATION_MODEL
17#define RADIATION_MODEL
18
19#include "CameraCalibration.h"
20#include "Context.h"
21#include "json.hpp"
22
23// NVIDIA OptiX Includes
24#include <optix.h>
25#include <optixu/optixpp_namespace.h>
26#include <optixu/optixu_vector_functions.h>
27#include <optixu/optixu_vector_types.h>
28
29#include <utility>
30
33
34 bool operator!=(const CameraProperties &rhs) const {
35 return !(rhs == *this);
36 }
37
40
43
46
48 float HFOV;
49
52
56 lens_diameter = 0.05;
57 FOV_aspect_ratio = 1.f;
58 HFOV = 20.f;
59 FOV_aspect_ratio = 1.f;
60 }
61
62 bool operator==(const CameraProperties &rhs) const {
64 }
65};
66
69
70 // Constructor
71 RadiationCamera(std::string initlabel, const std::vector<std::string> &band_label, const helios::vec3 &initposition, const helios::vec3 &initlookat, const CameraProperties &camera_properties, uint initantialiasing_samples) :
72 label(std::move(initlabel)), band_labels(band_label), position(initposition), lookat(initlookat), antialiasing_samples(initantialiasing_samples) {
73 for (const auto &band: band_label) {
74 band_spectral_response[band] = "uniform";
75 }
76 focal_length = camera_properties.focal_plane_distance;
77 resolution = camera_properties.camera_resolution;
78 lens_diameter = camera_properties.lens_diameter;
79 HFOV_degrees = camera_properties.HFOV;
80 FOV_aspect_ratio = camera_properties.FOV_aspect_ratio;
81 }
82
83 // Label for camera array
84 std::string label;
85 // Cartesian (x,y,z) position of camera array center
86 helios::vec3 position;
87 // Direction camera is pointed (normal vector of camera surface). This vector will automatically be normalized
88 helios::vec3 lookat;
89 // Physical dimensions of the camera lens
90 float lens_diameter;
91 // Resolution of camera sub-divisions (i.e., pixels)
92 helios::int2 resolution;
93 // camera focal length.
94 float focal_length;
95 // camera horizontal field of view (degrees)
96 float HFOV_degrees;
97 // Ratio of camera horizontal field of view to vertical field of view
98 float FOV_aspect_ratio;
99 // Number of antialiasing samples per pixel
100 uint antialiasing_samples;
101
102 std::vector<std::string> band_labels;
103
104 std::map<std::string, std::string> band_spectral_response;
105
106 std::map<std::string, std::vector<float>> pixel_data;
107
108 std::vector<uint> pixel_label_UUID;
109 std::vector<float> pixel_depth;
110
112 void normalizePixels();
113
115
122
128 void whiteBalance(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float p = 5.0);
129
131
140 void whiteBalanceGrayEdge(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, int derivative_order = 1, float p = 5.0);
141
143
150 void whiteBalanceWhitePatch(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float percentile = 0.99f);
151
153
159 void whiteBalanceAuto(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
160
162
170 void applyCameraSpectralCorrection(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, helios::Context *context);
171
173
180 void reinhardToneMapping(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
181
183
191 void applyGain(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float percentile = 0.95f);
192
194
199 void adjustSBC(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float saturation, float brightness, float contrast);
200
202
207 // void applyCCM(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
208
210
217 void gammaCompress(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
218
226 void globalHistogramEqualization(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
227
229
235 void autoExposure(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float gain_multiplier);
236
238
245 void adjustBrightnessContrast(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float brightness, float contrast);
246
248
254 void adjustSaturation(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float saturation);
255
256private:
258
264 static float luminance(float red, float green, float blue) noexcept {
265 return 0.2126f * red + 0.7152f * green + 0.0722f * blue;
266 }
267
269
273 static float lin_to_srgb(float x) noexcept {
274 // Clamp negative values to 0, bright values > 1.0 to white (1.0)
275 if (x <= 0.0f)
276 return 0.0f;
277 if (x >= 1.0f)
278 return 1.0f; // Bright pixels clipped to white
279 return (x <= 0.0031308f) ? 12.92f * x : 1.055f * std::pow(x, 1.0f / 2.4f) - 0.055f;
280 }
281
283
287 static float srgb_to_lin(float v) noexcept {
288 return (v <= 0.04045f) ? v / 12.92f : std::pow((v + 0.055f) / 1.055f, 2.4f);
289 }
290};
291
294
296 explicit RadiationBand(std::string a_label, size_t directRayCount_default, size_t diffuseRayCount_default, float diffuseFlux_default, uint scatteringDepth_default, float minScatterEnergy_default) : label(std::move(a_label)) {
297 directRayCount = directRayCount_default;
298 diffuseRayCount = diffuseRayCount_default;
299 diffuseFlux = diffuseFlux_default;
300 scatteringDepth = scatteringDepth_default;
301 minScatterEnergy = minScatterEnergy_default;
302 diffuseExtinction = 0.f;
303 diffuseDistNorm = 1.f;
304 emissionFlag = true;
306 }
307
309 std::string label;
310
313
316
319
322
325
328
330 std::vector<helios::vec2> diffuse_spectrum;
331
334
337
340
343};
344
346enum RadiationSourceType { RADIATION_SOURCE_TYPE_COLLIMATED = 0, RADIATION_SOURCE_TYPE_SPHERE = 1, RADIATION_SOURCE_TYPE_SUN_SPHERE = 2, RADIATION_SOURCE_TYPE_RECTANGLE = 3, RADIATION_SOURCE_TYPE_DISK = 4 };
347
350public:
352 explicit RadiationSource(const helios::vec3 &position) : source_position(position) {
353 source_type = RADIATION_SOURCE_TYPE_COLLIMATED;
354
355 // initialize other unused variables
358 };
359
361 RadiationSource(const helios::vec3 &position, float width) : source_position(position) {
362 source_type = RADIATION_SOURCE_TYPE_SPHERE;
363
364 source_width = helios::make_vec2(width, width);
365
366 // initialize other unused variables
369 };
370
372 RadiationSource(const helios::vec3 &position, float position_scaling_factor, float width, float flux_scaling_factor) :
373 source_position(position), source_position_scaling_factor(position_scaling_factor), source_flux_scaling_factor(flux_scaling_factor) {
374 source_type = RADIATION_SOURCE_TYPE_SUN_SPHERE;
375 source_width = helios::make_vec2(width, width);
376 };
377
378
380 RadiationSource(const helios::vec3 &position, const helios::vec2 &size, const helios::vec3 &rotation) : source_position(position), source_width(size), source_rotation(rotation) {
381 source_type = RADIATION_SOURCE_TYPE_RECTANGLE;
382
383 // initialize other unused variables
386 };
387
389 RadiationSource(const helios::vec3 &position, float width, const helios::vec3 &rotation) : source_position(position), source_rotation(rotation) {
390 source_type = RADIATION_SOURCE_TYPE_DISK;
391
392 source_width = helios::make_vec2(width, width);
393
394 // initialize other unused variables
397 };
398
401
404
406 std::vector<helios::vec2> source_spectrum;
407
408 std::string source_spectrum_label = "none";
409
412
415
418
421
423 std::map<std::string, float> source_fluxes;
424};
425
428public:
430 explicit RadiationModel(helios::Context *context);
431
434
436
439 static int selfTest(int argc = 0, char **argv = nullptr);
440
442
445 void disableMessages();
446
448 void enableMessages();
449
451
454 void optionalOutputPrimitiveData(const char *label);
455
457
462 void setDirectRayCount(const std::string &label, size_t N);
463
465
470 void setDiffuseRayCount(const std::string &label, size_t N);
471
473
478 void setDiffuseRadiationFlux(const std::string &label, float flux);
479
481
488 void setDiffuseRadiationExtinctionCoeff(const std::string &label, float K, const helios::vec3 &peak_dir);
489
491
498 void setDiffuseRadiationExtinctionCoeff(const std::string &label, float K, const helios::SphericalCoord &peak_dir);
499
501
505 void setDiffuseSpectrumIntegral(float spectrum_integral);
506
508
514 void setDiffuseSpectrumIntegral(float spectrum_integral, float wavelength_min, float wavelength_max);
515
517
522 void setDiffuseSpectrumIntegral(const std::string &band_label, float spectrum_integral);
523
525
532 void setDiffuseSpectrumIntegral(const std::string &band_label, float spectrum_integral, float wavelength_min, float wavelength_max);
533
535
538 void addRadiationBand(const std::string &label);
539
541
546 void addRadiationBand(const std::string &label, float wavelength_min, float wavelength_max);
547
549
553 void copyRadiationBand(const std::string &old_label, const std::string &new_label);
554
556
562 void copyRadiationBand(const std::string &old_label, const std::string &new_label, float wavelength_min, float wavelength_max);
563
565
568 bool doesBandExist(const std::string &label) const;
569
571
574 void disableEmission(const std::string &label);
575
577
580 void enableEmission(const std::string &label);
581
583
587
589
594
596
601
603
608 uint addSphereRadiationSource(const helios::vec3 &position, float radius);
609
611
615
617
622
624
628 uint addSunSphereRadiationSource(const helios::vec3 &sun_direction);
629
631
637 uint addRectangleRadiationSource(const helios::vec3 &position, const helios::vec2 &size, const helios::vec3 &rotation);
638
640
646 uint addDiskRadiationSource(const helios::vec3 &position, float radius, const helios::vec3 &rotation);
647
649
652 void deleteRadiationSource(uint sourceID);
653
655
660 void setSourceSpectrumIntegral(uint source_ID, float source_integral);
661
663
670 void setSourceSpectrumIntegral(uint source_ID, float source_integral, float wavelength_min, float wavelength_max);
671
673
678 void setSourceFlux(uint source_ID, const std::string &band_label, float flux);
679
681
686 void setSourceFlux(const std::vector<uint> &source_ID, const std::string &band_label, float flux);
687
689
694 float getSourceFlux(uint source_ID, const std::string &band_label) const;
695
697
701 void setSourcePosition(uint source_ID, const helios::vec3 &position);
702
704
708 void setSourcePosition(uint source_ID, const helios::SphericalCoord &position);
709
711
715 helios::vec3 getSourcePosition(uint source_ID) const;
716
718
722 void setSourceSpectrum(uint source_ID, const std::vector<helios::vec2> &spectrum);
723
725
729 void setSourceSpectrum(const std::vector<uint> &source_ID, const std::vector<helios::vec2> &spectrum);
730
732
736 void setSourceSpectrum(uint source_ID, const std::string &spectrum_label);
737
739
743 void setSourceSpectrum(const std::vector<uint> &source_ID, const std::string &spectrum_label);
744
746
750 void setDiffuseSpectrum(const std::string &band_label, const std::string &spectrum_label);
751
753
757 void setDiffuseSpectrum(const std::vector<std::string> &band_labels, const std::string &spectrum_label);
758
760
764 float getDiffuseFlux(const std::string &band_label) const;
765
768
771
774
777
779
785 float integrateSpectrum(const std::vector<helios::vec2> &object_spectrum, float wavelength_min, float wavelength_max) const;
786
788
792 float integrateSpectrum(const std::vector<helios::vec2> &object_spectrum) const;
793
795
802 float integrateSpectrum(uint source_ID, const std::vector<helios::vec2> &object_spectrum, float wavelength_min, float wavelength_max) const;
803
805
811 float integrateSpectrum(uint source_ID, const std::vector<helios::vec2> &object_spectrum, const std::vector<helios::vec2> &camera_spectrum) const;
812
814
819 float integrateSpectrum(const std::vector<helios::vec2> &object_spectrum, const std::vector<helios::vec2> &camera_spectrum) const;
820
822
828 float integrateSourceSpectrum(uint source_ID, float wavelength_min, float wavelength_max) const;
829
831
836 void scaleSpectrum(const std::string &existing_global_data_label, const std::string &new_global_data_label, float scale_factor) const;
837
839
843 void scaleSpectrum(const std::string &global_data_label, float scale_factor) const;
844
846
852 void scaleSpectrumRandomly(const std::string &existing_global_data_label, const std::string &new_global_data_label, float minimum_scale_factor, float maximum_scale_factor) const;
853
855
861 void blendSpectra(const std::string &new_spectrum_label, const std::vector<std::string> &spectrum_labels, const std::vector<float> &weights) const;
862
864
869 void blendSpectraRandomly(const std::string &new_spectrum_label, const std::vector<std::string> &spectrum_labels) const;
870
872
876 void setScatteringDepth(const std::string &label, uint depth);
877
879
883 void setMinScatterEnergy(const std::string &label, uint energy);
884
886
890 void enforcePeriodicBoundary(const std::string &boundary);
891
893
901 void addRadiationCamera(const std::string &camera_label, const std::vector<std::string> &band_label, const helios::vec3 &position, const helios::vec3 &lookat, const CameraProperties &camera_properties, uint antialiasing_samples);
902
904
912 void addRadiationCamera(const std::string &camera_label, const std::vector<std::string> &band_label, const helios::vec3 &position, const helios::SphericalCoord &viewing_direction, const CameraProperties &camera_properties,
913 uint antialiasing_samples);
914
915
917
923 void setCameraSpectralResponse(const std::string &camera_label, const std::string &band_label, const std::string &global_data);
924
926
934 void setCameraSpectralResponseFromLibrary(const std::string &camera_label, const std::string &camera_library_name);
935
937
941 void setCameraPosition(const std::string &camera_label, const helios::vec3 &position);
942
944
948 helios::vec3 getCameraPosition(const std::string &camera_label) const;
949
951
955 void setCameraLookat(const std::string &camera_label, const helios::vec3 &lookat);
956
958
962 helios::vec3 getCameraLookat(const std::string &camera_label) const;
963
965
969 void setCameraOrientation(const std::string &camera_label, const helios::vec3 &direction);
970
972
976 void setCameraOrientation(const std::string &camera_label, const helios::SphericalCoord &direction);
977
979
983 helios::SphericalCoord getCameraOrientation(const std::string &camera_label) const;
984
986
989 std::vector<std::string> getAllCameraLabels();
990
992
996 void updateGeometry();
997
999
1004 void updateGeometry(const std::vector<uint> &UUIDs);
1005
1007
1012 void runBand(const std::string &label);
1013
1015
1020 void runBand(const std::vector<std::string> &labels);
1021
1023 std::vector<float> getTotalAbsorbedFlux();
1024
1026 float getSkyEnergy();
1027
1029
1034 float calculateGtheta(helios::Context *context, helios::vec3 view_direction);
1035
1036 void setCameraCalibration(CameraCalibration *CameraCalibration);
1037
1039
1047 void updateCameraResponse(const std::string &orginalcameralabel, const std::vector<std::string> &sourcelabels_raw, const std::vector<std::string> &cameraresponselabels, helios::vec2 &wavelengthrange,
1048 const std::vector<std::vector<float>> &truevalues, const std::string &calibratedmark);
1049
1051
1060 float getCameraResponseScale(const std::string &orginalcameralabel, const std::vector<std::string> &cameraresponselabels, const std::vector<std::string> &bandlabels, const std::vector<std::string> &sourcelabels, helios::vec2 &wavelengthrange,
1061 const std::vector<std::vector<float>> &truevalues);
1062
1064
1074 void runRadiationImaging(const std::string &cameralabel, const std::vector<std::string> &sourcelabels, const std::vector<std::string> &bandlabels, const std::vector<std::string> &cameraresponselabels, helios::vec2 wavelengthrange,
1075 float fluxscale = 1, float diffusefactor = 0.0005, uint scatteringdepth = 4);
1076
1078
1088 void runRadiationImaging(const std::vector<std::string> &cameralabels, const std::vector<std::string> &sourcelabels, const std::vector<std::string> &bandlabels, const std::vector<std::string> &cameraresponselabels, helios::vec2 wavelengthrange,
1089 float fluxscale = 1, float diffusefactor = 0.0005, uint scatteringdepth = 4);
1090
1092
1104 void applyImageProcessingPipeline(const std::string &cameralabel, const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float saturation_adjustment = 1.f, float brightness_adjustment = 1.f,
1105 float contrast_adjustment = 1.f, float gain_adjustment = 1.f);
1106
1108
1115 void applyCameraColorCorrectionMatrix(const std::string &camera_label, const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, const std::string &ccm_file_path);
1116
1118
1124 void whiteBalanceAuto(const std::string &cameralabel, const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
1125
1127
1134 void whiteBalanceWhitePatch(const std::string &cameralabel, const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float percentile = 0.99f);
1135
1137
1144 void whiteBalanceGrayWorld(const std::string &cameralabel, const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float p = 6.0f);
1145
1146
1148
1158 std::string writeCameraImage(const std::string &camera, const std::vector<std::string> &bands, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1, float flux_to_pixel_conversion = 1.f);
1159
1161
1169 std::string writeNormCameraImage(const std::string &camera, const std::vector<std::string> &bands, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1);
1170
1172
1179 void writeCameraImageData(const std::string &camera, const std::string &band, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1);
1180
1182
1190 void writePrimitiveDataLabelMap(const std::string &cameralabel, const std::string &primitive_data_label, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1, float padvalue = NAN);
1191
1193
1201 void writeObjectDataLabelMap(const std::string &cameralabel, const std::string &object_data_label, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1, float padvalue = NAN);
1202
1204
1210 void writeDepthImageData(const std::string &cameralabel, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1);
1211
1213
1220 void writeNormDepthImage(const std::string &cameralabel, const std::string &imagefile_base, float max_depth, const std::string &image_path = "./", int frame = -1);
1221
1223
1232 DEPRECATED(void writeImageBoundingBoxes(const std::string &cameralabel, const std::string &primitive_data_label, uint object_class_ID, const std::string &imagefile_base, const std::string &image_path = "./", bool append_label_file = false,
1233 int frame = -1));
1234
1236
1245 DEPRECATED(void writeImageBoundingBoxes_ObjectData(const std::string &cameralabel, const std::string &object_data_label, uint object_class_ID, const std::string &imagefile_base, const std::string &image_path = "./",
1246 bool append_label_file = false, int frame = -1));
1247
1249
1258 void writeImageBoundingBoxes(const std::string &cameralabel, const std::string &primitive_data_label, const uint &object_class_ID, const std::string &image_file, const std::string &classes_txt_file = "classes.txt",
1259 const std::string &image_path = "./");
1260
1262
1271 void writeImageBoundingBoxes(const std::string &cameralabel, const std::vector<std::string> &primitive_data_label, const std::vector<uint> &object_class_ID, const std::string &image_file, const std::string &classes_txt_file = "classes.txt",
1272 const std::string &image_path = "./");
1273
1275
1284 void writeImageBoundingBoxes_ObjectData(const std::string &cameralabel, const std::string &object_data_label, const uint &object_class_ID, const std::string &image_file, const std::string &classes_txt_file = "classes.txt",
1285 const std::string &image_path = "./");
1286
1288
1297 void writeImageBoundingBoxes_ObjectData(const std::string &cameralabel, const std::vector<std::string> &object_data_label, const std::vector<uint> &object_class_ID, const std::string &image_file,
1298 const std::string &classes_txt_file = "classes.txt", const std::string &image_path = "./");
1299
1301
1310 void writeImageSegmentationMasks(const std::string &cameralabel, const std::string &primitive_data_label, const uint &object_class_ID, const std::string &json_filename, const std::string &image_file, bool append_file = false);
1311
1313
1322 void writeImageSegmentationMasks(const std::string &cameralabel, const std::vector<std::string> &primitive_data_label, const std::vector<uint> &object_class_ID, const std::string &json_filename, const std::string &image_file,
1323 bool append_file = false);
1324
1326
1335 void writeImageSegmentationMasks_ObjectData(const std::string &cameralabel, const std::string &object_data_label, const uint &object_class_ID, const std::string &json_filename, const std::string &image_file, bool append_file = false);
1336
1338
1347 void writeImageSegmentationMasks_ObjectData(const std::string &cameralabel, const std::vector<std::string> &object_data_label, const std::vector<uint> &object_class_ID, const std::string &json_filename, const std::string &image_file,
1348 bool append_file = false);
1349
1350private:
1351 // Helper functions for COCO JSON handling
1352 std::pair<nlohmann::json, int> initializeCOCOJsonWithImageId(const std::string &filename, bool append_file, const std::string &cameralabel, const helios::int2 &camera_resolution, const std::string &image_file);
1353 nlohmann::json initializeCOCOJson(const std::string &filename, bool append_file, const std::string &cameralabel, const helios::int2 &camera_resolution, const std::string &image_file);
1354 void addCategoryToCOCO(nlohmann::json &coco_json, const std::vector<uint> &object_class_ID, const std::vector<std::string> &category_name);
1355 void writeCOCOJson(const nlohmann::json &coco_json, const std::string &filename);
1356
1357 // Helper functions for mask generation and boundary tracing
1358 std::map<int, std::vector<std::vector<bool>>> generateLabelMasks(const std::string &cameralabel, const std::string &data_label, bool use_object_data);
1359 std::pair<int, int> findStartingBoundaryPixel(const std::vector<std::vector<bool>> &mask, const helios::int2 &camera_resolution);
1360 std::vector<std::pair<int, int>> traceBoundaryMoore(const std::vector<std::vector<bool>> &mask, int start_x, int start_y, const helios::int2 &camera_resolution);
1361 std::vector<std::pair<int, int>> traceBoundarySimple(const std::vector<std::vector<bool>> &mask, int start_x, int start_y, const helios::int2 &camera_resolution);
1362 std::vector<std::map<std::string, std::vector<float>>> generateAnnotationsFromMasks(const std::map<int, std::vector<std::vector<bool>>> &label_masks, uint object_class_ID, const helios::int2 &camera_resolution, int image_id);
1363
1364public:
1366
1371 void setPadValue(const std::string &cameralabel, const std::vector<std::string> &bandlabels, const std::vector<float> &padvalues);
1372
1374
1383 void calibrateCamera(const std::string &orginalcameralabel, const std::vector<std::string> &sourcelabels, const std::vector<std::string> &cameraresponselabels, const std::vector<std::string> &bandlabels, const float scalefactor,
1384 const std::vector<std::vector<float>> &truevalues, const std::string &calibratedmark);
1385
1387
1393 void calibrateCamera(const std::string &originalcameralabel, const float scalefactor, const std::vector<std::vector<float>> &truevalues, const std::string &calibratedmark);
1394
1401
1403
1414 std::string autoCalibrateCameraImage(const std::string &camera_label, const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, const std::string &output_file_path,
1415 bool print_quality_report = false, ColorCorrectionAlgorithm algorithm = ColorCorrectionAlgorithm::MATRIX_3X3_AUTO, const std::string &ccm_export_file_path = "");
1416
1418 void exportColorCorrectionMatrixXML(const std::string &file_path, const std::string &camera_label, const std::vector<std::vector<float>> &matrix, const std::string &source_image_path, const std::string &colorboard_type, float average_delta_e);
1419
1421 std::vector<std::vector<float>> loadColorCorrectionMatrixXML(const std::string &file_path, std::string &camera_label_out);
1422
1424 std::vector<float> getCameraPixelData(const std::string &camera_label, const std::string &band_label);
1425
1427 void setCameraPixelData(const std::string &camera_label, const std::string &band_label, const std::vector<float> &pixel_data);
1428
1429protected:
1431 bool message_flag;
1432
1434 helios::Context *context;
1435
1436 CameraCalibration *cameracalibration;
1437 bool calibration_flag = false;
1438
1440 std::string getCurrentDateTime();
1441
1443 std::vector<uint> primitiveID;
1444
1446 std::vector<uint> context_UUIDs;
1447
1448 // --- Radiation Band Variables --- //
1449
1450 std::map<std::string, RadiationBand> radiation_bands;
1451
1452 std::map<std::string, bool> scattering_iterations_needed;
1453
1454 // --- radiation source variables --- //
1455
1456 std::vector<RadiationSource> radiation_sources;
1457
1459 RTvariable Nsources_RTvariable;
1460
1462 RTbuffer source_positions_RTbuffer;
1464 RTvariable source_positions_RTvariable;
1465
1467 RTbuffer source_types_RTbuffer;
1469 RTvariable source_types_RTvariable;
1470
1472 RTbuffer source_fluxes_RTbuffer;
1474 RTvariable source_fluxes_RTvariable;
1475
1477 RTbuffer source_widths_RTbuffer;
1479 RTvariable source_widths_RTvariable;
1480
1481
1483 RTbuffer source_rotations_RTbuffer;
1485 RTvariable source_rotations_RTvariable;
1486
1487 // --- Camera Variables --- //
1488
1490 std::map<std::string, RadiationCamera> cameras;
1491
1493 RTvariable camera_position_RTvariable;
1494
1496 RTvariable camera_direction_RTvariable;
1497
1499 RTvariable camera_lens_diameter_RTvariable;
1500
1502 RTvariable FOV_aspect_RTvariable;
1503
1505 RTvariable camera_focal_length_RTvariable;
1506
1508 RTvariable camera_viewplane_length_RTvariable;
1509
1511 RTvariable Ncameras_RTvariable;
1512
1514 RTvariable camera_ID_RTvariable;
1515
1517 std::map<std::string, std::vector<uint>> spectral_reflectivity_data;
1518
1520 std::map<std::string, std::vector<uint>> spectral_transmissivity_data;
1521
1522 std::vector<helios::vec2> generateGaussianCameraResponse(float FWHM, float mu, float centrawavelength, const helios::int2 &wavebanrange);
1523
1524 // --- Constants and Defaults --- //
1525
1527 float sigma = 5.6703744E-8;
1528
1530 float rho_default;
1531
1533 float tau_default;
1534
1536 float eps_default;
1537
1539 float kappa_default;
1540
1542 float sigmas_default;
1543
1545 float temperature_default;
1546
1548 size_t directRayCount_default;
1549
1551 size_t diffuseRayCount_default;
1552
1554 float diffuseFlux_default;
1555
1557 float minScatterEnergy_default;
1558
1560 uint scatteringDepth_default;
1561
1562 // --- Functions --- //
1563
1565 void initializeOptiX();
1566
1568
1571 void updateRadiativeProperties();
1572
1574
1578 std::vector<helios::vec2> loadSpectralData(const std::string &global_data_label) const;
1579
1581
1583
1586 std::vector<float> getOptiXbufferData(RTbuffer buffer);
1587
1589
1592 std::vector<double> getOptiXbufferData_d(RTbuffer buffer);
1593
1595
1598 std::vector<uint> getOptiXbufferData_ui(RTbuffer buffer);
1599
1600 void addBuffer(const char *name, RTbuffer &buffer, RTvariable &variable, RTbuffertype type, RTformat format, size_t dimension);
1601
1603
1607 void zeroBuffer1D(RTbuffer &buffer, size_t bsize);
1608
1610
1614 void copyBuffer1D(RTbuffer &buffer, RTbuffer &buffer_copy);
1615
1617
1621 void initializeBuffer1Dd(RTbuffer &buffer, const std::vector<double> &array);
1623
1627 void initializeBuffer1Df(RTbuffer &buffer, const std::vector<float> &array);
1629
1633 void initializeBuffer1Dfloat2(RTbuffer &buffer, const std::vector<optix::float2> &array);
1635
1639 void initializeBuffer1Dfloat3(RTbuffer &buffer, const std::vector<optix::float3> &array);
1641
1645 void initializeBuffer1Dfloat4(RTbuffer &buffer, const std::vector<optix::float4> &array);
1647
1651 void initializeBuffer1Di(RTbuffer &buffer, const std::vector<int> &array);
1653
1657 void initializeBuffer1Dui(RTbuffer &buffer, const std::vector<uint> &array);
1659
1663 void initializeBuffer1Dint2(RTbuffer &buffer, const std::vector<optix::int2> &array);
1665
1669 void initializeBuffer1Dint3(RTbuffer &buffer, const std::vector<optix::int3> &array);
1671
1675 void initializeBuffer1Dchar(RTbuffer &buffer, const std::vector<char> &array);
1677
1681 void zeroBuffer2D(RTbuffer &buffer, optix::int2 bsize);
1683
1687 void initializeBuffer2Dd(RTbuffer &buffer, const std::vector<std::vector<double>> &array);
1689
1693 void initializeBuffer2Df(RTbuffer &buffer, const std::vector<std::vector<float>> &array);
1695
1699 void initializeBuffer2Dfloat2(RTbuffer &buffer, const std::vector<std::vector<optix::float2>> &array);
1701
1705 void initializeBuffer2Dfloat3(RTbuffer &buffer, const std::vector<std::vector<optix::float3>> &array);
1707
1711 void initializeBuffer2Dfloat4(RTbuffer &buffer, const std::vector<std::vector<optix::float4>> &array);
1713
1717 void initializeBuffer2Di(RTbuffer &buffer, const std::vector<std::vector<int>> &array);
1719
1723 void initializeBuffer2Dui(RTbuffer &buffer, const std::vector<std::vector<uint>> &array);
1725
1729 void initializeBuffer2Dint2(RTbuffer &buffer, const std::vector<std::vector<optix::int2>> &array);
1731
1735 void initializeBuffer2Dint3(RTbuffer &buffer, const std::vector<std::vector<optix::int3>> &array);
1737
1741 void initializeBuffer2Dbool(RTbuffer &buffer, const std::vector<std::vector<bool>> &array);
1742
1744
1748 template<typename anytype>
1749 void initializeBuffer3D(RTbuffer &buffer, const std::vector<std::vector<std::vector<anytype>>> &array);
1750
1751 void buildLightModelGeometry(uint sourceID);
1752
1753 void buildCameraModelGeometry(const std::string &cameralabel);
1754
1755 void updateLightModelPosition(uint sourceID, const helios::vec3 &delta_position);
1756
1757 void updateCameraModelPosition(const std::string &cameralabel);
1758
1760 std::map<uint, std::vector<uint>> source_model_UUIDs;
1762 std::map<std::string, std::vector<uint>> camera_model_UUIDs;
1763
1764 /* Primary RT API objects */
1765
1767 RTcontext OptiX_Context;
1769 RTprogram direct_raygen;
1771 RTprogram diffuse_raygen;
1772
1774 RTprogram camera_raygen;
1776 RTprogram pixel_label_raygen;
1777
1778 /* Variables */
1779
1780 RTgeometrygroup base_geometry_group;
1781
1783 RTvariable random_seed_RTvariable;
1784
1786 RTvariable launch_offset_RTvariable;
1787
1789 RTvariable launch_face_RTvariable;
1790
1792 RTvariable max_scatters_RTvariable;
1793 RTbuffer max_scatters_RTbuffer;
1794
1796 RTvariable Nbands_global_RTvariable;
1797
1799 RTvariable Nbands_launch_RTvariable;
1800
1802 RTvariable band_launch_flag_RTvariable;
1803 RTbuffer band_launch_flag_RTbuffer;
1804
1806 RTvariable Nprimitives_RTvariable;
1807
1809 RTvariable diffuse_flux_RTvariable;
1810 RTbuffer diffuse_flux_RTbuffer;
1811
1813 RTvariable diffuse_extinction_RTvariable;
1814 RTbuffer diffuse_extinction_RTbuffer;
1815
1817 RTvariable diffuse_peak_dir_RTvariable;
1818 RTbuffer diffuse_peak_dir_RTbuffer;
1819
1821 RTvariable diffuse_dist_norm_RTvariable;
1822 RTbuffer diffuse_dist_norm_RTbuffer;
1823
1825 RTvariable emission_flag_RTvariable;
1826 RTbuffer emission_flag_RTbuffer;
1827
1829 helios::vec2 periodic_flag;
1830 RTvariable periodic_flag_RTvariable;
1831
1833 RTvariable Rsky_RTvariable;
1834
1836 RTbuffer rho_RTbuffer;
1838 RTvariable rho_RTvariable;
1840 RTbuffer tau_RTbuffer;
1842 RTvariable tau_RTvariable;
1843
1845 RTbuffer rho_cam_RTbuffer;
1847 RTvariable rho_cam_RTvariable;
1849 RTbuffer tau_cam_RTbuffer;
1851 RTvariable tau_cam_RTvariable;
1852
1854 RTbuffer specular_exponent_RTbuffer;
1856 RTvariable specular_exponent_RTvariable;
1857
1859 RTbuffer specular_scale_RTbuffer;
1861 RTvariable specular_scale_RTvariable;
1862
1864
1869 RTvariable specular_reflection_enabled_RTvariable;
1870
1872 RTbuffer primitive_type_RTbuffer;
1874 RTvariable primitive_type_RTvariable;
1875
1877 RTbuffer primitive_solid_fraction_RTbuffer;
1879 RTvariable primitive_solid_fraction_RTvariable;
1880
1882 RTbuffer patch_UUID_RTbuffer;
1883 RTbuffer triangle_UUID_RTbuffer;
1884 RTbuffer disk_UUID_RTbuffer;
1885 RTbuffer tile_UUID_RTbuffer;
1886 RTbuffer voxel_UUID_RTbuffer;
1887 RTbuffer bbox_UUID_RTbuffer;
1889 RTvariable patch_UUID_RTvariable;
1890 RTvariable triangle_UUID_RTvariable;
1891 RTvariable disk_UUID_RTvariable;
1892 RTvariable tile_UUID_RTvariable;
1893 RTvariable voxel_UUID_RTvariable;
1894 RTvariable bbox_UUID_RTvariable;
1895
1897 RTbuffer objectID_RTbuffer;
1899 RTvariable objectID_RTvariable;
1900
1902 RTbuffer primitiveID_RTbuffer;
1904 RTvariable primitiveID_RTvariable;
1905
1907 RTbuffer twosided_flag_RTbuffer;
1909 RTvariable twosided_flag_RTvariable;
1910
1912 RTbuffer Rsky_RTbuffer;
1913
1914 //-- Patch Buffers --//
1915 RTbuffer patch_vertices_RTbuffer;
1916 RTvariable patch_vertices_RTvariable;
1917
1918 //-- Triangle Buffers --//
1919 RTbuffer triangle_vertices_RTbuffer;
1920 RTvariable triangle_vertices_RTvariable;
1921
1922 //-- Disk Buffers --//
1923 RTbuffer disk_centers_RTbuffer;
1924 RTvariable disk_centers_RTvariable;
1925 RTbuffer disk_radii_RTbuffer;
1926 RTvariable disk_radii_RTvariable;
1927 RTbuffer disk_normals_RTbuffer;
1928 RTvariable disk_normals_RTvariable;
1929
1930 //-- Tile Buffers --//
1931 RTbuffer tile_vertices_RTbuffer;
1932 RTvariable tile_vertices_RTvariable;
1933
1934 //-- Voxel Buffers --//
1935 RTbuffer voxel_vertices_RTbuffer;
1936 RTvariable voxel_vertices_RTvariable;
1937
1938 //-- Bounding Box Buffers --//
1939 RTbuffer bbox_vertices_RTbuffer;
1940 RTvariable bbox_vertices_RTvariable;
1941
1942 //-- Object Buffers --//
1943 RTbuffer object_subdivisions_RTbuffer;
1944 RTvariable object_subdivisions_RTvariable;
1945
1946 /* Output Buffers */
1947
1949 RTbuffer transform_matrix_RTbuffer;
1951 RTvariable transform_matrix_RTvariable;
1953 RTbuffer primitive_emission_RTbuffer;
1955 RTvariable primitive_emission_RTvariable;
1956
1958 RTbuffer radiation_in_RTbuffer;
1960 RTvariable radiation_in_RTvariable;
1962 RTbuffer radiation_out_top_RTbuffer;
1964 RTvariable radiation_out_top_RTvariable;
1966 RTbuffer radiation_out_bottom_RTbuffer;
1968 RTvariable radiation_out_bottom_RTvariable;
1970 RTbuffer scatter_buff_top_RTbuffer;
1972 RTvariable scatter_buff_top_RTvariable;
1974 RTbuffer scatter_buff_bottom_RTbuffer;
1976 RTvariable scatter_buff_bottom_RTvariable;
1977
1979 RTbuffer radiation_in_camera_RTbuffer;
1981 RTvariable radiation_in_camera_RTvariable;
1982
1984 RTbuffer scatter_buff_top_cam_RTbuffer;
1986 RTvariable scatter_buff_top_cam_RTvariable;
1988 RTbuffer scatter_buff_bottom_cam_RTbuffer;
1990 RTvariable scatter_buff_bottom_cam_RTvariable;
1991
1993 RTbuffer camera_pixel_label_RTbuffer;
1995 RTvariable camera_pixel_label_RTvariable;
1996
1998 RTbuffer camera_pixel_depth_RTbuffer;
2000 RTvariable camera_pixel_depth_RTvariable;
2001
2003 RTbuffer maskdata_RTbuffer;
2005 RTvariable maskdata_RTvariable;
2007 RTbuffer masksize_RTbuffer;
2009 RTvariable masksize_RTvariable;
2011 RTbuffer maskID_RTbuffer;
2013 RTvariable maskID_RTvariable;
2015 RTbuffer uvdata_RTbuffer;
2017 RTvariable uvdata_RTvariable;
2019 RTbuffer uvID_RTbuffer;
2021 RTvariable uvID_RTvariable;
2022
2023
2024 /* Ray Types */
2025
2027 RTvariable direct_ray_type_RTvariable;
2029 RTvariable diffuse_ray_type_RTvariable;
2030
2031 // Handle to OptiX ray type for camera rays
2032 RTvariable camera_ray_type_RTvariable;
2033 // Handle to OptiX ray type for camera pixel labeling rays
2034 RTvariable pixel_label_ray_type_RTvariable;
2035
2037 enum RayType { RAYTYPE_DIRECT = 0, RAYTYPE_DIFFUSE = 1, RAYTYPE_CAMERA = 2, RAYTYPE_PIXEL_LABEL = 3 };
2038
2039 /* OptiX Geometry Structures */
2040 RTgeometry patch;
2041 RTgeometry triangle;
2042 RTgeometry disk;
2043 RTgeometry tile;
2044 RTgeometry voxel;
2045 RTgeometry bbox;
2046 RTmaterial patch_material;
2047 RTmaterial triangle_material;
2048 RTmaterial disk_material;
2049 RTmaterial tile_material;
2050 RTmaterial voxel_material;
2051 RTmaterial bbox_material;
2052
2053 RTgroup top_level_group;
2054 RTacceleration top_level_acceleration;
2055 RTvariable top_object;
2056 RTacceleration geometry_acceleration;
2057
2058
2060 bool isgeometryinitialized;
2061
2062 bool radiativepropertiesneedupdate = true;
2063
2064 std::vector<bool> isbandpropertyinitialized;
2065
2066 bool islightvisualizationenabled = false;
2067 bool iscameravisualizationenabled = false;
2068
2070 std::vector<std::string> output_prim_data;
2071
2072 std::vector<std::string> spectral_library_files;
2073};
2074
2075void sutilHandleError(RTcontext context, RTresult code, const char *file, int line);
2076
2077void sutilReportError(const char *message);
2078
2079/* assumes current scope has Context variable named 'OptiX_Context' */
2080#define RT_CHECK_ERROR(func) \
2081 do { \
2082 RTresult code = func; \
2083 if (code != RT_SUCCESS) \
2084 sutilHandleError(OptiX_Context, code, __FILE__, __LINE__); \
2085 } while (0)
2086
2087#endif