4 #include <sensor_msgs/PointCloud.h> 
    6 int main(
int argc, 
char** argv)
 
   17       n.
advertise<sensor_msgs::PointCloud>(
"changing_channels_test", 0);
 
   28     sensor_msgs::PointCloud changing_cloud;
 
   31       static sensor_msgs::PointCloud cloud;
 
   33       if (cloud.channels.empty())
 
   35         cloud.header.stamp = tm;
 
   36         cloud.header.frame_id = 
"base_link";
 
   38         cloud.channels.resize(1);
 
   42         int32_t total = xcount * ycount * zcount;
 
   43         cloud.points.resize(total);
 
   44         cloud.channels[0].values.resize(total);
 
   45         cloud.channels[0].name = 
"intensities";
 
   47         for (int32_t x = 0; x < xcount; ++x)
 
   49           for (int32_t y = 0; y < ycount; ++y)
 
   51             for (int32_t z = 0; z < zcount; ++z)
 
   53               int32_t index = (ycount * zcount * x) + zcount * y + z;
 
   54               geometry_msgs::Point32& point = cloud.points[index];
 
   59               cloud.channels[0].values[index] = (index % 4096);
 
   65       million_pub.publish(cloud);
 
   69       sensor_msgs::PointCloud cloud;
 
   70       cloud.header.stamp = tm;
 
   71       cloud.header.frame_id = 
"base_link";
 
   73       cloud.points.resize(5);
 
   74       cloud.channels.resize(2);
 
   75       for (
int j = 0; j < 5; ++j)
 
   77         cloud.points[j].x = (float)j;
 
   78         cloud.points[j].y = 0.0f;
 
   79         cloud.points[j].z = i % 10;
 
   83           cloud.points[j].z = std::numeric_limits<float>::quiet_NaN();
 
   87       cloud.channels[0].name = 
"rgb";
 
   88       cloud.channels[0].values.resize(5);
 
   90       int rgb = (0xff << 16);
 
   91       cloud.channels[0].values[0] = *
reinterpret_cast<float*
>(&rgb);
 
   93       cloud.channels[0].values[1] = *
reinterpret_cast<float*
>(&rgb);
 
   95       cloud.channels[0].values[2] = *
reinterpret_cast<float*
>(&rgb);
 
   96       rgb = (0xff << 16) | (0xff << 8);
 
   97       cloud.channels[0].values[3] = *
reinterpret_cast<float*
>(&rgb);
 
   98       rgb = (0xff << 8) | 0xff;
 
   99       cloud.channels[0].values[4] = *
reinterpret_cast<float*
>(&rgb);
 
  101       cloud.channels[1].name = 
"intensity";
 
  102       cloud.channels[1].values.resize(5);
 
  103       cloud.channels[1].values[0] = 0;
 
  104       cloud.channels[1].values[1] = 100;
 
  105       cloud.channels[1].values[2] = 200;
 
  106       cloud.channels[1].values[3] = 300;
 
  107       cloud.channels[1].values[4] = 400;
 
  113       sensor_msgs::PointCloud cloud;
 
  114       cloud.header.stamp = tm;
 
  115       cloud.header.frame_id = 
"base_link";
 
  117       cloud.points.resize(5);
 
  118       cloud.channels.resize(3);
 
  119       for (
int j = 0; j < 5; ++j)
 
  121         cloud.points[j].x = (float)j;
 
  122         cloud.points[j].y = 1.0f;
 
  123         cloud.points[j].z = i % 10;
 
  126       cloud.channels[0].name = 
"r";
 
  127       cloud.channels[0].values.resize(5);
 
  128       cloud.channels[1].name = 
"g";
 
  129       cloud.channels[1].values.resize(5);
 
  130       cloud.channels[2].name = 
"b";
 
  131       cloud.channels[2].values.resize(5);
 
  133       cloud.channels[0].values[0] = 1.0f;
 
  134       cloud.channels[1].values[0] = 0.0f;
 
  135       cloud.channels[2].values[0] = 0.0f;
 
  137       cloud.channels[0].values[1] = 0.0f;
 
  138       cloud.channels[1].values[1] = 1.0f;
 
  139       cloud.channels[2].values[1] = 0.0f;
 
  141       cloud.channels[0].values[2] = 0.0f;
 
  142       cloud.channels[1].values[2] = 0.0f;
 
  143       cloud.channels[2].values[2] = 1.0f;
 
  145       cloud.channels[0].values[3] = 1.0f;
 
  146       cloud.channels[1].values[3] = 1.0f;
 
  147       cloud.channels[2].values[3] = 0.0f;
 
  149       cloud.channels[0].values[4] = 0.0f;
 
  150       cloud.channels[1].values[4] = 1.0f;
 
  151       cloud.channels[2].values[4] = 1.0f;
 
  153       rgb2_pub.publish(cloud);
 
  155       if ((i % 10) - 5 < 0)
 
  157         changing_cloud = cloud;
 
  162       sensor_msgs::PointCloud cloud;
 
  163       cloud.header.stamp = tm;
 
  164       cloud.header.frame_id = 
"base_link";
 
  168       int total_pts = num_rows * num_cols;
 
  169       cloud.points.resize(total_pts);
 
  170       cloud.channels.resize(1);
 
  171       cloud.channels[0].values.resize(total_pts);
 
  172       cloud.channels[0].name = 
"intensities";
 
  175       for (
int z = 0; z < num_rows; ++z)
 
  177         for (
int x = 0; x < num_cols; ++x, ++j)
 
  179           cloud.points[j].x = x;
 
  180           cloud.points[j].y = 0;
 
  184             cloud.points[j].z = i % 10;
 
  188             cloud.points[j].z = z;
 
  191           cloud.channels[0].values[j] = j;
 
  195       intensity_pub.publish(cloud);
 
  197       if ((i % 10) - 5 >= 0)
 
  199         changing_cloud = cloud;
 
  203     changing_channels_pub.publish(changing_cloud);