point_cloud_transformers.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef POINT_CLOUD_TRANSFORMERS_H
00031 #define POINT_CLOUD_TRANSFORMERS_H
00032 
00033 #include <sensor_msgs/PointCloud2.h>
00034 
00035 #include "point_cloud_transformer.h"
00036 
00037 namespace rviz
00038 {
00039 
00040 class BoolProperty;
00041 class ColorProperty;
00042 class EditableEnumProperty;
00043 class EnumProperty;
00044 class FloatProperty;
00045 
00046 typedef std::vector<std::string> V_string; 
00047 
00048 inline int32_t findChannelIndex(const sensor_msgs::PointCloud2ConstPtr& cloud, const std::string& channel)
00049 {
00050   for (size_t i = 0; i < cloud->fields.size(); ++i)
00051   {
00052     if (cloud->fields[i].name == channel)
00053     {
00054       return i;
00055     }
00056   }
00057 
00058   return -1;
00059 }
00060 
00061 template<typename T>
00062 inline T valueFromCloud(const sensor_msgs::PointCloud2ConstPtr& cloud, uint32_t offset, uint8_t type, uint32_t point_step, uint32_t index)
00063 {
00064   const uint8_t* data = &cloud->data[(point_step * index) + offset];
00065   T ret = 0;
00066 
00067   switch (type)
00068   {
00069   case sensor_msgs::PointField::INT8:
00070   case sensor_msgs::PointField::UINT8:
00071     {
00072       uint8_t val = *reinterpret_cast<const uint8_t*>(data);
00073       ret = static_cast<T>(val);
00074       break;
00075     }
00076 
00077   case sensor_msgs::PointField::INT16:
00078   case sensor_msgs::PointField::UINT16:
00079     {
00080       uint16_t val = *reinterpret_cast<const uint16_t*>(data);
00081       ret = static_cast<T>(val);
00082       break;
00083     }
00084 
00085   case sensor_msgs::PointField::INT32:
00086   case sensor_msgs::PointField::UINT32:
00087     {
00088       uint32_t val = *reinterpret_cast<const uint32_t*>(data);
00089       ret = static_cast<T>(val);
00090       break;
00091     }
00092 
00093   case sensor_msgs::PointField::FLOAT32:
00094     {
00095       float val = *reinterpret_cast<const float*>(data);
00096       ret = static_cast<T>(val);
00097       break;
00098     }
00099 
00100   case sensor_msgs::PointField::FLOAT64:
00101     {
00102       double val = *reinterpret_cast<const double*>(data);
00103       ret = static_cast<T>(val);
00104       break;
00105     }
00106   default:
00107     break;
00108   }
00109 
00110   return ret;
00111 }
00112 
00113 class IntensityPCTransformer : public PointCloudTransformer
00114 {
00115 Q_OBJECT
00116 public:
00117   virtual uint8_t supports(const sensor_msgs::PointCloud2ConstPtr& cloud);
00118   virtual bool transform(const sensor_msgs::PointCloud2ConstPtr& cloud,
00119                          uint32_t mask,
00120                          const Ogre::Matrix4& transform,
00121                          V_PointCloudPoint& points_out);
00122   virtual uint8_t score(const sensor_msgs::PointCloud2ConstPtr& cloud);
00123   virtual void createProperties( Property* parent_property, uint32_t mask, QList<Property*>& out_props );
00124   void updateChannels(const sensor_msgs::PointCloud2ConstPtr& cloud); 
00125 
00126 private Q_SLOTS:
00127   void updateUseRainbow();
00128   void updateAutoComputeIntensityBounds();
00129 
00130 private:
00131   V_string available_channels_;
00132 
00133   ColorProperty* min_color_property_;
00134   ColorProperty* max_color_property_;
00135   BoolProperty* auto_compute_intensity_bounds_property_;
00136   BoolProperty* use_rainbow_property_;
00137   FloatProperty* min_intensity_property_;
00138   FloatProperty* max_intensity_property_;
00139   EditableEnumProperty* channel_name_property_;
00140 };
00141 
00142 class XYZPCTransformer : public PointCloudTransformer
00143 {
00144 Q_OBJECT
00145 public:
00146   virtual uint8_t supports(const sensor_msgs::PointCloud2ConstPtr& cloud);
00147   virtual bool transform(const sensor_msgs::PointCloud2ConstPtr& cloud, uint32_t mask, const Ogre::Matrix4& transform, V_PointCloudPoint& points_out);
00148 };
00149 
00150 
00151 
00152 class RGB8PCTransformer : public PointCloudTransformer
00153 {
00154 Q_OBJECT
00155 public:
00156   virtual uint8_t supports(const sensor_msgs::PointCloud2ConstPtr& cloud);
00157   virtual bool transform(const sensor_msgs::PointCloud2ConstPtr& cloud, uint32_t mask, const Ogre::Matrix4& transform, V_PointCloudPoint& points_out);
00158 };
00159 
00160 
00161 
00162 class RGBF32PCTransformer : public PointCloudTransformer
00163 {
00164 Q_OBJECT
00165 public:
00166   virtual uint8_t supports(const sensor_msgs::PointCloud2ConstPtr& cloud);
00167   virtual bool transform(const sensor_msgs::PointCloud2ConstPtr& cloud, uint32_t mask, const Ogre::Matrix4& transform, V_PointCloudPoint& points_out);
00168 };
00169 
00170 
00171 
00172 class FlatColorPCTransformer : public PointCloudTransformer
00173 {
00174 Q_OBJECT
00175 public:
00176   virtual uint8_t supports(const sensor_msgs::PointCloud2ConstPtr& cloud);
00177   virtual bool transform(const sensor_msgs::PointCloud2ConstPtr& cloud, uint32_t mask, const Ogre::Matrix4& transform, V_PointCloudPoint& points_out);
00178   virtual void createProperties( Property* parent_property, uint32_t mask, QList<Property*>& out_props );
00179   virtual uint8_t score(const sensor_msgs::PointCloud2ConstPtr& cloud);
00180 
00181 private:
00182   ColorProperty* color_property_;
00183 };
00184 
00185 class AxisColorPCTransformer : public PointCloudTransformer
00186 {
00187 Q_OBJECT
00188 public:
00189   virtual uint8_t supports(const sensor_msgs::PointCloud2ConstPtr& cloud);
00190   virtual bool transform(const sensor_msgs::PointCloud2ConstPtr& cloud, uint32_t mask, const Ogre::Matrix4& transform, V_PointCloudPoint& points_out);
00191   virtual void createProperties( Property* parent_property, uint32_t mask, QList<Property*>& out_props );
00192   virtual uint8_t score(const sensor_msgs::PointCloud2ConstPtr& cloud);
00193 
00194   enum Axis
00195   {
00196     AXIS_X,
00197     AXIS_Y,
00198     AXIS_Z
00199   };
00200 
00201 private Q_SLOTS:
00202   void updateAutoComputeBounds();
00203 
00204 private:
00205   BoolProperty* auto_compute_bounds_property_;
00206   FloatProperty* min_value_property_;
00207   FloatProperty* max_value_property_;
00208   EnumProperty* axis_property_;
00209   BoolProperty* use_fixed_frame_property_;
00210 };
00211 
00212 }
00213 
00214 #endif // POINT_CLOUD_TRANSFORMERS_H


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:35