Go to the documentation of this file.00001
00002
00003
00004 #ifndef aglowavTree_hh
00005 #define aglowavTree_hh
00006
00007 #ifdef __GUNG__
00008 #pragma interface
00009 #endif
00010
00011 #include "basics/exceptions.hh"
00012 #include "space/space.hh"
00013 #include "bem/element.hh"
00014 #include "cluster/tree.hh"
00015
00016 namespace aglowav {
00017
00018
00019
00022 template<class o2mNode>
00023 class One2ManyTreeTraits {
00024 public:
00025 static o2mNode* child(const o2mNode* nd, uint j) {return nd->child(j);}
00026 };
00027
00028
00029
00030 template<class o2mNode>
00031 class One2ManyTree;
00032
00033 template<class o2mNode>
00034 inline std::ostream& operator<<(std::ostream& os,
00035 const One2ManyTree<o2mNode>& t) {
00036 return t.info(os);
00037 }
00038
00039 template<class o2mNode>
00040 class One2ManyTree {
00042 friend std::ostream& operator<< <>(std::ostream& os,
00043 const One2ManyTree<o2mNode>& t);
00044
00045 public:
00047 typedef One2ManyTreeTraits<o2mNode> Traits;
00048 typedef o2mNode Node;
00049
00051 virtual ~One2ManyTree() {}
00052
00054 virtual const o2mNode* root() const = 0;
00056 virtual uint nleaf() const = 0;
00057
00059 virtual std::ostream& info(std::ostream& os) const;
00064 void sketch(std::ostream& os, const o2mNode* rt = 0, uint l = 0) const;
00065 };
00066
00067
00068
00071 template<class Node>
00072 class BiTreeTraits : public One2ManyTreeTraits<Node> {
00073 public:
00075 static Node* lft(const Node* nd) {return nd->lft();}
00076 static Node*& lft(Node* nd) {return nd->lft();}
00078 static Node* rght(const Node* nd) {return nd->rght();}
00079 };
00080
00081
00082
00085 template<class biNode>
00086 class BiTree : public One2ManyTree<biNode> {
00087 public:
00089 typedef BiTreeTraits<biNode> Traits;
00090
00092 virtual const biNode* root() const = 0;
00093 };
00094
00095
00096
00099 template<class BiClNode>
00100 class ClstBiTreeTraits : public BiTreeTraits<BiClNode>,
00101 public cluster::TreeTraits<BiClNode> {
00102 public:
00104 typedef typename cluster::TreeTraits<BiClNode>::F F;
00105
00107 static BiClNode* newNode(const concepts::Element<F>& elm,
00108 const cluster::BBall<F>& ball, BiClNode* lft) {
00109 return new BiClNode(elm, ball, lft);
00110 }
00112 static BiClNode* newNode(uint idx, BiClNode& lft, BiClNode& rght,
00113 const concepts::Real3d& c,
00114 concepts::Real r, uint nlf = 0) {
00115 return new BiClNode(idx, lft, rght, c, r, nlf);
00116 }
00117 };
00118
00119
00120
00121 template<class F>
00122 class BiClNode00;
00123
00124 template<class F>
00125 inline std::ostream& operator<<(std::ostream& os, const BiClNode00<F>& nd) {
00126 os << "aglowav::BiClNode00(idx = " << nd.index()
00127 << ", nleaf = " << nd.nleaf();
00128 return os << ", r = " << nd.radius() << ", c = " << nd.center() << ')';
00129 }
00130
00133 template<class F>
00134 class BiClNode00 {
00136 friend std::ostream& operator<< <> (std::ostream& os,
00137 const BiClNode00<F>& nd);
00138
00139 public:
00141 typedef F CF;
00142
00150 BiClNode00(const concepts::Element<F>& elm, const cluster::BBall<F>& ball,
00151 BiClNode00<F>* lft);
00160 BiClNode00(uint idx, BiClNode00<F>& lft, BiClNode00<F>& rght,
00161 const concepts::Real3d& c, concepts::Real r, uint nleaf = 0);
00162
00164 BiClNode00<F>* child(uint j) const;
00166 BiClNode00<F>* lft() const {return lft_;}
00167 BiClNode00<F>*& lft() {return lft_;}
00169 BiClNode00<F>* rght() const {return (nlf_) ? ne_.rght : (BiClNode00<F>*)0;}
00171 const bem::Constant3d001<F>* element() const;
00173 const concepts::Real3d& center() const {return c_;}
00175 uint nleaf() const {return nlf_;}
00177 concepts::Real radius() const {return r_;}
00179 uint index() const {return idx_;}
00180
00181 private:
00183 union NE {
00184 BiClNode00<F>* rght;
00185 const bem::Constant3d001<F>* elm;
00186 };
00187
00189 BiClNode00<F>* lft_;
00191 NE ne_;
00193 uint idx_;
00195 uint nlf_;
00197 concepts::Real3d c_;
00199 concepts::Real r_;
00200 };
00201
00202 template<class F>
00203 inline BiClNode00<F>* BiClNode00<F>::child(uint j) const {
00204 return (!j) ? lft_ : (nlf_ && j == 1) ? ne_.rght : (BiClNode00<F>*)0;
00205 }
00206
00207 template<class F>
00208 inline const bem::Constant3d001<F>* BiClNode00<F>::element() const {
00209 return (nlf_) ? (const bem::Constant3d001<F>*)0 : ne_.elm;
00210 }
00211
00212 }
00213
00214 #endif // aglowavTree_hh