44 #ifndef FASTRACK_BOUND_CYLINDER_H 45 #define FASTRACK_BOUND_CYLINDER_H 50 #include <fastrack_srvs/TrackingBoundCylinder.h> 51 #include <fastrack_srvs/TrackingBoundCylinderResponse.h> 66 if (params.size() != 2) {
67 ROS_ERROR(
"Cylinder: params were incorrect size.");
77 void FromRos(
const fastrack_srvs::TrackingBoundCylinder::Response& res) {
82 fastrack_srvs::TrackingBoundCylinder::Response
ToRos()
const {
83 fastrack_srvs::TrackingBoundCylinder::Response res;
92 double radius)
const {
94 if (p(2) + z < center(2) - radius || p(2) - z > center(2) + radius)
98 const double closest_z = std::max(p(2) - z, std::min(p(2) + z, center(2)));
101 const double dz = center(2) - closest_z;
102 const double effective_r = std::sqrt(radius * radius - dz * dz);
104 return (p.head<2>() - center.head<2>()).squaredNorm() <=
105 (effective_r +
r) * (effective_r + r);
109 const Vector3d& upper)
const {
111 if (p(2) < lower(2) - z || p(2) > lower(2) + z)
return false;
114 const double closest_x = std::min(upper(0), std::max(p(0), lower(0)));
115 const double closest_y = std::min(upper(1), std::max(p(1), lower(1)));
116 const double dx = closest_x - p(0);
117 const double dy = closest_y - p(1);
119 return dx * dx + dy * dy <=
r;
125 const Vector3d& upper)
const {
126 return p(0) >= lower(0) + r && p(0) <= upper(0) - r &&
127 p(1) >= lower(1) + r && p(1) <= upper(1) - r &&
128 p(2) >= lower(2) + z && p(2) <= upper(2) -
z;
132 void Visualize(
const ros::Publisher& pub,
const std::string& frame)
const {
133 visualization_msgs::Marker m;
135 m.header.frame_id = frame;
136 m.header.stamp = ros::Time::now();
138 m.type = visualization_msgs::Marker::CYLINDER;
139 m.action = visualization_msgs::Marker::ADD;
bool Initialize(const std::vector< double > ¶ms)
bool OverlapsSphere(const Vector3d &p, const Vector3d ¢er, double radius) const
fastrack_srvs::TrackingBoundCylinder::Response ToRos() const
void FromRos(const fastrack_srvs::TrackingBoundCylinder::Response &res)
bool OverlapsBox(const Vector3d &p, const Vector3d &lower, const Vector3d &upper) const
bool ContainedWithinBox(const Vector3d &p, const Vector3d &lower, const Vector3d &upper) const
void Visualize(const ros::Publisher &pub, const std::string &frame) const