Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lazy feature #476

Open
wants to merge 3 commits into
base: jazzy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pcl_ros/include/pcl_ros/filters/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class Filter : public PCLNode<sensor_msgs::msg::PointCloud2>
virtual void
unsubscribe();

/** \brief Create publishers for output PointCloud2 data. */
virtual void
createPublishers();

/** \brief Call the child filter () method, optionally transform the result, and publish it.
* \param input the input point cloud dataset.
* \param indices a pointer to the vector of point indices to use.
Expand Down
1 change: 0 additions & 1 deletion pcl_ros/include/pcl_ros/pcl_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include <pcl_conversions/pcl_conversions.h>
#include <tf2_ros/transform_listener.h>
#include <tf2_ros/buffer.h>
// #include <nodelet_topic_tools/nodelet_lazy.h> // TODO(daisukes): lazy subscription

#include <memory>
#include <string>
Expand Down
3 changes: 1 addition & 2 deletions pcl_ros/src/pcl_ros/filters/crop_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ pcl_ros::CropBox::CropBox(const rclcpp::NodeOptions & options)

config_callback(get_parameters(param_names));

// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();
createPublishers();
}

void
Expand Down
4 changes: 2 additions & 2 deletions pcl_ros/src/pcl_ros/filters/extract_indices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pcl_ros::ExtractIndices::ExtractIndices(const rclcpp::NodeOptions & options)
if (!result.successful) {
throw std::runtime_error(result.reason);
}
// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();

createPublishers();
}

void
Expand Down
16 changes: 15 additions & 1 deletion pcl_ros/src/pcl_ros/filters/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,24 @@ pcl_ros::Filter::unsubscribe()
pcl_ros::Filter::Filter(std::string node_name, const rclcpp::NodeOptions & options)
: PCLNode(node_name, options)
{
pub_output_ = create_publisher<PointCloud2>("output", max_queue_size_);
RCLCPP_DEBUG(this->get_logger(), "Node successfully created.");
}

//////////////////////////////////////////////////////////////////////////////////////////////
void
pcl_ros::Filter::createPublishers()
{
auto pub_options = rclcpp::PublisherOptions();
pub_options.event_callbacks.matched_callback = [this](rclcpp::MatchedInfo & /*info*/) {
if (pub_output_->get_subscription_count() == 0) {
unsubscribe();
} else {
subscribe();
}
};
pub_output_ = create_publisher<PointCloud2>("output", max_queue_size_, pub_options);
}

//////////////////////////////////////////////////////////////////////////////////////////////
void
pcl_ros::Filter::use_frame_params()
Expand Down
3 changes: 1 addition & 2 deletions pcl_ros/src/pcl_ros/filters/passthrough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ pcl_ros::PassThrough::PassThrough(const rclcpp::NodeOptions & options)

config_callback(get_parameters(param_names));

// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();
createPublishers();
}

void pcl_ros::PassThrough::filter(
Expand Down
3 changes: 1 addition & 2 deletions pcl_ros/src/pcl_ros/filters/project_inliers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ pcl_ros::ProjectInliers::ProjectInliers(const rclcpp::NodeOptions & options)
impl_.setCopyAllFields(copy_all_fields);
impl_.setCopyAllData(copy_all_data);

// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();
createPublishers();
}

void
Expand Down
3 changes: 1 addition & 2 deletions pcl_ros/src/pcl_ros/filters/radius_outlier_removal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ pcl_ros::RadiusOutlierRemoval::RadiusOutlierRemoval(const rclcpp::NodeOptions &

config_callback(get_parameters(param_names));

// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();
createPublishers();
}

void
Expand Down
3 changes: 1 addition & 2 deletions pcl_ros/src/pcl_ros/filters/statistical_outlier_removal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ pcl_ros::StatisticalOutlierRemoval::StatisticalOutlierRemoval(const rclcpp::Node

config_callback(get_parameters(param_names));

// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();
createPublishers();
}

void
Expand Down
3 changes: 1 addition & 2 deletions pcl_ros/src/pcl_ros/filters/voxel_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ pcl_ros::VoxelGrid::VoxelGrid(const rclcpp::NodeOptions & options)

config_callback(get_parameters(param_names));

// TODO(daisukes): lazy subscription after rclcpp#2060
subscribe();
createPublishers();
}

void
Expand Down