/* * Copyright (c) 2008, 2013, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Authors: Conor McGann */ #ifndef ROBOT_COSTMAP_2D_OBSERVATION_H_ #define ROBOT_COSTMAP_2D_OBSERVATION_H_ #include #include #include namespace robot_costmap_2d { /** * @brief A depth frame and its per-source frustum-clearing configuration. * * The message is shared so returning buffered observations does not copy the * full depth image on every costmap update. */ class DepthCameraObservation { public: DepthCameraObservation() : data_(nullptr), topic_(), pixel_step_(0), min_range_(0.0), max_range_(0.0) { } DepthCameraObservation( const robot_sensor_msgs::DepthCameraData& data, std::string topic, const robot::Time& received_time, unsigned int pixel_step, double min_range, double max_range) : data_(new robot_sensor_msgs::DepthCameraData(data)), topic_(std::move(topic)), received_time_(received_time), pixel_step_(pixel_step), min_range_(min_range), max_range_(max_range) { } // Copy constructor: deep copy DepthCameraObservation(const DepthCameraObservation& other) : data_(other.data_ ? new robot_sensor_msgs::DepthCameraData(*other.data_) : nullptr), topic_(other.topic_), received_time_(other.received_time_), pixel_step_(other.pixel_step_), min_range_(other.min_range_), max_range_(other.max_range_) { } // Copy assignment: deep copy DepthCameraObservation& operator=(const DepthCameraObservation& other) { if (this == &other) { return *this; } robot_sensor_msgs::DepthCameraData* new_data = nullptr; if (other.data_ != nullptr) { new_data = new robot_sensor_msgs::DepthCameraData(*other.data_); } delete data_; data_ = new_data; topic_ = other.topic_; received_time_ = other.received_time_; pixel_step_ = other.pixel_step_; min_range_ = other.min_range_; max_range_ = other.max_range_; return *this; } // Move constructor: chuyển quyền sở hữu DepthCameraObservation(DepthCameraObservation&& other) noexcept : data_(other.data_), topic_(std::move(other.topic_)), received_time_(other.received_time_), pixel_step_(other.pixel_step_), min_range_(other.min_range_), max_range_(other.max_range_) { other.data_ = nullptr; other.pixel_step_ = 0; other.min_range_ = 0.0; other.max_range_ = 0.0; } // Move assignment DepthCameraObservation& operator=(DepthCameraObservation&& other) noexcept { if (this == &other) { return *this; } delete data_; data_ = other.data_; topic_ = std::move(other.topic_); received_time_ = other.received_time_; pixel_step_ = other.pixel_step_; min_range_ = other.min_range_; max_range_ = other.max_range_; other.data_ = nullptr; other.pixel_step_ = 0; other.min_range_ = 0.0; other.max_range_ = 0.0; return *this; } ~DepthCameraObservation() { delete data_; data_ = nullptr; } robot_sensor_msgs::DepthCameraData* data_; std::string topic_; robot::Time received_time_; unsigned int pixel_step_; double min_range_; double max_range_; }; /** * @brief Stores an observation in terms of a point cloud and the origin of the source * @note Tried to make members and constructor arguments const but the compiler would not accept the default * assignment operator for vector insertion! */ class Observation { public: /** * @brief Creates an empty observation */ Observation() : cloud_(new robot_sensor_msgs::PointCloud2()), obstacle_range_(0.0), raytrace_range_(0.0) { } virtual ~Observation() { delete cloud_; } /** * @brief Creates an observation from an origin point and a point cloud * @param origin The origin point of the observation * @param cloud The point cloud of the observation * @param obstacle_range The range out to which an observation should be able to insert obstacles * @param raytrace_range The range out to which an observation should be able to clear via raytracing */ Observation(robot_geometry_msgs::Point& origin, const robot_sensor_msgs::PointCloud2 &cloud, double obstacle_range, double raytrace_range) : origin_(origin), cloud_(new robot_sensor_msgs::PointCloud2(cloud)), obstacle_range_(obstacle_range), raytrace_range_(raytrace_range) { } /** * @brief Copy constructor * @param obs The observation to copy */ Observation(const Observation& obs) : origin_(obs.origin_), cloud_(new robot_sensor_msgs::PointCloud2(*(obs.cloud_))), obstacle_range_(obs.obstacle_range_), raytrace_range_(obs.raytrace_range_) { } /** * @brief Creates an observation from a point cloud * @param cloud The point cloud of the observation * @param obstacle_range The range out to which an observation should be able to insert obstacles */ Observation(const robot_sensor_msgs::PointCloud2 &cloud, double obstacle_range) : cloud_(new robot_sensor_msgs::PointCloud2(cloud)), obstacle_range_(obstacle_range), raytrace_range_(0.0) { } robot_geometry_msgs::Point origin_; robot_sensor_msgs::PointCloud2* cloud_; double obstacle_range_, raytrace_range_; }; } // namespace robot_costmap_2d #endif // ROBOT_COSTMAP_2D_OBSERVATION_H_