Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace raw arrays with std::vectors in RangeImageBorderExtractor #3533

Merged
merged 3 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions features/include/pcl/features/range_image_border_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ namespace pcl
getRangeImage () const { return *range_image_; }

float*
getBorderScoresLeft () { extractBorderScoreImages (); return border_scores_left_; }
getBorderScoresLeft () { extractBorderScoreImages (); return border_scores_left_.data (); }

float*
getBorderScoresRight () { extractBorderScoreImages (); return border_scores_right_; }
getBorderScoresRight () { extractBorderScoreImages (); return border_scores_right_.data (); }

float*
getBorderScoresTop () { extractBorderScoreImages (); return border_scores_top_; }
getBorderScoresTop () { extractBorderScoreImages (); return border_scores_top_.data (); }

float*
getBorderScoresBottom () { extractBorderScoreImages (); return border_scores_bottom_; }
getBorderScoresBottom () { extractBorderScoreImages (); return border_scores_bottom_.data (); }

LocalSurface**
getSurfaceStructure () { extractLocalSurfaceStructure (); return surface_structure_; }
Expand All @@ -182,7 +182,8 @@ namespace pcl
Parameters parameters_;
const RangeImage* range_image_;
int range_image_size_during_extraction_;
float* border_scores_left_, * border_scores_right_, * border_scores_top_, * border_scores_bottom_;
std::vector<float> border_scores_left_, border_scores_right_;
std::vector<float> border_scores_top_, border_scores_bottom_;
LocalSurface** surface_structure_;
PointCloudOut* border_descriptions_;
ShadowBorderIndices** shadow_border_informations_;
Expand Down Expand Up @@ -347,6 +348,10 @@ namespace pcl
/** \brief Implementation of abstract derived function */
void
computeFeature (PointCloudOut &output) override;

private:
std::vector<float>
updatedScoresAccordingToNeighborValues (const std::vector<float>& border_scores) const;
};
} // namespace end

