octomap  1.9.7
AbstractOcTree.h
Go to the documentation of this file.
1 /*
2  * OctoMap - An Efficient Probabilistic 3D Mapping Framework Based on Octrees
3  * https://octomap.github.io/
4  *
5  * Copyright (c) 2009-2013, K.M. Wurm and A. Hornung, University of Freiburg
6  * All rights reserved.
7  * License: New BSD
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the University of Freiburg nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef OCTOMAP_ABSTRACT_OCTREE_H
35 #define OCTOMAP_ABSTRACT_OCTREE_H
36 
37 #include <cstddef>
38 #include <fstream>
39 #include <string>
40 #include <iostream>
41 #include <map>
42 
43 namespace octomap {
44 
51  friend class StaticMapInit;
52  public:
54  virtual ~AbstractOcTree() {};
55 
57  virtual AbstractOcTree* create() const = 0;
58 
60  virtual std::string getTreeType() const = 0;
61 
62 
63 
64  virtual double getResolution() const = 0;
65  virtual void setResolution(double res) = 0;
66  virtual size_t size() const = 0;
67  virtual size_t memoryUsage() const = 0;
68  virtual size_t memoryUsageNode() const = 0;
69  virtual void getMetricMin(double& x, double& y, double& z) = 0;
70  virtual void getMetricMin(double& x, double& y, double& z) const = 0;
71  virtual void getMetricMax(double& x, double& y, double& z) = 0;
72  virtual void getMetricMax(double& x, double& y, double& z) const = 0;
73  virtual void getMetricSize(double& x, double& y, double& z) = 0;
74 
75  virtual void prune() = 0;
76  virtual void expand() = 0;
77  virtual void clear() = 0;
78 
79  //-- Iterator tree access
80 
81  // default iterator is leaf_iterator
82 // class leaf_iterator;
83 // class tree_iterator;
84 // class leaf_bbx_iterator;
85 // typedef leaf_iterator iterator;
86  class iterator_base;
87 // /// @return beginning of the tree as leaf iterator
88  //virtual iterator_base begin(unsigned char maxDepth=0) const = 0;
89 // /// @return end of the tree as leaf iterator
90 // virtual const iterator end() const = 0;
91 // /// @return beginning of the tree as leaf iterator
92 // virtual leaf_iterator begin_leafs(unsigned char maxDepth=0) const = 0;
93 // /// @return end of the tree as leaf iterator
94 // virtual const leaf_iterator end_leafs() const = 0;
95 // /// @return beginning of the tree as leaf iterator in a bounding box
96 // virtual leaf_bbx_iterator begin_leafs_bbx(const OcTreeKey& min, const OcTreeKey& max, unsigned char maxDepth=0) const = 0;
97 // /// @return beginning of the tree as leaf iterator in a bounding box
98 // virtual leaf_bbx_iterator begin_leafs_bbx(const point3d& min, const point3d& max, unsigned char maxDepth=0) const = 0;
99 // /// @return end of the tree as leaf iterator in a bounding box
100 // virtual const leaf_bbx_iterator end_leafs_bbx() const = 0;
101 // /// @return beginning of the tree as iterator to all nodes (incl. inner)
102 // virtual tree_iterator begin_tree(unsigned char maxDepth=0) const = 0;
103 // /// @return end of the tree as iterator to all nodes (incl. inner)
104 // const tree_iterator end_tree() const = 0;
105 
107  bool write(const std::string& filename) const;
109  bool write(std::ostream& s) const;
110 
118  static AbstractOcTree* createTree(const std::string id, double res);
119 
130  static AbstractOcTree* read(const std::string& filename);
131 
134  static AbstractOcTree* read(std::istream &s);
135 
142  virtual std::istream& readData(std::istream &s) = 0;
143 
146  virtual std::ostream& writeData(std::ostream &s) const = 0;
147  private:
149  static std::map<std::string, AbstractOcTree*>& classIDMapping();
150 
151  protected:
152  static bool readHeader(std::istream &s, std::string& id, unsigned& size, double& res);
153  static void registerTreeType(AbstractOcTree* tree);
154 
155  static const std::string fileHeader;
156  };
157 
158 
159 
160 
161 } // end namespace
162 
163 
164 #endif
octomap::AbstractOcTree::expand
virtual void expand()=0
octomap::AbstractOcTree::memoryUsage
virtual size_t memoryUsage() const =0
octomap::AbstractOcTree::prune
virtual void prune()=0
octomap::AbstractOcTree::memoryUsageNode
virtual size_t memoryUsageNode() const =0
octomap::AbstractOcTree::~AbstractOcTree
virtual ~AbstractOcTree()
Definition: AbstractOcTree.h:54
octomap::AbstractOcTree::writeData
virtual std::ostream & writeData(std::ostream &s) const =0
Write complete state of tree to stream (without file header) unmodified. Pruning the tree first produ...
octomap::AbstractOcTree::fileHeader
static const std::string fileHeader
Definition: AbstractOcTree.h:155
octomap::AbstractOcTree::write
bool write(const std::string &filename) const
Write file header and complete tree to file (serialization)
Definition: AbstractOcTree.cpp:45
octomap::AbstractOcTree::getMetricMax
virtual void getMetricMax(double &x, double &y, double &z)=0
octomap::AbstractOcTree::getResolution
virtual double getResolution() const =0
octomap::AbstractOcTree
This abstract class is an interface to all octrees and provides a factory design pattern for readin a...
Definition: AbstractOcTree.h:50
octomap::AbstractOcTree::StaticMapInit
friend class StaticMapInit
Definition: AbstractOcTree.h:51
octomap::AbstractOcTree::createTree
static AbstractOcTree * createTree(const std::string id, double res)
Creates a certain OcTree (factory pattern)
Definition: AbstractOcTree.cpp:184
octomap::AbstractOcTree::clear
virtual void clear()=0
octomap::AbstractOcTree::readHeader
static bool readHeader(std::istream &s, std::string &id, unsigned &size, double &res)
Definition: AbstractOcTree.cpp:119
iterator_base
Base class for OcTree iterators.
Definition: OcTreeIterator.hxx:42
octomap::AbstractOcTree::getTreeType
virtual std::string getTreeType() const =0
returns actual class name as string for identification
octomap::AbstractOcTree::size
virtual size_t size() const =0
octomap::AbstractOcTree::registerTreeType
static void registerTreeType(AbstractOcTree *tree)
Definition: AbstractOcTree.cpp:205
octomap::AbstractOcTree::AbstractOcTree
AbstractOcTree()
Definition: AbstractOcTree.cpp:41
octomap::AbstractOcTree::read
static AbstractOcTree * read(const std::string &filename)
Read the file header, create the appropriate class and deserialize.
Definition: AbstractOcTree.cpp:74
iterator_base::tree
OcTreeBaseImpl< NodeType, INTERFACE > const * tree
Octree this iterator is working on.
Definition: OcTreeIterator.hxx:158
octomap
Tables used by the Marching Cubes Algorithm The tables are from Paul Bourke's web page http://paulbou...
octomap::AbstractOcTree::readData
virtual std::istream & readData(std::istream &s)=0
Read all nodes from the input stream (without file header), for this the tree needs to be already cre...
octomap::AbstractOcTree::getMetricMin
virtual void getMetricMin(double &x, double &y, double &z)=0
octomap::AbstractOcTree::create
virtual AbstractOcTree * create() const =0
virtual constructor: creates a new object of same type
octomap::AbstractOcTree::getMetricSize
virtual void getMetricSize(double &x, double &y, double &z)=0
octomap::AbstractOcTree::setResolution
virtual void setResolution(double res)=0