void ITM<ITM_TRAITS>::handleDeletions( node_type best, node_type second ) { observation_type & bestCentroid = graph_[best].centroid; observation_type & secondCentroid = graph_[second].centroid; // Don't know of other way to avoid iterator invalidation than to do this // twice. out_edge_iterator iChild; out_edge_iterator eChild; typename std::list<node_type> erase; for ( boost::tie( iChild, eChild ) = boost::out_edges( best, graph_ ); iChild != eChild; ++iChild ) { node_type child = boost::target( *iChild, graph_ ); if ( child != best ) { // Do not try to delete self-edges observation_type centroid = graph_[child].centroid; observation_type center = ( bestCentroid + centroid ) * 0.5; if ( distance_( center, secondCentroid ) < distance_( center, centroid ) ) { erase.push_back( child ); } } } typename std::list<node_type>::iterator iErase; typename std::list<node_type>::iterator eErase = erase.end(); for ( iErase = erase.begin(); iErase != eErase; ++iErase ) { boost::remove_edge( best, *iErase, graph_ ); boost::remove_edge( *iErase, best, graph_ ); boost::tie( iChild, eChild ) = boost::out_edges( *iErase, graph_ ); // The or condition is to handle self-edges if ( iChild == eChild || ( std::distance( iChild, eChild ) == 1 && boost::target( *iChild, graph_ ) == *iErase ) ) { boost::clear_vertex( *iErase, graph_ ); boost::remove_vertex( *iErase, graph_ ); } } }
/** * @param[in] dp Center of 3D point (dp[0], dp[1], dp[2]). * @param[in] radius Radius of a sphere. * @param[out] result resutl of the points. */ void find(const T &pnt, const double radius, typename std::list<T>& result) { if (this->_list.empty()) return; if (this->isLeaf()) { typename std::list<T>::iterator iter; const double sqr = radius * radius; for (iter = this->_list.begin() ; iter != this->_list.end() ; iter++) { double check = 0; for ( size_t i = 0 ; i < Dim ; i++) check += (iter->operator[](i) - pnt[i])*(iter->operator[](i) - pnt[i]); if ( check <= sqr ) result.push_back(*iter); } } else { const double p = this->_list.begin()->operator[](this->_dim); const double x = pnt[this->_dim]; if ( fabs(x-p) <= radius ) { this->_child[0].find(pnt, radius, result); this->_child[1].find(pnt, radius, result); } else { if ( x < p )this->_child[0].find(pnt, radius, result); else this->_child[1].find(pnt, radius, result); } } return; }