Hierarchy *makeHier(int nn, int ne, v_data * graph, double *x_coords, double *y_coords, hierparms_t* parms) { v_data *delaunay; ex_vtx_data *geom_graph; int ngeom_edges; Hierarchy *hp; int i; delaunay = UG_graph(x_coords, y_coords, nn, 0); ngeom_edges = init_ex_graph(delaunay, graph, nn, x_coords, y_coords, &geom_graph); free(delaunay[0].edges); free(delaunay); hp = create_hierarchy(graph, nn, ne, geom_graph, ngeom_edges, parms); free(geom_graph[0].edges); free(geom_graph); init_active_level(hp, 0); geom_graph = hp->geom_graphs[0]; for (i = 0; i < hp->nvtxs[0]; i++) { geom_graph[i].physical_x_coord = (float) x_coords[i]; geom_graph[i].physical_y_coord = (float) y_coords[i]; } /* dumpHier (hp); */ return hp; }
SparseMatrix call_tri2(int n, int dim, real * xx) { real *x, *y; v_data *delaunay; int i, j; SparseMatrix A; SparseMatrix B; real one = 1; x = N_GNEW(n, real); y = N_GNEW(n, real); for (i = 0; i < n; i++) { x[i] = xx[dim * i]; y[i] = xx[dim * i + 1]; } delaunay = UG_graph(x, y, n, 0); A = SparseMatrix_new(n, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); for (i = 0; i < n; i++) { for (j = 1; j < delaunay[i].nedges; j++) { SparseMatrix_coordinate_form_add_entries(A, 1, &i, &(delaunay[i]. edges[j]), &one); } } for (i = 0; i < n; i++) { SparseMatrix_coordinate_form_add_entries(A, 1, &i, &i, &one); } B = SparseMatrix_from_coordinate_format(A); B = SparseMatrix_symmetrize(B, FALSE); SparseMatrix_delete(A); free (x); free (y); freeGraph (delaunay); return B; }
void rescale_layout_polar(double *x_coords, double *y_coords, double *x_foci, double *y_foci, int num_foci, int n, int interval, double width, double height, double margin, double distortion) { // Polar distortion - main function int i; double minX, maxX, minY, maxY; double aspect_ratio; v_data *graph; double scaleX; double scale_ratio; width -= 2 * margin; height -= 2 * margin; // compute original aspect ratio minX = maxX = x_coords[0]; minY = maxY = y_coords[0]; for (i = 1; i < n; i++) { if (x_coords[i] < minX) minX = x_coords[i]; if (y_coords[i] < minY) minY = y_coords[i]; if (x_coords[i] > maxX) maxX = x_coords[i]; if (y_coords[i] > maxY) maxY = y_coords[i]; } aspect_ratio = (maxX - minX) / (maxY - minY); // construct mutual neighborhood graph graph = UG_graph(x_coords, y_coords, n, 0); if (num_foci == 1) { // accelerate execution of most common case rescale_layout_polarFocus(graph, n, x_coords, y_coords, x_foci[0], y_foci[0], interval, distortion); } else { // average-based rescale double *final_x_coords = N_NEW(n, double); double *final_y_coords = N_NEW(n, double); double *cp_x_coords = N_NEW(n, double); double *cp_y_coords = N_NEW(n, double); for (i = 0; i < n; i++) { final_x_coords[i] = final_y_coords[i] = 0; } for (i = 0; i < num_foci; i++) { cpvec(cp_x_coords, 0, n - 1, x_coords); cpvec(cp_y_coords, 0, n - 1, y_coords); rescale_layout_polarFocus(graph, n, cp_x_coords, cp_y_coords, x_foci[i], y_foci[i], interval, distortion); scadd(final_x_coords, 0, n - 1, 1.0 / num_foci, cp_x_coords); scadd(final_y_coords, 0, n - 1, 1.0 / num_foci, cp_y_coords); } cpvec(x_coords, 0, n - 1, final_x_coords); cpvec(y_coords, 0, n - 1, final_y_coords); free(final_x_coords); free(final_y_coords); free(cp_x_coords); free(cp_y_coords); } free(graph[0].edges); free(graph); minX = maxX = x_coords[0]; minY = maxY = y_coords[0]; for (i = 1; i < n; i++) { if (x_coords[i] < minX) minX = x_coords[i]; if (y_coords[i] < minY) minY = y_coords[i]; if (x_coords[i] > maxX) maxX = x_coords[i]; if (y_coords[i] > maxY) maxY = y_coords[i]; } // shift points: for (i = 0; i < n; i++) { x_coords[i] -= minX; y_coords[i] -= minY; } // rescale x_coords to maintain aspect ratio: scaleX = aspect_ratio * (maxY - minY) / (maxX - minX); for (i = 0; i < n; i++) { x_coords[i] *= scaleX; } // scale the layout to fit full drawing area: scale_ratio = MIN((width) / (aspect_ratio * (maxY - minY)), (height) / (maxY - minY)); for (i = 0; i < n; i++) { x_coords[i] *= scale_ratio; y_coords[i] *= scale_ratio; } for (i = 0; i < n; i++) { x_coords[i] += margin; y_coords[i] += margin; } }
void rescale_layout(double *x_coords, double *y_coords, int n, int interval, double width, double height, double margin, double distortion) { // Rectlinear distortion - main function int i; double minX, maxX, minY, maxY; double aspect_ratio; v_data *graph; double scaleX; double scale_ratio; width -= 2 * margin; height -= 2 * margin; // compute original aspect ratio minX = maxX = x_coords[0]; minY = maxY = y_coords[0]; for (i = 1; i < n; i++) { if (x_coords[i] < minX) minX = x_coords[i]; if (y_coords[i] < minY) minY = y_coords[i]; if (x_coords[i] > maxX) maxX = x_coords[i]; if (y_coords[i] > maxY) maxY = y_coords[i]; } aspect_ratio = (maxX - minX) / (maxY - minY); // construct mutual neighborhood graph graph = UG_graph(x_coords, y_coords, n, 0); rescaleLayout(graph, n, x_coords, y_coords, interval, distortion); free(graph[0].edges); free(graph); // compute new aspect ratio minX = maxX = x_coords[0]; minY = maxY = y_coords[0]; for (i = 1; i < n; i++) { if (x_coords[i] < minX) minX = x_coords[i]; if (y_coords[i] < minY) minY = y_coords[i]; if (x_coords[i] > maxX) maxX = x_coords[i]; if (y_coords[i] > maxY) maxY = y_coords[i]; } // shift points: for (i = 0; i < n; i++) { x_coords[i] -= minX; y_coords[i] -= minY; } // rescale x_coords to maintain aspect ratio: scaleX = aspect_ratio * (maxY - minY) / (maxX - minX); for (i = 0; i < n; i++) { x_coords[i] *= scaleX; } // scale the layout to fit full drawing area: scale_ratio = MIN((width) / (aspect_ratio * (maxY - minY)), (height) / (maxY - minY)); for (i = 0; i < n; i++) { x_coords[i] *= scale_ratio; y_coords[i] *= scale_ratio; } for (i = 0; i < n; i++) { x_coords[i] += margin; y_coords[i] += margin; } }