From 7d900b4ede22215413e4a0ddd1675c650ba3225f Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 25 Jun 2006 11:49:32 +0200 Subject: implement various helper methods --- src/Panorama.H | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Panorama.H') diff --git a/src/Panorama.H b/src/Panorama.H index 32cefa6..740f164 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -144,5 +144,7 @@ class Panorama { Projection::Projection_t get_projection(); void set_projection(Projection::Projection_t p); + + int get_coordinates(double a_view, double a_nick, int *x, int *y); }; #endif -- cgit v1.2.3 From 70a6e7c52eb8830e7e2c5884247201defdeb6a1c Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 26 Jun 2006 18:05:47 +0200 Subject: switch to double coordinates --- src/DataImage.H | 6 ++++++ src/DataImage.cxx | 19 ++++++++++++++++++- src/GipfelWidget.cxx | 9 ++++++--- src/Panorama.H | 2 +- src/Panorama.cxx | 30 ++++++++++++------------------ src/Projection.H | 3 ++- src/Projection.cxx | 3 ++- src/ProjectionSphaeric.H | 5 ++--- src/ProjectionSphaeric.cxx | 22 ++++++---------------- src/ProjectionTangential.H | 3 ++- src/ProjectionTangential.cxx | 11 ++++++----- 11 files changed, 63 insertions(+), 50 deletions(-) (limited to 'src/Panorama.H') diff --git a/src/DataImage.H b/src/DataImage.H index fe6200d..ec3b1ec 100644 --- a/src/DataImage.H +++ b/src/DataImage.H @@ -40,6 +40,12 @@ class DataImage : public Fl_Widget { static int get_pixel(Fl_Image *img, int x, int y, char *r, char *g, char *b); + + static int get_pixel_bilinear(Fl_Image *img, double x, double y, + char *r, char *g, char *b); + + static int get_pixel_nearest(Fl_Image *img, double x, double y, + char *r, char *g, char *b); }; #endif diff --git a/src/DataImage.cxx b/src/DataImage.cxx index 680d218..efc05e3 100644 --- a/src/DataImage.cxx +++ b/src/DataImage.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -62,6 +63,23 @@ DataImage::draw() { fl_pop_clip(); } +int +DataImage::get_pixel_bilinear(Fl_Image *img, double x, double y, + char *r, char *g, char *b) { + + +} + +int +DataImage::get_pixel_nearest(Fl_Image *img, double x, double y, + char *r, char *g, char *b) { + if (isnan(x) || isnan(y)) { + return 1; + } else { + return get_pixel(img, (int) rint(x), (int) rint(y), r, g, b); + } +} + int DataImage::get_pixel(Fl_Image *img, int x, int y, char *r, char *g, char *b) { @@ -72,7 +90,6 @@ DataImage::get_pixel(Fl_Image *img, int x, int y, if (x < 0 || x >=img->w() || y < 0 || y >= img->h()) { return 1; } - long index = (y * img->w() * img->d()) + (x * img->d()); // X/Y -> buf index switch ( img->count() ) { case 1: { // bitmap diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index aac0b49..67695ad 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -749,16 +749,19 @@ GipfelWidget::handle(int event) { int GipfelWidget::get_pixel(double a_view, double a_nick, char *r, char *g, char *b) { - int px, py; + double px, py; if (img == NULL) { return 1; } - pan->get_coordinates(a_view, a_nick, &px, &py); + if (pan->get_coordinates(a_view, a_nick, &px, &py) != 0) { + return 1; + } //printf("===> %s: %f, %f -> %d %d\n", img_file, a_view, a_nick, px, py); - return DataImage::get_pixel(img, px + img->w() / 2, py + img->h() / 2, r, g, b); + return DataImage::get_pixel_nearest(img, px + ((double) img->w()) / 2.0, + py + ((double) img->h()) / 2.0, r, g, b); } diff --git a/src/Panorama.H b/src/Panorama.H index 740f164..20d3213 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -145,6 +145,6 @@ class Panorama { void set_projection(Projection::Projection_t p); - int get_coordinates(double a_view, double a_nick, int *x, int *y); + int get_coordinates(double a_view, double a_nick, double *x, double *y); }; #endif diff --git a/src/Panorama.cxx b/src/Panorama.cxx index a644732..73bc003 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -508,8 +508,11 @@ Panorama::update_coordinates() { for (int i=0; iget_num(); i++) { m = visible_mountains->get(i); + double tmp_x, tmp_y; - proj->set_coordinates(m, &parms); + proj->get_coordinates(m->a_view, m->a_nick, &parms, &tmp_x, &tmp_y); + m->x = (int) rint(tmp_x); + m->y = (int) rint(tmp_y); } } @@ -587,29 +590,20 @@ Panorama::get_real_distance(Hill *m) { } int -Panorama::get_coordinates(double a_view, double a_nick, int *x, int *y) { - Hill m(0,0); +Panorama::get_coordinates(double a_view, double a_nick, double *x, double *y) { + a_view = a_view - parms.a_center; - - - m.a_view = a_view - parms.a_center; - - if (m.a_view > pi_d) { - m.a_view -= 2.0*pi_d; - } else if (m.a_view < -pi_d) { - m.a_view += 2.0*pi_d; + if (a_view > pi_d) { + a_view -= 2.0*pi_d; + } else if (a_view < -pi_d) { + a_view += 2.0*pi_d; } - if (m.a_view > view_angle || m.a_view < - view_angle) { + if (a_view > view_angle || a_view < - view_angle) { return 1; } - m.a_nick = a_nick; - - proj->set_coordinates(&m, &parms); - - *x = m.x; - *y = m.y; + proj->get_coordinates(a_view, a_nick, &parms, x, y); return 0; } diff --git a/src/Projection.H b/src/Projection.H index b81e531..f6de5ae 100644 --- a/src/Projection.H +++ b/src/Projection.H @@ -37,7 +37,8 @@ class Projection { Projection(); - virtual void set_coordinates(Hill *m, const ViewParams *parms); + 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); }; diff --git a/src/Projection.cxx b/src/Projection.cxx index 57a210a..1f224e8 100644 --- a/src/Projection.cxx +++ b/src/Projection.cxx @@ -31,7 +31,8 @@ Projection::Projection() { }; void -Projection::set_coordinates(Hill *m, const ViewParams *parms) { +Projection::get_coordinates(double a_view, double a_nick, + const ViewParams *parms, double *x, double *y) { fprintf(stderr, "Error: Projection::set_coordinates()\n"); } diff --git a/src/ProjectionSphaeric.H b/src/ProjectionSphaeric.H index fcaffa8..06396f1 100644 --- a/src/ProjectionSphaeric.H +++ b/src/ProjectionSphaeric.H @@ -30,11 +30,10 @@ class ProjectionSphaeric : public Projection { double comp_dir_view(const Hill *m1, const Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3); double comp_nick_view(const Hill *m1, const Hill *m2, double d_m1_2, double scale, double dir_view, double sign1); double comp_tilt_view(const Hill *m, double scale, double dir_view, double nick_view); - void set_coordinates(const Hill *m, const ViewParams *parms, - double *x, double *y); public: - void set_coordinates(Hill *m, const ViewParams *parms); + 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); }; diff --git a/src/ProjectionSphaeric.cxx b/src/ProjectionSphaeric.cxx index 74c9de6..e69882b 100644 --- a/src/ProjectionSphaeric.cxx +++ b/src/ProjectionSphaeric.cxx @@ -66,9 +66,9 @@ ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parm isnan(tmp.a_nick) || isnan(tmp.a_tilt)) { ; } else { - set_coordinates(m1, &tmp, &tmp_x, &tmp_y); + get_coordinates(m1->a_view, m1->a_nick, &tmp, &tmp_x, &tmp_y); val = sqrt(pow(tmp_x - m1->x, 2.0) + pow(tmp_y - m1->y, 2.0)); - set_coordinates(m2, &tmp, &tmp_x, &tmp_y); + get_coordinates(m2->a_view, m2->a_nick, &tmp, &tmp_x, &tmp_y); val += sqrt(pow(tmp_x - m2->x, 2.0) + pow(tmp_y - m2->y, 2.0)); if (val < best_val) { @@ -88,22 +88,12 @@ ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parm } void -ProjectionSphaeric::set_coordinates(Hill *m, const ViewParams *parms) { +ProjectionSphaeric::get_coordinates(double a_view, double a_nick, + const ViewParams *parms, double *x, double *y) { double x_tmp, y_tmp; - set_coordinates(m, parms, &x_tmp, &y_tmp); - - m->x = (int) rint(x_tmp); - m->y = (int) rint(y_tmp); -} - -void -ProjectionSphaeric::set_coordinates(const Hill *m, const ViewParams *parms, - double *x, double *y) { - double x_tmp, y_tmp; - - x_tmp = m->a_view * parms->scale; - y_tmp = - (m->a_nick - parms->a_nick) * parms->scale; + x_tmp = a_view * parms->scale; + y_tmp = - (a_nick - parms->a_nick) * parms->scale; // rotate by a_tilt; *x = x_tmp * cos(parms->a_tilt) - y_tmp * sin(parms->a_tilt); diff --git a/src/ProjectionTangential.H b/src/ProjectionTangential.H index 8e7673e..74a4b59 100644 --- a/src/ProjectionTangential.H +++ b/src/ProjectionTangential.H @@ -36,7 +36,8 @@ class ProjectionTangential : public Projection { int optimize(const Hill *m1, const Hill *m2, ViewParams *parms); public: - void set_coordinates(Hill *m, const ViewParams *parms); + 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); }; diff --git a/src/ProjectionTangential.cxx b/src/ProjectionTangential.cxx index 032005d..416d27d 100644 --- a/src/ProjectionTangential.cxx +++ b/src/ProjectionTangential.cxx @@ -160,15 +160,16 @@ ProjectionTangential::optimize(const Hill *m1, const Hill *m2, ViewParams *parms } void -ProjectionTangential::set_coordinates(Hill *m, const ViewParams *parms) { +ProjectionTangential::get_coordinates(double a_view, double a_nick, + const ViewParams *parms, double *x, double *y) { double x_tmp, y_tmp; - x_tmp = tan(m->a_view) * parms->scale; - y_tmp = - (tan(m->a_nick - parms->a_nick) * parms->scale); + x_tmp = tan(a_view) * parms->scale; + y_tmp = - (tan(a_nick - parms->a_nick) * parms->scale); // rotate by a_tilt; - m->x = (int) rint(x_tmp * cos(parms->a_tilt) - y_tmp * sin(parms->a_tilt)); - m->y = (int) rint(x_tmp * sin(parms->a_tilt) + y_tmp * cos(parms->a_tilt)); + *x = x_tmp * cos(parms->a_tilt) - y_tmp * sin(parms->a_tilt); + *y = x_tmp * sin(parms->a_tilt) + y_tmp * cos(parms->a_tilt); } double -- cgit v1.2.3 From feae8373e6fbdafe5368410ba0ac51059f7155f7 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 9 Aug 2006 22:19:00 +0200 Subject: Header and Copyright cleanup --- src/Fl_Search_Chooser.H | 4 ---- src/Fl_Value_Dial.H | 8 -------- src/Fl_Value_Dial.cxx | 4 ---- src/GipfelWidget.H | 4 +--- src/Hill.H | 2 -- src/Panorama.H | 2 -- src/Projection.H | 4 +--- src/ProjectionTangential.H | 2 -- src/choose_hill.H | 6 ------ 9 files changed, 2 insertions(+), 34 deletions(-) (limited to 'src/Panorama.H') diff --git a/src/Fl_Search_Chooser.H b/src/Fl_Search_Chooser.H index 6bb71fe..c87f0de 100644 --- a/src/Fl_Search_Chooser.H +++ b/src/Fl_Search_Chooser.H @@ -1,6 +1,4 @@ // -// "$Id: Fl_Value_Dial.H,v 1.2 2005/05/18 11:34:30 hofmann Exp $" -// // Value dial header file for the Fast Light Tool Kit (FLTK). // // Copyright 1998-2004 by Bill Spitzak and others. @@ -20,8 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@fltk.org". -// #ifndef FL_SEARCH_CHOOSER_H #define FL_SEARCH_CHOOSER_H diff --git a/src/Fl_Value_Dial.H b/src/Fl_Value_Dial.H index 7d41aa5..f9ac18c 100644 --- a/src/Fl_Value_Dial.H +++ b/src/Fl_Value_Dial.H @@ -1,6 +1,4 @@ // -// "$Id: Fl_Value_Dial.H,v 1.2 2005/05/18 11:34:30 hofmann Exp $" -// // Value dial header file for the Fast Light Tool Kit (FLTK). // // Copyright 1998-2004 by Bill Spitzak and others. @@ -20,8 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@fltk.org". -// #ifndef Fl_Value_Dial_H #define Fl_Value_Dial_H @@ -45,7 +41,3 @@ class Fl_Value_Dial : public Fl_Dial { }; #endif - -// -// End of "$Id: Fl_Value_Dial.H,v 1.2 2005/05/18 11:34:30 hofmann Exp $". -// diff --git a/src/Fl_Value_Dial.cxx b/src/Fl_Value_Dial.cxx index 6e5c35c..c837930 100644 --- a/src/Fl_Value_Dial.cxx +++ b/src/Fl_Value_Dial.cxx @@ -1,6 +1,4 @@ // -// "$Id: Fl_Value_Dial.cxx,v 1.2 2005/05/18 11:34:30 hofmann Exp $" -// // Value dial widget for the Fast Light Tool Kit (FLTK). // // Copyright 1998-2004 by Bill Spitzak and others. @@ -20,8 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@fltk.org". -// #include #include diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 4e74cb4..7bcd3c0 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,7 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.22 2005/06/22 19:47:19 hofmann Exp $" -// -// Copyright 2005 by Johannes Hofmann +// Copyright 2006 by Johannes Hofmann // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public diff --git a/src/Hill.H b/src/Hill.H index fde7a89..13d7d64 100644 --- a/src/Hill.H +++ b/src/Hill.H @@ -1,6 +1,4 @@ // -// "$Id: Hill.H,v 1.16 2005/06/22 20:40:35 hofmann Exp $" -// // Copyright 2005 by Johannes Hofmann // // This library is free software; you can redistribute it and/or diff --git a/src/Panorama.H b/src/Panorama.H index 20d3213..a538809 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -1,6 +1,4 @@ // -// "$Id: Panorama.H,v 1.20 2005/06/22 19:47:20 hofmann Exp $" -// // Copyright 2005 by Johannes Hofmann // // This library is free software; you can redistribute it and/or diff --git a/src/Projection.H b/src/Projection.H index f6de5ae..0a6ec81 100644 --- a/src/Projection.H +++ b/src/Projection.H @@ -1,7 +1,5 @@ // -// "$Id: Panorama.H,v 1.20 2005/06/22 19:47:20 hofmann Exp $" -// -// Copyright 2005 by Johannes Hofmann +// Copyright 2006 by Johannes Hofmann // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public diff --git a/src/ProjectionTangential.H b/src/ProjectionTangential.H index 74a4b59..e74511f 100644 --- a/src/ProjectionTangential.H +++ b/src/ProjectionTangential.H @@ -1,6 +1,4 @@ // -// "$Id: Panorama.H,v 1.20 2005/06/22 19:47:20 hofmann Exp $" -// // Copyright 2005 by Johannes Hofmann // // This library is free software; you can redistribute it and/or diff --git a/src/choose_hill.H b/src/choose_hill.H index 1387868..e424d70 100644 --- a/src/choose_hill.H +++ b/src/choose_hill.H @@ -1,8 +1,4 @@ // -// "$Id: Fl_Value_Dial.H,v 1.2 2005/05/18 11:34:30 hofmann Exp $" -// -// Value dial header file for the Fast Light Tool Kit (FLTK). -// // Copyright 1998-2004 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or @@ -20,8 +16,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@fltk.org". -// #ifndef CHOOSE_HILL_H #define CHOOSE_HILL_H -- cgit v1.2.3