diff --git a/features/include/pcl/features/range_image_border_extractor.h b/features/include/pcl/features/range_image_border_extractor.h index a87dcb327d7..f93ddfbb8ab 100644 --- a/features/include/pcl/features/range_image_border_extractor.h +++ b/features/include/pcl/features/range_image_border_extractor.h @@ -159,24 +159,24 @@ namespace pcl getBorderScoresBottom () { extractBorderScoreImages (); return border_scores_bottom_.data (); } LocalSurface** - getSurfaceStructure () { extractLocalSurfaceStructure (); return surface_structure_; } + getSurfaceStructure () { extractLocalSurfaceStructure (); return surface_structure_.get(); } PointCloudOut& - getBorderDescriptions () { classifyBorders (); return *border_descriptions_; } + getBorderDescriptions() { classifyBorders(); return *border_descriptions_.get(); } ShadowBorderIndices** - getShadowBorderInformations () { findAndEvaluateShadowBorders (); return shadow_border_informations_; } + getShadowBorderInformations() { findAndEvaluateShadowBorders(); return shadow_border_informations_.get(); } Eigen::Vector3f** - getBorderDirections () { calculateBorderDirections (); return border_directions_; } + getBorderDirections() { calculateBorderDirections(); return border_directions_.get(); } float* - getSurfaceChangeScores () { calculateSurfaceChanges (); return surface_change_scores_; } + getSurfaceChangeScores () { calculateSurfaceChanges (); return surface_change_scores_.data(); } Eigen::Vector3f* - getSurfaceChangeDirections () { calculateSurfaceChanges (); return surface_change_directions_; } - - + getSurfaceChangeDirections() { calculateSurfaceChanges(); return surface_change_directions_.get(); } + + protected: // =====PROTECTED MEMBER VARIABLES===== Parameters parameters_; @@ -184,13 +184,12 @@ namespace pcl int range_image_size_during_extraction_; std::vector border_scores_left_, border_scores_right_; std::vector border_scores_top_, border_scores_bottom_; - LocalSurface** surface_structure_; - PointCloudOut* border_descriptions_; - ShadowBorderIndices** shadow_border_informations_; - Eigen::Vector3f** border_directions_; - - float* surface_change_scores_; - Eigen::Vector3f* surface_change_directions_; + std::unique_ptr surface_structure_; + std::unique_ptr border_descriptions_; + std::unique_ptr shadow_border_informations_; + std::unique_ptr border_directions_; + std::vector surface_change_scores_; + std::unique_ptr surface_change_directions_; // =====PROTECTED METHODS===== diff --git a/features/src/range_image_border_extractor.cpp b/features/src/range_image_border_extractor.cpp index 2a74d52bed2..990195dace6 100644 --- a/features/src/range_image_border_extractor.cpp +++ b/features/src/range_image_border_extractor.cpp @@ -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(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(width * height); for (int y = 0; y < static_cast (height); ++y) { for (int x = 0; x < static_cast (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(); 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(size); for (int y=0; y average_border_directions(std::make_unique(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; iwidth, 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(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 blurred_scores(range_image.width*range_image.height); for (int y=0; y(std::move(blurred_directions)); + surface_change_scores_.clear(); surface_change_scores_ = blurred_scores; } diff --git a/test/features/CMakeLists.txt b/test/features/CMakeLists.txt index 9775415a1d2..6b7907b4474 100644 --- a/test/features/CMakeLists.txt +++ b/test/features/CMakeLists.txt @@ -57,6 +57,10 @@ if(BUILD_io) FILES test_boundary_estimation.cpp LINK_WITH pcl_gtest pcl_features pcl_io ARGUMENTS "${PCL_SOURCE_DIR}/test/bun0.pcd") + PCL_ADD_TEST(feature_range_image_border_extraction test_range_image_border_extraction + FILES test_boundary_estimation.cpp + LINK_WITH pcl_gtest pcl_features pcl_io + ARGUMENTS "${PCL_SOURCE_DIR}/test/bun0.pcd") PCL_ADD_TEST(feature_curvatures_estimation test_curvatures_estimation FILES test_curvatures_estimation.cpp LINK_WITH pcl_gtest pcl_features pcl_io diff --git a/test/features/test_range_image_border_extraction.cpp b/test/features/test_range_image_border_extraction.cpp new file mode 100644 index 00000000000..4f39080cfaf --- /dev/null +++ b/test/features/test_range_image_border_extraction.cpp @@ -0,0 +1,101 @@ +/* + * 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 +#include +#include +#include +#include + +using namespace pcl; +using namespace pcl::io; +using namespace std; + +PointCloud cloud; +std::vector 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 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 (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 (i); + + tree->setInputCloud (cloud.makeShared ()); + + testing::InitGoogleTest (&argc, argv); + return (RUN_ALL_TESTS ()); +} +/* ]--- */