Main MRPT website > C++ reference for MRPT 1.4.0
AbstractOcTree.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef OCTOMAP_ABSTRACT_OCTREE_H
10 #define OCTOMAP_ABSTRACT_OCTREE_H
11 
12 // $Id: AbstractOcTree.h 408 2012-08-22 09:59:55Z ahornung $
13 
14 /**
15 * OctoMap:
16 * A probabilistic, flexible, and compact 3D mapping library for robotic systems.
17 * @author K. M. Wurm, A. Hornung, University of Freiburg, Copyright (C) 2009-2011.
18 * @see http://octomap.sourceforge.net/
19 * License: New BSD License
20 */
21 
22 /*
23  * Copyright (c) 2009-2011, K. M. Wurm, A. Hornung, University of Freiburg
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are met:
28  *
29  * * Redistributions of source code must retain the above copyright
30  * notice, this list of conditions and the following disclaimer.
31  * * Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * * Neither the name of the University of Freiburg nor the names of its
35  * contributors may be used to endorse or promote products derived from
36  * this software without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
42  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49  */
50 
51 #include <cstddef>
52 #include <fstream>
53 #include <string>
54 #include <iostream>
55 #include <map>
56 
57 namespace octomap {
58 
59  /**
60  * This abstract class is an interface to all octrees and provides a
61  * factory design pattern for readin and writing all kinds of OcTrees
62  * to files (see read()).
63  */
65  friend class StaticMapInit;
66  public:
68  virtual ~AbstractOcTree() {};
69 
70  /// virtual constructor: creates a new object of same type
71  virtual AbstractOcTree* create() const = 0;
72 
73  /// returns actual class name as string for identification
74  virtual std::string getTreeType() const = 0;
75 
76 
77 
78  virtual double getResolution() const = 0;
79  virtual void setResolution(double res) = 0;
80  virtual size_t size() const = 0;
81  virtual size_t memoryUsage() const = 0;
82  virtual size_t memoryUsageNode() const = 0;
83  virtual void getMetricMin(double& x, double& y, double& z) = 0;
84  virtual void getMetricMin(double& x, double& y, double& z) const = 0;
85  virtual void getMetricMax(double& x, double& y, double& z) = 0;
86  virtual void getMetricMax(double& x, double& y, double& z) const = 0;
87  virtual void getMetricSize(double& x, double& y, double& z) = 0;
88 
89  virtual void prune() = 0;
90  virtual void expand() = 0;
91  virtual void clear() = 0;
92 
93  //-- Iterator tree access
94 
95  // default iterator is leaf_iterator
96 // class leaf_iterator;
97 // class tree_iterator;
98 // class leaf_bbx_iterator;
99 // typedef leaf_iterator iterator;
100  class iterator_base;
101 // /// @return beginning of the tree as leaf iterator
102  //virtual iterator_base begin(unsigned char maxDepth=0) const = 0;
103 // /// @return end of the tree as leaf iterator
104 // virtual const iterator end() const = 0;
105 // /// @return beginning of the tree as leaf iterator
106 // virtual leaf_iterator begin_leafs(unsigned char maxDepth=0) const = 0;
107 // /// @return end of the tree as leaf iterator
108 // virtual const leaf_iterator end_leafs() const = 0;
109 // /// @return beginning of the tree as leaf iterator in a bounding box
110 // virtual leaf_bbx_iterator begin_leafs_bbx(const OcTreeKey& min, const OcTreeKey& max, unsigned char maxDepth=0) const = 0;
111 // /// @return beginning of the tree as leaf iterator in a bounding box
112 // virtual leaf_bbx_iterator begin_leafs_bbx(const point3d& min, const point3d& max, unsigned char maxDepth=0) const = 0;
113 // /// @return end of the tree as leaf iterator in a bounding box
114 // virtual const leaf_bbx_iterator end_leafs_bbx() const = 0;
115 // /// @return beginning of the tree as iterator to all nodes (incl. inner)
116 // virtual tree_iterator begin_tree(unsigned char maxDepth=0) const = 0;
117 // /// @return end of the tree as iterator to all nodes (incl. inner)
118 // const tree_iterator end_tree() const = 0;
119 
120  /// Write file header and complete tree to file (serialization)
121  bool write(const std::string& filename) const;
122  /// Write file header and complete tree to stream (serialization)
123  bool write(std::ostream& s) const;
124 
125  /**
126  * Creates a certain OcTree (factory pattern)
127  *
128  * @param id unique ID of OcTree
129  * @param res resolution of OcTree
130  * @return pointer to newly created OcTree (empty). NULL if the ID is unknown!
131  */
132  static AbstractOcTree* createTree(const std::string id, double res);
133 
134  /**
135  * Read the file header, create the appropriate class and deserialize.
136  * This creates a new octree which you need to delete yourself. If you
137  * expect or requre a specific kind of octree, use dynamic_cast afterwards:
138  * @code
139  * AbstractOcTree* tree = AbstractOcTree::read("filename.ot");
140  * OcTree* octree = dynamic_cast<OcTree*>(tree);
141  *
142  * @endcode
143  */
144  static AbstractOcTree* read(const std::string& filename);
145 
146  /// Read the file header, create the appropriate class and deserialize.
147  /// This creates a new octree which you need to delete yourself.
148  static AbstractOcTree* read(std::istream &s);
149 
150  /**
151  * Read all nodes from the input stream (without file header),
152  * for this the tree needs to be already created.
153  * For general file IO, you
154  * should probably use AbstractOcTree::read() instead.
155  */
156  virtual std::istream& readData(std::istream &s) = 0;
157 
158  /// Write complete state of tree to stream (without file header) unmodified.
159  /// Pruning the tree first produces smaller files (lossless compression)
160  virtual std::ostream& writeData(std::ostream &s) const = 0;
161  private:
162  /// create private store, Construct on first use
163  static std::map<std::string, AbstractOcTree*>& classIDMapping();
164 
165  protected:
166  static bool readHeader(std::istream &s, std::string& id, unsigned& size, double& res);
167  static void registerTreeType(AbstractOcTree* tree);
168 
169  static const std::string fileHeader;
170  };
171 
172 
173 
174 
175 } // end namespace
176 
177 
178 #endif
OctoMap: A probabilistic, flexible, and compact 3D mapping library for robotic systems.
This abstract class is an interface to all octrees and provides a factory design pattern for readin a...
virtual std::ostream & writeData(std::ostream &s) const =0
Write complete state of tree to stream (without file header) unmodified.
virtual void prune()=0
static std::map< std::string, AbstractOcTree * > & classIDMapping()
create private store, Construct on first use
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...
static AbstractOcTree * createTree(const std::string id, double res)
Creates a certain OcTree (factory pattern)
virtual double getResolution() const =0
friend class StaticMapInit
virtual void clear()=0
virtual size_t memoryUsage() const =0
static AbstractOcTree * read(const std::string &filename)
Read the file header, create the appropriate class and deserialize.
bool write(const std::string &filename) const
Write file header and complete tree to file (serialization)
virtual void getMetricSize(double &x, double &y, double &z)=0
virtual AbstractOcTree * create() const =0
virtual constructor: creates a new object of same type
virtual std::string getTreeType() const =0
returns actual class name as string for identification
virtual void getMetricMin(double &x, double &y, double &z)=0
virtual void expand()=0
static void registerTreeType(AbstractOcTree *tree)
static const std::string fileHeader
static bool readHeader(std::istream &s, std::string &id, unsigned &size, double &res)
virtual void getMetricMax(double &x, double &y, double &z)=0
virtual size_t size() const =0
virtual size_t memoryUsageNode() const =0
virtual void setResolution(double res)=0



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN: at Sun Aug 14 23:58:29 UTC 2016