Skip to content

Commit 3381c8b

Browse files
committed
First pass at GP integration
1 parent ae39579 commit 3381c8b

20 files changed

+2061
-35
lines changed

CMakeLists.txt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ find_package(catkin REQUIRED COMPONENTS
100100
## DEPENDS: system dependencies of this project that dependent projects also need
101101
catkin_package(
102102
INCLUDE_DIRS include
103-
LIBRARIES bgkoctomap
104103
# CATKIN_DEPENDS geometry_msgs pcl_ros roscpp
105104
# DEPENDS system_lib
106105
)
@@ -123,19 +122,25 @@ include_directories(
123122
# src/${PROJECT_NAME}/bgkoctomap.cpp
124123
# )
125124

126-
## Declare a cpp executable
127-
set(SOURCE_FILES src/block.cpp
125+
# Set relevant BGK source files
126+
set(BGK_SOURCE_FILES src/bgkblock.cpp
128127
src/bgkoctomap.cpp
129-
# src/gpoctomap.cpp # Add back when gpoctomap integration is fixed
130-
src/octree_node.cpp
131-
src/octree.cpp
132-
src/point3f.cpp)
133-
add_executable(bgkoctomap_static_node ${SOURCE_FILES}
128+
src/bgkoctree_node.cpp
129+
src/bgkoctree.cpp
130+
src/point3f.cpp
131+
)
132+
133+
set(GP_SOURCE_FILES src/gpblock.cpp
134+
src/gpoctomap.cpp
135+
src/gpoctree_node.cpp
136+
src/gpoctree.cpp
137+
src/point3f)
138+
139+
add_executable(bgkoctomap_static_node ${BGK_SOURCE_FILES}
134140
src/bgkoctomap_static_node.cpp)
135141

136-
# TODO - fix GPOctoMap integration
137-
# add_executable(gpoctomap_static_node ${SOURCE_FILES}
138-
# src/gpoctomap_static_node.cpp)
142+
add_executable(gpoctomap_static_node ${GP_SOURCE_FILES}
143+
src/gpoctomap_static_node.cpp)
139144

140145
add_executable(octomap_static_node src/octomap_static_node.cpp)
141146

@@ -156,9 +161,9 @@ target_link_libraries(bgkoctomap_static_node
156161
${catkin_LIBRARIES}
157162
)
158163

159-
# target_link_libraries(gpoctomap_static_node
160-
# ${catkin_LIBRARIES}
161-
# )
164+
target_link_libraries(gpoctomap_static_node
165+
${catkin_LIBRARIES}
166+
)
162167

163168
target_link_libraries(octomap_static_node
164169
${catkin_LIBRARIES}

config/methods/gpoctomap.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# GPOctoMap config
2+
3+
# Map topic, grid cell mininum resolution
4+
topic: /occupied_cells_vis_array
5+
resolution: 0.1
6+
block_depth: 3 # Test-data octree depth (see Wang & Englot ICRA 2016)
7+
8+
# GP parameters
9+
sf2: 1.0
10+
ell: 1.0
11+
noise: 0.01
12+
l: 100
13+
max_var: 1000
14+
min_var: 0.001
15+
max_known_var: 0.02
16+
17+
# Sampling resolutions
18+
free_resolution: 0.3 # Free space sampling resolution
19+
ds_resolution: 0.1 # Downsampling factor
20+
21+
# Free/Occupied Thresholds
22+
free_thresh: free_thresh
23+
occupied_thresh: 0.7
24+
var_thresh: 1000.0 # Threshold on variance to distinguish known/unknown

include/block.h renamed to include/bgkblock.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef LA3DM_BLOCK_H
2-
#define LA3DM_BLOCK_H
1+
#ifndef LA3DM_BGK_BLOCK_H
2+
#define LA3DM_BGK_BLOCK_H
33

44
#include <unordered_map>
55
#include <array>
66
#include "point3f.h"
7-
#include "octree_node.h"
8-
#include "octree.h"
7+
#include "bgkoctree_node.h"
8+
#include "bgkoctree.h"
99

1010
namespace la3dm {
1111

@@ -106,4 +106,4 @@ namespace la3dm {
106106
};
107107
}
108108

109-
#endif // LA3DM_BLOCK_H
109+
#endif // LA3DM_BGK_BLOCK_H

include/bgkoctomap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#ifndef LA3DM_BGKOCTOMAP_H
2-
#define LA3DM_BGKOCTOMAP_H
1+
#ifndef LA3DM_BGK_OCTOMAP_H
2+
#define LA3DM_BGK_OCTOMAP_H
33

44
#include <unordered_map>
55
#include <vector>
66
#include <pcl/point_cloud.h>
77
#include <pcl/point_types.h>
88
#include "rtree.h"
9-
#include "block.h"
10-
#include "octree_node.h"
9+
#include "bgkblock.h"
10+
#include "bgkoctree_node.h"
1111

1212
namespace la3dm {
1313

include/octree.h renamed to include/bgkoctree.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#ifndef LA3DM_OCTREE_H
2-
#define LA3DM_OCTREE_H
1+
#ifndef LA3DM_BGK_OCTREE_H
2+
#define LA3DM_BGK_OCTREE_H
33

44
#include <stack>
55
#include <vector>
66
#include "point3f.h"
7-
#include "octree_node.h"
7+
#include "bgkoctree_node.h"
88

99
namespace la3dm {
1010

@@ -158,4 +158,4 @@ namespace la3dm {
158158
};
159159
}
160160

161-
#endif // LA3DM_OCTREE_H
161+
#endif // LA3DM_BGK_OCTREE_H

include/octree_node.h renamed to include/bgkoctree_node.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef LA3DM_OCCUPANCY_H
2-
#define LA3DM_OCCUPANCY_H
1+
#ifndef LA3DM_BGK_OCCUPANCY_H
2+
#define LA3DM_BGK_OCCUPANCY_H
33

44
#include <iostream>
55
#include <fstream>
@@ -94,4 +94,4 @@ namespace la3dm {
9494
typedef Occupancy OcTreeNode;
9595
}
9696

97-
#endif // LA3DM_OCCUPANCY_H
97+
#endif // LA3DM_BGK_OCCUPANCY_H

include/gpblock.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#ifndef LA3DM_GP_BLOCK_H
2+
#define LA3DM_GP_BLOCK_H
3+
4+
#include <unordered_map>
5+
#include <array>
6+
#include "point3f.h"
7+
#include "gpoctree_node.h"
8+
#include "gpoctree.h"
9+
10+
namespace la3dm {
11+
12+
/// Hask key to index Block given block's center.
13+
typedef int64_t BlockHashKey;
14+
15+
/// Initialize Look-Up Table
16+
std::unordered_map<OcTreeHashKey, point3f> init_key_loc_map(float resolution, unsigned short max_depth);
17+
18+
std::unordered_map<unsigned short, OcTreeHashKey> init_index_map(const std::unordered_map<OcTreeHashKey, point3f> &key_loc_map,
19+
unsigned short max_depth);
20+
21+
/// Extended Block
22+
#ifdef PREDICT
23+
typedef std::array<BlockHashKey, 27> ExtendedBlock;
24+
#else
25+
typedef std::array<BlockHashKey, 7> ExtendedBlock;
26+
#endif
27+
28+
/// Convert from block to hash key.
29+
BlockHashKey block_to_hash_key(point3f center);
30+
31+
/// Convert from block to hash key.
32+
BlockHashKey block_to_hash_key(float x, float y, float z);
33+
34+
/// Convert from hash key to block.
35+
point3f hash_key_to_block(BlockHashKey key);
36+
37+
/// Get current block's extended block.
38+
ExtendedBlock get_extended_block(BlockHashKey key);
39+
40+
/*
41+
* @brief Block is built on top of OcTree, providing the functions to locate nodes.
42+
*
43+
* Block stores the information needed to locate each OcTreeNode's position:
44+
* fixed resolution, fixed block_size, both of which must be initialized.
45+
* The localization is implemented using Loop-Up Table.
46+
*/
47+
class Block : public OcTree {
48+
friend BlockHashKey block_to_hash_key(point3f center);
49+
50+
friend BlockHashKey block_to_hash_key(float x, float y, float z);
51+
52+
friend point3f hash_key_to_block(BlockHashKey key);
53+
54+
friend ExtendedBlock get_extended_block(BlockHashKey key);
55+
56+
friend class GPOctoMap;
57+
58+
public:
59+
Block();
60+
61+
Block(point3f center);
62+
63+
/// @return location of the OcTreeNode given OcTree's LeafIterator.
64+
inline point3f get_loc(const LeafIterator &it) const {
65+
return Block::key_loc_map[it.get_hash_key()] + center;
66+
}
67+
68+
/// @return size of the OcTreeNode given OcTree's LeafIterator.
69+
inline float get_size(const LeafIterator &it) const {
70+
unsigned short depth, index;
71+
hash_key_to_node(it.get_hash_key(), depth, index);
72+
return float(size / pow(2, depth));
73+
}
74+
75+
/// @return center of current Block.
76+
inline point3f get_center() const { return center; }
77+
78+
/// @return min lim of current Block.
79+
inline point3f get_lim_min() const { return center - point3f(size / 2.0f, size / 2.0f, size / 2.0f); }
80+
81+
/// @return max lim of current Block.
82+
inline point3f get_lim_max() const { return center + point3f(size / 2.0f, size / 2.0f, size / 2.0f); }
83+
84+
/// @return ExtendedBlock of current Block.
85+
ExtendedBlock get_extended_block() const;
86+
87+
OcTreeHashKey get_node(unsigned short x, unsigned short y, unsigned short z) const;
88+
89+
point3f get_point(unsigned short x, unsigned short y, unsigned short z) const;
90+
91+
void get_index(const point3f &p, unsigned short &x, unsigned short &y, unsigned short &z) const;
92+
93+
OcTreeNode &search(float x, float y, float z) const;
94+
95+
OcTreeNode &search(point3f p) const;
96+
97+
private:
98+
// Loop-Up Table
99+
static std::unordered_map<OcTreeHashKey, point3f> key_loc_map;
100+
static std::unordered_map<unsigned short, OcTreeHashKey> index_map;
101+
static float resolution;
102+
static float size;
103+
static unsigned short cell_num;
104+
105+
point3f center;
106+
};
107+
108+
}
109+
110+
#endif // LA3DM_GP_BLOCK_H

0 commit comments

Comments
 (0)