octomap 1.5.0
include/octomap/OccupancyOcTreeBase.h
Go to the documentation of this file.
00001 #ifndef OCTOMAP_OCCUPANCY_OCTREE_BASE_H
00002 #define OCTOMAP_OCCUPANCY_OCTREE_BASE_H
00003 
00004 // $Id: OccupancyOcTreeBase.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 <list>
00044 #include <stdlib.h>
00045 
00046 #include "octomap_types.h"
00047 #include "octomap_utils.h"
00048 #include "OcTreeBaseImpl.h"
00049 #include "AbstractOccupancyOcTree.h"
00050 
00051 
00052 namespace octomap {
00053 
00072   template <class NODE>
00073   class OccupancyOcTreeBase : public OcTreeBaseImpl<NODE,AbstractOccupancyOcTree> {
00074 
00075   public:
00077     OccupancyOcTreeBase(double resolution);
00078     virtual ~OccupancyOcTreeBase();
00079 
00081     OccupancyOcTreeBase(const OccupancyOcTreeBase<NODE>& rhs);
00082 
00093     virtual void insertScan(const Pointcloud& scan, const octomap::point3d& sensor_origin,
00094                     double maxrange=-1., bool pruning=true, bool lazy_eval = false);
00095 
00107     virtual void insertScan(const Pointcloud& scan, const point3d& sensor_origin, const pose6d& frame_origin,
00108                     double maxrange=-1., bool pruning = true, bool lazy_eval = false);
00109 
00119     virtual void insertScan(const ScanNode& scan, double maxrange=-1., bool pruning = true, bool lazy_eval = false);
00120 
00122     virtual void insertScanNaive(const Pointcloud& pc, const point3d& origin, double maxrange, bool pruning = true, bool lazy_eval = false);
00123 
00133     virtual NODE* updateNode(const OcTreeKey& key, float log_odds_update, bool lazy_eval = false);
00134 
00145     virtual NODE* updateNode(const point3d& value, float log_odds_update, bool lazy_eval = false);
00146 
00156     virtual NODE* updateNode(const OcTreeKey& key, bool occupied, bool lazy_eval = false);
00157 
00168     virtual NODE* updateNode(const point3d& value, bool occupied, bool lazy_eval = false);
00169 
00170 
00176     virtual void toMaxLikelihood();
00177 
00189     virtual bool insertRay(const point3d& origin, const point3d& end, double maxrange=-1.0, bool lazy_eval = false);
00190     
00205     virtual bool castRay(const point3d& origin, const point3d& direction, point3d& end,
00206                  bool ignoreUnknownCells=false, double maxRange=-1.0) const;
00207    
00216     DEPRECATED( void getOccupied(point3d_list& node_centers, unsigned int max_depth = 0) const);
00217     
00226     DEPRECATED(void getOccupied(std::list<OcTreeVolume>& occupied_volumes, unsigned int max_depth = 0) const);
00227 
00239     DEPRECATED(void getOccupied(std::list<OcTreeVolume>& binary_nodes, std::list<OcTreeVolume>& delta_nodes,
00240                      unsigned int max_depth = 0) const);
00241 
00242 
00248     DEPRECATED(void getOccupiedLeafsBBX(point3d_list& node_centers, point3d min, point3d max) const);
00249 
00258     DEPRECATED(void getFreespace(std::list<OcTreeVolume>& free_volumes, unsigned int max_depth = 0) const);
00259 
00270     DEPRECATED(void getFreespace(std::list<OcTreeVolume>& binary_nodes, std::list<OcTreeVolume>& delta_nodes,
00271                       unsigned int max_depth = 0) const);
00272 
00273 
00274 
00275     //-- set BBX limit (limits tree updates to this bounding box  
00276 
00278     void useBBXLimit(bool enable) { use_bbx_limit = enable; }
00279     bool bbxSet() const { return use_bbx_limit; }
00281     void setBBXMin (point3d& min);
00283     void setBBXMax (point3d& max);
00285     point3d getBBXMin () const { return bbx_min; }
00287     point3d getBBXMax () const { return bbx_max; }
00288     point3d getBBXBounds () const;
00289     point3d getBBXCenter () const;
00291     bool inBBX(const point3d& p) const;
00293     bool inBBX(const OcTreeKey& key) const;
00294 
00295     //-- change detection on occupancy:
00297     void enableChangeDetection(bool enable) { use_change_detection = enable; }
00299     void resetChangeDetection() { changed_keys.clear(); }
00300 
00306     KeyBoolMap::const_iterator changedKeysBegin() {return changed_keys.begin();}
00307 
00309     KeyBoolMap::const_iterator changedKeysEnd() {return changed_keys.end();}
00310 
00311 
00323     void computeUpdate(const Pointcloud& scan, const octomap::point3d& origin,
00324                        KeySet& free_cells,
00325                        KeySet& occupied_cells,
00326                        double maxrange);
00327 
00328     // -- I/O  -----------------------------------------
00329 
00335     std::istream& readBinaryData(std::istream &s);
00336 
00347     std::istream& readBinaryNode(std::istream &s, NODE* node) const;
00348 
00360     std::ostream& writeBinaryNode(std::ostream &s, const NODE* node) const;
00361 
00366     std::ostream& writeBinaryData(std::ostream &s) const;
00367 
00368 
00369     void calcNumThresholdedNodes(unsigned int& num_thresholded, unsigned int& num_other) const;
00370 
00376     void updateInnerOccupancy();
00377 
00378 
00380     virtual void integrateHit(NODE* occupancyNode) const;
00382     virtual void integrateMiss(NODE* occupancyNode) const;
00383     // update logodds value of node, given update is added to current value.
00384     virtual void updateNodeLogOdds(NODE* occupancyNode, const float& update) const;
00385 
00387     virtual void nodeToMaxLikelihood(NODE* occupancyNode) const;
00389     virtual void nodeToMaxLikelihood(NODE& occupancyNode) const;
00390 
00391   protected:
00394     OccupancyOcTreeBase(double resolution, unsigned int tree_depth, unsigned int tree_max_val);
00395 
00400     inline bool integrateMissOnRay(const point3d& origin, const point3d& end, bool lazy_eval = false);
00401 
00402 
00403     // recursive calls ----------------------------
00404 
00405     NODE* updateNodeRecurs(NODE* node, bool node_just_created, const OcTreeKey& key,
00406                            unsigned int depth, const float& log_odds_update, bool lazy_eval = false);
00407     
00408     void updateInnerOccupancyRecurs(NODE* node, unsigned int depth);
00409 
00410     void getOccupiedLeafsBBXRecurs( point3d_list& node_centers, unsigned int max_depth, NODE* node, 
00411                                     unsigned int depth, const OcTreeKey& parent_key, 
00412                                     const OcTreeKey& min, const OcTreeKey& max) const;
00413     
00414     void toMaxLikelihoodRecurs(NODE* node, unsigned int depth, unsigned int max_depth);
00415 
00416     void calcNumThresholdedNodesRecurs (NODE* node,
00417                                         unsigned int& num_thresholded,
00418                                         unsigned int& num_other) const;
00419 
00420   protected:
00421     bool use_bbx_limit;  
00422     point3d bbx_min;
00423     point3d bbx_max;
00424     OcTreeKey bbx_min_key;
00425     OcTreeKey bbx_max_key;
00426 
00427     bool use_change_detection;
00429     KeyBoolMap changed_keys;
00430     
00431 
00432   };
00433 
00434 } // namespace
00435 
00436 #include "octomap/OccupancyOcTreeBase.hxx"
00437 
00438 #endif