Main MRPT website > C++ reference for MRPT 1.3.2
OcTreeDataNode.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-2015, 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_OCTREE_DATA_NODE_H
10 #define OCTOMAP_OCTREE_DATA_NODE_H
11 
12 // $Id: OcTreeDataNode.h 401 2012-08-03 15:16:39Z 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.
18 * @see http://octomap.sourceforge.net/
19 * License: New BSD License
20 */
21 
22 /*
23  * Copyright (c) 2009, 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 "octomap_types.h"
52 #include "assert.h"
53 #include <bitset>
54 
55 namespace octomap {
56 
58 
59 
60  };
61 
62  /**
63  * Basic node in the OcTree that can hold arbitrary data of type T in value.
64  * This is the base class for nodes used in an OcTree. The used implementation
65  * for occupancy mapping is in OcTreeNode.#
66  * \tparam T data to be stored in the node (e.g. a float for probabilities)
67  *
68  */
69  template<typename T> class OcTreeDataNode: public AbstractOcTreeNode {
70 
71  public:
72 
74  OcTreeDataNode(T initVal);
75  /// Copy constructor, performs a recursive deep-copy of all children
76  OcTreeDataNode(const OcTreeDataNode& rhs);
77 
78  ~OcTreeDataNode();
79 
80  /// Equals operator, compares if the stored value is identical
81  bool operator==(const OcTreeDataNode& rhs) const;
82 
83 
84  // -- children ----------------------------------
85 
86 
87  /// initialize i-th child, allocate children array if needed
88  bool createChild(unsigned int i);
89 
90  /// \return true if the i-th child exists
91  bool childExists(unsigned int i) const;
92 
93  /// \return a pointer to the i-th child of the node. The child needs to exist.
94  OcTreeDataNode<T>* getChild(unsigned int i);
95 
96  /// \return a const pointer to the i-th child of the node. The child needs to exist.
97  const OcTreeDataNode<T>* getChild(unsigned int i) const;
98 
99  /// \return true if the node has at least one child
100  bool hasChildren() const;
101 
102  /// A node is collapsible if all children exist, don't have children of their own
103  /// and have the same occupancy value
104  bool collapsible() const;
105 
106  /// Deletes the i-th child of the node
107  void deleteChild(unsigned int i);
108 
109  // -- pruning of children -----------------------
110 
111 
112  /**
113  * Prunes a node when it is collapsible
114  * @return true if pruning was successful
115  */
116  bool pruneNode();
117 
118  /**
119  * Expands a node (reverse of pruning): All children are created and
120  * their occupancy probability is set to the node's value.
121  *
122  * You need to verify that this is indeed a pruned node (i.e. not a
123  * leaf at the lowest level)
124  *
125  */
126  void expandNode();
127 
128  /// @return value stored in the node
129  T getValue() const{return value;};
130  /// sets value to be stored in the node
131  void setValue(T v) {value = v;};
132 
133  // file IO:
134 
135  /**
136  * Read node from binary stream (incl. float value),
137  * recursively continue with all children.
138  *
139  * @param s
140  * @return
141  */
142  std::istream& readValue(std::istream &s);
143 
144  /**
145  * Write node to binary stream (incl float value),
146  * recursively continue with all children.
147  * This preserves the complete state of the node.
148  *
149  * @param s
150  * @return
151  */
152  std::ostream& writeValue(std::ostream &s) const;
153 
154 
155  /// Make the templated data type available from the outside
156  typedef T DataType;
157 
158 
159  protected:
160  void allocChildren();
161 
162  /// pointer to array of children, may be NULL
164  /// stored data (payload)
165  T value;
166 
167  };
168 
169 
170 } // end namespace
171 
172 #include "mrpt/otherlibs/octomap/OcTreeDataNode.hxx"
173 
174 #endif
OctoMap: A probabilistic, flexible, and compact 3D mapping library for robotic systems.
OcTreeDataNode< T > ** children
pointer to array of children, may be NULL
bool operator==(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:279
void setValue(T v)
sets value to be stored in the node
T value
stored data (payload)
Basic node in the OcTree that can hold arbitrary data of type T in value.
T DataType
Make the templated data type available from the outside.



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN:Unversioned directory at Sun May 1 08:45:24 UTC 2016