Skip to content
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

Enable arbitary size Indices for Octree module #4350

Merged
merged 12 commits into from
Mar 14, 2021
3 changes: 2 additions & 1 deletion .ci/azure-pipelines/build/ubuntu_indices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ steps:
-DPCL_INDEX_SIGNED=$INDEX_SIGNED \
-DPCL_INDEX_SIZE=$INDEX_SIZE \
-DBUILD_geometry=OFF \
-DBUILD_io=OFF \
-DBUILD_tools=OFF \
-DBUILD_kdtree=OFF \
-DBUILD_ml=OFF \
-DBUILD_octree=OFF \
-DBUILD_stereo=OFF \
-DBUILD_global_tests=ON
# Temporary fix to ensure no tests are skipped
cmake $(Build.SourcesDirectory)
Expand Down
4 changes: 2 additions & 2 deletions common/include/pcl/common/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ namespace pcl
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointT, typename IndicesVectorAllocator = std::allocator<int>> void
template <typename PointT, typename IndicesVectorAllocator = std::allocator<index_t>> void
copyPointCloud (const pcl::PointCloud<PointT> &cloud_in,
const IndicesAllocator< IndicesVectorAllocator> &indices,
pcl::PointCloud<PointT> &cloud_out);
Expand Down Expand Up @@ -392,7 +392,7 @@ namespace pcl
* \note Assumes unique indices.
* \ingroup common
*/
template <typename PointInT, typename PointOutT, typename IndicesVectorAllocator = std::allocator<int>> void
template <typename PointInT, typename PointOutT, typename IndicesVectorAllocator = std::allocator<index_t>> void
copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
const IndicesAllocator<IndicesVectorAllocator> &indices,
pcl::PointCloud<PointOutT> &cloud_out);
Expand Down
2 changes: 1 addition & 1 deletion common/src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ pcl::copyPointCloud (
void
pcl::copyPointCloud (
const pcl::PCLPointCloud2 &cloud_in,
const IndicesAllocator< Eigen::aligned_allocator<pcl::index_t> > &indices,
const IndicesAllocator< Eigen::aligned_allocator<index_t> > &indices,
pcl::PCLPointCloud2 &cloud_out)
{
cloud_out.header = cloud_in.header;
Expand Down
47 changes: 22 additions & 25 deletions io/include/pcl/compression/color_coding.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,16 @@ class ColorCoding
* \param inputCloud_arg input point cloud
* */
void
encodeAverageOfPoints (const typename std::vector<int>& indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
encodeAverageOfPoints (const Indices& indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
mvieth marked this conversation as resolved.
Show resolved Hide resolved
{
unsigned int avgRed = 0;
unsigned int avgGreen = 0;
unsigned int avgBlue = 0;
uindex_t avgRed = 0;
uindex_t avgGreen = 0;
uindex_t avgBlue = 0;

// iterate over points
std::size_t len = indexVector_arg.size ();
for (std::size_t i = 0; i < len; i++)
for (const auto& idx: indexVector_arg)
{
// get color information from points
const int& idx = indexVector_arg[i];
const char* idxPointPtr = reinterpret_cast<const char*> (&(*inputCloud_arg)[idx]);
const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);

Expand All @@ -177,12 +175,13 @@ class ColorCoding

}

const uindex_t len = static_cast<uindex_t> (indexVector_arg.size());
// calculated average color information
if (len > 1)
{
avgRed /= static_cast<unsigned int> (len);
avgGreen /= static_cast<unsigned int> (len);
avgBlue /= static_cast<unsigned int> (len);
avgRed /= len;
avgGreen /= len;
avgBlue /= len;
}

// remove least significant bits
Expand All @@ -202,21 +201,19 @@ class ColorCoding
* \param inputCloud_arg input point cloud
* */
void
encodePoints (const typename std::vector<int>& indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
encodePoints (const Indices& indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
{
unsigned int avgRed;
unsigned int avgGreen;
unsigned int avgBlue;
uindex_t avgRed;
uindex_t avgGreen;
uindex_t avgBlue;

// initialize
avgRed = avgGreen = avgBlue = 0;

// iterate over points
std::size_t len = indexVector_arg.size ();
for (std::size_t i = 0; i < len; i++)
for (const auto& idx: indexVector_arg)
{
// get color information from point
const int& idx = indexVector_arg[i];
const char* idxPointPtr = reinterpret_cast<const char*> (&(*inputCloud_arg)[idx]);
const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);

Expand All @@ -227,21 +224,21 @@ class ColorCoding

}

const uindex_t len = static_cast<uindex_t> (indexVector_arg.size());
if (len > 1)
{
unsigned char diffRed;
unsigned char diffGreen;
unsigned char diffBlue;

// calculated average color information
avgRed /= static_cast<unsigned int> (len);
avgGreen /= static_cast<unsigned int> (len);
avgBlue /= static_cast<unsigned int> (len);
avgRed /= len;
avgGreen /= len;
avgBlue /= len;

// iterate over points for differential encoding
for (std::size_t i = 0; i < len; i++)
for (const auto& idx: indexVector_arg)
{
const int& idx = indexVector_arg[i];
const char* idxPointPtr = reinterpret_cast<const char*> (&(*inputCloud_arg)[idx]);
const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);

Expand Down Expand Up @@ -281,12 +278,12 @@ class ColorCoding
* \param rgba_offset_arg offset to color information
*/
void
decodePoints (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg, unsigned char rgba_offset_arg)
decodePoints (PointCloudPtr outputCloud_arg, uindex_t beginIdx_arg, uindex_t endIdx_arg, unsigned char rgba_offset_arg)
{
assert (beginIdx_arg <= endIdx_arg);

// amount of points to be decoded
unsigned int pointCount = static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
const index_t pointCount = endIdx_arg - beginIdx_arg;

// get averaged color information for current voxel
unsigned char avgRed = *(pointAvgColorDataVector_Iterator_++);
Expand All @@ -299,7 +296,7 @@ class ColorCoding
avgBlue = static_cast<unsigned char> (avgBlue << colorBitReduction_);

// iterate over points
for (std::size_t i = 0; i < pointCount; i++)
for (index_t i = 0; i < pointCount; i++)
{
unsigned int colorInt;
if (pointCount > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ namespace pcl
LeafT &leaf_arg, const OctreeKey & key_arg)
{
// reference to point indices vector stored within octree leaf
const std::vector<int>& leafIdx = leaf_arg.getPointIndicesVector();
const auto& leafIdx = leaf_arg.getPointIndicesVector();

if (!do_voxel_grid_enDecoding_)
{
Expand Down
2 changes: 1 addition & 1 deletion io/include/pcl/compression/octree_pointcloud_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace pcl
* \param[in] pointIdx_arg the index representing the point in the dataset given by \a setInputCloud to be added
*/
void
addPointIdx (const int pointIdx_arg) override
addPointIdx (const uindex_t pointIdx_arg) override
{
++object_count_;
OctreePointCloud<PointT, LeafT, BranchT, OctreeT>::addPointIdx(pointIdx_arg);
Expand Down
15 changes: 6 additions & 9 deletions io/include/pcl/compression/point_coding.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,15 @@ class PointCoding
* \param inputCloud_arg input point cloud
*/
void
encodePoints (const typename std::vector<int>& indexVector_arg, const double* referencePoint_arg,
encodePoints (const Indices& indexVector_arg, const double* referencePoint_arg,
mvieth marked this conversation as resolved.
Show resolved Hide resolved
PointCloudConstPtr inputCloud_arg)
{
std::size_t len = indexVector_arg.size ();

// iterate over points within current voxel
for (std::size_t i = 0; i < len; i++)
for (const auto& idx: indexVector_arg)
{
unsigned char diffX, diffY, diffZ;

// retrieve point from cloud
const int& idx = indexVector_arg[i];
const PointT& idxPoint = (*inputCloud_arg)[idx];

// differentially encode point coordinates and truncate overflow
Expand All @@ -159,15 +156,15 @@ class PointCoding
* \param endIdx_arg index indicating last point to be assigned with color information
*/
void
decodePoints (PointCloudPtr outputCloud_arg, const double* referencePoint_arg, std::size_t beginIdx_arg,
std::size_t endIdx_arg)
decodePoints (PointCloudPtr outputCloud_arg, const double* referencePoint_arg, uindex_t beginIdx_arg,
uindex_t endIdx_arg)
{
assert (beginIdx_arg <= endIdx_arg);

unsigned int pointCount = static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
const uindex_t pointCount = endIdx_arg - beginIdx_arg;

// iterate over points within current voxel
for (std::size_t i = 0; i < pointCount; i++)
for (uindex_t i = 0; i < pointCount; i++)
{
// retrieve differential point information
const unsigned char& diffX = static_cast<unsigned char> (*(pointDiffDataVectorIterator_++));
Expand Down
8 changes: 4 additions & 4 deletions kdtree/include/pcl/kdtree/impl/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ template <typename Point1T, typename Point2T> void
pcl::getApproximateIndices (
const typename pcl::PointCloud<Point1T>::ConstPtr &cloud_in,
const typename pcl::PointCloud<Point2T>::ConstPtr &cloud_ref,
std::vector<int> &indices)
Indices &indices)
{
pcl::KdTreeFLANN<Point2T> tree;
tree.setInputCloud (cloud_ref);

std::vector<int> nn_idx (1);
Indices nn_idx (1);
std::vector<float> nn_dists (1);
indices.resize (cloud_in->size ());
for (std::size_t i = 0; i < cloud_in->size (); ++i)
Expand All @@ -67,12 +67,12 @@ template <typename PointT> void
pcl::getApproximateIndices (
const typename pcl::PointCloud<PointT>::ConstPtr &cloud_in,
const typename pcl::PointCloud<PointT>::ConstPtr &cloud_ref,
std::vector<int> &indices)
Indices &indices)
{
pcl::KdTreeFLANN<PointT> tree;
tree.setInputCloud (cloud_ref);

std::vector<int> nn_idx (1);
Indices nn_idx (1);
std::vector<float> nn_dists (1);
indices.resize (cloud_in->size ());
for (std::size_t i = 0; i < cloud_in->size (); ++i)
Expand Down
16 changes: 8 additions & 8 deletions kdtree/include/pcl/kdtree/impl/kdtree_flann.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ pcl::KdTreeFLANN<PointT, Dist>::setInputCloud (const PointCloudConstPtr &cloud,
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename Dist> int
template <typename PointT, typename Dist> int
pcl::KdTreeFLANN<PointT, Dist>::nearestKSearch (const PointT &point, unsigned int k,
std::vector<int> &k_indices,
Indices &k_indices,
std::vector<float> &k_distances) const
{
assert (point_representation_->isValid (point) && "Invalid (NaN, Inf) point coordinates given to nearestKSearch!");
Expand All @@ -147,7 +147,7 @@ pcl::KdTreeFLANN<PointT, Dist>::nearestKSearch (const PointT &point, unsigned in
std::vector<float> query (dim_);
point_representation_->vectorize (static_cast<PointT> (point), query);

::flann::Matrix<int> k_indices_mat (&k_indices[0], 1, k);
::flann::Matrix<index_t> k_indices_mat (&k_indices[0], 1, k);
::flann::Matrix<float> k_distances_mat (&k_distances[0], 1, k);
// Wrap the k_indices and k_distances vectors (no data copy)
flann_index_->knnSearch (::flann::Matrix<float> (&query[0], 1, dim_),
Expand All @@ -159,7 +159,7 @@ pcl::KdTreeFLANN<PointT, Dist>::nearestKSearch (const PointT &point, unsigned in
{
for (std::size_t i = 0; i < static_cast<std::size_t> (k); ++i)
{
int& neighbor_index = k_indices[i];
auto& neighbor_index = k_indices[i];
neighbor_index = index_mapping_[neighbor_index];
}
}
Expand All @@ -169,7 +169,7 @@ pcl::KdTreeFLANN<PointT, Dist>::nearestKSearch (const PointT &point, unsigned in

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename Dist> int
pcl::KdTreeFLANN<PointT, Dist>::radiusSearch (const PointT &point, double radius, std::vector<int> &k_indices,
pcl::KdTreeFLANN<PointT, Dist>::radiusSearch (const PointT &point, double radius, Indices &k_indices,
std::vector<float> &k_sqr_dists, unsigned int max_nn) const
{
assert (point_representation_->isValid (point) && "Invalid (NaN, Inf) point coordinates given to radiusSearch!");
Expand All @@ -181,7 +181,7 @@ pcl::KdTreeFLANN<PointT, Dist>::radiusSearch (const PointT &point, double radius
if (max_nn == 0 || max_nn > total_nr_points_)
max_nn = total_nr_points_;

std::vector<std::vector<int> > indices(1);
std::vector<Indices > indices(1);
std::vector<std::vector<float> > dists(1);

::flann::SearchParams params (param_radius_);
Expand All @@ -204,7 +204,7 @@ pcl::KdTreeFLANN<PointT, Dist>::radiusSearch (const PointT &point, double radius
{
for (int i = 0; i < neighbors_in_radius; ++i)
{
int& neighbor_index = k_indices[i];
auto& neighbor_index = k_indices[i];
neighbor_index = index_mapping_[neighbor_index];
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ pcl::KdTreeFLANN<PointT, Dist>::convertCloudToArray (const PointCloud &cloud)

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename Dist> void
pcl::KdTreeFLANN<PointT, Dist>::convertCloudToArray (const PointCloud &cloud, const std::vector<int> &indices)
pcl::KdTreeFLANN<PointT, Dist>::convertCloudToArray (const PointCloud &cloud, const Indices &indices)
{
// No point in doing anything if the array is empty
if (cloud.empty ())
Expand Down
4 changes: 2 additions & 2 deletions kdtree/include/pcl/kdtree/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace pcl
template <typename PointT> void
getApproximateIndices (const typename pcl::PointCloud<PointT>::ConstPtr &cloud_in,
const typename pcl::PointCloud<PointT>::ConstPtr &cloud_ref,
std::vector<int> &indices);
Indices &indices);

/** \brief Get a set of approximate indices for a given point cloud into a reference point cloud.
* The coordinates of the two point clouds can differ. The method uses an internal KdTree for
Expand All @@ -69,7 +69,7 @@ namespace pcl
template <typename Point1T, typename Point2T> void
getApproximateIndices (const typename pcl::PointCloud<Point1T>::ConstPtr &cloud_in,
const typename pcl::PointCloud<Point2T>::ConstPtr &cloud_ref,
std::vector<int> &indices);
Indices &indices);
}

#include <pcl/kdtree/impl/io.hpp>
Loading