self_mask_named_link.h
Go to the documentation of this file.
00001 // -*- mode: c++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2015, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
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        // place the links in the assumed frame
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          // find the transform between the link's frame and the pointcloud frame
00072          tf::StampedTransform transf;
00073          try {
00074            tf_.lookupTransform(header.frame_id, tf_prefix_+bodies_[i].name, header.stamp, transf);
00075            // tf_.lookupTransform(header.frame_id, tf_prefix_+bodies_[i].name, header.stamp, transf);
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          // set it for each body; we also include the offset specified in URDF
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


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Tue Jul 2 2019 19:41:45