|
Graphviz
2.29.20120523.0446
|
00001 /* $Id$ $Revision$ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /************************************************************************* 00005 * Copyright (c) 2011 AT&T Intellectual Property 00006 * All rights reserved. This program and the accompanying materials 00007 * are made available under the terms of the Eclipse Public License v1.0 00008 * which accompanies this distribution, and is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * 00011 * Contributors: See CVS logs. Details at http://www.graphviz.org/ 00012 *************************************************************************/ 00013 00014 #ifdef HAVE_CONFIG_H 00015 #include "config.h" 00016 #endif 00017 00018 #include "SparseMatrix.h" 00019 #include "logic.h" 00020 #include "memory.h" 00021 #include "delaunay.h" 00022 00023 SparseMatrix call_tri(int n, int dim, real * x) 00024 { 00025 real one = 1; 00026 int i, ii, jj; 00027 SparseMatrix A; 00028 SparseMatrix B; 00029 int* edgelist = NULL; 00030 real* xv = N_GNEW(n, real); 00031 real* yv = N_GNEW(n, real); 00032 int numberofedges; 00033 00034 for (i = 0; i < n; i++) { 00035 xv[i] = x[i * 2]; 00036 yv[i] = x[i * 2 + 1]; 00037 } 00038 00039 if (n > 2) { 00040 edgelist = delaunay_tri (xv, yv, n, &numberofedges); 00041 } else { 00042 numberofedges = 0; 00043 } 00044 00045 A = SparseMatrix_new(n, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); 00046 for (i = 0; i < numberofedges; i++) { 00047 ii = edgelist[i * 2]; 00048 jj = edgelist[i * 2 + 1]; 00049 SparseMatrix_coordinate_form_add_entries(A, 1, &(ii), &(jj), &one); 00050 } 00051 if (n == 2) { /* if two points, add edge i->j */ 00052 ii = 0; 00053 jj = 1; 00054 SparseMatrix_coordinate_form_add_entries(A, 1, &(ii), &(jj), &one); 00055 } 00056 for (i = 0; i < n; i++) { 00057 SparseMatrix_coordinate_form_add_entries(A, 1, &i, &i, &one); 00058 } 00059 B = SparseMatrix_from_coordinate_format(A); 00060 SparseMatrix_delete(A); 00061 A = SparseMatrix_symmetrize(B, FALSE); 00062 SparseMatrix_delete(B); 00063 B = A; 00064 00065 free (edgelist); 00066 free (xv); 00067 free (yv); 00068 return B; 00069 } 00070 00071 SparseMatrix call_tri2(int n, int dim, real * xx) 00072 { 00073 real *x, *y; 00074 v_data *delaunay; 00075 int i, j; 00076 SparseMatrix A; 00077 SparseMatrix B; 00078 real one = 1; 00079 x = N_GNEW(n, real); 00080 y = N_GNEW(n, real); 00081 00082 for (i = 0; i < n; i++) { 00083 x[i] = xx[dim * i]; 00084 y[i] = xx[dim * i + 1]; 00085 } 00086 00087 delaunay = UG_graph(x, y, n, 0); 00088 00089 A = SparseMatrix_new(n, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); 00090 00091 for (i = 0; i < n; i++) { 00092 for (j = 1; j < delaunay[i].nedges; j++) { 00093 SparseMatrix_coordinate_form_add_entries(A, 1, &i, 00094 &(delaunay[i]. 00095 edges[j]), &one); 00096 } 00097 } 00098 for (i = 0; i < n; i++) { 00099 SparseMatrix_coordinate_form_add_entries(A, 1, &i, &i, &one); 00100 } 00101 B = SparseMatrix_from_coordinate_format(A); 00102 B = SparseMatrix_symmetrize(B, FALSE); 00103 SparseMatrix_delete(A); 00104 00105 free (x); 00106 free (y); 00107 freeGraph (delaunay); 00108 00109 return B; 00110 00111 } 00112
1.7.5