1 #ifndef boxm2_multi_pre_vis_inf_h_
2 #define boxm2_multi_pre_vis_inf_h_
3 //:
4 // \file
5 // \brief This class does the cumulative seg len and cumulative observation on the GPU.
6 
7 #include <boxm2_multi_cache.h>
8 #include <boxm2/boxm2_scene.h>
9 #include <boxm2/ocl/boxm2_opencl_cache1.h>
10 #include <vil/vil_image_view.h>
11 #include <vpgl/vpgl_camera_double_sptr.h>
12 #include <bocl/bocl_device.h>
13 #include <bocl/bocl_kernel.h>
14 #include <boxm2_multi/algo/boxm2_multi_update.h>
15 
16 //: boxm2_multi_cache - example realization of abstract cache class
17 class boxm2_multi_pre_vis_inf
18 {
19   public:
20 
21     //three separate sub procedures (three separate map reduce tasks)
22     //static float pre_vis_inf( boxm2_multi_cache&              cache,
23     //                          const vil_image_view<float>&    img,
24     //                          vpgl_camera_double_sptr         cam,
25     //                          std::map<bocl_device*, float*>&  vis_map,
26     //                          std::map<bocl_device*, float*>&  pre_map,
27     //                          float*                          norm_img,
28     //                          boxm2_multi_update_helper&      helper);
29     static float pre_vis_inf( boxm2_multi_cache&              cache,
30                               const vil_image_view<float>&    img,
31                               const vpgl_camera_double_sptr&         cam,
32                               float*                          norm_img,
33                               boxm2_multi_update_helper&      helper);
34 
35   private:
36 
37     //runs pre/vis on single block
38     static float pre_vis_per_block(const boxm2_block_id&     id,
39                                         const boxm2_scene_sptr&    scene,
40                                         boxm2_opencl_cache1* opencl_cache,
41                                         cl_command_queue&   queue,
42                                         const std::string&          data_type,
43                                         bocl_kernel*        kernel,
44                                         bocl_mem_sptr&      vis_image,
45                                         bocl_mem_sptr&      pre_image,
46                                         bocl_mem_sptr&      img_dim,
47                                         bocl_mem_sptr&      ray_o_buff,
48                                         bocl_mem_sptr&      ray_d_buff,
49                                         bocl_mem_sptr&      tnearfarptr,
50                                         bocl_mem_sptr&      cl_output,
51                                         bocl_mem_sptr&      lookup,
52                                         std::size_t*         lthreads,
53                                         std::size_t*         gThreads);
54 
55 #if 0
56     //reduction step (proc norm image)
57     static float pre_vis_reduce( boxm2_multi_cache&    cache,
58                                  std::vector<float*>&   pre_imgs,
59                                  std::vector<float*>&   vis_imgs,
60                                  std::vector<boxm2_opencl_cache1*>& ocl_caches,
61                                  std::map<bocl_device*, float*>& pre_map,
62                                  std::map<bocl_device*, float*>& vis_map,
63                                  int ni,
64                                  int nj,
65                                  float* norm_img   );
66 #endif
67 
68     //map keeps track of all kernels compiled and cached
69     static std::map<std::string, std::vector<bocl_kernel*> > kernels_;
70 
71     //compile kernels and cache
72     static std::vector<bocl_kernel*>& get_kernels(const bocl_device_sptr& device, const std::string& opts);
73 
74     //debug write imgs to disk method
75     static void write_imgs_out(std::map<bocl_device*, float*>& img_map, int ni, int nj,const std::string& name);
76 
77     template <class T>
clamp(T x,T a,T b)78     static inline T clamp(T x, T a, T b) { return x < a ? a : (x > b ? b : x); }
79 };
80 
81 #endif
82