octonode.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id: octonode.h 2155 2012-12-27 17:45:59Z spanel $
00005  *
00006  * Copyright (C) Brno University of Technology
00007  *
00008  * This file is part of software developed by dcgm-robotics@FIT group.
00009  *
00010  * Author: Vit Stancl (stancl@fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: dd/mm/2012
00013  * 
00014  * This file is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation, either version 3 of the License, or
00017  * (at your option) any later version.
00018  * 
00019  * This file is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
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         // overloaded, so that the return type is correct:
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         // has any color been integrated? (pure white is very unlikely...)
00103         inline bool isColorSet() const {
00104                 return ((m_r != 255) || (m_g != 255) || (m_b != 255));
00105         }
00106 
00107         // overloaded tree pruning taking care of node colors
00108         bool pruneNode();
00109 
00110         // overloaded tree expanding taking care of node colors
00111         void expandNode();
00112 
00113         // update node color
00114         void updateColorChildren();
00115 
00116         // set color to average child color
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 }; // class EModelTreeNode
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         // set node color at given key or coordinate. Replaces previous color.
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         // integrate color measurement at given key or coordinate. Average with previous color
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         // integrate color measurement at given key or coordinate.
00224         // Average with previous color taking account of node probabilities
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         // update inner nodes, sets color to average child color
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         // Overloaded. Inserts colored scan
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 }; // class EMOcTree
00275 
00276 }
00277 ; // namespace srs_env_model
00278 
00279 #endif // OCTONODE_H


srs_env_model
Author(s): Vit Stancl (stancl@fit.vutbr.cz), Tomas Lokaj, Jan Gorig, Michal Spanel (spanel@fit.vutbr.cz)
autogenerated on Sun Jan 5 2014 11:50:49