30 #ifndef MCL_3DL_CHUNKED_KDTREE_H 31 #define MCL_3DL_CHUNKED_KDTREE_H 36 #include <unordered_map> 39 #include <pcl/point_types.h> 40 #include <pcl/kdtree/kdtree.h> 41 #include <pcl/kdtree/kdtree_flann.h> 45 template <
typename POINT_TYPE>
49 using Ptr = std::shared_ptr<ChunkedKdtree>;
54 using Ptr = std::shared_ptr<ChunkId>;
62 return x_ == a.
x_ && y_ == a.
y_ && z_ == a.
z_;
74 return (
id.x_) ^ (
id.y_ << 11) ^ (
id.z_ << 22);
76 ChunkId(
const int x,
const int y,
const int z)
91 const float chunk_length = 20.0,
92 const float max_search_radius = 1.0,
93 const bool keep_clouds =
false)
108 chunk.second.kdtree_->setEpsilon(
epsilon_);
117 chunk.second.kdtree_->setPointRepresentation(
point_rep_);
125 const typename pcl::PointCloud<POINT_TYPE>::ConstPtr& cloud)
133 for (
auto& p : *cloud)
136 clouds[chunk_id].push_back(p);
137 ids[chunk_id].push_back(i);
160 if (x_bound && y_bound && z_bound)
163 clouds[id].push_back(p);
164 ids[id].push_back(i);
166 if (x_bound && y_bound)
169 clouds[id].push_back(p);
170 ids[id].push_back(i);
172 if (y_bound && z_bound)
175 clouds[id].push_back(p);
176 ids[id].push_back(i);
178 if (z_bound && x_bound)
181 clouds[id].push_back(p);
182 ids[id].push_back(i);
187 clouds[id].push_back(p);
188 ids[id].push_back(i);
193 clouds[id].push_back(p);
194 ids[id].push_back(i);
199 clouds[id].push_back(p);
200 ids[id].push_back(i);
204 for (
auto& cloud : clouds)
210 auto cloud_ptr = cloud.second.makeShared();
211 chunks_[cloud.first].kdtree_->setInputCloud(cloud_ptr);
213 chunks_[cloud.first].cloud_ = cloud_ptr;
214 chunks_[cloud.first].original_ids_ = ids[cloud.first];
220 std::vector<int>&
id,
221 std::vector<float>& dist_sq,
225 throw std::runtime_error(
"ChunkedKdtree: radius must be <chunk_length");
231 const auto ret =
chunks_[chunk_id].kdtree_->radiusSearch(p, radius,
id, dist_sq, num);
234 i =
chunks_[chunk_id].original_ids_[i];
245 return typename pcl::KdTreeFLANN<POINT_TYPE>::Ptr();
248 typename pcl::PointCloud<POINT_TYPE>::Ptr
getChunkCloud(
const POINT_TYPE& p)
255 return typename pcl::PointCloud<POINT_TYPE>::Ptr();
269 typename pcl::KdTreeFLANN<POINT_TYPE>::Ptr
kdtree_;
271 typename pcl::PointCloud<POINT_TYPE>::Ptr
cloud_;
274 : kdtree_(new
pcl::KdTreeFLANN<POINT_TYPE>)
288 using ChunkMap = std::unordered_map<ChunkId, Chunk, ChunkId>;
296 #endif // MCL_3DL_CHUNKED_KDTREE_H std::vector< size_t > original_ids_
pcl::PointCloud< POINT_TYPE >::Ptr getChunkCloud(const ChunkId &c)
const float chunk_length_
ChunkId getChunkId(const POINT_TYPE &p) const
std::shared_ptr< ChunkedKdtree > Ptr
void setInputCloud(const typename pcl::PointCloud< POINT_TYPE >::ConstPtr &cloud)
ChunkId(const int x, const int y, const int z)
pcl::KdTreeFLANN< POINT_TYPE >::Ptr getChunkKdtree(const POINT_TYPE &p)
sensor_msgs::PointCloud2 PointCloud
std::unordered_map< ChunkId, typename pcl::PointCloud< mcl_3dl::PointXYZIL >, ChunkId > ChunkCloud
pcl::KdTreeFLANN< POINT_TYPE >::Ptr kdtree_
ChunkedKdtree(const float chunk_length=20.0, const float max_search_radius=1.0, const bool keep_clouds=false)
pcl::PointCloud< POINT_TYPE >::Ptr getChunkCloud(const POINT_TYPE &p)
constexpr bool operator!=(const ChunkId &a) const
int radiusSearch(const POINT_TYPE &p, const float &radius, std::vector< int > &id, std::vector< float > &dist_sq, const size_t &num)
std::unordered_map< ChunkId, Chunk, ChunkId > ChunkMap
std::shared_ptr< ChunkId > Ptr
pcl::PointCloud< POINT_TYPE >::ConstPtr input_cloud_
const float max_search_radius_
void setPointRepresentation(boost::shared_ptr< pcl::PointRepresentation< POINT_TYPE >> point_rep)
constexpr ChunkId operator+(const ChunkId &a) const
boost::shared_ptr< pcl::PointRepresentation< POINT_TYPE > > point_rep_
std::unordered_map< ChunkId, std::vector< size_t >, ChunkId > ChunkOriginalIds
const float pos_to_chunk_
pcl::PointCloud< POINT_TYPE >::Ptr cloud_
pcl::KdTreeFLANN< POINT_TYPE >::Ptr getChunkKdtree(const ChunkId &c)
constexpr bool operator==(const ChunkId &a) const
size_t operator()(const ChunkId &id) const
void setEpsilon(const float epsilon)
const pcl::PointCloud< POINT_TYPE >::ConstPtr & getInputCloud() const