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 #include <ias_descriptors_3d/channel.h>
00036
00037 using namespace std;
00038
00039
00040
00041
00042 Channel::Channel(const string& channel_name)
00043 {
00044 channel_name_ = channel_name;
00045 result_size_ = 1;
00046 result_size_defined_ = true;
00047 }
00048
00049
00050
00051
00052 void Channel::clearShared()
00053 {
00054 }
00055
00056
00057
00058
00059 std::string Channel::getName() const
00060 {
00061 return string("TODO: Add a name to this feature.");
00062 }
00063
00064
00065
00066
00067 int Channel::precompute(const sensor_msgs::PointCloud& data,
00068 cloud_kdtree::KdTree& data_kdtree,
00069 const std::vector<const geometry_msgs::Point32*>& interest_pts)
00070 {
00071 return 0;
00072 }
00073
00074
00075
00076
00077 int Channel::precompute(const sensor_msgs::PointCloud& data,
00078 cloud_kdtree::KdTree& data_kdtree,
00079 const std::vector<const std::vector<int>*>& interest_region_indices)
00080 {
00081 return 0;
00082 }
00083
00084
00085
00086
00087 void Channel::doComputation(const sensor_msgs::PointCloud& data,
00088 cloud_kdtree::KdTree& data_kdtree,
00089 const std::vector<const geometry_msgs::Point32*>& interest_pts,
00090 std::vector<std::vector<float> >& results)
00091 {
00092
00093
00094 int channel_idx = cloud_geometry::getChannelIndex(data, channel_name_);
00095 if (channel_idx < 0)
00096 {
00097 ROS_ERROR("Channel::doComputation() could not find channel %s in given point cloud", channel_name_.c_str());
00098 return;
00099 }
00100 const std::vector<sensor_msgs::ChannelFloat32>& pt_cloud_chans = data.channels;
00101
00102
00103
00104
00105 int nbr_interest_pts = interest_pts.size();
00106 #pragma omp parallel for
00107 for (int i = 0 ; i < nbr_interest_pts ; i++)
00108 {
00109
00110 if (interest_pts[static_cast<size_t> (i)] == NULL)
00111 {
00112 ROS_WARN("Channel::doComputation() passed NULL interest point %u", i);
00113 continue;
00114 }
00115 const geometry_msgs::Point32& curr_interest_pt = *(interest_pts[static_cast<size_t> (i)]);
00116
00117
00118
00119 vector<int> neighbor_indices;
00120 vector<float> neighbor_distances;
00121 data_kdtree.nearestKSearch(curr_interest_pt, 1, neighbor_indices, neighbor_distances);
00122 unsigned int nearest_pt_idx = neighbor_indices.at(0);
00123 const geometry_msgs::Point32& nearest_pt = data.points[nearest_pt_idx];
00124
00125
00126
00127 if (cloud_geometry::distances::pointToPointDistanceSqr(curr_interest_pt, nearest_pt) > 1e-8)
00128 {
00129 ROS_WARN("Channel::doComputation() could not find point (%f,%f,%f) in the given point cloud",
00130 curr_interest_pt.x, curr_interest_pt.y, curr_interest_pt.z);
00131 continue;
00132 }
00133
00134
00135
00136 results[static_cast<size_t> (i)].resize(result_size_);
00137 results[static_cast<size_t> (i)][0] = pt_cloud_chans[channel_idx].values[nearest_pt_idx];
00138 }
00139 }
00140
00141
00142
00143
00144 void Channel::doComputation(const sensor_msgs::PointCloud& data,
00145 cloud_kdtree::KdTree& data_kdtree,
00146 const std::vector<const vector<int>*>& interest_region_indices,
00147 std::vector<std::vector<float> >& results)
00148 {
00149
00150
00151 int channel_idx = cloud_geometry::getChannelIndex(data, channel_name_);
00152 if (channel_idx < 0)
00153 {
00154 ROS_ERROR("Channel::doComputation() could not find channel %s in given point cloud", channel_name_.c_str());
00155 return;
00156 }
00157 const std::vector<sensor_msgs::ChannelFloat32>& pt_cloud_chans = data.channels;
00158
00159
00160
00161
00162 int nbr_interest_regions = interest_region_indices.size();
00163 #pragma omp parallel for
00164 for (int i = 0 ; i < nbr_interest_regions ; i++)
00165 {
00166
00167 if (interest_region_indices[static_cast<size_t> (i)] == NULL)
00168 {
00169 ROS_WARN("Channel::doComputation passed NULL interest region %u", i);
00170 continue;
00171 }
00172 const vector<int>& curr_interest_region = *(interest_region_indices[static_cast<size_t> (i)]);
00173
00174
00175
00176 results[static_cast<size_t> (i)].resize(result_size_);
00177 results[static_cast<size_t> (i)][0] = 0.0;
00178
00179
00180
00181 unsigned int nbr_pts_in_region = curr_interest_region.size();
00182 for (unsigned int j = 0 ; j < nbr_pts_in_region ; j++)
00183 {
00184 unsigned int curr_interest_pt_idx = static_cast<unsigned int> (curr_interest_region[j]);
00185 results[static_cast<size_t> (i)][0] += pt_cloud_chans[channel_idx].values.at(
00186 curr_interest_pt_idx);
00187 }
00188
00189
00190
00191 results[static_cast<size_t> (i)][0] /= static_cast<float> (nbr_pts_in_region);
00192 }
00193 }