1 #ifndef boxm2_vecf_shuttle_scene_h_
2 #define boxm2_vecf_shuttle_scene_h_
3 //:
4 // \file
5 // \brief  A model of the space shuttle for testing particle filtering
6 //
7 // \author J.L. Mundy
8 // \date   16 Jan 2016
9 //
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 #include <boxm2/boxm2_block.h>
14 #include <boxm2/boxm2_scene.h>
15 #include <boxm2/boxm2_data.h>
16 #ifdef _MSC_VER
17 #  include <vcl_msvc_warnings.h>
18 #endif
19 #include <vil/vil_image_view.h>
20 #include <vpgl/vpgl_camera_double_sptr.h>
21 class boxm2_vecf_particle{
22  public:
boxm2_vecf_particle()23  boxm2_vecf_particle(): p_(0.0f), cam_(nullptr), tx_(0.0), ty_(0.0), s_(0.0),
24     rx_(0.0),ry_(0.0),rz_(0.0){}
boxm2_vecf_particle(float p,vpgl_camera_double_sptr const & cam)25  boxm2_vecf_particle(float p, vpgl_camera_double_sptr const& cam): p_(p), cam_(cam),
26     tx_(0.0), ty_(0.0), s_(0.0), rx_(0.0),ry_(0.0),rz_(0.0){}
27   bool operator () (boxm2_vecf_particle const& p0, boxm2_vecf_particle const& p1);
print()28   void print() { std::cout << "(" << tx_ << ' ' << ty_ << ' ' << s_ << ' ' << rx_ << ' ' << ry_ << ' ' << rz_ << " p: " << p_ << std::endl;}
print_txty()29   void print_txty() { std::cout << '{' << tx_ << ',' << ty_ << ',' << p_ << '}'<< std::endl;}
print_txs()30   void print_txs() { std::cout << '{' << tx_ << ',' << s_ << ',' << p_ << '}'<< std::endl;}
print_txry()31   void print_txry() { std::cout << '{' << tx_ << ',' << ry_ << ',' << p_ << '}'<< std::endl;}
print_txrz()32   void print_txrz() { std::cout << '{' << tx_ << ',' << rz_ << ',' << p_ << '}'<< std::endl;}
33   float p_;
34   vpgl_camera_double_sptr cam_;
35   double tx_;
36   double ty_;
37   double s_;
38   double rx_;
39   double ry_;
40   double rz_;
41 };
42 
43 class boxm2_vecf_shuttle_scene : public boxm2_scene
44 {
45  public:
boxm2_vecf_shuttle_scene()46  boxm2_vecf_shuttle_scene(): alpha_data_(nullptr), app_data_(nullptr), nobs_data_(nullptr){}
47 
48   boxm2_vecf_shuttle_scene(std::string const& scene_file, std::string const& imesh_file);
49 
50   boxm2_vecf_shuttle_scene(std::string const& scene_file);
51 
scene()52   boxm2_scene_sptr scene(){ return base_model_;}
53 
54   vil_image_view<float> silhouette(vpgl_camera_double_sptr const& cam, unsigned ni, unsigned nj) const;
55   void generate_particles(const vpgl_camera_double_sptr& cam, double txmin, double txmax, double dtx);
56   void generate_particles_txy(const vpgl_camera_double_sptr& cam,
57                           double txmin, double txmax, double dtx,
58                           double tymin, double tymax, double dty);
59   void generate_particles_txs(vpgl_camera_double_sptr cam,
60                           double txmin, double txmax, double dtx,
61                           double smin, double smax, double ds);
62   void generate_particles_txry(const vpgl_camera_double_sptr& cam,
63                                double txmin, double txmax, double dtx,
64                                double rymin, double rymax, double dry);
65   void generate_particles_txrz(const vpgl_camera_double_sptr& cam,
66                                double txmin, double txmax, double dtx,
67                                double rzmin, double rzmax, double drz);
68   void evaluate_particles(vil_image_view<vxl_byte> const& observed_img, vgl_box_2d<int> const& bkg_box);
69   void save_silhouettes(std::string const& base_dir);
70   void save_cameras(std::string const& base_dir);
71  private:
72   boxm2_scene_sptr base_model_;
73   //:scan spherical shell
74   //: set up pointers to source block databases
75   void extract_block_data();
76   boxm2_block* blk_;                     // the source block
77   boxm2_block* target_blk_;              // the target block
78   boxm2_data<BOXM2_ALPHA>* alpha_data_;  // source alpha database
79   boxm2_data<BOXM2_MOG3_GREY>* app_data_;// source appearance database
80   boxm2_data<BOXM2_NUM_OBS>* nobs_data_; // source nobs database
81   std::vector<boxm2_vecf_particle> particles_;
82   std::vector<vil_image_view<float> > silhouettes_;
83   double bk_var_;
84   double bk_mean_;
85   double total_var_;
86   double total_mean_;
87   double log_p_uniform_;
88 };
89 #endif // boxm2_vecf_shuttle_scene_h_
90