Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __NTREEHELPER_H_
00025 #define __NTREEHELPER_H_
00026
00027 #include <NodeHandle.h>
00028 #include <Vector2D.h>
00029
00030 class NTreeScope
00031 {
00032 public:
00033 NTreeScope();
00034 NTreeScope(const Vector2D& _origin, double _size);
00035 void resize(const Vector2D& _origin, double _size);
00036 bool contains(const Vector2D&) const;
00037 NTreeScope getSubScope( unsigned int quadrant ) const;
00038
00039 bool isValid() const { return size >= 0; }
00040 Vector2D origin;
00041 double size;
00042
00043 friend bool operator==(const NTreeScope& a, const NTreeScope& b);
00044 friend bool operator<(const NTreeScope& a, const NTreeScope& b);
00045 friend std::ostream& operator<<(std::ostream& Stream, const NTreeScope& scope);
00046 };
00047
00048
00049 class NTreeGroup
00050 {
00051 public:
00052 NodeHandle leader;
00053 std::set<NodeHandle> members;
00054 NTreeScope scope;
00055 bool dividePending;
00056
00057 bool isInScope(const Vector2D& p) const;
00058 NTreeGroup(const NTreeScope& _scope);
00059 NTreeGroup(const Vector2D& _origin, double _size);
00060
00061 friend bool operator==(const NTreeGroup& a, const NTreeGroup& b);
00062 friend bool operator<(const NTreeGroup& a, const NTreeGroup& b);
00063 friend std::ostream& operator<<(std::ostream& Stream, const NTreeGroup& group);
00064 };
00065
00066 class NTreeNode
00067 {
00068 public:
00069 NTreeScope scope;
00070 NodeHandle parent;
00071 NodeHandle children[4];
00072
00073 NTreeGroup* group;
00074
00075 unsigned int aggChildCount[4];
00076
00077 NodeHandle siblings[4];
00078 std::set<NodeHandle> childChildren[4];
00079 simtime_t lastPing;
00080 bool parentIsRoot;
00081
00082 bool isInScope(const Vector2D& p) const;
00083 const NodeHandle& getChildForPos( const Vector2D& pos ) const;
00084 NTreeNode(const NTreeScope& _scope);
00085 NTreeNode(const Vector2D& _origin, double _size);
00086
00087 friend bool operator==(const NTreeNode& a, const NTreeNode& b);
00088 friend bool operator<(const NTreeNode& a, const NTreeNode& b);
00089 friend std::ostream& operator<<(std::ostream& Stream, const NTreeNode& node);
00090 };
00091
00092 class NTreeGroupDivideContext
00093 {
00094 public:
00095 NodeHandle newChild[4];
00096 NTreeScope nodeScope;
00097 };
00098
00099 class NTreeGroupDivideContextPtr : public cPolymorphic
00100 {
00101 public:
00102 NTreeGroupDivideContext* ptr;
00103 };
00104
00105 class NTreePingContext : public cPolymorphic
00106 {
00107 public:
00108 NTreePingContext(const NTreeScope& _scope, unsigned int _quadrant);
00109 NTreeScope nodeScope;
00110 unsigned int quadrant;
00111 };
00112
00113 #endif