Skip to content

Commit ee3018b

Browse files
Replace raw double pointers with unique_ptr
1 parent 8d7033e commit ee3018b

File tree

4 files changed

+130
-26
lines changed

4 files changed

+130
-26
lines changed

features/include/pcl/features/range_image_border_extractor.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,36 +159,35 @@ namespace pcl
159159
getBorderScoresBottom () { extractBorderScoreImages (); return border_scores_bottom_.data (); }
160160

161161
LocalSurface**
162-
getSurfaceStructure () { extractLocalSurfaceStructure (); return surface_structure_; }
162+
getSurfaceStructure () { extractLocalSurfaceStructure (); return surface_structure_.get(); }
163163

164164
PointCloudOut&
165-
getBorderDescriptions () { classifyBorders (); return *border_descriptions_; }
165+
getBorderDescriptions() { classifyBorders(); return *border_descriptions_.get(); }
166166

167167
ShadowBorderIndices**
168-
getShadowBorderInformations () { findAndEvaluateShadowBorders (); return shadow_border_informations_; }
168+
getShadowBorderInformations() { findAndEvaluateShadowBorders(); return shadow_border_informations_.get(); }
169169

170170
Eigen::Vector3f**
171-
getBorderDirections () { calculateBorderDirections (); return border_directions_; }
171+
getBorderDirections() { calculateBorderDirections(); return border_directions_.get(); }
172172

173173
float*
174174
getSurfaceChangeScores () { calculateSurfaceChanges (); return surface_change_scores_; }
175175

176176
Eigen::Vector3f*
177-
getSurfaceChangeDirections () { calculateSurfaceChanges (); return surface_change_directions_; }
178-
179-
177+
getSurfaceChangeDirections() { calculateSurfaceChanges(); return surface_change_directions_; }
178+
179+
180180
protected:
181181
// =====PROTECTED MEMBER VARIABLES=====
182182
Parameters parameters_;
183183
const RangeImage* range_image_;
184184
int range_image_size_during_extraction_;
185185
std::vector<float> border_scores_left_, border_scores_right_;
186186
std::vector<float> border_scores_top_, border_scores_bottom_;
187-
LocalSurface** surface_structure_;
188-
PointCloudOut* border_descriptions_;
189-
ShadowBorderIndices** shadow_border_informations_;
190-
Eigen::Vector3f** border_directions_;
191-
187+
std::unique_ptr<LocalSurface*[]> surface_structure_;
188+
std::unique_ptr<PointCloudOut> border_descriptions_;
189+
std::unique_ptr<ShadowBorderIndices*[]> shadow_border_informations_;
190+
std::unique_ptr<Eigen::Vector3f*[]> border_directions_;
192191
float* surface_change_scores_;
193192
Eigen::Vector3f* surface_change_directions_;
194193

features/src/range_image_border_extractor.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ RangeImageBorderExtractor::clearData ()
8888
if (border_directions_!=nullptr)
8989
delete border_directions_[i];
9090
}
91-
delete[] surface_structure_; surface_structure_ = nullptr;
92-
delete border_descriptions_; border_descriptions_ = nullptr;
93-
delete[] shadow_border_informations_; shadow_border_informations_ = nullptr;
94-
delete[] border_directions_; border_directions_ = nullptr;
95-
96-
delete[] surface_change_scores_; surface_change_scores_ = nullptr;
97-
delete[] surface_change_directions_; surface_change_directions_ = nullptr;
91+
surface_structure_.reset();
92+
border_descriptions_.reset();
93+
shadow_border_informations_.reset();
94+
border_directions_.reset();
95+
delete[] surface_change_scores_;
96+
surface_change_scores_ = nullptr;
97+
delete[] surface_change_directions_;
98+
surface_change_directions_ = nullptr;
9899
}
99100

100101
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -110,7 +111,7 @@ RangeImageBorderExtractor::extractLocalSurfaceStructure ()
110111
const auto height = range_image_->height;
111112
range_image_size_during_extraction_ = width*height;
112113
const auto array_size = range_image_size_during_extraction_;
113-
surface_structure_ = new LocalSurface*[array_size];
114+
surface_structure_ = std::make_unique<LocalSurface*[]>(array_size);
114115
const auto step_size = std::max(1, parameters_.pixel_radius_plane_extraction/2);
115116
//std::cout << PVARN(step_size);
116117
const auto sqrt_neighbors = parameters_.pixel_radius_plane_extraction/step_size + 1;
@@ -257,7 +258,7 @@ RangeImageBorderExtractor::findAndEvaluateShadowBorders ()
257258

