Skip to content

Commit 8e6e563

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

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
@@ -627,7 +627,6 @@ bool DepthCameraSensor::Update(
627627
// Set the time stamp
628628
*this->dataPtr->pointMsg.mutable_header()->mutable_stamp() =
629629
msgs::Convert(_now);
630-
this->dataPtr->pointMsg.set_is_dense(true);
631630

632631
if (!this->dataPtr->xyzBuffer)
633632
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
@@ -578,7 +578,6 @@ bool RgbdCameraSensor::Update(const std::chrono::steady_clock::duration &_now)
578578
// Set the time stamp
579579
*this->dataPtr->pointMsg.mutable_header()->mutable_stamp() =
580580
msgs::Convert(_now);
581-
this->dataPtr->pointMsg.set_is_dense(true);
582581

583582
if ((this->dataPtr->hasDepthNearClip || this->dataPtr->hasDepthFarClip)
584583
&& this->dataPtr->depthBuffer)

0 commit comments

Comments
 (0)