unsigned int c;
char* cmd = argv[0];
- int cs_len = 10000;
- int r, g, b;
outfile = NULL;
Verbose = FALSE;
*infile = NULL;
*check_edges_with_same_endpoint = 0;
*seed = 123;
- if (!(*color_scheme)) *color_scheme = malloc(sizeof(char)*cs_len);
- strcpy(*color_scheme, "lab");
+ *color_scheme = "lab";
*lightness = NULL;
while ((c = getopt(argc, argv, ":vc:a:s:r:l:o")) != -1) {
break;
case 'c':
if (strncmp(optarg,"olor_scheme=", 12) == 0){
- if (strcmp(optarg + 12,"rgb") != 0 && strcmp(optarg + 12,"lab") != 0 && strcmp(optarg + 12,"gray") != 0 &&
- (!color_palettes_Q(optarg + 12)) &&
- sscanf(optarg + 12,"#%02X%02X%02X", &r, &g, &b) != 3){
+ if (knownColorScheme(optarg + 12))
+ *color_scheme = optarg+12;
+ else {
fprintf(stderr,"-color_scheme option must be a valid string\n");
usage(cmd, 1);
- } else {
- if (strlen(*color_scheme) < strlen(optarg + 12)) *color_scheme = realloc(*color_scheme, sizeof(char)*(strlen(optarg + 12) + 1));
- strcpy(*color_scheme, optarg + 12);
}
} else {
usage(cmd, 1);
int check_edges_with_same_endpoint, seed;
char *color_scheme = NULL;
char *lightness = NULL;
- Agraph_t *g;
- Agraph_t *prev = NULL;
- ingraph_state ig;
- int rv = 0;
+ Agraph_t *g;
+ Agraph_t *prev = NULL;
+ ingraph_state ig;
+ int rv = 0;
init(argc, argv, &angle, &accuracy, &infile, &check_edges_with_same_endpoint, &seed, &color_scheme, &lightness);
newIngraph(&ig, Files, gread);
-I$(top_srcdir)/lib/neatogen \
-I$(top_srcdir)/lib/sfdpgen \
-I$(top_srcdir)/lib/sparse \
+ -I$(top_srcdir)/lib/edgepaint \
-I$(top_srcdir)/lib/cgraph \
-I$(top_srcdir)/lib/ingraphs \
-I$(top_srcdir)/lib/cdt
cluster_CPPFLAGS = $(AM_CPPFLAGS) -g
gvmap_LDADD = \
+ $(top_builddir)/lib/edgepaint/libedgepaint_C.la \
$(top_builddir)/lib/sfdpgen/libsfdpgen_C.la \
$(top_builddir)/lib/neatogen/libneatogen_C.la \
$(top_builddir)/lib/sparse/libsparse_C.la \
$(GTS_LIBS) -lm
cluster_LDADD = \
+ $(top_builddir)/lib/edgepaint/libedgepaint_C.la \
$(top_builddir)/lib/sfdpgen/libsfdpgen_C.la \
$(top_builddir)/lib/neatogen/libneatogen_C.la \
$(top_builddir)/lib/sparse/libsparse_C.la \
#include "ingraphs.h"
#include "DotIO.h"
#include "colorutil.h"
+#include "color_palette.h"
+
#ifdef WIN32
#define strdup(x) _strdup(x)
#endif
int plotedges;
int color_scheme;
real line_width;
+ char *color_scheme_str;
char *opacity;
char *plot_label;
real *bg_color;
pm->outfile = NULL;
pm->opacity = NULL;
+ pm->color_scheme_str = NULL;
pm->nrandom = -1;
pm->dim = 2;
pm->shore_depth_tol = 0;
pm->opacity = strdup(stmp);
} else if ((sscanf(optarg,"%d",&r) > 0) && r >= COLOR_SCHEME_NONE && r <= COLOR_SCHEME_GREY){
pm->color_scheme = r;
+ } else if (knownColorScheme(optarg)) {
+ pm->color_scheme = COLOR_SCHEME_NONE;
+ pm->color_scheme_str = optarg;
} else {
- usage(cmd,1);
+ fprintf(stderr,"-c option %s is invalid, must be a valid integer or string\n", optarg);
+ usage(cmd, 1);
}
break;
case 'd':
/* compute a good color permutation */
if (pm->color_optimize && country_graph && rgb_r && rgb_g && rgb_b)
map_optimal_coloring(pm->seed, country_graph, rgb_r, rgb_g, rgb_b);
+ else if (pm->color_scheme_str){
+ map_palette_optimal_coloring(pm->color_scheme_str, "0,100", country_graph, 0.01, -10,
+ &rgb_r, &rgb_g, &rgb_b);
+ }
#ifdef TIME
fprintf(stderr, "map making time = %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC);
#endif /* not SINGLE */
/* #include "triangle.h" */
+#include "lab.h"
+#include "node_distinct_coloring.h"
+
+void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A0, real accuracy, int seed,
+ float **rgb_r, float **rgb_g, float **rgb_b){
+ /*
+ for a graph A, get a distinctive color of its nodes so that the color distanmce among all nodes are maximized. Here
+ color distance on a node is defined as the minimum of color differences between a node and its neighbors.
+ accuracy is the threshold given so that when finding the coloring for each node, the optimal is
+ with in "accuracy" of the true global optimal.
+ color_scheme: rgb, gray, lab, or one of the color palettes in color_palettes.h, or a list of hex rgb colors separaterd by comma like "#ff0000,#00ff00"
+ lightness: of the form 0,70, specifying the range of lightness of LAB color. Ignored if scheme is not COLOR_LAB.
+ . if NULL, 0,70 is assumed
+ A: the graph of n nodes
+ accuracy: how accurate to find the optimal
+ cdim: dimension of the color space
+ seed: random_seed. If negative, consider -seed as the number of random start iterations
+ rgb_r, rgb_g, rgb_b: float array of length A->m + 1, which contains color for each country. 1-based
+ */
+
+ /*color: On input an array of size n*cdim, if NULL, will be allocated. On exit the final color assignment for node i is [cdim*i,cdim*(i+1)), in RGB (between 0 to 1)
+ color_diff: the minuimum color difference across all edges
+ color_diff_sum: the sum of min color dfference across all nodes
+ */
+ real *colors = NULL, color_diff, color_diff_sum;
+ int flag;
+ int n = A0->m, i, cdim;
+
+ SparseMatrix A, B;
+ int weightedQ = TRUE;
+ int iter_max = 100;
+
+ {real *dist = NULL;
+ A = SparseMatrix_symmetrize(A0, FALSE);
+ SparseMatrix_distance_matrix(A, 0, &dist);
+ SparseMatrix_delete(A);
+ A = SparseMatrix_from_dense(n, n, dist);
+ FREE(dist);
+ A = SparseMatrix_remove_diagonal(A);
+ SparseMatrix_export(stdout, A);
+ }
+
+ // A = SparseMatrix_multiply(A0, A0);
+ node_distinct_coloring(color_scheme, lightness, weightedQ, A, accuracy, iter_max, seed, &cdim, &colors, &color_diff, &color_diff_sum, &flag);
+
+ if (A != A0){
+ SparseMatrix_delete(A);
+ }
+ *rgb_r = MALLOC(sizeof(float)*(n+1));
+ *rgb_g = MALLOC(sizeof(float)*(n+1));
+ *rgb_b = MALLOC(sizeof(float)*(n+1));
+
+ for (i = 0; i < n; i++){
+ (*rgb_r)[i+1] = (float) colors[cdim*i];
+ (*rgb_g)[i+1] = (float) colors[cdim*i + 1];
+ (*rgb_b)[i+1] = (float) colors[cdim*i + 2];
+ }
+ FREE(colors);
+
+}
+
void map_optimal_coloring(int seed, SparseMatrix A, float *rgb_r, float *rgb_g, float *rgb_b){
int *p = NULL;
float *u = NULL;
#endif
void map_optimal_coloring(int seed, SparseMatrix A, float *rgb_r, float *rgb_g, float *rgb_b);
+void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A, real accuracy, int seed, float **rgb_r, float **rgb_g, float **rgb_b);
enum {POLY_LINE_REAL_EDGE, POLY_LINE_NOT_REAL_EDGE};
enum {OUT_PS = 1, OUT_M = 0, OUT_M_COUNTRY_GRAPH = 2, OUT_DOT = 3, OUT_PROCESSING = 4};
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
#include "general.h"
#include "time.h"
#include "SparseMatrix.h"
+/*************************************************************************
+ * Copyright (c) 2014 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+#ifndef EDGE_DISTINCT_COLORING_H
+#define EDGE_DISTINCT_COLORING_H
+
Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* g, real angle, real accuracy, real check_edges_with_same_endpoint, int seed);
+
+#endif
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
#include "general.h"
#include "QuadTree.h"
#include "furtherest_point.h"
+/*************************************************************************
+ * Copyright (c) 2014 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+#ifndef FURTHEREST_POINT_H
+#define FURTHEREST_POINT_H
+
void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real width, int max_level, real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax);
void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, int max_level,
real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax);
+
+#endif
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
#include "general.h"
static real cross(real *u, real *v){
+/*************************************************************************
+ * Copyright (c) 2014 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+#ifndef INTERSECTION_H
+#define INTERSECTION_H
+
real intersection_angle(real *p1, real *p2, real *q1, real *q2);
+
+#endif
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
#include "general.h"
#include "QuadTree.h"
#include "lab.h"
+/*************************************************************************
+ * Copyright (c) 2014 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
#ifndef LAB_H
#define LAB_H
+/*************************************************************************
+ * Copyright (c) 2014 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+#ifndef LAB_GAMUT_H
+#define LAB_GAMUT_H
+
static color_lab lab_gamut_data[] = {{0,0,0},
{1,-2,1},
{1,-1,-1},
{99,1,1},
{99,2,-1},
{100,0,0}};
+
+#endif
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
#include "general.h"
#include "SparseMatrix.h"
#include "QuadTree.h"
+/*************************************************************************
+ * Copyright (c) 2014 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+#ifndef NODE_DISTINCT_COLORING_H
+#define NODE_DISTINCT_COLORING_H
+
enum {COLOR_RGB, COLOR_GRAY, COLOR_LAB};
enum {ERROR_BAD_LAB_GAMUT_FILE = -10, ERROR_BAD_COLOR_SCHEME = -9};
void node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A, real accuracy, int iter_max, int seed, int *cdim, real **colors, real *color_diff, real *color_diff_sum, int *flag);
+
+#endif
if (width && dim == 2){
for (i = 0; i < A->m; i++){
if (i >= 0) fprintf(fp,",");
- fprintf(fp,"(*%f,%f*){GrayLevel[.5,.5],Rectangle[{%f,%f},{%f,%f}]}", width[i*dim], width[i*dim+1],x[i*dim] - width[i*dim] + 5, x[i*dim+1] - width[i*dim+1] + 5,
- x[i*dim] + width[i*dim] - 5, x[i*dim+1] + width[i*dim+1] - 5);
+ fprintf(fp,"(*width={%f,%f}, x = {%f,%f}*){GrayLevel[.5,.5],Rectangle[{%f,%f},{%f,%f}]}", width[i*dim], width[i*dim+1], x[i*dim], x[i*dim + 1],
+ x[i*dim] - width[i*dim], x[i*dim+1] - width[i*dim+1],
+ x[i*dim] + width[i*dim], x[i*dim+1] + width[i*dim+1]);
}
}
int max_qtree_level = ctrl->max_qtree_level;
oned_optimizer qtree_level_optimizer = NULL;
- if (!A) return;
+ if (!A || maxiter <= 0) return;
m = A->m, n = A->n;
if (n <= 0 || dim <= 0) return;
oned_optimizer qtree_level_optimizer = NULL;
fprintf(stderr,"spring_electrical_embedding_slow");
- if (!A) return;
+ if (!A || maxiter <= 0) return;
m = A->m, n = A->n;
if (n <= 0 || dim <= 0) return;
int max_qtree_level = ctrl->max_qtree_level;
oned_optimizer qtree_level_optimizer = NULL;
- if (!A) return;
+ if (!A || maxiter <= 0) return;
m = A->m, n = A->n;
if (n <= 0 || dim <= 0) return;
double stress = 0;
#endif
- if (!A) return;
+ if (!A || maxiter <= 0) return;
m = A->m, n = A->n;
if (n <= 0 || dim <= 0) return;
real *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0;
int max_qtree_level = 10;
- if (!A) return;
+ if (!A || maxiter <= 0) return;
m = A->m, n = A->n;
if (n <= 0 || dim <= 0) return;
post_process_smoothing(dim, A, ctrl, node_weights, x, flag);
+ if (Verbose) fprintf(stderr, "ctrl->overlap=%d\n",ctrl->overlap);
+
+ /* rotation has to be done before overlap removal, since rotation could induce overlaps */
if (dim == 2){
pcp_rotate(n, dim, x);
}
if (ctrl->rotation != 0) rotate(n, dim, x, ctrl->rotation);
- if (Verbose) fprintf(stderr, "ctrl->overlap=%d\n",ctrl->overlap);
remove_overlap(dim, A, x, label_sizes, ctrl->overlap, ctrl->initial_scaling,
ctrl->edge_labeling_scheme, n_edge_label_nodes, edge_label_nodes, A, ctrl->do_shrinking, flag);
+
+/*************************************************************************
+ * Copyright (c) 2013 AT&T Intellectual Property
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
#include "color_palette.h"
#include "string.h"
+#include "macros.h"
+
+int knownColorScheme (char* name)
+{
+ int r, g, b;
+
+ return streq(name,"rgb")
+ || streq(name,"lab")
+ || streq(name,"gray")
+ || color_palettes_Q(name)
+ || (sscanf(name,"#%02X%02X%02X", &r, &g, &b) == 3);
+}
char *color_palettes_get(char *color_palette_name){
int i;
enum {MAX_COLOR = 1001};
enum {npalettes = 265};
+extern int knownColorScheme (char*);
extern char *color_palettes[npalettes][2];
-char *color_palettes_get(char *color_palette_name);/* return a list of rgb in hex form: "#ff0000,#00ff00,..." */
-void color_palettes_name_print(FILE *fp);
-int color_palettes_Q(char *color_palette_name);
+ /* return a list of rgb in hex form: "#ff0000,#00ff00,..." */
+extern char *color_palettes_get(char *color_palette_name);
+extern void color_palettes_name_print(FILE *fp);
+extern int color_palettes_Q(char *color_palette_name);
extern float palette_pastel[1001][3];
extern float palette_blue_to_yellow[1001][3];