-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Modernise manual memory management in range_image_border_extractor
#3865
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ namespace pcl | |
RangeImageBorderExtractor::RangeImageBorderExtractor(const RangeImage* range_image) : | ||
range_image_(range_image), range_image_size_during_extraction_(0), | ||
surface_structure_(nullptr), border_descriptions_(nullptr), shadow_border_informations_(nullptr), border_directions_(nullptr), | ||
surface_change_scores_(nullptr), surface_change_directions_(nullptr) | ||
surface_change_directions_(nullptr) | ||
{ | ||
} | ||
|
||
|
@@ -88,13 +88,13 @@ RangeImageBorderExtractor::clearData () | |
if (border_directions_!=nullptr) | ||
delete border_directions_[i]; | ||
} | ||
delete[] surface_structure_; surface_structure_ = nullptr; | ||
delete[] shadow_border_informations_; shadow_border_informations_ = nullptr; | ||
delete[] border_directions_; border_directions_ = nullptr; | ||
delete border_descriptions_; border_descriptions_ = nullptr; | ||
surface_structure_.reset(); | ||
shadow_border_informations_.reset(); | ||
border_directions_.reset(); | ||
border_descriptions_.reset(); | ||
|
||
delete[] surface_change_scores_; surface_change_scores_ = nullptr; | ||
delete[] surface_change_directions_; surface_change_directions_ = nullptr; | ||
surface_change_directions_.reset(); | ||
surface_change_scores_.clear(); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
@@ -110,7 +110,7 @@ RangeImageBorderExtractor::extractLocalSurfaceStructure () | |
const auto height = range_image_->height; | ||
range_image_size_during_extraction_ = width*height; | ||
const auto array_size = range_image_size_during_extraction_; | ||
surface_structure_ = new LocalSurface*[array_size]; | ||
surface_structure_ = std::make_unique<LocalSurface*[]>(array_size); | ||
const auto step_size = std::max(1, parameters_.pixel_radius_plane_extraction/2); | ||
//std::cout << PVARN(step_size); | ||
const auto sqrt_neighbors = parameters_.pixel_radius_plane_extraction/step_size + 1; | ||
|
@@ -257,7 +257,7 @@ RangeImageBorderExtractor::findAndEvaluateShadowBorders () | |
|
||
int width = range_image_->width, | ||
height = range_image_->height; | ||
shadow_border_informations_ = new ShadowBorderIndices*[width*height]; | ||
shadow_border_informations_ = std::make_unique<ShadowBorderIndices*[]>(width * height); | ||
for (int y = 0; y < static_cast<int> (height); ++y) | ||
{ | ||
for (int x = 0; x < static_cast<int> (width); ++x) | ||
|
@@ -393,7 +393,7 @@ RangeImageBorderExtractor::classifyBorders () | |
|
||
BorderDescription initial_border_description; | ||
initial_border_description.traits = 0; | ||
border_descriptions_ = new PointCloudOut; | ||
border_descriptions_ = std::make_unique<PointCloudOut>(); | ||
border_descriptions_->width = width; | ||
border_descriptions_->height = height; | ||
border_descriptions_->is_dense = true; | ||
|
@@ -488,7 +488,7 @@ RangeImageBorderExtractor::calculateBorderDirections () | |
int width = range_image_->width, | ||
height = range_image_->height, | ||
size = width*height; | ||
border_directions_ = new Eigen::Vector3f*[size]; | ||
border_directions_ = std::make_unique<Eigen::Vector3f*[]>(size); | ||
for (int y=0; y<height; ++y) | ||
{ | ||
for (int x=0; x<width; ++x) | ||
|
@@ -497,7 +497,7 @@ RangeImageBorderExtractor::calculateBorderDirections () | |
} | ||
} | ||
|
||
Eigen::Vector3f** average_border_directions = new Eigen::Vector3f*[size]; | ||
std::unique_ptr<Eigen::Vector3f*[]> average_border_directions(std::make_unique<Eigen::Vector3f*[]>(size)); | ||
int radius = parameters_.pixel_radius_border_direction; | ||
int minimum_weight = radius+1; | ||
float min_cos_angle=std::cos(deg2rad(120.0f)); | ||
|
@@ -553,15 +553,14 @@ RangeImageBorderExtractor::calculateBorderDirections () | |
|
||
for (int i=0; i<size; ++i) | ||
delete border_directions_[i]; | ||
delete[] border_directions_; | ||
border_directions_ = average_border_directions; | ||
border_directions_ = std::move(average_border_directions); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
void | ||
RangeImageBorderExtractor::calculateSurfaceChanges () | ||
{ | ||
if (surface_change_scores_!=nullptr) | ||
if (!surface_change_scores_.empty()) | ||
return; | ||
|
||
calculateBorderDirections(); | ||
|
@@ -571,8 +570,8 @@ RangeImageBorderExtractor::calculateSurfaceChanges () | |
int width = range_image_->width, | ||
height = range_image_->height, | ||
size = width*height; | ||
surface_change_scores_ = new float[size]; | ||
surface_change_directions_ = new Eigen::Vector3f[size]; | ||
surface_change_scores_.resize(size); | ||
surface_change_directions_ = std::make_unique<Eigen::Vector3f[]>(size); | ||
#pragma omp parallel for \ | ||
default(none) \ | ||
shared(height, width) \ | ||
|
@@ -619,7 +618,7 @@ RangeImageBorderExtractor::blurSurfaceChanges () | |
const RangeImage& range_image = *range_image_; | ||
|
||
Eigen::Vector3f* blurred_directions = new Eigen::Vector3f[range_image.width*range_image.height]; | ||
float* blurred_scores = new float[range_image.width*range_image.height]; | ||
std::vector<float> blurred_scores(range_image.width*range_image.height); | ||
for (int y=0; y<int(range_image.height); ++y) | ||
{ | ||
for (int x=0; x<int(range_image.width); ++x) | ||
|
@@ -665,9 +664,9 @@ RangeImageBorderExtractor::blurSurfaceChanges () | |
new_score /= counter; | ||
} | ||
} | ||
delete[] surface_change_directions_; | ||
surface_change_directions_ = blurred_directions; | ||
delete[] surface_change_scores_; | ||
surface_change_directions_.reset(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swap and reset instead? |
||
surface_change_directions_ = std::unique_ptr<Eigen::Vector3f[]>(std::move(blurred_directions)); | ||
surface_change_scores_.clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to clear |
||
surface_change_scores_ = blurred_scores; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Save 40 lines using SPDX license |
||
* Software License Agreement (BSD License) | ||
* | ||
* Point Cloud Library (PCL) - www.pointclouds.org | ||
* Copyright (c) 2010-2012, Willow Garage, Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the copyright holder(s) nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* $Id$ | ||
* | ||
*/ | ||
|
||
#include <pcl/test/gtest.h> | ||
#include <pcl/point_cloud.h> | ||
#include <pcl/range_image/range_image.h> | ||
#include <pcl/features/range_image_border_extractor.h> | ||
#include <pcl/io/pcd_io.h> | ||
|
||
using namespace pcl; | ||
using namespace pcl::io; | ||
using namespace std; | ||
|
||
PointCloud<PointXYZ> cloud; | ||
std::vector<int> indices; | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
TEST (PCL, RangeImageBorderExtract) | ||
{ | ||
float noise_level = 0.0; | ||
float min_range = 0.0f; | ||
int border_size = 1; | ||
pcl::RangeImage::Ptr range_image_ptr (new pcl::RangeImage); | ||
pcl::RangeImage& range_image = *range_image_ptr; | ||
range_image.createFromPointCloud (cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f), | ||
scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size); | ||
range_image.integrateFarRanges (far_ranges); | ||
if (setUnseenToMaxRange) | ||
range_image.setUnseenToMaxRange (); | ||
|
||
|
||
pcl::RangeImageBorderExtractor border_extractor (&range_image); | ||
pcl::PointCloud<pcl::BorderDescription> border_descriptions; | ||
border_extractor.compute (border_descriptions); | ||
|
||
printf("RangeImageBorderExtract Test Completed\n"); | ||
|
||
} | ||
|
||
/* ---[ */ | ||
int | ||
main (int argc, char** argv) | ||
{ | ||
if (argc < 2) | ||
{ | ||
std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl; | ||
return (-1); | ||
} | ||
|
||
if (loadPCDFile<PointXYZ> (argv[1], cloud) < 0) | ||
{ | ||
std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl; | ||
return (-1); | ||
} | ||
|
||
indices.resize (cloud.points.size ()); | ||
for (std::size_t i = 0; i < indices.size (); ++i) | ||
indices[i] = static_cast<int> (i); | ||
|
||
tree->setInputCloud (cloud.makeShared ()); | ||
|
||
testing::InitGoogleTest (&argc, argv); | ||
return (RUN_ALL_TESTS ()); | ||
} | ||
/* ]--- */ |
Uh oh!
There was an error while loading. Please reload this page.