diff options
author | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-05-05 13:24:43 +0000 |
---|---|---|
committer | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-05-05 13:24:43 +0000 |
commit | 03ea98b6fece946fce0019bb3e84ab6793f9bedb (patch) | |
tree | 3d9d915c416365af3c80bd9374a86ec4f4a9e5c8 /src | |
parent | 7da9aa2e9bc0dc209d1a6daefd75f9bd556c3b45 (diff) |
cleanups
cleanups
Diffstat (limited to 'src')
-rw-r--r-- | src/GipfelWidget.H | 4 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 38 | ||||
-rw-r--r-- | src/Panorama.H | 11 | ||||
-rw-r--r-- | src/Panorama.cxx | 96 |
4 files changed, 74 insertions, 75 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 4d1296c..36f801f 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.15 2005/05/03 21:36:39 hofmann Exp $" +// "$Id: GipfelWidget.H,v 1.16 2005/05/05 15:24:43 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -33,9 +33,11 @@ class GipfelWidget : public Fl_Widget { Fl_Image *img; Mountain *cur_mountain; Mountains *marker; + Mountain *m1, *m2; Panorama *pan; Fl_Menu_Button *mb; + int handle(int event); int set_cur_mountain(int m_x, int m_y); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 7e8c258..2ee9457 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.cxx,v 1.20 2005/05/05 13:00:59 hofmann Exp $" +// "$Id: GipfelWidget.cxx,v 1.21 2005/05/05 15:24:43 hofmann Exp $" // // PSEditWidget routines. // @@ -55,6 +55,8 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { cur_mountain = NULL; mb = NULL; marker = new Mountains(); + m1 = NULL; + m2 = NULL; for (i=0; i<=3; i++) { marker->add(new Mountain(i * 10, 0)); } @@ -178,6 +180,20 @@ GipfelWidget::set_cur_mountain(int m_x, int m_y) { if (m_x - center >= m->x - 2 && m_x - center < m->x + 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); + } + redraw(); return 0; } @@ -200,7 +216,6 @@ GipfelWidget::set_cur_mountain(int m_x, int m_y) { int GipfelWidget::set_mountain(int m_x, int m_y) { - int ret; int center_x = w() / 2; int center_y = h() / 2; @@ -208,10 +223,11 @@ GipfelWidget::set_mountain(int m_x, int m_y) { return 1; } - ret = pan->set_mountain(cur_mountain, m_x - center_x, m_y - center_y); - + cur_mountain->x = m_x - center_x; + cur_mountain->y = m_y - center_y; + redraw(); - return ret; + return 0; } void @@ -251,14 +267,22 @@ GipfelWidget::set_height_dist_ratio(double r) { int GipfelWidget::comp_params() { - pan->comp_params(); + if (m1 == NULL || m2 == NULL) { + fprintf(stderr, "Position m1 and m2 first.\n"); + return 1; + } + pan->comp_params(m1, m2); set_labels(pan->get_visible_mountains()); redraw(); } int GipfelWidget::guess() { - pan->guess(marker); + if (m1 == NULL) { + fprintf(stderr, "Position m1 first.\n"); + return 1; + } + pan->guess(marker, m1); set_labels(pan->get_visible_mountains()); redraw(); } diff --git a/src/Panorama.H b/src/Panorama.H index dfb5695..d88c0c6 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -1,5 +1,5 @@ // -// "$Id: Panorama.H,v 1.12 2005/05/03 20:29:59 hofmann Exp $" +// "$Id: Panorama.H,v 1.13 2005/05/05 15:24:43 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -32,7 +32,6 @@ class Panorama { double height_dist_ratio; Mountains *mountains; Mountains *visible_mountains; - Mountain *m1, *m2; int x1, y1, x2, y2; double a_center; double scale; @@ -63,7 +62,7 @@ class Panorama { int get_matrix(double m[]); - int optimize(); + int optimize(Mountain *m1, Mountain *m2); double get_value(Mountains *p); @@ -80,8 +79,6 @@ class Panorama { Mountains * get_visible_mountains(); - int set_mountain(Mountain *m, int x, int y); - void set_center_angle(double a); void set_nick_angle(double a); @@ -90,8 +87,8 @@ class Panorama { void set_scale(double s); - int comp_params(); + int comp_params(Mountain *m1, Mountain *m2); - int guess(Mountains *p1); + int guess(Mountains *p1, Mountain *m1); }; #endif diff --git a/src/Panorama.cxx b/src/Panorama.cxx index 484c36e..e335153 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -1,5 +1,5 @@ // -// "$Id: Panorama.cxx,v 1.27 2005/05/05 13:00:59 hofmann Exp $" +// "$Id: Panorama.cxx,v 1.28 2005/05/05 15:24:43 hofmann Exp $" // // Panorama routines. // @@ -52,8 +52,6 @@ comp_tilt(double tan_nick_view, double tan_dir_view, double n_scale, static double pi_d, deg2rad; Panorama::Panorama() { - m1 = NULL; - m2 = NULL; mountains = new Mountains(); visible_mountains = new Mountains(); height_dist_ratio = 0.07; @@ -131,26 +129,6 @@ Panorama::get_visible_mountains() { return visible_mountains; } -int -Panorama::set_mountain(Mountain *m, int x, int y) { - if (m1 && m2 && m != m1 && m != m2) { - fprintf(stderr, "Resetting mountains\n"); - m1 = NULL; - m2 = NULL; - } - - m->x = x; - m->y = y; - - if (m1 == NULL) { - m1 = m; - fprintf(stderr, "m1=%s\n", m1->name); - } else if (m2 == NULL && m != m1) { - m2 = m; - fprintf(stderr, "m2=%s\n", m2->name); - } -} - double Panorama::get_value(Mountains *p) { int i, j; @@ -185,8 +163,9 @@ extern GipfelWidget *gipf; int -Panorama::guess(Mountains *p) { +Panorama::guess(Mountains *p, Mountain *m1) { Mountain *p2, *m_tmp1, *m_tmp2; + Mountain *m2; double best = 100000000.0, v; double a_center_best, a_nick_best, a_tilt_best, scale_best; int x1_sav, y1_sav; @@ -205,35 +184,35 @@ Panorama::guess(Mountains *p) { p2 = p->get(i); for (j=0; j<mountains->get_num(); j++) { m_tmp2 = mountains->get(j); + m1 = m_tmp1; m1->x = x1_sav; m1->y = y1_sav; - if (fabs(m1->alph - m_tmp2->alph) < pi_d / 2.0 && - m_tmp2->height / (m_tmp2->dist * EARTH_RADIUS) > + if (m1 == m_tmp2 || + fabs(m1->alph - m_tmp2->alph) > pi_d *0.7 || + m_tmp2->height / (m_tmp2->dist * EARTH_RADIUS) < height_dist_ratio) { + continue; + } + + m2 = m_tmp2; + m2->x = p2->x; + m2->y = p2->y; + + comp_params(m1, m2); + + v = get_value(p); - if (m1 != m_tmp2) { + if (v < best) { + best = v; + a_center_best = a_center; + a_nick_best = a_nick; + a_tilt_best = a_tilt; + scale_best = scale; + gipf->update(); - m_tmp2->x = p2->x; - m_tmp2->y = p2->y; - m2 = m_tmp2; - - comp_params(); - - v = get_value(p); - - if (v < best) { - best = v; - a_center_best = a_center; - a_nick_best = a_nick; - a_tilt_best = a_tilt; - scale_best = scale; - gipf->update(); - - fprintf(stderr, "best %f\n", best); - } - } + fprintf(stderr, "best %f\n", best); } } } @@ -249,13 +228,13 @@ Panorama::guess(Mountains *p) { } int -Panorama::comp_params() { - - if (m1 == NULL || m2 == NULL) { - fprintf(stderr, "Position two mountains first.\n"); - m1 = NULL; - m2 = NULL; - return 1; +Panorama::comp_params(Mountain *m1, Mountain *m2) { + Mountain *tmp; + + if (m1->x > m2->x) { + tmp = m1; + m1 = m2; + m2 = tmp; } x1 = m1->x; @@ -269,7 +248,7 @@ Panorama::comp_params() { a_nick = atan ((y1 + tan(m1->a_nick) * scale) / ( scale - y1 * tan(m1->a_nick))); - optimize(); + optimize(m1, m2); update_visible_mountains(); @@ -277,7 +256,7 @@ Panorama::comp_params() { } int -Panorama::optimize() { +Panorama::optimize(Mountain *m1, Mountain *m2) { int i; double tan_nick_view, tan_dir_view, n_scale; double tan_nick_m1, tan_dir_m1; @@ -296,14 +275,10 @@ Panorama::optimize() { tan_dir_m2 = tan(m2->alph); tan_nick_m2 = tan(m2->a_nick); - // fprintf(stderr, "m1: %d, %d; m2: %d, %d\n", x1, y1, x2, y2); d_m1_2 = pow(x1, 2.0) + pow(y1, 2.0); d_m2_2 = pow(x2, 2.0) + pow(y2, 2.0); d_m1_m2_2 = pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0); - // fprintf(stderr, "d_m1_2 %f, d_m2_2 %f, d_m1_m2_2 %f\n", - // d_m1_2, d_m2_2, d_m1_m2_2); - for (i=0; i<5; i++) { newton(&tan_nick_view, &tan_dir_view, &n_scale, tan_dir_m1, tan_nick_m1, tan_dir_m2, tan_nick_m2, @@ -316,8 +291,9 @@ Panorama::optimize() { if (fabs(a_center - m1->alph) > pi_d/2.0) { a_center = a_center + pi_d; } + if (a_center > 2.0 * pi_d) { - a_center = a_center - 2.0 * pi_d; + a_center = a_center - 2.0 * pi_d; } else if (a_center < 0.0) { a_center = a_center + 2.0 * pi_d; } |