octomap 1.5.0
|
00001 #ifndef OCTOMAP_ABSTRACT_OCTREE_H 00002 #define OCTOMAP_ABSTRACT_OCTREE_H 00003 00004 // $Id: AbstractOcTree.h 408 2012-08-22 09:59:55Z 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 <cstddef> 00044 #include <fstream> 00045 #include <string> 00046 #include <iostream> 00047 #include <map> 00048 00049 namespace octomap { 00050 00056 class AbstractOcTree { 00057 friend class StaticMapInit; 00058 public: 00059 AbstractOcTree(); 00060 virtual ~AbstractOcTree() {}; 00061 00063 virtual AbstractOcTree* create() const = 0; 00064 00066 virtual std::string getTreeType() const = 0; 00067 00068 00069 00070 virtual double getResolution() const = 0; 00071 virtual void setResolution(double res) = 0; 00072 virtual size_t size() const = 0; 00073 virtual size_t memoryUsage() const = 0; 00074 virtual size_t memoryUsageNode() const = 0; 00075 virtual void getMetricMin(double& x, double& y, double& z) = 0; 00076 virtual void getMetricMin(double& x, double& y, double& z) const = 0; 00077 virtual void getMetricMax(double& x, double& y, double& z) = 0; 00078 virtual void getMetricMax(double& x, double& y, double& z) const = 0; 00079 virtual void getMetricSize(double& x, double& y, double& z) = 0; 00080 00081 virtual void prune() = 0; 00082 virtual void expand() = 0; 00083 virtual void clear() = 0; 00084 00085 //-- Iterator tree access 00086 00087 // default iterator is leaf_iterator 00088 // class leaf_iterator; 00089 // class tree_iterator; 00090 // class leaf_bbx_iterator; 00091 // typedef leaf_iterator iterator; 00092 class iterator_base; 00093 // /// @return beginning of the tree as leaf iterator 00094 //virtual iterator_base begin(unsigned char maxDepth=0) const = 0; 00095 // /// @return end of the tree as leaf iterator 00096 // virtual const iterator end() const = 0; 00097 // /// @return beginning of the tree as leaf iterator 00098 // virtual leaf_iterator begin_leafs(unsigned char maxDepth=0) const = 0; 00099 // /// @return end of the tree as leaf iterator 00100 // virtual const leaf_iterator end_leafs() const = 0; 00101 // /// @return beginning of the tree as leaf iterator in a bounding box 00102 // virtual leaf_bbx_iterator begin_leafs_bbx(const OcTreeKey& min, const OcTreeKey& max, unsigned char maxDepth=0) const = 0; 00103 // /// @return beginning of the tree as leaf iterator in a bounding box 00104 // virtual leaf_bbx_iterator begin_leafs_bbx(const point3d& min, const point3d& max, unsigned char maxDepth=0) const = 0; 00105 // /// @return end of the tree as leaf iterator in a bounding box 00106 // virtual const leaf_bbx_iterator end_leafs_bbx() const = 0; 00107 // /// @return beginning of the tree as iterator to all nodes (incl. inner) 00108 // virtual tree_iterator begin_tree(unsigned char maxDepth=0) const = 0; 00109 // /// @return end of the tree as iterator to all nodes (incl. inner) 00110 // const tree_iterator end_tree() const = 0; 00111 00113 bool write(const std::string& filename) const; 00115 bool write(std::ostream& s) const; 00116 00124 static AbstractOcTree* createTree(const std::string id, double res); 00125 00136 static AbstractOcTree* read(const std::string& filename); 00137 00140 static AbstractOcTree* read(std::istream &s); 00141 00148 virtual std::istream& readData(std::istream &s) = 0; 00149 00152 virtual std::ostream& writeData(std::ostream &s) const = 0; 00153 private: 00155 static std::map<std::string, AbstractOcTree*>& classIDMapping(); 00156 00157 protected: 00158 static bool readHeader(std::istream &s, std::string& id, unsigned& size, double& res); 00159 static void registerTreeType(AbstractOcTree* tree); 00160 00161 static const std::string fileHeader; 00162 }; 00163 00164 00165 00166 00167 } // end namespace 00168 00169 00170 #endif