1.3.64
 
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 "RayTracingBackend.h"
22#include "json.hpp"
23
24#include <utility>
25
28
29 bool operator!=(const CameraProperties &rhs) const {
30 return !(rhs == *this);
31 }
32
35
38
41
44
46 float HFOV;
47
50
53
55 std::string model;
56
58 std::string lens_make;
59
61 std::string lens_model;
62
64 std::string lens_specification;
65
68 std::string exposure;
69
72
74 std::string white_balance;
75
89
93 lens_focal_length = 0.05; // 50mm default
94 lens_diameter = 0.05;
95 FOV_aspect_ratio = 0.f; // Sentinel value: 0 means auto-calculate from camera_resolution
96 HFOV = 20.f;
97 sensor_width_mm = 35.f;
98 model = "generic";
99 exposure = "auto";
100 shutter_speed = 1.f / 125.f; // 1/125 second (standard default)
101 white_balance = "auto";
102 camera_zoom = 1.0f;
103 }
104
105 bool operator==(const CameraProperties &rhs) const {
109 }
110};
111
114
117
119 float coating_efficiency = 0.96f;
120
122 float ghost_intensity = 1.0f;
123
126
129
131 int ghost_count = 5;
132
133 bool operator==(const LensFlareProperties &rhs) const {
136 }
137
138 bool operator!=(const LensFlareProperties &rhs) const {
139 return !(rhs == *this);
140 }
141};
142
145
146 // Constructor
147 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) :
148 label(std::move(initlabel)), band_labels(band_label), position(initposition), lookat(initlookat), antialiasing_samples(initantialiasing_samples) {
149 for (const auto &band: band_label) {
150 band_spectral_response[band] = "uniform";
151 }
152 focal_length = camera_properties.focal_plane_distance; // working distance for ray generation
153 lens_focal_length = camera_properties.lens_focal_length; // optical focal length for aperture
154 resolution = camera_properties.camera_resolution;
155 lens_diameter = camera_properties.lens_diameter;
156 HFOV_degrees = camera_properties.HFOV;
157 FOV_aspect_ratio = camera_properties.FOV_aspect_ratio;
158 sensor_width_mm = camera_properties.sensor_width_mm;
159 model = camera_properties.model;
160 lens_make = camera_properties.lens_make;
161 lens_model = camera_properties.lens_model;
162 lens_specification = camera_properties.lens_specification;
163 exposure = camera_properties.exposure;
164 shutter_speed = camera_properties.shutter_speed;
165 white_balance = camera_properties.white_balance;
166 camera_zoom = camera_properties.camera_zoom;
167 }
168
169 // Label for camera array
170 std::string label;
171 // Cartesian (x,y,z) position of camera array center
172 helios::vec3 position;
173 // Direction camera is pointed (normal vector of camera surface). This vector will automatically be normalized
174 helios::vec3 lookat;
175 // Physical dimensions of the camera lens
176 float lens_diameter;
177 // Resolution of camera sub-divisions (i.e., pixels)
178 helios::int2 resolution;
179 // camera focal length (working distance for ray generation)
180 float focal_length;
181 // lens optical focal length (for f-number and aperture calculations). This is the physical focal length, not the 35mm equivalent.
182 float lens_focal_length;
183 // camera horizontal field of view (degrees)
184 float HFOV_degrees;
185 // Ratio of camera horizontal field of view to vertical field of view
186 float FOV_aspect_ratio;
187 // Physical sensor width in mm
188 float sensor_width_mm;
189 // Camera model name
190 std::string model;
191 // Lens make/manufacturer
192 std::string lens_make;
193 // Lens model name
194 std::string lens_model;
195 // Lens specification
196 std::string lens_specification;
197 // Exposure mode: "auto", "ISOXXX" (e.g., "ISO100"), or "manual"
198 std::string exposure;
199 // Camera shutter speed in seconds
200 float shutter_speed;
201 // White balance mode: "auto" or "off"
202 std::string white_balance;
203 // Camera optical zoom multiplier
204 float camera_zoom;
205 // Camera type (rgb, spectral, or thermal)
206 std::string camera_type;
207 // Number of antialiasing samples per pixel
208 uint antialiasing_samples;
209
210 std::vector<std::string> band_labels;
211
212 std::map<std::string, std::string> band_spectral_response;
213
214 std::map<std::string, std::vector<float>> pixel_data;
215
216 std::vector<uint> pixel_label_UUID;
217 std::vector<float> pixel_depth;
218
220 bool lens_flare_enabled = false;
221
224
226 void normalizePixels();
227
229
236
242 void whiteBalance(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float p = 5.0);
243
245
254 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);
255
257
264 void whiteBalanceWhitePatch(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float percentile = 0.99f);
265
266
268
278 void whiteBalanceSpectral(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, helios::Context *context);
279
281
288 void reinhardToneMapping(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
289
291
299 void applyGain(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float percentile = 0.95f);
300
302
307 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);
308
310
315 // void applyCCM(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
316
318
325 void gammaCompress(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
326
334 void globalHistogramEqualization(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label);
335
337
343 void autoExposure(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float gain_multiplier);
344
346
358
360
372
374
381 void adjustBrightnessContrast(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float brightness, float contrast);
382
384
390 void adjustSaturation(const std::string &red_band_label, const std::string &green_band_label, const std::string &blue_band_label, float saturation);
391
393
397 static float lin_to_srgb(float x) noexcept {
398 // Clamp negative values to 0, bright values > 1.0 to white (1.0)
399 if (x <= 0.0f)
400 return 0.0f;
401 if (x >= 1.0f)
402 return 1.0f; // Bright pixels clipped to white
403 return (x <= 0.0031308f) ? 12.92f * x : 1.055f * std::pow(x, 1.0f / 2.4f) - 0.055f;
404 }
405
407
411 static float srgb_to_lin(float v) noexcept {
412 return (v <= 0.04045f) ? v / 12.92f : std::pow((v + 0.055f) / 1.055f, 2.4f);
413 }
414
415private:
417
423 static float luminance(float red, float green, float blue) noexcept {
424 return 0.2126f * red + 0.7152f * green + 0.0722f * blue;
425 }
426};
427
433
436
438 std::string path;
439
442 int height;
443 int width;
445 std::string type;
447 std::string aperture;
450 std::string model;
451 std::string lens_make;
452 std::string lens_model;
453 std::string lens_specification;
454 std::string exposure;
456 std::string white_balance;
458 } camera_properties;
459
462 float latitude;
463 float longitude;
464 } location_properties;
465
468 std::string date;
469 std::string time;
473 std::string light_source;
474 } acquisition_properties;
475
481 std::string color_space = "linear";
482 } image_processing;
483
486 std::vector<std::string> plant_species;
487 std::vector<int> plant_count;
488 std::vector<float> plant_height_m;
489 std::vector<float> plant_age_days;
490 std::vector<std::string> plant_stage;
491 std::vector<float> leaf_area_m2;
492 std::string weed_pressure;
493 } agronomic_properties;
494};
495
498
500 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)) {
501 directRayCount = directRayCount_default;
502 diffuseRayCount = diffuseRayCount_default;
503 diffuseFlux = diffuseFlux_default;
504 scatteringDepth = scatteringDepth_default;
505 minScatterEnergy = minScatterEnergy_default;
506 diffuseExtinction = 0.f;
507 diffuseDistNorm = 1.f;
508 emissionFlag = true;
510 }
511
513 std::string label;
514
517
520
523
526
529
532
536 helios::vec4 diffusePragueParams = helios::make_vec4(0, 0, 0, 0);
537
539 std::vector<helios::vec2> diffuse_spectrum;
540
543
546
549
552};
553
555enum 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 };
556
559public:
561 explicit RadiationSource(const helios::vec3 &position) : source_position(position) {
562 source_type = RADIATION_SOURCE_TYPE_COLLIMATED;
563
564 // initialize other unused variables
567 };
568
570 RadiationSource(const helios::vec3 &position, float width) : source_position(position) {
571 source_type = RADIATION_SOURCE_TYPE_SPHERE;
572
573 source_width = helios::make_vec2(width, width);
574
575 // initialize other unused variables
578 };
579
581 RadiationSource(const helios::vec3 &position, float position_scaling_factor, float width, float flux_scaling_factor) :
582 source_position(position), source_position_scaling_factor(position_scaling_factor), source_flux_scaling_factor(flux_scaling_factor) {
583 source_type = RADIATION_SOURCE_TYPE_SUN_SPHERE;
584 source_width = helios::make_vec2(width, width);
585 };
586
587
589 RadiationSource(const helios::vec3 &position, const helios::vec2 &size, const helios::vec3 &rotation) : source_position(position), source_width(size), source_rotation(rotation) {
590 source_type = RADIATION_SOURCE_TYPE_RECTANGLE;
591
592 // initialize other unused variables
595 };
596
598 RadiationSource(const helios::vec3 &position, float width, const helios::vec3 &rotation) : source_position(position), source_rotation(rotation) {
599 source_type = RADIATION_SOURCE_TYPE_DISK;
600
601 source_width = helios::make_vec2(width, width);
602
603 // initialize other unused variables
606 };
607
610
613
615 std::vector<helios::vec2> source_spectrum;
616
617 std::string source_spectrum_label = "none";
618
621
624
627
630
633
635 std::map<std::string, float> source_fluxes;
636};
637
640public:
642 explicit RadiationModel(helios::Context *context);
643
646
648
651 static int selfTest(int argc = 0, char **argv = nullptr);
652
654
657 void disableMessages();
658
660 void enableMessages();
661
663
666 void optionalOutputPrimitiveData(const char *label);
667
669
674 void setDirectRayCount(const std::string &label, size_t N);
675
677
682 void setDiffuseRayCount(const std::string &label, size_t N);
683
685
690 void setDiffuseRadiationFlux(const std::string &label, float flux);
691
693
700 void setDiffuseRadiationExtinctionCoeff(const std::string &label, float K, const helios::vec3 &peak_dir);
701
703
710 void setDiffuseRadiationExtinctionCoeff(const std::string &label, float K, const helios::SphericalCoord &peak_dir);
711
713
719 void setDiffuseSpectrumIntegral(float spectrum_integral);
720
722
730 void setDiffuseSpectrumIntegral(float spectrum_integral, float wavelength_min, float wavelength_max);
731
733
738 void setDiffuseSpectrumIntegral(const std::string &band_label, float spectrum_integral);
739
741
748 void setDiffuseSpectrumIntegral(const std::string &band_label, float spectrum_integral, float wavelength_min, float wavelength_max);
749
751
754 void addRadiationBand(const std::string &label);
755
757
762 void addRadiationBand(const std::string &label, float wavelength_min, float wavelength_max);
763
765
769 void copyRadiationBand(const std::string &old_label, const std::string &new_label);
770
772
778 void copyRadiationBand(const std::string &old_label, const std::string &new_label, float wavelength_min, float wavelength_max);
779
781
784 bool doesBandExist(const std::string &label) const;
785
787
790 void disableEmission(const std::string &label);
791
793
796 void enableEmission(const std::string &label);
797
799
803
805
810
812
817
819
824 uint addSphereRadiationSource(const helios::vec3 &position, float radius);
825
827
831
833
838
840
844 uint addSunSphereRadiationSource(const helios::vec3 &sun_direction);
845
847
853 uint addRectangleRadiationSource(const helios::vec3 &position, const helios::vec2 &size, const helios::vec3 &rotation_rad);
854
856
862 uint addDiskRadiationSource(const helios::vec3 &position, float radius, const helios::vec3 &rotation_rad);
863
865
868 void deleteRadiationSource(uint sourceID);
869
871
876 void setSourceSpectrumIntegral(uint source_ID, float source_integral);
877
879
886 void setSourceSpectrumIntegral(uint source_ID, float source_integral, float wavelength_min, float wavelength_max);
887
889
894 void setSourceFlux(uint source_ID, const std::string &band_label, float flux);
895
897
902 void setSourceFlux(const std::vector<uint> &source_ID, const std::string &band_label, float flux);
903
905
910 float getSourceFlux(uint source_ID, const std::string &band_label) const;
911
913
917 void setSourcePosition(uint source_ID, const helios::vec3 &position);
918
920
925 void setSourcePosition(uint source_ID, const helios::SphericalCoord &position);
926
928
932 helios::vec3 getSourcePosition(uint source_ID) const;
933
935
939 void setSourceSpectrum(uint source_ID, const std::vector<helios::vec2> &spectrum);
940
942
946 void setSourceSpectrum(const std::vector<uint> &source_ID, const std::vector<helios::vec2> &spectrum);
947
949
953 void setSourceSpectrum(uint source_ID, const std::string &spectrum_label);
954
956
960 void setSourceSpectrum(const std::vector<uint> &source_ID, const std::string &spectrum_label);
961
963
967 void setDiffuseSpectrum(const std::string &spectrum_label);
968
970
974 float getDiffuseFlux(const std::string &band_label) const;
975
978
981
984
987
989
995 float integrateSpectrum(const std::vector<helios::vec2> &object_spectrum, float wavelength_min, float wavelength_max) const;
996
998
1002 float integrateSpectrum(const std::vector<helios::vec2> &object_spectrum) const;
1003
1005
1012 float integrateSpectrum(uint source_ID, const std::vector<helios::vec2> &object_spectrum, float wavelength_min, float wavelength_max) const;
1013
1015
1021 float integrateSpectrum(uint source_ID, const std::vector<helios::vec2> &object_spectrum, const std::vector<helios::vec2> &camera_spectrum) const;
1022
1024
1029 float integrateSpectrum(const std::vector<helios::vec2> &object_spectrum, const std::vector<helios::vec2> &camera_spectrum) const;
1030
1032
1038 float integrateSourceSpectrum(uint source_ID, float wavelength_min, float wavelength_max) const;
1039
1041
1046 void scaleSpectrum(const std::string &existing_global_data_label, const std::string &new_global_data_label, float scale_factor) const;
1047
1049
1053 void scaleSpectrum(const std::string &global_data_label, float scale_factor) const;
1054
1056
1062 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;
1063
1065
1071 void blendSpectra(const std::string &new_spectrum_label, const std::vector<std::string> &spectrum_labels, const std::vector<float> &weights) const;
1072
1074
1079 void blendSpectraRandomly(const std::string &new_spectrum_label, const std::vector<std::string> &spectrum_labels) const;
1080
1082
1093 void interpolateSpectrumFromPrimitiveData(const std::vector<uint> &primitive_UUIDs, const std::vector<std::string> &spectra, const std::vector<float> &values, const std::string &primitive_data_query_label,
1094 const std::string &primitive_data_radprop_label);
1095
1097
1109 void interpolateSpectrumFromObjectData(const std::vector<uint> &object_IDs, const std::vector<std::string> &spectra, const std::vector<float> &values, const std::string &object_data_query_label, const std::string &primitive_data_radprop_label);
1110
1112
1116 void setScatteringDepth(const std::string &label, uint depth);
1117
1119
1123 void setMinScatterEnergy(const std::string &label, uint energy);
1124
1126
1130 void enforcePeriodicBoundary(const std::string &boundary);
1131
1133
1141 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);
1142
1144
1152 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,
1153 uint antialiasing_samples);
1154
1155
1157
1163 void setCameraSpectralResponse(const std::string &camera_label, const std::string &band_label, const std::string &global_data);
1164
1166
1174 void setCameraSpectralResponseFromLibrary(const std::string &camera_label, const std::string &camera_library_name);
1175
1177
1195 void addRadiationCameraFromLibrary(const std::string &camera_label, const std::string &library_camera_label, const helios::vec3 &position, const helios::vec3 &lookat, uint antialiasing_samples);
1196
1198
1217 void addRadiationCameraFromLibrary(const std::string &camera_label, const std::string &library_camera_label, const helios::vec3 &position, const helios::vec3 &lookat, uint antialiasing_samples, const std::vector<std::string> &band_labels);
1218
1220
1224 void setCameraPosition(const std::string &camera_label, const helios::vec3 &position);
1225
1227
1231 helios::vec3 getCameraPosition(const std::string &camera_label) const;
1232
1234
1238 void setCameraLookat(const std::string &camera_label, const helios::vec3 &lookat);
1239
1241
1245 helios::vec3 getCameraLookat(const std::string &camera_label) const;
1246
1248
1252 void setCameraOrientation(const std::string &camera_label, const helios::vec3 &direction);
1253
1255
1259 void setCameraOrientation(const std::string &camera_label, const helios::SphericalCoord &direction);
1260
1262
1266 helios::SphericalCoord getCameraOrientation(const std::string &camera_label) const;
1267
1269
1280 CameraProperties getCameraParameters(const std::string &camera_label) const;
1281
1283
1296 void updateCameraParameters(const std::string &camera_label, const CameraProperties &camera_properties);
1297
1299
1302 std::vector<std::string> getAllCameraLabels();
1303
1305
1310 void enableCameraMetadata(const std::string &camera_label);
1311
1313
1318 void enableCameraMetadata(const std::vector<std::string> &camera_labels);
1319
1321
1326 CameraMetadata getCameraMetadata(const std::string &camera_label) const;
1327
1329
1334 void setCameraMetadata(const std::string &camera_label, const CameraMetadata &metadata);
1335
1337
1343 void enableCameraLensFlare(const std::string &camera_label);
1344
1346
1349 void disableCameraLensFlare(const std::string &camera_label);
1350
1352
1356 [[nodiscard]] bool isCameraLensFlareEnabled(const std::string &camera_label) const;
1357
1359
1364 void setCameraLensFlareProperties(const std::string &camera_label, const LensFlareProperties &properties);
1365
1367
1371 [[nodiscard]] LensFlareProperties getCameraLensFlareProperties(const std::string &camera_label) const;
1372
1374
1378 void updateGeometry();
1379
1381
1386 void updateGeometry(const std::vector<uint> &UUIDs);
1387
1389
1394 void runBand(const std::string &label);
1395
1397
1402 void runBand(const std::vector<std::string> &labels);
1403
1405 std::vector<float> getTotalAbsorbedFlux();
1406
1408 float getSkyEnergy();
1409
1411
1416 float calculateGtheta(helios::Context *context, helios::vec3 view_direction);
1417
1418 void setCameraCalibration(CameraCalibration *CameraCalibration);
1419
1421
1429 void updateCameraResponse(const std::string &orginalcameralabel, const std::vector<std::string> &sourcelabels_raw, const std::vector<std::string> &cameraresponselabels, helios::vec2 &wavelengthrange,
1430 const std::vector<std::vector<float>> &truevalues, const std::string &calibratedmark);
1431
1433
1442 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,
1443 const std::vector<std::vector<float>> &truevalues);
1444
1446
1456 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,
1457 float fluxscale = 1, float diffusefactor = 0.0005, uint scatteringdepth = 4);
1458
1460
1470 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,
1471 float fluxscale = 1, float diffusefactor = 0.0005, uint scatteringdepth = 4);
1472
1474
1487 void applyCameraImageCorrections(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,
1488 float contrast_adjustment = 1.f);
1489
1491 [[deprecated("Use applyCameraImageCorrections() instead")]]
1492 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,
1493 float contrast_adjustment = 1.f, float gain_adjustment = 1.f);
1494
1496
1503 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);
1504
1505
1507
1517 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);
1518
1520
1528 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);
1529
1531
1538 void writeCameraImageData(const std::string &camera, const std::string &band, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1);
1539
1541
1549 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);
1550
1552
1560 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);
1561
1563
1569 void writeDepthImageData(const std::string &cameralabel, const std::string &imagefile_base, const std::string &image_path = "./", int frame = -1);
1570
1572
1579 void writeNormDepthImage(const std::string &cameralabel, const std::string &imagefile_base, float max_depth, const std::string &image_path = "./", int frame = -1);
1580
1582
1591 [[deprecated]]
1592 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, int frame = -1);
1593
1595
1604 [[deprecated]]
1605 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 = "./", bool append_label_file = false,
1606 int frame = -1);
1607
1609
1618 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",
1619 const std::string &image_path = "./");
1620
1622
1631 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",
1632 const std::string &image_path = "./");
1633
1635
1644 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",
1645 const std::string &image_path = "./");
1646
1648
1657 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,
1658 const std::string &classes_txt_file = "classes.txt", const std::string &image_path = "./");
1659
1661
1672 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,
1673 const std::vector<std::string> &data_attribute_labels = {}, bool append_file = false);
1674
1676
1687 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,
1688 const std::vector<std::string> &data_attribute_labels = {}, bool append_file = false);
1689
1691
1702 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,
1703 const std::vector<std::string> &data_attribute_labels = {}, bool append_file = false);
1704
1706
1717 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,
1718 const std::vector<std::string> &data_attribute_labels = {}, bool append_file = false);
1719
1720private:
1721 // Helper functions for COCO JSON handling
1722 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);
1723 nlohmann::json initializeCOCOJson(const std::string &filename, bool append_file, const std::string &cameralabel, const helios::int2 &camera_resolution, const std::string &image_file);
1724 void addCategoryToCOCO(nlohmann::json &coco_json, const std::vector<uint> &object_class_ID, const std::vector<std::string> &category_name);
1725 void writeCOCOJson(const nlohmann::json &coco_json, const std::string &filename);
1726
1727 // Helper functions for mask generation and boundary tracing
1728 std::map<int, std::vector<std::vector<bool>>> generateLabelMasks(const std::string &cameralabel, const std::string &data_label, bool use_object_data);
1729 std::pair<int, int> findStartingBoundaryPixel(const std::vector<std::vector<bool>> &mask, const helios::int2 &camera_resolution);
1730 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);
1731 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);
1732 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);
1733
1734 // Helper functions for camera metadata export
1735 std::string detectLightingType() const;
1736 float calculateCameraTiltAngle(const helios::vec3 &position, const helios::vec3 &lookat) const;
1737 void computeAgronomicProperties(const std::string &camera_label, CameraMetadata::AgronomicProperties &props) const;
1738 void populateCameraMetadata(const std::string &camera_label, CameraMetadata &metadata) const;
1739 std::string writeCameraMetadataFile(const std::string &camera_label, const std::string &output_path = "./") const;
1740
1741public:
1743
1748 void setPadValue(const std::string &cameralabel, const std::vector<std::string> &bandlabels, const std::vector<float> &padvalues);
1749
1751
1760 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,
1761 const std::vector<std::vector<float>> &truevalues, const std::string &calibratedmark);
1762
1764
1770 void calibrateCamera(const std::string &originalcameralabel, const float scalefactor, const std::vector<std::vector<float>> &truevalues, const std::string &calibratedmark);
1771
1778
1780
1791 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,
1792 bool print_quality_report = false, ColorCorrectionAlgorithm algorithm = ColorCorrectionAlgorithm::MATRIX_3X3_AUTO, const std::string &ccm_export_file_path = "");
1793
1795 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);
1796
1798 std::vector<std::vector<float>> loadColorCorrectionMatrixXML(const std::string &file_path, std::string &camera_label_out);
1799
1801 std::vector<float> getCameraPixelData(const std::string &camera_label, const std::string &band_label);
1802
1804 void setCameraPixelData(const std::string &camera_label, const std::string &band_label, const std::vector<float> &pixel_data);
1805
1807
1811 void queryBackendGPUMemory() const;
1812
1814
1818 size_t testBuildGeometryData();
1819
1822
1825
1828
1830 std::vector<helios::RayTracingSource> &getSourceData();
1831
1834
1835protected:
1837 bool message_flag;
1838
1840 uint specular_reflection_mode = 0;
1841
1843 helios::Context *context;
1844
1845 CameraCalibration *cameracalibration;
1846 bool calibration_flag = false;
1847
1849 std::string getCurrentDateTime();
1850
1852 std::vector<uint> primitiveID;
1853
1855 std::vector<uint> context_UUIDs;
1856
1859 std::unordered_map<uint, size_t> uuid_to_position;
1860
1863 std::vector<uint> position_to_uuid;
1864
1865 // --- Radiation Band Variables --- //
1866
1867 std::map<std::string, RadiationBand> radiation_bands;
1868
1870 std::vector<helios::vec2> global_diffuse_spectrum;
1871
1873 std::string global_diffuse_spectrum_label = "none";
1874
1876 uint64_t global_diffuse_spectrum_version = 0;
1877
1878 std::map<std::string, bool> scattering_iterations_needed;
1879
1880 // --- radiation source variables --- //
1881
1882 std::vector<RadiationSource> radiation_sources;
1883
1884 // --- Camera Variables --- //
1885
1887 std::map<std::string, RadiationCamera> cameras;
1888
1890 std::map<std::string, CameraMetadata> camera_metadata;
1891
1893 std::set<std::string> metadata_enabled_cameras;
1894
1896 std::map<std::string, std::vector<uint>> spectral_reflectivity_data;
1897
1899 std::map<std::string, std::vector<uint>> spectral_transmissivity_data;
1900
1902 struct SpectrumInterpolationConfig {
1903 std::unordered_set<uint> primitive_UUIDs; // Primitive UUIDs to apply this config to
1904 std::unordered_set<uint> object_IDs; // Object IDs to apply this config to
1905 std::vector<std::string> spectra_labels; // Global data labels for spectra
1906 std::vector<float> mapping_values; // Values corresponding to each spectrum
1907 std::string query_data_label; // Primitive/object data to query (e.g., "age")
1908 std::string target_data_label; // Primitive data to set (e.g., "reflectivity_spectrum")
1909 };
1910
1911 std::vector<SpectrumInterpolationConfig> spectrum_interpolation_configs;
1912
1913 std::vector<helios::vec2> generateGaussianCameraResponse(float FWHM, float mu, float centrawavelength, const helios::int2 &wavebandrange);
1914
1915 // --- Constants and Defaults --- //
1916
1918 float sigma = 5.6703744E-8;
1919
1921 float rho_default;
1922
1924 float tau_default;
1925
1927 float eps_default;
1928
1930 float kappa_default;
1931
1933 float sigmas_default;
1934
1936 float temperature_default;
1937
1939 size_t directRayCount_default;
1940
1942 size_t diffuseRayCount_default;
1943
1945 float diffuseFlux_default;
1946
1948 float minScatterEnergy_default;
1949
1951 uint scatteringDepth_default;
1952
1953 // --- Functions --- //
1954
1956 void initializeOptiX();
1957
1959
1964 void updateRadiativeProperties();
1965
1967
1983 std::vector<float> updateAtmosphericSkyModel(const std::vector<std::string> &band_labels, const RadiationCamera &camera);
1984
1986
1992 void updatePragueParametersForGeneralDiffuse(const std::vector<std::string> &band_labels);
1993
1995
1999 std::vector<helios::vec2> loadSpectralData(const std::string &global_data_label) const;
2000
2002
2003
2004 void buildLightModelGeometry(uint sourceID);
2005
2006 void buildCameraModelGeometry(const std::string &cameralabel);
2007
2008 void updateLightModelPosition(uint sourceID, const helios::vec3 &delta_position);
2009
2010 void updateCameraModelPosition(const std::string &cameralabel);
2011
2013
2022 helios::RayTracingLaunchParams buildCameraLaunchParams(const RadiationCamera &camera, uint camera_id, uint antialiasing_samples, const helios::int2 &tile_resolution, const helios::int2 &tile_offset);
2023
2025
2031 std::vector<CameraTile> computeCameraTiles(const RadiationCamera &camera, size_t maxRays);
2032
2034
2038 void buildGeometryData();
2039
2041
2046 void buildTextureData();
2047
2050 void buildUUIDMapping();
2051
2053 void buildMaterialData();
2054
2056 void buildSourceData();
2057
2059 std::map<uint, std::vector<uint>> source_model_UUIDs;
2061 std::map<std::string, std::vector<uint>> camera_model_UUIDs;
2062
2063 /* Phase 1: Backend abstraction layer (for incremental OptiX code replacement) */
2064
2066 std::unique_ptr<helios::RayTracingBackend> backend;
2067
2069 helios::RayTracingGeometry geometry_data;
2070
2072 helios::RayTracingMaterial material_data;
2073
2075 std::vector<helios::RayTracingSource> source_data;
2076
2077
2079 bool isgeometryinitialized;
2080
2082 helios::vec2 periodic_flag;
2083
2084 bool radiativepropertiesneedupdate = true;
2085
2086 std::vector<bool> isbandpropertyinitialized;
2087
2088 bool islightvisualizationenabled = false;
2089 bool iscameravisualizationenabled = false;
2090
2092 std::vector<std::string> output_prim_data;
2093
2094 std::vector<std::string> spectral_library_files;
2095
2096 // Helper methods for Prague Sky Model spectral integration from Context
2097 float integrateOverResponse(const std::vector<float> &wavelengths, const std::vector<float> &values, const std::vector<helios::vec2> &camera_response) const;
2098
2099 float weightedAverageOverResponse(const std::vector<float> &wavelengths, const std::vector<float> &param_values, const std::vector<float> &weight_values, const std::vector<helios::vec2> &camera_response) const;
2100
2101 float computeAngularNormalization(float circ_str, float circ_width, float horiz_bright) const;
2102};
2103
2104#endif