MyOcTree.h
Go to the documentation of this file.
00001 #ifndef MYOCTREE_H
00002 #define MYOCTREE_H
00003 
00004 
00005 #include <iostream>
00006 #include "octomap/OccupancyOcTreeBase.h"
00007 //#include "octomap_server/MyOcTreeNode.h"
00008 
00009 namespace octomap {
00010 
00011   // node definition
00012   class MyOcTreeNode : public OcTreeNode {
00013   public:
00014 
00015     class Color {
00016     public:
00017     Color() : r(255), g(255), b(255) {}
00018     Color(unsigned char _r, unsigned char _g, unsigned char _b)
00019       : r(_r), g(_g), b(_b) {}
00020       inline bool operator== (const Color &other) const {
00021         return (r==other.r && g==other.g && b==other.b);
00022       }
00023       inline bool operator!= (const Color &other) const {
00024         return (r!=other.r || g!=other.g || b!=other.b);
00025       }
00026       unsigned char r, g, b;
00027     };
00028 
00029   public:
00030     MyOcTreeNode() : OcTreeNode() {sqrtRecipStd=1.0/pow(0.05,2); visCount=0;}
00031 
00032     MyOcTreeNode(const MyOcTreeNode& rhs) : OcTreeNode(rhs), color(rhs.color),sqrtRecipStd(rhs.sqrtRecipStd),curDist(rhs.curDist) {}
00033 
00034     bool operator==(const MyOcTreeNode& rhs) const{
00035       return (rhs.value == value && rhs.color == color&& rhs.sqrtRecipStd==sqrtRecipStd);
00036     }
00037 
00038     // children
00039     inline MyOcTreeNode* getChild(unsigned int i) {
00040       return static_cast<MyOcTreeNode*> (OcTreeNode::getChild(i));
00041     }
00042     inline const MyOcTreeNode* getChild(unsigned int i) const {
00043       return static_cast<const MyOcTreeNode*> (OcTreeNode::getChild(i));
00044     }
00045 
00046     bool createChild(unsigned int i) {
00047       if (children == NULL) allocChildren();
00048       children[i] = new MyOcTreeNode();
00049       return true;
00050     }
00051 
00052     bool pruneNode();
00053     void expandNode();
00054 
00055     inline Color getColor() const { return color; }
00056     inline void  setColor(Color c) {this->color = c; }
00057     inline void  setColor(unsigned char r, unsigned char g, unsigned char b) {
00058       this->color = Color(r,g,b);
00059     }
00060 
00061     Color& getColor() { return color; }
00062 
00063     // has any color been integrated? (pure white is very unlikely...)
00064     inline bool isColorSet() const {
00065       return ((color.r != 255) || (color.g != 255) || (color.b != 255));
00066     }
00067 
00068     void updateColorChildren();
00069     void updateSqrtRecipStdChildren();
00070 
00071     MyOcTreeNode::Color getAverageChildColor() const;
00072     double getMaxChildSqrtRecipStd() const;
00073     double getMeanChildSqrtRecipStd() const;
00074     // file I/O
00075     std::istream& readValue (std::istream &s);
00076     std::ostream& writeValue(std::ostream &s) const;
00077 
00078 
00079     //
00080     inline double getSqrtRecipStd() const { return sqrtRecipStd; }
00081     inline double setSqrtRecipStd(double sqrtRecipStd_) { this->sqrtRecipStd=sqrtRecipStd_; }
00082     inline double getCurDist() const { return curDist; }
00083     inline double setCurDist(double dist){ this->curDist=dist; }
00084     inline double getVisCount() const { return curDist; }
00085     inline double setVisCount(int visCount_){ this->visCount=visCount_; }
00086 
00087     void addSqrtRecipStd(const double& sqrtRecipStd_update);
00088 
00089 
00090     //
00091 
00092   protected:
00093     Color color;
00094     double sqrtRecipStd;
00095     float curDist;
00096     int visCount;
00097   };
00098 
00099 
00100   // tree definition
00101   class MyOcTree : public OccupancyOcTreeBase <MyOcTreeNode> {
00102 
00103   public:
00105     MyOcTree(double resolution) : OccupancyOcTreeBase<MyOcTreeNode>(resolution) {claming_visCount_thres=360;}
00106 
00109     MyOcTree* create() const {return new MyOcTree(resolution); }
00110 
00111     std::string getTreeType() const {return "ColorTree";}
00112 
00113     void setClampingVisCountThres(int max_visCount_){claming_visCount_thres=max_visCount_;}
00114 
00115 
00116     // set node color at given key or coordinate. Replaces previous color.
00117     MyOcTreeNode* setNodeColor(const OcTreeKey& key, const unsigned char& r,
00118                                  const unsigned char& g, const unsigned char& b);
00119 
00120     MyOcTreeNode* setNodeColor(const float& x, const float& y,
00121                                  const float& z, const unsigned char& r,
00122                                  const unsigned char& g, const unsigned char& b) {
00123       OcTreeKey key;
00124       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return NULL;
00125       return setNodeColor(key,r,g,b);
00126     }
00127     MyOcTreeNode* setNodeSqrtRecipStd(const OcTreeKey& key,const double &sqrtRecipStd_ );
00128 
00129     MyOcTreeNode* setNodeSqrtRecipStd(const float& x, const float& y,
00130                                  const float& z,const double &sqrtRecipStd_) {
00131       OcTreeKey key;
00132       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return NULL;
00133       return setNodeSqrtRecipStd(key,sqrtRecipStd_);
00134     }
00135     MyOcTreeNode* setNodeCurDist(const OcTreeKey& key,const double &dist  );
00136 
00137     MyOcTreeNode* setNodeCurDist(const float& x, const float& y,
00138                                  const float& z,const double &dist) {
00139       OcTreeKey key;
00140       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return NULL;
00141       return setNodeCurDist(key,dist);
00142     }
00143 
00144     double getNodeCurDist(const OcTreeKey& key);
00145 
00146     double getNodeCurDist(const float& x, const float& y,
00147                           const float& z){
00148         OcTreeKey key;
00149         if (!this->coordToKeyChecked(point3d(x,y,z), key)) return -1.0;
00150         return getNodeCurDist(key);
00151     }
00152     double getNodeSqrtRecipStdt(const OcTreeKey& key);
00153 
00154     double getNodeSqrtRecipStdt(const float& x, const float& y,
00155                           const float& z){
00156         OcTreeKey key;
00157         if (!this->coordToKeyChecked(point3d(x,y,z), key)) return -1.0;
00158         return getNodeSqrtRecipStdt(key);
00159     }
00160 
00161     int getNodeVisCount(const OcTreeKey& key);
00162 
00163     int getNodeVisCount(const float& x, const float& y,
00164                           const float& z){
00165         OcTreeKey key;
00166         if (!this->coordToKeyChecked(point3d(x,y,z), key)) return -1;
00167         return getNodeVisCount(key);
00168     }
00169 
00170     // integrate color measurement at given key or coordinate. Average with previous color
00171     MyOcTreeNode* averageNodeColor(const OcTreeKey& key, const unsigned char& r,
00172                                   const unsigned char& g, const unsigned char& b);
00173 
00174     MyOcTreeNode* averageNodeColor(const float& x, const float& y,
00175                                       const float& z, const unsigned char& r,
00176                                       const unsigned char& g, const unsigned char& b) {
00177       OcTreeKey key;
00178       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return NULL;
00179       return averageNodeColor(key,r,g,b);
00180     }
00181 
00182     // integrate color measurement at given key or coordinate. Average with previous color
00183     MyOcTreeNode* integrateNodeColor(const OcTreeKey& key, const unsigned char& r,
00184                                   const unsigned char& g, const unsigned char& b);
00185 
00186     MyOcTreeNode* integrateNodeColor(const float& x, const float& y,
00187                                       const float& z, const unsigned char& r,
00188                                       const unsigned char& g, const unsigned char& b) {
00189       OcTreeKey key;
00190       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return NULL;
00191       return integrateNodeColor(key,r,g,b);
00192     }
00193 
00194     // update inner nodes, sets color to average child color
00195     void updateInnerOccupancy();
00196 
00197     void updateNodeSqrtRecipStd(const OcTreeKey& key,const double &sqrtRecipStd_update );
00198     void updateNodeSqrtRecipStd(const float& x, const float& y,
00199                                  const float& z,const double &sqrtRecipStd_update) {
00200       OcTreeKey key;
00201       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return;
00202       updateNodeSqrtRecipStd(key,sqrtRecipStd_update);
00203     }
00204 
00205     void updateNodeVisCount(const OcTreeKey& key);
00206     void updateNodeVisCount(const float& x, const float& y,
00207                                  const float& z) {
00208       OcTreeKey key;
00209       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return;
00210       updateNodeVisCount(key);
00211     }
00212 
00213 
00214 
00215     inline double getModelNoiseStd(double dist){
00216         return 0.0012+0.0019*pow((dist-0.4),2);
00217     }
00218     inline double CalCurSqrtRecipStd(double dist){
00219         return 1/pow(getModelNoiseStd(dist),2);
00220     }
00221     void groundColorMix(double* color, double x, double min, double max);
00222     // uses gnuplot to plot a RGB histogram in EPS format
00223     void writeColorHistogram(std::string filename);
00224 
00225   protected:
00226     void updateInnerOccupancyRecurs(MyOcTreeNode* node, unsigned int depth);
00227 
00232     class StaticMemberInitializer{
00233        public:
00234          StaticMemberInitializer() {
00235            MyOcTree* tree = new MyOcTree(0.1);
00236            AbstractOcTree::registerTreeType(tree);
00237          }
00238     };
00240     static StaticMemberInitializer MyOcTreeMemberInit;
00241     int claming_visCount_thres;
00242 
00243   };
00244 
00246   std::ostream& operator<<(std::ostream& out, MyOcTreeNode::Color const& c);
00247 
00248 } // end namespace
00249 
00250 #endif


octomap_tensor_field
Author(s): Lintao Zheng
autogenerated on Thu Jun 6 2019 19:50:39