octomap 1.5.0
include/octomap/AbstractOccupancyOcTree.h
Go to the documentation of this file.
00001 #ifndef OCTOMAP_ABSTRACT_OCCUPANCY_OCTREE_H
00002 #define OCTOMAP_ABSTRACT_OCCUPANCY_OCTREE_H
00003 
00004 // $Id: AbstractOccupancyOcTree.h 420 2012-08-27 14:10:25Z ahornung $
00005 
00014 /*
00015  * Copyright (c) 2009-2011, K. M. Wurm, A. Hornung, University of Freiburg
00016  * All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions are met:
00020  *
00021  *     * Redistributions of source code must retain the above copyright
00022  *       notice, this list of conditions and the following disclaimer.
00023  *     * Redistributions in binary form must reproduce the above copyright
00024  *       notice, this list of conditions and the following disclaimer in the
00025  *       documentation and/or other materials provided with the distribution.
00026  *     * Neither the name of the University of Freiburg nor the names of its
00027  *       contributors may be used to endorse or promote products derived from
00028  *       this software without specific prior written permission.
00029  *
00030  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00031  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00032  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00033  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00034  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00035  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00036  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00037  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00038  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00039  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00040  * POSSIBILITY OF SUCH DAMAGE.
00041  */
00042 
00043 #include "AbstractOcTree.h"
00044 #include "octomap_utils.h"
00045 #include "OcTreeNode.h"
00046 #include "OcTreeKey.h"
00047 #include <cassert>
00048 #include <fstream>
00049 
00050 
00051 namespace octomap {
00052 
00058   class AbstractOccupancyOcTree : public AbstractOcTree {
00059   public:
00060     AbstractOccupancyOcTree();
00061     virtual ~AbstractOccupancyOcTree() {};
00062 
00063     //-- IO
00064 
00070     bool writeBinary(const std::string& filename);
00071 
00078     bool writeBinary(std::ostream &s);
00079 
00087     bool writeBinaryConst(const std::string& filename) const;
00088 
00095     bool writeBinaryConst(std::ostream &s) const;
00096 
00098     virtual std::ostream& writeBinaryData(std::ostream &s) const = 0;
00099     
00105     bool readBinary(std::istream &s);
00106     
00112     bool readBinary(const std::string& filename);
00113 
00115     virtual std::istream& readBinaryData(std::istream &s) = 0;
00116 
00117     // -- occupancy queries
00118 
00120     inline bool isNodeOccupied(const OcTreeNode* occupancyNode) const{
00121       return (occupancyNode->getLogOdds() >= this->occ_prob_thres_log);
00122     }
00123 
00125     inline bool isNodeOccupied(const OcTreeNode& occupancyNode) const{
00126       return (occupancyNode.getLogOdds() >= this->occ_prob_thres_log);
00127     }
00128 
00130     inline bool isNodeAtThreshold(const OcTreeNode* occupancyNode) const{
00131       return (occupancyNode->getLogOdds() >= this->clamping_thres_max
00132           || occupancyNode->getLogOdds() <= this->clamping_thres_min);
00133     }
00134 
00136     inline bool isNodeAtThreshold(const OcTreeNode& occupancyNode) const{
00137       return (occupancyNode.getLogOdds() >= this->clamping_thres_max
00138           || occupancyNode.getLogOdds() <= this->clamping_thres_min);
00139     }
00140 
00141     // - update functions
00142 
00152     virtual OcTreeNode* updateNode(const OcTreeKey& key, float log_odds_update, bool lazy_eval = false) = 0;
00153 
00164     virtual OcTreeNode* updateNode(const point3d& value, float log_odds_update, bool lazy_eval = false) = 0;
00165 
00175     virtual OcTreeNode* updateNode(const OcTreeKey& key, bool occupied, bool lazy_eval = false) = 0;
00176 
00187     virtual OcTreeNode* updateNode(const point3d& value, bool occupied, bool lazy_eval = false) = 0;
00188 
00189     virtual void toMaxLikelihood() = 0;
00190 
00191     //-- parameters for occupancy and sensor model:
00192 
00194     void setOccupancyThres(double prob){occ_prob_thres_log = logodds(prob); }
00196     void setProbHit(double prob){prob_hit_log = logodds(prob); assert(prob_hit_log >= 0.0);}
00198     void setProbMiss(double prob){prob_miss_log = logodds(prob); assert(prob_miss_log <= 0.0);}
00200     void setClampingThresMin(double thresProb){clamping_thres_min = logodds(thresProb); }
00202     void setClampingThresMax(double thresProb){clamping_thres_max = logodds(thresProb); }
00203 
00205     double getOccupancyThres() const {return probability(occ_prob_thres_log); }
00207     float getOccupancyThresLog() const {return occ_prob_thres_log; }
00208 
00210     double getProbHit() const {return probability(prob_hit_log); }
00212     float getProbHitLog() const {return prob_hit_log; }
00214     double getProbMiss() const {return probability(prob_miss_log); }
00216     float getProbMissLog() const {return prob_miss_log; }
00217 
00219     double getClampingThresMin() const {return probability(clamping_thres_min); }
00221     float getClampingThresMinLog() const {return clamping_thres_min; }
00223     double getClampingThresMax() const {return probability(clamping_thres_max); }
00225     float getClampingThresMaxLog() const {return clamping_thres_max; }
00226 
00227 
00228 
00229 
00230   protected:
00232     bool readBinaryLegacyHeader(std::istream &s, unsigned int& size, double& res);
00233     
00234     // occupancy parameters of tree, stored in logodds:
00235     float clamping_thres_min;
00236     float clamping_thres_max;
00237     float prob_hit_log;
00238     float prob_miss_log;
00239     float occ_prob_thres_log;
00240 
00241     static const std::string binaryFileHeader;
00242   };
00243 
00244 }; // end namespace
00245 
00246 
00247 #endif