template<typename PointT, typename LeafContainerT, typename BranchContainerT> void pcl::octree::OctreePointCloudSuperVoxel<PointT, LeafContainerT, BranchContainerT>::computeSuperVoxelAdjacencyGraph (const std::map<uint32_t,PointSuperVoxel> &supervoxel_centers, VoxelAdjacencyList &supervoxel_adjacency_graph) { supervoxel_adjacency_graph.clear (); std::map<uint32_t,PointSuperVoxel>::const_iterator it_labels, it_labels_end; it_labels_end = supervoxel_centers.end (); //Add a vertex for each label, store ids in map std::map <uint32_t, VoxelID> label_ID_map; for (it_labels = supervoxel_centers.begin (); it_labels!=it_labels_end; ++it_labels) { VoxelID node_id = add_vertex (supervoxel_adjacency_graph); supervoxel_adjacency_graph[node_id] = (it_labels->second); label_ID_map.insert (std::make_pair (it_labels->first, node_id)); } typename OctreeSuperVoxelT::LeafNodeIterator leaf_itr; LeafContainerT *leaf_container; //Iterate through and add edges to adjacency graph for ( leaf_itr = this->leaf_begin () ; leaf_itr != this->leaf_end (); ++leaf_itr) { leaf_container = dynamic_cast<LeafContainerT*> (*leaf_itr); uint32_t leaf_label = leaf_container->getLabel (); if (leaf_label != 0) { typename std::set<LeafContainerT*>::iterator neighbor_itr; typename std::set<LeafContainerT*>::iterator neighbor_end; boost::tie (neighbor_itr, neighbor_end) = leaf_container->getAdjacentVoxels (); LeafContainerT* neighbor_container; for ( ; neighbor_itr != neighbor_end; ++neighbor_itr) { neighbor_container = *neighbor_itr; uint32_t neighbor_label = neighbor_container->getLabel (); if ( neighbor_label != 0 && neighbor_label != leaf_label) { //Labels are different for neighboring voxels, add an edge! bool edge_added; EdgeID edge; VoxelID u = (label_ID_map.find (leaf_label))->second; VoxelID v = (label_ID_map.find (neighbor_label))->second; boost::tie (edge, edge_added) = add_edge (u,v,supervoxel_adjacency_graph); //Calc distance between centers, set as edge weight if (edge_added) { float length = supervoxelDistance (supervoxel_centers.find (leaf_label)->second ,supervoxel_centers.find (neighbor_label)->second); supervoxel_adjacency_graph[edge].length = length; } } } } } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////// GETTER FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template <typename PointT> void pcl::SupervoxelClustering<PointT>::getSupervoxelAdjacencyList (VoxelAdjacencyList &adjacency_list_arg) const { adjacency_list_arg.clear (); //Add a vertex for each label, store ids in map std::map <uint32_t, VoxelID> label_ID_map; for (typename HelperListT::const_iterator sv_itr = supervoxel_helpers_.cbegin (); sv_itr != supervoxel_helpers_.cend (); ++sv_itr) { VoxelID node_id = add_vertex (adjacency_list_arg); adjacency_list_arg[node_id] = (sv_itr->getLabel ()); label_ID_map.insert (std::make_pair (sv_itr->getLabel (), node_id)); } for (typename HelperListT::const_iterator sv_itr = supervoxel_helpers_.cbegin (); sv_itr != supervoxel_helpers_.cend (); ++sv_itr) { uint32_t label = sv_itr->getLabel (); std::set<uint32_t> neighbor_labels; sv_itr->getNeighborLabels (neighbor_labels); for (std::set<uint32_t>::iterator label_itr = neighbor_labels.begin (); label_itr != neighbor_labels.end (); ++label_itr) { bool edge_added; EdgeID edge; VoxelID u = (label_ID_map.find (label))->second; VoxelID v = (label_ID_map.find (*label_itr))->second; boost::tie (edge, edge_added) = add_edge (u,v,adjacency_list_arg); //Calc distance between centers, set as edge weight if (edge_added) { VoxelData centroid_data = (sv_itr)->getCentroid (); //Find the neighbhor with this label VoxelData neighb_centroid_data; for (typename HelperListT::const_iterator neighb_itr = supervoxel_helpers_.cbegin (); neighb_itr != supervoxel_helpers_.cend (); ++neighb_itr) { if (neighb_itr->getLabel () == (*label_itr)) { neighb_centroid_data = neighb_itr->getCentroid (); break; } } float length = voxelDataDistance (centroid_data, neighb_centroid_data); adjacency_list_arg[edge] = length; } } } }