175 label(std::move(initlabel)), band_labels(band_label), position(initposition), lookat(initlookat), antialiasing_samples(initantialiasing_samples) {
176 for (
const auto &band: band_label) {
177 band_spectral_response[band] =
"uniform";
183 HFOV_degrees = camera_properties.
HFOV;
186 model = camera_properties.
model;
190 exposure = camera_properties.
exposure;
209 float lens_focal_length;
213 float FOV_aspect_ratio;
215 float sensor_width_mm;
219 std::string lens_make;
221 std::string lens_model;
223 std::string lens_specification;
225 std::string exposure;
229 std::string white_balance;
233 std::string camera_type;
235 uint antialiasing_samples;
237 std::vector<std::string> band_labels;
239 std::map<std::string, std::string> band_spectral_response;
241 std::map<std::string, std::vector<float>> pixel_data;
243 std::vector<uint> pixel_label_UUID;
244 std::vector<float> pixel_depth;
275 void whiteBalance(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float p = 5.0);
287 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);
297 void whiteBalanceWhitePatch(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float percentile = 0.99f);
321 void reinhardToneMapping(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label);
332 void applyGain(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float percentile = 0.95f);
340 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);
358 void gammaCompress(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label);
367 void globalHistogramEqualization(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label);
376 void autoExposure(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float gain_multiplier);
414 void adjustBrightnessContrast(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float brightness,
float contrast);
423 void adjustSaturation(
const std::string &red_band_label,
const std::string &green_band_label,
const std::string &blue_band_label,
float saturation);
436 return (x <= 0.0031308f) ? 12.92f * x : 1.055f * std::pow(x, 1.0f / 2.4f) - 0.055f;
445 return (v <= 0.04045f) ? v / 12.92f : std::pow((v + 0.055f) / 1.055f, 2.4f);
456 static float luminance(
float red,
float green,
float blue)
noexcept {
457 return 0.2126f * red + 0.7152f * green + 0.0722f * blue;
694 static int selfTest(
int argc = 0,
char **argv =
nullptr);
820 void setDiffuseSpectrumIntegral(
const std::string &band_label,
float spectrum_integral,
float wavelength_min,
float wavelength_max);
834 void addRadiationBand(
const std::string &label,
float wavelength_min,
float wavelength_max);
841 void copyRadiationBand(
const std::string &old_label,
const std::string &new_label);
850 void copyRadiationBand(
const std::string &old_label,
const std::string &new_label,
float wavelength_min,
float wavelength_max);
974 void setSourceFlux(
const std::vector<uint> &source_ID,
const std::string &band_label,
float flux);
1018 void setSourceSpectrum(
const std::vector<uint> &source_ID,
const std::vector<helios::vec2> &spectrum);
1032 void setSourceSpectrum(
const std::vector<uint> &source_ID,
const std::string &spectrum_label);
1067 float integrateSpectrum(
const std::vector<helios::vec2> &object_spectrum,
float wavelength_min,
float wavelength_max)
const;
1074 float integrateSpectrum(
const std::vector<helios::vec2> &object_spectrum)
const;
1084 float integrateSpectrum(
uint source_ID,
const std::vector<helios::vec2> &object_spectrum,
float wavelength_min,
float wavelength_max)
const;
1093 float integrateSpectrum(
uint source_ID,
const std::vector<helios::vec2> &object_spectrum,
const std::vector<helios::vec2> &camera_spectrum)
const;
1101 float integrateSpectrum(
const std::vector<helios::vec2> &object_spectrum,
const std::vector<helios::vec2> &camera_spectrum)
const;
1118 void scaleSpectrum(
const std::string &existing_global_data_label,
const std::string &new_global_data_label,
float scale_factor)
const;
1125 void scaleSpectrum(
const std::string &global_data_label,
float scale_factor)
const;
1134 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;
1143 void blendSpectra(
const std::string &new_spectrum_label,
const std::vector<std::string> &spectrum_labels,
const std::vector<float> &weights)
const;
1151 void blendSpectraRandomly(
const std::string &new_spectrum_label,
const std::vector<std::string> &spectrum_labels)
const;
1165 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,
1166 const std::string &primitive_data_radprop_label);
1181 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);
1225 uint antialiasing_samples);
1274 uint antialiasing_samples);
1294 [[nodiscard]]
bool isSIFCamera(
const std::string &camera_label)
const;
1304 void setCameraSpectralResponse(
const std::string &camera_label,
const std::string &band_label,
const std::string &global_data);
1535 void runBand(
const std::string &label);
1543 void runBand(
const std::vector<std::string> &labels);
1570 void updateCameraResponse(
const std::string &orginalcameralabel,
const std::vector<std::string> &sourcelabels_raw,
const std::vector<std::string> &cameraresponselabels,
helios::vec2 &wavelengthrange,
1571 const std::vector<std::vector<float>> &truevalues,
const std::string &calibratedmark);
1583 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,
1584 const std::vector<std::vector<float>> &truevalues);
1597 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,
1598 float fluxscale = 1,
float diffusefactor = 0.0005,
uint scatteringdepth = 4);
1611 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,
1612 float fluxscale = 1,
float diffusefactor = 0.0005,
uint scatteringdepth = 4);
1628 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,
1629 float contrast_adjustment = 1.f);
1632 [[deprecated(
"Use applyCameraImageCorrections() instead")]]
1633 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,
1634 float contrast_adjustment = 1.f,
float gain_adjustment = 1.f);
1644 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);
1658 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);
1669 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);
1679 void writeCameraImageData(
const std::string &camera,
const std::string &band,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1689 void writeCameraImageDataEXR(
const std::string &camera,
const std::string &band,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1699 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);
1710 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);
1721 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);
1730 void writeDepthImageData(
const std::string &cameralabel,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1739 void writeDepthImageDataEXR(
const std::string &cameralabel,
const std::string &imagefile_base,
const std::string &image_path =
"./",
int frame = -1);
1749 void writeNormDepthImage(
const std::string &cameralabel,
const std::string &imagefile_base,
float max_depth,
const std::string &image_path =
"./",
int frame = -1);
1762 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);
1775 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,
1788 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",
1789 const std::string &image_path =
"./");
1801 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",
1802 const std::string &image_path =
"./");
1814 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",
1815 const std::string &image_path =
"./");
1827 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,
1828 const std::string &classes_txt_file =
"classes.txt",
const std::string &image_path =
"./");
1842 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,
1843 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1857 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,
1858 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1872 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,
1873 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1887 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,
1888 const std::vector<std::string> &data_attribute_labels = {},
bool append_file =
false);
1892 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);
1893 nlohmann::json initializeCOCOJson(
const std::string &filename,
bool append_file,
const std::string &cameralabel,
const helios::int2 &camera_resolution,
const std::string &image_file);
1894 void addCategoryToCOCO(nlohmann::json &coco_json,
const std::vector<uint> &object_class_ID,
const std::vector<std::string> &category_name);
1895 void writeCOCOJson(
const nlohmann::json &coco_json,
const std::string &filename);
1898 std::map<int, std::vector<std::vector<bool>>> generateLabelMasks(
const std::string &cameralabel,
const std::string &data_label,
bool use_object_data);
1899 std::pair<int, int> findStartingBoundaryPixel(
const std::vector<std::vector<bool>> &mask,
const helios::int2 &camera_resolution);
1900 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);
1901 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);
1902 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);
1905 std::string detectLightingType()
const;
1908 void populateCameraMetadata(
const std::string &camera_label,
CameraMetadata &metadata)
const;
1909 std::string writeCameraMetadataFile(
const std::string &camera_label,
const std::string &output_path =
"./")
const;
1918 void setPadValue(
const std::string &cameralabel,
const std::vector<std::string> &bandlabels,
const std::vector<float> &padvalues);
1930 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,
1931 const std::vector<std::vector<float>> &truevalues,
const std::string &calibratedmark);
1940 void calibrateCamera(
const std::string &originalcameralabel,
const float scalefactor,
const std::vector<std::vector<float>> &truevalues,
const std::string &calibratedmark);
1961 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,
1965 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);
1971 std::vector<float>
getCameraPixelData(
const std::string &camera_label,
const std::string &band_label);
1974 void setCameraPixelData(
const std::string &camera_label,
const std::string &band_label,
const std::vector<float> &pixel_data);
1981 size_t testBuildGeometryData();
1993 std::vector<helios::RayTracingSource> &getSourceData();
1996 void testBuildAllBackendData();
1999 void queryBackendGPUMemory()
const;
2006 uint specular_reflection_mode = 0;
2012 bool calibration_flag =
false;
2015 std::string getCurrentDateTime();
2018 std::vector<uint> primitiveID;
2021 std::vector<uint> context_UUIDs;
2025 std::unordered_map<uint, size_t> uuid_to_position;
2029 std::vector<uint> position_to_uuid;
2033 std::map<std::string, RadiationBand> radiation_bands;
2036 std::vector<helios::vec2> global_diffuse_spectrum;
2039 std::string global_diffuse_spectrum_label =
"none";
2042 uint64_t global_diffuse_spectrum_version = 0;
2044 std::map<std::string, bool> scattering_iterations_needed;
2051 std::map<std::string, std::unordered_map<uint, float>> sif_emission_buffer;
2056 std::map<std::string, std::unordered_map<uint, float>> sif_emission_buffer_bottom;
2060 std::set<std::string> sif_emission_bands;
2065 std::map<std::string, float> sif_band_bin_width;
2068 std::set<std::string> sif_cameras;
2073 struct FluspectCacheKey {
2074 std::string biochem_label;
2075 float excitation_step_nm;
2076 bool operator==(
const FluspectCacheKey &o)
const noexcept;
2078 struct FluspectCacheKeyHash {
2079 std::size_t operator()(
const FluspectCacheKey &k)
const noexcept;
2082 std::unordered_map<FluspectCacheKey, helios::FluspectKernel, FluspectCacheKeyHash> fluspect_cache;
2085 bool fluspect_optipar_loaded =
false;
2088 struct ExcitationSet {
2090 uint scattering_depth = 0;
2091 std::vector<std::string> band_labels;
2092 std::vector<float> band_min_nm;
2093 std::vector<float> band_max_nm;
2095 std::unordered_map<uint, std::vector<float>> apar_buffer;
2097 bool populated =
false;
2100 std::map<float, ExcitationSet> excitation_sets;
2108 static float calculateFluorescenceYield(
float J_over_Jmax,
float T_leaf_K);
2111 void ensureFluspectOptiparLoaded();
2126 ExcitationSet &ensureExcitationSet(
float bin_width_nm,
uint scattering_depth = 0);
2131 void populateExcitationAPAR(ExcitationSet &exc);
2135 void runExcitationBands();
2142 void computeSIFEmission(
const std::string &emission_band);
2146 std::vector<RadiationSource> radiation_sources;
2151 std::map<std::string, RadiationCamera> cameras;
2154 std::map<std::string, CameraMetadata> camera_metadata;
2157 std::set<std::string> metadata_enabled_cameras;
2160 std::map<std::string, std::vector<uint>> spectral_reflectivity_data;
2163 std::map<std::string, std::vector<uint>> spectral_transmissivity_data;
2166 struct SpectrumInterpolationConfig {
2167 std::unordered_set<uint> primitive_UUIDs;
2168 std::unordered_set<uint> object_IDs;
2169 std::vector<std::string> spectra_labels;
2170 std::vector<float> mapping_values;
2171 std::string query_data_label;
2172 std::string target_data_label;
2175 std::vector<SpectrumInterpolationConfig> spectrum_interpolation_configs;
2177 std::vector<helios::vec2> generateGaussianCameraResponse(
float FWHM,
float mu,
float centrawavelength,
const helios::int2 &wavebandrange);
2182 float sigma = 5.6703744E-8;
2194 float kappa_default;
2197 float sigmas_default;
2200 float temperature_default;
2203 size_t directRayCount_default;
2206 size_t diffuseRayCount_default;
2209 float diffuseFlux_default;
2212 float minScatterEnergy_default;
2215 uint scatteringDepth_default;
2220 void initializeOptiX();
2228 void updateRadiativeProperties();
2247 std::vector<float> updateAtmosphericSkyModel(
const std::vector<std::string> &band_labels,
const RadiationCamera &camera);
2256 void updatePragueParametersForGeneralDiffuse(
const std::vector<std::string> &band_labels);
2263 std::vector<helios::vec2> loadSpectralData(
const std::string &global_data_label)
const;
2268 void buildLightModelGeometry(
uint sourceID);
2270 void buildCameraModelGeometry(
const std::string &cameralabel);
2272 void updateLightModelPosition(
uint sourceID,
const helios::vec3 &delta_position);
2274 void updateCameraModelPosition(
const std::string &cameralabel);
2295 std::vector<CameraTile> computeCameraTiles(
const RadiationCamera &camera,
size_t maxRays);
2303 void buildGeometryData(
const std::vector<uint> &UUIDs);
2311 void buildTextureData();
2315 void buildUUIDMapping();
2318 void buildMaterialData();
2321 void buildSourceData();
2324 std::map<uint, std::vector<uint>> source_model_UUIDs;
2326 std::map<std::string, std::vector<uint>> camera_model_UUIDs;
2331 std::unique_ptr<helios::RayTracingBackend> backend;
2340 std::vector<helios::RayTracingSource> source_data;
2344 bool isgeometryinitialized;
2349 bool radiativepropertiesneedupdate =
true;
2351 std::vector<bool> isbandpropertyinitialized;
2353 bool islightvisualizationenabled =
false;
2354 bool iscameravisualizationenabled =
false;
2357 std::vector<std::string> output_prim_data;
2359 std::vector<std::string> spectral_library_files;
2362 float integrateOverResponse(
const std::vector<float> &wavelengths,
const std::vector<float> &values,
const std::vector<helios::vec2> &camera_response)
const;
2364 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;
2366 float computeAngularNormalization(
float circ_str,
float circ_width,
float horiz_bright)
const;