1 // This is brl/bseg/bvxm/bvxm_von_mises_tangent_processor.h
2 #ifndef bvxm_von_mises_tangent_processor_h_
3 #define bvxm_von_mises_tangent_processor_h_
4 //:
5 // \file
6 // \brief A class for a 3-d tangent vector process
7 //
8 // \author Joseph L. Mundy
9 // \date Aug. 8, 2009
10 // \verbatim
11 //  Modifications
12 //   <none>
13 // \endverbatim
14 
15 #include <vgl/vgl_plane_3d.h>
16 #include <vgl/vgl_infinite_line_3d.h>
17 #include <bvxm/grid/bvxm_voxel_slab.h>
18 #include <bsta/algo/bsta_adaptive_updater.h>
19 #include <bsta/bsta_distribution.h>
20 #include <bsta/bsta_gaussian_sphere.h>
21 #include <bsta/bsta_attributes.h>
22 #include <bsta/bsta_von_mises.h>
23 #include <vpgl/vpgl_proj_camera.h>
24 
25 //:
26 // uses the VonMises distribution on the sphere of unit vectors
27 // and a 3-d spherical gaussian distribution for sub-voxel vector origin
28 // within the voxel
29 // The update process can be accelerated by a factor k, where
30 // mu^N+1 = 1-(k/N+1)mu^N + s*k/(N+1), and mu is the current
31 // distribution mean (direction or position) and N+1 is the current
32 // number of observations. If k==1 the update corresponds to simple
33 // averaging. It is necessary to have N > k-1 in order for the mean
34 // weight to be positive.
35 template <class T>
36 class  bvxm_von_mises_tangent_processor
37 {
38  public:
39 
40   typedef bsta_vsum_num_obs<bsta_von_mises<T, 3> > dir_dist_t;
41   typedef bsta_num_obs<bsta_gaussian_sphere<T, 2> > pos_dist_t;
42   typedef typename bsta_von_mises<T, 3>::vector_type dir_t;
43   typedef typename bsta_gaussian_sphere<T, 2>::vector_type pos_t;
44   typedef T obs_math_t;
45 
bvxm_von_mises_tangent_processor()46   bvxm_von_mises_tangent_processor() :
47     theta_max_(static_cast<obs_math_t>(0.1)),
48     x0_radius_(static_cast<obs_math_t>(0.2)), k_(T(1)) {}
49 
bvxm_von_mises_tangent_processor(T theta_max,T x0_radius,T k)50   bvxm_von_mises_tangent_processor(T theta_max, T x0_radius, T k) :
51     theta_max_(theta_max), x0_radius_(x0_radius), k_(k) {}
52 
53   virtual ~bvxm_von_mises_tangent_processor() = default;
54 
55   bool update( bvxm_voxel_slab<dir_dist_t> & dir_dist,
56                bvxm_voxel_slab<pos_dist_t> & pos_dist,
57                bvxm_voxel_slab<dir_t> const& dir,
58                bvxm_voxel_slab<pos_t> const& pos,
59                bvxm_voxel_slab<bool> const& flag);
60 
61   //: A helpful utility function to map two 2-d image tangents to a 3-d line
62   static bool tangent_3d_from_2d(T img_a0, T img_b0, T img_c0,
63                                  vpgl_proj_camera<double> const& cam0,
64                                  T img_a1, T img_b1, T img_c1,
65                                  vpgl_proj_camera<double> const& cam1,
66                                  vgl_infinite_line_3d<T>& line_3d);
67 
68   static bool pos_dir_from_tangent_plane(vgl_plane_3d<T> const& plane,
69                                          pos_dist_t const& pos_dist,
70                                          dir_dist_t const& dir_dist,
71                                          vgl_infinite_line_3d<T>& line_3d);
72 
73   static bool pos_dir_from_image_tangent(T img_a, T img_b, T img_c,
74                                          vpgl_proj_camera<double> const& cam,
75                                          pos_dist_t const& pos_dist,
76                                          dir_dist_t const& dir_dist,
77                                          vgl_infinite_line_3d<T>& line_3d);
78 
79  private:
80   T theta_max_;
81   T x0_radius_;
82   T k_;
83 };
84 
85 #define BVXM_VON_MISES_TANGENT_PROCESSOR_INSTANTIATE(T) extern "please include bvxm/bvxm_von_mises_tangent_processor.txx first"
86 
87 #endif // bvxm_von_mises_tangent_processor_h_
88