1 #ifndef boxm2_shadow_model_functor_h_ 2 #define boxm2_shadow_model_functor_h_ 3 //: 4 // \file 5 6 #include <boxm2/cpp/algo/boxm2_cast_ray_function.h> 7 #include <boxm2/cpp/algo/boxm2_mog3_grey_processor.h> 8 #include <boxm2/io/boxm2_stream_cache.h> 9 #include <bsta/algo/bsta_sigma_normalizer.h> 10 11 class boxm2_compute_ambient_functor 12 { 13 public: 14 typedef boxm2_data_traits<BOXM2_AUX0>::datatype aux0_datatype; 15 typedef boxm2_data_traits<BOXM2_AUX1>::datatype aux1_datatype; 16 typedef boxm2_data_traits<BOXM2_AUX2>::datatype aux2_datatype; 17 18 //: "default" constructor 19 boxm2_compute_ambient_functor() = default; 20 init_data(boxm2_data_base * sunvis,boxm2_stream_cache_sptr str_cache,float & sunvis_weights,float & weighted_sunvis_intensities,float block_len,int max_levels)21 bool init_data(boxm2_data_base *sunvis, 22 boxm2_stream_cache_sptr str_cache, 23 float & sunvis_weights, 24 float & weighted_sunvis_intensities, 25 float block_len, int max_levels) 26 { 27 sunvis_data_=new boxm2_data<BOXM2_AUX0>(sunvis->data_buffer(),sunvis->buffer_length(),sunvis->block_id()); 28 str_cache_ = str_cache; 29 id_ = sunvis_data_->block_id(); 30 sunvis_weights_=&sunvis_weights; 31 weighted_sunvis_intensities_=&weighted_sunvis_intensities; 32 33 return true; 34 } 35 process_cell(int index)36 inline bool process_cell(int index) 37 { 38 boxm2_data<BOXM2_ALPHA>::datatype & sunvis=sunvis_data_->data()[index]; 39 40 std::vector<aux0_datatype> out0 = str_cache_->get_next<BOXM2_AUX0>(id_, index); 41 std::vector<aux1_datatype> out1 = str_cache_->get_next<BOXM2_AUX1>(id_, index); 42 std::vector<aux1_datatype> out2 = str_cache_->get_next<BOXM2_AUX2>(id_, index); 43 44 std::vector<aux0_datatype> obs; std::vector<float> vis; 45 46 float sumobs=0.0f; 47 float weight=0.0f; 48 unsigned nimgs = (unsigned)out0.size(); 49 for (unsigned m = 0; m < nimgs; m++) { 50 if(out0[m]>1e-10f) 51 { 52 float mean_obs = out1[m]/out0[m]; 53 float vis_i = out2[m]/out0[m]; // mean vis 54 sumobs+=vis_i*mean_obs; 55 weight+=vis_i; 56 } 57 } 58 if(weight>1e-10f) 59 { 60 if(sunvis<0.05) 61 { 62 (*sunvis_weights_)+=(1-sunvis); 63 (*weighted_sunvis_intensities_)+=(1-sunvis)*(sumobs/weight); 64 } 65 } 66 return true; 67 } 68 69 private: 70 boxm2_data<BOXM2_AUX0>* sunvis_data_; 71 boxm2_stream_cache_sptr str_cache_; 72 boxm2_block_id id_; 73 float * sunvis_weights_; 74 float * weighted_sunvis_intensities_; 75 }; 76 77 78 79 #endif // boxm2_shadow_model_functor_h_ 80