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++) {
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) {
148 int *irn, *jcn, nz, nz2 = 0;
149 double cos_critical = cos(angle/180*3.14159), cos_a;
150 int u1, v1, u2, v2, i, j;
151 double *colors =
NULL;
153 char **xsplines =
NULL;
158 fprintf(stderr,
"The gv file contains no or improper 2D coordinates\n");
163 irn =
A->ia; jcn =
A->ja;
167 for (i = 0; i < nz; i++){
168 if (irn[i] != jcn[i]){
175 fprintf(stderr,
"cos = %f, nz2 = %d\n", cos_critical, nz2);
181 clock_t start = clock();
185 for (i = 0; i < nz2; i++){
186 for (j = i+1; j < nz2; j++){
188 check_edges_with_same_endpoint, xsplines[i],
195 fprintf(stderr,
"cpu for dual graph =%10.3f", ((
double) (clock() - start))/CLOCKS_PER_SEC);
201 clock_t start = clock();
205 for (i = 0; i < nz2; i++){
206 u1 = irn[i]; v1 = jcn[i];
207 for (j = i+1; j < nz2; j++){
208 u2 = irn[j]; v2 = jcn[j];
210 if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = fabs(cos_a);
211 if (cos_a > cos_critical) {
217 fprintf(stderr,
"cpu for dual graph (splines) =%10.3f\n", ((
double) (clock() - start))/CLOCKS_PER_SEC);
225 clock_t start = clock();
227 const bool weightedQ =
false;
229 accuracy,
seed, &cdim, &colors);
232 fprintf(stderr,
"cpu for color assignmment =%10.3f\n", ((
double) (clock() - start))/CLOCKS_PER_SEC);
237 fprintf(stderr,
"The edge conflict graph has %d nodes and %d edges\n",
C->m,
C->nz);
247 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(const 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(const char *color_scheme, int *lightness, bool weightedQ, SparseMatrix A0, double accuracy, int seed, int *cdim0, double **colors)