diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GipfelWidget.H | 8 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 16 | ||||
-rw-r--r-- | src/Hill.H | 53 | ||||
-rw-r--r-- | src/Hill.cxx | 79 | ||||
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/Panorama.H | 53 | ||||
-rw-r--r-- | src/Panorama.cxx | 147 | ||||
-rw-r--r-- | src/gipfel.cxx | 3 |
8 files changed, 345 insertions, 16 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 732329d..f30f9ca 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.1 2005/04/13 15:36:36 hofmann Exp $" +// "$Id: GipfelWidget.H,v 1.2 2005/04/13 18:07:16 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -24,9 +24,9 @@ #ifndef GipfelWidget_H #define GipfelWidget_H -#include <FL/Fl_Overlay_Window.H> +#include <FL/Fl_Widget.H> -class GipfelWidget : public Fl_Overlay_Window { +class GipfelWidget : public Fl_Widget { private: Fl_Image *img; @@ -35,8 +35,6 @@ class GipfelWidget : public Fl_Overlay_Window { int load(const char *file); - void draw_overlay(); - void draw(); }; #endif diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 8a3aa7b..10b8c55 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.cxx,v 1.1 2005/04/13 15:36:36 hofmann Exp $" +// "$Id: GipfelWidget.cxx,v 1.2 2005/04/13 18:07:16 hofmann Exp $" // // PSEditWidget routines. // @@ -40,7 +40,7 @@ #include "GipfelWidget.H" -GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Overlay_Window(X, Y, W, H) { +GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { img = NULL; fl_register_images(); @@ -66,14 +66,14 @@ GipfelWidget::draw() { return; } - img->draw(0,0,w(),h(),0,0); -} + fl_push_clip(x(), y(), w(), h()); + img->draw(x(),y(),w(),h(),0,0); + -void -GipfelWidget::draw_overlay() { fl_color(FL_RED); - fl_draw_box(FL_UP_BOX, 10, 10, 25,25, FL_GRAY); -} + fl_draw_box(FL_UP_BOX, x()+20, y()+20, 25,25, FL_GRAY); + fl_pop_clip(); +} diff --git a/src/Hill.H b/src/Hill.H new file mode 100644 index 0000000..69db8ba --- /dev/null +++ b/src/Hill.H @@ -0,0 +1,53 @@ +// +// "$Id: Hill.H,v 1.1 2005/04/13 18:07:16 hofmann Exp $" +// +// X11 header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 2004 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#ifndef MOUNTAIN_H +#define MOUNTAIN_H + +class Mountain; + +class Mountain { + private: + Mountain *next; + Mountain *next_visible; + + public: + double phi, lam; + double height; + char *name; + + Mountain(const char *n, double p, double l, double h); + + ~Mountain(); + + void append(Mountain *m); + + void append_visible(Mountain *m); + + void set_first_visible(); + + Mountain * get_next(); + + Mountain * get_next_visible(); +}; +#endif diff --git a/src/Hill.cxx b/src/Hill.cxx new file mode 100644 index 0000000..18cc353 --- /dev/null +++ b/src/Hill.cxx @@ -0,0 +1,79 @@ +// +// "$Id: Hill.cxx,v 1.1 2005/04/13 18:07:16 hofmann Exp $" +// +// PSEditWidget routines. +// +// Copyright 2004 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#include <stdlib.h> +#include <string.h> + +#include "Mountain.H" + +Mountain::Mountain(const char *n, double p, double l, double h) { + name = strdup(n); + phi = p; + lam = l; + height = h; + next = NULL; + next_visible = NULL; +} + +Mountain::~Mountain() { + if (next) { + delete(next); + } + + if (name) { + free(name); + } +} + +void +Mountain::append(Mountain *m) { + if (next) { + next->append(m); + } else { + next = m; + } +} + +Mountain * +Mountain::get_next() { + return next; +} + +void +Mountain::append_visible(Mountain *m) { + if (next_visible) { + next->append_visible(m); + } else { + next_visible = m; + } +} + +Mountain * +Mountain::get_next_visible() { + return next_visible; +} + +void +Mountain::set_first_visible() { + next_visible = NULL; +} diff --git a/src/Makefile b/src/Makefile index 4e02613..7edcf67 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,7 +4,7 @@ CFLAGS=-g -I/usr/X11R6/include CXXFLAGS=-g -I/usr/X11R6/include LDFLAGS=-g -OBJECTS=flmountains.o GipfelWidget.o +OBJECTS=flmountains.o GipfelWidget.o Mountain.o Panorama.o #%.o: %.c # $(CC) -c $(CFLAGS) $*.c diff --git a/src/Panorama.H b/src/Panorama.H new file mode 100644 index 0000000..ae6b839 --- /dev/null +++ b/src/Panorama.H @@ -0,0 +1,53 @@ +// +// "$Id: Panorama.H,v 1.1 2005/04/13 18:07:16 hofmann Exp $" +// +// X11 header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 2004 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#ifndef PANORAMA_H +#define PANORAMA_H + +#include "Mountain.H" + +class Panorama { + private: + double view_phi, view_lam; + double height_dist_ratio; + Mountain *mountains; + Mountain *visible_mountains; + double pi, deg2rad; + + int get_pos(const char *name, double *phi, double *lam); + + void check_visibility(); + + double Panorama::distance(double phi, double lam); + public: + Panorama(); + + ~Panorama(); + + int load_file(const char *name); + + int set_viewpoint(const char *pos); + + void set_height_dist_ratio(double r); +}; +#endif diff --git a/src/Panorama.cxx b/src/Panorama.cxx new file mode 100644 index 0000000..6a25ac4 --- /dev/null +++ b/src/Panorama.cxx @@ -0,0 +1,147 @@ +// +// "$Id: Panorama.cxx,v 1.1 2005/04/13 18:07:16 hofmann Exp $" +// +// PSEditWidget routines. +// +// Copyright 2004 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include "Panorama.H" + +Panorama::Panorama() { + mountains = NULL; + visible_mountains = NULL; + height_dist_ratio = 0.1; + pi = asin(1.0) * 2.0; + deg2rad = pi / 180.0; +} + +Panorama::~Panorama() { + if (mountains) { + delete(mountains); + } +} + +int +Panorama::load_file(const char *name) { + FILE *fp; + char buf[4000]; + char *vals[10]; + char **ap, *bp; + double phi, lam, height; + Mountain *m; + + fp = fopen(name, "r"); + if (!fp) { + perror("fopen"); + return 1; + } + + while (fgets(buf, sizeof(buf), fp)) { + bp = buf; + for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;) + if (++ap >= &vals[10]) + break; + + phi = atof(vals[3]) * deg2rad; + lam = atof(vals[4]) * deg2rad; + + height = atof(vals[5]); + + m = new Mountain(vals[1], phi, lam, height); + if (mountains) { + mountains->append(m); + } else { + mountains = m; + } + } + + fclose(fp); + + check_visibility(); + return 0; +} + +int +Panorama::set_viewpoint(const char *name) { + if (get_pos(name, &view_phi, &view_lam) != 1) { + fprintf(stderr, "Could not find exactly one entry for %s.\n"); + return 1; + } + + check_visibility(); + return 0; +} + +int +Panorama::get_pos(const char *name, double *phi, double *lam) { + Mountain *m = mountains; + int found = 0; + double p, l; + + while (m) { + if (strstr(m->name, name)) { + p = m->phi; + l = m->lam; + + fprintf(stderr, "Found matching entry: %s (%fm)\n", m->name, m->height); + found++; + } + + m = m->get_next(); + } + + if (found == 1) { + *phi = p; + *lam = l; + } + + return found; +} + +void +Panorama::check_visibility() { + Mountain *m = mountains; + visible_mountains = NULL; + + while (m) { + + if (m->height / (distance(m->phi, m->lam)* 6368000) + > height_dist_ratio) { + + if (visible_mountains) { + visible_mountains->append_visible(m); + } else { + visible_mountains = m; + } + } + + m = m->get_next(); + } +} + +double +Panorama::distance(double phi, double lam) { + return acos(sin(view_phi) * sin(phi) + + cos(view_phi) * cos(phi) * cos(view_lam - lam)); +} diff --git a/src/gipfel.cxx b/src/gipfel.cxx index e72703d..e71d34f 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -1,5 +1,5 @@ // -// "$Id: gipfel.cxx,v 1.2 2005/04/13 15:36:36 hofmann Exp $" +// "$Id: gipfel.cxx,v 1.3 2005/04/13 18:07:16 hofmann Exp $" // // flpsed program. // @@ -136,7 +136,6 @@ int main(int argc, char** argv) { win->end(); win->show(1, argv); - gipf->redraw_overlay(); return Fl::run(); } |