00001
00002
00003 #ifndef tag_h_
00004 #define tag_h_
00005
00006 #include <cstdlib>
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <iostream>
00010 #include <iomanip.h>
00011 #include <assert.h>
00012 #include <tclcl.h>
00013 #include <trace.h>
00014 #include <rng.h>
00015
00016 #define NUM_RECTANGLES 10 // Divide into 10 rectangles at each level
00017 #define TRUE 1
00018 #define FALSE 0
00019
00020
00021
00022 class TagCache {
00023 public:
00024 int obj_name_;
00025 int origin_time_;
00026 double X_;
00027 double Y_;
00028 };
00029
00030
00031
00032
00033 class attribs {
00034 char *name;
00035 char *value;
00036 attribs *next_;
00037 };
00038
00039
00040
00041 class tag {
00042 public:
00043 tag() { next_ = NULL;}
00044 double x_;
00045 double y_;
00046 int obj_name_;
00047 attribs *attributes_;
00048 tag *next_;
00049 };
00050
00051
00052
00053 class dbase_node {
00054 public:
00055 dbase_node (double x_min, double x_max, double y_min, double y_max) {
00056 assert ((x_min <= x_max) && (y_min <= y_max));
00057 x_min_ = x_min;
00058 x_max_ = x_max;
00059 y_min_ = y_min;
00060 y_max_ = y_max;
00061 tags_list_ = NULL;
00062
00063 for(int i = 0; i < NUM_RECTANGLES; ++i) {
00064 list_node_[i] = NULL;
00065 }
00066
00067 };
00068
00069 double x_min_;
00070 double x_max_;
00071 double y_min_;
00072 double y_max_;
00073
00074
00075 dbase_node *list_node_[NUM_RECTANGLES];
00076
00077 tag *tags_list_;
00078 };
00079
00080
00081
00082 class compr_taglist {
00083 public:
00084 compr_taglist() { next_ = NULL;}
00085 int obj_name_;
00086 compr_taglist *next_;
00087 };
00088
00089
00090
00091 class tags_database : public TclObject {
00092 public:
00093 tags_database() : tags_db_(NULL) {
00094 num_tags_ = 0;
00095 num_sensed_tags_ = 0;
00096 sensed_tag_list_ = NULL;
00097 num_freq_qry_tags_= 0;
00098 freq_qry_tag_list_ = NULL;
00099 rn_ = new RNG;
00100 }
00101
00102 ~tags_database() {
00103
00104 delete[] sensed_tag_list_;
00105 }
00106
00107 virtual int command(int argc, const char * const * argv);
00108
00109 void create_tags_database(double x_min, double x_max, double y_min, double y_max, int num_tags);
00110 void Addtag(const tag *tag_);
00111 void Deletetag(const tag *tag_);
00112 compr_taglist *Gettags(double x, double y, double r);
00113
00114 Trace *tracetarget_;
00115 void trace(char *fmt,...);
00116 int get_random_tag();
00117
00118 protected:
00119 dbase_node *tags_db_;
00120 int num_tags_;
00121 int num_sensed_tags_;
00122 int *sensed_tag_list_;
00123
00124 int num_freq_qry_tags_;
00125 int *freq_qry_tag_list_;
00126
00127 RNG *rn_;
00128 compr_taglist *vtags_;
00129 void add_level(double x_min, double x_max, double y_min, double y_max, dbase_node *dbnode);
00130 void search_tags_dbase(double x, double y, double r, dbase_node *dbnode);
00131 };
00132
00133
00134
00135 #endif
00136
00137
00138