38 #ifndef PCL_OCTREE_POINTCLOUD_ADJACENCY_HPP_ 39 #define PCL_OCTREE_POINTCLOUD_ADJACENCY_HPP_ 41 #include <pcl/console/print.h> 50 #include <pcl/octree/impl/octree_pointcloud.hpp> 53 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
56 ,
OctreeBase<LeafContainerT, BranchContainerT> > (resolution_arg)
62 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
void 66 float minX = std::numeric_limits<float>::max (), minY = std::numeric_limits<float>::max (), minZ = std::numeric_limits<float>::max ();
67 float maxX = -std::numeric_limits<float>::max(), maxY = -std::numeric_limits<float>::max(), maxZ = -std::numeric_limits<float>::max();
69 for (
size_t i = 0; i < input_->size (); ++i)
71 PointT temp (input_->points[i]);
73 transform_func_ (temp);
89 this->defineBoundingBox (minX, minY, minZ, maxX, maxY, maxZ);
93 LeafContainerT *leaf_container;
95 leaf_vector_.reserve (this->getLeafCount ());
96 for ( leaf_itr = this->leaf_depth_begin () ; leaf_itr != this->leaf_depth_end (); ++leaf_itr)
102 leaf_container->computeData ();
104 computeNeighbors (leaf_key, leaf_container);
106 leaf_vector_.push_back (leaf_container);
109 assert (leaf_vector_.size () == this->getLeafCount ());
113 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
void 119 transform_func_ (temp);
123 key_arg.
x = static_cast<unsigned int> ((temp.x - this->min_x_) / this->resolution_);
124 key_arg.
y = static_cast<unsigned int> ((temp.y - this->min_y_) / this->resolution_);
125 key_arg.
z = static_cast<unsigned int> ((temp.z - this->min_z_) / this->resolution_);
135 key_arg.
x = static_cast<unsigned int> ((point_arg.x - this->min_x_) / this->resolution_);
136 key_arg.
y = static_cast<unsigned int> ((point_arg.y - this->min_y_) / this->resolution_);
137 key_arg.
z = static_cast<unsigned int> ((point_arg.z - this->min_z_) / this->resolution_);
142 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
void 147 assert (pointIdx_arg < static_cast<int> (this->input_->points.size ()));
149 const PointT& point = this->input_->points[pointIdx_arg];
154 this->genOctreeKeyforPoint (point, key);
156 LeafContainerT* container = this->createLeaf(key);
157 container->addPoint (point);
161 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
void 165 if (key_arg.
x > this->max_key_.x || key_arg.
y > this->max_key_.y || key_arg.
z > this->max_key_.z)
167 PCL_ERROR (
"OctreePointCloudAdjacency::computeNeighbors Requested neighbors for invalid octree key\n");
172 int dx_min = (key_arg.
x > 0) ? -1 : 0;
173 int dy_min = (key_arg.
y > 0) ? -1 : 0;
174 int dz_min = (key_arg.
z > 0) ? -1 : 0;
175 int dx_max = (key_arg.
x == this->max_key_.x) ? 0 : 1;
176 int dy_max = (key_arg.
y == this->max_key_.y) ? 0 : 1;
177 int dz_max = (key_arg.
z == this->max_key_.z) ? 0 : 1;
179 for (
int dx = dx_min; dx <= dx_max; ++dx)
181 for (
int dy = dy_min; dy <= dy_max; ++dy)
183 for (
int dz = dz_min; dz <= dz_max; ++dz)
185 neighbor_key.
x = static_cast<uint32_t> (key_arg.
x + dx);
186 neighbor_key.
y = static_cast<uint32_t> (key_arg.
y + dy);
187 neighbor_key.
z = static_cast<uint32_t> (key_arg.
z + dz);
188 LeafContainerT *neighbor = this->findLeaf (neighbor_key);
191 leaf_container->addNeighbor (neighbor);
201 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT> LeafContainerT*
203 const PointT& point_arg)
const 206 LeafContainerT* leaf = 0;
208 this->genOctreeKeyforPoint (point_arg, key);
210 leaf = this->findLeaf (key);
216 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
void 221 voxel_adjacency_graph.clear ();
223 std::map <LeafContainerT*, VoxelID> leaf_vertex_id_map;
226 OctreeKey leaf_key = leaf_itr.getCurrentOctreeKey ();
228 this->genLeafNodeCenterFromOctreeKey (leaf_key, centroid_point);
229 VoxelID node_id = add_vertex (voxel_adjacency_graph);
231 voxel_adjacency_graph[node_id] = centroid_point;
232 LeafContainerT* leaf_container = &(leaf_itr.getLeafContainer ());
233 leaf_vertex_id_map[leaf_container] = node_id;
237 for (
typename std::vector<LeafContainerT*>::iterator leaf_itr = leaf_vector_.begin (); leaf_itr != leaf_vector_.end (); ++leaf_itr)
239 typename LeafContainerT::iterator neighbor_itr = (*leaf_itr)->begin ();
240 typename LeafContainerT::iterator neighbor_end = (*leaf_itr)->end ();
241 LeafContainerT* neighbor_container;
242 VoxelID u = (leaf_vertex_id_map.find (*leaf_itr))->second;
243 PointT p_u = voxel_adjacency_graph[u];
244 for ( ; neighbor_itr != neighbor_end; ++neighbor_itr)
246 neighbor_container = *neighbor_itr;
249 VoxelID v = (leaf_vertex_id_map.find (neighbor_container))->second;
250 boost::tie (edge, edge_added) = add_edge (u,v,voxel_adjacency_graph);
252 PointT p_v = voxel_adjacency_graph[v];
253 float dist = (p_v.getVector3fMap () - p_u.getVector3fMap ()).norm ();
254 voxel_adjacency_graph[edge] = dist;
263 template<
typename Po
intT,
typename LeafContainerT,
typename BranchContainerT>
bool 267 this->genOctreeKeyforPoint (point_arg, key);
269 Eigen::Vector3f sensor(camera_pos.x,
273 Eigen::Vector3f leaf_centroid(static_cast<float> ((static_cast<double> (key.
x) + 0.5f) * this->resolution_ + this->min_x_),
274 static_cast<float> ((static_cast<double> (key.
y) + 0.5f) * this->resolution_ + this->min_y_),
275 static_cast<float> ((static_cast<double> (key.
z) + 0.5f) * this->resolution_ + this->min_z_));
276 Eigen::Vector3f direction = sensor - leaf_centroid;
278 float norm = direction.norm ();
279 direction.normalize ();
280 float precision = 1.0f;
281 const float step_size = static_cast<const float> (resolution_) * precision;
282 const int nsteps = std::max (1, static_cast<int> (norm / step_size));
286 Eigen::Vector3f p = leaf_centroid;
288 for (
int i = 0; i < nsteps; ++i)
291 p += (direction * step_size);
298 this->genOctreeKeyforPoint (octree_p, key);
301 if ((key == prev_key))
306 LeafContainerT *leaf = this->findLeaf (key);
319 #define PCL_INSTANTIATE_OctreePointCloudAdjacency(T) template class PCL_EXPORTS pcl::octree::OctreePointCloudAdjacency<T>; void genOctreeKeyforPoint(const PointT &point_arg, OctreeKey &key_arg) const
Generates octree key for specified point (uses transform if provided).
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...
void addPointsFromInputCloud()
Add points from input point cloud to octree.
OctreePointCloudAdjacency(const double resolution_arg)
Constructor.
Defines some geometrical functions and utility functions.
VoxelAdjacencyList::vertex_descriptor VoxelID
const LeafContainer & getLeafContainer() const
Method for retrieving a single leaf container from the octree leaf node.
VoxelAdjacencyList::edge_descriptor EdgeID
virtual void addPointIdx(const int point_idx_arg)
Add point at index from input pointcloud dataset to octree.
void computeNeighbors(OctreeKey &key_arg, LeafContainerT *leaf_container)
Fills in the neighbors fields for new voxels.
A point structure representing Euclidean xyz coordinates.
Octree leaf node iterator class.
LeafContainerT * getLeafContainerAtPoint(const PointT &point_arg) const
Gets the leaf container for a given point.
const OctreeKey & getCurrentOctreeKey() const
Get octree key for the current iterator octree node.
bool testForOcclusion(const PointT &point_arg, const PointXYZ &camera_pos=PointXYZ(0, 0, 0))
Tests whether input point is occluded from specified camera point by other voxels.
boost::adjacency_list< boost::setS, boost::setS, boost::undirectedS, PointT, float > VoxelAdjacencyList
void computeVoxelAdjacencyGraph(VoxelAdjacencyList &voxel_adjacency_graph)
Computes an adjacency graph of voxel relations.
A point structure representing Euclidean xyz coordinates, and the RGB color.
void addPointsFromInputCloud()
Adds points from cloud to the octree.