00001
00015 #ifndef __OCT_STRUCT_H__
00016 #define __OCT_STRUCT_H__
00017
00018 #include <global.h>
00019 #include <exception.h>
00020
00024 typedef int PartType;
00025
00030 const PartType OCT_PARTS = 1 << DIMENSIONS;
00031
00036 typedef Color NodeStatus;
00037
00042 const NodeStatus NO_OBJECT= 0;
00043
00048 const NodeStatus UNDEF_OBJ= (-MAX_COLOR - 2);
00049
00056 class OctStruct {
00057 public:
00058 struct Node;
00062 typedef Node* _octree;
00063
00069 void clear();
00070
00077 bool empty();
00078
00085 void flush();
00086
00094 Color getMaxColor();
00095
00100 size_t getNodeSize();
00101
00106 _octree& getTree();
00107
00111 void print();
00112
00122 void stat(Hight h, unsigned &sumNodes, unsigned &leafs,
00123 unsigned &innerNodes, unsigned &borderNodes, unsigned &normCells);
00124
00125 protected:
00129 struct Node {
00134 struct Node *parts;
00135
00142 NodeStatus flag;
00143 };
00144
00151 OctStruct() throw (NotEnoughMemoryException*);
00152
00161 _octree createLeafs() throw (NotEnoughMemoryException*);
00162
00170 _octree createOneLeaf() throw (NotEnoughMemoryException*);
00171
00176 bool exist(_octree tree);
00177
00178 #ifdef MARK_BORDER
00179
00185 Color getBorderColor(Node node);
00186 #endif
00187
00196 _octree getChild(_octree parent, PartType i);
00197
00204 Color getColor(Node node);
00205
00206 #ifdef MARK_BORDER
00207
00213 bool isBorderNode(Node node);
00214 #endif
00215
00221 bool isLeaf(Node node);
00222
00228 bool isNoObject(Node node);
00229
00235 bool isUndefObj(Node node);
00236
00242 void remove(_octree &subtree);
00243
00244 #ifdef MARK_BORDER
00245
00252 void setBorderColor(Node &node, Color color);
00253 #endif
00254
00262 void setColor(Node &node, Color color);
00263
00272 void setTree(_octree &tree) throw (NotEnoughMemoryException*);
00273
00277 unsigned countBorderNodes;
00278
00279 private:
00288 bool canCompact(Node node, Color &color);
00289
00295 void compact(Node &node);
00296
00302 void compact(Node &node, Color color);
00303
00309 void printTree(Node node);
00310
00317 void setLeaf(Node &node);
00318
00329 void stat(_octree tree, Hight h, unsigned &sumNodes, unsigned &leafs,
00330 unsigned &innerNodes, unsigned &normCells);
00331
00336 _octree root;
00337 };
00338
00339 #endif // ! __OCT_STRUCT_H__