node_handle.h
Go to the documentation of this file.
00001 #ifndef MEGATREE_NODE_HANDLE_H
00002 #define MEGATREE_NODE_HANDLE_H
00003 
00004 #include <megatree/node.h>
00005 #include <megatree/node_file.h>
00006 
00007 
00008 namespace megatree
00009 {
00010 
00011 
00012 class NodeHandle
00013 {
00014 public:
00015   NodeHandle()
00016     : node(NULL), node_file(NULL), modified(false), new_family(false)
00017   {}
00018 
00019   ~NodeHandle()
00020   {
00021     if (node)
00022       fprintf(stderr, "NodeHandle destructed, even though it still has a node!\n");
00023   }
00024 
00025   void initialize(Node* node_p, const IdType& id_p, NodeFile* node_file_p, const NodeGeometry& node_geom_p)
00026   {
00027     new_family = false;
00028     modified = false;
00029     node = node_p;
00030     id = id_p;
00031     node_file = node_file_p;
00032     node_geom = node_geom_p;
00033   }
00034   
00035 
00036   bool isValid() const
00037   {
00038     // @TODO: is this checking too much??
00039     return (node_file != NULL && node_file->getNodeState() == LOADED && id.isValid());
00040   }
00041 
00042   bool hasNode() const
00043   {
00044     return node_file != NULL && node != NULL;
00045   }
00046 
00047   void invalidate()
00048   {
00049     node = NULL;
00050     node_file = NULL;
00051   }
00052 
00053   const IdType& getId() const
00054   {
00055     return id;
00056   }
00057 
00058   std::string toString() const;
00059 
00060   bool isModified() const
00061   {
00062     return modified;
00063   }
00064 
00065   bool isEmpty() const
00066   {
00067     return node->isEmpty();
00068   }
00069 
00070 
00071   Count getCount() const
00072   {
00073     return node->getCount();
00074   }
00075 
00076   bool isLeaf() const
00077   {
00078     return node->isLeaf();
00079   }
00080 
00081   bool hasChild(uint8_t i) const
00082   {
00083     return node->hasChild(i);
00084   }
00085 
00086   void setChild(uint8_t child) 
00087   {
00088     modified = true;
00089 
00090     node->setChild(child);
00091   }
00092 
00093   uint8_t getChildForNodePoint()
00094   {
00095     return node->getChildForNodePoint();
00096   }
00097 
00098 
00099   double* getPoint(double pnt[3]) const
00100   {
00101     return node->getPoint(node_geom, pnt);
00102   }
00103 
00104 
00105   double* getColor(double col[3]) const
00106   {
00107     return node->getColor(col);
00108   }
00109 
00110   float* getColor(float col[3]) const
00111   {
00112     return node->getColor(col);
00113   }
00114 
00115   void addPoint(const double* pt, const double* col)
00116   {
00117     modified = true;
00118     node->addPoint(node_geom, pt, col);
00119   }
00120 
00121 
00122   void setPoint(const double* pt, const double* col, Count cnt=1)
00123   {
00124     modified = true;
00125     node->setPoint(node_geom, pt, col, cnt);
00126   }
00127 
00128 
00129   bool operator==(const NodeHandle& nh) const
00130   {
00131     return *node == *(nh.node);
00132   }
00133 
00134   Node* getNode()
00135   {
00136     return node;
00137   }
00138 
00139   NodeFile* getNodeFile() const
00140   {
00141     return node_file;
00142   }
00143 
00144   const NodeGeometry& getNodeGeometry() const
00145   {
00146     return node_geom;
00147   }
00148 
00149   void copyFromChildNodes(NodeHandle children[8])
00150   {
00151     modified = true;
00152 
00153     Node* node_children[8];
00154     for (unsigned i=0; i<8; i++)
00155       if (children[i].isValid())
00156         node_children[i] = children[i].getNode();
00157       else
00158         node_children[i] = NULL;
00159             
00160 
00161     node->copyFromChildNodes(node_children);
00162   }
00163 
00164   bool isNewFamily()
00165   {
00166     return new_family;
00167   }
00168 
00169   void waitUntilLoaded()
00170   {
00171     assert(node_file);
00172     node_file->waitUntilLoaded();
00173   }
00174 
00175   friend class NodeCache;
00176 
00177   
00178 private:
00179   Node* node;
00180   NodeGeometry node_geom;
00181   IdType id;
00182   NodeFile* node_file;
00183   bool modified, new_family;
00184 
00185 };
00186 
00187 }
00188 
00189 #endif


megatree_cpp
Author(s): Stuart Glaser
autogenerated on Thu Nov 28 2013 11:30:34