octomap
1.9.8
Toggle main menu visibility
Loading...
Searching...
No Matches
OcTreeDataNode.hxx
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
namespace
octomap
{
35
36
template
<
typename
T>
37
OcTreeDataNode<T>::OcTreeDataNode
()
38
:
children
(NULL)
39
{
40
41
}
42
43
template
<
typename
T>
44
OcTreeDataNode<T>::OcTreeDataNode
(T initVal)
45
:
children
(NULL),
value
(initVal)
46
{
47
48
}
49
50
template
<
typename
T>
51
OcTreeDataNode<T>::OcTreeDataNode
(
const
OcTreeDataNode<T>
& rhs)
52
:
children
(NULL),
value
(rhs.
value
)
53
{
54
if
(rhs.
children
!= NULL){
55
allocChildren();
56
for (unsigned i = 0; i<8; ++i){
57
if (rhs.children[i] != NULL)
58
children[i] = new OcTreeDataNode<T>(*(static_cast<OcTreeDataNode<T>*>(rhs.children[i])));
59
60
}
61
}
62
}
63
64
template
<
typename
T>
65
OcTreeDataNode<T>::~OcTreeDataNode
()
66
{
67
// Delete only own members. OcTree maintains tree structure and must have deleted
68
// children already
69
assert(
children
== NULL);
70
}
71
72
template
<
typename
T>
73
void
OcTreeDataNode<T>::copyData
(
const
OcTreeDataNode<T>
& from){
74
value
= from.
value
;
75
}
76
77
template
<
typename
T>
78
bool
OcTreeDataNode<T>::operator==
(
const
OcTreeDataNode<T>
& rhs)
const
{
79
return
rhs.
value
==
value
;
80
}
81
82
// ============================================================
83
// = children =======================================
84
// ============================================================
85
86
87
template
<
typename
T>
88
bool
OcTreeDataNode<T>::childExists
(
unsigned
int
i)
const
{
89
assert(i < 8);
90
if
((
children
!= NULL) && (
children
[i] != NULL))
91
return
true
;
92
else
93
return
false
;
94
}
95
96
template
<
typename
T>
97
bool
OcTreeDataNode<T>::hasChildren
()
const
{
98
if
(children == NULL)
99
return
false
;
100
for
(
unsigned
int
i = 0; i<8; i++){
101
// fast check, we know children != NULL
102
if
(children[i] != NULL)
103
return
true
;
104
}
105
return
false
;
106
}
107
108
109
// ============================================================
110
// = File IO =======================================
111
// ============================================================
112
113
template
<
typename
T>
114
std::istream&
OcTreeDataNode<T>::readData
(std::istream &s) {
115
s.read((
char
*) &
value
,
sizeof
(
value
));
116
return
s;
117
}
118
119
120
template
<
typename
T>
121
std::ostream&
OcTreeDataNode<T>::writeData
(std::ostream &s)
const
{
122
s.write((
const
char
*) &
value
,
sizeof
(
value
));
123
return
s;
124
}
125
126
127
// ============================================================
128
// = private methodes =======================================
129
// ============================================================
130
template
<
typename
T>
131
void
OcTreeDataNode<T>::allocChildren
() {
132
children
=
new
AbstractOcTreeNode
*[8];
133
for
(
unsigned
int
i=0; i<8; i++) {
134
children
[i] = NULL;
135
}
136
}
137
138
139
}
// end namespace
140
octomap::AbstractOcTreeNode
Definition
OcTreeDataNode.h:43
octomap::OcTreeDataNode
Basic node in the OcTree that can hold arbitrary data of type T in value.
Definition
OcTreeDataNode.h:63
octomap::OcTreeDataNode::children
AbstractOcTreeNode ** children
pointer to array of children, may be NULL
Definition
OcTreeDataNode.h:126
octomap::OcTreeDataNode::value
T value
stored data (payload)
Definition
OcTreeDataNode.h:128
octomap::OcTreeDataNode::writeData
std::ostream & writeData(std::ostream &s) const
Write node payload (data only) to binary stream.
Definition
OcTreeDataNode.hxx:121
octomap::OcTreeDataNode::OcTreeDataNode
OcTreeDataNode()
Definition
OcTreeDataNode.hxx:37
octomap::OcTreeDataNode::allocChildren
void allocChildren()
Definition
OcTreeDataNode.hxx:131
octomap::OcTreeDataNode::readData
std::istream & readData(std::istream &s)
Read node payload (data only) from binary stream.
Definition
OcTreeDataNode.hxx:114
octomap::OcTreeDataNode::copyData
void copyData(const OcTreeDataNode &from)
Copy the payload (data in "value") from rhs into this node Opposed to copy ctor, this does not clone ...
Definition
OcTreeDataNode.hxx:73
octomap::OcTreeDataNode::~OcTreeDataNode
~OcTreeDataNode()
Delete only own members. OcTree maintains tree structure and must have deleted children already.
Definition
OcTreeDataNode.hxx:65
octomap
Namespace the OctoMap library and visualization tools.
include
octomap
OcTreeDataNode.hxx
Generated on
for octomap by
1.18.0