Skip to content

Commit 9719189

Browse files
authored
Merge pull request #5585 from mvieth/integral_image_normal_fix
Fix access violation in IntegralImageNormalEstimation when using dept…
2 parents a9da50b + a048858 commit 9719189

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

features/include/pcl/features/impl/integral_image_normal.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeatureFull (con
845845
// top and bottom borders
846846
// That sets the output density to false!
847847
output.is_dense = false;
848-
auto border = static_cast<unsigned>(normal_smoothing_size_);
848+
const auto border = static_cast<unsigned>(normal_smoothing_size_);
849849
PointOutT* vec1 = &output [0];
850850
PointOutT* vec2 = vec1 + input_->width * (input_->height - border);
851851

@@ -895,7 +895,13 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeatureFull (con
895895
if (smoothing > 2.0f)
896896
{
897897
setRectSize (static_cast<int> (smoothing), static_cast<int> (smoothing));
898-
computePointNormal (ci, ri, index, output [index]);
898+
// Since depth can be anything, we have no guarantee that the border is sufficient, so we need to check
899+
if(ci>static_cast<unsigned>(rect_width_2_) && ri>static_cast<unsigned>(rect_height_2_) && (ci+rect_width_2_)<input_->width && (ri+rect_height_2_)<input_->height) {
900+
computePointNormal (ci, ri, index, output [index]);
901+
} else {
902+
output[index].getNormalVector3fMap ().setConstant (bad_point);
903+
output[index].curvature = bad_point;
904+
}
899905
}
900906
else
901907
{
@@ -907,8 +913,6 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeatureFull (con
907913
}
908914
else
909915
{
910-
float smoothing_constant = normal_smoothing_size_;
911-
912916
index = border + input_->width * border;
913917
unsigned skip = (border << 1);
914918
for (unsigned ri = border; ri < input_->height - border; ++ri, index += skip)
@@ -924,7 +928,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeatureFull (con
924928
continue;
925929
}
926930

927-
float smoothing = (std::min)(distanceMap[index], smoothing_constant);
931+
float smoothing = (std::min)(distanceMap[index], normal_smoothing_size_);
928932

929933
if (smoothing > 2.0f)
930934
{
@@ -981,8 +985,6 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeatureFull (con
981985
}
982986
else
983987
{
984-
float smoothing_constant = normal_smoothing_size_;
985-
986988
//index = border + input_->width * border;
987989
//unsigned skip = (border << 1);
988990
//for (unsigned ri = border; ri < input_->height - border; ++ri, index += skip)
@@ -1000,7 +1002,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeatureFull (con
10001002
continue;
10011003
}
10021004

1003-
float smoothing = (std::min)(distanceMap[index], smoothing_constant);
1005+
float smoothing = (std::min)(distanceMap[index], normal_smoothing_size_);
10041006

10051007
if (smoothing > 2.0f)
10061008
{
@@ -1027,9 +1029,9 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeaturePart (con
10271029
if (border_policy_ == BORDER_POLICY_IGNORE)
10281030
{
10291031
output.is_dense = false;
1030-
auto border = static_cast<unsigned>(normal_smoothing_size_);
1031-
unsigned bottom = input_->height > border ? input_->height - border : 0;
1032-
unsigned right = input_->width > border ? input_->width - border : 0;
1032+
const auto border = static_cast<unsigned>(normal_smoothing_size_);
1033+
const unsigned bottom = input_->height > border ? input_->height - border : 0;
1034+
const unsigned right = input_->width > border ? input_->width - border : 0;
10331035
if (use_depth_dependent_smoothing_)
10341036
{
10351037
// Iterating over the entire index vector
@@ -1075,7 +1077,6 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeaturePart (con
10751077
}
10761078
else
10771079
{
1078-
float smoothing_constant = normal_smoothing_size_;
10791080
// Iterating over the entire index vector
10801081
for (std::size_t idx = 0; idx < indices_->size (); ++idx)
10811082
{
@@ -1103,7 +1104,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeaturePart (con
11031104
continue;
11041105
}
11051106

1106-
float smoothing = (std::min)(distanceMap[pt_index], smoothing_constant);
1107+
float smoothing = (std::min)(distanceMap[pt_index], normal_smoothing_size_);
11071108

11081109
if (smoothing > 2.0f)
11091110
{
@@ -1154,7 +1155,6 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeaturePart (con
11541155
}
11551156
else
11561157
{
1157-
float smoothing_constant = normal_smoothing_size_;
11581158
for (std::size_t idx = 0; idx < indices_->size (); ++idx)
11591159
{
11601160
unsigned pt_index = (*indices_)[idx];
@@ -1168,7 +1168,7 @@ pcl::IntegralImageNormalEstimation<PointInT, PointOutT>::computeFeaturePart (con
11681168
continue;
11691169
}
11701170

1171-
float smoothing = (std::min)(distanceMap[pt_index], smoothing_constant);
1171+
float smoothing = (std::min)(distanceMap[pt_index], normal_smoothing_size_);
11721172

11731173
if (smoothing > 2.0f)
11741174
{

features/include/pcl/features/integral_image_normal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ namespace pcl
189189
void
190190
setNormalSmoothingSize (float normal_smoothing_size)
191191
{
192-
if (normal_smoothing_size <= 0)
192+
if (normal_smoothing_size < 2.0f)
193193
{
194-
PCL_ERROR ("[pcl::%s::setNormalSmoothingSize] Invalid normal smoothing size given! (%f). Allowed ranges are: 0 < N. Defaulting to %f.\n",
194+
PCL_ERROR ("[pcl::%s::setNormalSmoothingSize] Invalid normal smoothing size given! (%g). Must be at least 2. Defaulting to %g.\n",
195195
feature_name_.c_str (), normal_smoothing_size, normal_smoothing_size_);
196196
return;
197197
}

0 commit comments

Comments
 (0)