MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / extractPointsAtLevel

Method extractPointsAtLevel

tools/octree_viewer.cpp:364–421  ·  view source on GitHub ↗

\brief Extracts all the points of depth = level from the octree * */

Source from the content-addressed store, hash-verified

362 *
363 */
364 void extractPointsAtLevel(int depth)
365 {
366 displayCloud->points.clear();
367 cloudVoxel->points.clear();
368
369 pcl::PointXYZ pt_voxel_center;
370 pcl::PointXYZ pt_centroid;
371 std::cout << "===== Extracting data at depth " << depth << "... " << std::flush;
372 double start = pcl::getTime ();
373
374 for (pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::FixedDepthIterator tree_it = octree.fixed_depth_begin (depth);
375 tree_it != octree.fixed_depth_end ();
376 ++tree_it)
377 {
378 // Compute the point at the center of the voxel which represents the current OctreeNode
379 Eigen::Vector3f voxel_min, voxel_max;
380 octree.getVoxelBounds (tree_it, voxel_min, voxel_max);
381
382 pt_voxel_center.x = (voxel_min.x () + voxel_max.x ()) / 2.0f;
383 pt_voxel_center.y = (voxel_min.y () + voxel_max.y ()) / 2.0f;
384 pt_voxel_center.z = (voxel_min.z () + voxel_max.z ()) / 2.0f;
385 cloudVoxel->points.push_back (pt_voxel_center);
386
387 // If the asked depth is the depth of the octree, retrieve the centroid at this LeafNode
388 if (octree.getTreeDepth () == static_cast<unsigned int>(depth))
389 {
390 auto* container = dynamic_cast<pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::LeafNode*> (tree_it.getCurrentOctreeNode ());
391
392 container->getContainer ().getCentroid (pt_centroid);
393 }
394 // Else, compute the centroid of the LeafNode under the current BranchNode
395 else
396 {
397 // Retrieve every centroid under the current BranchNode
398 pcl::octree::OctreeKey dummy_key;
399 pcl::PointCloud<pcl::PointXYZ>::VectorType voxelCentroids;
400 octree.getVoxelCentroidsRecursive (dynamic_cast<pcl::octree::OctreePointCloudVoxelCentroid<pcl::PointXYZ>::BranchNode*> (*tree_it), dummy_key, voxelCentroids);
401
402 // Iterate over the leafs to compute the centroid of all of them
403 pcl::CentroidPoint<pcl::PointXYZ> centroid;
404 for (const auto &voxelCentroid : voxelCentroids)
405 {
406 centroid.add (voxelCentroid);
407 }
408 centroid.get (pt_centroid);
409 }
410
411 displayCloud->points.push_back (pt_centroid);
412 }
413
414 double end = pcl::getTime ();
415 printf("%zu pts, %.4gs. %.4gs./pt. =====\n",
416 static_cast<std::size_t>(displayCloud->size()),
417 end - start,
418 (end - start) / static_cast<double>(displayCloud->size()));
419
420 update();
421 }

Callers

nothing calls this directly

Calls 14

getTimeFunction · 0.85
fixed_depth_beginMethod · 0.80
fixed_depth_endMethod · 0.80
getVoxelBoundsMethod · 0.80
updateFunction · 0.70
clearMethod · 0.45
xMethod · 0.45
push_backMethod · 0.45
getTreeDepthMethod · 0.45
getCurrentOctreeNodeMethod · 0.45
getCentroidMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected