25 double cos_critical,
int check_edges_with_same_endpoint,
26 char *xsplines1,
char *xsplines2){
33 size_t len1 = 100, len2 = 100;
34 size_t ns1 = 0, ns2 = 0;
35 int iter1 = 0, iter2 = 0;
37 int endp1 = 0, endp2 = 0;
40 double *x1 =
gv_calloc(len1,
sizeof(
double));
41 double *x2 =
gv_calloc(len2,
sizeof(
double));
51 if(strstr(xsplines1,
"e,")){
53 xsplines1 = strstr(xsplines1,
"e,") + 2;
54 }
else if (strstr(xsplines1,
"s,")){
55 xsplines1 = strstr(xsplines1,
"s,") + 2;
58 while (xsplines1 && sscanf(xsplines1,
"%lf,%lf", &(x1[ns1*dim]), &x1[ns1*dim + 1]) == 2){
59 if (endp1 && iter1 == 0){
60 tmp[0] = x1[ns1*dim]; tmp[1] = x1[ns1*dim + 1];
65 xsplines1 = strchr(xsplines1,
' ');
66 if (!xsplines1)
break;
69 size_t new_len1 = ns1 * dim +
MAX(10u, ns1 * dim / 5);
70 x1 =
gv_recalloc(x1, len1, new_len1,
sizeof(
double));
77 size_t new_len1 = ns1 * dim +
MAX(10u, ns1 * dim / 5);
78 x1 =
gv_recalloc(x1, len1, new_len1,
sizeof(
double));
81 x1[(ns1-1)*dim] = tmp[0]; x1[(ns1-1)*dim + 1] = tmp[1];
91 if(strstr(xsplines2,
"e,")){
93 xsplines2 = strstr(xsplines2,
"e,") + 2;
94 }
else if (strstr(xsplines2,
"s,")){
95 xsplines2 = strstr(xsplines2,
"s,") + 2;
98 while (xsplines2 && sscanf(xsplines2,
"%lf,%lf", &(x2[ns2*dim]), &x2[ns2*dim + 1]) == 2){
99 if (endp2 && iter2 == 0){
100 tmp[0] = x2[ns2*dim]; tmp[1] = x2[ns2*dim + 1];
105 xsplines2 = strchr(xsplines2,
' ');
106 if (!xsplines2)
break;
108 if (ns2*dim >= len2){
109 size_t new_len2 = ns2 * dim +
MAX(10u, ns2 * dim / 5);
110 x2 =
gv_recalloc(x2, len2, new_len2,
sizeof(
double));
116 if (ns2*dim >= len2){
117 size_t new_len2 = ns2 * dim +
MAX(10u, ns2 * dim / 5);
118 x2 =
gv_recalloc(x2, len2, new_len2,
sizeof(
double));
121 x2[(ns2-1)*dim] = tmp[0]; x2[(ns2-1)*dim + 1] = tmp[1];
124 for (
size_t i = 0; i < ns1 - 1; i++) {
125 for (
size_t j = 0; j < ns2 - 1; j++) {
126 cos_a =
intersection_angle(&(x1[dim*i]), &(x1[dim*(i + 1)]), &(x2[dim*j]), &(x2[dim*(j+1)]));
127 if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = fabs(cos_a);
128 if (cos_a > cos_critical) {
143 Agraph_t *g,
double angle,
double accuracy,
144 int check_edges_with_same_endpoint,
int seed) {
159 int *irn, *jcn, nz, nz2 = 0;
160 double cos_critical = cos(angle/180*3.14159), cos_a;
161 int u1, v1, u2, v2, i, j;
162 double *colors =
NULL;
164 char **xsplines =
NULL;
169 fprintf(stderr,
"The gv file contains no or improper 2D coordinates\n");
174 irn =
A->ia; jcn =
A->ja;
178 for (i = 0; i < nz; i++){
179 if (irn[i] != jcn[i]){
186 fprintf(stderr,
"cos = %f, nz2 = %d\n", cos_critical, nz2);
192 clock_t start = clock();
196 for (i = 0; i < nz2; i++){
197 for (j = i+1; j < nz2; j++){
199 check_edges_with_same_endpoint, xsplines[i],
206 fprintf(stderr,
"cpu for dual graph =%10.3f", ((
double) (clock() - start))/CLOCKS_PER_SEC);
212 clock_t start = clock();
216 for (i = 0; i < nz2; i++){
217 u1 = irn[i]; v1 = jcn[i];
218 for (j = i+1; j < nz2; j++){
219 u2 = irn[j]; v2 = jcn[j];
221 if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = fabs(cos_a);
222 if (cos_a > cos_critical) {
228 fprintf(stderr,
"cpu for dual graph (splines) =%10.3f\n", ((
double) (clock() - start))/CLOCKS_PER_SEC);
236 clock_t start = clock();
238 const bool weightedQ =
false;
240 accuracy,
seed, &cdim, &colors);
243 fprintf(stderr,
"cpu for color assignmment =%10.3f\n", ((
double) (clock() - start))/CLOCKS_PER_SEC);
248 fprintf(stderr,
"The edge conflict graph has %d nodes and %d edges\n",
C->m,
C->nz);
258 for (i = 0; i < ne; i++){
SparseMatrix SparseMatrix_import_dot(Agraph_t *g, int dim, double **x, int format)
void attach_edge_colors(Agraph_t *g, int dim, double *colors)
int Import_dot_splines(Agraph_t *g, int *ne, char ***xsplines)
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, int jcn, const void *val)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
static void * gv_calloc(size_t nmemb, size_t size)
Agraph_t * edge_distinct_coloring(char *color_scheme, int *lightness, Agraph_t *g, double angle, double accuracy, int check_edges_with_same_endpoint, int seed)
static int splines_intersect(size_t dim, double cos_critical, int check_edges_with_same_endpoint, char *xsplines1, char *xsplines2)
double intersection_angle(double *p1, double *p2, double *q1, double *q2)
int node_distinct_coloring(char *color_scheme, int *lightness, bool weightedQ, SparseMatrix A0, double accuracy, int seed, int *cdim0, double **colors)