1 #ifndef boxm2_vecf_ocl_filter_h
2 #define boxm2_vecf_ocl_filter_h
3 //:
4 // \file
5 // \brief A function to filter a block using the six neigborhood
6 // \author J.L. Mundy
7 // \date October 25, 2014
8 //
9 #include <iostream>
10 #include <vector>
11 #include <vbl/vbl_ref_count.h>
12 #ifdef _MSC_VER
13 #  include <vcl_msvc_warnings.h>
14 #endif
15 #include <boxm2/io/boxm2_cache.h>
16 #include <bocl/bocl_mem.h>
17 #include <bocl/bocl_device.h>
18 #include <boxm2/ocl/boxm2_opencl_cache.h>
19 
20 //: Map a scene with Euclidean and anisotropic scale transforms.
21 // the input transform is the inverse so that the target scene voxels
22 // are mapped backwards to extract the data from the source
23 // thus each target voxel is defined if the inverse transform lands on a
24 // valid source voxel.
25 class boxm2_vecf_ocl_filter
26 {
27  public:
28   //: Constructor.
29   boxm2_vecf_ocl_filter(boxm2_scene_sptr& source_scene,
30                                  boxm2_scene_sptr& temp_scene,
31                                  const boxm2_opencl_cache_sptr& ocl_cache);
32 
33   ~boxm2_vecf_ocl_filter();
34 
35 
36   //: transform a scene of arbitrary size, block by block
37   // no interpolation
38   bool filter(std::vector<float> const& weights, unsigned num_iterations = 1);
39 
40  protected:
41   bool compile_filter_kernel();
42   bool init_ocl_filter();
43   bool get_scene_appearance(const boxm2_scene_sptr& scene,
44                             std::string&      options);
45 
46   boxm2_opencl_cache_sptr  opencl_cache_;
47   boxm2_scene_sptr temp_scene_;
48   boxm2_scene_sptr source_scene_;
49   bocl_device_sptr device_;
50   int apptypesize_;//size of the appearance model in bytes
51   std::string app_type_; //type of appearance
52 
53   //filter kernel and args
54   bocl_kernel * filter_kern;
55   bocl_mem_sptr centerX;
56   bocl_mem_sptr centerY;
57   bocl_mem_sptr centerZ;
58   bocl_mem_sptr lookup;
59   bocl_mem_sptr output;
60 
61   bocl_mem* ocl_depth;
62   bocl_mem* ocl_n_iter;
63   bocl_mem* blk_info_temp;
64   bocl_mem* blk_info_source;
65   boxm2_scene_info* info_buffer;
66   bocl_mem* blk_temp;
67   bocl_mem* alpha_temp;
68   bocl_mem * mog_temp;
69   boxm2_scene_info* info_buffer_source;
70   bocl_mem* blk_source;
71   bocl_mem* alpha_source;
72   bocl_mem* mog_source;
73   bocl_mem* filter_weights;
74   cl_command_queue queue;
75 };
76 
77 #endif
78