1.3.82
 
Loading...
Searching...
No Matches
LeafOptics.h
Go to the documentation of this file.
1
16#include "Context.h"
17
19
22
23 float numberlayers = 1.5;
24 float brownpigments = 0.f;
25 float chlorophyllcontent = 30.f; // µg.cm-2
26 float carotenoidcontent = 7.f; // µg.cm-2
27 float anthocyancontent = 1; // µg.cm-2
28 float watermass = 0.015f; // g.cm-2
29 float drymass = 0.09f; // g.cm-2
30 float protein = 0.f; // g.cm-2
31 float carbonconstituents = 0.f; // g.cm-2
32
33 // === Fluspect-B SIF parameters (optional) ===
34 // These are used by the radiation plugin's SIF (solar-induced fluorescence)
35 // pipeline when it is active. They are ignored by the pure reflectance/
36 // transmittance PROSPECT calculation performed by LeafOptics. When
37 // LeafOptics::run() is called, it writes these values alongside the PROSPECT
38 // parameters to global data keyed by the spectrum label so that the radiation
39 // model can look them up per primitive.
40
45 float V2Z = 0.f;
46
51 float fqe = 1.f;
52
53 // Default values for Prospect-D
54 // float N=1.5; float CHL= 30.0 ; float CAR = 10.0; float ANT = 1.0; float Brown=0.0; float EWT= 0.015; float LMA = 0.009;
55
56 // Default values for Prospect-PRO
57 // float N=1.5; float CHL= 40.0 ; float CAR = 10.0; float ANT = 0.5; float Brown=0.0; float EWT= 0.015; float pro = 0.001; float carbon = 0.009;
58
60
61 LeafOpticsProperties(float chlorophyllcontent, float carotenoidcontent, float anthocyancontent, float watermass, float drymass, float protein, float carbonconstituents) :
62 chlorophyllcontent(chlorophyllcontent), carotenoidcontent(carotenoidcontent), anthocyancontent(anthocyancontent), watermass(watermass), drymass(drymass), protein(protein), carbonconstituents(carbonconstituents) {
63 }
64};
65
67
80
81 // === Nitrogen-to-pigment conversion coefficients ===
82
84 float f_photosynthetic = 0.50f;
85
87
88 float N_to_Cab_coefficient = 0.40f;
89
91
92 float Car_to_Cab_ratio = 0.25f;
93
94 // === Fixed PROSPECT parameters (not derived from nitrogen) ===
95
96 float numberlayers = 1.5f;
97 float anthocyancontent = 1.0f;
98 float brownpigments = 0.0f;
99 float watermass = 0.015f;
100 float drymass = 0.006f;
101 float protein = 0.0f;
102 float carbonconstituents = 0.0f;
103
104 // === Fluspect-B SIF parameters (optional, fixed per bin) ===
105 float V2Z = 0.f;
106 float fqe = 1.f;
107
108 // === Adaptive binning configuration ===
109
111
113
115
117
119
121};
122
124public:
126 LeafOptics(helios::Context *a_context);
127
129
132 static int selfTest(int argc = 0, char **argv = nullptr);
133
135
140 void run(const std::vector<uint> &UUIDs, const LeafOpticsProperties &leafproperties, const std::string &label);
141
143
147 void run(const LeafOpticsProperties &leafproperties, const std::string &label);
148
150
163 void PROSPECT(float numberlayers, float Chlorophyllcontent, float carotenoidcontent, float anthocyancontent, float brownpigments, float watermass, float drymass, float protein, float carbonconstituents, std::vector<float> &reflectivities_fit,
164 std::vector<float> &transmissivities_fit);
165
167
173 void getLeafSpectra(const LeafOpticsProperties &leafproperties, std::vector<helios::vec2> &reflectivities_fit, std::vector<helios::vec2> &transmissivities_fit);
174
176
180 void setProperties(const std::vector<uint> &UUIDs, const LeafOpticsProperties &leafproperties);
181
183
188 void getPropertiesFromSpectrum(const std::vector<uint> &UUIDs);
189
191
197
199
203 void getPropertiesFromLibrary(const std::string &species, LeafOpticsProperties &leafproperties);
204
206 void disableMessages();
207
209 void enableMessages();
210
212
215 void optionalOutputPrimitiveData(const char *label);
216
218
235 void run(const std::vector<uint> &UUIDs, const LeafOpticsProperties_Nauto &params);
236
238
249
250private:
251 std::vector<float> R_spec_normal, R_spec_diffuse, wave_length, Rtotal, Ttotal;
252
254 const uint nw = 2101;
255
257 helios::Context *context;
259 std::map<std::string, LeafOpticsProperties> spectrum_parameters_map;
261 std::map<std::string, LeafOpticsProperties> species_library;
263 void initializeSpeciesLibrary();
266 float chlorophyll_default = 43.0;
267 float chlorophyll_default_grass = 57.0;
268 float carotenoid2chlorophyll = 0.23;
269 float carotenoid2chlorophyll_grass = 0.21;
270 float anthocyanin2carotenoid = 0.06;
271 float anthocyanin2carotenoid_grass = 0.006;
272 float drymass2chlorophyll = 1.2669e-04;
273 float drymass2chlorophyll_grass = 9.2196e-05;
274 float watercontent = 0.9;
275
276 //
277 std::vector<float> refractiveindex, absorption_chlorophyll, absorption_carotenoid, absorption_anthocyanin, absorption_brown, absorption_water, absorption_drymass;
278 std::vector<float> absorption_protein, absorption_carbonconstituents;
279 std::vector<float> Rcof, Tcof;
280 // std::vector<float> R_spec_normal, R_spec_diffuse, wave_length;
281
283
287 void validateProperties(const LeafOpticsProperties &leafproperties);
288
289 float transmittance(double k);
290 // Computes the diffuse transmittance through an elementary layer
291
292 void surface(float degree, std::vector<float> &reflectivities);
293 // Computes surface reflectances for normal and diffuse light incidence
294
295 bool message_flag = true;
296
298 std::vector<std::string> output_prim_data;
299
300 // === Nitrogen mode state ===
301
303 bool nitrogen_mode_active = false;
304
306 LeafOpticsProperties_Nauto nitrogen_params;
307
309 struct SpectrumBin {
310 float N_center;
311 std::string spectrum_label;
312 };
313
315 std::vector<SpectrumBin> nitrogen_bins;
316
318 struct ObjectAssignment {
319 uint bin_index;
320 float N_at_assignment;
321 std::vector<uint> primitive_UUIDs;
322 };
323
325 std::map<uint, ObjectAssignment> object_assignments;
326
328 std::map<uint, uint> primitive_to_object;
329
330 // === Nitrogen mode helper methods ===
331
333 LeafOpticsProperties computePropertiesFromNitrogen(float N_area_gN_m2, const LeafOpticsProperties_Nauto &params);
334
336 std::map<uint, std::vector<uint>> groupPrimitivesByObject(const std::vector<uint> &UUIDs);
337
339 void createAdaptiveBins(const std::vector<float> &nitrogen_values);
340
342 uint findNearestBin(float N_value);
343
345 bool shouldReassign(float current_N, uint current_bin);
346
348 bool isSignificantImprovement(float current_N, uint old_bin, uint new_bin);
349
351 void assignSpectrumToPrimitives(const std::vector<uint> &UUIDs, uint bin_index);
352};