Skip to content

Commit

Permalink
Merge pull request #3182 from SunBlack/readability-else-after-return_…
Browse files Browse the repository at this point in the history
…kdtree-octree

Remove else after return statement [kdtree, keypoints, ml, octree]
  • Loading branch information
taketwo authored Jul 4, 2019
2 parents 6fdf439 + a02a76d commit bb26ea4
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 281 deletions.
14 changes: 4 additions & 10 deletions kdtree/include/pcl/kdtree/kdtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,8 @@ namespace pcl
assert (index >= 0 && index < static_cast<int> (input_->points.size ()) && "Out-of-bounds error in nearestKSearch!");
return (nearestKSearch (input_->points[index], k, k_indices, k_sqr_distances));
}
else
{
assert (index >= 0 && index < static_cast<int> (indices_->size ()) && "Out-of-bounds error in nearestKSearch!");
return (nearestKSearch (input_->points[(*indices_)[index]], k, k_indices, k_sqr_distances));
}
assert (index >= 0 && index < static_cast<int> (indices_->size ()) && "Out-of-bounds error in nearestKSearch!");
return (nearestKSearch (input_->points[(*indices_)[index]], k, k_indices, k_sqr_distances));
}

/** \brief Search for all the nearest neighbors of the query point in a given radius.
Expand Down Expand Up @@ -299,11 +296,8 @@ namespace pcl
assert (index >= 0 && index < static_cast<int> (input_->points.size ()) && "Out-of-bounds error in radiusSearch!");
return (radiusSearch (input_->points[index], radius, k_indices, k_sqr_distances, max_nn));
}
else
{
assert (index >= 0 && index < static_cast<int> (indices_->size ()) && "Out-of-bounds error in radiusSearch!");
return (radiusSearch (input_->points[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
}
assert (index >= 0 && index < static_cast<int> (indices_->size ()) && "Out-of-bounds error in radiusSearch!");
return (radiusSearch (input_->points[(*indices_)[index]], radius, k_indices, k_sqr_distances, max_nn));
}

/** \brief Set the search epsilon precision (error bound) for nearest neighbors searches.
Expand Down
31 changes: 15 additions & 16 deletions keypoints/include/pcl/keypoints/impl/keypoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,24 @@ pcl::Keypoint<PointInT, PointOutT>::initCompute ()
PCL_ERROR ("[pcl::%s::initCompute] Both radius (%f) and K (%d) defined! Set one of them to zero first and then re-run compute ().\n", getClassName ().c_str (), search_radius_, k_);
return (false);
}
else // Use the radiusSearch () function

// Use the radiusSearch () function
search_parameter_ = search_radius_;
if (surface_ == input_) // if the two surfaces are the same
{
search_parameter_ = search_radius_;
if (surface_ == input_) // if the two surfaces are the same
// Declare the search locator definition
search_method_ = [this] (int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
{
// Declare the search locator definition
search_method_ = [this] (int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
{
return tree_->radiusSearch (index, radius, k_indices, k_distances, 0);
};
}
else
return tree_->radiusSearch (index, radius, k_indices, k_distances, 0);
};
}
else
{
// Declare the search locator definition
search_method_surface_ = [this] (const PointCloudIn &cloud, int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
{
// Declare the search locator definition
search_method_surface_ = [this] (const PointCloudIn &cloud, int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
{
return tree_->radiusSearch (cloud, index, radius, k_indices, k_distances, 0);
};
}
return tree_->radiusSearch (cloud, index, radius, k_indices, k_distances, 0);
};
}
}
else
Expand Down
136 changes: 67 additions & 69 deletions keypoints/include/pcl/keypoints/impl/susan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,96 +318,94 @@ pcl::SUSANKeypoint<PointInT, PointOutT, NormalT, IntensityT>::detectKeypoints (P
const NormalT& normal_in = normals_->points [point_index];
if (!isFinite (point_in) || !isFinite (normal_in))
continue;
else

Eigen::Vector3f nucleus = point_in.getVector3fMap ();
Eigen::Vector3f nucleus_normal = normals_->points [point_index].getNormalVector3fMap ();
float nucleus_intensity = intensity_ (point_in);
std::vector<int> nn_indices;
std::vector<float> nn_dists;
tree_->radiusSearch (point_in, search_radius_, nn_indices, nn_dists);
float area = 0;
Eigen::Vector3f centroid = Eigen::Vector3f::Zero ();
// Exclude nucleus from the usan
std::vector<int> usan; usan.reserve (nn_indices.size () - 1);
for (std::vector<int>::const_iterator index = nn_indices.begin(); index != nn_indices.end(); ++index)
{
Eigen::Vector3f nucleus = point_in.getVector3fMap ();
Eigen::Vector3f nucleus_normal = normals_->points [point_index].getNormalVector3fMap ();
float nucleus_intensity = intensity_ (point_in);
std::vector<int> nn_indices;
std::vector<float> nn_dists;
tree_->radiusSearch (point_in, search_radius_, nn_indices, nn_dists);
float area = 0;
Eigen::Vector3f centroid = Eigen::Vector3f::Zero ();
// Exclude nucleus from the usan
std::vector<int> usan; usan.reserve (nn_indices.size () - 1);
for (std::vector<int>::const_iterator index = nn_indices.begin(); index != nn_indices.end(); ++index)
if ((*index != point_index) && std::isfinite (normals_->points[*index].normal_x))
{
if ((*index != point_index) && std::isfinite (normals_->points[*index].normal_x))
// if the point fulfill condition
if ((fabs (nucleus_intensity - intensity_ (input_->points[*index])) <= intensity_threshold_) ||
(1 - nucleus_normal.dot (normals_->points[*index].getNormalVector3fMap ()) <= angular_threshold_))
{
// if the point fulfill condition
if ((fabs (nucleus_intensity - intensity_ (input_->points[*index])) <= intensity_threshold_) ||
(1 - nucleus_normal.dot (normals_->points[*index].getNormalVector3fMap ()) <= angular_threshold_))
{
++area;
centroid += input_->points[*index].getVector3fMap ();
usan.push_back (*index);
}
++area;
centroid += input_->points[*index].getVector3fMap ();
usan.push_back (*index);
}
}
}

float geometric_threshold = 0.5f * (static_cast<float> (nn_indices.size () - 1));
if ((area > 0) && (area < geometric_threshold))
float geometric_threshold = 0.5f * (static_cast<float> (nn_indices.size () - 1));
if ((area > 0) && (area < geometric_threshold))
{
// if no geometric validation required add the point to the response
if (!geometric_validation_)
{
// if no geometric validation required add the point to the response
if (!geometric_validation_)
PointOutT point_out;
point_out.getVector3fMap () = point_in.getVector3fMap ();
//point_out.intensity = geometric_threshold - area;
intensity_out_.set (point_out, geometric_threshold - area);
// if a label field is found use it to save the index
if (label_idx_ != -1)
{
PointOutT point_out;
point_out.getVector3fMap () = point_in.getVector3fMap ();
//point_out.intensity = geometric_threshold - area;
intensity_out_.set (point_out, geometric_threshold - area);
// if a label field is found use it to save the index
if (label_idx_ != -1)
{
// save the index in the cloud
uint32_t label = static_cast<uint32_t> (point_index);
memcpy (reinterpret_cast<char*> (&point_out) + out_fields_[label_idx_].offset,
&label, sizeof (uint32_t));
}
// save the index in the cloud
uint32_t label = static_cast<uint32_t> (point_index);
memcpy (reinterpret_cast<char*> (&point_out) + out_fields_[label_idx_].offset,
&label, sizeof (uint32_t));
}
//#ifdef _OPENMP
//#pragma omp critical
//#endif
response->push_back (point_out);
}
else
response->push_back (point_out);
}
else
{
centroid /= area;
Eigen::Vector3f dist = nucleus - centroid;
// Check the distance <= distance_threshold_
if (dist.norm () >= distance_threshold_)
{
centroid /= area;
Eigen::Vector3f dist = nucleus - centroid;
// Check the distance <= distance_threshold_
if (dist.norm () >= distance_threshold_)
// point is valid from distance point of view
Eigen::Vector3f nc = centroid - nucleus;
// Check the contiguity
auto usan_it = usan.cbegin ();
for (; usan_it != usan.cend (); ++usan_it)
{
// point is valid from distance point of view
Eigen::Vector3f nc = centroid - nucleus;
// Check the contiguity
auto usan_it = usan.cbegin ();
for (; usan_it != usan.cend (); ++usan_it)
if (!isWithinNucleusCentroid (nucleus, centroid, nc, input_->points[*usan_it]))
break;
}
// All points within usan lies on the segment [nucleus centroid]
if (usan_it == usan.end ())
{
PointOutT point_out;
point_out.getVector3fMap () = point_in.getVector3fMap ();
// point_out.intensity = geometric_threshold - area;
intensity_out_.set (point_out, geometric_threshold - area);
// if a label field is found use it to save the index
if (label_idx_ != -1)
{
if (!isWithinNucleusCentroid (nucleus, centroid, nc, input_->points[*usan_it]))
break;
// save the index in the cloud
uint32_t label = static_cast<uint32_t> (point_index);
memcpy (reinterpret_cast<char*> (&point_out) + out_fields_[label_idx_].offset,
&label, sizeof (uint32_t));
}
// All points within usan lies on the segment [nucleus centroid]
if (usan_it == usan.end ())
{
PointOutT point_out;
point_out.getVector3fMap () = point_in.getVector3fMap ();
// point_out.intensity = geometric_threshold - area;
intensity_out_.set (point_out, geometric_threshold - area);
// if a label field is found use it to save the index
if (label_idx_ != -1)
{
// save the index in the cloud
uint32_t label = static_cast<uint32_t> (point_index);
memcpy (reinterpret_cast<char*> (&point_out) + out_fields_[label_idx_].offset,
&label, sizeof (uint32_t));
}
//#ifdef _OPENMP
//#pragma omp critical
//#endif
response->push_back (point_out);
}
response->push_back (point_out);
}
}
}
}
}
}

response->height = 1;
Expand Down
3 changes: 1 addition & 2 deletions keypoints/include/pcl/keypoints/keypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ namespace pcl
{
if (surface_ == input_) // if the two surfaces are the same
return (search_method_ (index, parameter, indices, distances));
else
return (search_method_surface_ (*input_, index, parameter, indices, distances));
return (search_method_surface_ (*input_, index, parameter, indices, distances));
}

protected:
Expand Down
62 changes: 28 additions & 34 deletions keypoints/src/brisk_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,22 @@ pcl::keypoints::brisk::ScaleSpace::getScoreAbove (

return (score);
}
else
{ // intra
const int eighths_x = 6 * x_layer - 1;
const int x_above = eighths_x / 8;
const int eighths_y = 6 * y_layer - 1;
const int y_above = eighths_y / 8;
const int r_x = (eighths_x % 8);
const int r_x_1 = 8 - r_x;
const int r_y = (eighths_y % 8);
const int r_y_1 = 8 - r_y;
uint8_t score = static_cast<uint8_t> (
0xFF & ((r_x_1 * r_y_1 * l.getAgastScore (x_above, y_above, 1) +
r_x * r_y_1 * l.getAgastScore (x_above + 1, y_above, 1) +
r_x_1 * r_y * l.getAgastScore (x_above , y_above + 1, 1) +
r_x * r_y * l.getAgastScore (x_above + 1, y_above + 1, 1) + 32) / 64));
return (score);
}

// intra
const int eighths_x = 6 * x_layer - 1;
const int x_above = eighths_x / 8;
const int eighths_y = 6 * y_layer - 1;
const int y_above = eighths_y / 8;
const int r_x = (eighths_x % 8);
const int r_x_1 = 8 - r_x;
const int r_y = (eighths_y % 8);
const int r_y_1 = 8 - r_y;
uint8_t score = static_cast<uint8_t> (
0xFF & ((r_x_1 * r_y_1 * l.getAgastScore (x_above, y_above, 1) +
r_x * r_y_1 * l.getAgastScore (x_above + 1, y_above, 1) +
r_x_1 * r_y * l.getAgastScore (x_above , y_above + 1, 1) +
r_x * r_y * l.getAgastScore (x_above + 1, y_above + 1, 1) + 32) / 64));
return (score);
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1277,12 +1276,9 @@ pcl::keypoints::brisk::ScaleSpace::subpixel2D (
delta_y = delta_x1;
return (max1);
}
else
{
delta_x = delta_x2;
delta_y = delta_x2;
return (max2);
}
delta_x = delta_x2;
delta_y = delta_x2;
return (max2);
}

// this is the case of the maximum inside the boundaries:
Expand Down Expand Up @@ -1431,17 +1427,15 @@ pcl::keypoints::brisk::Layer::getAgastScore (float xf, float yf, uint8_t thresho

return (static_cast<uint8_t> (value));
}
else
{
// this means we overlap area smoothing
const float halfscale = scale / 2.0f;
// get the scores first:
for (int x = int (xf - halfscale); x <= int (xf + halfscale + 1.0f); x++)
for (int y = int (yf - halfscale); y <= int (yf + halfscale + 1.0f); y++)
getAgastScore (x, y, threshold);
// get the smoothed value
return (getValue (scores_, img_width_, img_height_, xf, yf, scale));
}

// this means we overlap area smoothing
const float halfscale = scale / 2.0f;
// get the scores first:
for (int x = int (xf - halfscale); x <= int (xf + halfscale + 1.0f); x++)
for (int y = int (yf - halfscale); y <= int (yf + halfscale + 1.0f); y++)
getAgastScore (x, y, threshold);
// get the smoothed value
return (getValue (scores_, img_width_, img_height_, xf, yf, scale));
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit bb26ea4

Please sign in to comment.