NTreeHelper.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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         // On leafs, group points to the corresponding group. NULL else.
00073         NTreeGroup* group;
00074         // for computing when to collapse trees
00075         unsigned int aggChildCount[4];
00076         // for backup on node failure
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