diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-12-14 17:23:17 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-12-14 17:23:17 +0100 |
commit | 489bdd091ea9dae275717e95340a9fdd07dcba8c (patch) | |
tree | 414e271dae25ad7532ca20e829c4daf9b7c2e447 | |
parent | c3a34dad14632abed6cc15679a57997f91b99560 (diff) |
change Projection::comp_params() to allow a variable amount of known mountains
-rw-r--r-- | src/GipfelWidget.H | 4 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 80 | ||||
-rw-r--r-- | src/Hill.H | 8 | ||||
-rw-r--r-- | src/Hill.cxx | 25 | ||||
-rw-r--r-- | src/Panorama.H | 2 | ||||
-rw-r--r-- | src/Panorama.cxx | 10 | ||||
-rw-r--r-- | src/Projection.H | 2 | ||||
-rw-r--r-- | src/Projection.cxx | 2 | ||||
-rw-r--r-- | src/ProjectionSphaeric.H | 2 | ||||
-rw-r--r-- | src/ProjectionSphaeric.cxx | 12 | ||||
-rw-r--r-- | src/ProjectionTangential.H | 2 | ||||
-rw-r--r-- | src/ProjectionTangential.cxx | 12 |
12 files changed, 112 insertions, 49 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index adbb623..e1708f2 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -17,7 +17,7 @@ class GipfelWidget : public Fl_Widget { Hill *cur_mountain; Hills *marker; Hills *track_points; - Hill *m1, *m2; + Hills *known_hills; Panorama *pan; Fl_Menu_Button *mb; char *img_file; @@ -28,6 +28,8 @@ class GipfelWidget : public Fl_Widget { int set_cur_mountain(int m_x, int m_y); + int toggle_known_mountain(int m_x, int m_y); + int set_mountain(int m_x, int m_y); void set_labels(Hills *v); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 23cb075..6b51aa5 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -46,8 +46,7 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { cur_mountain = NULL; mb = NULL; marker = new Hills(); - m1 = NULL; - m2 = NULL; + known_hills = new Hills(); img_file = NULL; track_width = 200.0; show_hidden = 0; @@ -236,12 +235,9 @@ GipfelWidget::draw() { continue; } - if (m == m1) { + if (known_hills->contains(m)) { fl_color(FL_RED); draw_flag(center_x + m->x + x(), center_y + m->y + y(), "1"); - } else if (m == m2) { - fl_color(FL_RED); - draw_flag(center_x + m->x + x(), center_y + m->y + y(), "2"); } else if (m->flags & Hill::HIDDEN) { fl_color(FL_BLUE); } else { @@ -354,6 +350,28 @@ GipfelWidget::set_labels(Hills *v) { int GipfelWidget::set_cur_mountain(int m_x, int m_y) { + Hill *m; + int center_x = w() / 2; + int center_y = h() / 2; + int i; + + for (i=0; i<known_hills->get_num(); i++) { + m = known_hills->get(i); + + if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 && + m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) { + + cur_mountain = m; + return 0; + } + } + + return 1; +} + + +int +GipfelWidget::toggle_known_mountain(int m_x, int m_y) { Hills *mnts = pan->get_visible_mountains(); Hill *m; int center_x = w() / 2; @@ -368,19 +386,12 @@ GipfelWidget::set_cur_mountain(int m_x, int m_y) { if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 && m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) { - cur_mountain = m; - if (m1 != NULL && m2 != NULL) { - fprintf(stderr, "Resetting m1 and m2\n"); - m1 = NULL; - m2 = NULL; - } - if (m1 == NULL) { - m1 = cur_mountain; - fprintf(stderr, "m1 = %s\n", m1->name); - } else if (m2 == NULL) { - m2 = cur_mountain; - fprintf(stderr, "m2 = %s\n", m2->name); + + if (known_hills->contains(m)) { + known_hills->remove(m); + } else { + known_hills->add(m); } redraw(); @@ -524,11 +535,11 @@ GipfelWidget::center() { Hill *m = choose_hill(pan->get_close_mountains(), "Center Peak"); if (m) { set_center_angle(m->alph / deg2rad); - if (!m1 || (m1 && m2)) { - m1 = m; - } else { - m2 = m; + + if (!known_hills->contains(m)) { + known_hills->add(m); } + } } @@ -589,12 +600,12 @@ GipfelWidget::get_mountains() { int GipfelWidget::comp_params() { - if (m1 == NULL || m2 == NULL) { + if (known_hills->get_num() < 2) { fprintf(stderr, "Position m1 and m2 first.\n"); return 1; } fl_cursor(FL_CURSOR_WAIT); - pan->comp_params(m1, m2); + pan->comp_params(known_hills); set_labels(pan->get_visible_mountains()); redraw(); fl_cursor(FL_CURSOR_DEFAULT); @@ -602,12 +613,12 @@ GipfelWidget::comp_params() { int GipfelWidget::guess() { - if (m1 == NULL) { + if (known_hills->get_num() < 1) { fprintf(stderr, "Position m1 first.\n"); return 1; } fl_cursor(FL_CURSOR_WAIT); - pan->guess(marker, m1); + pan->guess(marker, known_hills->get(0)); set_labels(pan->get_visible_mountains()); redraw(); fl_cursor(FL_CURSOR_DEFAULT); @@ -639,20 +650,25 @@ GipfelWidget::handle(int event) { switch(event) { case FL_PUSH: + mark_x = Fl::event_x()-x(); + mark_y = Fl::event_y()-y(); if (Fl::event_button() == 1) { - - mark_x = Fl::event_x()-x(); - mark_y = Fl::event_y()-y(); set_cur_mountain(mark_x, mark_y); - - Fl::focus(this); - return 1; + } else if (Fl::event_button() == 2) { + toggle_known_mountain(mark_x, mark_y); } + + Fl::focus(this); + return 1; break; case FL_DRAG: set_mountain(Fl::event_x()-x(), Fl::event_y()-y()); return 1; break; + case FL_RELEASE: + cur_mountain = NULL; + return 1; + break; case FL_FOCUS: return 1; break; @@ -60,6 +60,8 @@ class Hills { void add(Hill *m); + void remove(const Hill *m); + void add(Hills *h); void sort_phi(); @@ -71,9 +73,11 @@ class Hills { void clear(); void clobber(); + + int contains(const Hill *m) const; - int get_num(); + int get_num() const; - Hill *get(int n); + Hill *get(int n) const; }; #endif diff --git a/src/Hill.cxx b/src/Hill.cxx index d5ce1f6..c5708f2 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -269,6 +269,27 @@ Hills::clear() { num = 0; } +int +Hills::contains(const Hill *m) const { + for(int i=0; i<get_num();i++) { + if (get(i) == m) { + return 1; + } + } + + return 0; +} + +void +Hills::remove(const Hill *h) { + for(int i=0; i<get_num();i++) { + if (get(i) == h) { + memmove(&m[i], &m[i+1], (get_num() - i - 1) * sizeof(Hill*)); + num--; + } + } +} + void Hills::clobber() { int i; @@ -283,12 +304,12 @@ Hills::clobber() { } int -Hills::get_num() { +Hills::get_num() const { return num; } Hill * -Hills::get(int n) { +Hills::get(int n) const { if (n < 0 || n >= num) { return NULL; } else { diff --git a/src/Panorama.H b/src/Panorama.H index 81cdf8e..505c56d 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -122,7 +122,7 @@ class Panorama { double get_real_distance(Hill *m); - int comp_params(Hill *m1, Hill *m2); + int comp_params(Hills *h); int guess(Hills *p1, Hill *m1); diff --git a/src/Panorama.cxx b/src/Panorama.cxx index 6ed8486..a5c4baf 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -161,6 +161,7 @@ int Panorama::guess(Hills *p, Hill *m1) { Hill *p2, *m_tmp1, *m_tmp2; Hill *m2; + Hills h; double best = 100000000.0, v; double a_center_best, a_nick_best, a_tilt_best, scale_best; int x1_sav, y1_sav; @@ -193,7 +194,10 @@ Panorama::guess(Hills *p, Hill *m1) { m2->x = p2->x; m2->y = p2->y; - comp_params(m1, m2); + h.clear(); + h.add(m1); + h.add(m2); + comp_params(&h); v = get_value(p); @@ -220,10 +224,10 @@ Panorama::guess(Hills *p, Hill *m1) { } int -Panorama::comp_params(Hill *m1, Hill *m2) { +Panorama::comp_params(Hills *h) { int ret; - ret = proj->comp_params(m1, m2, &parms); + ret = proj->comp_params(h, &parms); update_visible_mountains(); return ret; } diff --git a/src/Projection.H b/src/Projection.H index 3bc816e..2a953b2 100644 --- a/src/Projection.H +++ b/src/Projection.H @@ -25,6 +25,6 @@ class Projection { virtual void get_coordinates(double a_view, double a_nick, const ViewParams *parms, double *x, double *y); - virtual int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms); + virtual int comp_params(const Hills *h, ViewParams *parms); }; #endif diff --git a/src/Projection.cxx b/src/Projection.cxx index 02674a7..bb577a0 100644 --- a/src/Projection.cxx +++ b/src/Projection.cxx @@ -20,7 +20,7 @@ Projection::get_coordinates(double a_view, double a_nick, } int -Projection::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { +Projection::comp_params(const Hills *h, ViewParams *parms) { fprintf(stderr, "Error: Projection::comp_params()\n"); return 1; } diff --git a/src/ProjectionSphaeric.H b/src/ProjectionSphaeric.H index c6ce5f4..bb47fef 100644 --- a/src/ProjectionSphaeric.H +++ b/src/ProjectionSphaeric.H @@ -22,6 +22,6 @@ class ProjectionSphaeric : public Projection { void get_coordinates(double a_view, double a_nick, const ViewParams *parms, double *x, double *y); - int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms); + int comp_params(const Hills *h, ViewParams *parms); }; #endif diff --git a/src/ProjectionSphaeric.cxx b/src/ProjectionSphaeric.cxx index 96af4e0..5227355 100644 --- a/src/ProjectionSphaeric.cxx +++ b/src/ProjectionSphaeric.cxx @@ -13,8 +13,8 @@ #define BEST_UNDEF 10000000.0 int -ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { - const Hill *m_tmp; +ProjectionSphaeric::comp_params(const Hills *h, ViewParams *parms) { + const Hill *m_tmp, *m1, *m2; double tmp_x, tmp_y; double val; ViewParams best, tmp; @@ -22,6 +22,14 @@ ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parm double d_m1_2, d_m2_2, d_m1_m2_2; int i, j; + + if (h->get_num() != 2) { + return 1; + } + + m1 = h->get(0); + m2 = h->get(1); + if (m1->x < m2->x) { m_tmp = m1; m1 = m2; diff --git a/src/ProjectionTangential.H b/src/ProjectionTangential.H index 13e354a..6734e88 100644 --- a/src/ProjectionTangential.H +++ b/src/ProjectionTangential.H @@ -24,6 +24,6 @@ class ProjectionTangential : public Projection { void get_coordinates(double a_view, double a_nick, const ViewParams *parms, double *x, double *y); - int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms); + int comp_params(const Hills *h, ViewParams *parms); }; #endif diff --git a/src/ProjectionTangential.cxx b/src/ProjectionTangential.cxx index 8eed552..16488ad 100644 --- a/src/ProjectionTangential.cxx +++ b/src/ProjectionTangential.cxx @@ -29,10 +29,18 @@ comp_tilt(double tan_nick_view, double tan_dir_view, double n_scale, double x, double y, double pi_d); int -ProjectionTangential::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { - const Hill *tmp; +ProjectionTangential::comp_params(const Hills *h, ViewParams *parms) { + const Hill *tmp, *m1, *m2; double a_center_tmp, scale_tmp, a_nick_tmp; + if (h->get_num() != 2) { + return 1; + } + + m1 = h->get(0); + m2 = h->get(1); + + scale_tmp = comp_scale(m1->alph, m2->alph, m1->x, m2->x); if (isnan(scale_tmp) || scale_tmp < 100.0) { // try again with mountains swapped |