Skip to content

Commit f392a2e

Browse files
mergify[bot]Dyst-0iche033
authored
Added invalid point checking to RGBD and Depth Camera plugins to set is_dense flag accordingly (#575) (#578)
(cherry picked from commit e1c5bd6) Signed-off-by: Dyst-0 <69257845+Dyst-0@users.noreply.github.com> Co-authored-by: Dyst-0 <69257845+Dyst-0@users.noreply.github.com> Co-authored-by: Ian Chen <ichen@openrobotics.org>
1 parent 327e3be commit f392a2e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/DepthCameraSensor.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ bool DepthCameraSensor::Update(
624624
// Set the time stamp
625625
*this->dataPtr->pointMsg.mutable_header()->mutable_stamp() =
626626
msgs::Convert(_now);
627-
this->dataPtr->pointMsg.set_is_dense(true);
628627

629628
if (!this->dataPtr->xyzBuffer)
630629
this->dataPtr->xyzBuffer = new float[width*height*3];

src/PointCloudUtil.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/RgbdCameraSensor.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ bool RgbdCameraSensor::Update(const std::chrono::steady_clock::duration &_now)
559559
// Set the time stamp
560560
*this->dataPtr->pointMsg.mutable_header()->mutable_stamp() =
561561
msgs::Convert(_now);
562-
this->dataPtr->pointMsg.set_is_dense(true);
563562

564563
if ((this->dataPtr->hasDepthNearClip || this->dataPtr->hasDepthFarClip)
565564
&& this->dataPtr->depthBuffer)

0 commit comments

Comments
 (0)