[GRASS-SVN] r71061 - grass/trunk/vector/v.label.sa grass-addons/grass7/vector/v.label.sa
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 8 01:07:13 PDT 2017
Author: mmetz
Date: 2017-05-08 01:07:13 -0700 (Mon, 08 May 2017)
New Revision: 71061
Added:
grass-addons/grass7/vector/v.label.sa/font.c
grass/trunk/vector/v.label.sa/font.c
Modified:
grass-addons/grass7/vector/v.label.sa/annealing.c
grass-addons/grass7/vector/v.label.sa/labels.c
grass-addons/grass7/vector/v.label.sa/labels.h
grass-addons/grass7/vector/v.label.sa/main.c
grass/trunk/vector/v.label.sa/annealing.c
grass/trunk/vector/v.label.sa/labels.c
grass/trunk/vector/v.label.sa/labels.h
Log:
v.label.sa: fix and sync
Modified: grass/trunk/vector/v.label.sa/annealing.c
===================================================================
--- grass/trunk/vector/v.label.sa/annealing.c 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass/trunk/vector/v.label.sa/annealing.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -101,11 +101,11 @@
}
/* else apply with probability p=e^(-dE/T) */
else {
- double p, r;
+ double dp, dr;
- p = pow(M_E, -dE / T);
- r = (double)rand() / RAND_MAX;
- if (r <= p) {
+ dp = pow(M_E, -dE / T);
+ dr = (double)rand() / RAND_MAX;
+ if (dr <= dp) {
do_label_overlap(lp, cc, c);
lp->current_score += lp->candidates[c].score;
lp->current_candidate = c;
Copied: grass/trunk/vector/v.label.sa/font.c (from rev 71060, grass/branches/releasebranch_6_4/vector/v.label.sa/font.c)
===================================================================
--- grass/trunk/vector/v.label.sa/font.c (rev 0)
+++ grass/trunk/vector/v.label.sa/font.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -0,0 +1,97 @@
+/*
+ * from lib/driver/parse_ftcap.c
+ * These functions are copied from the diplay driver lib,
+ * so that we don't need to have an active display driver open,
+ * to run this module.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "labels.h"
+
+static int font_exists(const char *name);
+
+static int font_exists(const char *name)
+{
+ FILE *fp;
+
+ fp = fopen(name, "r");
+ if (!fp)
+ return 0;
+
+ fclose(fp);
+ return 1;
+}
+
+void free_freetypecap(struct GFONT_CAP *ftcap)
+{
+ if (ftcap == NULL)
+ return;
+ G_free(ftcap->name);
+ G_free(ftcap->longname);
+ G_free(ftcap->path);
+ G_free(ftcap->encoding);
+ G_free(ftcap);
+
+ return;
+}
+
+struct GFONT_CAP *find_font_from_freetypecap(const char *font)
+{
+ char *capfile, file[GPATH_MAX];
+ char buf[GPATH_MAX];
+ FILE *fp;
+ int fonts_count = 0;
+ struct GFONT_CAP *font_cap = NULL;
+
+ fp = NULL;
+ if ((capfile = getenv("GRASS_FONT_CAP"))) {
+ if ((fp = fopen(capfile, "r")) == NULL)
+ G_warning(_
+ ("%s: Unable to read font definition file; use the default"),
+ capfile);
+ }
+ if (fp == NULL) {
+ sprintf(file, "%s/etc/fontcap", G_gisbase());
+ if ((fp = fopen(file, "r")) == NULL)
+ G_warning(_("%s: No font definition file"), file);
+ }
+
+ if (fp != NULL) {
+ while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
+ char name[GNAME_MAX], longname[GNAME_MAX],
+ path[GPATH_MAX], encoding[128];
+ int type, index;
+ char *p;
+
+ p = strchr(buf, '#');
+ if (p)
+ *p = 0;
+
+ if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
+ name, longname, &type, path, &index, encoding)
+ != 6)
+ continue;
+ if (strcmp(name, font) != 0 && strcmp(longname, font) != 0)
+ continue;
+ if (!font_exists(path))
+ continue;
+
+ font_cap = (struct GFONT_CAP *)G_malloc(sizeof(struct GFONT_CAP));
+
+ font_cap[fonts_count].name = G_store(name);
+ font_cap[fonts_count].longname = G_store(longname);
+ font_cap[fonts_count].type = type;
+ font_cap[fonts_count].path = G_store(path);
+ font_cap[fonts_count].index = index;
+ font_cap[fonts_count].encoding = G_store(encoding);
+
+ }
+ fclose(fp);
+ }
+
+ return font_cap;
+}
Modified: grass/trunk/vector/v.label.sa/labels.c
===================================================================
--- grass/trunk/vector/v.label.sa/labels.c 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass/trunk/vector/v.label.sa/labels.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -97,7 +97,7 @@
else if (error)
G_fatal_error(_("Font file can not be loaded"));
p->font->answer = G_store(font_cap->name);
- free_fontcap(font_cap);
+ free_freetypecap(font_cap);
font_size = atof(p->size->answer);
buffer = atof(p->isize->answer);
@@ -1158,7 +1158,6 @@
for (l = 0; l < labels[k].n_candidates; l++) {
int overlap = 0;
- struct line_pnts *a = NULL, *b = NULL;
if ((labels[i].candidates[j].rotation == 0) &&
(labels[k].candidates[l].rotation == 0)) {
@@ -1184,6 +1183,8 @@
overlap = box_overlap(&a, &b);
}
else {
+ struct line_pnts *a = NULL, *b = NULL;
+
a = box_trans_rot(&labels[i].bb,
&labels[i].candidates[j].point,
labels[i].candidates[j].rotation);
Modified: grass/trunk/vector/v.label.sa/labels.h
===================================================================
--- grass/trunk/vector/v.label.sa/labels.h 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass/trunk/vector/v.label.sa/labels.h 2017-05-08 08:07:13 UTC (rev 71061)
@@ -179,4 +179,7 @@
struct line_pnts *skyline_trans_rot(struct line_pnts *skyline,
label_point_t * p, double angle);
+struct GFONT_CAP *find_font_from_freetypecap(const char *font);
+void free_freetypecap(struct GFONT_CAP *ftcap);
+
#endif /* _LABELS_H */
Modified: grass-addons/grass7/vector/v.label.sa/annealing.c
===================================================================
--- grass-addons/grass7/vector/v.label.sa/annealing.c 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass-addons/grass7/vector/v.label.sa/annealing.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -101,11 +101,11 @@
}
/* else apply with probability p=e^(-dE/T) */
else {
- double p, r;
+ double dp, dr;
- p = pow(M_E, -dE / T);
- r = (double)rand() / RAND_MAX;
- if (r <= p) {
+ dp = pow(M_E, -dE / T);
+ dr = (double)rand() / RAND_MAX;
+ if (dr <= dp) {
do_label_overlap(lp, cc, c);
lp->current_score += lp->candidates[c].score;
lp->current_candidate = c;
Copied: grass-addons/grass7/vector/v.label.sa/font.c (from rev 71060, grass/branches/releasebranch_6_4/vector/v.label.sa/font.c)
===================================================================
--- grass-addons/grass7/vector/v.label.sa/font.c (rev 0)
+++ grass-addons/grass7/vector/v.label.sa/font.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -0,0 +1,97 @@
+/*
+ * from lib/driver/parse_ftcap.c
+ * These functions are copied from the diplay driver lib,
+ * so that we don't need to have an active display driver open,
+ * to run this module.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "labels.h"
+
+static int font_exists(const char *name);
+
+static int font_exists(const char *name)
+{
+ FILE *fp;
+
+ fp = fopen(name, "r");
+ if (!fp)
+ return 0;
+
+ fclose(fp);
+ return 1;
+}
+
+void free_freetypecap(struct GFONT_CAP *ftcap)
+{
+ if (ftcap == NULL)
+ return;
+ G_free(ftcap->name);
+ G_free(ftcap->longname);
+ G_free(ftcap->path);
+ G_free(ftcap->encoding);
+ G_free(ftcap);
+
+ return;
+}
+
+struct GFONT_CAP *find_font_from_freetypecap(const char *font)
+{
+ char *capfile, file[GPATH_MAX];
+ char buf[GPATH_MAX];
+ FILE *fp;
+ int fonts_count = 0;
+ struct GFONT_CAP *font_cap = NULL;
+
+ fp = NULL;
+ if ((capfile = getenv("GRASS_FONT_CAP"))) {
+ if ((fp = fopen(capfile, "r")) == NULL)
+ G_warning(_
+ ("%s: Unable to read font definition file; use the default"),
+ capfile);
+ }
+ if (fp == NULL) {
+ sprintf(file, "%s/etc/fontcap", G_gisbase());
+ if ((fp = fopen(file, "r")) == NULL)
+ G_warning(_("%s: No font definition file"), file);
+ }
+
+ if (fp != NULL) {
+ while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
+ char name[GNAME_MAX], longname[GNAME_MAX],
+ path[GPATH_MAX], encoding[128];
+ int type, index;
+ char *p;
+
+ p = strchr(buf, '#');
+ if (p)
+ *p = 0;
+
+ if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
+ name, longname, &type, path, &index, encoding)
+ != 6)
+ continue;
+ if (strcmp(name, font) != 0 && strcmp(longname, font) != 0)
+ continue;
+ if (!font_exists(path))
+ continue;
+
+ font_cap = (struct GFONT_CAP *)G_malloc(sizeof(struct GFONT_CAP));
+
+ font_cap[fonts_count].name = G_store(name);
+ font_cap[fonts_count].longname = G_store(longname);
+ font_cap[fonts_count].type = type;
+ font_cap[fonts_count].path = G_store(path);
+ font_cap[fonts_count].index = index;
+ font_cap[fonts_count].encoding = G_store(encoding);
+
+ }
+ fclose(fp);
+ }
+
+ return font_cap;
+}
Modified: grass-addons/grass7/vector/v.label.sa/labels.c
===================================================================
--- grass-addons/grass7/vector/v.label.sa/labels.c 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass-addons/grass7/vector/v.label.sa/labels.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -97,7 +97,7 @@
else if (error)
G_fatal_error(_("Font file can not be loaded"));
p->font->answer = G_store(font_cap->name);
- free_fontcap(font_cap);
+ free_freetypecap(font_cap);
font_size = atof(p->size->answer);
buffer = atof(p->isize->answer);
@@ -1158,7 +1158,6 @@
for (l = 0; l < labels[k].n_candidates; l++) {
int overlap = 0;
- struct line_pnts *a = NULL, *b = NULL;
if ((labels[i].candidates[j].rotation == 0) &&
(labels[k].candidates[l].rotation == 0)) {
@@ -1184,6 +1183,8 @@
overlap = box_overlap(&a, &b);
}
else {
+ struct line_pnts *a = NULL, *b = NULL;
+
a = box_trans_rot(&labels[i].bb,
&labels[i].candidates[j].point,
labels[i].candidates[j].rotation);
Modified: grass-addons/grass7/vector/v.label.sa/labels.h
===================================================================
--- grass-addons/grass7/vector/v.label.sa/labels.h 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass-addons/grass7/vector/v.label.sa/labels.h 2017-05-08 08:07:13 UTC (rev 71061)
@@ -179,4 +179,7 @@
struct line_pnts *skyline_trans_rot(struct line_pnts *skyline,
label_point_t * p, double angle);
+struct GFONT_CAP *find_font_from_freetypecap(const char *font);
+void free_freetypecap(struct GFONT_CAP *ftcap);
+
#endif /* _LABELS_H */
Modified: grass-addons/grass7/vector/v.label.sa/main.c
===================================================================
--- grass-addons/grass7/vector/v.label.sa/main.c 2017-05-08 05:10:21 UTC (rev 71060)
+++ grass-addons/grass7/vector/v.label.sa/main.c 2017-05-08 08:07:13 UTC (rev 71061)
@@ -168,7 +168,7 @@
label_candidate_overlap(labels, n_labels);
/* 3. position selection */
simulate_annealing(labels, n_labels, &p);
- /* write lables to file */
+ /* write labels to file */
fprintf(stderr, "Writing labels to file: ...");
labelf = G_fopen_new("paint/labels", p.labels->answer);
for (i = 0; i < n_labels; i++) {
More information about the grass-commit
mailing list