00001 #ifndef brip_quadtree_h
00002 #define brip_quadtree_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <vcl_vector.h>
00024 #include <vbl/vbl_ref_count.h>
00025 #include <brip/brip_quadtree_node_base_sptr.h>
00026
00027
00028 class brip_quadtree_node_base : public vbl_ref_count
00029 {
00030 public:
00031 brip_quadtree_node_base()
00032 : iul_(0), jul_(0), ilr_(0), jlr_(0), valid_(false),
00033 children_(vcl_vector<brip_quadtree_node_base_sptr>(4)) {}
00034
00035 brip_quadtree_node_base(unsigned iul, unsigned jul,
00036 unsigned ilr, unsigned jlr, bool valid = false)
00037 : iul_(iul), jul_(jul), ilr_(ilr), jlr_(jlr), valid_(valid),
00038 children_(vcl_vector<brip_quadtree_node_base_sptr>(4)) {}
00039
00040 ~brip_quadtree_node_base() {}
00041
00042 bool data_valid() const { return valid_; }
00043
00044
00045 brip_quadtree_node_base_sptr child(unsigned i, unsigned j)
00046 { return children_[2*j+i]; }
00047
00048
00049 void set_child(unsigned i, unsigned j,
00050 brip_quadtree_node_base_sptr const& child)
00051 { children_[2*j+i] = child; }
00052
00053
00054 unsigned n_children() const
00055 { unsigned n=0; for (unsigned i=0; i<4; ++i) if (children_[i]) ++n; return n;}
00056
00057
00058 brip_quadtree_node_base_sptr parent() { return parent_; }
00059
00060
00061 void set_parent(brip_quadtree_node_base_sptr const& parent) {parent_=parent;}
00062
00063
00064 void region(unsigned& iul, unsigned& jul, unsigned& ilr, unsigned& jlr) const
00065 { iul = iul_; jul = jul_; ilr = ilr_; jlr = jlr_; }
00066
00067
00068 void set_region(unsigned iul, unsigned jul, unsigned ilr, unsigned jlr)
00069 { iul_ = iul; jul_ = jul; ilr_ = ilr; jlr_ = jlr;}
00070
00071 protected:
00072 unsigned iul_, jul_;
00073 unsigned ilr_, jlr_;
00074 bool valid_;
00075 brip_quadtree_node_base_sptr parent_;
00076 vcl_vector<brip_quadtree_node_base_sptr> children_;
00077 };
00078
00079
00080 template <class T>
00081 class brip_quadtree_node : public brip_quadtree_node_base
00082 {
00083
00084
00085 public:
00086
00087
00088 brip_quadtree_node()
00089 : data_(T(0)) {}
00090
00091 brip_quadtree_node(unsigned iul, unsigned jul, unsigned ilr, unsigned jlr)
00092 : brip_quadtree_node_base(iul, jul, ilr, jlr, false) {}
00093
00094 brip_quadtree_node(unsigned iul, unsigned jul, unsigned ilr,
00095 unsigned jlr, T data)
00096 : brip_quadtree_node_base(iul, jul, ilr, jlr, true),data_(data){}
00097
00098 ~brip_quadtree_node(){}
00099
00100
00101
00102 T data() const { return data_; }
00103
00104
00105
00106 protected:
00107 T data_;
00108 };
00109
00110 VCL_DEFINE_SPECIALIZATION
00111 class brip_quadtree_node<float> : public brip_quadtree_node_base
00112 {
00113 public:
00114
00115 brip_quadtree_node()
00116 : data_(float(0)) {}
00117
00118 brip_quadtree_node(unsigned iul, unsigned jul, unsigned ilr, unsigned jlr)
00119 : brip_quadtree_node_base(iul, jul, ilr, jlr, false) {}
00120
00121 brip_quadtree_node(unsigned iul, unsigned jul, unsigned ilr,
00122 unsigned jlr, float data)
00123 : brip_quadtree_node_base(iul, jul, ilr, jlr, true), data_(data) {}
00124
00125 ~brip_quadtree_node() {}
00126
00127
00128
00129 float data() const { return data_; }
00130
00131 protected:
00132 float data_;
00133 };
00134
00135 #endif // brip_quadtree_h