00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #pragma once
00028 #ifndef OCTONODE_H
00029 #define OCTONODE_H
00030
00031 #include "ButOctomapRos.h"
00032 #include <octomap/OcTreeStamped.h>
00033
00034 namespace srs_env_model {
00035
00040 class EModelTreeNode: public octomap::OcTreeNodeStamped {
00041
00042 public:
00043
00047 EModelTreeNode();
00048
00052 ~EModelTreeNode();
00053
00054 bool createChild(unsigned int i);
00055
00056
00057 inline EModelTreeNode* getChild(unsigned int i) {
00058 return static_cast<EModelTreeNode*> (octomap::OcTreeDataNode<float>::getChild(i));
00059 }
00060 inline const EModelTreeNode* getChild(unsigned int i) const {
00061 return static_cast<const EModelTreeNode*> (octomap::OcTreeDataNode<float>::getChild(
00062 i));
00063 }
00064
00066 unsigned char r() const {
00067 return m_r;
00068 }
00069 unsigned char g() const {
00070 return m_g;
00071 }
00072 unsigned char b() const {
00073 return m_b;
00074 }
00075 unsigned char a() const {
00076 return m_a;
00077 }
00078
00080 unsigned char & r() {
00081 return m_r;
00082 }
00083 unsigned char & g() {
00084 return m_g;
00085 }
00086 unsigned char & b() {
00087 return m_b;
00088 }
00089 unsigned char & a() {
00090 return m_a;
00091 }
00092
00094 void setColor(unsigned char r, unsigned char g, unsigned char b,
00095 unsigned char a = 255) {
00096 m_r = r;
00097 m_g = g;
00098 m_b = b;
00099 m_a = a;
00100 }
00101
00102
00103 inline bool isColorSet() const {
00104 return ((m_r != 255) || (m_g != 255) || (m_b != 255));
00105 }
00106
00107
00108 bool pruneNode();
00109
00110
00111 void expandNode();
00112
00113
00114 void updateColorChildren();
00115
00116
00117 void setAverageChildColor();
00118
00126 std::istream& readValue(std::istream &s);
00127
00136 std::ostream& writeValue(std::ostream &s) const;
00137
00138 protected:
00140 unsigned char m_r, m_g, m_b, m_a;
00141
00142 };
00143
00149 class EMOcTree: public octomap::OccupancyOcTreeBase<EModelTreeNode> {
00150
00151 public:
00153 typedef octomap::point3d tPoint;
00154
00156 typedef EModelTreeNode tNode;
00157
00158 typedef pcl::PointCloud<pcl::PointXYZRGB> typePointCloud;
00159
00160 public:
00161
00166 EMOcTree(double _resolution);
00167
00173 EMOcTree(std::string _filename);
00174
00178 virtual ~EMOcTree() {
00179 }
00180 ;
00181
00184 EMOcTree* create() const {
00185 return new EMOcTree(resolution);
00186 }
00187
00191 std::string getTreeType() const {
00192 return "EMOcTree";
00193 }
00194
00195
00196 EModelTreeNode* setNodeColor(const octomap::OcTreeKey& key, const unsigned char& r,
00197 const unsigned char& g, const unsigned char& b,
00198 const unsigned char& a);
00199
00200 EModelTreeNode* setNodeColor(const float& x, const float& y,
00201 const float& z, const unsigned char& r, const unsigned char& g,
00202 const unsigned char& b, const unsigned char& a) {
00203 octomap::OcTreeKey key;
00204 if (!this->genKey(octomap::point3d(x, y, z), key))
00205 return NULL;
00206 return setNodeColor(key, r, g, b, a);
00207 }
00208
00209
00210 EModelTreeNode* averageNodeColor(const octomap::OcTreeKey& key,
00211 const unsigned char& r, const unsigned char& g,
00212 const unsigned char& b, const unsigned char& a);
00213
00214 EModelTreeNode* averageNodeColor(const float& x, const float& y,
00215 const float& z, const unsigned char& r, const unsigned char& g,
00216 const unsigned char& b, const unsigned char& a) {
00217 octomap::OcTreeKey key;
00218 if (!this->genKey(octomap::point3d(x, y, z), key))
00219 return NULL;
00220 return averageNodeColor(key, r, g, b, a);
00221 }
00222
00223
00224
00225 EModelTreeNode* integrateNodeColor(const octomap::OcTreeKey& key,
00226 const unsigned char& r, const unsigned char& g,
00227 const unsigned char& b, const unsigned char& a);
00228
00229 EModelTreeNode* integrateNodeColor(const float& x, const float& y,
00230 const float& z, const unsigned char& r, const unsigned char& g,
00231 const unsigned char& b, const unsigned char& a) {
00232 octomap::OcTreeKey key;
00233 if (!this->genKey(octomap::point3d(x, y, z), key))
00234 return NULL;
00235 return integrateNodeColor(key, r, g, b, a);
00236 }
00237
00238
00239 void updateInnerOccupancy();
00240
00242 unsigned int getLastUpdateTime();
00243
00244 void degradeOutdatedNodes(unsigned int time_thres);
00245
00246 virtual void
00247 updateNodeLogOdds(EModelTreeNode* node, const float& update) const;
00248 void integrateMissNoTime(EModelTreeNode* node) const;
00249
00250
00251
00252 void insertColoredScan(const typePointCloud& coloredScan,
00253 const octomap::point3d& sensor_origin, double maxrange = -1.,
00254 bool pruning = true, bool lazy_eval = false);
00255
00256 protected:
00257 void updateInnerOccupancyRecurs(EModelTreeNode* node, unsigned int depth);
00258
00263 class StaticMemberInitializer {
00264 public:
00265 StaticMemberInitializer() {
00266 EMOcTree* tree = new EMOcTree(0.1);
00267 AbstractOcTree::registerTreeType(tree);
00268 std::cerr << "Registered tree type: " << tree->getTreeType() << std::endl;
00269 }
00270 };
00271
00273 static StaticMemberInitializer ocEMOcTreeMemberInit;
00274 };
00275
00276 }
00277 ;
00278
00279 #endif // OCTONODE_H