void mouse_callback( int button, int state, int x, int y ){ if( state == 0 ){ for( int i = 0; i < nodes_len; i++ ){ if( return_dist_sqr( x, y, nodes[i].x, nodes[i].y ) <= nodes[i].radius*nodes[i].radius ){ if( button_press_count == 0 ){ nodes[i].is_start = true; button_press_count += 1; start = nodes[i]; }else if( button_press_count == 1 ){ nodes[i].is_end = true; button_press_count += 1; end = nodes[i]; shortest_path( nodes, nodes_len, start, end ); }else if( button_press_count == 2 ){ button_press_count = 0; for( int x = 0; x < nodes_len; x++ ){ nodes[x].is_end = false; nodes[x].is_start = false; } } } } } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////// // input void mouse_motion_callback( int x, int y ){ for( int i = 0; i < nodes_len; i++ ){ if( return_dist_sqr( x, y, nodes[i].x, nodes[i].y ) <= nodes[i].radius*nodes[i].radius ){ nodes[i].hover = true; }else{ nodes[i].hover = false; } } }
// cycle through array of nodes to add links to the ones within the given range void create_links( Node * n, int n_len, float range ){ for( int i = 0; i < n_len; i++ ){ for( int x = i; x < n_len; x++ ){ if( x != i && return_dist_sqr( n[i].x, n[i].y, n[x].x, n[x].y ) < range*range ){ //std::cout << "coonnect \n"; n[i].add_link( &n[x], true ); n[x].add_link( &n[i], false ); } } } }
void KDTree::neighborSearch(Point & query_point, unsigned int patch_size, std::vector<std::size_t> & return_index) { // The query point has to be converted from a C++ array to a C array because nanoflann library // expects C arrays. const Real query_pt[] = {query_point(0), query_point(1), query_point(2)}; return_index.resize(patch_size, std::numeric_limits<std::size_t>::max()); std::vector<Real> return_dist_sqr(patch_size, std::numeric_limits<Real>::max()); _kd_tree->knnSearch(&query_pt[0], patch_size, &return_index[0], &return_dist_sqr[0]); if (return_dist_sqr[0] == std::numeric_limits<Real>::max() || return_index[0] == std::numeric_limits<std::size_t>::max()) mooseError("Unable to find closest node!"); }