Skip to content

Commit

Permalink
Replace raw arrays with std::vectors in RangeImageBorderExtractor (
Browse files Browse the repository at this point in the history
…#3533)

Replace raw arrays with std::vectors in RangeImageBorderExtractor
  • Loading branch information
kunaltyagi authored and taketwo committed Jan 16, 2020
1 parent 50c4c1d commit 35fb624
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
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 @@ -154,7 +149,7 @@ RangeImageBorderExtractor::extractLocalSurfaceStructure ()
void
RangeImageBorderExtractor::extractBorderScoreImages ()
{
if (border_scores_left_ != nullptr)
if (border_scores_left_.empty())
return;

extractLocalSurfaceStructure();
Expand All @@ -164,10 +159,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 @@ -202,6 +197,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 @@ -210,18 +216,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 @@ -231,7 +229,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 @@ -250,22 +248,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 @@ -397,7 +395,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 @@ -410,7 +408,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 @@ -423,7 +421,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 @@ -437,7 +435,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

0 comments on commit 35fb624

Please sign in to comment.