summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2005-04-13 17:09:19 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2005-04-13 17:09:19 +0000
commita25441aaab4c15bc5a0dba9dbd4d26cc36780163 (patch)
tree5825cce00541c766f1f25fdb12c889dbae935495 /src
parent9002a841a37a4dc4acd1c55e56a5e778156a5622 (diff)
es geht voran
es geht voran
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.H10
-rw-r--r--src/GipfelWidget.cxx28
-rw-r--r--src/Hill.H3
-rw-r--r--src/Hill.cxx3
-rw-r--r--src/Panorama.H19
-rw-r--r--src/Panorama.cxx70
-rw-r--r--src/gipfel.cxx32
7 files changed, 130 insertions, 35 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index f30f9ca..1eeeb72 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -1,5 +1,5 @@
//
-// "$Id: GipfelWidget.H,v 1.2 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: GipfelWidget.H,v 1.3 2005/04/13 19:09:19 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -25,15 +25,21 @@
#define GipfelWidget_H
#include <FL/Fl_Widget.H>
+#include "Panorama.H"
class GipfelWidget : public Fl_Widget {
private:
Fl_Image *img;
+ Panorama *pan;
public:
GipfelWidget(int X,int Y,int W, int H);
- int load(const char *file);
+ int load_image(const char *file);
+
+ int load_data(const char *file);
+
+ int set_viewpoint(const char *pos);
void draw();
};
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 10b8c55..821943d 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: GipfelWidget.cxx,v 1.2 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: GipfelWidget.cxx,v 1.3 2005/04/13 19:09:19 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -41,13 +41,13 @@
GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
-
img = NULL;
+ pan = new Panorama();
fl_register_images();
}
int
-GipfelWidget::load(const char *file) {
+GipfelWidget::load_image(const char *file) {
img = new Fl_JPEG_Image(file);
if (img == NULL) {
@@ -59,9 +59,21 @@ GipfelWidget::load(const char *file) {
return 0;
}
+int
+GipfelWidget::load_data(const char *file) {
+ return pan->load_file(file);
+}
+
+int
+GipfelWidget::set_viewpoint(const char *pos) {
+ return pan->set_viewpoint(pos);
+}
void
GipfelWidget::draw() {
+ Mountain *m;
+ int center = w() / 2;
+
if (img == NULL) {
return;
}
@@ -71,8 +83,16 @@ GipfelWidget::draw() {
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();
+ }
- 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
index 69db8ba..3474e28 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.H,v 1.1 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: Hill.H,v 1.2 2005/04/13 19:09:19 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -34,6 +34,7 @@ class Mountain {
public:
double phi, lam;
double height;
+ double alph;
char *name;
Mountain(const char *n, double p, double l, double h);
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 18cc353..e3d999c 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.cxx,v 1.1 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: Hill.cxx,v 1.2 2005/04/13 19:09:19 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -31,6 +31,7 @@ Mountain::Mountain(const char *n, double p, double l, double h) {
phi = p;
lam = l;
height = h;
+ alph = 0.0;
next = NULL;
next_visible = NULL;
}
diff --git a/src/Panorama.H b/src/Panorama.H
index ae6b839..690ed86 100644
--- a/src/Panorama.H
+++ b/src/Panorama.H
@@ -1,5 +1,5 @@
//
-// "$Id: Panorama.H,v 1.1 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: Panorama.H,v 1.2 2005/04/13 19:09:19 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -33,12 +33,21 @@ class Panorama {
Mountain *mountains;
Mountain *visible_mountains;
double pi, deg2rad;
+ double center_angle;
+ double scale;
int get_pos(const char *name, double *phi, double *lam);
- void check_visibility();
+ void update_visible_mountains();
+
+ double distance(double phi, double lam);
+
+ double sin_alpha(double lam, double phi, double c);
+
+ double cos_alpha(double phi, double c);
+
+ double alpha(double phi, double lam);
- double Panorama::distance(double phi, double lam);
public:
Panorama();
@@ -49,5 +58,9 @@ class Panorama {
int set_viewpoint(const char *pos);
void set_height_dist_ratio(double r);
+
+ Mountain * get_visible_mountains();
+
+ int get_x(Mountain *m);
};
#endif
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index 6a25ac4..e2fce5d 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Panorama.cxx,v 1.1 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: Panorama.cxx,v 1.2 2005/04/13 19:09:19 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -34,6 +34,8 @@ Panorama::Panorama() {
height_dist_ratio = 0.1;
pi = asin(1.0) * 2.0;
deg2rad = pi / 180.0;
+ center_angle = 0.0;
+ scale = 200.0;
}
Panorama::~Panorama() {
@@ -51,6 +53,13 @@ Panorama::load_file(const char *name) {
double phi, lam, height;
Mountain *m;
+ if (mountains) {
+ delete(mountains);
+ }
+
+ mountains = NULL;
+ visible_mountains = NULL;
+
fp = fopen(name, "r");
if (!fp) {
perror("fopen");
@@ -78,7 +87,7 @@ Panorama::load_file(const char *name) {
fclose(fp);
- check_visibility();
+ update_visible_mountains();
return 0;
}
@@ -89,10 +98,20 @@ Panorama::set_viewpoint(const char *name) {
return 1;
}
- check_visibility();
+ update_visible_mountains();
return 0;
}
+Mountain *
+Panorama::get_visible_mountains() {
+ return visible_mountains;
+}
+
+int
+Panorama::get_x(Mountain *m) {
+ return (int) (tan(m->alph - center_angle) * scale);
+}
+
int
Panorama::get_pos(const char *name, double *phi, double *lam) {
Mountain *m = mountains;
@@ -120,7 +139,7 @@ Panorama::get_pos(const char *name, double *phi, double *lam) {
}
void
-Panorama::check_visibility() {
+Panorama::update_visible_mountains() {
Mountain *m = mountains;
visible_mountains = NULL;
@@ -128,11 +147,14 @@ Panorama::check_visibility() {
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 ->alph = alpha(m->phi, m->lam);
+
+ if (m->alph < pi / 2.0 && m->alph > - pi / 2.0) {
+ if (visible_mountains) {
+ visible_mountains->append_visible(m);
+ } else {
+ visible_mountains = m;
+ }
}
}
@@ -145,3 +167,33 @@ Panorama::distance(double phi, double lam) {
return acos(sin(view_phi) * sin(phi) +
cos(view_phi) * cos(phi) * cos(view_lam - lam));
}
+
+double
+Panorama::sin_alpha(double lam, double phi, double c) {
+ return sin(lam - view_lam) * cos(phi) / sin(c);
+}
+
+
+double
+Panorama::cos_alpha(double phi, double c) {
+ return (sin(phi) - sin(view_phi) * cos(c)) / (cos(view_phi) * sin(c));
+}
+
+
+double
+Panorama::alpha(double phi, double lam) {
+ double dist, sin_alph, cos_alph, alph;
+
+ dist = distance(phi, lam);
+ sin_alph = sin_alpha(lam, phi, dist);
+ cos_alph = cos_alpha(phi, dist);
+
+ if (sin_alph > 0) {
+ alph = acos(cos_alph);
+ } else {
+ alph = 2.0 * pi - acos(cos_alph);
+ }
+
+ return alph;
+}
+
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index e71d34f..c3436e0 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: gipfel.cxx,v 1.3 2005/04/13 18:07:16 hofmann Exp $"
+// "$Id: gipfel.cxx,v 1.4 2005/04/13 19:09:19 hofmann Exp $"
//
// flpsed program.
//
@@ -43,10 +43,11 @@
#include "GipfelWidget.H"
-char *filename;
+char *img_file;
+char *data_file;
void open_cb() {
- char *file = fl_file_chooser("Open File?", "*.ps", filename);
+ char *file = fl_file_chooser("Open File?", "*.jpeg", img_file);
if(file != NULL) {
}
@@ -83,23 +84,24 @@ void usage() {
int main(int argc, char** argv) {
char c, *sep, *tmp, **my_argv;
+ char *view_point = NULL;
int err, bflag = 0, dflag = 0, my_argc;
Fl_Window *win;
Fl_Scroll *scroll;
Fl_Menu_Bar *m;
err = 0;
- while ((c = getopt(argc, argv, "hdbt:")) != EOF) {
+ while ((c = getopt(argc, argv, "d:v:")) != EOF) {
switch (c) {
case 'h':
usage();
exit(0);
break;
- case 'b':
- bflag = 1;
- break;
case 'd':
- dflag = 1;
+ data_file = optarg;
+ break;
+ case 'v':
+ view_point = optarg;
break;
default:
err++;
@@ -114,23 +116,23 @@ int main(int argc, char** argv) {
my_argc = argc - optind;
my_argv = argv + optind;
- fprintf(stderr, "%d %s\n", my_argc, my_argv[0]);
if (my_argc >= 1) {
- filename = my_argv[0];
+ img_file = my_argv[0];
}
-
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);
- fprintf(stderr, "%s\n", filename);
GipfelWidget *gipf = new GipfelWidget(0,30,500,500);
- gipf->load(filename);
- scroll->end();
-
+ gipf->load_image(img_file);
+ gipf->load_data(data_file);
+ if (view_point) {
+ gipf->set_viewpoint(view_point);
+ }
+ scroll->end();
win->resizable(scroll);