summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2005-06-19 14:54:02 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2005-06-19 14:54:02 +0000
commit1c92fda21514b790219dec9a2e5a85718cb83e73 (patch)
tree2ecff677606140a8332cc9d4f8487feb30d6780f
parentfe61e9b1f5b135f30bd1bf22a2be77ee85573ff9 (diff)
add duplicate removal
add duplicate removal
-rw-r--r--src/GipfelWidget.cxx14
-rw-r--r--src/Hill.H7
-rw-r--r--src/Hill.cxx55
-rw-r--r--src/Panorama.cxx4
4 files changed, 76 insertions, 4 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 85669b1..5e1c3bf 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: GipfelWidget.cxx,v 1.32 2005/05/20 13:34:39 hofmann Exp $"
+// "$Id: GipfelWidget.cxx,v 1.33 2005/06/19 16:54:02 hofmann Exp $"
//
// GipfelWidget routines.
//
@@ -133,6 +133,10 @@ GipfelWidget::draw() {
for (i=0; i<mnts->get_num(); i++) {
m = mnts->get(i);
+ if (m->duplicate) {
+ continue;
+ }
+
if (m == m1) {
fl_color(FL_RED);
draw_flag(center_x + m->x + x(), center_y + m->y + y(), "1");
@@ -179,6 +183,10 @@ GipfelWidget::set_labels(Hills *v) {
for (i=0; i<v->get_num(); i++) {
m = v->get(i);
+ if (m->duplicate) {
+ continue;
+ }
+
fl_measure(m->name, width, height);
m->label_x = m->x + width;
m->label_y = m->y;
@@ -186,6 +194,10 @@ GipfelWidget::set_labels(Hills *v) {
for (j=0; j<v->get_num() && j < i; j++) {
n = v->get(j);
+ if (n->duplicate) {
+ continue;
+ }
+
// Check for overlapping labels and
// overlaps between labels and peak markers
if ((overlap(m->x, m->label_x, n->x, n->label_x) &&
diff --git a/src/Hill.H b/src/Hill.H
index 7f7581f..bba2b4d 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.H,v 1.14 2005/05/10 17:16:54 hofmann Exp $"
+// "$Id: Hill.H,v 1.15 2005/06/19 16:54:02 hofmann Exp $"
//
// Copyright 2005 by Johannes Hofmann
//
@@ -37,6 +37,7 @@ class Hill {
int x, y;
int label_x, label_y;
char *name;
+ int duplicate;
Hill(const char *n, double p, double l, double h);
@@ -58,8 +59,12 @@ class Hills {
int load(const char *file);
+ void mark_duplicates(double dist);
+
void add(Hill *m);
+ void sort_phi();
+
void sort();
void clear();
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 5dbe226..8f2f527 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.cxx,v 1.14 2005/05/10 18:12:47 hofmann Exp $"
+// "$Id: Hill.cxx,v 1.15 2005/06/19 16:54:02 hofmann Exp $"
//
// Hill routines.
//
@@ -38,6 +38,7 @@ Hill::Hill(const char *n, double p, double l, double h) {
alph = 0.0;
x = 0;
y = 0;
+ duplicate = 0;
}
Hill::Hill(int x_tmp, int y_tmp) {
@@ -105,6 +106,31 @@ Hills::load(const char *file) {
return 0;
}
+void Hills::mark_duplicates(double dist) {
+ Hill *m, *n;
+ int i, j;
+
+ sort_phi();
+
+ for(i=0; i<get_num();i++) {
+ m = get(i);
+
+ if (m) {
+ j = i + 1;
+ n = get(j);
+ while (n && fabs(n->phi - m->phi) <= dist) {
+ // fprintf(stderr, "%s %f %f %s %f %f\n", m->name, m->phi, m->lam, n->name, n->phi, n->lam);
+ if (fabs(n->lam - m->lam) <= dist) {
+ fprintf(stderr, "Duplicate: %s <=> %s\n", m->name, n->name);
+ n->duplicate = 1;
+ }
+ j = j + 1;
+ n = get(j);
+ }
+ }
+ }
+}
+
Hills::~Hills() {
if (m) {
@@ -142,6 +168,24 @@ comp_mountains(const void *n1, const void *n2) {
}
}
+static int
+comp_mountains_phi(const void *n1, const void *n2) {
+ Hill *m1 = *(Hill **)n1;
+ Hill *m2 = *(Hill **)n2;
+
+ if (m1 && m2) {
+ if (m1->phi < m2->phi) {
+ return 1;
+ } else if (m1->phi > m2->phi) {
+ return -1;
+ } else {
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+}
+
void
Hills::sort() {
if (!m) {
@@ -152,6 +196,15 @@ Hills::sort() {
}
void
+Hills::sort_phi() {
+ if (!m) {
+ return;
+ }
+
+ qsort(m, num, sizeof(Hill *), comp_mountains_phi);
+}
+
+void
Hills::clear() {
if (m) {
free(m);
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index 7e1ccff..45bafe1 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Panorama.cxx,v 1.43 2005/05/20 13:34:39 hofmann Exp $"
+// "$Id: Panorama.cxx,v 1.44 2005/06/19 16:54:02 hofmann Exp $"
//
// Panorama routines.
//
@@ -80,6 +80,8 @@ Panorama::load_file(const char *name) {
return 1;
}
+ mountains->mark_duplicates(0.00001);
+
update_angles();
return 0;