258259
int width = range_image_->width,
259260
height = range_image_->height;
260-
shadow_border_informations_ = new ShadowBorderIndices*[width*height];
261+
shadow_border_informations_ = std::make_unique<ShadowBorderIndices*[]>(width * height);
261262
for (int y = 0; y < static_cast<int> (height); ++y)
262263
{
263264
for (int x = 0; x < static_cast<int> (width); ++x)
@@ -393,7 +394,7 @@ RangeImageBorderExtractor::classifyBorders ()
393394

394395
BorderDescription initial_border_description;
395396
initial_border_description.traits = 0;
396-
border_descriptions_ = new PointCloudOut;
397+
border_descriptions_ = std::make_unique<PointCloudOut>();
397398
border_descriptions_->width = width;
398399
border_descriptions_->height = height;
399400
border_descriptions_->is_dense = true;
@@ -488,7 +489,7 @@ RangeImageBorderExtractor::calculateBorderDirections ()
488489
int width = range_image_->width,
489490
height = range_image_->height,
490491
size = width*height;
491-
border_directions_ = new Eigen::Vector3f*[size];
492+
border_directions_ = std::make_unique<Eigen::Vector3f*[]>(size);
492493
for (int y=0; y<height; ++y)
493494
{
494495
for (int x=0; x<width; ++x)
@@ -497,7 +498,7 @@ RangeImageBorderExtractor::calculateBorderDirections ()
497498
}
498499
}
499500

500-
Eigen::Vector3f** average_border_directions = new Eigen::Vector3f*[size];
501+
std::unique_ptr<Eigen::Vector3f*[]> average_border_directions(std::make_unique<Eigen::Vector3f*[]>(size));
501502
int radius = parameters_.pixel_radius_border_direction;
502503
int minimum_weight = radius+1;
503504
float min_cos_angle=std::cos(deg2rad(120.0f));
@@ -553,8 +554,7 @@ RangeImageBorderExtractor::calculateBorderDirections ()
553554

554555
for (int i=0; i<size; ++i)
555556
delete border_directions_[i];
556-
delete[] border_directions_;
557-
border_directions_ = average_border_directions;
557+
border_directions_ = std::move(average_border_directions);
558558
}
559559

560560
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

test/features/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ if(BUILD_io)
5757
FILES test_boundary_estimation.cpp
5858
LINK_WITH pcl_gtest pcl_features pcl_io
5959
ARGUMENTS "${PCL_SOURCE_DIR}/test/bun0.pcd")
60+
PCL_ADD_TEST(feature_range_image_border_extraction test_range_image_border_extraction
61+
FILES test_boundary_estimation.cpp
62+
LINK_WITH pcl_gtest pcl_features pcl_io
63+
ARGUMENTS "${PCL_SOURCE_DIR}/test/bun0.pcd")
6064
PCL_ADD_TEST(feature_curvatures_estimation test_curvatures_estimation
6165
FILES test_curvatures_estimation.cpp
6266
LINK_WITH pcl_gtest pcl_features pcl_io
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Software License Agreement (BSD License)
3+
*
4+
* Point Cloud Library (PCL) - www.pointclouds.org
5+
* Copyright (c) 2010-2012, Willow Garage, Inc.
6+
*
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
*
13+
* * Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* * Redistributions in binary form must reproduce the above
16+
* copyright notice, this list of conditions and the following
17+
* disclaimer in the documentation and/or other materials provided
18+
* with the distribution.
19+
* * Neither the name of the copyright holder(s) nor the names of its
20+
* contributors may be used to endorse or promote products derived
21+
* from this software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
* POSSIBILITY OF SUCH DAMAGE.
35+
*
36+
* $Id$
37+
*
38+
*/
39+
40+
#include <pcl/test/gtest.h>
41+
#include <pcl/point_cloud.h>
42+
#include <pcl/range_image/range_image.h>
43+
#include <pcl/features/range_image_border_extractor.h>
44+
#include <pcl/io/pcd_io.h>
45+
46+
using namespace pcl;
47+
using namespace pcl::io;
48+
using namespace std;
49+
50+
PointCloud<PointXYZ> cloud;
51+
std::vector<int> indices;
52+
53+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54+
TEST (PCL, RangeImageBorderExtract)
55+
{
56+
float noise_level = 0.0;
57+
float min_range = 0.0f;
58+
int border_size = 1;
59+
pcl::RangeImage::Ptr range_image_ptr (new pcl::RangeImage);
60+
pcl::RangeImage& range_image = *range_image_ptr;
61+
range_image.createFromPointCloud (cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),
62+
scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
63+
range_image.integrateFarRanges (far_ranges);
64+
if (setUnseenToMaxRange)
65+
range_image.setUnseenToMaxRange ();
66+
67+
68+
pcl::RangeImageBorderExtractor border_extractor (&range_image);
69+
pcl::PointCloud<pcl::BorderDescription> border_descriptions;
70+
border_extractor.compute (border_descriptions);
71+
72+
printf("RangeImageBorderExtract Test Completed\n");
73+
74+
}
75+
76+
/* ---[ */
77+
int
78+
main (int argc, char** argv)
79+
{
80+
if (argc < 2)
81+
{
82+
std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl;
83+
return (-1);
84+
}
85+
86+
if (loadPCDFile<PointXYZ> (argv[1], cloud) < 0)
87+
{
88+
std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl;
89+
return (-1);
90+
}
91+
92+
indices.resize (cloud.points.size ());
93+
for (std::size_t i = 0; i < indices.size (); ++i)
94+
indices[i] = static_cast<int> (i);
95+
96+
tree->setInputCloud (cloud.makeShared ());
97+
98+
testing::InitGoogleTest (&argc, argv);
99+
return (RUN_ALL_TESTS ());
100+
}
101+
/* ]--- */

0 commit comments

Comments
 (0)