| 58 | { |
| 59 | public: |
| 60 | OctreeViewer (std::string &filename, double resolution) : |
| 61 | viz ("Octree visualizator"), |
| 62 | cloud (new pcl::PointCloud<pcl::PointXYZ>()), |
| 63 | displayCloud (new pcl::PointCloud<pcl::PointXYZ>()), |
| 64 | cloudVoxel (new pcl::PointCloud<pcl::PointXYZ>()), |
| 65 | octree (resolution) |
| 66 | { |
| 67 | |
| 68 | //try to load the cloud |
| 69 | if (!loadCloud(filename)) |
| 70 | return; |
| 71 | |
| 72 | //register keyboard callbacks |
| 73 | viz.registerKeyboardCallback(&OctreeViewer::keyboardEventOccurred, *this, nullptr); |
| 74 | |
| 75 | //key legends |
| 76 | viz.addText ("Keys:", 0, 170, 0.0, 1.0, 0.0, "keys_t"); |
| 77 | viz.addText ("a -> Increment displayed depth", 10, 155, 0.0, 1.0, 0.0, "key_a_t"); |
| 78 | viz.addText ("z -> Decrement displayed depth", 10, 140, 0.0, 1.0, 0.0, "key_z_t"); |
| 79 | viz.addText ("v -> Toggle octree cubes representation", 10, 125, 0.0, 1.0, 0.0, "key_v_t"); |
| 80 | viz.addText ("b -> Toggle centroid points representation", 10, 110, 0.0, 1.0, 0.0, "key_b_t"); |
| 81 | viz.addText ("n -> Toggle original point cloud representation", 10, 95, 0.0, 1.0, 0.0, "key_n_t"); |
| 82 | |
| 83 | //set current level to half the maximum one |
| 84 | displayedDepth = static_cast<int> (std::floor (octree.getTreeDepth() / 2.0)); |
| 85 | if (displayedDepth == 0) |
| 86 | displayedDepth = 1; |
| 87 | |
| 88 | // assign point cloud to octree |
| 89 | octree.setInputCloud (cloud); |
| 90 | |
| 91 | // add points from cloud to octree |
| 92 | octree.addPointsFromInputCloud (); |
| 93 | |
| 94 | //show octree at default depth |
| 95 | extractPointsAtLevel(displayedDepth); |
| 96 | |
| 97 | //reset camera |
| 98 | viz.resetCameraViewpoint("cloud"); |
| 99 | |
| 100 | //run main loop |
| 101 | run(); |
| 102 | |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | //======================================================== |
nothing calls this directly
no test coverage detected