Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 053995b

Browse files
committed
Small fixes and code improvements
- in PCLPointCloud2.h, a cast is necessary, otherwise the elements are printed as characters instead of numbers - in setNumberOfThreads, add debug output/warning if OpenMP is not available - resize is more efficient than substr - implicit_shape_model.hpp: move peak_counter increment inside if-statement. This does not change much in practice because all of the peak_densities are larger than -1.0, but it silences the warning that strongest_peak may be uninitialized - region_growing.hpp and region_growing_rgb.hpp: switch range-for-loop, while also fixing bug (i_point was used in nearestKSearch, but point_index should have been used instead) - pcl_visualizer.hpp: make sure that point and normals are finite, otherwise VTK displays strange things
1 parent 14caf35 commit 053995b

File tree

10 files changed

+26
-20
lines changed

10 files changed

+26
-20
lines changed

common/include/pcl/PCLPointCloud2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace pcl
143143
for (std::size_t i = 0; i < v.data.size (); ++i)
144144
{
145145
s << " data[" << i << "]: ";
146-
s << " " << v.data[i] << std::endl;
146+
s << " " << static_cast<int>(v.data[i]) << std::endl;
147147
}
148148
s << "is_dense: ";
149149
s << " " << v.is_dense << std::endl;

common/include/pcl/impl/pcl_base.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pcl::PCLBase<PointT>::initCompute ()
162162
catch (const std::bad_alloc&)
163163
{
164164
PCL_ERROR ("[initCompute] Failed to allocate %lu indices.\n", input_->size ());
165+
return (false);
165166
}
166167
for (auto i = indices_size; i < indices_->size (); ++i) { (*indices_)[i] = static_cast<int>(i); }
167168
}

common/src/pcl_base.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pcl::PCLBase<pcl::PCLPointCloud2>::initCompute ()
124124
catch (const std::bad_alloc&)
125125
{
126126
PCL_ERROR ("[initCompute] Failed to allocate %lu indices.\n", (input_->width * input_->height));
127+
return (false);
127128
}
128129
if (indices_size < indices_->size ())
129130
std::iota(indices_->begin () + indices_size, indices_->end (), indices_size);

features/include/pcl/features/impl/normal_3d_omp.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@
4747
template <typename PointInT, typename PointOutT> void
4848
pcl::NormalEstimationOMP<PointInT, PointOutT>::setNumberOfThreads (unsigned int nr_threads)
4949
{
50-
if (nr_threads == 0)
5150
#ifdef _OPENMP
51+
if (nr_threads == 0)
5252
threads_ = omp_get_num_procs();
53-
#else
54-
threads_ = 1;
55-
#endif
5653
else
5754
threads_ = nr_threads;
55+
PCL_DEBUG ("[pcl::NormalEstimationOMP::setNumberOfThreads] Setting number of threads to %u.\n", threads_);
56+
#else
57+
threads_ = 1;
58+
if (nr_threads != 1)
59+
PCL_WARN ("[pcl::NormalEstimationOMP::setNumberOfThreads] Parallelization is requested, but OpenMP is not available! Continuing without parallelization.\n");
60+
#endif // _OPENMP
5861
}
5962

6063
///////////////////////////////////////////////////////////////////////////////////////////

io/include/pcl/io/io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
*/
3939

4040
#pragma once
41+
#include <pcl/pcl_macros.h> // for PCL_DEPRECATED_HEADER
4142
PCL_DEPRECATED_HEADER(1, 15, "Please include pcl/common/io.h directly.")
4243
#include <pcl/common/io.h>

io/src/lzf_image_io.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pcl::io::LZFImageWriter::compress (const char* input,
135135
if (itype.size () > 16)
136136
{
137137
PCL_WARN ("[pcl::io::LZFImageWriter::compress] Image type should be a string of maximum 16 characters! Cutting %s to %s.\n", image_type.c_str (), image_type.substr (0, 15).c_str ());
138-
itype = itype.substr (0, 15);
138+
itype.resize(16);
139139
}
140140
if (itype.size () < 16)
141141
itype.insert (itype.end (), 16 - itype.size (), ' ');

recognition/include/pcl/recognition/impl/implicit_shape_model.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ pcl::features::ISMVoteList<PointT>::findStrongestPeaks (
192192
best_density = peak_densities[i];
193193
strongest_peak = peaks[i];
194194
best_peak_ind = i;
195+
++peak_counter;
195196
}
196-
++peak_counter;
197197
}
198198

199199
if( peak_counter == 0 )

