cl_list* clusterization(grid *grd) { int_list *cell = NULL; cluster *parent = NULL; cl_list *current = NULL; cl_list *clusters = NULL; int k; for (k = 0; k < grd->width * grd->height; k++) { if (grd->cells[k] == SITE_OPEN) { cell = int_list_create_node(k); parent = cluster_create(cell, k < grd->width, k >= (grd->height - 1) * grd->width); // get list of clusters that contain grd->cells[k] current = find_neighbors(&clusters, grd, k); while (current != NULL) { cluster_join(&parent, &(current->item)); free(current->item); current = current->next; } cl_list_push_item(&clusters, parent); grd->cells[k] = SITE_FULL; } } return clusters; }
void SurfaceEdgeCollapse::update(int &red_tri, int v1, int v2, Star &star, pair *link, int num_link, float x_0, float y_0, float z_0) { // To be invoked to complete each edge collapsing iteration. // Removes the vertex v2 from the vertex list, updates the coordinates of v1 // as well as all affected structures in the program: // stars of vertices in link, tri_list, heap, stars[v1] int l; int tri[2]; int vert[MAXTRI]; int to_remove = 0; int to_update = 0; // tri = pair of triangles to remove find_neighbors(v1, v2, star, to_remove, tri); if (!((to_remove == 2) || (star.boundary && (to_remove == 1)))) Covise::sendInfo("Edge has wrong number of neighbors!"); // vert = array of vertices in the link (to be updated) extract_points(v1, v2, num_link, link, to_update, vert); // update stars around the link for (l = 0; l < to_update; l++) update_star(v1, v2, star, l, vert, to_remove, tri); // update coordinates and label v2 as removed coords_x[v1] = x_0; coords_y[v1] = y_0; coords_z[v1] = z_0; is_removed[v2] = 1; // update star and tri_list update_global_structures(v1, v2, star, to_remove, tri); if (to_remove == 2) red_tri -= 2; else red_tri--; // copy star to stars[v1] delete[] stars[v1].tri; stars[v1].tri = new int[star.num_tri]; for (l = 0; l < star.num_tri; l++) stars[v1].tri[l] = star.tri[l]; stars[v1].num_tri = star.num_tri; stars[v1].boundary = star.boundary; stars[v1].manifold = star.manifold; if (angle[v2] > angle[v1]) angle[v1] = angle[v2]; //angle[v1] = (angle[v1] || angle[v2]); // update heap and edge_array update_heap(v1, v2, star, to_remove, tri); delete[] star.tri; }
void DBSCAN::dbscan( const DBSCAN::DistanceMatrix& dm ) { std::vector< uint8_t > visited( dm.size1() ); uint32_t cluster_id = 0; for ( uint32_t pid = 0; pid < dm.size1(); ++pid ) { if ( !visited[pid] ) { visited[pid] = 1; Neighbors ne = find_neighbors( dm, pid ); if ( ne.size() >= m_min_elems ) { m_labels[pid] = cluster_id; for ( uint32_t i = 0; i < ne.size(); ++i ) { uint32_t nPid = ne[i]; if ( !visited[nPid] ) { visited[nPid] = 1; Neighbors ne1 = find_neighbors( dm, nPid ); if ( ne1.size() >= m_min_elems ) { for ( const auto& n1 : ne1 ) { ne.push_back( n1 ); } } } if ( m_labels[nPid] == -1 ) { m_labels[nPid] = cluster_id; } } ++cluster_id; } } } }
/* ************************************************** */ int bootstrap(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity}; int nb_neigh = 0; nb_neigh=nb_neigh; /* Get mac header overhead */ nodedata->overhead = GET_HEADER_SIZE(&c0); /* Find all the node's neighbors (i.e. the one in range) */ nb_neigh = find_neighbors(c); PRINT_ROUTING("Node %d has %d neighbors\n", c->node, nb_neigh); return 0; }
void search_neighbors(double **x,double **cy,struct param p,struct sfound sf) { int ei,ej,i,hdim,whichsize,whichbox; long found; double epsilon; hdim=p.hdim; ei=(int)(cy[0][hdim]*EPSILONS); if (ei < 0) ei=0; else if (ei>(EPSILONS-1)) ei=EPSILONS-1; ej=(int)(cy[nsseconddim][hdim]*EPSILONS); if (ej < 0) ej=0; else if (ej>(EPSILONS-1)) ej=EPSILONS-1; if (countstarteps[ei][ej] > 0) epsilon=starteps[ei][ej]/countstarteps[ei][ej]; else epsilon=0.001; found=0; epsilon /= EPSFAC; while (found < p.MINN) { epsilon *= EPSFAC; whichsize=(int)(1.0/epsilon); if (whichsize > neigh[NEIGH-1].n) whichbox=NEIGH-1; else { whichbox=0; for (i=NEIGH-1; i>0; i--) { if ((whichsize > neigh[i-1].n) && (whichsize <= neigh[i].n)) whichbox=i-1; } } found=find_neighbors(x,cy,whichbox,p,sf,epsilon); } sort(found,p,sf); if (sf.distance[p.MINN-1] == 0.0) { fprintf(stderr,"all neighbors collapse to one point. Maybe add\n" "initial noise to the data\n"); exit(SEARCH_NEIGHBORS_ZERO_DISTANCE); } starteps[ei][ej] += sf.distance[p.MINN-1]; countstarteps[ei][ej]++; }
void generate_maze(long col, uint16_t (*cell)[col], long row, struct node *head ,long cl, char (*maze)[cl], long rl) { set_seed(); long cell_count = row*col; long visited_count = 1; // selected col/row long sc = get_rand(col); long sr = get_rand(row); // keep 1 before for visual (knock down wall) long sc_old = sc; long sr_old = sr; /* printf("AT (%ld, %ld)\n", sc, sr); */ int *dir_good = malloc(sizeof(int) * 4); update_maze(cl, maze, rl, sr, sc, sr_old, sc_old, START); while (visited_count < cell_count) { int neighbor_count = find_neighbors(col, cell, row, sc, sr, dir_good); if (neighbor_count > 0) { // pick a direction to go sc_old = sc; sr_old = sr; select_dir(col, cell, &sc, &sr, dir_good, head); update_maze(cl, maze, rl, sr, sc, sr_old, sc_old, PATH); visited_count++; } else { // backtrack struct coord loc = stack_pop(head); if (loc.col > sc) cell[sr][sc] = cell[sr][sc] | 0x2000; // east if (loc.col < sc) cell[sr][sc] = cell[sr][sc] | 0x8000; // west if (loc.row > sr) cell[sr][sc] = cell[sr][sc] | 0x4000; // south if (loc.row < sr) cell[sr][sc] = cell[sr][sc] | 0x1000; // north // new loc update_maze(cl, maze, rl, loc.row, loc.col, sr, sc, BACK); sc = loc.col; sr = loc.row; /* printf("BA (%ld, %ld)\n", sc, sr); */ } } update_maze(cl, maze, rl, sr, sc, sr_old, sc_old, END); free(dir_good); }
/******************************************************************************\ Sets up a plain icosahedron. The icosahedron has 12 vertices: (0, ±1, ±φ) (±1, ±φ, 0) (±φ, 0, ±1) http://en.wikipedia.org/wiki/Icosahedron#Cartesian_coordinates We need to have duplicates however because we keep three vertices for each face, regardless of unique position because their UV coordinates will probably be different. \******************************************************************************/ static void generate_icosahedron(void) { int i, regular_faces[] = { /* Front faces */ 7, 5, 4, 5, 7, 0, 0, 2, 5, 3, 5, 2, 2, 10, 3, 10, 2, 1, /* Rear faces */ 1, 11, 10, 11, 1, 6, 6, 8, 11, 9, 11, 8, 8, 4, 9, 4, 8, 7, /* Top/bottom faces */ 0, 6, 1, 6, 0, 7, 9, 3, 10, 3, 9, 4, }; flip_limit = 4; r_tiles_max = 20; r_globe_radius = sqrtf(C_TAU + 2); /* Flipped (over 0 vertex) face vertices */ r_globe_verts[0].v.co = C_vec3(0, C_TAU, 1); r_globe_verts[1].v.co = C_vec3(-C_TAU, 1, 0); r_globe_verts[2].v.co = C_vec3(-1, 0, C_TAU); r_globe_verts[3].v.co = C_vec3(0, -C_TAU, 1); r_globe_verts[4].v.co = C_vec3(C_TAU, -1, 0); r_globe_verts[5].v.co = C_vec3(1, 0, C_TAU); r_globe_verts[6].v.co = C_vec3(0, C_TAU, -1); r_globe_verts[7].v.co = C_vec3(C_TAU, 1, 0); r_globe_verts[8].v.co = C_vec3(1, 0, -C_TAU); r_globe_verts[9].v.co = C_vec3(0, -C_TAU, -1); r_globe_verts[10].v.co = C_vec3(-C_TAU, -1, 0); r_globe_verts[11].v.co = C_vec3(-1, 0, -C_TAU); /* Regular face vertices */ for (i = 12; i < r_tiles_max * 3; i++) { int index; index = regular_faces[i - 12]; r_globe_verts[i].v.co = r_globe_verts[index].v.co; } find_neighbors(); }
/************************************************************************* ************************************************************************** #cat: count_minutia_ridges - Takes a minutia, and determines its closest #cat: neighbors and counts the number of interveining ridges #cat: between the minutia point and each of its neighbors. Input: minutia - input minutia bdata - binary image data (0==while & 1==black) iw - width (in pixels) of image ih - height (in pixels) of image lfsparms - parameters and thresholds for controlling LFS Output: minutiae - minutia augmented with neighbors and ridge counts Return Code: Zero - successful completion Negative - system error **************************************************************************/ int count_minutia_ridges(const int first, MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, const LFSPARMS *lfsparms) { int i, ret, *nbr_list, *nbr_nridges, nnbrs; /* Find up to the maximum number of qualifying neighbors. */ if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, first, minutiae))){ free(nbr_list); return(ret); } print2log("NBRS FOUND: %d,%d = %d\n", minutiae->list[first]->x, minutiae->list[first]->y, nnbrs); /* If no neighors found ... */ if(nnbrs == 0){ /* Then no list returned and no ridges to count. */ return(0); } /* Sort neighbors on delta dirs. */ if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){ free(nbr_list); return(ret); } /* Count ridges between first and neighbors. */ /* List of ridge counts, one for each neighbor stored. */ nbr_nridges = (int *)malloc(nnbrs * sizeof(int)); if(nbr_nridges == (int *)NULL){ free(nbr_list); fprintf(stderr, "ERROR : count_minutia_ridges : malloc : nbr_nridges\n"); return(-450); } /* Foreach neighbor found and sorted in list ... */ for(i = 0; i < nnbrs; i++){ /* Count the ridges between the primary minutia and the neighbor. */ ret = ridge_count(first, nbr_list[i], minutiae, bdata, iw, ih, lfsparms); /* If system error ... */ if(ret < 0){ /* Deallocate working memories. */ free(nbr_list); free(nbr_nridges); /* Return error code. */ return(ret); } /* Otherwise, ridge count successful, so store ridge count to list. */ nbr_nridges[i] = ret; } /* Assign neighbor indices and ridge counts to primary minutia. */ minutiae->list[first]->nbrs = nbr_list; minutiae->list[first]->ridge_counts = nbr_nridges; minutiae->list[first]->num_nbrs = nnbrs; /* Return normally. */ return(0); }
void ir3_group(struct ir3 *ir) { ir3_clear_mark(ir); find_neighbors(ir); }