tree.hh

Go to the documentation of this file.
1 
6 #ifndef aglowavTree_hh
7 #define aglowavTree_hh
8 
9 #ifdef __GUNG__
10  #pragma interface
11 #endif
12 
13 #include "basics/exceptions.hh"
14 #include "space/space.hh"
15 #include "bem/element.hh"
16 #include "cluster/tree.hh"
17 
18 namespace aglowav {
19 
20  // **************************************************** One2ManyTreeTraits **
21 
24  template<class o2mNode>
26  public:
27  static o2mNode* child(const o2mNode* nd, uint j) {return nd->child(j);}
28  };
29 
30  // ********************************************************** One2ManyTree **
31 
32  template<class o2mNode>
33  class One2ManyTree;
34 
35  template<class o2mNode>
36  inline std::ostream& operator<<(std::ostream& os,
37  const One2ManyTree<o2mNode>& t) {
38  return t.info(os);
39  }
40 
41  template<class o2mNode>
42  class One2ManyTree {
44  friend std::ostream& operator<< <>(std::ostream& os,
45  const One2ManyTree<o2mNode>& t);
46 
47  public:
50  typedef o2mNode Node;
51 
53  virtual ~One2ManyTree() {}
54 
56  virtual const o2mNode* root() const = 0;
58  virtual uint nleaf() const = 0;
59 
61  virtual std::ostream& info(std::ostream& os) const;
66  void sketch(std::ostream& os, const o2mNode* rt = 0, uint l = 0) const;
67  };
68 
69  // ********************************************************** BiTreeTraits **
70 
73  template<class Node>
74  class BiTreeTraits : public One2ManyTreeTraits<Node> {
75  public:
77  static Node* lft(const Node* nd) {return nd->lft();}
78  static Node*& lft(Node* nd) {return nd->lft();}
80  static Node* rght(const Node* nd) {return nd->rght();}
81  };
82 
83  // **************************************************************** BiTree **
84 
87  template<class biNode>
88  class BiTree : public One2ManyTree<biNode> {
89  public:
92 
94  virtual const biNode* root() const = 0;
95  };
96 
97  // ****************************************************** ClstBiTreeTraits **
98 
101  template<class BiClNode>
102  class ClstBiTreeTraits : public BiTreeTraits<BiClNode>,
103  public cluster::TreeTraits<BiClNode> {
104  public:
107 
109  static BiClNode* newNode(const concepts::Element<F>& elm,
110  const cluster::BBall<F>& ball, BiClNode* lft) {
111  return new BiClNode(elm, ball, lft);
112  }
114  static BiClNode* newNode(uint idx, BiClNode& lft, BiClNode& rght,
115  const concepts::Real3d& c,
116  concepts::Real r, uint nlf = 0) {
117  return new BiClNode(idx, lft, rght, c, r, nlf);
118  }
119  };
120 
121  // ************************************************************ BiClNode00 **
122 
123  template<class F>
124  class BiClNode00;
125 
126  template<class F>
127  inline std::ostream& operator<<(std::ostream& os, const BiClNode00<F>& nd) {
128  os << "aglowav::BiClNode00(idx = " << nd.index()
129  << ", nleaf = " << nd.nleaf();
130  return os << ", r = " << nd.radius() << ", c = " << nd.center() << ')';
131  }
132 
135  template<class F>
136  class BiClNode00 {
138  friend std::ostream& operator<< <> (std::ostream& os,
139  const BiClNode00<F>& nd);
140 
141  public:
143  typedef F CF;
144 
153  BiClNode00<F>* lft);
163  const concepts::Real3d& c, concepts::Real r, uint nleaf = 0);
164 
166  BiClNode00<F>* child(uint j) const;
168  BiClNode00<F>* lft() const {return lft_;}
169  BiClNode00<F>*& lft() {return lft_;}
171  BiClNode00<F>* rght() const {return (nlf_) ? ne_.rght : (BiClNode00<F>*)0;}
175  const concepts::Real3d& center() const {return c_;}
177  uint nleaf() const {return nlf_;}
179  concepts::Real radius() const {return r_;}
181  uint index() const {return idx_;}
182 
183  private:
185  union NE {
188  };
189 
193  NE ne_;
195  uint idx_;
197  uint nlf_;
202  };
203 
204  template<class F>
205  inline BiClNode00<F>* BiClNode00<F>::child(uint j) const {
206  return (!j) ? lft_ : (nlf_ && j == 1) ? ne_.rght : (BiClNode00<F>*)0;
207  }
208 
209  template<class F>
211  return (nlf_) ? (const bem::Constant3d001<F>*)0 : ne_.elm;
212  }
213 
214 } // namespace aglowav
215 
216 #endif // aglowavTree_hh
Binary tree.
Definition: tree.hh:88
An abstract class for an element of a space.
Definition: exceptions.hh:15
virtual const biNode * root() const =0
Root of the tree.
const concepts::Real3d & center() const
Cluster center.
Definition: tree.hh:175
virtual std::ostream & info(std::ostream &os) const
Information about the tree.
concepts::Real3d c_
Cluster center.
Definition: tree.hh:199
uint idx_
Node number.
Definition: tree.hh:195
uint nlf_
Number of leafs in the subtree of the node.
Definition: tree.hh:197
virtual uint nleaf() const =0
Number of leafs.
Traits for the binary tree algorithm.
Definition: tree.hh:74
Binary node for the cluster and Haar wavelet agglomeration algorithm.
Definition: tree.hh:124
BiClNode00(const concepts::Element< F > &elm, const cluster::BBall< F > &ball, BiClNode00< F > *lft)
Constructor 1 (for a list of leafs, next leaf = left child)
uint nleaf() const
Number of leafs in the subtree of the node.
Definition: tree.hh:177
concepts::Real radius() const
Cluster radius.
Definition: tree.hh:179
Interface class for a node in a cluster tree.
Definition: tree.hh:252
Node -> rght, leaf -> elm.
Definition: tree.hh:185
const bem::Constant3d001< F > * element() const
Element of the node.
Definition: tree.hh:210
BiClNode00< F > * rght
Definition: tree.hh:186
Traits for trees where the nodes have always a fixed number of leafs.
Definition: tree.hh:25
Constant space element with a level dependent key.
Definition: element.hh:335
BiTreeTraits< biNode > Traits
How a Node has to behave.
Definition: tree.hh:91
static Node *& lft(Node *nd)
Definition: tree.hh:78
Abstract class to compute a bounding ball of an element (the leafs of a cluster tree).
Definition: tree.hh:36
static Node * rght(const Node *nd)
Right node.
Definition: tree.hh:80
BiClNode00< F > * child(uint j) const
j-th child of the node
Definition: tree.hh:205
Node::CF F
Field of the node (Real or Cmplx)
Definition: tree.hh:255
BiClNode00< F > * lft() const
Left child of the node.
Definition: tree.hh:168
concepts::Real r_
Cluster radius.
Definition: tree.hh:201
BiClNode00< F > * lft_
Left child of the node.
Definition: tree.hh:191
static BiClNode * newNode(uint idx, BiClNode &lft, BiClNode &rght, const concepts::Real3d &c, concepts::Real r, uint nlf=0)
Constructor of a new node (no leaf)
Definition: tree.hh:114
Traits for the binary cluster tree algorithm.
Definition: tree.hh:103
virtual const o2mNode * root() const =0
Root of the tree.
cluster::TreeTraits< BiClNode >::F F
Type of element (Real || Cmplx)
Definition: tree.hh:106
std::ostream & operator<<(std::ostream &os, const One2ManyTree< o2mNode > &t)
Definition: tree.hh:36
static BiClNode * newNode(const concepts::Element< F > &elm, const cluster::BBall< F > &ball, BiClNode *lft)
Constructor of a new leaf list (next leaf = left child)
Definition: tree.hh:109
NE ne_
Right child or element of the node.
Definition: tree.hh:193
void sketch(std::ostream &os, const o2mNode *rt=0, uint l=0) const
Sketches the structure of the tree.
F CF
Type of element (Real || Cmplx)
Definition: tree.hh:143
BiClNode00< F > * rght() const
Right child of the node.
Definition: tree.hh:171
One2ManyTreeTraits< o2mNode > Traits
How a Node has to behave.
Definition: tree.hh:49
virtual ~One2ManyTree()
Virtual destructor.
Definition: tree.hh:53
uint index() const
Cluster number.
Definition: tree.hh:181
const bem::Constant3d001< F > * elm
Definition: tree.hh:187
Used for the aglowav classes for the boundary element method.
Definition: element.hh:21
BiClNode00< F > *& lft()
Definition: tree.hh:169
static o2mNode * child(const o2mNode *nd, uint j)
Definition: tree.hh:27
BiClNode00(uint idx, BiClNode00< F > &lft, BiClNode00< F > &rght, const concepts::Real3d &c, concepts::Real r, uint nleaf=0)
Constructor 2 (new node, no leaf)
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
static Node * lft(const Node *nd)
Left node.
Definition: tree.hh:77
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich