Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef JSK_PCL_ROS_SELF_MASK_NAMED_LINK_H_
00037 #define JSK_PCL_ROS_SELF_MASK_NAMED_LINK_H_
00038
00039 #include <robot_self_filter/self_mask.h>
00040
00041 namespace robot_self_filter
00042 {
00043 class SelfMaskNamedLink : public SelfMask<pcl::PointXYZ>
00044 {
00045 public:
00050 SelfMaskNamedLink(tf::TransformListener& tf, const std::vector<LinkInfo>& links, const std::string& tf_prefix="")
00051 : SelfMask<pcl::PointXYZ>(tf, links),
00052 tf_prefix_(tf_prefix)
00053 {
00054 }
00055
00062 void assumeFrame(const std_msgs::Header& header) {
00063 const unsigned int bs = bodies_.size();
00064
00065
00066 for (unsigned int i = 0 ; i < bs ; ++i) {
00067 std::string err;
00068 if(!tf_.waitForTransform(header.frame_id, tf_prefix_+bodies_[i].name, header.stamp, ros::Duration(.1), ros::Duration(.01), &err)) {
00069 ROS_ERROR("WaitForTransform timed out from %s to %s after 100ms. Error string: %s", (tf_prefix_+bodies_[i].name).c_str(), header.frame_id.c_str(), err.c_str());
00070 }
00071
00072 tf::StampedTransform transf;
00073 try {
00074 tf_.lookupTransform(header.frame_id, tf_prefix_+bodies_[i].name, header.stamp, transf);
00075
00076 }
00077 catch (tf::TransformException& ex) {
00078 transf.setIdentity();
00079 ROS_ERROR("Unable to lookup transform from %s to %s. Exception: %s", (tf_prefix_+bodies_[i].name).c_str(), header.frame_id.c_str(), ex.what());
00080 }
00081
00082
00083 bodies_[i].body->setPose(transf * bodies_[i].constTransf);
00084 bodies_[i].unscaledBody->setPose(transf * bodies_[i].constTransf);
00085 }
00086 computeBoundingSpheres();
00087 }
00088
00089 int getMaskContainmentforNamedLink(const tf::Vector3& pt, const std::string name) const {
00090 const unsigned int bs = bodies_.size();
00091 int out = OUTSIDE;
00092 for (unsigned int j = 0 ; out == OUTSIDE && j < bs ; ++j) {
00093 if (bodies_[j].name == name) {
00094 if (bodies_[j].body->containsPoint(pt))
00095 out = INSIDE;
00096 break;
00097 }
00098 }
00099 return out;
00100 }
00101
00107 int getMaskContainmentforNamedLink(double x, double y, double z, const std::string name) const {
00108 return getMaskContainmentforNamedLink(tf::Vector3(x, y, z), name);
00109 }
00110
00111 protected:
00112 std::string tf_prefix_;
00113 };
00114 }
00115
00116 #endif