1 #ifndef bstm_block_metadata_h_
2 #define bstm_block_metadata_h_
3 //:
4 // \file
5 // \brief  bstm_block_metadata data keeps track of non structure, non visual data
6 //
7 //  Block meta data includes:
8 //    id,
9 //    block origin
10 //    num_sub_blocks (x,y,z,t)
11 //    sub_block_dim (x,y,z,t)
12 //    init_level, init_level_t
13 //    max_level, max_level_t
14 //    max_mb
15 //
16 // \author Ali Osman Ulusoy
17 // \date   03 Aug 2012
18 //
19 #include <iostream>
20 #include <iosfwd>
21 #include <utility>
22 #include <bstm/basic/bstm_block_id.h>
23 #include <vgl/vgl_point_3d.h>
24 #include <vgl/vgl_box_3d.h>
25 #include <vgl/vgl_vector_3d.h>
26 #ifdef _MSC_VER
27 #  include <vcl_msvc_warnings.h>
28 #endif
29 
30 #include <vbl/vbl_ref_count.h>
31 #include <vbl/vbl_smart_ptr.h>
32 
33 #include <vsl/vsl_basic_xml_element.h>
34 
35 #include <boxm2/boxm2_block_metadata.h>
36 class bstm_block_metadata:  public vbl_ref_count
37 {
38  public:
39   bstm_block_metadata() = default;
40   bstm_block_metadata(  bstm_block_id id,
41                         vgl_point_3d<double> local_origin,
42                         float local_t,
43                         vgl_vector_3d<double> sub_block_dim,
44                         double sub_block_dim_t,
45                         vgl_vector_3d<unsigned> sub_block_num,
46                         unsigned num_t,
47                         int init_level,
48                         int max_level,
49                         double max_mb,
50                         double p_init,
51                         int version = 1,
52                         int init_level_t=1,
53                         int max_level_t=6)
id_(id)54   :  id_(id),
55      local_origin_(local_origin),
56      local_origin_t_(local_t),
57      sub_block_dim_t_(sub_block_dim_t),
58      sub_block_num_t_(num_t),
59      sub_block_dim_(sub_block_dim),
60      sub_block_num_(sub_block_num),
61      init_level_(init_level),
62      max_level_(max_level),
63      init_level_t_(init_level_t),
64      max_level_t_(max_level_t),
65      max_mb_(max_mb),
66      p_init_(p_init),
67      version_(version) {}
68 
bstm_block_metadata(const bstm_block_metadata & that)69   bstm_block_metadata( const bstm_block_metadata& that)
70   : vbl_ref_count ()
71   , id_           (that.id_)
72   , local_origin_ (that.local_origin_)
73   , local_origin_t_ (that.local_origin_t_)
74   , sub_block_dim_t_(that.sub_block_dim_t_)
75   , sub_block_num_t_(that.sub_block_num_t_)
76   , sub_block_dim_(that.sub_block_dim_)
77   , sub_block_num_(that.sub_block_num_)
78   , init_level_   (that.init_level_)
79   , max_level_    (that.max_level_)
80   , init_level_t_ (that.init_level_t_)
81   , max_level_t_  (that.max_level_t_)
82   , max_mb_       (that.max_mb_)
83   , p_init_       (that.p_init_)
84   , version_      (that.version_)
85   {}
86 
87   //: id and local origin of the block
88   bstm_block_id          id_;
89   vgl_point_3d<double>    local_origin_;
90 
91   //: origin of time axis
92   double   local_origin_t_;
93 
94   //: dimension of time axis, e.g., 1s
95   double   sub_block_dim_t_;
96 
97   //: number of sub-blocks time dimension
98   unsigned   sub_block_num_t_;
99 
100   //: World dimensions of a sub block .e.g 1 meter x 1 meter x 1 meter
101   vgl_vector_3d<double>   sub_block_dim_;
102 
103   //: number of sub blocks in each dimension
104   vgl_vector_3d<unsigned> sub_block_num_;
105 
106   //: info about block's trees
107   int                     init_level_;    //each sub_blocks's init level (default 1)
108   int                     max_level_;     //each sub_blocks's max_level (default 4)
109   int                     init_level_t_;  //time tree's initial level(default 1)
110   int                     max_level_t_;   //time tree's maximum level(default 6)
111 
112   double                  max_mb_;       //each total block mb
113   double                  p_init_;       //initialize occupancy probs with this
114   int                     version_;
115 
116   //: checks if this block contains the given t, if yes, returns local_time
117   bool                    contains_t  (double const t, double& local_time) const;
118 
id()119   bstm_block_id id() const { return id_; }
120   //: bounding box for this block
121   vgl_box_3d<double>      bbox() const;
bbox_t(double & min_t,double & max_t)122   void   bbox_t(double& min_t, double& max_t) const {min_t = local_origin_t_; max_t = local_origin_t_ + sub_block_num_t_*sub_block_dim_t_; };
bbox_t()123   std::pair<double, double> bbox_t() const { std::pair<double,double> p; bbox_t(p.first, p.second); return p; }
resolution()124   std::pair<vgl_vector_3d<double>,double> resolution() const {
125     return std::pair<vgl_vector_3d<double>,double>(sub_block_dim_ / 8.0, sub_block_dim_t_ / 32.0);
126   }
127 
128   bool operator==(bstm_block_metadata const& m) const;
129   bool operator==(boxm2_block_metadata const& m) const;
130 
131   //: Writes this block's metadata to an XML element which can later
132   //be written to a file, e.g. as part of a scene.
133   void to_xml(vsl_basic_xml_element& block) const;
134   static bstm_block_metadata from_xml(const char **atts);
135 };
136 
137 //: Smart_Pointer typedef for bstm_block
138 typedef vbl_smart_ptr<bstm_block_metadata> bstm_block_metadata_sptr;
139 
140 std::ostream &operator<<(std::ostream &s, const bstm_block_metadata &metadata);
141 
142 //: Binary write boxm_update_bit_scene_manager scene to stream
143 void vsl_b_write(vsl_b_ostream& os, bstm_block_metadata const& scene);
144 void vsl_b_write(vsl_b_ostream& os, const bstm_block_metadata* &p);
145 void vsl_b_write(vsl_b_ostream& os, bstm_block_metadata_sptr& sptr);
146 void vsl_b_write(vsl_b_ostream& os, bstm_block_metadata_sptr const& sptr);
147 
148 //: Binary load boxm_update_bit_scene_manager scene from stream.
149 void vsl_b_read(vsl_b_istream& is, bstm_block_metadata &scene);
150 void vsl_b_read(vsl_b_istream& is, bstm_block_metadata* p);
151 void vsl_b_read(vsl_b_istream& is, bstm_block_metadata_sptr& sptr);
152 void vsl_b_read(vsl_b_istream& is, bstm_block_metadata_sptr const& sptr);
153 
154 #endif
155