segmentation/include/pcl/segmentation/impl/region_growing.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,30 +342,27 @@ pcl::RegionGrowing<PointT, NormalT>::prepareForSegmentation ()
342342
template <typename PointT, typename NormalT> void
343343
pcl::RegionGrowing<PointT, NormalT>::findPointNeighbours ()
344344
{
345-
int point_number = static_cast<int> (indices_->size ());
346345
pcl::Indices neighbours;
347346
std::vector<float> distances;
348347

349348
point_neighbours_.resize (input_->size (), neighbours);
350349
if (input_->is_dense)
351350
{
352-
for (int i_point = 0; i_point < point_number; i_point++)
351+
for (const auto& point_index: (*indices_))
353352
{
354-
const auto point_index = (*indices_)[i_point];
355353
neighbours.clear ();
356-
search_->nearestKSearch (i_point, neighbour_number_, neighbours, distances);
354+
search_->nearestKSearch (point_index, neighbour_number_, neighbours, distances);
357355
point_neighbours_[point_index].swap (neighbours);
358356
}
359357
}
360358
else
361359
{
362-
for (int i_point = 0; i_point < point_number; i_point++)
360+
for (const auto& point_index: (*indices_))
363361
{
364-
neighbours.clear ();
365-
const auto point_index = (*indices_)[i_point];
366362
if (!pcl::isFinite ((*input_)[point_index]))
367363
continue;
368-
search_->nearestKSearch (i_point, neighbour_number_, neighbours, distances);
364+
neighbours.clear ();
365+
search_->nearestKSearch (point_index, neighbour_number_, neighbours, distances);
369366
point_neighbours_[point_index].swap (neighbours);
370367
}
371368
}

segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,17 @@ pcl::RegionGrowingRGB<PointT, NormalT>::prepareForSegmentation ()
272272
template <typename PointT, typename NormalT> void
273273
pcl::RegionGrowingRGB<PointT, NormalT>::findPointNeighbours ()
274274
{
275-
int point_number = static_cast<int> (indices_->size ());
276275
pcl::Indices neighbours;
277276
std::vector<float> distances;
278277

279278
point_neighbours_.resize (input_->size (), neighbours);
280279
point_distances_.resize (input_->size (), distances);
281280

282-
for (int i_point = 0; i_point < point_number; i_point++)
281+
for (const auto& point_index: (*indices_))
283282
{
284-
int point_index = (*indices_)[i_point];
285283
neighbours.clear ();
286284
distances.clear ();
287-
search_->nearestKSearch (i_point, region_neighbour_number_, neighbours, distances);
285+
search_->nearestKSearch (point_index, region_neighbour_number_, neighbours, distances);
288286
point_neighbours_[point_index].swap (neighbours);
289287
point_distances_[point_index].swap (distances);
290288
}

visualization/include/pcl/visualization/impl/pcl_visualizer.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,8 @@ pcl::visualization::PCLVisualizer::addPointCloudNormals (
906906
for (vtkIdType x = 0; x < normals->width; x += point_step)
907907
{
908908
PointT p = (*cloud)(x, y);
909+
if (!pcl::isFinite(p) || !pcl::isNormalFinite((*normals)(x, y)))
910+
continue;
909911
p.x += (*normals)(x, y).normal[0] * scale;
910912
p.y += (*normals)(x, y).normal[1] * scale;
911913
p.z += (*normals)(x, y).normal[2] * scale;
@@ -928,8 +930,10 @@ pcl::visualization::PCLVisualizer::addPointCloudNormals (
928930
nr_normals = (cloud->size () - 1) / level + 1 ;
929931
pts = new float[2 * nr_normals * 3];
930932

931-
for (vtkIdType i = 0, j = 0; j < nr_normals; j++, i = j * level)
933+
for (vtkIdType i = 0, j = 0; (j < nr_normals) && (i < static_cast<vtkIdType>(cloud->size())); i += level)
932934
{
935+
if (!pcl::isFinite((*cloud)[i]) || !pcl::isNormalFinite((*normals)[i]))
936+
continue;
933937
PointT p = (*cloud)[i];
934938
p.x += (*normals)[i].normal[0] * scale;
935939
p.y += (*normals)[i].normal[1] * scale;
@@ -945,6 +949,7 @@ pcl::visualization::PCLVisualizer::addPointCloudNormals (
945949
lines->InsertNextCell (2);
946950
lines->InsertCellPoint (2 * j);
947951
lines->InsertCellPoint (2 * j + 1);
952+
++j;
948953
}
949954
}
950955

0 commit comments

Comments
 (0)