diff options
author | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-04-13 19:58:31 +0000 |
---|---|---|
committer | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-04-13 19:58:31 +0000 |
commit | 5e7c5bafd0828f09ca66d5311636700b51cc77ea (patch) | |
tree | d41aff3d84938c44410be4ae212b133c0ae1f0ca | |
parent | a25441aaab4c15bc5a0dba9dbd4d26cc36780163 (diff) |
bla
bla
-rw-r--r-- | src/GipfelWidget.H | 13 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 95 | ||||
-rw-r--r-- | src/Hill.H | 5 | ||||
-rw-r--r-- | src/Hill.cxx | 6 | ||||
-rw-r--r-- | src/Panorama.H | 16 | ||||
-rw-r--r-- | src/Panorama.cxx | 77 | ||||
-rw-r--r-- | src/gipfel.cxx | 37 |
7 files changed, 220 insertions, 29 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 1eeeb72..4d1f0fe 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.3 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: GipfelWidget.H,v 1.4 2005/04/13 21:58:31 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -31,7 +31,14 @@ class GipfelWidget : public Fl_Widget { private: Fl_Image *img; Panorama *pan; + Mountain *cur_mountain; + int handle(int event); + + int set_cur_mountain(int m_x, int m_y); + + int move_mountain(int m_x, int m_y); + public: GipfelWidget(int X,int Y,int W, int H); @@ -41,6 +48,10 @@ class GipfelWidget : public Fl_Widget { int set_viewpoint(const char *pos); + void set_center_angle(double a); + + void set_scale(double s); + void draw(); }; #endif diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 821943d..03267aa 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.cxx,v 1.3 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: GipfelWidget.cxx,v 1.4 2005/04/13 21:58:31 hofmann Exp $" // // PSEditWidget routines. // @@ -43,6 +43,7 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { img = NULL; pan = new Panorama(); + cur_mountain = NULL; fl_register_images(); } @@ -82,18 +83,98 @@ GipfelWidget::draw() { img->draw(x(),y(),w(),h(),0,0); - fl_color(FL_RED); + fl_font(FL_COURIER, 10); m = pan->get_visible_mountains(); while (m) { - int m_x = pan->get_x(m); - - fl_line(center + m_x + x(), 0 + y(), center + m_x + x(), h() + y()); - fl_draw(m->name, m_x + x(), 20 + y() + m_x / 4); - m = m->get_next(); + if (m == cur_mountain) { + fl_color(FL_RED); + } else { + fl_color(FL_BLACK); + } + + fl_line(center + m->x + x(), 0 + y(), center + m->x + x(), h() + y()); + fl_draw(m->name, center + m->x + x(), 20 + y() + (int) m->height / 6); + m = m->get_next_visible(); } fl_pop_clip(); } +int +GipfelWidget::set_cur_mountain(int m_x, int m_y) { + Mountain *m = pan->get_visible_mountains(); + int center = w() / 2; + + 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(); + } + cur_mountain = NULL; + redraw(); + return 1; +} + +int +GipfelWidget::move_mountain(int m_x, int m_y) { + int ret; + int center = w() / 2; + + if (cur_mountain == NULL) { + return 1; + } + + ret = pan->move_mountain(cur_mountain, m_x - center, m_y - center); + + redraw(); + return ret; +} + +void +GipfelWidget::set_center_angle(double a) { + pan->set_center_angle(a); + redraw(); +} + +void +GipfelWidget::set_scale(double s) { + pan->set_scale(s); + redraw(); +} + +int +GipfelWidget::handle(int event) { + int mark_x, mark_y; + + switch(event) { + case FL_PUSH: + if (Fl::event_button() == 1) { + + mark_x = Fl::event_x()-x(); + mark_y = Fl::event_y()-y(); + fprintf(stderr, "x %d, y %d\n", mark_x, mark_y); + set_cur_mountain(mark_x, mark_y); + + Fl::focus(this); + return 1; + } + break; + case FL_DRAG: + move_mountain(Fl::event_x()-x(), Fl::event_y()-y()); + return 1; + break; + case FL_FOCUS: + return 1; + break; + case FL_UNFOCUS: + return 0; + break; + } + return 0; +} @@ -1,5 +1,5 @@ // -// "$Id: Hill.H,v 1.2 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: Hill.H,v 1.3 2005/04/13 21:58:31 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -35,6 +35,7 @@ class Mountain { double phi, lam; double height; double alph; + int x, y; char *name; Mountain(const char *n, double p, double l, double h); @@ -45,7 +46,7 @@ class Mountain { void append_visible(Mountain *m); - void set_first_visible(); + void clear_next_visible(); Mountain * get_next(); diff --git a/src/Hill.cxx b/src/Hill.cxx index e3d999c..2790712 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -1,5 +1,5 @@ // -// "$Id: Hill.cxx,v 1.2 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: Hill.cxx,v 1.3 2005/04/13 21:58:31 hofmann Exp $" // // PSEditWidget routines. // @@ -32,6 +32,8 @@ Mountain::Mountain(const char *n, double p, double l, double h) { lam = l; height = h; alph = 0.0; + x = 0; + y = 0; next = NULL; next_visible = NULL; } @@ -75,6 +77,6 @@ Mountain::get_next_visible() { } void -Mountain::set_first_visible() { +Mountain::clear_next_visible() { next_visible = NULL; } diff --git a/src/Panorama.H b/src/Panorama.H index 690ed86..30e2635 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -1,5 +1,5 @@ // -// "$Id: Panorama.H,v 1.2 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: Panorama.H,v 1.3 2005/04/13 21:58:31 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -32,8 +32,9 @@ class Panorama { double height_dist_ratio; Mountain *mountains; Mountain *visible_mountains; + Mountain *m1, *m2; double pi, deg2rad; - double center_angle; + double a_center; double scale; int get_pos(const char *name, double *phi, double *lam); @@ -47,6 +48,10 @@ class Panorama { double cos_alpha(double phi, double c); double alpha(double phi, double lam); + + double center_angle(double alph_a, double alph_b, double d1, double d2); + + int get_x(Mountain *m); public: Panorama(); @@ -61,6 +66,11 @@ class Panorama { Mountain * get_visible_mountains(); - int get_x(Mountain *m); + int move_mountain(Mountain *m, int x, int y); + + void set_center_angle(double a); + + void set_scale(double s); + }; #endif diff --git a/src/Panorama.cxx b/src/Panorama.cxx index e2fce5d..7236d3e 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -1,5 +1,5 @@ // -// "$Id: Panorama.cxx,v 1.2 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: Panorama.cxx,v 1.3 2005/04/13 21:58:31 hofmann Exp $" // // PSEditWidget routines. // @@ -31,11 +31,13 @@ Panorama::Panorama() { mountains = NULL; visible_mountains = NULL; - height_dist_ratio = 0.1; + m1 = NULL; + m2 = NULL; + height_dist_ratio = 0.10; pi = asin(1.0) * 2.0; deg2rad = pi / 180.0; - center_angle = 0.0; - scale = 200.0; + a_center = 0.2*pi; + scale = 0.2; } Panorama::~Panorama() { @@ -109,7 +111,43 @@ Panorama::get_visible_mountains() { int Panorama::get_x(Mountain *m) { - return (int) (tan(m->alph - center_angle) * scale); + return (int) (tan(m->alph - a_center) * scale); +} + +int +Panorama::move_mountain(Mountain *m, int x, int y) { + if (m1 && m2 && m != m1 && m != m2) { + return 1; + } + + m->x = x; + + if (m1 == NULL) { + m1 = m; + } else if (m2 == NULL && m != m1) { + m2 = m; + } else if (m1 && m2) { + a_center = center_angle(m1->alph, m2->alph, m1->x, m2->x); + scale = (m1->x - m2->x) / + (tan(m1->alph - a_center) - tan(m2->alph - a_center)); + fprintf(stderr, "center = %f, scale = %f\n", a_center /deg2rad, scale); + update_visible_mountains(); + } + + return 0; +} + +void +Panorama::set_center_angle(double a) { + a_center = a; + fprintf(stderr, "--> %f\n", a); + update_visible_mountains(); +} + +void +Panorama::set_scale(double s) { + scale = s; + update_visible_mountains(); } int @@ -144,12 +182,18 @@ Panorama::update_visible_mountains() { visible_mountains = NULL; while (m) { - - if (m->height / (distance(m->phi, m->lam)* 6368000) - > height_dist_ratio) { - m ->alph = alpha(m->phi, m->lam); - - if (m->alph < pi / 2.0 && m->alph > - pi / 2.0) { + if ((m->phi != view_phi || m->lam != view_lam) && + (m->height / (distance(m->phi, m->lam)* 6368000) + > height_dist_ratio)) { + + m->alph = alpha(m->phi, m->lam); + + if (m->alph - a_center < pi / 2.0 && + m->alph - a_center > - pi / 2.0) { + // fprintf(stderr, "==> %s\n", m->name); + + m->x = get_x(m); + m->clear_next_visible(); if (visible_mountains) { visible_mountains->append_visible(m); } else { @@ -197,3 +241,14 @@ Panorama::alpha(double phi, double lam) { return alph; } +double +Panorama::center_angle(double alph_a, double alph_b, double d1, double d2) { + double tan_a, tan_b; + + tan_a = tan(alph_a - alph_b); + fprintf(stderr, "tan_a %f\n", tan_a); + tan_b = (d2 - d1 + ((sqrt((d2*(d2 - (2.0*d1*(1.0 + (2.0 * tan_a * tan_a))))) + (d1*d1))))) / (2.0*d2*tan_a); + + fprintf(stderr, "tan_b=%f\n", tan_b); + return alph_a + atan(tan_b); +} diff --git a/src/gipfel.cxx b/src/gipfel.cxx index c3436e0..3705986 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -1,5 +1,5 @@ // -// "$Id: gipfel.cxx,v 1.4 2005/04/13 19:09:19 hofmann Exp $" +// "$Id: gipfel.cxx,v 1.5 2005/04/13 21:58:31 hofmann Exp $" // // flpsed program. // @@ -45,6 +45,7 @@ char *img_file; char *data_file; +GipfelWidget *gipf; void open_cb() { char *file = fl_file_chooser("Open File?", "*.jpeg", img_file); @@ -53,6 +54,18 @@ void open_cb() { } } +void scale_cb(Fl_Slider* o, void*) { + if (gipf) { + gipf->set_scale((double)(o->value())); + } +} + +void angle_cb(Fl_Slider* o, void*) { + if (gipf) { + gipf->set_center_angle((double)(o->value())); + } +} + void about_cb() { fl_message("flpsed -- a pseudo PostScript editor\n" "(c) Johannes Hofmann 2004, 2005\n\n" @@ -123,9 +136,27 @@ int main(int argc, char** argv) { win = new Fl_Window(600,700); m = new Fl_Menu_Bar(0, 0, 600, 30); m->menu(menuitems); - scroll = new Fl_Scroll(0, 30, win->w(), win->h()-30); + Fl_Slider* s = new Fl_Slider(0, 30, 160, 15, "scale"); + s->type(1); + s->box(FL_THIN_DOWN_BOX); + s->labelsize(10); + s->step(10.0); + s->bounds(0.0, 800.0); + s->slider(FL_UP_BOX); + s->callback((Fl_Callback*)scale_cb); + Fl_Slider* a = new Fl_Slider(160, 30, 160, 15, "angle"); + a->type(1); + a->box(FL_THIN_DOWN_BOX); + a->labelsize(10); + a->step(0.01); + a->bounds(-4.0, 4.0); + a->slider(FL_UP_BOX); + a->callback((Fl_Callback*)angle_cb); + + + scroll = new Fl_Scroll(0, 60, win->w(), win->h()-60); - GipfelWidget *gipf = new GipfelWidget(0,30,500,500); + gipf = new GipfelWidget(0,60,500,500); gipf->load_image(img_file); gipf->load_data(data_file); |