37 #ifndef JSK_PCL_ROS_PLANE_SUPPORTED_CUBOID_ESTIMATOR_H_ 38 #define JSK_PCL_ROS_PLANE_SUPPORTED_CUBOID_ESTIMATOR_H_ 44 #include <boost/random.hpp> 45 #include <dynamic_reconfigure/server.h> 53 #include <jsk_recognition_msgs/PolygonArray.h> 54 #include <jsk_recognition_msgs/BoundingBoxArray.h> 55 #include <jsk_recognition_msgs/ModelCoefficientsArray.h> 56 #include <jsk_recognition_msgs/HistogramWithRange.h> 57 #include <jsk_pcl_ros/PlaneSupportedCuboidEstimatorConfig.h> 58 #include <sensor_msgs/PointCloud2.h> 59 #include <std_srvs/Empty.h> 62 #include <pcl/tracking/tracking.h> 65 #include <pcl/kdtree/kdtree_flann.h> 88 template <
class Config>
90 pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud,
91 const std::vector<Polygon::Ptr>& planes,
100 Eigen::Vector3f projected_point;
101 plane->project(Eigen::Vector3f(p.getVector3fMap()), projected_point);
102 if (plane->isInside(projected_point)) {
109 float local_z = plane->distanceToPoint(Eigen::Vector3f(p.getVector3fMap()));
110 likelihood *=
binaryLikelihood(local_z, config.range_likelihood_local_min_z, config.range_likelihood_local_max_z);
114 template <
class Config>
117 const std::vector<Polygon::Ptr>& planes,
118 const Config& config)
121 if (config.use_support_plane_angular_likelihood) {
123 double cos_likelihood = (p.
toEigenMatrix().rotation() * Eigen::Vector3f::UnitX()).
dot(plane->getNormal());
125 return pow(std::abs(cos_likelihood),
126 config.support_plane_angular_likelihood_weight_power);
134 template <
class Config>
137 const Config& config)
139 if (config.use_surface_area_likelihood) {
141 return 1.0 / (1.0 +
pow(v, config.surface_area_error_power));
148 template <
class Config>
151 pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud,
152 pcl::KdTreeFLANN<pcl::PointXYZ>& tree,
153 const Eigen::Vector3f& viewpoint,
154 const Config& config)
157 Eigen::Affine3f pose_inv = pose.inverse();
158 const Eigen::Vector3f local_vp = pose_inv * viewpoint;
161 std::vector<int> candidate_point_indices;
162 std::vector<float> candidate_point_distances;
163 pcl::PointXYZ xyz_point;
164 xyz_point.getVector3fMap() = p.getVector3fMap();
167 tree.radiusSearch(xyz_point, r + config.outlier_distance, candidate_point_indices, candidate_point_distances);
168 if (candidate_point_indices.size() < config.min_inliers) {
176 std::vector<Polygon::Ptr>
faces = cube->faces();
177 for (
size_t i = 0; i < candidate_point_indices.size(); i++) {
178 int index = candidate_point_indices[i];
179 Eigen::Vector3f
v = cloud->points[index].getVector3fMap();
180 if (config.use_occlusion_likelihood) {
182 if (d <= config.outlier_distance) {
184 error +=
pow(d, config.plane_distance_error_power);
189 Eigen::Vector3f local_v = pose_inv * v;
191 if (config.use_inside_points_distance_zero) {
199 if (d <= config.outlier_distance) {
201 error +=
pow(d, config.plane_distance_error_power);
208 size_t expected_num = p.
volume() / config.expected_density / config.expected_density / config.expected_density;
210 if (inliers < config.min_inliers) {
214 double non_inlier_value = 1 / (1 + error / inliers);
215 if (config.use_inliers) {
219 double inlier_likelihood = 1 / (1 +
pow(expected_num - inliers, config.inliers_power));
221 return non_inlier_value * inlier_likelihood;
224 return non_inlier_value;
230 template <
class Config>
232 const std::vector<float>& polygon_likelihood,
233 const Config& config)
235 if (config.use_polygon_likelihood) {
243 template <
class Config>
245 pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud,
246 pcl::KdTreeFLANN<pcl::PointXYZ>& tree,
247 const Eigen::Vector3f& viewpoint,
248 const std::vector<Polygon::Ptr>& polygons,
249 const std::vector<float>& polygon_likelihood,
250 const Config& config)
252 double range_likelihood = 1.0;
253 if (config.use_range_likelihood) {
257 if (range_likelihood == 0.0) {
258 return range_likelihood;
274 typedef PlaneSupportedCuboidEstimatorConfig
Config;
276 jsk_recognition_msgs::PolygonArray,
286 const jsk_recognition_msgs::PolygonArray::ConstPtr&
polygon_msg,
287 const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coef_msg);
289 const sensor_msgs::PointCloud2::ConstPtr&
msg);
291 const sensor_msgs::PointCloud2::ConstPtr& msg);
293 const sensor_msgs::PointCloud2::ConstPtr& msg);
294 virtual pcl::PointCloud<pcl::tracking::ParticleCuboid>::Ptr
initParticles();
301 virtual void likelihood(pcl::PointCloud<pcl::PointXYZ>::ConstPtr input,
305 const std_msgs::Header&
header);
307 std_srvs::EmptyResponse&
res);
315 const std::vector<jsk_recognition_utils::ConvexPolygon::Ptr>& polygons);
399 pcl::KdTreeFLANN<pcl::PointXYZ>
tree_;
PlaneSupportedCuboidEstimator()
pcl::PointCloud< Particle > ParticleCloud
message_filters::Subscriber< jsk_recognition_msgs::PolygonArray > sub_polygon_
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
double min(const OneDataStat &d)
wrapper function for min method for boost::function
virtual void estimate(const sensor_msgs::PointCloud2::ConstPtr &msg)
boost::shared_ptr< message_filters::Synchronizer< PolygonSyncPolicy > > sync_polygon_
ros::Publisher pub_histogram_global_yaw_
virtual size_t getNearestPolygon(const Particle &p, const std::vector< jsk_recognition_utils::ConvexPolygon::Ptr > &polygons)
Compute the nearest polygon to the particle `p'.
double init_world_position_z_min_
double init_local_orientation_pitch_variance_
pcl::tracking::ParticleCuboid Particle
Eigen::Vector3f viewpoint_
double surfaceAreaLikelihood(const pcl::tracking::ParticleCuboid &p, const Config &config)
std::string sensor_frame_
double max(const OneDataStat &d)
wrapper function for max method for boost::function
ros::Publisher pub_histogram_global_x_
virtual void configCallback(Config &config, uint32_t level)
bool use_global_init_yaw_
virtual void updateParticlePolygonRelationship(ParticleCloud::Ptr particles)
Compute distances between particles and polygons and assing each particle to the nearest polygon...
double rangeLikelihood(const pcl::tracking::ParticleCuboid &p, pcl::PointCloud< pcl::PointXYZ >::ConstPtr cloud, const std::vector< Polygon::Ptr > &planes, const Config &config)
ros::Publisher pub_histogram_global_y_
double step_roll_variance_
jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr latest_coefficients_msg_
Eigen::Affine3f toEigenMatrix() const
double init_local_orientation_yaw_variance_
double init_local_orientation_roll_mean_
double fast_cloud_threshold_
double step_pitch_variance_
jsk_pcl_ros::Cube::Ptr toCube() const
T dot(T *pf1, T *pf2, int length)
message_filters::sync_policies::ExactTime< jsk_recognition_msgs::PolygonArray, jsk_recognition_msgs::ModelCoefficientsArray > PolygonSyncPolicy
ros::Publisher pub_histogram_global_roll_
double init_global_orientation_yaw_variance_
virtual void publishHistogram(ParticleCloud::Ptr particles, int index, ros::Publisher &pub, const std_msgs::Header &header)
virtual size_t chooseUniformRandomPlaneIndex(const std::vector< Polygon::Ptr > &polygons)
virtual void fastCloudCallback(const sensor_msgs::PointCloud2::ConstPtr &msg)
std::vector< int > visibleFaceIndices(const Eigen::Vector3f local_view_point) const
pcl::PointCloud< pcl::PointXYZ >::Ptr candidate_cloud_
double binaryLikelihood(double v, double min, double max)
return 1.0 if v satisfies min < v < max, return 0 otherwise.
ros::ServiceServer srv_reset_
pcl::KdTreeFLANN< pcl::PointXYZ > tree_
boost::mt19937 random_generator_
double init_global_orientation_yaw_mean_
double signedDistanceToPlane(const Eigen::Vector3f &v, const int plane_index) const
virtual void polygonCallback(const jsk_recognition_msgs::PolygonArray::ConstPtr &polygon_msg, const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr &coef_msg)
virtual void likelihood(pcl::PointCloud< pcl::PointXYZ >::ConstPtr input, pcl::tracking::ParticleCuboid &p)
jsk_recognition_msgs::PolygonArray::ConstPtr polygon_msg
bool use_init_world_position_z_model_
virtual void unsubscribe()
ros::Publisher pub_histogram_dz_
ros::Publisher pub_candidate_cloud_
virtual pcl::PointCloud< pcl::tracking::ParticleCuboid >::Ptr initParticles()
double step_yaw_variance_
pcl::tracking::ROSCollaborativeParticleFilterTracker< pcl::PointXYZ, pcl::tracking::ParticleCuboid >::Ptr tracker_
boost::shared_ptr< PlaneSupportedCuboidEstimator > Ptr
ros::Publisher pub_histogram_global_pitch_
ros::Publisher pub_histogram_dy_
double init_local_position_z_min_
double init_local_orientation_yaw_mean_
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
ros::Publisher pub_histogram_dx_
double init_local_orientation_roll_variance_
boost::mutex mutex
global mutex.
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
virtual pcl::tracking::ParticleCuboid sample(const pcl::tracking::ParticleCuboid &p)
jsk_recognition_msgs::PolygonArray::ConstPtr latest_polygon_msg_
PlaneSupportedCuboidEstimatorConfig Config
bool support_plane_updated_
ros::Publisher pub_result_
ros::Subscriber sub_fast_cloud_
double computeLikelihood(const pcl::tracking::ParticleCuboid &p, pcl::PointCloud< pcl::PointXYZ >::ConstPtr cloud, pcl::KdTreeFLANN< pcl::PointXYZ > &tree, const Eigen::Vector3f &viewpoint, const std::vector< Polygon::Ptr > &polygons, const std::vector< float > &polygon_likelihood, const Config &config)
double init_world_position_z_max_
virtual bool resetCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
virtual void cloudCallback(const sensor_msgs::PointCloud2::ConstPtr &msg)
int nearestPlaneIndex(const Eigen::Vector3f &local_v) const
double init_local_orientation_pitch_mean_
std::vector< Polygon::Ptr > polygons_
ros::Publisher pub_histogram_global_z_
message_filters::Subscriber< jsk_recognition_msgs::ModelCoefficientsArray > sub_coefficients_
double distanceNearestToPlaneWithOcclusion(const Eigen::Vector3f &v, const std::vector< int > &visible_faces, std::vector< jsk_pcl_ros::Polygon::Ptr > &faces) const
double supportPlaneAngularLikelihood(const pcl::tracking::ParticleCuboid &p, const std::vector< Polygon::Ptr > &planes, const Config &config)
double planeLikelihood(const pcl::tracking::ParticleCuboid &p, const std::vector< float > &polygon_likelihood, const Config &config)
ros::Publisher pub_result_pose_
ros::Subscriber sub_cloud_
ros::Publisher pub_particles_
Cube cube(Eigen::Vector3f(1, 0, 0), Eigen::Quaternionf(0.108755, 0.088921, 0.108755, 0.984092), Eigen::Vector3f(0.3, 0.3, 0.3))
tf::TransformListener * tf_
double distanceFromPlaneBasedError(const pcl::tracking::ParticleCuboid &p, pcl::PointCloud< pcl::PointXYZ >::ConstPtr cloud, pcl::KdTreeFLANN< pcl::PointXYZ > &tree, const Eigen::Vector3f &viewpoint, const Config &config)
double init_local_position_z_max_
bool use_init_polygon_likelihood_