diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GipfelWidget.H | 4 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 41 | ||||
-rw-r--r-- | src/Hill.H | 24 | ||||
-rw-r--r-- | src/Hill.cxx | 66 | ||||
-rw-r--r-- | src/Panorama.H | 12 | ||||
-rw-r--r-- | src/Panorama.cxx | 161 |
6 files changed, 156 insertions, 152 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 688cb0f..ab86a5d 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.13 2005/05/02 16:36:45 hofmann Exp $" +// "$Id: GipfelWidget.H,v 1.14 2005/05/03 20:04:14 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -32,7 +32,7 @@ class GipfelWidget : public Fl_Widget { private: Fl_Image *img; Mountain *cur_mountain; - Mountain *marker; + Mountains *marker; Panorama *pan; Fl_Menu_Button *mb; diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 3ad141d..eeba2fa 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.cxx,v 1.16 2005/05/02 16:36:45 hofmann Exp $" +// "$Id: GipfelWidget.cxx,v 1.17 2005/05/03 20:04:14 hofmann Exp $" // // PSEditWidget routines. // @@ -54,9 +54,9 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { pan = new Panorama(); cur_mountain = NULL; mb = NULL; - marker = new Mountain(0,0); - for (i=1; i<=3; i++) { - marker->append(new Mountain(i * 10, 0)); + marker = new Mountains(); + for (i=0; i<=3; i++) { + marker->add(new Mountain(i * 10, 0)); } fl_register_images(); } @@ -92,9 +92,11 @@ GipfelWidget::set_viewpoint(const char *pos) { void GipfelWidget::draw() { + Mountains *mnts; Mountain *m; int center_x = w() / 2; int center_y = h() / 2; + int i; if (img == NULL) { return; @@ -104,8 +106,10 @@ GipfelWidget::draw() { img->draw(x(),y(),w(),h(),0,0); fl_font(FL_HELVETICA, 8); - m = pan->get_visible_mountains(); - while (m) { + mnts = pan->get_visible_mountains(); + for (i=0; i<mnts->get_num(); i++) { + m = mnts->get(i); + if (m == cur_mountain) { fl_color(FL_RED); } else { @@ -118,18 +122,14 @@ GipfelWidget::draw() { fl_draw(m->name, center_x + m->x + x(), center_y + m->y + y()); - m = m->get_next_visible(); } + for (i=0; i<marker->get_num(); i++) { + m = marker->get(i); - m = marker; - while (m) { fl_color(FL_GREEN); - fl_xyline(center_x + m->x + x() - 3, center_y + m->y + y(), center_x + m->x + x() + 3); fl_yxline(center_x + m->x + x(), center_y + m->y + y() - 3, center_y + m->y + y() + 3); - - m = m->get_next(); } fl_pop_clip(); @@ -137,28 +137,29 @@ GipfelWidget::draw() { int GipfelWidget::set_cur_mountain(int m_x, int m_y) { - Mountain *m = pan->get_visible_mountains(); + Mountains *mnts = pan->get_visible_mountains(); + Mountain *m; int center = w() / 2; + int i; + + for (i=0; i<mnts->get_num(); i++) { + m = mnts->get(i); - while (m) { if (m_x - center >= m->x - 2 && m_x - center < m->x + 2) { cur_mountain = m; redraw(); return 0; } - - m = m->get_next_visible(); } - m = marker; - while (m) { + for (i=0; i<marker->get_num(); i++) { + m = marker->get(i); + if (m_x - center >= m->x - 2 && m_x - center < m->x + 2) { cur_mountain = m; redraw(); return 0; } - - m = m->get_next(); } cur_mountain = NULL; @@ -1,5 +1,5 @@ // -// "$Id: Hill.H,v 1.6 2005/04/30 21:18:43 hofmann Exp $" +// "$Id: Hill.H,v 1.7 2005/05/03 20:04:14 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -57,4 +57,26 @@ class Mountain { Mountain * get_next_visible(); }; + + +class Mountains { + private: + int num, cap; + Mountain **m; + + public: + Mountains(); + + ~Mountains(); + + void add(Mountain *m); + + void clear(); + + void clobber(); + + int get_num(); + + Mountain *get(int n); +}; #endif diff --git a/src/Hill.cxx b/src/Hill.cxx index 550f925..8d9c4f8 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -1,5 +1,5 @@ // -// "$Id: Hill.cxx,v 1.4 2005/04/30 21:18:43 hofmann Exp $" +// "$Id: Hill.cxx,v 1.5 2005/05/03 20:04:14 hofmann Exp $" // // PSEditWidget routines. // @@ -22,6 +22,7 @@ // #include <stdlib.h> +#include <stdio.h> #include <string.h> #include "Mountain.H" @@ -92,3 +93,66 @@ void Mountain::clear_next_visible() { next_visible = NULL; } + + + +Mountains::Mountains() { + fprintf(stderr, "===>huhu\n"); + num = 0; + cap = 100; + m = (Mountain **) malloc(cap * sizeof(class Mountain *)); +} + +Mountains::~Mountains() { + if (m) { + free(m); + } +} + + +void +Mountains::add(Mountain *m1) { + if (num >= cap) { + cap = cap?cap * 2:100; + m = (Mountain **) realloc(m, cap * sizeof(class Mountain *)); + } + + m[num++] = m1; +} + +void +Mountains::clear() { + if (m) { + free(m); + m = NULL; + } + cap = 0; + num = 0; +} + +void +Mountains::clobber() { + int i; + + for(i=0; i<get_num();i++) { + if (get(i)) { + delete(get(i)); + } + } + + clear(); +} + +int +Mountains::get_num() { + return num; +} + +Mountain * +Mountains::get(int n) { + if (n < 0 || n >= num) { + return NULL; + } else { + return m[n]; + } +} diff --git a/src/Panorama.H b/src/Panorama.H index 6d60ad1..06d8c8f 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -1,5 +1,5 @@ // -// "$Id: Panorama.H,v 1.10 2005/04/30 21:18:43 hofmann Exp $" +// "$Id: Panorama.H,v 1.11 2005/05/03 20:04:14 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -30,8 +30,8 @@ class Panorama { private: double view_phi, view_lam, view_height; double height_dist_ratio; - Mountain *mountains; - Mountain *visible_mountains; + Mountains *mountains; + Mountains *visible_mountains; Mountain *m1, *m2; int x1, y1, x2, y2; double a_center; @@ -61,7 +61,7 @@ class Panorama { int optimize(); - double get_value(Mountain *p); + double get_value(Mountains *p); public: Panorama(); @@ -74,7 +74,7 @@ class Panorama { void set_height_dist_ratio(double r); - Mountain * get_visible_mountains(); + Mountains * get_visible_mountains(); int set_mountain(Mountain *m, int x, int y); @@ -88,6 +88,6 @@ class Panorama { int comp_params(); - int guess(Mountain *p1); + int guess(Mountains *p1); }; #endif diff --git a/src/Panorama.cxx b/src/Panorama.cxx index 3f5a19b..670f96e 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -1,5 +1,5 @@ // -// "$Id: Panorama.cxx,v 1.20 2005/05/02 16:36:45 hofmann Exp $" +// "$Id: Panorama.cxx,v 1.21 2005/05/03 20:04:14 hofmann Exp $" // // PSEditWidget routines. // @@ -52,10 +52,10 @@ comp_tilt(double tan_nick_view, double tan_dir_view, double n_scale, static double pi_d, deg2rad; Panorama::Panorama() { - mountains = NULL; - visible_mountains = NULL; m1 = NULL; m2 = NULL; + mountains = new Mountains(); + visible_mountains = new Mountains(); height_dist_ratio = 0.07; pi_d = asin(1.0) * 2.0; deg2rad = pi_d / 180.0; @@ -66,9 +66,10 @@ Panorama::Panorama() { } Panorama::~Panorama() { - if (mountains) { - delete(mountains); - } + visible_mountains->clear(); + mountains->clobber(); + delete(visible_mountains); + delete(mountains); } int @@ -80,12 +81,9 @@ Panorama::load_file(const char *name) { double phi, lam, height; Mountain *m; - if (mountains) { - delete(mountains); - } + visible_mountains->clear(); + mountains->clobber(); - mountains = NULL; - visible_mountains = NULL; fp = fopen(name, "r"); if (!fp) { @@ -105,11 +103,8 @@ Panorama::load_file(const char *name) { height = atof(vals[5]); m = new Mountain(vals[1], phi, lam, height); - if (mountains) { - mountains->append(m); - } else { - mountains = m; - } + + mountains->add(m); } fclose(fp); @@ -129,7 +124,7 @@ Panorama::set_viewpoint(const char *name) { return 0; } -Mountain * +Mountains * Panorama::get_visible_mountains() { return visible_mountains; } @@ -155,7 +150,8 @@ Panorama::set_mountain(Mountain *m, int x, int y) { } double -Panorama::get_value(Mountain *p) { +Panorama::get_value(Mountains *p) { + int i, j; Mountain *m; double v = 0.0, d_min, d; @@ -166,21 +162,17 @@ Panorama::get_value(Mountain *p) { return 10000000.0; } - while (p) { + + for (i=0; i<p->get_num(); i++) { d_min = 1000.0; - m = visible_mountains; - while (m) { - d = pow(p->x - m->x, 2.0) + pow(p->y - m->y, 2.0); + for (j=0; j<visible_mountains->get_num(); j++) { + d = pow(p->get(i)->x - visible_mountains->get(j)->x, 2.0) + + pow(p->get(i)->y - visible_mountains->get(j)->y, 2.0); if (d < d_min) { d_min = d; } - - m = m->get_next_visible(); } - v = v + d_min; - - p = p->get_next(); } return v; @@ -189,84 +181,14 @@ Panorama::get_value(Mountain *p) { extern GipfelWidget *gipf; -#if 0 -int -Panorama::guess(Mountain *p) { - Mountain *p1, *p2, *m_tmp1, *m_tmp2; - double best = 100000000.0, v; - double a_center_best, a_nick_best, a_tilt_best, scale_best; - - p1 = p; - - while (p1) { - p2 = p; - while (p2) { - if (fabs(p1->x - p2->x) + fabs(p1->y - p2->y) > 50.0) { - m_tmp1 = mountains; - while(m_tmp1) { - if (m_tmp1->height / (m_tmp1->dist * EARTH_RADIUS) > - height_dist_ratio) { - m_tmp2 = mountains; - - while(m_tmp2) { - if (fabs(m_tmp1->alph - m_tmp2->alph) < pi_d / 2.0 && - m_tmp2->height / (m_tmp2->dist * EARTH_RADIUS) > - height_dist_ratio) { - - if (p1 != p2 && m_tmp1 != m_tmp2) { - - m_tmp1->x = p1->x; - m_tmp1->y = p1->y; - m1 = m_tmp1; - 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); - } - } - } - - m_tmp2 = m_tmp2->get_next(); - } - } - m_tmp1 = m_tmp1->get_next(); - } - } - p2 = p2->get_next(); - } - p1 = p1->get_next(); - } - - a_center = a_center_best; - a_nick = a_nick_best; - a_tilt = a_tilt_best; - scale = scale_best; - fprintf(stderr, "best %f\n", best); - fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad); - update_visible_mountains(); - return 0; -} -#else int -Panorama::guess(Mountain *p) { +Panorama::guess(Mountains *p) { Mountain *p2, *m_tmp1, *m_tmp2; double best = 100000000.0, v; double a_center_best, a_nick_best, a_tilt_best, scale_best; int x1_sav, y1_sav; + int i, j; if (m1 == NULL) { fprintf(stderr, "Position one mountain first.\n"); @@ -277,10 +199,10 @@ Panorama::guess(Mountain *p) { x1_sav = m1->x; y1_sav = m1->y; - p2 = p; - while (p2) { - m_tmp2 = mountains; - while(m_tmp2) { + for (i=0; i<p->get_num(); i++) { + 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; @@ -311,10 +233,7 @@ Panorama::guess(Mountain *p) { } } } - - m_tmp2 = m_tmp2->get_next(); } - p2 = p2->get_next(); } a_center = a_center_best; @@ -326,7 +245,7 @@ Panorama::guess(Mountain *p) { update_visible_mountains(); return 0; } -#endif + int Panorama::comp_params() { @@ -452,11 +371,14 @@ Panorama::set_height_dist_ratio(double r) { int Panorama::get_pos(const char *name, double *phi, double *lam, double *height) { - Mountain *m = mountains; + int i; int found = 0; double p, l, h; + Mountain *m; + + for (i=0; i<mountains->get_num(); i++) { + m = mountains->get(i); - while (m) { if (strcmp(m->name, name) == 0) { p = m->phi; l = m->lam; @@ -465,8 +387,6 @@ Panorama::get_pos(const char *name, double *phi, double *lam, double *height) { fprintf(stderr, "Found matching entry: %s (%fm)\n", m->name, m->height); found++; } - - m = m->get_next(); } if (found == 1) { @@ -480,11 +400,14 @@ Panorama::get_pos(const char *name, double *phi, double *lam, double *height) { void Panorama::update_visible_mountains() { - Mountain *m = mountains; - visible_mountains = NULL; + int i; double x_tmp, y_tmp; + Mountain *m; - while (m) { + visible_mountains->clear(); + + for (i=0; i<mountains->get_num(); i++) { + m = mountains->get(i); m->dist = distance(m->phi, m->lam); if ((m->phi != view_phi || m->lam != view_lam) && @@ -507,16 +430,10 @@ Panorama::update_visible_mountains() { m->x = (int) rint(x_tmp * cos(a_tilt) - y_tmp * sin(a_tilt)); m->y = (int) rint(x_tmp * sin(a_tilt) + y_tmp * cos(a_tilt)); - m->clear_next_visible(); - if (visible_mountains) { - visible_mountains->append_visible(m); - } else { - visible_mountains = m; - } + + visible_mountains->add(m); } } - - m = m->get_next(); } } |