Expand Down
60 changes: 29 additions & 31 deletions features/src/range_image_border_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace pcl
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
RangeImageBorderExtractor::RangeImageBorderExtractor(const RangeImage* range_image) :
range_image_(range_image), range_image_size_during_extraction_(0),
border_scores_left_(nullptr), border_scores_right_(nullptr), border_scores_top_(nullptr), border_scores_bottom_(nullptr),
surface_structure_(nullptr), border_descriptions_(nullptr), shadow_border_informations_(nullptr), border_directions_(nullptr),
surface_change_scores_(nullptr), surface_change_directions_(nullptr)
{
Expand All @@ -79,10 +78,6 @@ RangeImageBorderExtractor::setRangeImage (const RangeImage* range_image)
void
RangeImageBorderExtractor::clearData ()
{
delete[] border_scores_left_; border_scores_left_ = nullptr;
delete[] border_scores_right_; border_scores_right_ = nullptr;
delete[] border_scores_top_; border_scores_top_ = nullptr;
delete[] border_scores_bottom_; border_scores_bottom_ = nullptr;
//std::cout << PVARC(range_image_size_during_extraction_)<<PVARN((void*)this);
for (int i=0; i<range_image_size_during_extraction_; ++i)
{
Expand Down Expand Up @@ -153,7 +148,7 @@ RangeImageBorderExtractor::extractLocalSurfaceStructure ()
void
RangeImageBorderExtractor::extractBorderScoreImages ()
{
if (border_scores_left_ != nullptr)
if (border_scores_left_.empty())
return;

extractLocalSurfaceStructure();
Expand All @@ -163,10 +158,10 @@ RangeImageBorderExtractor::extractBorderScoreImages ()
int width = range_image_->width,
height = range_image_->height,
size = width*height;
border_scores_left_ = new float[size];
border_scores_right_ = new float[size];
border_scores_top_ = new float[size];
border_scores_bottom_ = new float[size];
border_scores_left_.resize (size);
border_scores_right_.resize (size);
border_scores_top_.resize (size);
border_scores_bottom_ .resize (size);

# pragma omp parallel for num_threads(parameters_.max_no_of_threads) default(shared) schedule(dynamic, 10)
for (int y=0; y<height; ++y) {
Expand Down Expand Up @@ -201,6 +196,17 @@ RangeImageBorderExtractor::updatedScoresAccordingToNeighborValues (const float*
return (new_scores);
}

std::vector<float>
RangeImageBorderExtractor::updatedScoresAccordingToNeighborValues (const std::vector<float>& border_scores) const
{
std::vector<float> new_border_scores;
new_border_scores.reserve (range_image_->width*range_image_->height);
for (int y=0; y < static_cast<int> (range_image_->height); ++y)
for (int x=0; x < static_cast<int> (range_image_->width); ++x)
new_border_scores.push_back (updatedScoreAccordingToNeighborValues(x, y, border_scores.data ()));
return new_border_scores;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
RangeImageBorderExtractor::updateScoresAccordingToNeighborValues ()
Expand All @@ -209,18 +215,10 @@ RangeImageBorderExtractor::updateScoresAccordingToNeighborValues ()

//MEASURE_FUNCTION_TIME;

float* left_with_propagated_neighbors = updatedScoresAccordingToNeighborValues(border_scores_left_);
delete[] border_scores_left_;
border_scores_left_ = left_with_propagated_neighbors;
float* right_with_propagated_neighbors = updatedScoresAccordingToNeighborValues(border_scores_right_);
delete[] border_scores_right_;
border_scores_right_ = right_with_propagated_neighbors;
float* top_with_propagated_neighbors = updatedScoresAccordingToNeighborValues(border_scores_top_);
delete[] border_scores_top_;
border_scores_top_ = top_with_propagated_neighbors;
float* bottom_with_propagated_neighbors = updatedScoresAccordingToNeighborValues(border_scores_bottom_);
delete[] border_scores_bottom_;
border_scores_bottom_ = bottom_with_propagated_neighbors;
border_scores_left_ = updatedScoresAccordingToNeighborValues(border_scores_left_);
border_scores_right_ = updatedScoresAccordingToNeighborValues(border_scores_right_);
border_scores_top_ = updatedScoresAccordingToNeighborValues(border_scores_top_);
border_scores_bottom_ = updatedScoresAccordingToNeighborValues(border_scores_bottom_);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -230,7 +228,7 @@ RangeImageBorderExtractor::findAndEvaluateShadowBorders ()
if (shadow_border_informations_ != nullptr)
return;

if (border_scores_left_==nullptr)
if (border_scores_left_.empty ())
{
std::cerr << __PRETTY_FUNCTION__<<": border score images not available!\n";
}
Expand All @@ -249,22 +247,22 @@ RangeImageBorderExtractor::findAndEvaluateShadowBorders ()
shadow_border_indices = nullptr;
int shadow_border_idx;

if (changeScoreAccordingToShadowBorderValue(x, y, -1, 0, border_scores_left_, border_scores_right_, shadow_border_idx))
if (changeScoreAccordingToShadowBorderValue(x, y, -1, 0, border_scores_left_.data (), border_scores_right_.data (), shadow_border_idx))
{
shadow_border_indices = (shadow_border_indices==nullptr ? new ShadowBorderIndices : shadow_border_indices);
shadow_border_indices->left = shadow_border_idx;
}
if (changeScoreAccordingToShadowBorderValue(x, y, 1, 0, border_scores_right_, border_scores_left_, shadow_border_idx))
if (changeScoreAccordingToShadowBorderValue(x, y, 1, 0, border_scores_right_.data (), border_scores_left_.data (), shadow_border_idx))
{
shadow_border_indices = (shadow_border_indices==nullptr ? new ShadowBorderIndices : shadow_border_indices);
shadow_border_indices->right = shadow_border_idx;
}
if (changeScoreAccordingToShadowBorderValue(x, y, 0, -1, border_scores_top_, border_scores_bottom_, shadow_border_idx))
if (changeScoreAccordingToShadowBorderValue(x, y, 0, -1, border_scores_top_.data (), border_scores_bottom_.data (), shadow_border_idx))
{
shadow_border_indices = (shadow_border_indices==nullptr ? new ShadowBorderIndices : shadow_border_indices);
shadow_border_indices->top = shadow_border_idx;
}
if (changeScoreAccordingToShadowBorderValue(x, y, 0, 1, border_scores_bottom_, border_scores_top_, shadow_border_idx))
if (changeScoreAccordingToShadowBorderValue(x, y, 0, 1, border_scores_bottom_.data (), border_scores_top_.data (), shadow_border_idx))
{
shadow_border_indices = (shadow_border_indices==nullptr ? new ShadowBorderIndices : shadow_border_indices);
shadow_border_indices->bottom = shadow_border_idx;
Expand Down Expand Up @@ -396,7 +394,7 @@ RangeImageBorderExtractor::classifyBorders ()
continue;

int shadow_border_index = shadow_border_indices->left;
if (shadow_border_index >= 0 && checkIfMaximum(x, y, -1, 0, border_scores_left_, shadow_border_index))
if (shadow_border_index >= 0 && checkIfMaximum(x, y, -1, 0, border_scores_left_.data (), shadow_border_index))
{
BorderTraits& shadow_traits = border_descriptions_->points[shadow_border_index].traits;
border_traits[BORDER_TRAIT__OBSTACLE_BORDER] = border_traits[BORDER_TRAIT__OBSTACLE_BORDER_LEFT] = true;
Expand All @@ -409,7 +407,7 @@ RangeImageBorderExtractor::classifyBorders ()
}

shadow_border_index = shadow_border_indices->right;
if (shadow_border_index >= 0 && checkIfMaximum(x, y, 1, 0, border_scores_right_, shadow_border_index))
if (shadow_border_index >= 0 && checkIfMaximum(x, y, 1, 0, border_scores_right_.data (), shadow_border_index))
{
BorderTraits& shadow_traits = border_descriptions_->points[shadow_border_index].traits;
border_traits[BORDER_TRAIT__OBSTACLE_BORDER] = border_traits[BORDER_TRAIT__OBSTACLE_BORDER_RIGHT] = true;
Expand All @@ -422,7 +420,7 @@ RangeImageBorderExtractor::classifyBorders ()
}

shadow_border_index = shadow_border_indices->top;
if (shadow_border_index >= 0 && checkIfMaximum(x, y, 0, -1, border_scores_top_, shadow_border_index))
if (shadow_border_index >= 0 && checkIfMaximum(x, y, 0, -1, border_scores_top_.data (), shadow_border_index))
{
BorderTraits& shadow_traits = border_descriptions_->points[shadow_border_index].traits;
border_traits[BORDER_TRAIT__OBSTACLE_BORDER] = border_traits[BORDER_TRAIT__OBSTACLE_BORDER_TOP] = true;
Expand All @@ -436,7 +434,7 @@ RangeImageBorderExtractor::classifyBorders ()
}

shadow_border_index = shadow_border_indices->bottom;
if (shadow_border_index >= 0 && checkIfMaximum(x, y, 0, 1, border_scores_bottom_, shadow_border_index))
if (shadow_border_index >= 0 && checkIfMaximum(x, y, 0, 1, border_scores_bottom_.data (), shadow_border_index))
{
BorderTraits& shadow_traits = border_descriptions_->points[shadow_border_index].traits;
border_traits[BORDER_TRAIT__OBSTACLE_BORDER] = border_traits[BORDER_TRAIT__OBSTACLE_BORDER_BOTTOM] = true;
Expand Down