40 #include <geometry_msgs/PolygonStamped.h> 54 NODELET_DEBUG (
"[%s::onInit] Nodelet successfully created with the following parameters:\n" 55 " - use_indices : %s",
123 output.header = cloud->header;
128 if (indices && !
isValid (indices,
"indices"))
132 output.header = cloud->header;
140 " - PointCloud with %d data points (%s), stamp %f, and frame %s on topic %s received.\n" 141 " - PointIndices with %zu values, stamp %f, and frame %s on topic %s received.",
146 NODELET_DEBUG (
"[%s::input_indices_callback] PointCloud with %d data points, stamp %f, and frame %s on topic %s received.",
getName ().c_str (), cloud->width * cloud->height,
fromPCL(cloud->header).stamp.toSec (), cloud->header.frame_id.c_str (),
getMTPrivateNodeHandle ().
resolveName (
"input").c_str ());
151 indices_ptr.reset (
new std::vector<int> (indices->indices));
154 impl_.setIndices (indices_ptr);
157 impl_.reconstruct (output);
160 if (output.points.size () >= 3)
162 geometry_msgs::PolygonStamped poly;
163 poly.header =
fromPCL(output.header);
164 poly.polygon.points.resize (output.points.size ());
166 pcl::Vector4fMap O = output.points[1].getVector4fMap ();
167 pcl::Vector4fMap B = output.points[0].getVector4fMap ();
168 pcl::Vector4fMap A = output.points[2].getVector4fMap ();
170 Eigen::Vector4f OA = A - O;
171 Eigen::Vector4f OB = B - O;
172 Eigen::Vector4f N = OA.cross3 (OB);
173 double theta = N.dot (O);
174 bool reversed =
false;
175 if (theta < (M_PI / 2.0))
177 for (
size_t i = 0; i < output.points.size (); ++i)
181 size_t j = output.points.size () - i - 1;
182 poly.polygon.points[i].x = output.points[j].x;
183 poly.polygon.points[i].y = output.points[j].y;
184 poly.polygon.points[i].z = output.points[j].z;
188 poly.polygon.points[i].x = output.points[i].x;
189 poly.polygon.points[i].y = output.points[i].y;
190 poly.polygon.points[i].z = output.points[i].z;
193 pub_plane_.
publish (boost::make_shared<const geometry_msgs::PolygonStamped> (poly));
196 output.header = cloud->header;
virtual void unsubscribe()
std::string getFieldsList(const sensor_msgs::PointCloud2 &cloud)
#define NODELET_ERROR(...)
boost::shared_ptr< message_filters::Synchronizer< sync_policies::ExactTime< PointCloud, PointIndices > > > sync_input_indices_e_
Synchronized input, and indices.
virtual void onInit()
Nodelet initialization routine. Reads in global parameters used by all nodelets.
ros::Subscriber sub_input_
The input PointCloud subscriber.
ros::Publisher pub_plane_
Publisher for PolygonStamped.
ConvexHull2D represents a 2D ConvexHull implementation.
message_filters::Subscriber< PointIndices > sub_indices_filter_
The message filter subscriber for PointIndices.
void input_indices_callback(const PointCloudConstPtr &cloud, const PointIndicesConstPtr &indices)
Input point cloud callback.
bool isValid(const PointCloud2::ConstPtr &cloud, const std::string &topic_name="input")
Test whether a given PointCloud message is "valid" (i.e., has points, and width and height are non-ze...
ros::NodeHandle & getMTPrivateNodeHandle() const
const std::string & getName() const
void publish(const boost::shared_ptr< M > &message) const
virtual void subscribe()
LazyNodelet connection routine.
pcl::ConvexHull< pcl::PointXYZ > impl_
The PCL implementation used.
std::string resolveName(const std::string &name, bool remap=true) const
pcl::PointCloud< pcl::PointXYZ > PointCloud
virtual void onInit()
Nodelet initialization routine.
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
bool approximate_sync_
True if we use an approximate time synchronizer versus an exact one (false by default).
pcl::IndicesPtr IndicesPtr
int max_queue_size_
The maximum queue size (default: 3).
ros::Publisher pub_output_
The output PointCloud publisher.
boost::shared_ptr< message_filters::Synchronizer< sync_policies::ApproximateTime< PointCloud, PointIndices > > > sync_input_indices_a_
void fromPCL(const std::uint64_t &pcl_stamp, ros::Time &stamp)
uint32_t getNumSubscribers() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
boost::shared_ptr< T > pcl_ptr(const boost::shared_ptr< T > &p)
#define NODELET_DEBUG(...)
pcl_ros::ConvexHull2D ConvexHull2D
bool use_indices_
Set to true if point indices are used.
PointIndices::ConstPtr PointIndicesConstPtr
boost::shared_ptr< T > ros_ptr(const boost::shared_ptr< T > &p)
message_filters::Subscriber< PointCloud > sub_input_filter_
The message filter subscriber for PointCloud2.