1 #ifndef bstm_ingest_boxm2_scene_function_h_ 2 #define bstm_ingest_boxm2_scene_function_h_ 3 //: 4 // \file 5 6 #include <iostream> 7 #include <map> 8 #include <bstm/bstm_time_block.h> 9 #include <bstm/bstm_block.h> 10 #include <bstm/bstm_scene.h> 11 #include <bstm/bstm_data_traits.h> 12 #include <boct/boct_bit_tree.h> 13 #include <boxm2/basic/boxm2_array_3d.h> 14 #include <vnl/vnl_vector_fixed.h> 15 #ifdef _MSC_VER 16 # include <vcl_msvc_warnings.h> 17 #endif 18 #include <bstm/io/bstm_cache.h> 19 20 #include <boxm2/boxm2_scene.h> 21 #include <boxm2/io/boxm2_cache.h> 22 23 #include <bstm/cpp/algo/bstm_data_similarity_traits.h> 24 25 26 template <bstm_data_type APM_TYPE, boxm2_data_type BOXM2_APM_TYPE> 27 class bstm_ingest_boxm2_scene_function 28 { 29 public: 30 31 typedef unsigned char uchar; 32 typedef unsigned short ushort; 33 typedef vnl_vector_fixed<uchar, 16> uchar16; 34 typedef vnl_vector_fixed<uchar, 8> uchar8; 35 typedef vnl_vector_fixed<ushort, 4> ushort4; 36 37 //: "default" constructor does all the work 38 bstm_ingest_boxm2_scene_function(bstm_block* blk,bstm_time_block* blk_t, std::map<std::string, bstm_data_base*> & datas, 39 boxm2_block* boxm2_blk, std::map<std::string, boxm2_data_base*> & boxm2_datas, double local_time, double p_threshold, double app_threshold); 40 41 private: 42 43 //: initialize generic data base pointers as their data type 44 bool init_data(bstm_block* blk,bstm_time_block* blk_t, std::map<std::string, bstm_data_base*> & datas, 45 boxm2_block* boxm2_blk, std::map<std::string, boxm2_data_base*> & boxm2_datas, double time); 46 47 //main functions 48 bool ingest(); //inserts the boxm2 data into bstm blk 49 bool conform(); //make sure bstm blk conforms to the tree structure of boxm2 blk 50 51 //helpers 52 53 //: makes sure all the leaves of curr_tree is at least as deep as boxm2_curr_tree 54 boct_bit_tree conform_tree(boct_bit_tree curr_tree, boct_bit_tree boxm2_curr_tree); 55 56 //: moves the time trees of new refined bstm blk 57 int move_time_trees(boct_bit_tree& unrefined_tree, boct_bit_tree& refined_tree, bstm_time_block* newTimeBlk,char* depth_diff ); 58 59 //: refines all the time trees of a given cell, based on the boxm2 data input. 60 bool refine_all_time_trees(int bstm_data_offset,int boxm2_data_offset, int* dataIndex, int& currIndex, int& dataSize, 61 int currDepth, int currDepth_boxm2, bool is_leaf); 62 63 //: moves the data of all time trees of a given cell. Copies data from parents and places the boxm2 data to current time cell. 64 int move_all_time_trees_data( boxm2_array_1d<uchar8>& time_trees_blk_copy, 65 int bstm_data_offset,int boxm2_data_offset, int* dataIndex, int& currIndex, 66 bstm_data_traits<BSTM_ALPHA>::datatype* alpha_cpy, 67 typename bstm_data_traits<APM_TYPE>::datatype * apm_cpy, int depth_diff); 68 69 //: moves the data from the old time tree to the new time tree 70 int move_data(bstm_time_tree& unrefined_tree, bstm_time_tree& refined_tree, bstm_data_traits<BSTM_ALPHA>::datatype* alpha_cpy, typename bstm_data_traits<APM_TYPE>::datatype * apm_cpy); 71 72 //: inserts the current boxm2 data into the bstm scene 73 void place_curr_data( bstm_time_tree& refined_tree, int boxm2_data_offset, bstm_data_traits<BSTM_ALPHA>::datatype* alpha_cpy, typename bstm_data_traits<APM_TYPE>::datatype * apm_cpy, int depth_diff ); 74 75 //: refine input tree and return refined tree 76 bstm_time_tree refine_time_tree(const bstm_time_tree& input_tree, int bstm_data_offset, int boxm2_data_offset, int currDepth, int currDepth_boxm2); 77 78 //: function to define similarity measure between bstm data and current boxm2 data. 79 bool is_similar(float p, typename bstm_data_traits<APM_TYPE>::datatype mog, float boxm2_p, typename boxm2_data_traits<BOXM2_APM_TYPE>::datatype boxm2_mog); 80 81 bstm_block* blk_; 82 bstm_time_block* blk_t_; 83 boxm2_block* boxm2_blk_; 84 85 //bstm datas 86 bstm_data_traits<BSTM_ALPHA>::datatype * alpha_; 87 typename bstm_data_traits<APM_TYPE>::datatype* apm_model_; 88 bstm_data_traits<BSTM_CHANGE>::datatype * change_array_; 89 90 //boxm2 datas 91 boxm2_data_traits<BOXM2_ALPHA>::datatype * boxm2_alpha_; 92 typename boxm2_data_traits<BOXM2_APM_TYPE>::datatype* boxm2_apm_model_; 93 94 double local_time_; 95 96 unsigned sub_block_num_t_; 97 98 //block max level 99 int max_level_t_; 100 int max_level_; 101 int MAX_INNER_CELLS_; 102 int MAX_INNER_CELLS_T_; 103 int MAX_CELLS_; 104 int MAX_CELLS_T_; 105 106 //length of one side of a sub block 107 double block_len_; 108 109 int num_split_; 110 int num_split_t_; 111 112 double p_threshold_; 113 double app_threshold_; 114 }; 115 116 117 #endif // bstm_ingest_boxm2_scene_function_h_ 118