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      bool 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            return false;
00081          }
00082 
00083          
00084          bodies_[i].body->setPose(transf * bodies_[i].constTransf);
00085          bodies_[i].unscaledBody->setPose(transf * bodies_[i].constTransf);
00086        }
00087        computeBoundingSpheres();
00088        return true;
00089      }
00090 
00091      int getMaskContainmentforNamedLink(const tf::Vector3& pt, const std::string name) const {
00092        const unsigned int bs = bodies_.size();
00093        int out = OUTSIDE;
00094        for (unsigned int j = 0 ; out == OUTSIDE && j < bs ; ++j) {
00095          if (bodies_[j].name == name) {
00096            if (bodies_[j].body->containsPoint(pt))
00097              out = INSIDE;
00098            break;
00099          }
00100        }
00101        return out;
00102      }
00103 
00109      int getMaskContainmentforNamedLink(double x, double y, double z, const std::string name) const {
00110        return getMaskContainmentforNamedLink(tf::Vector3(x, y, z), name);
00111      }
00112 
00113    protected:
00114      std::string tf_prefix_;
00115    };
00116 }
00117 
00118 #endif