|
| 1 | +// Copyright 2023 TIER IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/* |
| 16 | + * |
| 17 | + * Software License Agreement (BSD License) |
| 18 | + * |
| 19 | + * Copyright (c) 2010, Willow Garage, Inc. |
| 20 | + * All rights reserved. |
| 21 | + * |
| 22 | + * Redistribution and use in source and binary forms, with or without |
| 23 | + * modification, are permitted provided that the following conditions |
| 24 | + * are met: |
| 25 | + * |
| 26 | + * * Redistributions of source code must retain the above copyright |
| 27 | + * notice, this list of conditions and the following disclaimer. |
| 28 | + * * Redistributions in binary form must reproduce the above |
| 29 | + * copyright notice, this list of conditions and the following |
| 30 | + * disclaimer in the documentation and/or other materials provided |
| 31 | + * with the distribution. |
| 32 | + * * Neither the name of Willow Garage, Inc. nor the names of its |
| 33 | + * contributors may be used to endorse or promote products derived |
| 34 | + * from this software without specific prior written permission. |
| 35 | + * |
| 36 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 37 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 38 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 39 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 40 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 41 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 42 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 43 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 44 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 45 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 46 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 47 | + * POSSIBILITY OF SUCH DAMAGE. |
| 48 | + * |
| 49 | + * $Id: cropboxes.cpp |
| 50 | + * |
| 51 | + */ |
| 52 | + |
| 53 | +#ifndef POINTCLOUD_PREPROCESSOR__CROP_BOX_FILTER__CROP_BOXES_FILTER_NODELET_HPP_ |
| 54 | +#define POINTCLOUD_PREPROCESSOR__CROP_BOX_FILTER__CROP_BOXES_FILTER_NODELET_HPP_ |
| 55 | + |
| 56 | +#include "pointcloud_preprocessor/filter.hpp" |
| 57 | +#include "pointcloud_preprocessor/transform_info.hpp" |
| 58 | + |
| 59 | +#include <geometry_msgs/msg/polygon_stamped.hpp> |
| 60 | + |
| 61 | +#include <pcl/filters/crop_box.h> |
| 62 | + |
| 63 | +#include <string> |
| 64 | +#include <unordered_map> |
| 65 | +#include <vector> |
| 66 | + |
| 67 | +namespace pointcloud_preprocessor |
| 68 | +{ |
| 69 | +class CropBoxesFilterComponent : public pointcloud_preprocessor::Filter |
| 70 | +{ |
| 71 | +protected: |
| 72 | + bool load_crop_boxes_parameters(); |
| 73 | + |
| 74 | + virtual void filter( |
| 75 | + const PointCloud2ConstPtr & input, const IndicesPtr & indices, PointCloud2 & output); |
| 76 | + |
| 77 | + // TODO(sykwer): Temporary Implementation: Remove this interface when all the filter nodes conform |
| 78 | + // to new API |
| 79 | + virtual void faster_filter( |
| 80 | + const PointCloud2ConstPtr & input, const IndicesPtr & indices, PointCloud2 & output, |
| 81 | + const TransformInfo & transform_info); |
| 82 | + |
| 83 | + void publishCropBoxPolygons(); |
| 84 | + |
| 85 | +private: |
| 86 | + struct CropBoxParam |
| 87 | + { |
| 88 | + float min_x; |
| 89 | + float max_x; |
| 90 | + float min_y; |
| 91 | + float max_y; |
| 92 | + float min_z; |
| 93 | + float max_z; |
| 94 | + bool negative{false}; |
| 95 | + }; |
| 96 | + |
| 97 | + std::unordered_map<std::string, CropBoxParam> crop_box_params_; |
| 98 | + |
| 99 | + std::unordered_map<std::string, rclcpp::Publisher<geometry_msgs::msg::PolygonStamped>::SharedPtr> |
| 100 | + crop_box_polygon_pubs_; |
| 101 | + |
| 102 | + /** \brief Parameter service callback result : needed to be hold */ |
| 103 | + OnSetParametersCallbackHandle::SharedPtr set_param_res_; |
| 104 | + |
| 105 | + /** \brief Parameter service callback */ |
| 106 | + rcl_interfaces::msg::SetParametersResult paramCallback(const std::vector<rclcpp::Parameter> & p); |
| 107 | + |
| 108 | +public: |
| 109 | + PCL_MAKE_ALIGNED_OPERATOR_NEW |
| 110 | + explicit CropBoxesFilterComponent(const rclcpp::NodeOptions & options); |
| 111 | +}; |
| 112 | +} // namespace pointcloud_preprocessor |
| 113 | + |
| 114 | +#endif // POINTCLOUD_PREPROCESSOR__CROP_BOX_FILTER__CROP_BOXES_FILTER_NODELET_HPP_ |
0 commit comments