@@ -37,6 +37,9 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
3737 msgBuffer->resize (_msg.row_step () * _msg.height ());
3838 char *msgBufferIndex = msgBuffer->data ();
3939
40+ // Set Pointcloud as dense. Change if invalid points are found.
41+ bool isDense { true };
42+
4043 // For depth calculation from image
4144 double fl = width / (2.0 * std::tan (_hfov.Radian () / 2.0 ));
4245
@@ -54,6 +57,10 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
5457 // Current point depth
5558 float depth = _depthData[j * width + i];
5659
60+ // Validate Depth/Radius and update pointcloud density flag
61+ if (isDense)
62+ isDense = !(gz::math::isnan (depth) || std::isinf (depth));
63+
5764 float yAngle = 0.0 ;
5865 if (fl > 0 && width > 1 )
5966 yAngle = std::atan2 (0.5 * (width - 1 ) - i, fl);
@@ -87,6 +94,7 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
8794 msgBufferIndex += _msg.point_step ();
8895 }
8996 }
97+ _msg.set_is_dense (isDense);
9098}
9199
92100// ////////////////////////////////////////////////
@@ -100,6 +108,9 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
100108 msgBuffer->resize (_msg.row_step () * _msg.height ());
101109 char *msgBufferIndex = msgBuffer->data ();
102110
111+ // Set Pointcloud as dense. Change if invalid points are found.
112+ bool isDense { true };
113+
103114 // Iterate over scan and populate point cloud
104115 for (uint32_t j = 0 ; j < height; ++j)
105116 {
@@ -111,6 +122,14 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
111122 float y = _xyzData[index + 1 ];
112123 float z = _xyzData[index + 2 ];
113124
125+ // Validate Depth/Radius and update pointcloud density flag
126+ if (isDense)
127+ {
128+ isDense = !(gz::math::isnan (x) || std::isinf (x) ||
129+ gz::math::isnan (y) || std::isinf (y) ||
130+ gz::math::isnan (z) || std::isinf (z));
131+ }
132+
114133 int fieldIndex = 0 ;
115134 *reinterpret_cast <float *>(msgBufferIndex +
116135 _msg.field (fieldIndex++).offset ()) = x;
@@ -142,6 +161,7 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
142161 msgBufferIndex += _msg.point_step ();
143162 }
144163 }
164+ _msg.set_is_dense (isDense);
145165}
146166
147167// ////////////////////////////////////////////////
@@ -157,6 +177,9 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
157177 msgBuffer->resize (_msg.row_step () * _msg.height ());
158178 char *msgBufferIndex = msgBuffer->data ();
159179
180+ // Set Pointcloud as dense. Change if invalid points are found.
181+ bool isDense { true };
182+
160183 // Iterate over scan and populate point cloud
161184 for (uint32_t j = 0 ; j < height; ++j)
162185 {
@@ -168,6 +191,14 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
168191 float x = _pointCloudData[pcIndex];
169192 float y = _pointCloudData[pcIndex + 1 ];
170193 float z = _pointCloudData[pcIndex + 2 ];
194+ // Validate Depth/Radius and update pointcloud density flag
195+ if (isDense)
196+ {
197+ isDense = !(gz::math::isnan (x) || std::isinf (x) ||
198+ gz::math::isnan (y) || std::isinf (y) ||
199+ gz::math::isnan (z) || std::isinf (z));
200+ }
201+
171202 float rgba = _pointCloudData[pcIndex + 3 ];
172203
173204 int fieldIndex = 0 ;
@@ -218,6 +249,7 @@ void PointCloudUtil::FillMsg(msgs::PointCloudPacked &_msg,
218249 }
219250 }
220251 }
252+ _msg.set_is_dense (isDense);
221253}
222254
223255
0 commit comments