1 #ifndef bvxm_world_params_h_
2 #define bvxm_world_params_h_
3 //:
4 // \file
5 // \brief
6 // \author Thomas Pollard
7 // \date January 12, 2008
8 //
9 // \verbatim
10 //  Modifications
11 //   Apr 18, 2008 Ozge C. Ozcanli - added the basis vectors to be used in transforming the local coordinate system of the world to actual 3D world
12 //                                  check the method voxel_index_to_xyz() in bvxm_voxel_world class for their use
13 //                                - also added a version number and updated binary load and save methods to read and write new parameters
14 //                                  since there was no version number previously, the parameters written previous to this update won't be readable
15 //                                  the version number will be 2 and one may switch to previous version temporarily and rebuilt to read the previous version and write back in version two
16 // \endverbatim
17 
18 #include <string>
19 #include <iostream>
20 #include <cmath>
21 #ifdef _MSC_VER
22 #  include <vcl_msvc_warnings.h>
23 #endif
24 #include <vbl/vbl_smart_ptr.h>
25 #include <vbl/vbl_ref_count.h>
26 #include <vgl/vgl_point_3d.h>
27 #include <vgl/vgl_vector_3d.h>
28 #include <vgl/vgl_box_3d.h>
29 
30 #include <vsl/vsl_binary_io.h>
31 #include <vgl/io/vgl_io_vector_3d.h>
32 #include <vgl/io/vgl_io_point_3d.h>
33 #include <vpgl/vpgl_lvcs.h>
34 #include <vpgl/vpgl_lvcs_sptr.h>
35 
36 class bvxm_world_params : public vbl_ref_count
37 {
38  public:
39 
40   bvxm_world_params();
41   ~bvxm_world_params() override;
42 
43   //enum appearance_model_type { apm_unknown, mog_grey, mog_rgb };
44 
45   void set_params(
46     const std::string& model_dir,
47     const vgl_point_3d<float>& corner,
48     const vgl_vector_3d<unsigned int>& num_voxels,
49     float voxel_length,
50     const vpgl_lvcs_sptr& lvcs = vpgl_lvcs_sptr(nullptr),
51     float min_ocp_prob = 0.001f,
52     float max_ocp_prob = 0.999f,
53     unsigned max_scale = 1,
54     vgl_vector_3d<float> basex = vgl_vector_3d<float>(1.0f,0.0f,0.0f),
55     vgl_vector_3d<float> basey = vgl_vector_3d<float>(0.0f,1.0f,0.0f),
56     vgl_vector_3d<float> basez = vgl_vector_3d<float>(0.0f,0.0f,1.0f));
57 
model_dir()58   inline std::string model_dir() const { return model_dir_; }
corner()59   inline vgl_point_3d<float> corner() const { return corner_; }
set_corner(vgl_point_3d<float> & new_c)60   inline void set_corner(vgl_point_3d<float>& new_c) { corner_ = new_c; }
61 
rpc_origin()62   inline vgl_point_3d<float> rpc_origin() const { return rpc_origin_; }
set_rpc_origin(vgl_point_3d<float> & new_rpc_origin)63   inline void set_rpc_origin(vgl_point_3d<float>& new_rpc_origin) {
64     vgl_point_3d<float> old_corner = corner();
65     vgl_point_3d<float> new_corner(
66       old_corner.x() + new_rpc_origin.x() - rpc_origin_.x(),
67       old_corner.y() + new_rpc_origin.y() - rpc_origin_.y(),
68       old_corner.z() + new_rpc_origin.z() - rpc_origin_.z());
69     set_corner(new_corner);
70     rpc_origin_ = new_rpc_origin;
71   }
72 
73   inline vgl_vector_3d<unsigned int> num_voxels(unsigned scale=0) {
74     vgl_vector_3d<unsigned int> num_voxels_scaled;
75     double divisor= 1.0 / double(1 << scale); // actually, inverse of divisor
76     num_voxels_scaled.set((unsigned int)(num_voxels_.x()*divisor),
77                           (unsigned int)(num_voxels_.y()*divisor),
78                           (unsigned int)(num_voxels_.z()*divisor));
79     return num_voxels_scaled;
80   }
81 
82   inline float voxel_length(unsigned scale=0) {
83     return float(1<<scale)*voxel_length_; }
84 
base_x()85   inline vgl_vector_3d<float> base_x() const { return base_x_; }
base_y()86   inline vgl_vector_3d<float> base_y() const { return base_y_; }
base_z()87   inline vgl_vector_3d<float> base_z() const { return base_z_; }
88 
set_base_x(vgl_vector_3d<float> & basex)89   inline void set_base_x(vgl_vector_3d<float>& basex) { base_x_ = basex; }
set_base_y(vgl_vector_3d<float> & basey)90   inline void set_base_y(vgl_vector_3d<float>& basey) { base_y_ = basey; }
set_base_z(vgl_vector_3d<float> & basez)91   inline void set_base_z(vgl_vector_3d<float>& basez) { base_z_ = basez; }
92 
set_model_dir(std::string model_dir)93   inline void set_model_dir(std::string model_dir) {model_dir_ = model_dir;}
94 
min_occupancy_prob()95   inline float min_occupancy_prob() const { return min_occupancy_prob_; }
max_occupancy_prob()96   inline float max_occupancy_prob() const { return max_occupancy_prob_; }
lvcs()97   inline vpgl_lvcs_sptr lvcs() { return lvcs_; }
98 
edges_n_normal()99   inline float edges_n_normal() const { return edges_n_normal_; }
increment_edges_n_normal(float increment)100   inline void increment_edges_n_normal(float increment) { edges_n_normal_ += increment; }
101 
max_scale()102   inline unsigned max_scale() const { return max_scale_; }
103   vgl_box_3d<double> world_box_local();
104 
105   vgl_point_3d<float> center();
106 
107   //: Serial I/O format version
version()108   virtual unsigned version() const { return 2; }
109 
110   //: Binary save parameters to stream.
111   void b_write(vsl_b_ostream & os) const;
112 
113   //: Binary load parameters from stream.
114   void b_read(vsl_b_istream & is);
115 
116   //: write as xml file to be passed to bvxm_create_world process
117   void write_xml(std::string const& filename, std::string const& lvcs_filename);
118 
119  protected:
120 
121   std::string model_dir_;
122   vgl_point_3d<float> corner_;
123   vgl_point_3d<float> rpc_origin_;
124   vgl_vector_3d<unsigned int> num_voxels_;
125   float voxel_length_;
126   vpgl_lvcs_sptr lvcs_;
127   float min_occupancy_prob_;
128   float max_occupancy_prob_;
129   float edges_n_normal_;
130 
131   vgl_vector_3d<float> base_x_;
132   vgl_vector_3d<float> base_y_;
133   vgl_vector_3d<float> base_z_;
134 
135   unsigned max_scale_;
136 
137  private:
138 
139   friend std::ostream&  operator << (std::ostream& os, bvxm_world_params const& params);
140   friend std::istream& operator >> (std::istream& is, bvxm_world_params &params);
141 };
142 
143 std::ostream&  operator << (std::ostream& os, bvxm_world_params const& params);
144 std::istream& operator >> (std::istream& is, bvxm_world_params &params);
145 
146 typedef vbl_smart_ptr<bvxm_world_params> bvxm_world_params_sptr;
147 
148 #endif // bvxm_world_params_h_
149