42 #include <pcl/memory.h>
43 #include <pcl/pcl_macros.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/common/point_tests.h>
46 #include <pcl/search/search.h>
47 #include <pcl/common/eigen.h>
64 template<
typename Po
intT>
75 using Ptr = shared_ptr<pcl::search::OrganizedNeighbor<PointT> >;
76 using ConstPtr = shared_ptr<const pcl::search::OrganizedNeighbor<PointT> >;
90 OrganizedNeighbor (
bool sorted_results =
false,
float eps = 1e-4f,
unsigned pyramid_level = 5)
114 float min_f = 0.043744332f *
static_cast<float>(
input_->width);
116 return (determinant3x3Matrix<Eigen::Matrix3f> (
KR_ / std::sqrt (
KR_KRT_.coeff (8))) >= (min_f * min_f));
148 for (std::size_t idx=0; idx<
input_->size(); ++idx)
170 std::vector<float> &k_sqr_distances,
171 unsigned int max_nn = 0)
const override;
213 std::vector<float> &k_sqr_distances)
const override;
252 float dist_x = point.x - query.x;
253 float dist_y = point.y - query.y;
254 float dist_z = point.z - query.z;
255 float squared_distance = dist_x * dist_x + dist_y * dist_y + dist_z * dist_z;
256 const auto queue_size = queue.size ();
257 const auto insert_into_queue = [&]{ queue.emplace (
258 std::upper_bound (queue.begin(), queue.end(), squared_distance,
259 [](
float dist,
const Entry& ent){
return dist<ent.distance; }),
260 index, squared_distance); };
263 insert_into_queue ();
264 return (queue_size + 1) == k;
266 if (queue.back ().distance > squared_distance)
269 insert_into_queue ();
277 clipRange (
int& begin,
int &end,
int min,
int max)
const
279 begin = std::max (std::min (begin, max), min);
280 end = std::min (std::max (end, min), max);
293 unsigned& maxX,
unsigned& maxY)
const;
300 Eigen::Matrix<float, 3, 3, Eigen::RowMajor>
KR_;
303 Eigen::Matrix<float, 3, 3, Eigen::RowMajor>
KR_KRT_;
319 #ifdef PCL_NO_PRECOMPILE
320 #include <pcl/search/impl/organized.hpp>
shared_ptr< const pcl::search::OrganizedNeighbor< PointT > > ConstPtr
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
typename PointCloud::Ptr PointCloudPtr
shared_ptr< PointCloud< PointT > > Ptr
bool projectPoint(const PointT &p, pcl::PointXY &q) const
projects a point into the image
Eigen::Matrix< float, 3, 3, Eigen::RowMajor > KR_KRT_
inveser of the left 3x3 projection matrix which is K * R (with K being the camera matrix and R the ro...
~OrganizedNeighbor() override=default
Empty deconstructor.
pcl::IndicesConstPtr IndicesConstPtr
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
PointCloudConstPtr input_
int radiusSearch(const PointT &p_q, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
Search for all neighbors of query point that are within a given radius.
Eigen::Matrix< float, 3, 3, Eigen::RowMajor > KR_
inveser of the left 3x3 projection matrix which is K * R (with K being the camera matrix and R the ro...
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
void setProjectionMatrix(const Eigen::Matrix< float, 3, 4 > &projection_matrix)
Set projection matrix manually.
A 2D point structure representing Euclidean xy coordinates.
Entry(index_t idx, float dist)
bool testPoint(const PointT &query, unsigned k, std::vector< Entry > &queue, index_t index) const
test if point given by index is among the k NN in results to the query point.
bool isValid() const
Test whether this search-object is valid (input is organized AND from projective device) User should ...
typename PointCloud::ConstPtr PointCloudConstPtr
const unsigned pyramid_level_
using only a subsample of points to calculate the projection matrix.
std::vector< unsigned char > mask_
mask, indicating whether the point was in the indices list or not, and whether it is finite...
void computeCameraMatrix(Eigen::Matrix3f &camera_matrix) const
Compute the camera matrix.
OrganizedNeighbor(bool sorted_results=false, float eps=1e-4f, unsigned pyramid_level=5)
Constructor.
Eigen::Matrix< float, 3, 4, Eigen::RowMajor > projection_matrix_
the projection matrix.
void clipRange(int &begin, int &end, int min, int max) const
shared_ptr< pcl::search::OrganizedNeighbor< PointT > > Ptr
IndicesAllocator<> Indices
Type used for indices in PCL.
bool testProjectionMatrix() const
Quick test if projection matrix and input cloud work together.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
int nearestKSearch(const PointT &p_q, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
Search for the k-nearest neighbors for a given query point.
float eps_
epsilon value for the MSE of the projection matrix estimation
void getProjectedRadiusSearchBox(const PointT &point, float squared_radius, unsigned &minX, unsigned &minY, unsigned &maxX, unsigned &maxY) const
Obtain a search box in 2D from a sphere with a radius in 3D.
shared_ptr< const PointCloud< PointT > > ConstPtr
OrganizedNeighbor is a class for optimized nearest neighbor search in organized projectable point clo...
bool operator<(const Entry &other) const
A point structure representing Euclidean xyz coordinates, and the RGB color.
bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input data set, if user has focal length he must set it before calling this...
bool estimateProjectionMatrix()
Estimate the projection matrix from the input cloud.