Skip to content

Commit 14e7f5e

Browse files
Adding optional filter (#172)
* adding filter options to STVL * Update src/spatio_temporal_voxel_layer.cpp Co-authored-by: nickvaras <[email protected]> * adding param description * grammar Co-authored-by: nickvaras <[email protected]>
1 parent e077795 commit 14e7f5e

File tree

8 files changed

+47
-19
lines changed

8 files changed

+47
-19
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Required dependencies ROS Kinetic, navigation, OpenVDB, TBB.
9999

100100
An example fully-described configuration is shown below.
101101

102+
Note: We supply two PCL filters within STVL to massage the data to lower compute overhead. STVL has an approximate voxel filter to make the data more sparse if very dense. It also has a passthrough filter to limit processing data within the valid minimum to maximum height bounds. The voxel filter is recommended if it lowers CPU overhead, otherwise, passthrough filter. No filter is also available if you pre-process your data or are not interested in performance optimizations.
103+
102104
```
103105
rgbd_obstacle_layer:
104106
enabled: true
@@ -130,7 +132,7 @@ rgbd_obstacle_layer:
130132
observation_persistence: 0.0 #default 0, use all measurements taken during now-value, 0=latest
131133
inf_is_valid: false #default false, for laser scans
132134
clear_after_reading: true #default false, clear the buffer after the layer gets readings from it
133-
voxel_filter: true #default off, apply voxel filter to sensor, recommend on
135+
filter: "voxel" #default passthrough, apply "voxel", "passthrough", or no filter to sensor data, recommended to have at one filter on
134136
voxel_min_points: 0 #default 0, minimum points per voxel for voxel filter
135137
rgbd1_clear:
136138
enabled: true #default true, can be toggled on/off with associated service call

example/constrained_indoor_environment_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rgbd_obstacle_layer:
2626
expected_update_rate: 0.0 # default 0, if not updating at this rate at least, remove from buffer
2727
observation_persistence: 0.0 # default 0, use all measurements taken during now-value, 0=latest
2828
inf_is_valid: false # default false, for laser scans
29-
voxel_filter: false # default off, apply voxel filter to sensor, recommend on
29+
filter: "passthrough" # default passthrough, apply "voxel", "passthrough", or no filter to sensor data, recommend on
3030
voxel_min_points: 0 # default 0, minimum points per voxel for voxel filter
3131
clear_after_reading: true # default false, clear the buffer after the layer gets readings from it
3232
rgbd1_clear:

example/outdoor_environment_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rgbd_obstacle_layer:
2626
expected_update_rate: 0.0 # default 0, if not updating at this rate at least, remove from buffer
2727
observation_persistence: 0.0 # default 0, use all measurements taken during now-value, 0=latest
2828
inf_is_valid: false # default false, for laser scans
29-
voxel_filter: false # default off, apply voxel filter to sensor, recommend on
29+
filter: "passthrough" # default passthrough, apply "voxel", "passthrough", or no filter to sensor data, recommend on
3030
voxel_min_points: 0 # default 0, minimum points per voxel for voxel filter
3131
clear_after_reading: true # default false, clear the buffer after the layer gets readings from it
3232
rgbd1_clear:

example/standard_indoor_environment_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rgbd_obstacle_layer:
2626
expected_update_rate: 0.0 # default 0, if not updating at this rate at least, remove from buffer
2727
observation_persistence: 0.0 # default 0, use all measurements taken during now-value, 0=latest
2828
inf_is_valid: false # default false, for laser scans
29-
voxel_filter: false # default off, apply voxel filter to sensor, recommend on
29+
filter: "passthrough" # default passthrough, apply "voxel", "passthrough", or no filter to sensor data, recommend on
3030
voxel_min_points: 0 # default 0, minimum points per voxel for voxel filter
3131
clear_after_reading: true # default false, clear the buffer after the layer gets readings from it
3232
rgbd1_clear:

example/vlp16_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rgbd_obstacle_layer:
2626
expected_update_rate: 0.0 # default 0, if not updating at this rate at least, remove from buffer
2727
observation_persistence: 0.0 # default 0, use all measurements taken during now-value, 0=latest
2828
inf_is_valid: false # default false, for laser scans
29-
voxel_filter: false # default off, apply voxel filter to sensor, recommend on
29+
filter: "voxel" # default passthrough, apply "voxel", "passthrough", or no filter to sensor data, recommend on
3030
voxel_min_points: 0 # default 0, minimum points per voxel for voxel filter
3131
clear_after_reading: true # default false, clear the buffer after the layer gets readings from it
3232
rgbd1_clear:

include/spatio_temporal_voxel_layer/measurement_buffer.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@
6767
namespace buffer
6868
{
6969

70+
enum class Filters
71+
{
72+
NONE = 0,
73+
VOXEL = 1,
74+
PASSTHROUGH = 2
75+
};
76+
7077
// conveniences for line lengths
7178
typedef std::list<observation::MeasurementReading>::iterator readings_iter;
7279
typedef sensor_msgs::PointCloud2::Ptr point_cloud_ptr;
@@ -94,7 +101,7 @@ class MeasurementBuffer
94101
const bool& marking, \
95102
const bool& clearing, \
96103
const double& voxel_size, \
97-
const bool& voxel_filter, \
104+
const Filters& filter, \
98105
const int& voxel_min_points, \
99106
const bool& enabled, \
100107
const bool& clear_buffer_after_reading, \
@@ -135,7 +142,8 @@ class MeasurementBuffer
135142
double _min_obstacle_height, _max_obstacle_height, _obstacle_range, _tf_tolerance;
136143
double _min_z, _max_z, _vertical_fov, _vertical_fov_padding, _horizontal_fov;
137144
double _decay_acceleration, _voxel_size;
138-
bool _marking, _clearing, _voxel_filter, _clear_buffer_after_reading, _enabled;
145+
bool _marking, _clearing, _clear_buffer_after_reading, _enabled;
146+
Filters _filter;
139147
int _voxel_min_points;
140148
ModelType _model_type;
141149
};

src/measurement_buffer.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ MeasurementBuffer::MeasurementBuffer(const std::string& topic_name, \
6161
const bool& marking, \
6262
const bool& clearing, \
6363
const double& voxel_size, \
64-
const bool& voxel_filter, \
64+
const Filters& filter, \
6565
const int& voxel_min_points, \
6666
const bool& enabled, \
6767
const bool& clear_buffer_after_reading, \
@@ -76,7 +76,7 @@ MeasurementBuffer::MeasurementBuffer(const std::string& topic_name, \
7676
_vertical_fov(vFOV), _vertical_fov_padding(vFOVPadding),
7777
_horizontal_fov(hFOV), _decay_acceleration(decay_acceleration),
7878
_marking(marking), _clearing(clearing), _voxel_size(voxel_size),
79-
_voxel_filter(voxel_filter), _voxel_min_points(voxel_min_points),
79+
_filter(filter), _voxel_min_points(voxel_min_points),
8080
_enabled(enabled), _clear_buffer_after_reading(clear_buffer_after_reading),
8181
_model_type(model_type)
8282
{
@@ -147,12 +147,11 @@ void MeasurementBuffer::BufferROSCloud(const sensor_msgs::PointCloud2& cloud)
147147
pcl::PCLPointCloud2::Ptr cloud_pcl (new pcl::PCLPointCloud2 ());
148148
pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ());
149149

150-
pcl_conversions::toPCL(*cld_global, *cloud_pcl);
151-
152150
// remove points that are below or above our height restrictions, and
153151
// in the same time, remove NaNs and if user wants to use it, combine with a
154-
if ( _voxel_filter )
152+
if (_filter == Filters::VOXEL)
155153
{
154+
pcl_conversions::toPCL(*cld_global, *cloud_pcl);
156155
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
157156
sor.setInputCloud (cloud_pcl);
158157
sor.setFilterFieldName("z");
@@ -163,19 +162,21 @@ void MeasurementBuffer::BufferROSCloud(const sensor_msgs::PointCloud2& cloud)
163162
(float)_voxel_size);
164163
sor.setMinimumPointsNumberPerVoxel(static_cast<unsigned int>(_voxel_min_points));
165164
sor.filter(*cloud_filtered);
165+
pcl_conversions::fromPCL(*cloud_filtered, *cld_global);
166166
}
167-
else
167+
else if (_filter == Filters::PASSTHROUGH)
168168
{
169+
pcl_conversions::toPCL(*cld_global, *cloud_pcl);
169170
pcl::PassThrough<pcl::PCLPointCloud2> pass_through_filter;
170171
pass_through_filter.setInputCloud(cloud_pcl);
171172
pass_through_filter.setKeepOrganized(false);
172173
pass_through_filter.setFilterFieldName("z");
173174
pass_through_filter.setFilterLimits( \
174175
_min_obstacle_height,_max_obstacle_height);
175176
pass_through_filter.filter(*cloud_filtered);
177+
pcl_conversions::fromPCL(*cloud_filtered, *cld_global);
176178
}
177179

178-
pcl_conversions::fromPCL(*cloud_filtered, *cld_global);
179180
_observation_list.front()._cloud = cld_global;
180181
}
181182
catch (tf::TransformException& ex)

src/spatio_temporal_voxel_layer.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ void SpatioTemporalVoxelLayer::onInitialize(void)
147147
double observation_keep_time, expected_update_rate, min_obstacle_height;
148148
double max_obstacle_height, min_z, max_z, vFOV, vFOVPadding;
149149
double hFOV, decay_acceleration;
150-
std::string topic, sensor_frame, data_type;
151-
bool inf_is_valid, clearing, marking, voxel_filter, clear_after_reading, enabled;
150+
std::string topic, sensor_frame, data_type, filter_str;
151+
bool inf_is_valid, clearing, marking, clear_after_reading, enabled;
152152
int voxel_min_points;
153+
buffer::Filters filter;
153154

154155
source_node.param("topic", topic, source);
155156
source_node.param("sensor_frame", sensor_frame, std::string(""));
@@ -173,8 +174,8 @@ void SpatioTemporalVoxelLayer::onInitialize(void)
173174
source_node.param("horizontal_fov_angle", hFOV, 1.04);
174175
// acceleration scales the model's decay in presence of readings
175176
source_node.param("decay_acceleration", decay_acceleration, 0.);
176-
// performs an approximate voxel filter over the data to reduce
177-
source_node.param("voxel_filter", voxel_filter, false);
177+
// Apply a PCL filter (Approximate VoxeGrid or PassThrough) or skip
178+
source_node.param("filter", filter_str, std::string("passthrough"));
178179
// minimum points per voxel for voxel filter
179180
source_node.param("voxel_min_points", voxel_min_points, 0);
180181
// clears measurement buffer after reading values from it
@@ -186,6 +187,22 @@ void SpatioTemporalVoxelLayer::onInitialize(void)
186187
source_node.param("model_type", model_type_int, 0);
187188
ModelType model_type = static_cast<ModelType>(model_type_int);
188189

190+
if (filter_str == "passthrough")
191+
{
192+
ROS_INFO("Passthough filter activated.");
193+
filter = buffer::Filters::PASSTHROUGH;
194+
}
195+
else if (filter_str == "voxel")
196+
{
197+
ROS_INFO("Voxel filter activated.");
198+
filter = buffer::Filters::VOXEL;
199+
}
200+
else
201+
{
202+
ROS_INFO("No filters activated.");
203+
filter = buffer::Filters::NONE;
204+
}
205+
189206
if (!sensor_frame.empty())
190207
{
191208
sensor_frame = tf::resolve(tf_prefix, sensor_frame);
@@ -212,7 +229,7 @@ void SpatioTemporalVoxelLayer::onInitialize(void)
212229
obstacle_range, *tf_, _global_frame, sensor_frame, \
213230
transform_tolerance, min_z, max_z, vFOV, vFOVPadding, hFOV, \
214231
decay_acceleration, marking, clearing, _voxel_size, \
215-
voxel_filter, voxel_min_points, enabled, clear_after_reading, \
232+
filter, voxel_min_points, enabled, clear_after_reading, \
216233
model_type)));
217234

218235
// Add buffer to marking observation buffers

0 commit comments

Comments
 (0)