178 label(std::move(initlabel)), band_labels(band_label), position(initposition), lookat(initlookat), antialiasing_samples(initantialiasing_samples) {
179 for (
const auto &band: band_label) {
180 band_spectral_response[band] =
"uniform";
182 focal_length = camera_properties.focal_plane_distance;
183 lens_focal_length = camera_properties.lens_focal_length;
184 resolution = camera_properties.camera_resolution;
185 lens_diameter = camera_properties.lens_diameter;
186 HFOV_degrees = camera_properties.HFOV;
187 FOV_aspect_ratio = camera_properties.FOV_aspect_ratio;
188 sensor_width_mm = camera_properties.sensor_width_mm;
190 model = camera_properties.model;
191 lens_make = camera_properties.lens_make;
192 lens_model = camera_properties.lens_model;
193 lens_specification = camera_properties.lens_specification;
194 exposure = camera_properties.exposure;
195 shutter_speed = camera_properties.shutter_speed;
196 white_balance = camera_properties.white_balance;
197 camera_zoom = camera_properties.camera_zoom;
213 float lens_focal_length;
217 float FOV_aspect_ratio;
219 float sensor_width_mm;
225 std::string lens_make;
227 std::string lens_model;
229 std::string lens_specification;
231 std::string exposure;
235 std::string white_balance;
239 std::string camera_type;
241 uint antialiasing_samples;
243 std::vector<std::string> band_labels;
245 std::map<std::string, std::string> band_spectral_response;
247 std::map<std::string, std::vector<float>> pixel_data;
249 std::vector<uint> pixel_label_UUID;
250 std::vector<float> pixel_depth;
281 void whiteBalance(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float p = 5.0);
293 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);
303 void whiteBalanceWhitePatch(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float percentile = 0.99f);
327 void reinhardToneMapping(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label);
338 void applyGain(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float percentile = 0.95f);
346 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);
364 void gammaCompress(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label);
373 void globalHistogramEqualization(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label);
382 void autoExposure(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float gain_multiplier);
420 void adjustBrightnessContrast(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float brightness,
float contrast);
429 void adjustSaturation(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float saturation);
442 return (x <= 0.0031308f) ? 12.92f * x : 1.055f * std::pow(x, 1.0f / 2.4f) - 0.055f;
451 return (v <= 0.04045f) ? v / 12.92f : std::pow((v + 0.055f) / 1.055f, 2.4f);
462 static float luminance(
float red,
float green,
float blue)
noexcept {
463 return 0.2126f * red + 0.7152f * green + 0.0722f * blue;
700 static int selfTest(
int argc = 0,
char **argv =
nullptr);
788 void setDiffuseRadiationExtinctionCoeff(
const std::string &label,
float K,
const helios::SphericalCoord &peak_dir);
826 void setDiffuseSpectrumIntegral(
const std::string &band_label,
float spectrum_integral,
float wavelength_min,
float wavelength_max);
840 void addRadiationBand(
const std::string &label,
float wavelength_min,
float wavelength_max);
847 void copyRadiationBand(
const std::string &old_label,
const std::string &new_label);
856 void copyRadiationBand(
const std::string &old_label,
const std::string &new_label,
float wavelength_min,
float wavelength_max);
964 void setSourceSpectrumIntegral(
uint source_ID,
float source_integral,
float wavelength_min,
float wavelength_max);
980 void setSourceFlux(
const std::vector<uint> &source_ID,
const std::string &band_label,
float flux);
1024 void setSourceSpectrum(
const std::vector<uint> &source_ID,
const std::vector<helios::vec2> &spectrum);
1038 void setSourceSpectrum(
const std::vector<uint> &source_ID,
const std::string &spectrum_label);
1073 float integrateSpectrum(
const std::vector<helios::vec2> &object_spectrum,
float wavelength_min,
float wavelength_max)
const;
1080 float integrateSpectrum(
const std::vector<helios::vec2> &object_spectrum)
const;
1090 float integrateSpectrum(
uint source_ID,
const std::vector<helios::vec2> &object_spectrum,
float wavelength_min,
float wavelength_max)
const;
1099 float integrateSpectrum(
uint source_ID,
const std::vector<helios::vec2> &object_spectrum,
const std::vector<helios::vec2> &camera_spectrum)
const;
1107 float integrateSpectrum(
const std::vector<helios::vec2> &object_spectrum,
const std::vector<helios::vec2> &camera_spectrum)
const;
1124 void scaleSpectrum(
const std::string &existing_global_data_label,
const std::string &new_global_data_label,
float scale_factor)
const;
1131 void scaleSpectrum(
const std::string &global_data_label,
float scale_factor)
const;
1140 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;
1149 void blendSpectra(
const std::string &new_spectrum_label,
const std::vector<std::string> &spectrum_labels,
const std::vector<float> &weights)
const;
1157 void blendSpectraRandomly(
const std::string &new_spectrum_label,
const std::vector<std::string> &spectrum_labels)
const;
1171 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,
1172 const std::string &primitive_data_radprop_label);
1187 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);
1231 uint antialiasing_samples);
1280 uint antialiasing_samples);
1300 [[nodiscard]]
bool isSIFCamera(
const std::string &camera_label)
const;
1310 void setCameraSpectralResponse(
const std::string &camera_label,
const std::string &band_label,
const std::string &global_data);
1541 void runBand(
const std::string &label);
1549 void runBand(
const std::vector<std::string> &labels);
1576 void updateCameraResponse(
const std::string &orginalcameralabel,
const std::vector<std::string> &sourcelabels_raw,
const std::vector<std::string> &cameraresponselabels,
helios::vec2 &wavelengthrange,
1577 const std::vector<std::vector<float>> &truevalues,
const std::string &calibratedmark);
1589 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,
1590 const std::vector<std::vector<float>> &truevalues);
1603 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,
1604 float fluxscale = 1,
float diffusefactor = 0.0005,
uint scatteringdepth = 4);
1617 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,
1618 float fluxscale = 1,
float diffusefactor = 0.0005,
uint scatteringdepth = 4);
1634 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,
1635 float contrast_adjustment = 1.f);
1638 [[deprecated(
"Use applyCameraImageCorrections() instead")]]
1639 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,
1640 float contrast_adjustment = 1.f,
float gain_adjustment = 1.f);
1650 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);
1664 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);
1675 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);
1685 void writeCameraImageData(
const std::string &camera,
const std::string &band,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1695 void writeCameraImageDataEXR(
const std::string &camera,
const std::string &band,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1705 void writeCameraImageDataEXR(
const std::string &camera,
const std::vector<std::string> &bands,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1716 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);
1727 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);
1736 void writeDepthImageData(
const std::string &cameralabel,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1745 void writeDepthImageDataEXR(
const std::string &cameralabel,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1755 void writeNormDepthImage(
const std::string &cameralabel,
const std::string &imagefile_base,
float max_depth,
const std::string &image_path =
"./",
int frame = -1);
1768 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);
1781 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,
1794 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",
1795 const std::string &image_path =
"./");
1807 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",
1808 const std::string &image_path =
"./");
1820 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",
1821 const std::string &image_path =
"./");
1833 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,
1834 const std::string &classes_txt_file =
"classes.txt",
const std::string &image_path =
"./");
1848 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,
1849 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1863 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,
1864 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1878 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,
1879 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1893 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,
1894 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1898 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);
1899 nlohmann::json initializeCOCOJson(
const std::string &filename,
bool append_file,
const std::string &cameralabel,
const helios::int2 &camera_resolution,
const std::string &image_file);
1900 void addCategoryToCOCO(nlohmann::json &coco_json,
const std::vector<uint> &object_class_ID,
const std::vector<std::string> &category_name);
1901 void writeCOCOJson(
const nlohmann::json &coco_json,
const std::string &filename);
1904 std::map<int, std::vector<std::vector<bool>>> generateLabelMasks(
const std::string &cameralabel,
const std::string &data_label,
bool use_object_data);
1905 std::pair<int, int> findStartingBoundaryPixel(
const std::vector<std::vector<bool>> &mask,
const helios::int2 &camera_resolution);
1906 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);
1907 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);
1908 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);
1911 std::string detectLightingType()
const;
1914 void populateCameraMetadata(
const std::string &camera_label,
CameraMetadata &metadata)
const;
1915 std::string writeCameraMetadataFile(
const std::string &camera_label,
const std::string &output_path =
"./")
const;
1935 void setPadValue(
const std::string &cameralabel,
const std::vector<std::string> &bandlabels,
const std::vector<float> &padvalues);
1947 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,
1948 const std::vector<std::vector<float>> &truevalues,
const std::string &calibratedmark);
1957 void calibrateCamera(
const std::string &originalcameralabel,
const float scalefactor,
const std::vector<std::vector<float>> &truevalues,
const std::string &calibratedmark);
1978 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,
1982 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);
1988 std::vector<float>
getCameraPixelData(
const std::string &camera_label,
const std::string &band_label);
1991 void setCameraPixelData(
const std::string &camera_label,
const std::string &band_label,
const std::vector<float> &pixel_data);
1998 size_t testBuildGeometryData();
2010 std::vector<helios::RayTracingSource> &getSourceData();
2013 void testBuildAllBackendData();
2016 void queryBackendGPUMemory()
const;
2023 uint specular_reflection_mode = 0;
2029 bool calibration_flag =
false;
2032 std::string getCurrentDateTime();
2035 std::vector<uint> primitiveID;
2038 std::vector<uint> context_UUIDs;
2042 std::unordered_map<uint, size_t> uuid_to_position;
2046 std::vector<uint> position_to_uuid;
2050 std::map<std::string, RadiationBand> radiation_bands;
2053 std::vector<helios::vec2> global_diffuse_spectrum;
2056 std::string global_diffuse_spectrum_label =
"none";
2059 uint64_t global_diffuse_spectrum_version = 0;
2061 std::map<std::string, bool> scattering_iterations_needed;
2068 std::map<std::string, std::unordered_map<uint, float>> sif_emission_buffer;
2073 std::map<std::string, std::unordered_map<uint, float>> sif_emission_buffer_bottom;
2077 std::set<std::string> sif_emission_bands;
2082 std::map<std::string, float> sif_band_bin_width;
2085 std::set<std::string> sif_cameras;
2090 struct FluspectCacheKey {
2091 std::string biochem_label;
2092 float excitation_step_nm;
2093 bool operator==(
const FluspectCacheKey &o)
const noexcept;
2095 struct FluspectCacheKeyHash {
2096 std::size_t operator()(
const FluspectCacheKey &k)
const noexcept;
2099 std::unordered_map<FluspectCacheKey, helios::FluspectKernel, FluspectCacheKeyHash> fluspect_cache;
2102 bool fluspect_optipar_loaded =
false;
2105 struct ExcitationSet {
2107 uint scattering_depth = 0;
2108 std::vector<std::string> band_labels;
2109 std::vector<float> band_min_nm;
2110 std::vector<float> band_max_nm;
2112 std::unordered_map<uint, std::vector<float>> apar_buffer;
2114 bool populated =
false;
2117 std::map<float, ExcitationSet> excitation_sets;
2125 static float calculateFluorescenceYield(
float J_over_Jmax,
float T_leaf_K);
2128 void ensureFluspectOptiparLoaded();
2143 ExcitationSet &ensureExcitationSet(
float bin_width_nm,
uint scattering_depth = 0);
2148 void populateExcitationAPAR(ExcitationSet &exc);
2152 void runExcitationBands();
2159 void computeSIFEmission(
const std::string &emission_band);
2163 std::vector<RadiationSource> radiation_sources;
2168 std::map<std::string, RadiationCamera> cameras;
2171 std::map<std::string, CameraMetadata> camera_metadata;
2174 std::set<std::string> metadata_enabled_cameras;
2177 std::map<std::string, std::vector<uint>> spectral_reflectivity_data;
2180 std::map<std::string, std::vector<uint>> spectral_transmissivity_data;
2183 struct SpectrumInterpolationConfig {
2184 std::unordered_set<uint> primitive_UUIDs;
2185 std::unordered_set<uint> object_IDs;
2186 std::vector<std::string> spectra_labels;
2187 std::vector<float> mapping_values;
2188 std::string query_data_label;
2189 std::string target_data_label;
2192 std::vector<SpectrumInterpolationConfig> spectrum_interpolation_configs;
2194 std::vector<helios::vec2> generateGaussianCameraResponse(
float FWHM,
float mu,
float centrawavelength,
const helios::int2 &wavebandrange);
2199 float sigma = 5.6703744E-8;
2211 float kappa_default;
2214 float sigmas_default;
2217 float temperature_default;
2220 size_t directRayCount_default;
2223 size_t diffuseRayCount_default;
2226 float diffuseFlux_default;
2229 float minScatterEnergy_default;
2232 uint scatteringDepth_default;
2237 void initializeOptiX();
2245 void updateRadiativeProperties();
2264 std::vector<float> updateAtmosphericSkyModel(
const std::vector<std::string> &band_labels,
const RadiationCamera &camera);
2273 void updatePragueParametersForGeneralDiffuse(
const std::vector<std::string> &band_labels);
2280 std::vector<helios::vec2> loadSpectralData(
const std::string &global_data_label)
const;
2285 void buildLightModelGeometry(
uint sourceID);
2287 void buildCameraModelGeometry(
const std::string &cameralabel);
2289 void updateLightModelPosition(
uint sourceID,
const helios::vec3 &delta_position);
2291 void updateCameraModelPosition(
const std::string &cameralabel);
2312 std::vector<CameraTile> computeCameraTiles(
const RadiationCamera &camera,
size_t maxRays);
2320 void buildGeometryData(
const std::vector<uint> &UUIDs);
2328 void buildTextureData();
2332 void buildUUIDMapping();
2335 void buildMaterialData();
2338 void buildSourceData();
2341 std::map<uint, std::vector<uint>> source_model_UUIDs;
2343 std::map<std::string, std::vector<uint>> camera_model_UUIDs;
2348 std::unique_ptr<helios::RayTracingBackend> backend;
2357 std::vector<helios::RayTracingSource> source_data;
2361 bool isgeometryinitialized;
2366 bool radiativepropertiesneedupdate =
true;
2368 std::vector<bool> isbandpropertyinitialized;
2370 bool islightvisualizationenabled =
false;
2371 bool iscameravisualizationenabled =
false;
2374 std::vector<std::string> output_prim_data;
2376 std::vector<std::string> spectral_library_files;
2379 float integrateOverResponse(
const std::vector<float> &wavelengths,
const std::vector<float> &values,
const std::vector<helios::vec2> &camera_response)
const;
2381 float weightedAverageOverResponse(
const std::vector<float> &wavelengths,
const std::vector<float> ¶m_values,
const std::vector<float> &weight_values,
const std::vector<helios::vec2> &camera_response)
const;
2383 float computeAngularNormalization(
float circ_str,
float circ_width,
float horiz_bright)
const;