5 #include "sensor_msgs/PointCloud.h" 9 int main(
int argc,
char** argv)
20 n.
advertise<sensor_msgs::PointCloud>(
"changing_channels_test", 0);
36 sensor_msgs::PointCloud changing_cloud;
39 static sensor_msgs::PointCloud cloud;
41 if (cloud.channels.empty())
43 cloud.header.stamp = tm;
44 cloud.header.frame_id =
"/base_link";
46 cloud.channels.resize(1);
50 int32_t total = xcount * ycount * zcount;
51 cloud.points.resize(total);
52 cloud.channels[0].values.resize(total);
53 cloud.channels[0].name =
"intensities";
55 for (int32_t x = 0; x < xcount; ++x)
57 for (int32_t y = 0; y < ycount; ++y)
59 for (int32_t z = 0; z < zcount; ++z)
61 int32_t index = (ycount * zcount * x) + zcount * y + z;
62 geometry_msgs::Point32& point = cloud.points[index];
67 cloud.channels[0].values[index] = (index % 4096);
73 million_pub.publish(cloud);
77 sensor_msgs::PointCloud cloud;
78 cloud.header.stamp = tm;
79 cloud.header.frame_id =
"/base_link";
81 cloud.points.resize(5);
82 cloud.channels.resize(2);
83 for (
int j = 0; j < 5; ++j)
85 cloud.points[j].x = (float)j;
86 cloud.points[j].y = 0.0f;
87 cloud.points[j].z = i % 10;
91 cloud.points[j].z = std::numeric_limits<float>::quiet_NaN();
95 cloud.channels[0].name =
"rgb";
96 cloud.channels[0].values.resize(5);
98 int rgb = (0xff << 16);
99 cloud.channels[0].values[0] = *
reinterpret_cast<float*
>(&rgb);
101 cloud.channels[0].values[1] = *
reinterpret_cast<float*
>(&rgb);
103 cloud.channels[0].values[2] = *
reinterpret_cast<float*
>(&rgb);
104 rgb = (0xff << 16) | (0xff << 8);
105 cloud.channels[0].values[3] = *
reinterpret_cast<float*
>(&rgb);
106 rgb = (0xff << 8) | 0xff;
107 cloud.channels[0].values[4] = *
reinterpret_cast<float*
>(&rgb);
109 cloud.channels[1].name =
"intensity";
110 cloud.channels[1].values.resize(5);
111 cloud.channels[1].values[0] = 0;
112 cloud.channels[1].values[1] = 100;
113 cloud.channels[1].values[2] = 200;
114 cloud.channels[1].values[3] = 300;
115 cloud.channels[1].values[4] = 400;
121 sensor_msgs::PointCloud cloud;
122 cloud.header.stamp = tm;
123 cloud.header.frame_id =
"/base_link";
125 cloud.points.resize(5);
126 cloud.channels.resize(3);
127 for (
int j = 0; j < 5; ++j)
129 cloud.points[j].x = (float)j;
130 cloud.points[j].y = 1.0f;
131 cloud.points[j].z = i % 10;
134 cloud.channels[0].name =
"r";
135 cloud.channels[0].values.resize(5);
136 cloud.channels[1].name =
"g";
137 cloud.channels[1].values.resize(5);
138 cloud.channels[2].name =
"b";
139 cloud.channels[2].values.resize(5);
141 cloud.channels[0].values[0] = 1.0f;
142 cloud.channels[1].values[0] = 0.0f;
143 cloud.channels[2].values[0] = 0.0f;
145 cloud.channels[0].values[1] = 0.0f;
146 cloud.channels[1].values[1] = 1.0f;
147 cloud.channels[2].values[1] = 0.0f;
149 cloud.channels[0].values[2] = 0.0f;
150 cloud.channels[1].values[2] = 0.0f;
151 cloud.channels[2].values[2] = 1.0f;
153 cloud.channels[0].values[3] = 1.0f;
154 cloud.channels[1].values[3] = 1.0f;
155 cloud.channels[2].values[3] = 0.0f;
157 cloud.channels[0].values[4] = 0.0f;
158 cloud.channels[1].values[4] = 1.0f;
159 cloud.channels[2].values[4] = 1.0f;
161 rgb2_pub.publish(cloud);
163 if ((i % 10) - 5 < 0)
165 changing_cloud = cloud;
170 sensor_msgs::PointCloud cloud;
171 cloud.header.stamp = tm;
172 cloud.header.frame_id =
"/base_link";
176 int total_pts = num_rows * num_cols;
177 cloud.points.resize(total_pts);
178 cloud.channels.resize(1);
179 cloud.channels[0].values.resize(total_pts);
180 cloud.channels[0].name =
"intensities";
183 for (
int z = 0; z < num_rows; ++z)
185 for (
int x = 0; x < num_cols; ++x, ++j)
187 cloud.points[j].x = x;
188 cloud.points[j].y = 0;
192 cloud.points[j].z = i % 10;
196 cloud.points[j].z = z;
199 cloud.channels[0].values[j] = j;
203 intensity_pub.publish(cloud);
205 if ((i % 10) - 5 >= 0)
207 changing_cloud = cloud;
211 changing_channels_pub.publish(changing_cloud);
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
geometry_msgs::TransformStamped t
void publish(const boost::shared_ptr< M > &message) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)