summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-11-26 17:22:42 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-11-26 17:22:42 +0100
commit2aaf6d31566df56d30ee492418562e04732c8059 (patch)
tree3062dd55798ec76edb095c4f83abecd27c7da328
parentceec61fe9614b7fb631781c3f9d21894e084077b (diff)
parenta10646b1c87e6abc1651ae7160ddd2c7fd1753bc (diff)
merge with mainline
-rw-r--r--NEWS8
-rw-r--r--README1
-rw-r--r--configure.ac2
-rw-r--r--src/Fl_Search_Chooser.H56
-rw-r--r--src/Fl_Search_Chooser.cxx144
-rw-r--r--src/Fl_Value_Dial.H47
-rw-r--r--src/Fl_Value_Dial.cxx111
-rw-r--r--src/GipfelWidget.H135
-rw-r--r--src/GipfelWidget.cxx1037
-rw-r--r--src/Hill.H115
-rw-r--r--src/Hill.cxx415
-rw-r--r--src/ImageMetaData.H50
-rw-r--r--src/ImageMetaData.cxx340
-rw-r--r--src/JPEGOutputImage.H19
-rw-r--r--src/JPEGOutputImage.cxx19
-rw-r--r--src/Makefile.am4
-rw-r--r--src/OutputImage.H19
-rw-r--r--src/OutputImage.cxx19
-rw-r--r--src/Panorama.H159
-rw-r--r--src/Panorama.cxx717
-rw-r--r--src/PreviewOutputImage.H19
-rw-r--r--src/PreviewOutputImage.cxx19
-rw-r--r--src/Projection.H43
-rw-r--r--src/Projection.cxx29
-rw-r--r--src/ProjectionSphaeric.H37
-rw-r--r--src/ProjectionSphaeric.cxx218
-rw-r--r--src/ProjectionTangential.H39
-rw-r--r--src/ProjectionTangential.cxx429
-rw-r--r--src/Stitch.H25
-rw-r--r--src/Stitch.cxx23
-rw-r--r--src/TIFFOutputImage.H19
-rw-r--r--src/TIFFOutputImage.cxx19
-rw-r--r--src/ViewParams.H29
-rw-r--r--src/choose_hill.H19
-rw-r--r--src/choose_hill.cxx74
-rw-r--r--src/gipfel.cxx717
-rw-r--r--src/panorama.c386
-rw-r--r--src/util.c107
-rw-r--r--src/util.h28
39 files changed, 2601 insertions, 3095 deletions
diff --git a/NEWS b/NEWS
index 7a4cfa5..f815647 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,13 @@
gipfel ChangeLog
=================
+gipfel-0.2.0
+ - Change scale factor to "focal length in 35mm" this makes it
+ independent of the image size. One can now scale an already
+ oriented image without invalidating the orientation information.
+ - gipfel now tries to find a reasonable default for the scale value
+ when opening new images based on the "Focal Length In 35mm" Exif
+ tag, if it exists.
+ - GPS position Exif tags are used if they exist.
gipfel-0.1.3
- Add stitching mode (gipfel -s). See README for details.
diff --git a/README b/README
index ff96a64..9a6c469 100644
--- a/README
+++ b/README
@@ -21,6 +21,7 @@ Requirements
- fltk-1.1.x (http://www.fltk.org)
- libtiff (http://www.remotesensing.org/libtiff/)
- libjpeg (http://www.ijg.org/)
+- exif utility (http://libexif.sourceforge.net/)
- ccmath library (http://freshmeat.net/projects/ccmath/)
- gipfel works on UNIX-like system (e.g. Linux, *BSD and probably others)
diff --git a/configure.ac b/configure.ac
index 1b5d0ac..27e4908 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT(gipfel, 0.1.3, Johannes.Hofmann@gmx.de)
+AC_INIT(gipfel, 0.2.0, Johannes.Hofmann@gmx.de)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/Panorama.H])
AC_CONFIG_HEADER(config.h)
diff --git a/src/Fl_Search_Chooser.H b/src/Fl_Search_Chooser.H
index c87f0de..e968452 100644
--- a/src/Fl_Search_Chooser.H
+++ b/src/Fl_Search_Chooser.H
@@ -1,23 +1,8 @@
//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef FL_SEARCH_CHOOSER_H
#define FL_SEARCH_CHOOSER_H
@@ -27,28 +12,27 @@
#include <FL/Fl_Input.H>
class Fl_Search_Browser : public Fl_Select_Browser {
- public:
-
- Fl_Search_Browser(int X, int Y, int W, int H, const char *c):Fl_Select_Browser(X,Y,W,H,c){};
+ public:
- int find_prefix(const char *p);
- private:
- int find_prefix(const char *p, int s, int e);
+ Fl_Search_Browser(int X, int Y, int W, int H, const char *c):Fl_Select_Browser(X,Y,W,H,c){};
+
+ int find_prefix(const char *p);
+ private:
+ int find_prefix(const char *p, int s, int e);
};
class Fl_Search_Chooser {
- private:
- public:
- Fl_Window *w;
- Fl_Search_Browser *sb;
-
- Fl_Search_Chooser(const char *title);
- ~Fl_Search_Chooser();
-
- void add(const char *t, void *d);
- void *data();
- void show();
- int shown();
+ private:
+ public:
+ Fl_Window *w;
+ Fl_Search_Browser *sb;
+
+ Fl_Search_Chooser(const char *title);
+
+ void add(const char *t, void *d);
+ void *data();
+ void show();
+ int shown();
};
#endif
diff --git a/src/Fl_Search_Chooser.cxx b/src/Fl_Search_Chooser.cxx
index 62aa7d1..d4f93b2 100644
--- a/src/Fl_Search_Chooser.cxx
+++ b/src/Fl_Search_Chooser.cxx
@@ -1,24 +1,8 @@
//
-// Search Chooser widget for the Fast Light Tool Kit (FLTK).
-//
-// Copyright 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.
-//
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <string.h>
@@ -29,103 +13,97 @@
int
Fl_Search_Browser::find_prefix(const char *p) {
- int i = find_prefix(p, 1, size());
- if (i == -1) {
- return 1;
- } else {
- deselect();
- middleline(i);
- select(i);
- return 0;
- }
+ int i = find_prefix(p, 1, size());
+ if (i == -1) {
+ return 1;
+ } else {
+ deselect();
+ middleline(i);
+ select(i);
+ return 0;
+ }
};
int
Fl_Search_Browser::find_prefix(const char *p, int s, int e) {
- if (s < 0 || e > size() || s > e) {
- fprintf(stderr, "Invalid search range %d %d\n", s, e);
- return 1;
- } else if (e - s <= 1) {
- if (strncasecmp(p, text(s), strlen(p)) == 0) {
- return s;
- } else if (strncasecmp(p, text(e), strlen(p)) == 0){
- return e;
- } else {
- return -1;
- }
- } else {
- int med = s + (e - s) / 2;
- if (strncasecmp(p, text(med), strlen(p)) > 0) {
- return find_prefix(p, med, e);
- } else {
- return find_prefix(p, s, med);
- }
- }
+ if (s < 0 || e > size() || s > e) {
+ fprintf(stderr, "Invalid search range %d %d\n", s, e);
+ return 1;
+ } else if (e - s <= 1) {
+ if (strncasecmp(p, text(s), strlen(p)) == 0) {
+ return s;
+ } else if (strncasecmp(p, text(e), strlen(p)) == 0){
+ return e;
+ } else {
+ return -1;
+ }
+ } else {
+ int med = s + (e - s) / 2;
+ if (strncasecmp(p, text(med), strlen(p)) > 0) {
+ return find_prefix(p, med, e);
+ } else {
+ return find_prefix(p, s, med);
+ }
+ }
}
static void input_cb(Fl_Input* in, void*c) {
- Fl_Search_Browser *sb = ((Fl_Search_Chooser *) c)->sb;
- sb->find_prefix(in->value());
+ Fl_Search_Browser *sb = ((Fl_Search_Chooser *) c)->sb;
+ sb->find_prefix(in->value());
}
static void ok_cb(Fl_Input* in, void*c) {
- Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c;
- sc->w->hide();
+ Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c;
+ sc->w->hide();
}
static void cancel_cb(Fl_Input* in, void*c) {
- Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c;
- sc->sb->deselect();
- sc->w->hide();
+ Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c;
+ sc->sb->deselect();
+ sc->w->hide();
}
Fl_Search_Chooser::Fl_Search_Chooser(const char *title) {
- w = new Fl_Window(320, 320, title?title:"Choose");
- Fl_Group *g = new Fl_Group(10, 10, w->w() - 10, w->h() - 10);
- sb = new Fl_Search_Browser(g->x(), g->y(), g->w() , g->h() - 100, NULL);
- sb->type(FL_HOLD_BROWSER);
- Fl_Input *in = new Fl_Input(g->x()+50, g->h()-80, g->w()-80, 20, "Search");
- in->callback((Fl_Callback*) input_cb, this);
- in->when(FL_WHEN_CHANGED);
- Fl_Button *cancel_b = new Fl_Button(g->w()-200, g->h()-30, 80, 25, "Cancel");
- cancel_b->callback((Fl_Callback*) cancel_cb, this);
- Fl_Button *ok_b = new Fl_Button(g->w()-100, g->h()-30, 80, 25, "Ok");
- ok_b->callback((Fl_Callback*) ok_cb, this);
- Fl::focus(in);
- g->end();
- w->end();
-}
-
-Fl_Search_Chooser::~Fl_Search_Chooser() {
- delete sb;
- delete w;
+ w = new Fl_Window(320, 320, title?title:"Choose");
+ Fl_Group *g = new Fl_Group(10, 10, w->w() - 10, w->h() - 10);
+ sb = new Fl_Search_Browser(g->x(), g->y(), g->w() , g->h() - 100, NULL);
+ sb->type(FL_HOLD_BROWSER);
+ Fl_Input *in = new Fl_Input(g->x()+50, g->h()-80, g->w()-80, 20, "Search");
+ in->callback((Fl_Callback*) input_cb, this);
+ in->when(FL_WHEN_CHANGED);
+ Fl_Button *cancel_b = new Fl_Button(g->w()-200, g->h()-30, 80, 25, "Cancel");
+ cancel_b->callback((Fl_Callback*) cancel_cb, this);
+ Fl_Button *ok_b = new Fl_Button(g->w()-100, g->h()-30, 80, 25, "Ok");
+ ok_b->callback((Fl_Callback*) ok_cb, this);
+ Fl::focus(in);
+ g->end();
+ w->end();
}
void
Fl_Search_Chooser::add(const char *t, void *d) {
- sb->add(t, d);
+ sb->add(t, d);
}
void *
Fl_Search_Chooser::data() {
- int v = sb->value();
- if (v) {
- return sb->data(v);
- } else {
- return NULL;
- }
+ int v = sb->value();
+ if (v) {
+ return sb->data(v);
+ } else {
+ return NULL;
+ }
}
void
Fl_Search_Chooser::show() {
- w->show();
+ w->show();
}
int
Fl_Search_Chooser::shown() {
- return w->shown();
+ return w->shown();
}
-
diff --git a/src/Fl_Value_Dial.H b/src/Fl_Value_Dial.H
index f9ac18c..94fda5a 100644
--- a/src/Fl_Value_Dial.H
+++ b/src/Fl_Value_Dial.H
@@ -1,23 +1,8 @@
//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef Fl_Value_Dial_H
#define Fl_Value_Dial_H
@@ -25,19 +10,19 @@
#include <FL/Fl_Dial.H>
class Fl_Value_Dial : public Fl_Dial {
- uchar textfont_, textsize_;
- unsigned textcolor_;
- public:
- void draw();
- int handle(int event);
-
- Fl_Value_Dial(int x,int y,int w,int h, const char *l = 0);
- Fl_Font textfont() const {return (Fl_Font)textfont_;}
- void textfont(uchar s) {textfont_ = s;}
- uchar textsize() const {return textsize_;}
- void textsize(uchar s) {textsize_ = s;}
- Fl_Color textcolor() const {return (Fl_Color)textcolor_;}
- void textcolor(unsigned s) {textcolor_ = s;}
+ uchar textfont_, textsize_;
+ unsigned textcolor_;
+ public:
+ void draw();
+ int handle(int event);
+
+ Fl_Value_Dial(int x,int y,int w,int h, const char *l = 0);
+ Fl_Font textfont() const {return (Fl_Font)textfont_;}
+ void textfont(uchar s) {textfont_ = s;}
+ uchar textsize() const {return textsize_;}
+ void textsize(uchar s) {textsize_ = s;}
+ Fl_Color textcolor() const {return (Fl_Color)textcolor_;}
+ void textcolor(unsigned s) {textcolor_ = s;}
};
#endif
diff --git a/src/Fl_Value_Dial.cxx b/src/Fl_Value_Dial.cxx
index c837930..f210ca3 100644
--- a/src/Fl_Value_Dial.cxx
+++ b/src/Fl_Value_Dial.cxx
@@ -1,23 +1,8 @@
//
-// Value dial widget 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <FL/Fl.H>
#include <FL/fl_draw.H>
@@ -25,57 +10,57 @@
#include "Fl_Value_Dial.H"
Fl_Value_Dial::Fl_Value_Dial(int X, int Y, int W, int H, const char*l)
-: Fl_Dial(X,Y,W,H,l) {
- step(1,100);
- textfont_ = FL_HELVETICA;
- textsize_ = 10;
- textcolor_ = FL_BLACK;
-}
+ : Fl_Dial(X,Y,W,H,l) {
+ step(1,100);
+ textfont_ = FL_HELVETICA;
+ textsize_ = 10;
+ textcolor_ = FL_BLACK;
+ }
void Fl_Value_Dial::draw() {
- int sxx = x(), syy = y(), sww = w(), shh = h();
- int bxx = x(), byy = y(), bww = w(), bhh = h();
+ int sxx = x(), syy = y(), sww = w(), shh = h();
+ int bxx = x(), byy = y(), bww = w(), bhh = h();
- if (damage()&FL_DAMAGE_ALL) draw_box(box(),sxx,syy,sww,shh,color());
- Fl_Dial::draw(sxx+Fl::box_dx(box()),
- syy+Fl::box_dy(box()),
- sww-Fl::box_dw(box()),
- shh-Fl::box_dh(box()));
+ if (damage()&FL_DAMAGE_ALL) draw_box(box(),sxx,syy,sww,shh,color());
+ Fl_Dial::draw(sxx+Fl::box_dx(box()),
+ syy+Fl::box_dy(box()),
+ sww-Fl::box_dw(box()),
+ shh-Fl::box_dh(box()));
- char buf[128];
- format(buf);
- fl_font(textfont(), textsize());
+ char buf[128];
+ format(buf);
+ fl_font(textfont(), textsize());
- fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
- fl_draw(buf, bxx, byy + fl_height() - 2, bww, bhh, FL_ALIGN_TOP);
+ fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
+ fl_draw(buf, bxx, byy + fl_height() - 2, bww, bhh, FL_ALIGN_TOP);
}
int Fl_Value_Dial::handle(int event) {
- switch (event) {
- case FL_KEYBOARD :
- switch (Fl::event_key()) {
- case FL_Left:
- handle_drag(clamp(increment(value(),-1)));
- handle_release();
- return 1;
- case FL_Right:
- handle_drag(clamp(increment(value(),1)));
- handle_release();
- return 1;
- default:
- return 0;
- }
- break;
- case FL_FOCUS :
- case FL_UNFOCUS :
- if (Fl::visible_focus()) {
- redraw();
- return 1;
- } else return 0;
- case FL_ENTER :
- case FL_LEAVE :
- return 1;
- default:
- return Fl_Dial::handle(event);
- }
+ switch (event) {
+ case FL_KEYBOARD :
+ switch (Fl::event_key()) {
+ case FL_Left:
+ handle_drag(clamp(increment(value(),-1)));
+ handle_release();
+ return 1;
+ case FL_Right:
+ handle_drag(clamp(increment(value(),1)));
+ handle_release();
+ return 1;
+ default:
+ return 0;
+ }
+ break;
+ case FL_FOCUS :
+ case FL_UNFOCUS :
+ if (Fl::visible_focus()) {
+ redraw();
+ return 1;
+ } else return 0;
+ case FL_ENTER :
+ case FL_LEAVE :
+ return 1;
+ default:
+ return Fl_Dial::handle(event);
+ }
}
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 054e9ef..80761a5 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef GipfelWidget_H
#define GipfelWidget_H
@@ -25,111 +12,111 @@
#include "Panorama.H"
class GipfelWidget : public Fl_Widget {
- private:
- Fl_Image *img;
- Hill *cur_mountain;
- Hills *marker;
- Hills *track_points;
- Hill *m1, *m2;
- Panorama *pan;
- Fl_Menu_Button *mb;
- char *img_file;
- double track_width;
- int show_hidden;
+ private:
+ Fl_Image *img;
+ Hill *cur_mountain;
+ Hills *marker;
+ Hills *track_points;
+ Hill *m1, *m2;
+ Panorama *pan;
+ Fl_Menu_Button *mb;
+ char *img_file;
+ double track_width;
+ int show_hidden;
- int handle(int event);
+ int handle(int event);
- int set_cur_mountain(int m_x, int m_y);
+ int set_cur_mountain(int m_x, int m_y);
- int set_mountain(int m_x, int m_y);
+ int set_mountain(int m_x, int m_y);
- void set_labels(Hills *v);
+ void set_labels(Hills *v);
- int get_rel_track_width(Hill *m);
+ int get_rel_track_width(Hill *m);
- static int get_pixel_nearest(Fl_Image *img, double x, double y,
+ static int get_pixel_nearest(Fl_Image *img, double x, double y,
uchar *r, uchar *g, uchar *b);
static int get_pixel_bilinear(Fl_Image *img, double x, double y,
uchar *r, uchar *g, uchar *b);
- static int get_pixel(Fl_Image *img, int x, int y,
+ static int get_pixel(Fl_Image *img, int x, int y,
uchar *r, uchar *g, uchar *b);
- public:
- GipfelWidget(int X,int Y,int W, int H);
+ public:
+ GipfelWidget(int X,int Y,int W, int H);
+
+ void center();
+
+ int load_image(char *file);
- void center();
+ int save_image(char *file);
- int load_image(char *file);
+ const char * get_image_filename();
- int save_image(char *file);
-
- const char * get_image_filename();
+ int load_data(const char *file);
- int load_data(const char *file);
+ int load_track(const char *file);
- int load_track(const char *file);
+ int set_viewpoint(const char *pos);
- int set_viewpoint(const char *pos);
+ void set_viewpoint(const Hill *m);
- void set_viewpoint(const Hill *m);
+ void set_center_angle(double a);
- void set_center_angle(double a);
+ void set_nick_angle(double a);
- void set_nick_angle(double a);
+ void set_tilt_angle(double a);
- void set_tilt_angle(double a);
+ void set_focal_length_35mm(double s);
- void set_scale(double s);
+ void set_height_dist_ratio(double r);
- void set_height_dist_ratio(double r);
+ void set_hide_value(double h);
- void set_hide_value(double h);
+ void set_show_hidden(int h);
- void set_show_hidden(int h);
+ void set_view_lat(double v);
- void set_view_lat(double v);
+ void set_view_long(double v);
- void set_view_long(double v);
+ void set_view_height(double v);
- void set_view_height(double v);
-
- const char * get_viewpoint();
+ const char * get_viewpoint();
- double get_center_angle();
+ double get_center_angle();
- double get_nick_angle();
+ double get_nick_angle();
- double get_tilt_angle();
+ double get_tilt_angle();
- double get_scale();
+ double get_focal_length_35mm();
- double get_height_dist_ratio();
+ double get_height_dist_ratio();
- double get_view_lat();
+ double get_view_lat();
- double get_view_long();
+ double get_view_long();
- double get_view_height();
+ double get_view_height();
- void set_track_width(double w);
+ void set_track_width(double w);
- Projection::Projection_t get_projection();
+ Projection::Projection_t get_projection();
- void set_projection(Projection::Projection_t p);
+ void set_projection(Projection::Projection_t p);
- Hills *get_mountains();
+ Hills *get_mountains();
- int comp_params();
+ int comp_params();
- int guess();
+ int guess();
- int update();
+ int update();
- int get_pixel(double a_view, double a_nick,
+ int get_pixel(double a_view, double a_nick,
uchar *r, uchar *g, uchar *b);
- void draw();
+ void draw();
};
#endif
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 272189c..00c5aad 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <string.h>
@@ -35,9 +22,9 @@
#include <FL/Fl_JPEG_Image.H>
#include <FL/fl_draw.H>
+#include "ImageMetaData.H"
#include "Fl_Search_Chooser.H"
#include "choose_hill.H"
-#include "util.h"
#include "GipfelWidget.H"
#define CROSS_SIZE 2
@@ -50,97 +37,75 @@ static double pi_d, deg2rad;
static void center_cb(Fl_Widget *o, void *f);
GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
- int i;
-
- pi_d = asin(1.0) * 2.0;
- deg2rad = pi_d / 180.0;
- img = NULL;
- pan = new Panorama();
- cur_mountain = NULL;
- mb = NULL;
- marker = new Hills();
- m1 = NULL;
- m2 = NULL;
- img_file = NULL;
- track_width = 200.0;
- show_hidden = 0;
-
- for (i=0; i<=3; i++) {
- marker->add(new Hill(i * 10, 0));
- }
- track_points = NULL;
- fl_register_images();
-}
-
-#define GIPFEL_FORMAT "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, scale %lf, projection type %d"
+ int i;
+
+ pi_d = asin(1.0) * 2.0;
+ deg2rad = pi_d / 180.0;
+ img = NULL;
+ pan = new Panorama();
+ cur_mountain = NULL;
+ mb = NULL;
+ marker = new Hills();
+ m1 = NULL;
+ m2 = NULL;
+ img_file = NULL;
+ track_width = 200.0;
+ show_hidden = 0;
+
+ for (i=0; i<=3; i++) {
+ marker->add(new Hill(i * 10, 0));
+ }
+ track_points = NULL;
+ fl_register_images();
+}
int
GipfelWidget::load_image(char *file) {
- char * args[32];
- FILE *p;
- pid_t pid;
- char buf[1024];
- double lo, la, he, dir, ni, ti, sc;
- int status;
- Projection::Projection_t pt = Projection::TANGENTIAL;
- Fl_Image *new_img;
-
- new_img = new Fl_JPEG_Image(file);
-
- if (new_img == NULL) {
- return 1;
- }
-
- if (img) {
- delete img;
- }
-
- img = new_img;
-
- if (img_file) {
- free(img_file);
- }
-
- img_file = strdup(file);
-
- h(img->h());
- w(img->w());
-
- mb = new Fl_Menu_Button(x(),y(),w()+x(),h()+y(),"&popup");
- mb->type(Fl_Menu_Button::POPUP3);
- mb->box(FL_NO_BOX);
- mb->add("Center Peak", 0, (Fl_Callback*) center_cb, this);
-
-// try to retrieve gipfel data from JPEG comment section
- args[0] = "rdjpgcom";
- args[1] = file;
- args[2] = NULL;
-
- p = pexecvp(args[0], args, &pid, "r");
-
- if (p) {
- while (fgets(buf, sizeof(buf), p) != NULL) {
- if (sscanf(buf, GIPFEL_FORMAT, &lo, &la, &he, &dir, &ni, &ti, &sc, &pt) >= 7) {
- set_view_long(lo);
- set_view_lat(la);
- set_view_height(he);
- set_center_angle(dir);
- set_nick_angle(ni);
- set_tilt_angle(ti);
- set_scale(sc);
- set_projection(pt);
-
- break;
- }
- }
- fclose(p);
- waitpid(pid, &status, 0);
- if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
- fprintf(stderr, "%s not found\n", args[0]);
- }
- }
-
- return 0;
+ Fl_Image *new_img;
+ ImageMetaData *md;
+ int ret;
+
+ new_img = new Fl_JPEG_Image(file);
+
+ if (new_img == NULL) {
+ return 1;
+ }
+
+ if (img) {
+ delete img;
+ }
+
+ img = new_img;
+
+ if (img_file) {
+ free(img_file);
+ }
+
+ img_file = strdup(file);
+
+ h(img->h());
+ w(img->w());
+
+ mb = new Fl_Menu_Button(x(),y(),w()+x(),h()+y(),"&popup");
+ mb->type(Fl_Menu_Button::POPUP3);
+ mb->box(FL_NO_BOX);
+ mb->add("Center Peak", 0, (Fl_Callback*) center_cb, this);
+
+ // try to retrieve gipfel data from JPEG meta data
+ md = new ImageMetaData();
+ md->load_image(file, img->w());
+ set_view_long(md->get_longitude());
+ set_view_lat(md->get_latitude());
+ set_view_height(md->get_height());
+ set_center_angle(md->get_direction());
+ set_nick_angle(md->get_nick());
+ set_tilt_angle(md->get_tilt());
+ set_projection((Projection::Projection_t) md->get_projection_type());
+ set_focal_length_35mm(md->get_focal_length_35mm());
+
+ delete md;
+
+ return 0;
}
const char *
@@ -150,605 +115,557 @@ GipfelWidget::get_image_filename() {
int
GipfelWidget::save_image(char *file) {
- char * args[32];
- FILE *p, *out;
- pid_t pid;
- char buf[1024];
- int status;
- size_t n;
- struct stat in_stat, out_stat;
-
- if (img_file == NULL) {
- fprintf(stderr, "Nothing to save\n");
- return 1;
- }
-
- if (stat(img_file, &in_stat) != 0) {
- perror("stat");
- return 1;
- }
-
- if (stat(file, &out_stat) == 0) {
- if (in_stat.st_ino == out_stat.st_ino) {
- fprintf(stderr, "Input image %s and output image %s are the same file\n",
- img_file, file);
- return 1;
- }
- }
-
- out = fopen(file, "w");
- if (out == NULL) {
- perror("fopen");
- return 1;
- }
-
- snprintf(buf, sizeof(buf), GIPFEL_FORMAT,
- get_view_long(),
- get_view_lat(),
- get_view_height(),
- get_center_angle(),
- get_nick_angle(),
- get_tilt_angle(),
- get_scale(),
- (int) get_projection());
-
-// try to save gipfel data in JPEG comment section
- args[0] = "wrjpgcom";
- args[1] = "-replace";
- args[2] = "-comment";
- args[3] = buf;
- args[4] = img_file;
- args[5] = NULL;
-
- p = pexecvp(args[0], args, &pid, "r");
-
- if (p) {
- while ((n = fread(buf, 1, sizeof(buf), p)) != 0) {
- if (fwrite(buf, 1, n, out) != n) {
- perror("fwrite");
- fclose(out);
- fclose(p);
- waitpid(pid, &status, 0);
- }
- }
- fclose(p);
- waitpid(pid, &status, 0);
- if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
- fprintf(stderr, "%s not found\n", args[0]);
- }
- }
-
- fclose(out);
- return 0;
-}
+ ImageMetaData *md;
+ int ret;
+
+ if (img_file == NULL) {
+ fprintf(stderr, "Nothing to save\n");
+ return 1;
+ }
+
+ md = new ImageMetaData();
+ md->set_longitude(get_view_long());
+ md->set_latitude(get_view_lat());
+ md->set_height(get_view_height());
+ md->set_direction(get_center_angle());
+ md->set_nick(get_nick_angle());
+ md->set_tilt(get_tilt_angle());
+ md->set_focal_length_35mm(get_focal_length_35mm());
+ md->set_projection_type((int) get_projection());
+
+ ret = md->save_image(img_file, file);
+ delete md;
+
+ return ret;
+}
int
GipfelWidget::load_data(const char *file) {
- int r;
+ int r;
- r = pan->load_data(file);
- set_labels(pan->get_visible_mountains());
+ r = pan->load_data(file);
+ set_labels(pan->get_visible_mountains());
- return r;
+ return r;
}
int
GipfelWidget::load_track(const char *file) {
- if (track_points) {
- pan->remove_trackpoints();
- track_points->clobber();
- delete track_points;
- }
+ if (track_points) {
+ pan->remove_trackpoints();
+ track_points->clobber();
+ delete track_points;
+ }
- track_points = new Hills();
+ track_points = new Hills();
- if (track_points->load(file) != 0) {
- delete track_points;
- track_points = NULL;
- return 1;
- }
+ if (track_points->load(file) != 0) {
+ delete track_points;
+ track_points = NULL;
+ return 1;
+ }
- for (int i=0; i<track_points->get_num(); i++) {
- track_points->get(i)->flags |= Hill::TRACK_POINT;
- }
+ for (int i=0; i<track_points->get_num(); i++) {
+ track_points->get(i)->flags |= Hill::TRACK_POINT;
+ }
- pan->add_hills(track_points);
- redraw();
-
- return 0;
+ pan->add_hills(track_points);
+ redraw();
+
+ return 0;
}
int
GipfelWidget::set_viewpoint(const char *pos) {
- int r;
+ int r;
- r = pan->set_viewpoint(pos);
- set_labels(pan->get_visible_mountains());
+ r = pan->set_viewpoint(pos);
+ set_labels(pan->get_visible_mountains());
- return r;
+ return r;
}
void
GipfelWidget::set_viewpoint(const Hill *m) {
- pan->set_viewpoint(m);
- set_labels(pan->get_visible_mountains());
+ pan->set_viewpoint(m);
+ set_labels(pan->get_visible_mountains());
}
static void
draw_flag(int x, int y, char *s) {
- Fl_Color c = fl_color();
+ Fl_Color c = fl_color();
+
+ fl_polygon(x, y - 10, x, y - 20, x + 10, y - 15);
+ fl_yxline(x, y, y - 10);
- fl_polygon(x, y - 10, x, y - 20, x + 10, y - 15);
- fl_yxline(x, y, y - 10);
-
- if (s) {
- fl_color(FL_WHITE);
- fl_draw(s, x , y - 12);
- fl_color(c);
- }
+ if (s) {
+ fl_color(FL_WHITE);
+ fl_draw(s, x , y - 12);
+ fl_color(c);
+ }
}
void
GipfelWidget::draw() {
- Hills *mnts;
- Hill *m;
- int center_x = w() / 2;
- int center_y = h() / 2;
- int i;
-
- if (img == NULL) {
- return;
- }
-
- fl_push_clip(x(), y(), w(), h());
- img->draw(x(),y(),w(),h(),0,0);
-
- /* hills */
- fl_font(FL_HELVETICA, 10);
- mnts = pan->get_visible_mountains();
- for (i=0; i<mnts->get_num(); i++) {
- m = mnts->get(i);
-
- if (m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) {
- continue;
- }
-
- if (!show_hidden && (m->flags & Hill::HIDDEN)) {
- continue;
- }
-
- if (m == m1) {
- fl_color(FL_RED);
- draw_flag(center_x + m->x + x(), center_y + m->y + y(), "1");
- } else if (m == m2) {
- fl_color(FL_RED);
- draw_flag(center_x + m->x + x(), center_y + m->y + y(), "2");
- } else if (m->flags & Hill::HIDDEN) {
- fl_color(FL_BLUE);
- } else {
- fl_color(FL_BLACK);
- }
-
- fl_xyline(center_x + m->x + x() - CROSS_SIZE, center_y + m->y + y(), center_x + m->x + x() + CROSS_SIZE);
- fl_yxline(center_x + m->x + x(), center_y + m->y + m->label_y + y() - CROSS_SIZE, center_y + m->y + y() + CROSS_SIZE);
-
- fl_draw(m->name,
- center_x + m->x + x(),
- center_y + m->y + m->label_y + y());
- }
-
- /* markers */
- for (i=0; i<marker->get_num(); i++) {
- m = marker->get(i);
-
- fl_color(FL_GREEN);
- fl_xyline(center_x + m->x + x() - CROSS_SIZE * 2, center_y + m->y + y(), center_x + m->x + x() + CROSS_SIZE * 2);
- fl_yxline(center_x + m->x + x(), center_y + m->y + y() - CROSS_SIZE * 2, center_y + m->y + y() + CROSS_SIZE * 2);
- draw_flag(center_x + m->x + x(), center_y + m->y + y(), NULL);
- }
-
- /* track */
- if (track_points && track_points->get_num() > 0) {
- int last_x, last_y, last_initialized = 0;
-
- for (i=1; i<track_points->get_num(); i++) {
- if (!(track_points->get(i)->flags & Hill::VISIBLE)) {
- continue;
- }
-
- if (track_points->get(i)->flags & Hill::HIDDEN) {
- fl_color(FL_BLUE);
- } else {
- fl_color(FL_RED);
- }
-
- fl_line_style(FL_SOLID|FL_CAP_ROUND|FL_JOIN_ROUND,
- get_rel_track_width(track_points->get(i)));
- if (last_initialized) {
- fl_begin_line();
- fl_vertex(center_x + x() + last_x, center_y + y() + last_y);
- fl_vertex(center_x + x() + track_points->get(i)->x,
- center_y + y() + track_points->get(i)->y);
- fl_end_line();
- }
-
- last_x = track_points->get(i)->x;
- last_y = track_points->get(i)->y;
- last_initialized++;
- }
- fl_line_style(0);
- }
-
- fl_pop_clip();
+ Hills *mnts;
+ Hill *m;
+ int center_x = w() / 2;
+ int center_y = h() / 2;
+ int i;
+
+ if (img == NULL) {
+ return;
+ }
+
+ fl_push_clip(x(), y(), w(), h());
+ img->draw(x(),y(),w(),h(),0,0);
+
+ /* hills */
+ fl_font(FL_HELVETICA, 10);
+ mnts = pan->get_visible_mountains();
+ for (i=0; i<mnts->get_num(); i++) {
+ m = mnts->get(i);
+
+ if (m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) {
+ continue;
+ }
+
+ if (!show_hidden && (m->flags & Hill::HIDDEN)) {
+ continue;
+ }
+
+ if (m == m1) {
+ fl_color(FL_RED);
+ draw_flag(center_x + m->x + x(), center_y + m->y + y(), "1");
+ } else if (m == m2) {
+ fl_color(FL_RED);
+ draw_flag(center_x + m->x + x(), center_y + m->y + y(), "2");
+ } else if (m->flags & Hill::HIDDEN) {
+ fl_color(FL_BLUE);
+ } else {
+ fl_color(FL_BLACK);
+ }
+
+ fl_xyline(center_x + m->x + x() - CROSS_SIZE, center_y + m->y + y(), center_x + m->x + x() + CROSS_SIZE);
+ fl_yxline(center_x + m->x + x(), center_y + m->y + m->label_y + y() - CROSS_SIZE, center_y + m->y + y() + CROSS_SIZE);
+
+ fl_draw(m->name,
+ center_x + m->x + x(),
+ center_y + m->y + m->label_y + y());
+ }
+
+ /* markers */
+ for (i=0; i<marker->get_num(); i++) {
+ m = marker->get(i);
+
+ fl_color(FL_GREEN);
+ fl_xyline(center_x + m->x + x() - CROSS_SIZE * 2, center_y + m->y + y(), center_x + m->x + x() + CROSS_SIZE * 2);
+ fl_yxline(center_x + m->x + x(), center_y + m->y + y() - CROSS_SIZE * 2, center_y + m->y + y() + CROSS_SIZE * 2);
+ draw_flag(center_x + m->x + x(), center_y + m->y + y(), NULL);
+ }
+
+ /* track */
+ if (track_points && track_points->get_num() > 0) {
+ int last_x, last_y, last_initialized = 0;
+
+ for (i=1; i<track_points->get_num(); i++) {
+ if (!(track_points->get(i)->flags & Hill::VISIBLE)) {
+ continue;
+ }
+
+ if (track_points->get(i)->flags & Hill::HIDDEN) {
+ fl_color(FL_BLUE);
+ } else {
+ fl_color(FL_RED);
+ }
+
+ fl_line_style(FL_SOLID|FL_CAP_ROUND|FL_JOIN_ROUND,
+ get_rel_track_width(track_points->get(i)));
+ if (last_initialized) {
+ fl_begin_line();
+ fl_vertex(center_x + x() + last_x, center_y + y() + last_y);
+ fl_vertex(center_x + x() + track_points->get(i)->x,
+ center_y + y() + track_points->get(i)->y);
+ fl_end_line();
+ }
+
+ last_x = track_points->get(i)->x;
+ last_y = track_points->get(i)->y;
+ last_initialized++;
+ }
+ fl_line_style(0);
+ }
+
+ fl_pop_clip();
}
static int
overlap(int m1, int n1, int m2, int n2) {
- return m1 <= n2 && n1 >= m2;
+ return m1 <= n2 && n1 >= m2;
}
void
GipfelWidget::set_labels(Hills *v) {
- int i, j, width, height;
- Hill *m, *n;
-
- fl_font(FL_HELVETICA, 10);
- height = fl_height();
-
- for (i=0; i<v->get_num(); i++) {
- m = v->get(i);
-
- if (m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) {
- continue;
- }
-
- if (!show_hidden && (m->flags & Hill::HIDDEN)) {
- continue;
- }
-
- width = (int) ceilf(fl_width(m->name));
- m->label_x = width;
- m->label_y = 0;
- for (j=0; j < i; j++) {
- n = v->get(j);
-
- if (n->flags & (Hill::DUPLICATE | Hill::TRACK_POINT)) {
- continue;
- }
-
- if (!show_hidden && (n->flags & Hill::HIDDEN)) {
- continue;
- }
-
- // Check for overlapping labels and
- // overlaps between labels and peak markers
- if ((overlap(m->x, m->x + m->label_x, n->x, n->x + n->label_x) &&
- overlap(m->y + m->label_y - height, m->y + m->label_y, n->y + n->label_y - height, n->y + n->label_y)) ||
- (overlap(m->x, m->x + m->label_x, n->x - 2, n->x + 2) &&
- overlap(m->y + m->label_y - height, m->y + m->label_y, n->y - 2, n->y + 2))) {
- m->label_y = n->y + n->label_y - m->y - height - 1;
- }
- }
- }
+ int i, j, width, height;
+ Hill *m, *n;
+
+ fl_font(FL_HELVETICA, 10);
+ height = fl_height();
+
+ for (i=0; i<v->get_num(); i++) {
+ m = v->get(i);
+
+ if (m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) {
+ continue;
+ }
+
+ if (!show_hidden && (m->flags & Hill::HIDDEN)) {
+ continue;
+ }
+
+ width = (int) ceilf(fl_width(m->name));
+ m->label_x = width;
+ m->label_y = 0;
+ for (j=0; j < i; j++) {
+ n = v->get(j);
+
+ if (n->flags & (Hill::DUPLICATE | Hill::TRACK_POINT)) {
+ continue;
+ }
+
+ if (!show_hidden && (n->flags & Hill::HIDDEN)) {
+ continue;
+ }
+
+ // Check for overlapping labels and
+ // overlaps between labels and peak markers
+ if ((overlap(m->x, m->x + m->label_x, n->x, n->x + n->label_x) &&
+ overlap(m->y + m->label_y - height, m->y + m->label_y, n->y + n->label_y - height, n->y + n->label_y)) ||
+ (overlap(m->x, m->x + m->label_x, n->x - 2, n->x + 2) &&
+ overlap(m->y + m->label_y - height, m->y + m->label_y, n->y - 2, n->y + 2))) {
+ m->label_y = n->y + n->label_y - m->y - height - 1;
+ }
+ }
+ }
}
int
GipfelWidget::set_cur_mountain(int m_x, int m_y) {
- Hills *mnts = pan->get_visible_mountains();
- Hill *m;
- int center_x = w() / 2;
- int center_y = h() / 2;
- int i;
-
- for (i=0; i<mnts->get_num(); i++) {
- m = mnts->get(i);
- if (m->flags & (Hill::DUPLICATE | Hill::TRACK_POINT)) {
- continue;
- }
-
- if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 &&
- m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) {
- cur_mountain = m;
- if (m1 != NULL && m2 != NULL) {
- fprintf(stderr, "Resetting m1 and m2\n");
- m1 = NULL;
- m2 = NULL;
- }
-
- if (m1 == NULL) {
- m1 = cur_mountain;
- fprintf(stderr, "m1 = %s\n", m1->name);
- } else if (m2 == NULL) {
- m2 = cur_mountain;
- fprintf(stderr, "m2 = %s\n", m2->name);
- }
+ Hills *mnts = pan->get_visible_mountains();
+ Hill *m;
+ int center_x = w() / 2;
+ int center_y = h() / 2;
+ int i;
+
+ for (i=0; i<mnts->get_num(); i++) {
+ m = mnts->get(i);
+ if (m->flags & (Hill::DUPLICATE | Hill::TRACK_POINT)) {
+ continue;
+ }
- redraw();
- return 0;
- }
- }
+ if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 &&
+ m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) {
+ cur_mountain = m;
+ if (m1 != NULL && m2 != NULL) {
+ fprintf(stderr, "Resetting m1 and m2\n");
+ m1 = NULL;
+ m2 = NULL;
+ }
+
+ if (m1 == NULL) {
+ m1 = cur_mountain;
+ fprintf(stderr, "m1 = %s\n", m1->name);
+ } else if (m2 == NULL) {
+ m2 = cur_mountain;
+ fprintf(stderr, "m2 = %s\n", m2->name);
+ }
+
+ redraw();
+ return 0;
+ }
+ }
- for (i=0; i<marker->get_num(); i++) {
- m = marker->get(i);
+ for (i=0; i<marker->get_num(); i++) {
+ m = marker->get(i);
- if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 &&
- m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) {
- cur_mountain = m;
- redraw();
- return 0;
- }
- }
+ if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 &&
+ m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) {
+ cur_mountain = m;
+ redraw();
+ return 0;
+ }
+ }
- cur_mountain = NULL;
- redraw();
- return 1;
+ cur_mountain = NULL;
+ redraw();
+ return 1;
}
int
GipfelWidget::set_mountain(int m_x, int m_y) {
- int old_x, old_y, old_label_y;
- int center_x = w() / 2;
- int center_y = h() / 2;
-
- if (cur_mountain == NULL) {
- return 1;
- }
-
- old_x = cur_mountain->x;
- old_y = cur_mountain->y;
- old_label_y = cur_mountain->label_y;
-
- cur_mountain->x = m_x - center_x;
- cur_mountain->y = m_y - center_y;
- cur_mountain->label_y = 0;
-
- damage(4, center_x + x() + old_x - 2*CROSS_SIZE - 1,
- center_y + y() + old_y + old_label_y - 2*CROSS_SIZE - 20,
- MAX(20, cur_mountain->label_x) + 2*CROSS_SIZE + 2,
- MAX(20, old_label_y) + 22 );
- damage(4, center_x + x() + cur_mountain->x - 2*CROSS_SIZE - 1,
- center_y + y() + cur_mountain->y + cur_mountain->label_y - 2*CROSS_SIZE - 20,
- MAX(20, cur_mountain->label_x) + 2*CROSS_SIZE + 2,
- MAX(20, cur_mountain->label_y) + 22 );
-
- return 0;
+ int old_x, old_y, old_label_y;
+ int center_x = w() / 2;
+ int center_y = h() / 2;
+
+ if (cur_mountain == NULL) {
+ return 1;
+ }
+
+ old_x = cur_mountain->x;
+ old_y = cur_mountain->y;
+ old_label_y = cur_mountain->label_y;
+
+ cur_mountain->x = m_x - center_x;
+ cur_mountain->y = m_y - center_y;
+ cur_mountain->label_y = 0;
+
+ damage(4, center_x + x() + old_x - 2*CROSS_SIZE - 1,
+ center_y + y() + old_y + old_label_y - 2*CROSS_SIZE - 20,
+ MAX(20, cur_mountain->label_x) + 2*CROSS_SIZE + 2,
+ MAX(20, old_label_y) + 22 );
+ damage(4, center_x + x() + cur_mountain->x - 2*CROSS_SIZE - 1,
+ center_y + y() + cur_mountain->y + cur_mountain->label_y - 2*CROSS_SIZE - 20,
+ MAX(20, cur_mountain->label_x) + 2*CROSS_SIZE + 2,
+ MAX(20, cur_mountain->label_y) + 22 );
+
+ return 0;
}
void
GipfelWidget::set_center_angle(double a) {
- pan->set_center_angle(a);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_center_angle(a);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
void
GipfelWidget::set_nick_angle(double a) {
- pan->set_nick_angle(a);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_nick_angle(a);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
void
GipfelWidget::set_tilt_angle(double a) {
- pan->set_tilt_angle(a);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_tilt_angle(a);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
void
-GipfelWidget::set_scale(double s) {
- pan->set_scale(s);
- set_labels(pan->get_visible_mountains());
- redraw();
+GipfelWidget::set_focal_length_35mm(double s) {
+ pan->set_scale(s * (double) img->w() / 35.0);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
void
GipfelWidget::set_projection(Projection::Projection_t p) {
- pan->set_projection(p);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_projection(p);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
Projection::Projection_t
GipfelWidget::get_projection() {
- return pan->get_projection();
+ return pan->get_projection();
}
double
GipfelWidget::get_center_angle() {
- return pan->get_center_angle();
+ return pan->get_center_angle();
}
double
GipfelWidget::get_nick_angle() {
- return pan->get_nick_angle();
+ return pan->get_nick_angle();
}
double
GipfelWidget::get_tilt_angle() {
- return pan->get_tilt_angle();
+ return pan->get_tilt_angle();
}
double
-GipfelWidget::get_scale() {
- return pan->get_scale();
+GipfelWidget::get_focal_length_35mm() {
+ return pan->get_scale() * 35.0 / (double) img->w();
}
double
GipfelWidget::get_height_dist_ratio() {
- return pan->get_height_dist_ratio();
+ return pan->get_height_dist_ratio();
}
const char *
GipfelWidget::get_viewpoint() {
- return pan->get_viewpoint();
+ return pan->get_viewpoint();
}
double
GipfelWidget::get_view_lat() {
- return pan->get_view_lat();
+ return pan->get_view_lat();
}
double
GipfelWidget::get_view_long() {
- return pan->get_view_long();
+ return pan->get_view_long();
}
double
GipfelWidget::get_view_height() {
- return pan->get_view_height();
+ return pan->get_view_height();
}
void
GipfelWidget::center() {
- Hill *m = choose_hill(pan->get_close_mountains(), "Center Peak");
- if (m) {
- set_center_angle(m->alph / deg2rad);
- if (!m1 || (m1 && m2)) {
- m1 = m;
- } else {
- m2 = m;
- }
- }
+ Hill *m = choose_hill(pan->get_close_mountains(), "Center Peak");
+ if (m) {
+ set_center_angle(m->alph / deg2rad);
+ if (!m1 || (m1 && m2)) {
+ m1 = m;
+ } else {
+ m2 = m;
+ }
+ }
}
static void
center_cb(Fl_Widget *o, void *f) {
- ((GipfelWidget*)f)->center();
+ ((GipfelWidget*)f)->center();
}
void
GipfelWidget::set_height_dist_ratio(double r) {
- pan->set_height_dist_ratio(r);
- set_labels(pan->get_visible_mountains());
-
- redraw();
+ pan->set_height_dist_ratio(r);
+ set_labels(pan->get_visible_mountains());
+
+ redraw();
}
void
GipfelWidget::set_hide_value(double h) {
- pan->set_hide_value(h);
- set_labels(pan->get_visible_mountains());
-
- redraw();
+ pan->set_hide_value(h);
+ set_labels(pan->get_visible_mountains());
+
+ redraw();
}
void
GipfelWidget::set_show_hidden(int h) {
- show_hidden = h;
- set_labels(pan->get_visible_mountains());
-
- redraw();
+ show_hidden = h;
+ set_labels(pan->get_visible_mountains());
+
+ redraw();
}
void
GipfelWidget::set_view_lat(double v) {
- pan->set_view_lat(v);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_view_lat(v);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
void
GipfelWidget::set_view_long(double v) {
- pan->set_view_long(v);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_view_long(v);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
void
GipfelWidget::set_view_height(double v) {
- pan->set_view_height(v);
- set_labels(pan->get_visible_mountains());
- redraw();
+ pan->set_view_height(v);
+ set_labels(pan->get_visible_mountains());
+ redraw();
}
Hills*
GipfelWidget::get_mountains() {
- return pan->get_mountains();
+ return pan->get_mountains();
}
int
GipfelWidget::comp_params() {
- if (m1 == NULL || m2 == NULL) {
- fprintf(stderr, "Position m1 and m2 first.\n");
- return 1;
- }
- fl_cursor(FL_CURSOR_WAIT);
- pan->comp_params(m1, m2);
- set_labels(pan->get_visible_mountains());
- redraw();
- fl_cursor(FL_CURSOR_DEFAULT);
+ if (m1 == NULL || m2 == NULL) {
+ fprintf(stderr, "Position m1 and m2 first.\n");
+ return 1;
+ }
+ fl_cursor(FL_CURSOR_WAIT);
+ pan->comp_params(m1, m2);
+ set_labels(pan->get_visible_mountains());
+ redraw();
+ fl_cursor(FL_CURSOR_DEFAULT);
}
int
GipfelWidget::guess() {
- if (m1 == NULL) {
- fprintf(stderr, "Position m1 first.\n");
- return 1;
- }
- fl_cursor(FL_CURSOR_WAIT);
- pan->guess(marker, m1);
- set_labels(pan->get_visible_mountains());
- redraw();
- fl_cursor(FL_CURSOR_DEFAULT);
+ if (m1 == NULL) {
+ fprintf(stderr, "Position m1 first.\n");
+ return 1;
+ }
+ fl_cursor(FL_CURSOR_WAIT);
+ pan->guess(marker, m1);
+ set_labels(pan->get_visible_mountains());
+ redraw();
+ fl_cursor(FL_CURSOR_DEFAULT);
}
int
GipfelWidget::update() {
- redraw();
- Fl::wait(1.0);
+ redraw();
+ Fl::wait(1.0);
}
int
GipfelWidget::get_rel_track_width(Hill *m) {
- double dist = pan->get_real_distance(m);
+ double dist = pan->get_real_distance(m);
- return MAX((pan->get_scale() * track_width) / (dist * 10.0), 1.0);
+ return MAX((pan->get_scale() * track_width) / (dist * 10.0), 1.0);
}
void
GipfelWidget::set_track_width(double w) {
- track_width = w;
- redraw();
+ track_width = w;
+ 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();
- set_cur_mountain(mark_x, mark_y);
-
- Fl::focus(this);
- return 1;
- }
- break;
- case FL_DRAG:
- set_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;
+ 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();
+ set_cur_mountain(mark_x, mark_y);
+
+ Fl::focus(this);
+ return 1;
+ }
+ break;
+ case FL_DRAG:
+ set_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;
}
int
GipfelWidget::get_pixel(double a_view, double a_nick,
- uchar *r, uchar *g, uchar *b) {
+ uchar *r, uchar *g, uchar *b) {
double px, py;
@@ -761,7 +678,7 @@ GipfelWidget::get_pixel(double a_view, double a_nick,
}
return get_pixel_bilinear(img, px + ((double) img->w()) / 2.0,
- py + ((double) img->h()) / 2.0, r, g, b);
+ py + ((double) img->h()) / 2.0, r, g, b);
}
int
@@ -816,39 +733,39 @@ GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y,
int
GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
uchar *r, uchar *g, uchar *b) {
- if ( img->d() == 0 ) {
- return 1;
- }
-
- 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
- const char *buf = img->data()[0];
- switch ( img->d() ) {
- case 1: { // 8bit
- *r = *g = *b = *(buf+index);
- break;
- }
- case 3: // 24bit
- *r = *(buf+index+0);
- *g = *(buf+index+1);
- *b = *(buf+index+2);
- break;
- default: // ??
- printf("Not supported: chans=%d\n", img->d());
- return 1;
- }
- break;
- }
- default: // ?? pixmap, bit vals
- printf("Not supported: count=%d\n", img->count());
- return 1;
- }
-
- return 0;
+ if ( img->d() == 0 ) {
+ return 1;
+ }
-}
+ 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
+ const char *buf = img->data()[0];
+ switch (img->d())
+ {
+ case 1:
+ *r = *g = *b = *(buf+index);
+ break;
+ case 3: // 24bit
+ *r = *(buf+index+0);
+ *g = *(buf+index+1);
+ *b = *(buf+index+2);
+ break;
+ default: // ??
+ printf("Not supported: chans=%d\n", img->d());
+ return 1;
+ }
+ break;
+ }
+ default: // ?? pixmap, bit vals
+ printf("Not supported: count=%d\n", img->count());
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/src/Hill.H b/src/Hill.H
index 13d7d64..2e95def 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef HILL_H
#define HILL_H
@@ -24,69 +11,69 @@
class Hill;
class Hill {
- private:
-
- public:
- typedef enum {
- DUPLICATE = 0x01,
- TRACK_POINT = 0x02,
- VISIBLE = 0x04,
- HIDDEN = 0x08
- } flags_t;
-
- double phi, lam;
- double height;
- double alph;
- double a_view;
- double a_nick;
- double dist;
- int x, y;
- int label_x, label_y;
- char *name;
- int flags;
-
- Hill(const char *n, double p, double l, double h);
-
- Hill(const Hill& h);
-
- Hill(int x_tmp, int y_tmp);
-
- ~Hill();
+ private:
+
+ public:
+ typedef enum {
+ DUPLICATE = 0x01,
+ TRACK_POINT = 0x02,
+ VISIBLE = 0x04,
+ HIDDEN = 0x08
+ } flags_t;
+
+ double phi, lam;
+ double height;
+ double alph;
+ double a_view;
+ double a_nick;
+ double dist;
+ int x, y;
+ int label_x, label_y;
+ char *name;
+ int flags;
+
+ Hill(const char *n, double p, double l, double h);
+
+ Hill(const Hill& h);
+
+ Hill(int x_tmp, int y_tmp);
+
+ ~Hill();
};
class Hills {
- private:
- int num, cap;
- Hill **m;
+ private:
+ int num, cap;
+ Hill **m;
+
+ public:
+ Hills();
+
+ Hills(const Hills *h);
- public:
- Hills();
+ ~Hills();
- Hills(const Hills *h);
+ int load(const char *file);
- ~Hills();
+ void mark_duplicates(double dist);
- int load(const char *file);
+ void add(Hill *m);
- void mark_duplicates(double dist);
+ void add(Hills *h);
- void add(Hill *m);
+ void sort_phi();
- void add(Hills *h);
+ void sort_name();
- void sort_phi();
+ void sort();
- void sort_name();
+ void clear();
- void sort();
-
- void clear();
+ void clobber();
- void clobber();
+ int get_num();
- int get_num();
-
- Hill *get(int n);
+ Hill *get(int n);
};
#endif
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 277cefe..d5ce1f6 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdlib.h>
#include <stdio.h>
@@ -27,284 +14,284 @@
static double pi_d, deg2rad;
Hill::Hill(const char *n, double p, double l, double h) {
- name = strdup(n);
- phi = p;
- lam = l;
- height = h;
- alph = 0.0;
- x = 0;
- y = 0;
- flags = 0;
+ name = strdup(n);
+ phi = p;
+ lam = l;
+ height = h;
+ alph = 0.0;
+ x = 0;
+ y = 0;
+ flags = 0;
}
Hill::Hill(const Hill& h) {
- name = strdup(h.name);
- phi = h.phi;
- lam = h.lam;
- height = h.height;
- alph = h.alph;
- a_view = h.a_view;
- a_view = h.a_view;
- dist = h.dist;
- x = h.x;
- y = h.y;
- label_x = h.label_x;
- label_y = h.label_y;
- flags = h.flags;
+ name = strdup(h.name);
+ phi = h.phi;
+ lam = h.lam;
+ height = h.height;
+ alph = h.alph;
+ a_view = h.a_view;
+ a_view = h.a_view;
+ dist = h.dist;
+ x = h.x;
+ y = h.y;
+ label_x = h.label_x;
+ label_y = h.label_y;
+ flags = h.flags;
}
Hill::Hill(int x_tmp, int y_tmp) {
- name = NULL;
- phi = 0.0;
- lam = 0.0;
- height = 0.0;
- alph = 0.0;
- x = x_tmp;
- y = y_tmp;
+ name = NULL;
+ phi = 0.0;
+ lam = 0.0;
+ height = 0.0;
+ alph = 0.0;
+ x = x_tmp;
+ y = y_tmp;
}
Hill::~Hill() {
- if (name) {
- free(name);
- }
+ if (name) {
+ free(name);
+ }
}
Hills::Hills() {
- num = 0;
- cap = 100;
- m = (Hill **) malloc(cap * sizeof(Hill *));
+ num = 0;
+ cap = 100;
+ m = (Hill **) malloc(cap * sizeof(Hill *));
- pi_d = asin(1.0) * 2.0;
- deg2rad = pi_d / 180.0;
+ pi_d = asin(1.0) * 2.0;
+ deg2rad = pi_d / 180.0;
}
Hills::Hills(const Hills *h) {
- num = h->num;
- cap = h->cap;
- m = (Hill **) malloc(cap * sizeof(Hill *));
- memcpy(m, h->m, cap * sizeof(Hill *));
+ num = h->num;
+ cap = h->cap;
+ m = (Hill **) malloc(cap * sizeof(Hill *));
+ memcpy(m, h->m, cap * sizeof(Hill *));
- pi_d = asin(1.0) * 2.0;
- deg2rad = pi_d / 180.0;
+ pi_d = asin(1.0) * 2.0;
+ deg2rad = pi_d / 180.0;
}
int
Hills::load(const char *file) {
- FILE *fp;
- char buf[4000];
- char *vals[10];
- char **ap, *bp;
- double phi, lam, height;
- Hill *m;
- int n;
-
- fp = fopen(file, "r");
- if (!fp) {
- perror("fopen");
- return 1;
- }
-
- while (fgets(buf, sizeof(buf), fp)) {
- bp = buf;
- memset(vals, 0, sizeof(vals));
- n = 0;
- for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;) {
- n++;
- if (++ap >= &vals[10]) {
- break;
- }
- }
-
- // standard format including name and description
- if (n == 6 && vals[1] && vals [3] && vals[4] && vals[5]) {
- phi = atof(vals[3]) * deg2rad;
- lam = atof(vals[4]) * deg2rad;
- height = atof(vals[5]);
-
- m = new Hill(vals[1], phi, lam, height);
-
- add(m);
- // track point format
- } else if (n == 3 && vals[0] && vals[1] && vals[2]) {
- phi = atof(vals[0]) * deg2rad;
- lam = atof(vals[1]) * deg2rad;
- height = atof(vals[2]);
-
- m = new Hill("", phi, lam, height);
-
- add(m);
- }
- }
-
- fclose(fp);
-
- return 0;
+ FILE *fp;
+ char buf[4000];
+ char *vals[10];
+ char **ap, *bp;
+ double phi, lam, height;
+ Hill *m;
+ int n;
+
+ fp = fopen(file, "r");
+ if (!fp) {
+ perror("fopen");
+ return 1;
+ }
+
+ while (fgets(buf, sizeof(buf), fp)) {
+ bp = buf;
+ memset(vals, 0, sizeof(vals));
+ n = 0;
+ for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;) {
+ n++;
+ if (++ap >= &vals[10]) {
+ break;
+ }
+ }
+
+ // standard format including name and description
+ if (n == 6 && vals[1] && vals [3] && vals[4] && vals[5]) {
+ phi = atof(vals[3]) * deg2rad;
+ lam = atof(vals[4]) * deg2rad;
+ height = atof(vals[5]);
+
+ m = new Hill(vals[1], phi, lam, height);
+
+ add(m);
+ // track point format
+ } else if (n == 3 && vals[0] && vals[1] && vals[2]) {
+ phi = atof(vals[0]) * deg2rad;
+ lam = atof(vals[1]) * deg2rad;
+ height = atof(vals[2]);
+
+ m = new Hill("", phi, lam, height);
+
+ add(m);
+ }
+ }
+
+ fclose(fp);
+
+ return 0;
}
void Hills::mark_duplicates(double dist) {
- Hill *m, *n;
- int i, j;
-
- sort_phi();
-
- for(i=0; i<get_num();i++) {
- m = get(i);
-
- if (m->flags & Hill::TRACK_POINT) {
- continue;
- }
-
- if (m) {
- j = i + 1;
- n = get(j);
- while (n && fabs(n->phi - m->phi) <= dist) {
- if (! n->flags & Hill::DUPLICATE) {
- if (fabs(n->lam - m->lam) <= dist &&
- fabs(n->height - m->height) <= 50.0 ) {
- n->flags |= Hill::DUPLICATE;
- }
- }
- j = j + 1;
- n = get(j);
- }
- }
- }
+ Hill *m, *n;
+ int i, j;
+
+ sort_phi();
+
+ for(i=0; i<get_num();i++) {
+ m = get(i);
+
+ if (m->flags & Hill::TRACK_POINT) {
+ continue;
+ }
+
+ if (m) {
+ j = i + 1;
+ n = get(j);
+ while (n && fabs(n->phi - m->phi) <= dist) {
+ if (! n->flags & Hill::DUPLICATE) {
+ if (fabs(n->lam - m->lam) <= dist &&
+ fabs(n->height - m->height) <= 50.0 ) {
+ n->flags |= Hill::DUPLICATE;
+ }
+ }
+ j = j + 1;
+ n = get(j);
+ }
+ }
+ }
}
Hills::~Hills() {
- if (m) {
- free(m);
- }
+ if (m) {
+ free(m);
+ }
}
void
Hills::add(Hill *m1) {
- if (num >= cap) {
- cap = cap?cap * 2:100;
- m = (Hill **) realloc(m, cap * sizeof(Hill *));
- }
+ if (num >= cap) {
+ cap = cap?cap * 2:100;
+ m = (Hill **) realloc(m, cap * sizeof(Hill *));
+ }
- m[num++] = m1;
+ m[num++] = m1;
}
void
Hills::add(Hills *h) {
- for(int i=0; i<h->get_num(); i++) {
- add(h->get(i));
- }
+ for(int i=0; i<h->get_num(); i++) {
+ add(h->get(i));
+ }
}
static int
comp_mountains(const void *n1, const void *n2) {
- Hill *m1 = *(Hill **)n1;
- Hill *m2 = *(Hill **)n2;
-
- if (m1 && m2) {
- if (m1->alph < m2->alph) {
- return 1;
- } else if (m1->alph > m2->alph) {
- return -1;
- } else {
- return 0;
- }
- } else {
- return 0;
- }
+ Hill *m1 = *(Hill **)n1;
+ Hill *m2 = *(Hill **)n2;
+
+ if (m1 && m2) {
+ if (m1->alph < m2->alph) {
+ return 1;
+ } else if (m1->alph > m2->alph) {
+ return -1;
+ } else {
+ return 0;
+ }
+ } else {
+ return 0;
+ }
}
static int
comp_mountains_phi(const void *n1, const void *n2) {
- Hill *m1 = *(Hill **)n1;
- Hill *m2 = *(Hill **)n2;
-
- if (m1 && m2) {
- if (m1->phi < m2->phi) {
- return 1;
- } else if (m1->phi > m2->phi) {
- return -1;
- } else {
- return 0;
- }
- } else {
- return 0;
- }
+ Hill *m1 = *(Hill **)n1;
+ Hill *m2 = *(Hill **)n2;
+
+ if (m1 && m2) {
+ if (m1->phi < m2->phi) {
+ return 1;
+ } else if (m1->phi > m2->phi) {
+ return -1;
+ } else {
+ return 0;
+ }
+ } else {
+ return 0;
+ }
}
static int
comp_mountains_name(const void *n1, const void *n2) {
- Hill *m1 = *(Hill **)n1;
- Hill *m2 = *(Hill **)n2;
-
- if (m1 && m2) {
- return strcasecmp(m1->name, m2->name);
- } else {
- return 0;
- }
+ Hill *m1 = *(Hill **)n1;
+ Hill *m2 = *(Hill **)n2;
+
+ if (m1 && m2) {
+ return strcasecmp(m1->name, m2->name);
+ } else {
+ return 0;
+ }
}
void
Hills::sort() {
- if (!m) {
- return;
- }
+ if (!m) {
+ return;
+ }
- qsort(m, num, sizeof(Hill *), comp_mountains);
+ qsort(m, num, sizeof(Hill *), comp_mountains);
}
void
Hills::sort_phi() {
- if (!m) {
- return;
- }
+ if (!m) {
+ return;
+ }
- qsort(m, num, sizeof(Hill *), comp_mountains_phi);
+ qsort(m, num, sizeof(Hill *), comp_mountains_phi);
}
void
Hills::sort_name() {
- if (!m) {
- return;
- }
+ if (!m) {
+ return;
+ }
- qsort(m, num, sizeof(Hill *), comp_mountains_name);
+ qsort(m, num, sizeof(Hill *), comp_mountains_name);
}
void
Hills::clear() {
- if (m) {
- free(m);
- m = NULL;
- }
- cap = 0;
- num = 0;
+ if (m) {
+ free(m);
+ m = NULL;
+ }
+ cap = 0;
+ num = 0;
}
void
Hills::clobber() {
- int i;
-
- for(i=0; i<get_num();i++) {
- if (get(i)) {
- delete(get(i));
- }
- }
-
- clear();
+ int i;
+
+ for(i=0; i<get_num();i++) {
+ if (get(i)) {
+ delete(get(i));
+ }
+ }
+
+ clear();
}
int
Hills::get_num() {
- return num;
+ return num;
}
Hill *
Hills::get(int n) {
- if (n < 0 || n >= num) {
- return NULL;
- } else {
- return m[n];
- }
+ if (n < 0 || n >= num) {
+ return NULL;
+ } else {
+ return m[n];
+ }
}
diff --git a/src/ImageMetaData.H b/src/ImageMetaData.H
new file mode 100644
index 0000000..5796964
--- /dev/null
+++ b/src/ImageMetaData.H
@@ -0,0 +1,50 @@
+//
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
+//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
+
+#ifndef IMAGE_META_DATA_H
+#define IMAGE_META_DATA_H
+
+class ImageMetaData {
+ private:
+ double longitude;
+ double latitude;
+ double height;
+ double direction;
+ double nick;
+ double tilt;
+ double focal_length_35mm;
+ double scale;
+ int projection_type;
+
+ int load_image_jpgcom(char *name);
+ int save_image_jpgcom(char *in_img, char *out_img);
+ int load_image_exif(char *name);
+
+ public:
+ ImageMetaData();
+
+ int load_image(char *name, int img_width);
+ int save_image(char *in_img, char *out_img);
+
+ double get_longitude();
+ double get_latitude();
+ double get_height();
+ double get_direction();
+ double get_nick();
+ double get_tilt();
+ double get_focal_length_35mm();
+ int get_projection_type();
+
+ void set_longitude(double v);
+ void set_latitude(double v);
+ void set_height(double v);
+ void set_direction(double v);
+ void set_nick(double v);
+ void set_tilt(double v);
+ void set_focal_length_35mm(double v);
+ void set_projection_type(int v);
+};
+#endif
diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx
new file mode 100644
index 0000000..6519239
--- /dev/null
+++ b/src/ImageMetaData.cxx
@@ -0,0 +1,340 @@
+//
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
+//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+
+#include "util.h"
+
+#include "ImageMetaData.H"
+
+ImageMetaData::ImageMetaData() {
+ longitude = NAN;
+ latitude = NAN;
+ height = 0.0;
+ direction = 0.0;
+ nick = 0.0;
+ tilt = 0.0;
+ focal_length_35mm = 35.0;
+ scale = NAN;
+ projection_type = 0;
+}
+
+
+int
+ImageMetaData::load_image(char *name, int img_width) {
+ int ret;
+
+ ret = load_image_jpgcom(name);
+ if (ret == 2) { // old format
+ focal_length_35mm = scale * 35.0 / (double) img_width;
+ } else if (ret == 1) { // get reasonable defaults from exif data
+ ret = load_image_exif(name);
+ }
+
+ return ret;
+}
+
+int
+ImageMetaData::save_image(char *in_img, char *out_img) {
+ return save_image_jpgcom(in_img, out_img);
+}
+
+static double
+degminsecstr2double(char *val) {
+ double ret, dv;
+
+ ret = 0.0;
+ for (dv=1.0; dv <= 3600.0; dv = dv * 60.0) {
+ ret = ret + atof(val) / dv;
+ val = strchr(val, ',');
+ if (!val || val[1] == '\0') {
+ break;
+ } else {
+ val++;
+ }
+ }
+
+ return ret;
+}
+
+#define EXIF_FOCAL_LENGTH_IN_35MM_FILM 0xa405
+#define EXIF_GPS_LATIITUDE 0x0002
+#define EXIF_GPS_LONGITUDE 0x0004
+#define EXIF_GPS_ALTITUDE 0x0006
+
+int
+ImageMetaData::load_image_exif(char *name) {
+ char * args[32];
+ FILE *p;
+ pid_t pid;
+ int status;
+ char buf[1024];
+ char val[1024];
+ int id;
+
+ args[0] = "exif";
+ args[1] = "-i";
+ args[2] = "-m";
+ args[3] = name;
+ args[4] = NULL;
+
+ p = pexecvp(args[0], args, &pid, "r");
+
+ if (p) {
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ if (sscanf(buf, "%x\t%[^\n]\n", &id, val) != 2) {
+ continue;
+ }
+
+ switch(id) {
+ case EXIF_FOCAL_LENGTH_IN_35MM_FILM:
+ focal_length_35mm = atof(val);
+ break;
+ case EXIF_GPS_LONGITUDE:
+ longitude = degminsecstr2double(val);
+ break;
+ case EXIF_GPS_LATIITUDE:
+ latitude = degminsecstr2double(val);
+ break;
+ case EXIF_GPS_ALTITUDE:
+ height = atof(val);
+ break;
+ }
+ }
+ }
+
+ fclose(p);
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
+ fprintf(stderr, "%s not found\n", args[0]);
+ }
+
+ return 0;
+}
+
+
+#define GIPFEL_FORMAT_1 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, scale %lf, projection type %d"
+#define GIPFEL_FORMAT_2 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, focal_length_35mm %lf, projection type %d"
+
+int
+ImageMetaData::load_image_jpgcom(char *name) {
+ char * args[32];
+ FILE *p;
+ pid_t pid;
+ int status;
+ char buf[1024];
+ double lo, la, he, dir, ni, ti, fr;
+ int pt;
+ int ret = 1;
+
+ args[0] = "rdjpgcom";
+ args[1] = name;
+ args[2] = NULL;
+
+ p = pexecvp(args[0], args, &pid, "r");
+
+ if (p) {
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ if (sscanf(buf, GIPFEL_FORMAT_2,
+ &lo, &la, &he, &dir, &ni, &ti, &fr, &pt) >= 7) {
+
+ longitude = lo;
+ latitude = la;
+ height = he;
+ direction = dir;
+ nick = ni;
+ tilt = ti;
+ focal_length_35mm = fr;
+ projection_type = pt;
+
+ ret = 0;
+
+ break;
+ } else if (sscanf(buf, GIPFEL_FORMAT_1,
+ &lo, &la, &he, &dir, &ni, &ti, &fr, &pt) >= 7) {
+
+ longitude = lo;
+ latitude = la;
+ height = he;
+ direction = dir;
+ nick = ni;
+ tilt = ti;
+ scale = fr;
+ projection_type = pt;
+
+ ret = 2; // special return value for compatibility with
+ // old format
+
+ break;
+ }
+ }
+
+ fclose(p);
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
+ fprintf(stderr, "%s not found\n", args[0]);
+ }
+ }
+
+ return ret;
+}
+
+int
+ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) {
+ char * args[32];
+ FILE *p, *out;
+ pid_t pid;
+ char buf[1024];
+ int status;
+ size_t n;
+ struct stat in_stat, out_stat;
+
+ if (stat(in_img, &in_stat) != 0) {
+ perror("stat");
+ return 1;
+ }
+
+ if (stat(out_img, &out_stat) == 0) {
+ if (in_stat.st_ino == out_stat.st_ino) {
+ fprintf(stderr, "Input image %s and output image %s are the same file\n",
+ in_img, out_img);
+ return 1;
+ }
+ }
+
+ out = fopen(out_img, "w");
+ if (out == NULL) {
+ perror("fopen");
+ return 1;
+ }
+
+ snprintf(buf, sizeof(buf), GIPFEL_FORMAT_2,
+ longitude,
+ latitude,
+ height,
+ direction,
+ nick,
+ tilt,
+ focal_length_35mm,
+ projection_type);
+
+ // try to save gipfel data in JPEG comment section
+ args[0] = "wrjpgcom";
+ args[1] = "-replace";
+ args[2] = "-comment";
+ args[3] = buf;
+ args[4] = in_img;
+ args[5] = NULL;
+
+ p = pexecvp(args[0], args, &pid, "r");
+
+ if (p) {
+ while ((n = fread(buf, 1, sizeof(buf), p)) != 0) {
+ if (fwrite(buf, 1, n, out) != n) {
+ perror("fwrite");
+ fclose(out);
+ fclose(p);
+ waitpid(pid, &status, 0);
+ }
+ }
+ fclose(p);
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
+ fprintf(stderr, "%s not found\n", args[0]);
+ }
+ }
+
+ fclose(out);
+ return 0;
+}
+
+
+double
+ImageMetaData::get_longitude() {
+ return longitude;
+}
+
+double
+ImageMetaData::get_latitude() {
+ return latitude;
+}
+
+double
+ImageMetaData::get_height() {
+ return height;
+}
+
+double
+ImageMetaData::get_direction() {
+ return direction;
+}
+
+double
+ImageMetaData::get_nick() {
+ return nick;
+}
+
+double
+ImageMetaData::get_tilt() {
+ return tilt;
+}
+
+double
+ImageMetaData::get_focal_length_35mm() {
+ return focal_length_35mm;
+}
+
+int
+ImageMetaData::get_projection_type() {
+ return projection_type;
+}
+
+void
+ImageMetaData::set_longitude(double v) {
+ longitude = v;
+}
+
+void
+ImageMetaData::set_latitude(double v) {
+ latitude = v;
+}
+
+void
+ImageMetaData::set_height(double v) {
+ height = v;
+}
+
+void
+ImageMetaData::set_direction(double v) {
+ direction = v;
+}
+
+void
+ImageMetaData::set_nick(double v) {
+ nick = v;
+}
+
+void
+ImageMetaData::set_tilt(double v) {
+ tilt = v;
+}
+
+void
+ImageMetaData::set_focal_length_35mm(double v) {
+ focal_length_35mm = v;
+}
+
+void
+ImageMetaData::set_projection_type(int v) {
+ projection_type = v;
+}
diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H
index 50570e5..b3554c8 100644
--- a/src/JPEGOutputImage.H
+++ b/src/JPEGOutputImage.H
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef JPEGOUTPUTIMAGE_H
#define JPEGOUTPUTIMAGE_H
diff --git a/src/JPEGOutputImage.cxx b/src/JPEGOutputImage.cxx
index 3f7fd11..6e685d0 100644
--- a/src/JPEGOutputImage.cxx
+++ b/src/JPEGOutputImage.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/Makefile.am b/src/Makefile.am
index 5577090..8ba69c1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,8 @@ gipfel_SOURCES = \
OutputImage.cxx \
JPEGOutputImage.cxx \
TIFFOutputImage.cxx \
- PreviewOutputImage.cxx
+ PreviewOutputImage.cxx \
+ ImageMetaData.cxx
noinst_HEADERS = \
GipfelWidget.H \
@@ -34,4 +35,5 @@ noinst_HEADERS = \
JPEGOutputImage.H \
TIFFOutputImage.H \
PreviewOutputImage.H \
+ ImageMetaData.H \
util.h
diff --git a/src/OutputImage.H b/src/OutputImage.H
index 8792eb6..9be72c5 100644
--- a/src/OutputImage.H
+++ b/src/OutputImage.H
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef OUTPUTIMAGE_H
#define OUTPUTIMAGE_H
diff --git a/src/OutputImage.cxx b/src/OutputImage.cxx
index f2e7296..ddf8e14 100644
--- a/src/OutputImage.cxx
+++ b/src/OutputImage.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/Panorama.H b/src/Panorama.H
index a538809..81cdf8e 100644
--- a/src/Panorama.H
+++ b/src/Panorama.H
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef PANORAMA_H
#define PANORAMA_H
@@ -27,122 +14,122 @@
class Panorama {
- private:
- double view_phi, view_lam, view_height;
- char *view_name;
- double height_dist_ratio;
- double view_angle;
- double hide_value;
- Hills *mountains;
- Hills *close_mountains;
- Hills *visible_mountains;
- ViewParams parms;
- Projection::Projection *proj;
- Projection::Projection_t projection_type;
-
- Hill * get_pos(const char *name);
+ private:
+ double view_phi, view_lam, view_height;
+ char *view_name;
+ double height_dist_ratio;
+ double view_angle;
+ double hide_value;
+ Hills *mountains;
+ Hills *close_mountains;
+ Hills *visible_mountains;
+ ViewParams parms;
+ Projection::Projection *proj;
+ Projection::Projection_t projection_type;
+
+ Hill * get_pos(const char *name);
+
+ void update_angles();
+
+ void update_coordinates();
+
+ void update_close_mountains();
+
+ void update_visible_mountains();
- void update_angles();
+ void mark_hidden(Hills *hills);
- void update_coordinates();
+ double distance(double phi, double lam);
- void update_close_mountains();
+ double sin_alpha(double lam, double phi, double c);
- void update_visible_mountains();
-
- void mark_hidden(Hills *hills);
+ double cos_alpha(double phi, double c);
- double distance(double phi, double lam);
+ double alpha(double phi, double lam);
- double sin_alpha(double lam, double phi, double c);
+ double nick(double dist, double height);
- double cos_alpha(double phi, double c);
+ double comp_center_angle(double alph_a, double alph_b, double d1, double d2);
- double alpha(double phi, double lam);
+ double comp_scale(double alph_a, double alph_b, double d1, double d2);
- double nick(double dist, double height);
-
- double comp_center_angle(double alph_a, double alph_b, double d1, double d2);
+ int get_matrix(double m[]);
- double comp_scale(double alph_a, double alph_b, double d1, double d2);
+ int optimize(Hill *m1, Hill *m2);
- int get_matrix(double m[]);
+ double get_value(Hills *p);
- int optimize(Hill *m1, Hill *m2);
+ double pi_d, deg2rad;
- double get_value(Hills *p);
+ public:
+ Panorama();
- double pi_d, deg2rad;
+ ~Panorama();
- public:
- Panorama();
+ int load_data(const char *name);
- ~Panorama();
-
- int load_data(const char *name);
+ void add_hills(Hills *h);
- void add_hills(Hills *h);
+ void remove_trackpoints();
- void remove_trackpoints();
+ int set_viewpoint(const char *pos);
- int set_viewpoint(const char *pos);
+ void set_viewpoint(const Hill *m);
- void set_viewpoint(const Hill *m);
+ void set_height_dist_ratio(double r);
- void set_height_dist_ratio(double r);
+ void set_hide_value(double h);
- void set_hide_value(double h);
+ Hills * get_mountains();
- Hills * get_mountains();
+ Hills * get_close_mountains();
- Hills * get_close_mountains();
+ Hills * get_visible_mountains();
- Hills * get_visible_mountains();
+ void set_center_angle(double a);
- void set_center_angle(double a);
+ void set_nick_angle(double a);
- void set_nick_angle(double a);
+ void set_tilt_angle(double a);
- void set_tilt_angle(double a);
+ void set_scale(double s);
- void set_scale(double s);
+ void set_view_lat(double v);
- void set_view_lat(double v);
+ void set_view_long(double v);
- void set_view_long(double v);
+ void set_view_height(double v);
- void set_view_height(double v);
+ const char * get_viewpoint();
- const char * get_viewpoint();
+ double get_center_angle();
- double get_center_angle();
+ double get_nick_angle();
- double get_nick_angle();
+ double get_tilt_angle();
- double get_tilt_angle();
+ double get_scale();
- double get_scale();
+ double get_height_dist_ratio();
- double get_height_dist_ratio();
-
- double get_view_lat();
+ double get_view_lat();
- double get_view_long();
+ double get_view_long();
- double get_view_height();
+ double get_view_height();
- double get_earth_radius(Hill *m);
+ double get_earth_radius(Hill *m);
- double get_real_distance(Hill *m);
+ double get_real_distance(Hill *m);
- int comp_params(Hill *m1, Hill *m2);
+ int comp_params(Hill *m1, Hill *m2);
- int guess(Hills *p1, Hill *m1);
+ int guess(Hills *p1, Hill *m1);
- Projection::Projection_t get_projection();
+ Projection::Projection_t get_projection();
- void set_projection(Projection::Projection_t p);
+ void set_projection(Projection::Projection_t p);
- int get_coordinates(double a_view, double a_nick, double *x, double *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 ebf0b5b..4ecf2f4 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <stdlib.h>
@@ -29,580 +16,580 @@
#define EARTH_RADIUS 6371010.0
Panorama::Panorama() {
- mountains = new Hills();
- close_mountains = new Hills();
- visible_mountains = new Hills();
- height_dist_ratio = 0.07;
- hide_value = 1.2;
- pi_d = asin(1.0) * 2.0;
- deg2rad = pi_d / 180.0;
- parms.a_center = 0.0;
- parms.a_nick = 0.0;
- parms.a_tilt = 0.0;
- parms.scale = 3500.0;
- view_name = NULL;
- view_phi = 0.0;
- view_lam = 0.0;
- view_height = 0.0;
- proj = NULL;
- set_projection(Projection::TANGENTIAL);
+ mountains = new Hills();
+ close_mountains = new Hills();
+ visible_mountains = new Hills();
+ height_dist_ratio = 0.07;
+ hide_value = 1.2;
+ pi_d = asin(1.0) * 2.0;
+ deg2rad = pi_d / 180.0;
+ parms.a_center = 0.0;
+ parms.a_nick = 0.0;
+ parms.a_tilt = 0.0;
+ parms.scale = 3500.0;
+ view_name = NULL;
+ view_phi = 0.0;
+ view_lam = 0.0;
+ view_height = 0.0;
+ proj = NULL;
+ set_projection(Projection::TANGENTIAL);
}
Panorama::~Panorama() {
- visible_mountains->clear();
- mountains->clobber();
- delete(visible_mountains);
- delete(mountains);
+ visible_mountains->clear();
+ mountains->clobber();
+ delete(visible_mountains);
+ delete(mountains);
}
int
Panorama::load_data(const char *name) {
- if (mountains->load(name) != 0) {
- fprintf(stderr, "Could not load datafile %s\n", name);
- return 1;
- }
+ if (mountains->load(name) != 0) {
+ fprintf(stderr, "Could not load datafile %s\n", name);
+ return 1;
+ }
- mountains->mark_duplicates(0.00001);
- update_angles();
+ mountains->mark_duplicates(0.00001);
+ update_angles();
- return 0;
+ return 0;
}
void
Panorama::add_hills(Hills *h) {
- mountains->add(h);
+ mountains->add(h);
- mountains->mark_duplicates(0.00001);
- update_angles();
+ mountains->mark_duplicates(0.00001);
+ update_angles();
}
void
Panorama::remove_trackpoints() {
- Hills *h_new = new Hills();
- Hill *m;
+ Hills *h_new = new Hills();
+ Hill *m;
+
+ for(int i=0; i<mountains->get_num(); i++) {
+ m = mountains->get(i);
+ if (! (m->flags & Hill::TRACK_POINT)) {
+ h_new->add(m);
+ }
+ }
- for(int i=0; i<mountains->get_num(); i++) {
- m = mountains->get(i);
- if (! (m->flags & Hill::TRACK_POINT)) {
- h_new->add(m);
- }
- }
-
- delete mountains;
- mountains = h_new;
+ delete mountains;
+ mountains = h_new;
}
-
+
int
Panorama::set_viewpoint(const char *name) {
- Hill *m = get_pos(name);
- if (m == NULL) {
- fprintf(stderr, "Could not find exactly one entry for %s.\n");
- return 1;
- }
+ Hill *m = get_pos(name);
+ if (m == NULL) {
+ fprintf(stderr, "Could not find exactly one entry for %s.\n");
+ return 1;
+ }
- set_viewpoint(m);
- return 0;
+ set_viewpoint(m);
+ return 0;
}
void
Panorama::set_viewpoint(const Hill *m) {
- if (m == NULL) {
- return;
- }
-
- view_phi = m->phi;
- view_lam = m->lam;
- view_height = m->height;
+ if (m == NULL) {
+ return;
+ }
- if (view_name) {
- free(view_name);
- }
+ view_phi = m->phi;
+ view_lam = m->lam;
+ view_height = m->height;
- view_name = strdup(m->name);
+ if (view_name) {
+ free(view_name);
+ }
- update_angles();
+ view_name = strdup(m->name);
+
+ update_angles();
}
Hills *
Panorama::get_mountains() {
- return mountains;
+ return mountains;
}
Hills *
Panorama::get_close_mountains() {
- return close_mountains;
+ return close_mountains;
}
Hills *
Panorama::get_visible_mountains() {
- return visible_mountains;
+ return visible_mountains;
}
double
Panorama::get_value(Hills *p) {
- int i, j;
- Hill *m;
- double v = 0.0, d_min, d;
-
- if (isnan(parms.scale) || isnan(parms.a_center) || isnan(parms.a_tilt) || isnan(parms.a_nick) ||
- parms.scale < 500.0 || parms.scale > 100000.0 ||
- parms.a_nick > pi_d/4.0 || parms.a_nick < - pi_d/4.0 ||
- parms.a_tilt > pi_d/16.0 || parms.a_tilt < - pi_d/16.0) {
- return 10000000.0;
- }
-
-
- for (i=0; i<p->get_num(); i++) {
- d_min = 1000.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;
- }
- }
- v = v + d_min;
- }
-
- return v;
+ int i, j;
+ Hill *m;
+ double v = 0.0, d_min, d;
+
+ if (isnan(parms.scale) || isnan(parms.a_center) || isnan(parms.a_tilt) || isnan(parms.a_nick) ||
+ parms.scale < 500.0 || parms.scale > 100000.0 ||
+ parms.a_nick > pi_d/4.0 || parms.a_nick < - pi_d/4.0 ||
+ parms.a_tilt > pi_d/16.0 || parms.a_tilt < - pi_d/16.0) {
+ return 10000000.0;
+ }
+
+
+ for (i=0; i<p->get_num(); i++) {
+ d_min = 1000.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;
+ }
+ }
+ v = v + d_min;
+ }
+
+ return v;
}
int
Panorama::guess(Hills *p, Hill *m1) {
- Hill *p2, *m_tmp1, *m_tmp2;
- Hill *m2;
- 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");
- return 1;
- }
-
- m_tmp1 = m1;
- x1_sav = m1->x;
- y1_sav = m1->y;
-
- for (i=0; i<p->get_num(); i++) {
- p2 = p->get(i);
- for (j=0; j<close_mountains->get_num(); j++) {
- m_tmp2 = close_mountains->get(j);
-
- m1 = m_tmp1;
- m1->x = x1_sav;
- m1->y = y1_sav;
-
- if (m_tmp2->flags & Hill::TRACK_POINT ||
- m1 == m_tmp2 || fabs(m1->alph - m_tmp2->alph) > pi_d *0.7) {
- continue;
- }
-
- m2 = m_tmp2;
- m2->x = p2->x;
- m2->y = p2->y;
-
- comp_params(m1, m2);
-
- v = get_value(p);
-
- if (v < best) {
- best = v;
- a_center_best = parms.a_center;
- a_nick_best = parms.a_nick;
- a_tilt_best = parms.a_tilt;
- scale_best = parms.scale;
- }
- }
- }
-
- if (best < 4000.0) {
- parms.a_center = a_center_best;
- parms.a_nick = a_nick_best;
- parms.a_tilt = a_tilt_best;
- parms.scale = scale_best;
- } else {
- fprintf(stderr, "No solution found.\n");
- }
- update_visible_mountains();
- return 0;
+ Hill *p2, *m_tmp1, *m_tmp2;
+ Hill *m2;
+ 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");
+ return 1;
+ }
+
+ m_tmp1 = m1;
+ x1_sav = m1->x;
+ y1_sav = m1->y;
+
+ for (i=0; i<p->get_num(); i++) {
+ p2 = p->get(i);
+ for (j=0; j<close_mountains->get_num(); j++) {
+ m_tmp2 = close_mountains->get(j);
+
+ m1 = m_tmp1;
+ m1->x = x1_sav;
+ m1->y = y1_sav;
+
+ if (m_tmp2->flags & Hill::TRACK_POINT ||
+ m1 == m_tmp2 || fabs(m1->alph - m_tmp2->alph) > pi_d *0.7) {
+ continue;
+ }
+
+ m2 = m_tmp2;
+ m2->x = p2->x;
+ m2->y = p2->y;
+
+ comp_params(m1, m2);
+
+ v = get_value(p);
+
+ if (v < best) {
+ best = v;
+ a_center_best = parms.a_center;
+ a_nick_best = parms.a_nick;
+ a_tilt_best = parms.a_tilt;
+ scale_best = parms.scale;
+ }
+ }
+ }
+
+ if (best < 4000.0) {
+ parms.a_center = a_center_best;
+ parms.a_nick = a_nick_best;
+ parms.a_tilt = a_tilt_best;
+ parms.scale = scale_best;
+ } else {
+ fprintf(stderr, "No solution found.\n");
+ }
+ update_visible_mountains();
+ return 0;
}
int
Panorama::comp_params(Hill *m1, Hill *m2) {
- int ret;
+ int ret;
- ret = proj->comp_params(m1, m2, &parms);
- update_visible_mountains();
- return ret;
+ ret = proj->comp_params(m1, m2, &parms);
+ update_visible_mountains();
+ return ret;
}
void
Panorama::set_center_angle(double a) {
- parms.a_center = a * deg2rad;
- update_visible_mountains();
+ parms.a_center = a * deg2rad;
+ update_visible_mountains();
}
void
Panorama::set_nick_angle(double a) {
- parms.a_nick = a * deg2rad;
- update_coordinates();
+ parms.a_nick = a * deg2rad;
+ update_coordinates();
}
void
Panorama::set_tilt_angle(double a) {
- parms.a_tilt = a * deg2rad;
- update_coordinates();
+ parms.a_tilt = a * deg2rad;
+ update_coordinates();
}
void
Panorama::set_scale(double s) {
- parms.scale = s;
- update_coordinates();
+ parms.scale = s;
+ update_coordinates();
}
void
Panorama::set_height_dist_ratio(double r) {
- height_dist_ratio = r;
- update_close_mountains();
+ height_dist_ratio = r;
+ update_close_mountains();
}
void
Panorama::set_view_long(double v) {
- view_lam = v * deg2rad;
- update_angles();
+ view_lam = v * deg2rad;
+ update_angles();
}
void
Panorama::set_view_lat(double v) {
- view_phi = v * deg2rad;
- update_angles();
+ view_phi = v * deg2rad;
+ update_angles();
}
void
Panorama::set_view_height(double v) {
- view_height = v;
- update_angles();
+ view_height = v;
+ update_angles();
}
void
Panorama::set_projection(Projection::Projection_t p) {
- projection_type = p;
-
- if (proj) {
- delete proj;
- }
-
- switch(projection_type) {
- case Projection::TANGENTIAL:
- proj = new ProjectionTangential();
- view_angle = pi_d / 3.0;
- break;
- case Projection::SPHAERIC:
- proj = new ProjectionSphaeric();
- view_angle = pi_d * 2.0;
- break;
- }
- update_angles();
+ projection_type = p;
+
+ if (proj) {
+ delete proj;
+ }
+
+ switch(projection_type) {
+ case Projection::TANGENTIAL:
+ proj = new ProjectionTangential();
+ view_angle = pi_d / 3.0;
+ break;
+ case Projection::SPHAERIC:
+ proj = new ProjectionSphaeric();
+ view_angle = pi_d * 2.0;
+ break;
+ }
+ update_angles();
}
const char *
Panorama::get_viewpoint() {
- return view_name;
+ return view_name;
}
double
Panorama::get_center_angle() {
- return parms.a_center / deg2rad;
+ return parms.a_center / deg2rad;
}
double
Panorama::get_nick_angle() {
- return parms.a_nick / deg2rad;
+ return parms.a_nick / deg2rad;
}
double
Panorama::get_tilt_angle() {
- return parms.a_tilt / deg2rad;
+ return parms.a_tilt / deg2rad;
}
double
Panorama::get_scale() {
- return parms.scale;
+ return parms.scale;
}
double
Panorama::get_height_dist_ratio() {
- return height_dist_ratio;
+ return height_dist_ratio;
}
double
Panorama::get_view_long() {
- return view_lam / deg2rad;
+ return view_lam / deg2rad;
}
double
Panorama::get_view_lat() {
- return view_phi / deg2rad;
+ return view_phi / deg2rad;
}
double
Panorama::get_view_height() {
- return view_height;
+ return view_height;
}
Projection::Projection_t
Panorama::get_projection() {
- return projection_type;
+ return projection_type;
}
Hill *
Panorama::get_pos(const char *name) {
- int i;
- int found = 0;
- double p, l, h;
- Hill *m, *ret;
-
- for (i=0; i<mountains->get_num(); i++) {
- m = mountains->get(i);
-
- if (strcmp(m->name, name) == 0) {
- ret = m;
- fprintf(stderr, "Found matching entry: %s (%fm)\n", m->name, m->height);
- found++;
- }
- }
+ int i;
+ int found = 0;
+ double p, l, h;
+ Hill *m, *ret;
+
+ for (i=0; i<mountains->get_num(); i++) {
+ m = mountains->get(i);
+
+ if (strcmp(m->name, name) == 0) {
+ ret = m;
+ fprintf(stderr, "Found matching entry: %s (%fm)\n", m->name, m->height);
+ found++;
+ }
+ }
- if (found == 1) {
- return ret;
- }
+ if (found == 1) {
+ return ret;
+ }
- return NULL;
+ return NULL;
}
void
Panorama::update_angles() {
- int i;
- Hill *m;
+ int i;
+ Hill *m;
- 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) {
-
- m->alph = alpha(m->phi, m->lam);
- m->a_nick = nick(m->dist, m->height);
- }
- }
+ 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) {
+
+ m->alph = alpha(m->phi, m->lam);
+ m->a_nick = nick(m->dist, m->height);
+ }
+ }
- mountains->sort();
+ mountains->sort();
- update_close_mountains();
+ update_close_mountains();
}
void
Panorama::set_hide_value(double h) {
- hide_value = h;
- update_visible_mountains();
+ hide_value = h;
+ update_visible_mountains();
}
void
Panorama::mark_hidden(Hills *hills) {
- int i, j;
- Hill *m, *n;
- double h;
-
- for (i=0; i<hills->get_num(); i++) {
- m = hills->get(i);
-
- m->flags &= ~Hill::HIDDEN;
-
- if (m->flags & Hill::DUPLICATE) {
- continue;
- }
-
- for (j=0; j<hills->get_num(); j++) {
- n = hills->get(j);
-
- if (n->flags & Hill::DUPLICATE || n->flags & Hill::TRACK_POINT) {
- continue;
- }
- if (m == n || fabs(m->alph - n->alph > pi_d / 2.0)) {
- continue;
- }
- if (m->dist < n->dist || m->a_nick > n->a_nick) {
- continue;
- }
-
- h = (n->a_nick - m->a_nick) / fabs(m->alph - n->alph);
- if (isinf(h) || h > hide_value) {
- m->flags |= Hill::HIDDEN;
- }
- }
-
- }
+ int i, j;
+ Hill *m, *n;
+ double h;
+
+ for (i=0; i<hills->get_num(); i++) {
+ m = hills->get(i);
+
+ m->flags &= ~Hill::HIDDEN;
+
+ if (m->flags & Hill::DUPLICATE) {
+ continue;
+ }
+
+ for (j=0; j<hills->get_num(); j++) {
+ n = hills->get(j);
+
+ if (n->flags & Hill::DUPLICATE || n->flags & Hill::TRACK_POINT) {
+ continue;
+ }
+ if (m == n || fabs(m->alph - n->alph > pi_d / 2.0)) {
+ continue;
+ }
+ if (m->dist < n->dist || m->a_nick > n->a_nick) {
+ continue;
+ }
+
+ h = (n->a_nick - m->a_nick) / fabs(m->alph - n->alph);
+ if (isinf(h) || h > hide_value) {
+ m->flags |= Hill::HIDDEN;
+ }
+ }
+
+ }
}
void
Panorama::update_close_mountains() {
- int i;
- Hill *m;
+ int i;
+ Hill *m;
- close_mountains->clear();
+ close_mountains->clear();
- for (i=0; i<mountains->get_num(); i++) {
- m = mountains->get(i);
-
- if (m->flags & Hill::TRACK_POINT ||
- ((m->phi != view_phi || m->lam != view_lam) &&
- (m->height / (m->dist * get_earth_radius(m))
- > height_dist_ratio))) {
+ for (i=0; i<mountains->get_num(); i++) {
+ m = mountains->get(i);
- close_mountains->add(m);
- }
- }
+ if (m->flags & Hill::TRACK_POINT ||
+ ((m->phi != view_phi || m->lam != view_lam) &&
+ (m->height / (m->dist * get_earth_radius(m))
+ > height_dist_ratio))) {
+
+ close_mountains->add(m);
+ }
+ }
- mark_hidden(close_mountains);
- update_visible_mountains();
+ mark_hidden(close_mountains);
+ update_visible_mountains();
}
void
Panorama::update_visible_mountains() {
- int i;
- Hill *m;
+ int i;
+ Hill *m;
- visible_mountains->clear();
+ visible_mountains->clear();
- for (i=0; i<close_mountains->get_num(); i++) {
- m = close_mountains->get(i);
+ for (i=0; i<close_mountains->get_num(); i++) {
+ m = close_mountains->get(i);
- m->a_view = m->alph - parms.a_center;
+ m->a_view = m->alph - 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 (m->a_view < view_angle && m->a_view > - view_angle) {
- visible_mountains->add(m);
- m->flags |= Hill::VISIBLE;
- } else {
- m->flags &= ~Hill::VISIBLE;
- }
- }
+ 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;
+ }
- update_coordinates();
+ if (m->a_view < view_angle && m->a_view > - view_angle) {
+ visible_mountains->add(m);
+ m->flags |= Hill::VISIBLE;
+ } else {
+ m->flags &= ~Hill::VISIBLE;
+ }
+ }
+
+ update_coordinates();
}
void
Panorama::update_coordinates() {
- Hill *m;
+ Hill *m;
+
+ for (int i=0; i<visible_mountains->get_num(); i++) {
+ m = visible_mountains->get(i);
+ double tmp_x, tmp_y;
- for (int i=0; i<visible_mountains->get_num(); i++) {
- m = visible_mountains->get(i);
- double tmp_x, tmp_y;
-
- 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);
- }
+ 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);
+ }
}
double
Panorama::distance(double phi, double lam) {
- return acos(sin(view_phi) * sin(phi) +
- cos(view_phi) * cos(phi) * cos(view_lam - 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);
+ 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));
+ 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);
+ 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_d - acos(cos_alph);
- }
+ if (sin_alph > 0) {
+ alph = acos(cos_alph);
+ } else {
+ alph = 2.0 * pi_d - acos(cos_alph);
+ }
- if (alph > 2.0 * pi_d) {
- alph = alph - 2.0 * pi_d;
- } else if (alph < 0.0) {
- alph = alph + 2.0 * pi_d;
- }
- return alph;
+ if (alph > 2.0 * pi_d) {
+ alph = alph - 2.0 * pi_d;
+ } else if (alph < 0.0) {
+ alph = alph + 2.0 * pi_d;
+ }
+ return alph;
}
double
Panorama::nick(double dist, double height) {
- double a, b, c;
- double beta;
+ double a, b, c;
+ double beta;
- b = height + EARTH_RADIUS;
- c = view_height + EARTH_RADIUS;
+ b = height + EARTH_RADIUS;
+ c = view_height + EARTH_RADIUS;
- a = pow(((b * (b - (2.0 * c * cos(dist)))) + (c * c)), (1.0 / 2.0));
- beta = acos((-(b*b) + (a*a) + (c*c))/(2 * a * c));
-
- return beta - pi_d / 2.0;
+ a = pow(((b * (b - (2.0 * c * cos(dist)))) + (c * c)), (1.0 / 2.0));
+ beta = acos((-(b*b) + (a*a) + (c*c))/(2 * a * c));
+
+ return beta - pi_d / 2.0;
}
double
Panorama::get_earth_radius(Hill *m) {
- return EARTH_RADIUS;
+ return EARTH_RADIUS;
}
double
Panorama::get_real_distance(Hill *m) {
- double a, b, c, gam;
+ double a, b, c, gam;
- a = view_height + get_earth_radius(m); // using m here is not quite right
- b = m->height + get_earth_radius(m);
- gam = m->dist;
+ a = view_height + get_earth_radius(m); // using m here is not quite right
+ b = m->height + get_earth_radius(m);
+ gam = m->dist;
- c = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b * cos(gam));
- return c;
+ c = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b * cos(gam));
+ return c;
}
int
Panorama::get_coordinates(double a_view, double a_nick, double *x, double *y) {
a_view = a_view - parms.a_center;
- if (a_view > pi_d) {
- a_view -= 2.0*pi_d;
- } else if (a_view < -pi_d) {
- a_view += 2.0*pi_d;
- }
-
- if (a_view > view_angle || a_view < - view_angle) {
+ if (a_view > pi_d) {
+ a_view -= 2.0*pi_d;
+ } else if (a_view < -pi_d) {
+ a_view += 2.0*pi_d;
+ }
+
+ if (a_view > view_angle || a_view < - view_angle) {
return 1;
}
- proj->get_coordinates(a_view, a_nick, &parms, x, y);
+ proj->get_coordinates(a_view, a_nick, &parms, x, y);
return 0;
}
diff --git a/src/PreviewOutputImage.H b/src/PreviewOutputImage.H
index 7095999..8b41684 100644
--- a/src/PreviewOutputImage.H
+++ b/src/PreviewOutputImage.H
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef PREVIEWOUTPUTIMAGE_H
#define PREVIEWOUTPUTIMAGE_H
diff --git a/src/PreviewOutputImage.cxx b/src/PreviewOutputImage.cxx
index 8b09e80..4b1d993 100644
--- a/src/PreviewOutputImage.cxx
+++ b/src/PreviewOutputImage.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/Projection.H b/src/Projection.H
index 0a6ec81..3bc816e 100644
--- a/src/Projection.H
+++ b/src/Projection.H
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef PROJECTION_H
#define PROJECTION_H
@@ -24,20 +11,20 @@
#include "ViewParams.H"
class Projection {
- protected:
- double pi_d;
+ protected:
+ double pi_d;
+
+ public:
+ typedef enum {
+ TANGENTIAL = 0,
+ SPHAERIC = 1
+ } Projection_t;
- public:
- typedef enum {
- TANGENTIAL = 0,
- SPHAERIC = 1
- } Projection_t;
+ Projection();
- Projection();
+ virtual void get_coordinates(double a_view, double a_nick,
+ const ViewParams *parms, double *x, double *y);
- 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);
+ virtual int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms);
};
#endif
diff --git a/src/Projection.cxx b/src/Projection.cxx
index 1916d55..02674a7 100644
--- a/src/Projection.cxx
+++ b/src/Projection.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <math.h>
@@ -23,17 +10,17 @@
#include "Projection.H"
Projection::Projection() {
- pi_d = asin(1.0) * 2.0;
+ pi_d = asin(1.0) * 2.0;
};
void
Projection::get_coordinates(double a_view, double a_nick,
- const ViewParams *parms, double *x, double *y) {
- fprintf(stderr, "Error: Projection::set_coordinates()\n");
+ const ViewParams *parms, double *x, double *y) {
+ fprintf(stderr, "Error: Projection::set_coordinates()\n");
}
int
Projection::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) {
- fprintf(stderr, "Error: Projection::comp_params()\n");
- return 1;
+ fprintf(stderr, "Error: Projection::comp_params()\n");
+ return 1;
}
diff --git a/src/ProjectionSphaeric.H b/src/ProjectionSphaeric.H
index 06396f1..c6ce5f4 100644
--- a/src/ProjectionSphaeric.H
+++ b/src/ProjectionSphaeric.H
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef PROJECTIONSPHAERIC_H
#define PROJECTIONSPHAERIC_H
@@ -24,17 +11,17 @@
#include "Projection.H"
class ProjectionSphaeric : public Projection {
- private:
+ private:
- double comp_scale(const Hill *m1, const Hill *m2, double d_m1_m2_2);
- 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);
+ double comp_scale(const Hill *m1, const Hill *m2, double d_m1_m2_2);
+ 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);
- public:
- void get_coordinates(double a_view, double a_nick, const ViewParams *parms,
- double *x, double *y);
+ public:
+ 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);
+ int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms);
};
#endif
diff --git a/src/ProjectionSphaeric.cxx b/src/ProjectionSphaeric.cxx
index e69882b..96af4e0 100644
--- a/src/ProjectionSphaeric.cxx
+++ b/src/ProjectionSphaeric.cxx
@@ -1,22 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
-// 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.
-//
-
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -28,142 +14,142 @@
int
ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) {
- const Hill *m_tmp;
- double tmp_x, tmp_y;
- double val;
- ViewParams best, tmp;
- double best_val = BEST_UNDEF;
- double d_m1_2, d_m2_2, d_m1_m2_2;
- int i, j;
-
- if (m1->x < m2->x) {
- m_tmp = m1;
- m1 = m2;
- m2 = m_tmp;
- }
-
- d_m1_2 = pow(m1->x, 2.0) + pow(m1->y, 2.0);
- d_m2_2 = pow(m2->x, 2.0) + pow(m2->y, 2.0);
- d_m1_m2_2 = pow(m1->x - m2->x, 2.0) + pow(m1->y - m2->y, 2.0);
-
- tmp.scale = comp_scale(m1, m2, d_m1_m2_2);
-
- for(i=0; i<2; i++) { // we need to try four possible solutions ...
- for(j=0; j<2; j++) {
- tmp.a_center = comp_dir_view(m1, m2, d_m1_2, d_m2_2,
- tmp.scale, i==0?1.0:-1.0);
- tmp.a_nick = comp_nick_view(m1, m2, d_m1_2, tmp.scale, tmp.a_center,
- j==0?1.0:-1.0);
-
- // use the point with greater distance from center for tilt computation
- if (d_m1_2 > d_m2_2) {
- tmp.a_tilt = comp_tilt_view(m1, tmp.scale, tmp.a_center, tmp.a_nick);
- } else {
- tmp.a_tilt = comp_tilt_view(m2, tmp.scale, tmp.a_center, tmp.a_nick);
- }
-
- if (isnan(tmp.a_center) || isnan(tmp.scale) ||
- isnan(tmp.a_nick) || isnan(tmp.a_tilt)) {
- ;
- } else {
- 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));
- 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) {
- best_val = val;
- best = tmp;
- }
- }
- }
- }
-
- if (best_val < BEST_UNDEF) {
- *parms = best;
- return 0;
- } else {
- return 1;
- }
+ const Hill *m_tmp;
+ double tmp_x, tmp_y;
+ double val;
+ ViewParams best, tmp;
+ double best_val = BEST_UNDEF;
+ double d_m1_2, d_m2_2, d_m1_m2_2;
+ int i, j;
+
+ if (m1->x < m2->x) {
+ m_tmp = m1;
+ m1 = m2;
+ m2 = m_tmp;
+ }
+
+ d_m1_2 = pow(m1->x, 2.0) + pow(m1->y, 2.0);
+ d_m2_2 = pow(m2->x, 2.0) + pow(m2->y, 2.0);
+ d_m1_m2_2 = pow(m1->x - m2->x, 2.0) + pow(m1->y - m2->y, 2.0);
+
+ tmp.scale = comp_scale(m1, m2, d_m1_m2_2);
+
+ for(i=0; i<2; i++) { // we need to try four possible solutions ...
+ for(j=0; j<2; j++) {
+ tmp.a_center = comp_dir_view(m1, m2, d_m1_2, d_m2_2,
+ tmp.scale, i==0?1.0:-1.0);
+ tmp.a_nick = comp_nick_view(m1, m2, d_m1_2, tmp.scale, tmp.a_center,
+ j==0?1.0:-1.0);
+
+ // use the point with greater distance from center for tilt computation
+ if (d_m1_2 > d_m2_2) {
+ tmp.a_tilt = comp_tilt_view(m1, tmp.scale, tmp.a_center, tmp.a_nick);
+ } else {
+ tmp.a_tilt = comp_tilt_view(m2, tmp.scale, tmp.a_center, tmp.a_nick);
+ }
+
+ if (isnan(tmp.a_center) || isnan(tmp.scale) ||
+ isnan(tmp.a_nick) || isnan(tmp.a_tilt)) {
+ ;
+ } else {
+ 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));
+ 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) {
+ best_val = val;
+ best = tmp;
+ }
+ }
+ }
+ }
+
+ if (best_val < BEST_UNDEF) {
+ *parms = best;
+ return 0;
+ } else {
+ return 1;
+ }
}
void
ProjectionSphaeric::get_coordinates(double a_view, double a_nick,
const ViewParams *parms, double *x, double *y) {
- double x_tmp, y_tmp;
+ double x_tmp, y_tmp;
- x_tmp = a_view * parms->scale;
- y_tmp = - (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);
- *y = x_tmp * sin(parms->a_tilt) + y_tmp * cos(parms->a_tilt);
+ // rotate by 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
ProjectionSphaeric::comp_scale(const Hill *m1, const Hill *m2, double d_m1_m2_2) {
- double sign1 = 1.0;
- double nick_m1 = m1->a_nick;
- double nick_m2 = m2->a_nick;
- double dir_m1 = m1->alph;
- double dir_m2 = m2->alph;
+ double sign1 = 1.0;
+ double nick_m1 = m1->a_nick;
+ double nick_m2 = m2->a_nick;
+ double dir_m1 = m1->alph;
+ double dir_m2 = m2->alph;
- return (pow((d_m1_m2_2 / ((dir_m2 * dir_m2) - (2.0 * ((dir_m2 * dir_m1) + (nick_m2 * nick_m1))) + (nick_m2 * nick_m2) + (dir_m1 * dir_m1) + (nick_m1 * nick_m1))), (1.0 / 2.0)) * sign1);
+ return (pow((d_m1_m2_2 / ((dir_m2 * dir_m2) - (2.0 * ((dir_m2 * dir_m1) + (nick_m2 * nick_m1))) + (nick_m2 * nick_m2) + (dir_m1 * dir_m1) + (nick_m1 * nick_m1))), (1.0 / 2.0)) * sign1);
}
// using the sign3 parameter one can choose between the two possible solutions
// sign3 must be 1.0 or -1.0
double
ProjectionSphaeric::comp_dir_view(const Hill *m1, const Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3) {
- double dir_view;
- double nick_m1 = m1->a_nick;
- double nick_m2 = m2->a_nick;
- double dir_m1 = m1->alph;
- double dir_m2 = m2->alph;
+ double dir_view;
+ double nick_m1 = m1->a_nick;
+ double nick_m2 = m2->a_nick;
+ double dir_m1 = m1->alph;
+ double dir_m2 = m2->alph;
- dir_view = (((pow((16.0 * pow(scale, 4.0) * (((scale * scale) * ((2.0 * (((scale * scale) * ((dir_m1 * ((dir_m1 * ((nick_m1 * ((nick_m1 * ((nick_m2 * ((4.0 * nick_m1) - (6.0 * nick_m2))) - (nick_m1 * nick_m1))) + (nick_m2 * ((4.0 * (nick_m2 * nick_m2)) + (6.0 * (dir_m2 * dir_m2)) + (dir_m1 * dir_m1))))) - pow(nick_m2, 4.0))) + (nick_m1 * nick_m2 * dir_m2 * ((nick_m1 * ((12.0 * nick_m2) - (8.0 * nick_m1))) - (8.0 * (nick_m2 * nick_m2)))))) + ((dir_m2 * dir_m2) * ((nick_m1 * ((nick_m2 * (dir_m2 * dir_m2)) - pow(nick_m1, 3.0))) - pow(nick_m2, 4.0))))) + ((d_m1_2 + d_m2_2) * ((((nick_m1 * nick_m1) + (nick_m2 * nick_m2)) * ((dir_m1 * dir_m1) + (dir_m2 * dir_m2))) + pow(nick_m1, 4.0) + pow(nick_m2, 4.0))))) + (4.0 * ((dir_m1 * ((nick_m1 * ((nick_m1 * dir_m2 * (((scale * scale) * ((nick_m1 * nick_m1) + (dir_m1 * dir_m1) + (dir_m2 * dir_m2))) - d_m1_2 - d_m2_2)) - (dir_m1 * nick_m2 * (d_m2_2 + d_m1_2)))) + ((nick_m2 * nick_m2) * dir_m2 * (((scale * scale) * ((nick_m2 * nick_m2) + (dir_m1 * dir_m1) + (dir_m2 * dir_m2))) - d_m1_2 - d_m2_2)))) - (nick_m1 * nick_m2 * (dir_m2 * dir_m2) * (d_m1_2 + d_m2_2)))) + ((scale * scale) * ((nick_m1 * ((nick_m1 * ((nick_m2 * (((dir_m2 * dir_m2) * ((8.0 * nick_m1) - (12.0 * nick_m2))) + (nick_m1 * ((nick_m1 * ((6.0 * nick_m1) - (15.0 * nick_m2))) + (20.0 * (nick_m2 * nick_m2)))) - (15.0 * pow(nick_m2, 3.0)))) - ((dir_m1 * dir_m1) * ((dir_m1 * dir_m1) + (6.0 * (dir_m2 * dir_m2)))) - pow(dir_m2, 4.0) - pow(nick_m1, 4.0))) + (nick_m2 * ((8.0 * dir_m2 * ((dir_m2 * ((nick_m2 * nick_m2) - (dir_m1 * dir_m2))) - pow(dir_m1, 3.0))) + (6.0 * pow(nick_m2, 4.0)))))) - ((nick_m2 * nick_m2) * (((dir_m1 * dir_m1) * ((6.0 * (dir_m2 * dir_m2)) + (dir_m1 * dir_m1))) + pow(dir_m2, 4.0) + pow(nick_m2, 4.0))))) + (nick_m1 * nick_m2 * (d_m1_2 + d_m2_2) * ((8.0 * ((dir_m1 * dir_m2) - (nick_m1 * nick_m1) - (nick_m2 * nick_m2))) + (12.0 * nick_m1 * nick_m2))))) + (((d_m1_2 * ((2.0 * d_m2_2) - d_m1_2)) - (d_m2_2 * d_m2_2)) * ((nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2))))), (1.0 / 2.0)) * sign3 / 2.0) + (2.0 * (scale * scale) * (((scale * scale) * ((dir_m1 * ((nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2) - (dir_m2 * (dir_m2 + dir_m1)) + (dir_m1 * dir_m1))) + (dir_m2 * ((dir_m2 * dir_m2) + (nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2))))) + ((dir_m2 - dir_m1) * (d_m1_2 - d_m2_2))))) / (4.0 * pow(scale, 4.0) * ((dir_m1 * (dir_m1 - (2.0 * dir_m2))) + (dir_m2 * dir_m2) + (nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2))));
+ dir_view = (((pow((16.0 * pow(scale, 4.0) * (((scale * scale) * ((2.0 * (((scale * scale) * ((dir_m1 * ((dir_m1 * ((nick_m1 * ((nick_m1 * ((nick_m2 * ((4.0 * nick_m1) - (6.0 * nick_m2))) - (nick_m1 * nick_m1))) + (nick_m2 * ((4.0 * (nick_m2 * nick_m2)) + (6.0 * (dir_m2 * dir_m2)) + (dir_m1 * dir_m1))))) - pow(nick_m2, 4.0))) + (nick_m1 * nick_m2 * dir_m2 * ((nick_m1 * ((12.0 * nick_m2) - (8.0 * nick_m1))) - (8.0 * (nick_m2 * nick_m2)))))) + ((dir_m2 * dir_m2) * ((nick_m1 * ((nick_m2 * (dir_m2 * dir_m2)) - pow(nick_m1, 3.0))) - pow(nick_m2, 4.0))))) + ((d_m1_2 + d_m2_2) * ((((nick_m1 * nick_m1) + (nick_m2 * nick_m2)) * ((dir_m1 * dir_m1) + (dir_m2 * dir_m2))) + pow(nick_m1, 4.0) + pow(nick_m2, 4.0))))) + (4.0 * ((dir_m1 * ((nick_m1 * ((nick_m1 * dir_m2 * (((scale * scale) * ((nick_m1 * nick_m1) + (dir_m1 * dir_m1) + (dir_m2 * dir_m2))) - d_m1_2 - d_m2_2)) - (dir_m1 * nick_m2 * (d_m2_2 + d_m1_2)))) + ((nick_m2 * nick_m2) * dir_m2 * (((scale * scale) * ((nick_m2 * nick_m2) + (dir_m1 * dir_m1) + (dir_m2 * dir_m2))) - d_m1_2 - d_m2_2)))) - (nick_m1 * nick_m2 * (dir_m2 * dir_m2) * (d_m1_2 + d_m2_2)))) + ((scale * scale) * ((nick_m1 * ((nick_m1 * ((nick_m2 * (((dir_m2 * dir_m2) * ((8.0 * nick_m1) - (12.0 * nick_m2))) + (nick_m1 * ((nick_m1 * ((6.0 * nick_m1) - (15.0 * nick_m2))) + (20.0 * (nick_m2 * nick_m2)))) - (15.0 * pow(nick_m2, 3.0)))) - ((dir_m1 * dir_m1) * ((dir_m1 * dir_m1) + (6.0 * (dir_m2 * dir_m2)))) - pow(dir_m2, 4.0) - pow(nick_m1, 4.0))) + (nick_m2 * ((8.0 * dir_m2 * ((dir_m2 * ((nick_m2 * nick_m2) - (dir_m1 * dir_m2))) - pow(dir_m1, 3.0))) + (6.0 * pow(nick_m2, 4.0)))))) - ((nick_m2 * nick_m2) * (((dir_m1 * dir_m1) * ((6.0 * (dir_m2 * dir_m2)) + (dir_m1 * dir_m1))) + pow(dir_m2, 4.0) + pow(nick_m2, 4.0))))) + (nick_m1 * nick_m2 * (d_m1_2 + d_m2_2) * ((8.0 * ((dir_m1 * dir_m2) - (nick_m1 * nick_m1) - (nick_m2 * nick_m2))) + (12.0 * nick_m1 * nick_m2))))) + (((d_m1_2 * ((2.0 * d_m2_2) - d_m1_2)) - (d_m2_2 * d_m2_2)) * ((nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2))))), (1.0 / 2.0)) * sign3 / 2.0) + (2.0 * (scale * scale) * (((scale * scale) * ((dir_m1 * ((nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2) - (dir_m2 * (dir_m2 + dir_m1)) + (dir_m1 * dir_m1))) + (dir_m2 * ((dir_m2 * dir_m2) + (nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2))))) + ((dir_m2 - dir_m1) * (d_m1_2 - d_m2_2))))) / (4.0 * pow(scale, 4.0) * ((dir_m1 * (dir_m1 - (2.0 * dir_m2))) + (dir_m2 * dir_m2) + (nick_m1 * (nick_m1 - (2.0 * nick_m2))) + (nick_m2 * nick_m2))));
- return dir_view;
+ return dir_view;
}
double
ProjectionSphaeric::comp_nick_view(const Hill *m1, const Hill *m2, double d_m1_2, double scale, double dir_view, double sign1) {
- double nick_view;
- double nick_m1 = m1->a_nick;
- double dir_m1 = m1->alph;
+ double nick_view;
+ double nick_m1 = m1->a_nick;
+ double dir_m1 = m1->alph;
- nick_view = ((pow(((d_m1_2 / (scale * scale)) - pow((dir_view - dir_m1), 2.0)), (1.0 / 2.0)) * sign1) + nick_m1);
+ nick_view = ((pow(((d_m1_2 / (scale * scale)) - pow((dir_view - dir_m1), 2.0)), (1.0 / 2.0)) * sign1) + nick_m1);
- return nick_view;
+ return nick_view;
}
double
ProjectionSphaeric::comp_tilt_view(const Hill *m, double scale, double dir_view, double nick_view) {
- double sin_a_tilt1, sin_a_tilt2, sin_a_tilt, res;
- double x_tmp = (m->alph - dir_view) * scale;
- double y_tmp = (m->a_nick - nick_view) * scale;
- double x = m->x;
- double y = m->y;
+ double sin_a_tilt1, sin_a_tilt2, sin_a_tilt, res;
+ double x_tmp = (m->alph - dir_view) * scale;
+ double y_tmp = (m->a_nick - nick_view) * scale;
+ double x = m->x;
+ double y = m->y;
+
+ sin_a_tilt1 = - (y * - pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
+ (x*x + y*y);
- sin_a_tilt1 = - (y * - pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
- (x*x + y*y);
+ sin_a_tilt2 = - (y * pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
+ (x*x + y*y);
- sin_a_tilt2 = - (y * pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
- (x*x + y*y);
+ sin_a_tilt = fabs(sin_a_tilt1) < fabs(sin_a_tilt2)?sin_a_tilt1:sin_a_tilt2;
- sin_a_tilt = fabs(sin_a_tilt1) < fabs(sin_a_tilt2)?sin_a_tilt1:sin_a_tilt2;
+ res = asin(sin_a_tilt);
- res = asin(sin_a_tilt);
+ if (res > pi_d / 4.0) {
+ res = res - pi_d / 2.0;
+ } else if (res < -pi_d / 4.0) {
+ res = res + pi_d / 2.0;
+ }
- if (res > pi_d / 4.0) {
- res = res - pi_d / 2.0;
- } else if (res < -pi_d / 4.0) {
- res = res + pi_d / 2.0;
- }
+ return res;
- return res;
-
}
diff --git a/src/ProjectionTangential.H b/src/ProjectionTangential.H
index e74511f..13e354a 100644
--- a/src/ProjectionTangential.H
+++ b/src/ProjectionTangential.H
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef PROJECTIONTANGENTIAL_H
#define PROJECTIONTANGENTIAL_H
@@ -24,19 +11,19 @@
#include "Projection.H"
class ProjectionTangential : public Projection {
- private:
- double comp_center_angle(double alph_a, double alph_b, double d1, double d2);
+ private:
+ double comp_center_angle(double alph_a, double alph_b, double d1, double d2);
+
+ double comp_scale(double alph_a, double alph_b, double d1, double d2);
- double comp_scale(double alph_a, double alph_b, double d1, double d2);
+ double angle_dist(double a1, double a2);
- double angle_dist(double a1, double a2);
+ int optimize(const Hill *m1, const Hill *m2, ViewParams *parms);
- int optimize(const Hill *m1, const Hill *m2, ViewParams *parms);
+ public:
+ void get_coordinates(double a_view, double a_nick, const ViewParams *parms,
+ double *x, double *y);
- public:
- 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);
+ int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms);
};
#endif
diff --git a/src/ProjectionTangential.cxx b/src/ProjectionTangential.cxx
index 2578c5a..8eed552 100644
--- a/src/ProjectionTangential.cxx
+++ b/src/ProjectionTangential.cxx
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <stdlib.h>
@@ -28,284 +15,284 @@ extern "C" {
#include "ProjectionTangential.H"
static int opt_step(double *tan_nick_view,
- double *tan_dir_view,
- double *n_scale,
- double tan_dir_m1,
- double tan_nick_m1,
- double tan_dir_m2,
- double tan_nick_m2,
- double d_m1_2, double d_m2_2, double d_m1_m2_2);
+ double *tan_dir_view,
+ double *n_scale,
+ double tan_dir_m1,
+ double tan_nick_m1,
+ double tan_dir_m2,
+ double tan_nick_m2,
+ double d_m1_2, double d_m2_2, double d_m1_m2_2);
static double
comp_tilt(double tan_nick_view, double tan_dir_view, double n_scale,
- double tan_nick_m, double tan_dir_m,
- double x, double y, double pi_d);
+ double tan_nick_m, double tan_dir_m,
+ double x, double y, double pi_d);
int
ProjectionTangential::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) {
- const Hill *tmp;
- double a_center_tmp, scale_tmp, a_nick_tmp;
-
- scale_tmp = comp_scale(m1->alph, m2->alph, m1->x, m2->x);
- if (isnan(scale_tmp) || scale_tmp < 100.0) {
- // try again with mountains swapped
- tmp = m1;
- m1 = m2;
- m2 = tmp;
- scale_tmp = comp_scale(m1->alph, m2->alph, m1->x, m2->x);
- }
-
- a_center_tmp = comp_center_angle(m1->alph, m2->alph, m1->x, m2->x);
- a_nick_tmp = atan ((m1->y + tan(m1->a_nick) * parms->scale) /
- (parms->scale - m1->y * tan(m1->a_nick)));
-
- if (isnan(a_center_tmp) || isnan(scale_tmp) ||
- scale_tmp < 100.0 || isnan(a_nick_tmp)) {
- return 1;
- } else {
-
- parms->a_center = a_center_tmp;
- parms->scale = scale_tmp;
- parms->a_nick = a_nick_tmp;
-
- optimize(m1, m2, parms);
-
- return 0;
- }
+ const Hill *tmp;
+ double a_center_tmp, scale_tmp, a_nick_tmp;
+
+ scale_tmp = comp_scale(m1->alph, m2->alph, m1->x, m2->x);
+ if (isnan(scale_tmp) || scale_tmp < 100.0) {
+ // try again with mountains swapped
+ tmp = m1;
+ m1 = m2;
+ m2 = tmp;
+ scale_tmp = comp_scale(m1->alph, m2->alph, m1->x, m2->x);
+ }
+
+ a_center_tmp = comp_center_angle(m1->alph, m2->alph, m1->x, m2->x);
+ a_nick_tmp = atan ((m1->y + tan(m1->a_nick) * parms->scale) /
+ (parms->scale - m1->y * tan(m1->a_nick)));
+
+ if (isnan(a_center_tmp) || isnan(scale_tmp) ||
+ scale_tmp < 100.0 || isnan(a_nick_tmp)) {
+ return 1;
+ } else {
+
+ parms->a_center = a_center_tmp;
+ parms->scale = scale_tmp;
+ parms->a_nick = a_nick_tmp;
+
+ optimize(m1, m2, parms);
+
+ return 0;
+ }
}
double
ProjectionTangential::angle_dist(double a1, double a2) {
- double ret;
-
- a1 = fmod(a1, 2.0 * pi_d);
- if (a1 < 0.0) {
- a1 = a1 + 2.0 * pi_d;
- }
- a2 = fmod(a2, 2.0 * pi_d);
- if (a2 < 0.0) {
- a2 = a2 + 2.0 * pi_d;
- }
-
- ret = fabs(a1 - a2);
- if (ret > pi_d) {
- ret = 2.0 * pi_d - ret;
- }
-
- return ret;
+ double ret;
+
+ a1 = fmod(a1, 2.0 * pi_d);
+ if (a1 < 0.0) {
+ a1 = a1 + 2.0 * pi_d;
+ }
+ a2 = fmod(a2, 2.0 * pi_d);
+ if (a2 < 0.0) {
+ a2 = a2 + 2.0 * pi_d;
+ }
+
+ ret = fabs(a1 - a2);
+ if (ret > pi_d) {
+ ret = 2.0 * pi_d - ret;
+ }
+
+ return ret;
}
int
ProjectionTangential::optimize(const Hill *m1, const Hill *m2, ViewParams *parms) {
- int i;
- double tan_nick_view, tan_dir_view, n_scale;
- double tan_nick_m1, tan_dir_m1;
- double tan_nick_m2, tan_dir_m2;
- double d_m1_2, d_m2_2, d_m1_m2_2;
-
- d_m1_2 = pow(m1->x, 2.0) + pow(m1->y, 2.0);
- d_m2_2 = pow(m2->x, 2.0) + pow(m2->y, 2.0);
- d_m1_m2_2 = pow(m1->x - m2->x, 2.0) + pow(m1->y - m2->y, 2.0);
-
- tan_nick_view = tan(parms->a_nick);
- tan_dir_view = tan(parms->a_center);
- n_scale = parms->scale;
- tan_dir_m1 = tan(m1->alph);
- tan_nick_m1 = tan(m1->a_nick);
- tan_dir_m2 = tan(m2->alph);
- tan_nick_m2 = tan(m2->a_nick);
-
- for (i=0; i<5; i++) {
- opt_step(&tan_nick_view, &tan_dir_view, &n_scale,
- tan_dir_m1, tan_nick_m1, tan_dir_m2, tan_nick_m2,
- d_m1_2, d_m2_2, d_m1_m2_2);
- }
-
- if (isnan(tan_dir_view) || isnan(tan_nick_view) || isnan(n_scale)) {
- fprintf(stderr, "No solution found.\n");
- return 1;
- }
-
- parms->a_center = atan(tan_dir_view);
- parms->a_nick = atan(tan_nick_view);
-
- if (parms->a_center > 2.0 * pi_d) {
- parms->a_center = parms->a_center - 2.0 * pi_d;
- } else if (parms->a_center < 0.0) {
- parms->a_center = parms->a_center + 2.0 * pi_d;
- }
-
- // atan(tan_dir_view) is not the only possible solution.
- // Choose the one which is close to m1->alph.
- if (angle_dist(parms->a_center, m1->alph) > pi_d/2.0) {
- parms->a_center = parms->a_center + pi_d;
- }
-
- parms->scale = n_scale;
-
- // use the point with greater distance from center for tilt computation
- if (d_m1_2 > d_m2_2) {
- parms->a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale,
- tan_nick_m1, tan_dir_m1,
- (double) m1->x, (double) m1->y, pi_d);
- } else {
- parms->a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale,
- tan_nick_m2, tan_dir_m2,
- (double) m2->x, (double) m2->y, pi_d);
- }
-
- return 0;
+ int i;
+ double tan_nick_view, tan_dir_view, n_scale;
+ double tan_nick_m1, tan_dir_m1;
+ double tan_nick_m2, tan_dir_m2;
+ double d_m1_2, d_m2_2, d_m1_m2_2;
+
+ d_m1_2 = pow(m1->x, 2.0) + pow(m1->y, 2.0);
+ d_m2_2 = pow(m2->x, 2.0) + pow(m2->y, 2.0);
+ d_m1_m2_2 = pow(m1->x - m2->x, 2.0) + pow(m1->y - m2->y, 2.0);
+
+ tan_nick_view = tan(parms->a_nick);
+ tan_dir_view = tan(parms->a_center);
+ n_scale = parms->scale;
+ tan_dir_m1 = tan(m1->alph);
+ tan_nick_m1 = tan(m1->a_nick);
+ tan_dir_m2 = tan(m2->alph);
+ tan_nick_m2 = tan(m2->a_nick);
+
+ for (i=0; i<5; i++) {
+ opt_step(&tan_nick_view, &tan_dir_view, &n_scale,
+ tan_dir_m1, tan_nick_m1, tan_dir_m2, tan_nick_m2,
+ d_m1_2, d_m2_2, d_m1_m2_2);
+ }
+
+ if (isnan(tan_dir_view) || isnan(tan_nick_view) || isnan(n_scale)) {
+ fprintf(stderr, "No solution found.\n");
+ return 1;
+ }
+
+ parms->a_center = atan(tan_dir_view);
+ parms->a_nick = atan(tan_nick_view);
+
+ if (parms->a_center > 2.0 * pi_d) {
+ parms->a_center = parms->a_center - 2.0 * pi_d;
+ } else if (parms->a_center < 0.0) {
+ parms->a_center = parms->a_center + 2.0 * pi_d;
+ }
+
+ // atan(tan_dir_view) is not the only possible solution.
+ // Choose the one which is close to m1->alph.
+ if (angle_dist(parms->a_center, m1->alph) > pi_d/2.0) {
+ parms->a_center = parms->a_center + pi_d;
+ }
+
+ parms->scale = n_scale;
+
+ // use the point with greater distance from center for tilt computation
+ if (d_m1_2 > d_m2_2) {
+ parms->a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale,
+ tan_nick_m1, tan_dir_m1,
+ (double) m1->x, (double) m1->y, pi_d);
+ } else {
+ parms->a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale,
+ tan_nick_m2, tan_dir_m2,
+ (double) m2->x, (double) m2->y, pi_d);
+ }
+
+ return 0;
}
void
ProjectionTangential::get_coordinates(double a_view, double a_nick,
const ViewParams *parms, double *x, double *y) {
- double x_tmp, y_tmp;
+ double x_tmp, y_tmp;
- x_tmp = tan(a_view) * parms->scale;
- y_tmp = - (tan(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;
- *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);
+ // rotate by 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
ProjectionTangential::comp_center_angle(double a1, double a2, double d1, double d2) {
- double sign1 = 1.0;
- double tan_acenter, tan_a1, tan_a2, a_center;
+ double sign1 = 1.0;
+ double tan_acenter, tan_a1, tan_a2, a_center;
- tan_a1 = tan(a1);
- tan_a2 = tan(a2);
+ tan_a1 = tan(a1);
+ tan_a2 = tan(a2);
- tan_acenter = (((pow(((pow((1.0 + (tan_a1 * tan_a2)), 2.0) * ((d1 * d1) + (d2 * d2))) + (2.0 * d1 * d2 * ((2.0 * ((tan_a2 * tan_a1) - (tan_a2 * tan_a2))) - ((tan_a1 * tan_a1) * (2.0 + (tan_a2 * tan_a2))) - 1.0))), (1.0 / 2.0)) * sign1) + ((1.0 - (tan_a1 * tan_a2)) * (d1 - d2))) / (2.0 * ((d2 * tan_a2) - (d1 * tan_a1))));
+ tan_acenter = (((pow(((pow((1.0 + (tan_a1 * tan_a2)), 2.0) * ((d1 * d1) + (d2 * d2))) + (2.0 * d1 * d2 * ((2.0 * ((tan_a2 * tan_a1) - (tan_a2 * tan_a2))) - ((tan_a1 * tan_a1) * (2.0 + (tan_a2 * tan_a2))) - 1.0))), (1.0 / 2.0)) * sign1) + ((1.0 - (tan_a1 * tan_a2)) * (d1 - d2))) / (2.0 * ((d2 * tan_a2) - (d1 * tan_a1))));
- a_center = atan(tan_acenter);
+ a_center = atan(tan_acenter);
- if (a_center > 2.0 * pi_d) {
- a_center = a_center - 2.0 * pi_d;
- } else if (a_center < 0.0) {
- a_center = a_center + 2.0 * pi_d;
- }
+ if (a_center > 2.0 * pi_d) {
+ a_center = a_center - 2.0 * pi_d;
+ } else if (a_center < 0.0) {
+ a_center = a_center + 2.0 * pi_d;
+ }
- // atan(tan_dir_view) is not the only possible solution.
- // Choose the one which is close to m1->alph.
- if (fabs(a_center - a1) > pi_d/2.0) {
- a_center = a_center + pi_d;
- }
+ // atan(tan_dir_view) is not the only possible solution.
+ // Choose the one which is close to m1->alph.
+ if (fabs(a_center - a1) > pi_d/2.0) {
+ a_center = a_center + pi_d;
+ }
- return a_center;
+ return a_center;
}
double
ProjectionTangential::comp_scale(double a1, double a2, double d1, double d2) {
- double sign1 = 1.0;
- double sc, tan_a1, tan_a2;
+ double sign1 = 1.0;
+ double sc, tan_a1, tan_a2;
+
+ tan_a1 = tan(a1);
+ tan_a2 = tan(a2);
- tan_a1 = tan(a1);
- tan_a2 = tan(a2);
-
- sc = ((((1.0 + (tan_a1 * tan_a2)) * (d1 - d2)) - (sign1 * pow((((1.0 + pow((tan_a1 * tan_a2), 2.0)) * ((d1 * d1) + (d2 * d2))) + (2.0 * ((tan_a1 * tan_a2 * pow((d1 + d2), 2.0)) - (d1 * d2 * (((tan_a1 * tan_a1) * (2.0 + (tan_a2 * tan_a2))) + 1.0 + (2.0 * (tan_a2 * tan_a2))))))), (1.0 / 2.0)))) / (2.0 * (tan_a1 - tan_a2)));
+ sc = ((((1.0 + (tan_a1 * tan_a2)) * (d1 - d2)) - (sign1 * pow((((1.0 + pow((tan_a1 * tan_a2), 2.0)) * ((d1 * d1) + (d2 * d2))) + (2.0 * ((tan_a1 * tan_a2 * pow((d1 + d2), 2.0)) - (d1 * d2 * (((tan_a1 * tan_a1) * (2.0 + (tan_a2 * tan_a2))) + 1.0 + (2.0 * (tan_a2 * tan_a2))))))), (1.0 / 2.0)))) / (2.0 * (tan_a1 - tan_a2)));
- return sc;
+ return sc;
}
static int
get_matrix(double m[],
- double tan_nick_view, double tan_dir_view, double n_scale,
- double tan_dir_m1, double tan_nick_m1,
- double tan_dir_m2, double tan_nick_m2) {
-
- m[0] = pow(n_scale,2.0)*(1.0/pow((tan_nick_m1*tan_nick_view + 1.0),2.0)*(2.0*tan_nick_m1 - 2.0 * tan_nick_view) + 2.0*tan_nick_m1*pow((tan_nick_m1 - tan_nick_view), 2.0)/pow((tan_nick_m1*tan_nick_view + 1.0), 3.0));
+ double tan_nick_view, double tan_dir_view, double n_scale,
+ double tan_dir_m1, double tan_nick_m1,
+ double tan_dir_m2, double tan_nick_m2) {
- m[1] = pow(n_scale, 2.0) *(1.0/pow((tan_dir_m1*tan_dir_view + 1.0), 2.0) * (2.0*tan_dir_m1 - 2.0*tan_dir_view) + 2.0*tan_dir_m1*pow((tan_dir_m1 - tan_dir_view),2.0) / pow((tan_dir_m1*tan_dir_view + 1.0), 3.0));
+ m[0] = pow(n_scale,2.0)*(1.0/pow((tan_nick_m1*tan_nick_view + 1.0),2.0)*(2.0*tan_nick_m1 - 2.0 * tan_nick_view) + 2.0*tan_nick_m1*pow((tan_nick_m1 - tan_nick_view), 2.0)/pow((tan_nick_m1*tan_nick_view + 1.0), 3.0));
- m[2] = -2.0*n_scale*(pow((tan_dir_m1 - tan_dir_view), 2.0)/pow((tan_dir_m1*tan_dir_view + 1.0), 2.0) + pow((tan_nick_m1 - tan_nick_view), 2.0)/pow((tan_nick_m1*tan_nick_view + 1.0), 2.0));
+ m[1] = pow(n_scale, 2.0) *(1.0/pow((tan_dir_m1*tan_dir_view + 1.0), 2.0) * (2.0*tan_dir_m1 - 2.0*tan_dir_view) + 2.0*tan_dir_m1*pow((tan_dir_m1 - tan_dir_view),2.0) / pow((tan_dir_m1*tan_dir_view + 1.0), 3.0));
- m[3] = pow(n_scale, 2.0)*(1.0/pow((tan_nick_m2*tan_nick_view + 1.0), 2.0)*(2.0*tan_nick_m2 - 2.0*tan_nick_view) + 2.0*tan_nick_m2*pow((tan_nick_m2 - tan_nick_view), 2.0)/pow((tan_nick_m2*tan_nick_view + 1.0), 3.0));
+ m[2] = -2.0*n_scale*(pow((tan_dir_m1 - tan_dir_view), 2.0)/pow((tan_dir_m1*tan_dir_view + 1.0), 2.0) + pow((tan_nick_m1 - tan_nick_view), 2.0)/pow((tan_nick_m1*tan_nick_view + 1.0), 2.0));
- m[4] = pow(n_scale, 2.0)*(1.0/pow((tan_dir_m2*tan_dir_view + 1.0), 2.0)*(2.0*tan_dir_m2 - 2.0*tan_dir_view) + 2.0*tan_dir_m2*pow((tan_dir_m2 - tan_dir_view), 2.0)/pow((tan_dir_m2*tan_dir_view + 1.0), 3.0));
+ m[3] = pow(n_scale, 2.0)*(1.0/pow((tan_nick_m2*tan_nick_view + 1.0), 2.0)*(2.0*tan_nick_m2 - 2.0*tan_nick_view) + 2.0*tan_nick_m2*pow((tan_nick_m2 - tan_nick_view), 2.0)/pow((tan_nick_m2*tan_nick_view + 1.0), 3.0));
- m[5] = -2.0*n_scale*(pow((tan_dir_m2 - tan_dir_view), 2.0)/pow((tan_dir_m2*tan_dir_view + 1.0), 2.0) + pow((tan_nick_m2 - tan_nick_view), 2.0)/pow((tan_nick_m2*tan_nick_view + 1.0), 2.0));
+ m[4] = pow(n_scale, 2.0)*(1.0/pow((tan_dir_m2*tan_dir_view + 1.0), 2.0)*(2.0*tan_dir_m2 - 2.0*tan_dir_view) + 2.0*tan_dir_m2*pow((tan_dir_m2 - tan_dir_view), 2.0)/pow((tan_dir_m2*tan_dir_view + 1.0), 3.0));
- m[6] = 2.0*(n_scale*(tan_nick_m1 - tan_nick_view)/(tan_nick_m1*tan_nick_view + 1.0) - n_scale*(tan_nick_m2 - tan_nick_view)/(tan_nick_m2*tan_nick_view + 1.0))*(n_scale/(tan_nick_m1*tan_nick_view + 1.0) - n_scale/(tan_nick_m2*tan_nick_view + 1.0) + tan_nick_m1*n_scale*(tan_nick_m1 - tan_nick_view)/pow((tan_nick_m1*tan_nick_view + 1.0), 2.0) - tan_nick_m2*n_scale*(tan_nick_m2 - tan_nick_view)/pow((tan_nick_m2*tan_nick_view + 1.0),2.0));
+ m[5] = -2.0*n_scale*(pow((tan_dir_m2 - tan_dir_view), 2.0)/pow((tan_dir_m2*tan_dir_view + 1.0), 2.0) + pow((tan_nick_m2 - tan_nick_view), 2.0)/pow((tan_nick_m2*tan_nick_view + 1.0), 2.0));
- m[7] = 2.0*(n_scale*(tan_dir_m1 - tan_dir_view)/(tan_dir_m1*tan_dir_view + 1.0) - n_scale*(tan_dir_m2 - tan_dir_view)/(tan_dir_m2*tan_dir_view + 1.0))*(n_scale/(tan_dir_m1*tan_dir_view + 1.0) - n_scale/(tan_dir_m2*tan_dir_view + 1.0) + tan_dir_m1*n_scale*(tan_dir_m1 - tan_dir_view)/pow((tan_dir_m1*tan_dir_view + 1.0), 2.0) - tan_dir_m2*n_scale*(tan_dir_m2 - tan_dir_view)/pow((tan_dir_m2*tan_dir_view + 1.0), 2.0));
+ m[6] = 2.0*(n_scale*(tan_nick_m1 - tan_nick_view)/(tan_nick_m1*tan_nick_view + 1.0) - n_scale*(tan_nick_m2 - tan_nick_view)/(tan_nick_m2*tan_nick_view + 1.0))*(n_scale/(tan_nick_m1*tan_nick_view + 1.0) - n_scale/(tan_nick_m2*tan_nick_view + 1.0) + tan_nick_m1*n_scale*(tan_nick_m1 - tan_nick_view)/pow((tan_nick_m1*tan_nick_view + 1.0), 2.0) - tan_nick_m2*n_scale*(tan_nick_m2 - tan_nick_view)/pow((tan_nick_m2*tan_nick_view + 1.0),2.0));
- m[8] = - 2.0*(n_scale*(tan_dir_m1 - tan_dir_view)/(tan_dir_m1*tan_dir_view + 1.0) - n_scale*(tan_dir_m2 - tan_dir_view)/(tan_dir_m2*tan_dir_view + 1.0))*((tan_dir_m1 - tan_dir_view)/(tan_dir_m1*tan_dir_view + 1.0) - (tan_dir_m2 - tan_dir_view)/(tan_dir_m2*tan_dir_view + 1.0)) - 2.0*(n_scale*(tan_nick_m1 - tan_nick_view)/(tan_nick_m1*tan_nick_view + 1.0) - n_scale*(tan_nick_m2 - tan_nick_view)/(tan_nick_m2*tan_nick_view + 1.0))*((tan_nick_m1 - tan_nick_view)/(tan_nick_m1*tan_nick_view + 1.0) - (tan_nick_m2 - tan_nick_view)/(tan_nick_m2*tan_nick_view + 1.0));
+ m[7] = 2.0*(n_scale*(tan_dir_m1 - tan_dir_view)/(tan_dir_m1*tan_dir_view + 1.0) - n_scale*(tan_dir_m2 - tan_dir_view)/(tan_dir_m2*tan_dir_view + 1.0))*(n_scale/(tan_dir_m1*tan_dir_view + 1.0) - n_scale/(tan_dir_m2*tan_dir_view + 1.0) + tan_dir_m1*n_scale*(tan_dir_m1 - tan_dir_view)/pow((tan_dir_m1*tan_dir_view + 1.0), 2.0) - tan_dir_m2*n_scale*(tan_dir_m2 - tan_dir_view)/pow((tan_dir_m2*tan_dir_view + 1.0), 2.0));
- return 0;
+ m[8] = - 2.0*(n_scale*(tan_dir_m1 - tan_dir_view)/(tan_dir_m1*tan_dir_view + 1.0) - n_scale*(tan_dir_m2 - tan_dir_view)/(tan_dir_m2*tan_dir_view + 1.0))*((tan_dir_m1 - tan_dir_view)/(tan_dir_m1*tan_dir_view + 1.0) - (tan_dir_m2 - tan_dir_view)/(tan_dir_m2*tan_dir_view + 1.0)) - 2.0*(n_scale*(tan_nick_m1 - tan_nick_view)/(tan_nick_m1*tan_nick_view + 1.0) - n_scale*(tan_nick_m2 - tan_nick_view)/(tan_nick_m2*tan_nick_view + 1.0))*((tan_nick_m1 - tan_nick_view)/(tan_nick_m1*tan_nick_view + 1.0) - (tan_nick_m2 - tan_nick_view)/(tan_nick_m2*tan_nick_view + 1.0));
+
+ return 0;
}
static int opt_step(double *tan_nick_view,
- double *tan_dir_view,
- double *n_scale,
- double tan_dir_m1,
- double tan_nick_m1,
- double tan_dir_m2,
- double tan_nick_m2,
- double d_m1_2, double d_m2_2, double d_m1_m2_2) {
- double a[9];
- double b[3];
- double a_x0[3], f_x0 [3], x0[3];
- int ret;
+ double *tan_dir_view,
+ double *n_scale,
+ double tan_dir_m1,
+ double tan_nick_m1,
+ double tan_dir_m2,
+ double tan_nick_m2,
+ double d_m1_2, double d_m2_2, double d_m1_m2_2) {
+ double a[9];
+ double b[3];
+ double a_x0[3], f_x0 [3], x0[3];
+ int ret;
+
+ get_matrix(a, *tan_nick_view, *tan_dir_view, *n_scale,
+ tan_dir_m1, tan_nick_m1, tan_dir_m2, tan_nick_m2);
- get_matrix(a, *tan_nick_view, *tan_dir_view, *n_scale,
- tan_dir_m1, tan_nick_m1, tan_dir_m2, tan_nick_m2);
+ f_x0[0] = d_m1_2 - (pow((*tan_nick_view-tan_nick_m1),2.0)/pow((tan_nick_m1**tan_nick_view+1), 2.0)+pow((*tan_dir_view-tan_dir_m1),2.0)/pow((tan_dir_m1**tan_dir_view+1),2.0))*pow(*n_scale, 2.0);
- f_x0[0] = d_m1_2 - (pow((*tan_nick_view-tan_nick_m1),2.0)/pow((tan_nick_m1**tan_nick_view+1), 2.0)+pow((*tan_dir_view-tan_dir_m1),2.0)/pow((tan_dir_m1**tan_dir_view+1),2.0))*pow(*n_scale, 2.0);
+ f_x0[1] = d_m2_2 - (pow((*tan_nick_view-tan_nick_m2),2.0)/pow((tan_nick_m2**tan_nick_view+1),2.0)+pow((*tan_dir_view-tan_dir_m2),2.0)/pow((tan_dir_m2**tan_dir_view+1),2.0))*pow(*n_scale, 2.0);
- f_x0[1] = d_m2_2 - (pow((*tan_nick_view-tan_nick_m2),2.0)/pow((tan_nick_m2**tan_nick_view+1),2.0)+pow((*tan_dir_view-tan_dir_m2),2.0)/pow((tan_dir_m2**tan_dir_view+1),2.0))*pow(*n_scale, 2.0);
+ f_x0[2] = d_m1_m2_2 - (pow((- (((*tan_dir_view - tan_dir_m1) * *n_scale) / (tan_dir_m1 * *tan_dir_view + 1.0)) + (((*tan_dir_view - tan_dir_m2) * *n_scale) / (tan_dir_m2 * *tan_dir_view + 1))), 2.0) + pow((- (((*tan_nick_view - tan_nick_m1) * *n_scale) / (tan_nick_m1 * *tan_nick_view + 1)) + ((*tan_nick_view - tan_nick_m2) * *n_scale) / (tan_nick_m2 * *tan_nick_view + 1)), 2.0));
- f_x0[2] = d_m1_m2_2 - (pow((- (((*tan_dir_view - tan_dir_m1) * *n_scale) / (tan_dir_m1 * *tan_dir_view + 1.0)) + (((*tan_dir_view - tan_dir_m2) * *n_scale) / (tan_dir_m2 * *tan_dir_view + 1))), 2.0) + pow((- (((*tan_nick_view - tan_nick_m1) * *n_scale) / (tan_nick_m1 * *tan_nick_view + 1)) + ((*tan_nick_view - tan_nick_m2) * *n_scale) / (tan_nick_m2 * *tan_nick_view + 1)), 2.0));
+ x0[0] = *tan_nick_view;
+ x0[1] = *tan_dir_view;
+ x0[2] = *n_scale;
- x0[0] = *tan_nick_view;
- x0[1] = *tan_dir_view;
- x0[2] = *n_scale;
+ rmmult(a_x0, a, x0, 3, 3, 1);
- rmmult(a_x0, a, x0, 3, 3, 1);
-
- b[0] = a_x0[0] - f_x0[0];
- b[1] = a_x0[1] - f_x0[1];
- b[2] = a_x0[2] - f_x0[2];
+ b[0] = a_x0[0] - f_x0[0];
+ b[1] = a_x0[1] - f_x0[1];
+ b[2] = a_x0[2] - f_x0[2];
- ret = solv(a, b, 3);
+ ret = solv(a, b, 3);
- *tan_nick_view = b[0];
- *tan_dir_view = b[1];
- *n_scale = b[2];
+ *tan_nick_view = b[0];
+ *tan_dir_view = b[1];
+ *n_scale = b[2];
- return 0;
+ return 0;
}
static double
comp_tilt(double tan_nick_view, double tan_dir_view, double n_scale,
- double tan_nick_m, double tan_dir_m,
- double x, double y, double pi_d) {
- double y_tmp, x_tmp, sin_a_tilt1, sin_a_tilt2, sin_a_tilt, res;
+ double tan_nick_m, double tan_dir_m,
+ double x, double y, double pi_d) {
+ double y_tmp, x_tmp, sin_a_tilt1, sin_a_tilt2, sin_a_tilt, res;
- y_tmp = - (((tan_nick_view - tan_nick_m) * n_scale) /
- (tan_nick_m * tan_nick_view + 1));
- x_tmp = - (((tan_dir_view - tan_dir_m) * n_scale) /
- (tan_dir_m * tan_dir_view + 1));
+ y_tmp = - (((tan_nick_view - tan_nick_m) * n_scale) /
+ (tan_nick_m * tan_nick_view + 1));
+ x_tmp = - (((tan_dir_view - tan_dir_m) * n_scale) /
+ (tan_dir_m * tan_dir_view + 1));
- sin_a_tilt1 = - (y * - pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
- (x*x + y*y);
+ sin_a_tilt1 = - (y * - pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
+ (x*x + y*y);
- sin_a_tilt2 = - (y * pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
- (x*x + y*y);
+ sin_a_tilt2 = - (y * pow(x*x + y*y - y_tmp*y_tmp, 0.5) - x * y_tmp) /
+ (x*x + y*y);
- sin_a_tilt = fabs(sin_a_tilt1) < fabs(sin_a_tilt2)?sin_a_tilt1:sin_a_tilt2;
+ sin_a_tilt = fabs(sin_a_tilt1) < fabs(sin_a_tilt2)?sin_a_tilt1:sin_a_tilt2;
- res = asin(sin_a_tilt);
+ res = asin(sin_a_tilt);
- if (res > pi_d / 4.0) {
- res = res - pi_d / 2.0;
- } else if (res < -pi_d / 4.0) {
- res = res + pi_d / 2.0;
- }
+ if (res > pi_d / 4.0) {
+ res = res - pi_d / 2.0;
+ } else if (res < -pi_d / 4.0) {
+ res = res + pi_d / 2.0;
+ }
- return res;
+ return res;
}
diff --git a/src/Stitch.H b/src/Stitch.H
index 0bb6d48..49dd6b8 100644
--- a/src/Stitch.H
+++ b/src/Stitch.H
@@ -1,21 +1,8 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef STITCH_H
#define STITCH_H
@@ -25,19 +12,19 @@
#define MAX_PICS 256
-
+
class Stitch {
private:
GipfelWidget *gipf[MAX_PICS];
OutputImage *single_images[MAX_PICS];
OutputImage *merged_image;
-
+
public:
Stitch();
~Stitch();
-
+
int load_image(char *file);
OutputImage * set_output(OutputImage *img);
diff --git a/src/Stitch.cxx b/src/Stitch.cxx
index f8f77fb..f45bda4 100644
--- a/src/Stitch.cxx
+++ b/src/Stitch.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdlib.h>
#include <stdio.h>
@@ -91,12 +78,12 @@ Stitch::set_output(const char *file, OutputImage *img) {
int
Stitch::resample(int w, int h,
- double view_start, double view_end) {
+ double view_start, double view_end) {
double step_view = (view_end - view_start) / w;
uchar r, g, b;
int y_off = h / 2;
int merged_pixel_set;
- double radius = (double) w / (view_end -view_start);
+ double radius = (double) w / (view_end -view_start);
if (merged_image) {
merged_image->init(w, h);
diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H
index 3a14279..820a281 100644
--- a/src/TIFFOutputImage.H
+++ b/src/TIFFOutputImage.H
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef TIFFOUTPUTIMAGE_H
#define TIFFOUTPUTIMAGE_H
diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx
index b8433ca..cc1b289 100644
--- a/src/TIFFOutputImage.cxx
+++ b/src/TIFFOutputImage.cxx
@@ -1,21 +1,8 @@
-//
-// 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
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/ViewParams.H b/src/ViewParams.H
index 37c5e48..d321253 100644
--- a/src/ViewParams.H
+++ b/src/ViewParams.H
@@ -1,31 +1,18 @@
-//
-// Copyright 2005 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef VIEWPARAMS_H
#define VIEWPARAMS_H
class ViewParams {
- public:
- double a_center;
- double scale;
- double a_nick;
- double a_tilt;
+ public:
+ double a_center;
+ double scale;
+ double a_nick;
+ double a_tilt;
};
#endif
diff --git a/src/choose_hill.H b/src/choose_hill.H
index e424d70..2425fa3 100644
--- a/src/choose_hill.H
+++ b/src/choose_hill.H
@@ -1,21 +1,8 @@
//
-// Copyright 1998-2004 by Bill Spitzak and others.
-//
-// 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#ifndef CHOOSE_HILL_H
#define CHOOSE_HILL_H
diff --git a/src/choose_hill.cxx b/src/choose_hill.cxx
index f144d5e..879e18a 100644
--- a/src/choose_hill.cxx
+++ b/src/choose_hill.cxx
@@ -1,24 +1,8 @@
//
-// Search Chooser widget for the Fast Light Tool Kit (FLTK).
-//
-// Copyright 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.
-//
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <string.h>
@@ -27,30 +11,30 @@
Hill*
choose_hill(const Hills *hills, const char *l) {
- Fl_Search_Chooser *sc = new Fl_Search_Chooser(l?l:"Choose Hill");
- Hills *h_sort = new Hills(hills);
- Hill *ret;
-
- h_sort->sort_name();
-
- for (int i=0; i<h_sort->get_num(); i++) {
- Hill *m = h_sort->get(i);
- if (m->flags & (Hill::DUPLICATE | Hill::TRACK_POINT)) {
- continue;
- }
- sc->add(m->name, m);
- }
-
- delete h_sort;
-
- sc->show();
- while (sc->shown()) {
- Fl::wait();
- }
-
- ret = (Hill*) sc->data();
-
- delete(sc);
-
- return ret;
+ Fl_Search_Chooser *sc = new Fl_Search_Chooser(l?l:"Choose Hill");
+ Hills *h_sort = new Hills(hills);
+ Hill *ret;
+
+ h_sort->sort_name();
+
+ for (int i=0; i<h_sort->get_num(); i++) {
+ Hill *m = h_sort->get(i);
+ if (m->flags & (Hill::DUPLICATE | Hill::TRACK_POINT)) {
+ continue;
+ }
+ sc->add(m->name, m);
+ }
+
+ delete h_sort;
+
+ sc->show();
+ while (sc->shown()) {
+ Fl::wait();
+ }
+
+ ret = (Hill*) sc->data();
+
+ delete(sc);
+
+ return ret;
}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 1106c48..cf43af7 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -1,28 +1,14 @@
-//
-// gipfel program.
//
-// Copyright 2006 by Johannes Hofmann
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This program 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
-// General Public License for more details.
-//
-// You should have received a copy of the GNU 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.
+// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
+// This software may be used and distributed according to the terms
+// of the GNU General Public License, incorporated herein by reference.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+#include <math.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
@@ -56,8 +42,9 @@ char *img_file;
char *data_file = DEFAULT_DATAFILE;
GipfelWidget *gipf = NULL;
+Fl_Window *control_win, *view_win;
Fl_Dial *s_center = NULL;
-Fl_Slider *s_nick, *s_scale, *s_tilt, *s_height_dist, *s_track_width;
+Fl_Slider *s_nick, *s_focal_length, *s_tilt, *s_height_dist, *s_track_width;
Fl_Value_Input *i_view_lat, *i_view_long, *i_view_height;
Fl_Box *b_viewpoint;
Fl_Menu_Bar *mb;
@@ -66,426 +53,430 @@ Fl_Menu_Bar *mb;
#define STITCH_JPEG 2
#define STITCH_TIFF 4
static int stitch(int stitch_w, int stitch_h, int type, const char *path,
- int argc, char **argv);
+ int argc, char **argv);
void set_values() {
- s_center->value(gipf->get_center_angle());
- s_nick->value(gipf->get_nick_angle());
- s_scale->value(gipf->get_scale());
- s_tilt->value(gipf->get_tilt_angle());
- s_height_dist->value(gipf->get_height_dist_ratio());
- i_view_lat->value(gipf->get_view_lat());
- i_view_long->value(gipf->get_view_long());
- i_view_height->value(gipf->get_view_height());
- b_viewpoint->label(gipf->get_viewpoint());
- if (gipf->get_projection() == Projection::TANGENTIAL) {
- mb->mode(8, FL_MENU_RADIO|FL_MENU_VALUE);
- mb->mode(9, FL_MENU_RADIO);
- } else {
- mb->mode(9, FL_MENU_RADIO|FL_MENU_VALUE);
- mb->mode(8, FL_MENU_RADIO);
- }
+ s_center->value(gipf->get_center_angle());
+ s_nick->value(gipf->get_nick_angle());
+ s_focal_length->value(gipf->get_focal_length_35mm());
+ s_tilt->value(gipf->get_tilt_angle());
+ s_height_dist->value(gipf->get_height_dist_ratio());
+ i_view_lat->value(gipf->get_view_lat());
+ i_view_long->value(gipf->get_view_long());
+ i_view_height->value(gipf->get_view_height());
+ b_viewpoint->label(gipf->get_viewpoint());
+ if (gipf->get_projection() == Projection::TANGENTIAL) {
+ mb->mode(8, FL_MENU_RADIO|FL_MENU_VALUE);
+ mb->mode(9, FL_MENU_RADIO);
+ } else {
+ mb->mode(9, FL_MENU_RADIO|FL_MENU_VALUE);
+ mb->mode(8, FL_MENU_RADIO);
+ }
}
void quit_cb() {
- exit(0);
+ exit(0);
}
void open_cb() {
- char *file = fl_file_chooser("Open File?", "*.jpg", img_file);
- if(file != NULL) {
- gipf->load_image(file);
- set_values();
- }
+ char *file = fl_file_chooser("Open File?", "*.jpg", img_file);
+ if(file != NULL) {
+ gipf->load_image(file);
+ view_win->label(file);
+ control_win->label(file);
+ set_values();
+ }
}
void track_cb() {
- char *file = fl_file_chooser("Track File?", NULL, NULL);
- if (gipf->load_track(file) == 0) {
- s_track_width->activate();
- }
+ char *file = fl_file_chooser("Track File?", NULL, NULL);
+ if (gipf->load_track(file) == 0) {
+ s_track_width->activate();
+ }
}
void save_cb() {
- char *file = fl_file_chooser("Save Image As?", NULL, NULL);
- if (file) {
- gipf->save_image(file);
- }
+ char *file = fl_file_chooser("Save Image As?", NULL, NULL);
+ if (file) {
+ gipf->save_image(file);
+ }
}
-void scale_cb(Fl_Slider* o, void*) {
- gipf->set_scale(o->value());
+void focal_length_cb(Fl_Slider* o, void*) {
+ gipf->set_focal_length_35mm(o->value());
}
void angle_cb(Fl_Slider* o, void*) {
- gipf->set_center_angle(o->value());
+ gipf->set_center_angle(o->value());
}
void nick_cb(Fl_Slider* o, void*) {
- gipf->set_nick_angle(o->value());
+ gipf->set_nick_angle(o->value());
}
void tilt_cb(Fl_Slider* o, void*) {
- gipf->set_tilt_angle(o->value());
+ gipf->set_tilt_angle(o->value());
}
void h_d_cb(Fl_Slider* o, void*) {
- gipf->set_height_dist_ratio(o->value());
+ gipf->set_height_dist_ratio(o->value());
}
void view_lat_cb(Fl_Value_Input* o, void*) {
- gipf->set_view_lat(o->value());
+ gipf->set_view_lat(o->value());
}
void view_long_cb(Fl_Value_Input* o, void*) {
- gipf->set_view_long(o->value());
+ gipf->set_view_long(o->value());
}
void view_height_cb(Fl_Value_Input* o, void*) {
- gipf->set_view_height(o->value());
+ gipf->set_view_height(o->value());
}
void track_width_cb(Fl_Value_Input* o, void*) {
- gipf->set_track_width(o->value());
+ gipf->set_track_width(o->value());
}
void viewpoint_cb(Fl_Value_Input* o, void*) {
- Hill *m = choose_hill(gipf->get_mountains(), "Choose Viewpoint");
- if (m) {
- gipf->set_viewpoint(m);
- set_values();
- }
+ Hill *m = choose_hill(gipf->get_mountains(), "Choose Viewpoint");
+ if (m) {
+ gipf->set_viewpoint(m);
+ set_values();
+ }
}
void proj_cb(Fl_Value_Input* o, void*d) {
- if(d == NULL) {
- gipf->set_projection(Projection::TANGENTIAL);
- } else {
- gipf->set_projection(Projection::SPHAERIC);
- }
+ if(d == NULL) {
+ gipf->set_projection(Projection::TANGENTIAL);
+ } else {
+ gipf->set_projection(Projection::SPHAERIC);
+ }
}
void hidden_cb(Fl_Menu_* o, void*d) {
- gipf->set_show_hidden(o->mvalue()->value());
+ gipf->set_show_hidden(o->mvalue()->value());
}
void comp_cb(Fl_Widget *, void *) {
- gipf->comp_params();
- set_values();
+ gipf->comp_params();
+ set_values();
}
void guess_cb(Fl_Widget *, void *) {
- gipf->guess();
- set_values();
+ gipf->guess();
+ set_values();
}
void about_cb() {
- fl_message("gipfel -- and you know what you see.\n"
- "Version %s\n\n"
- "(c) Johannes Hofmann 2006\n\n"
- "Default datafile by http://www.alpin-koordinaten.de\n",
- VERSION);
+ fl_message("gipfel -- and you know what you see.\n"
+ "Version %s\n\n"
+ "(c) Johannes Hofmann 2006\n\n"
+ "Default datafile by http://www.alpin-koordinaten.de\n",
+ VERSION);
}
void fill_menubar(Fl_Menu_Bar* mb) {
- mb->add("&File/L&oad Image", FL_CTRL+'o', (Fl_Callback*)open_cb);
- mb->add("&File/&Save Image", FL_CTRL+'s', (Fl_Callback*)save_cb);
- mb->add("&File/Choose &Viewpoint", FL_CTRL+'v', (Fl_Callback*)viewpoint_cb);
- mb->add("&File/Load &Track", FL_CTRL+'t', (Fl_Callback*)track_cb);
- mb->add("&File/&Quit", FL_CTRL+'q', (Fl_Callback*)quit_cb);
-
+ mb->add("&File/L&oad Image", FL_CTRL+'o', (Fl_Callback*)open_cb);
+ mb->add("&File/&Save Image", FL_CTRL+'s', (Fl_Callback*)save_cb);
+ mb->add("&File/Choose &Viewpoint", FL_CTRL+'v', (Fl_Callback*)viewpoint_cb);
+ mb->add("&File/Load &Track", FL_CTRL+'t', (Fl_Callback*)track_cb);
+ mb->add("&File/&Quit", FL_CTRL+'q', (Fl_Callback*)quit_cb);
- mb->add("&Projection/Normal Projection", 0, (Fl_Callback *)proj_cb,
- (void *)0, FL_MENU_RADIO|FL_MENU_VALUE);
- mb->add("&Projection/Panoramic Projection", 0, (Fl_Callback *)proj_cb,
- (void *)1, FL_MENU_RADIO);
+ mb->add("&Projection/Normal Projection", 0, (Fl_Callback *)proj_cb,
+ (void *)0, FL_MENU_RADIO|FL_MENU_VALUE);
+ mb->add("&Projection/Panoramic Projection", 0, (Fl_Callback *)proj_cb,
+ (void *)1, FL_MENU_RADIO);
- mb->add("&Option/Show Hidden", 0, (Fl_Callback *) hidden_cb,
- (void *)0, FL_MENU_TOGGLE);
+ mb->add("&Option/Show Hidden", 0, (Fl_Callback *) hidden_cb,
+ (void *)0, FL_MENU_TOGGLE);
- mb->add("&Help/About", 0, (Fl_Callback*)about_cb);
+ mb->add("&Help/About", 0, (Fl_Callback*)about_cb);
}
void usage() {
- fprintf(stderr,
- "usage: gipfel [-v <viewpoint>] [-d <datafile>]\n"
- " [-s] [-j <outfile>] [-t <outdir] [-w <width>] [-h <height>]\n"
- " [<image(s)>]\n"
- " -v <viewpoint> Set point from which the picture was taken.\n"
- " This must be a string that unambiguously \n"
- " matches the name of an entry in the data file.\n"
- " -d <datafile> Use <datafile> for GPS data.\n"
- " -s Stitch mode.\n"
- " -w <width> Width of result image.\n"
- " -h <height> Height of result image.\n"
- " -j <outfile> JPEG output file for Stitch mode.\n"
- " -t <outdir> Output directory for TIFF images in Stitch mode.\n"
- " <image(s)> JPEG file(s) to use.\n");
+ fprintf(stderr,
+ "usage: gipfel [-v <viewpoint>] [-d <datafile>]\n"
+ " [-s] [-j <outfile>] [-t <outdir] [-w <width>] [-h <height>]\n"
+ " [<image(s)>]\n"
+ " -v <viewpoint> Set point from which the picture was taken.\n"
+ " This must be a string that unambiguously \n"
+ " matches the name of an entry in the data file.\n"
+ " -d <datafile> Use <datafile> for GPS data.\n"
+ " -s Stitch mode.\n"
+ " -w <width> Width of result image.\n"
+ " -h <height> Height of result image.\n"
+ " -j <outfile> JPEG output file for Stitch mode.\n"
+ " -t <outdir> Output directory for TIFF images in Stitch mode.\n"
+ " <image(s)> JPEG file(s) to use.\n");
}
Fl_Window *
create_control_window() {
- Fl_Window *win = new Fl_Window(400,350);
- mb = new Fl_Menu_Bar(0, 0, 400, 30);
- fill_menubar(mb);
-
- s_center = new Fl_Value_Dial(40, 60, 150, 150, NULL);
- s_center->type(FL_LINE_DIAL);
- s_center->labelsize(10);
- s_center->step(0.01);
- s_center->bounds(0.0, 360.0);
- s_center->angles(180, 540);
- s_center->callback((Fl_Callback*)angle_cb);
-
- Fl_Box *north = new Fl_Box(95, 40, 40, 20, "North");
- Fl_Box *south = new Fl_Box(95, 210, 40, 20, "South");
- Fl_Box *east = new Fl_Box(190, 125, 40, 20, "East");
- Fl_Box *west = new Fl_Box(0, 125, 40, 20, "West");
-
-
- s_scale = new Fl_Value_Slider(235, 60, 160, 15, "Scale");
- s_scale->type(1);
- s_scale->box(FL_THIN_DOWN_BOX);
- s_scale->labelsize(10);
- s_scale->step(5.0);
- s_scale->bounds(0.0, 10000.0);
- s_scale->slider(FL_UP_BOX);
- s_scale->callback((Fl_Callback*)scale_cb);
- s_scale->align(FL_ALIGN_TOP);
-
- s_nick = new Fl_Value_Slider(235, 90, 160, 15, "Nick (deg.)");
- s_nick->type(1);
- s_nick->box(FL_THIN_DOWN_BOX);
- s_nick->labelsize(10);
- s_nick->step(0.01);
- s_nick->bounds(-20.0, 20.0);
- s_nick->slider(FL_UP_BOX);
- s_nick->callback((Fl_Callback*)nick_cb);
- s_nick->align(FL_ALIGN_TOP);
-
- s_tilt = new Fl_Value_Slider(235, 120, 160, 15, "Tilt (deg.)");
- s_tilt->type(1);
- s_tilt->box(FL_THIN_DOWN_BOX);
- s_tilt->labelsize(10);
- s_tilt->step(0.01);
- s_tilt->bounds(-10.0, 10.0);
- s_tilt->slider(FL_UP_BOX);
- s_tilt->callback((Fl_Callback*)tilt_cb);
- s_tilt->align(FL_ALIGN_TOP);
-
- s_height_dist = new Fl_Value_Slider(235, 150, 160, 15, "Visibility");
- s_height_dist->type(1);
- s_height_dist->box(FL_THIN_DOWN_BOX);
- s_height_dist->labelsize(10);
- s_height_dist->step(-0.001);
- s_height_dist->bounds(0.1, 0.01);
- s_height_dist->slider(FL_UP_BOX);
- s_height_dist->callback((Fl_Callback*)h_d_cb);
- s_height_dist->align(FL_ALIGN_TOP);
-
- s_track_width = new Fl_Value_Slider(235, 180, 160, 15, "Track Width");
- s_track_width->type(1);
- s_track_width->box(FL_THIN_DOWN_BOX);
- s_track_width->labelsize(10);
- s_track_width->step(1.0);
- s_track_width->bounds(1.0, 500.0);
- s_track_width->value(200.0);
- s_track_width->slider(FL_UP_BOX);
- s_track_width->callback((Fl_Callback*)track_width_cb);
- s_track_width->align(FL_ALIGN_TOP);
- s_track_width->deactivate();
- // Viewpoint Stuff
-
- b_viewpoint = new Fl_Box(FL_DOWN_BOX, 30, 255, 300, 80, "");
- b_viewpoint->align(FL_ALIGN_TOP);
-
- i_view_lat = new Fl_Value_Input(40, 270, 100, 20, "Latitude");
- i_view_lat->labelsize(10);
- i_view_lat->align(FL_ALIGN_TOP);
- i_view_lat->when(FL_WHEN_ENTER_KEY);
- i_view_lat->callback((Fl_Callback*)view_lat_cb);
-
- i_view_long = new Fl_Value_Input(200, 270, 100, 20, "Longitude");
- i_view_long->labelsize(10);
- i_view_long->align(FL_ALIGN_TOP);
- i_view_long->when(FL_WHEN_ENTER_KEY);
- i_view_long->callback((Fl_Callback*)view_long_cb);
-
- i_view_height = new Fl_Value_Input(40, 310, 80, 20, "Height");
- i_view_height->labelsize(10);
- i_view_height->align(FL_ALIGN_TOP);
- i_view_height->when(FL_WHEN_ENTER_KEY);
- i_view_height->callback((Fl_Callback*)view_height_cb);
-
- // Buttons
- Fl_Button *b = new Fl_Button(240, 210, 60, 20, "comp");
- b->color(FL_RED);
- b->callback(comp_cb);
- Fl_Button *b1 = new Fl_Button(320, 210, 60, 20, "guess");
- b1->callback(guess_cb);
- b1->color(FL_GREEN);
-
- win->end();
- return win;
+ Fl_Window *win = new Fl_Window(400,350);
+ mb = new Fl_Menu_Bar(0, 0, 400, 30);
+ fill_menubar(mb);
+
+ s_center = new Fl_Value_Dial(40, 60, 150, 150, NULL);
+ s_center->type(FL_LINE_DIAL);
+ s_center->labelsize(10);
+ s_center->step(0.01);
+ s_center->bounds(0.0, 360.0);
+ s_center->angles(180, 540);
+ s_center->callback((Fl_Callback*)angle_cb);
+
+ Fl_Box *north = new Fl_Box(95, 40, 40, 20, "North");
+ Fl_Box *south = new Fl_Box(95, 210, 40, 20, "South");
+ Fl_Box *east = new Fl_Box(190, 125, 40, 20, "East");
+ Fl_Box *west = new Fl_Box(0, 125, 40, 20, "West");
+
+
+ s_focal_length = new Fl_Value_Slider(235, 60, 160, 15, "Focal Length in 35mm");
+ s_focal_length->type(1);
+ s_focal_length->box(FL_THIN_DOWN_BOX);
+ s_focal_length->labelsize(10);
+ s_focal_length->step(0.01);
+ s_focal_length->bounds(1.0, 300.0);
+ s_focal_length->slider(FL_UP_BOX);
+ s_focal_length->callback((Fl_Callback*)focal_length_cb);
+ s_focal_length->align(FL_ALIGN_TOP);
+
+ s_nick = new Fl_Value_Slider(235, 90, 160, 15, "Nick (deg.)");
+ s_nick->type(1);
+ s_nick->box(FL_THIN_DOWN_BOX);
+ s_nick->labelsize(10);
+ s_nick->step(0.01);
+ s_nick->bounds(-20.0, 20.0);
+ s_nick->slider(FL_UP_BOX);
+ s_nick->callback((Fl_Callback*)nick_cb);
+ s_nick->align(FL_ALIGN_TOP);
+
+ s_tilt = new Fl_Value_Slider(235, 120, 160, 15, "Tilt (deg.)");
+ s_tilt->type(1);
+ s_tilt->box(FL_THIN_DOWN_BOX);
+ s_tilt->labelsize(10);
+ s_tilt->step(0.01);
+ s_tilt->bounds(-10.0, 10.0);
+ s_tilt->slider(FL_UP_BOX);
+ s_tilt->callback((Fl_Callback*)tilt_cb);
+ s_tilt->align(FL_ALIGN_TOP);
+
+ s_height_dist = new Fl_Value_Slider(235, 150, 160, 15, "Visibility");
+ s_height_dist->type(1);
+ s_height_dist->box(FL_THIN_DOWN_BOX);
+ s_height_dist->labelsize(10);
+ s_height_dist->step(-0.001);
+ s_height_dist->bounds(0.1, 0.01);
+ s_height_dist->slider(FL_UP_BOX);
+ s_height_dist->callback((Fl_Callback*)h_d_cb);
+ s_height_dist->align(FL_ALIGN_TOP);
+
+ s_track_width = new Fl_Value_Slider(235, 180, 160, 15, "Track Width");
+ s_track_width->type(1);
+ s_track_width->box(FL_THIN_DOWN_BOX);
+ s_track_width->labelsize(10);
+ s_track_width->step(1.0);
+ s_track_width->bounds(1.0, 500.0);
+ s_track_width->value(200.0);
+ s_track_width->slider(FL_UP_BOX);
+ s_track_width->callback((Fl_Callback*)track_width_cb);
+ s_track_width->align(FL_ALIGN_TOP);
+ s_track_width->deactivate();
+ // Viewpoint Stuff
+
+ b_viewpoint = new Fl_Box(FL_DOWN_BOX, 30, 255, 300, 80, "");
+ b_viewpoint->align(FL_ALIGN_TOP);
+
+ i_view_lat = new Fl_Value_Input(40, 270, 100, 20, "Latitude");
+ i_view_lat->labelsize(10);
+ i_view_lat->align(FL_ALIGN_TOP);
+ i_view_lat->when(FL_WHEN_ENTER_KEY);
+ i_view_lat->callback((Fl_Callback*)view_lat_cb);
+
+ i_view_long = new Fl_Value_Input(200, 270, 100, 20, "Longitude");
+ i_view_long->labelsize(10);
+ i_view_long->align(FL_ALIGN_TOP);
+ i_view_long->when(FL_WHEN_ENTER_KEY);
+ i_view_long->callback((Fl_Callback*)view_long_cb);
+
+ i_view_height = new Fl_Value_Input(40, 310, 80, 20, "Height");
+ i_view_height->labelsize(10);
+ i_view_height->align(FL_ALIGN_TOP);
+ i_view_height->when(FL_WHEN_ENTER_KEY);
+ i_view_height->callback((Fl_Callback*)view_height_cb);
+
+ // Buttons
+ Fl_Button *b = new Fl_Button(240, 210, 60, 20, "comp");
+ b->color(FL_RED);
+ b->callback(comp_cb);
+ Fl_Button *b1 = new Fl_Button(320, 210, 60, 20, "guess");
+ b1->callback(guess_cb);
+ b1->color(FL_GREEN);
+
+ win->end();
+ return win;
}
int main(int argc, char** argv) {
- char c, *sep, *tmp, **my_argv;
- char *view_point = NULL;
- int err, bflag = 0, dflag = 0, my_argc;
- int stitch_flag = 0, stitch_w = 2000, stitch_h = 500;
- int jpeg_flag = 0, tiff_flag = 0;
- char *outpath;
- Fl_Window *control_win, *view_win;
- Fl_Scroll *scroll;
-
-
- err = 0;
- while ((c = getopt(argc, argv, "?d:v:sw:h:j:t:")) != EOF) {
- switch (c) {
- case '?':
- usage();
- exit(0);
- break;
- case 'd':
- data_file = optarg;
- break;
- case 'v':
- view_point = optarg;
- break;
- case 's':
- stitch_flag++;
- break;
- case 'j':
- jpeg_flag++;
- outpath = optarg;
- break;
- case 't':
- tiff_flag++;
- outpath = optarg;
- break;
- case 'w':
- stitch_w = atoi(optarg);
- break;
- case 'h':
- stitch_h = atoi(optarg);
- break;
- default:
- err++;
- }
- }
-
-
- my_argc = argc - optind;
- my_argv = argv + optind;
-
- if (my_argc >= 1) {
- img_file = my_argv[0];
- }
-
- if (data_file == NULL || err) {
- usage();
- exit(1);
- }
-
- if (stitch_flag) {
- int type = STITCH_PREVIEW;
- if (jpeg_flag) {
- type = STITCH_JPEG;
- } else if (tiff_flag) {
- type = STITCH_TIFF;
- }
- stitch(stitch_w, stitch_h, type, outpath, my_argc, my_argv);
- exit(0);
- }
-
- Fl::get_system_colors();
- if (getenv("FLTK_SCHEME")) {
- Fl::scheme(NULL);
- } else {
- Fl::scheme("plastic");
- }
-
- control_win = create_control_window();
-
- view_win = new Fl_Window(800, 600);
-
- // The Fl_Group is used to avoid FL_DAMAGE_ALL in Fl_Scroll::position
- Fl_Group *g = new Fl_Group(0, 0, view_win->w(), view_win->h());
- view_win->resizable(g);
- scroll = new Fl_Scroll(0, 0, view_win->w(), view_win->h());
-
- gipf = new GipfelWidget(0,0,800,600);
- if (img_file) {
- gipf->load_image(img_file);
- }
-
- view_win->size(gipf->w(), gipf->h());
- scroll->size(gipf->w(), gipf->h());
-
- gipf->load_data(data_file);
- scroll->end();
-
- set_values();
-
- view_win->resizable(scroll);
-
- view_win->end();
- view_win->show(1, argv);
- control_win->show(1, argv);
-
- if (view_point) {
- gipf->set_viewpoint(view_point);
- } else if (img_file &&
- gipf->get_view_lat()==0.0 && gipf->get_view_long()==0.0) {
- viewpoint_cb(NULL, NULL);
- }
-
- return Fl::run();
+ char c, *sep, *tmp, **my_argv;
+ char *view_point = NULL;
+ int err, bflag = 0, dflag = 0, my_argc;
+ int stitch_flag = 0, stitch_w = 2000, stitch_h = 500;
+ int jpeg_flag = 0, tiff_flag = 0;
+ char *outpath;
+ Fl_Scroll *scroll;
+
+
+ err = 0;
+ while ((c = getopt(argc, argv, "?d:v:sw:h:j:t:")) != EOF) {
+ switch (c) {
+ case '?':
+ usage();
+ exit(0);
+ break;
+ case 'd':
+ data_file = optarg;
+ break;
+ case 'v':
+ view_point = optarg;
+ break;
+ case 's':
+ stitch_flag++;
+ break;
+ case 'j':
+ jpeg_flag++;
+ outpath = optarg;
+ break;
+ case 't':
+ tiff_flag++;
+ outpath = optarg;
+ break;
+ case 'w':
+ stitch_w = atoi(optarg);
+ break;
+ case 'h':
+ stitch_h = atoi(optarg);
+ break;
+ default:
+ err++;
+ }
+ }
+
+
+ my_argc = argc - optind;
+ my_argv = argv + optind;
+
+ if (my_argc >= 1) {
+ img_file = my_argv[0];
+ }
+
+ if (data_file == NULL || err) {
+ usage();
+ exit(1);
+ }
+
+ if (stitch_flag) {
+ int type = STITCH_PREVIEW;
+ if (jpeg_flag) {
+ type = STITCH_JPEG;
+ } else if (tiff_flag) {
+ type = STITCH_TIFF;
+ }
+ stitch(stitch_w, stitch_h, type, outpath, my_argc, my_argv);
+ exit(0);
+ }
+
+ Fl::get_system_colors();
+ if (getenv("FLTK_SCHEME")) {
+ Fl::scheme(NULL);
+ } else {
+ Fl::scheme("plastic");
+ }
+
+ control_win = create_control_window();
+
+ view_win = new Fl_Window(800, 600);
+
+ // The Fl_Group is used to avoid FL_DAMAGE_ALL in Fl_Scroll::position
+ Fl_Group *g = new Fl_Group(0, 0, view_win->w(), view_win->h());
+ view_win->resizable(g);
+ scroll = new Fl_Scroll(0, 0, view_win->w(), view_win->h());
+
+ gipf = new GipfelWidget(0,0,800,600);
+ if (img_file) {
+ gipf->load_image(img_file);
+ view_win->label(img_file);
+ control_win->label(img_file);
+ }
+
+ view_win->size(gipf->w(), gipf->h());
+ scroll->size(gipf->w(), gipf->h());
+
+ gipf->load_data(data_file);
+ scroll->end();
+
+ set_values();
+
+ view_win->resizable(scroll);
+
+ view_win->end();
+ view_win->show(1, argv);
+ control_win->show(1, argv);
+
+ if (view_point) {
+ gipf->set_viewpoint(view_point);
+ } else if (img_file &&
+ (isnan(gipf->get_view_lat()) || isnan(gipf->get_view_long()))) {
+ viewpoint_cb(NULL, NULL);
+ }
+
+ return Fl::run();
}
static int stitch(int stitch_w, int stitch_h, int type, const char *path, int argc, char **argv) {
- Fl_Window *win;
- Fl_Scroll *scroll;
- Stitch *st = new Stitch();
-
- for (int i=0; i<argc; i++) {
- st->load_image(argv[i]);
- }
-
- if (type == STITCH_JPEG) {
-
- st->set_output((OutputImage*) new JPEGOutputImage(path, 90));
- st->resample(stitch_w, stitch_h, 0.0, 7.0);
-
- } else if (type == STITCH_TIFF) {
-
- for (int i=0; i<argc; i++) {
- char buf[1024];
- char *dot;
-
- snprintf(buf, sizeof(buf), "%s/%s", path, argv[i]);
- dot = strrchr(buf, '.');
- *dot = '\0';
- strncat(buf, ".tiff", sizeof(buf));
-
- st->set_output(argv[i], (OutputImage*) new TIFFOutputImage(buf));
- }
-
- st->resample(stitch_w, stitch_h, 0.0, 7.0);
-
- } else {
- win = new Fl_Window(0,0, stitch_w, stitch_h);
- scroll = new Fl_Scroll(0, 0, win->w(), win->h());
- PreviewOutputImage *img = new PreviewOutputImage(0, 0, stitch_w, stitch_h);
- win->resizable(scroll);
- win->show(0, argv);
- st->set_output((OutputImage*) img);
- st->resample(stitch_w, stitch_h, 0.0, 7.0);
- img->redraw();
- Fl::run();
- }
-
- return 0;
+ Fl_Window *win;
+ Fl_Scroll *scroll;
+ Stitch *st = new Stitch();
+
+ for (int i=0; i<argc; i++) {
+ st->load_image(argv[i]);
+ }
+
+ if (type == STITCH_JPEG) {
+
+ st->set_output((OutputImage*) new JPEGOutputImage(path, 90));
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
+
+ } else if (type == STITCH_TIFF) {
+
+ for (int i=0; i<argc; i++) {
+ char buf[1024];
+ char *dot;
+
+ snprintf(buf, sizeof(buf), "%s/%s", path, argv[i]);
+ dot = strrchr(buf, '.');
+ *dot = '\0';
+ strncat(buf, ".tiff", sizeof(buf));
+
+ st->set_output(argv[i], (OutputImage*) new TIFFOutputImage(buf));
+ }
+
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
+
+ } else {
+ win = new Fl_Window(0,0, stitch_w, stitch_h);
+ scroll = new Fl_Scroll(0, 0, win->w(), win->h());
+ PreviewOutputImage *img =
+ new PreviewOutputImage(0, 0, stitch_w, stitch_h);
+
+ win->resizable(scroll);
+ win->show(0, argv);
+ st->set_output((OutputImage*) img);
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
+ img->redraw();
+ Fl::run();
+ }
+
+ return 0;
}
diff --git a/src/panorama.c b/src/panorama.c
deleted file mode 100644
index 2c58c65..0000000
--- a/src/panorama.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * "$Id: panorama.c,v 1.8 2005/04/12 19:56:42 hofmann Exp $"
- *
- * flpsed program.
- *
- * Copyright 2004,2005 by Johannes Hofmann
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program 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
- * General Public License for more details.
- *
- * You should have received a copy of the GNU 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 <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-double pi, deg2rad;
-
-double distance(double phi_a, double lam_a, double phi_b, double lam_b);
-double sin_alpha(double lam_a, double lam_b, double phi_b, double c);
-double cos_alpha(double phi_a, double phi_b, double c);
-double alpha(double phi_a, double lam_a, double phi_b, double lam_b);
-double center_angle(double alph_a, double alph_b, double d1, double d2);
-int read_file(double phi_a, double lam_a, char *name,
- int dist, double h_d_ratio, double mm_per_deg,
- double a_center);
-int
-main(int argc, char **argv) {
- char c;
- char *sep, *tmp, *data_file = NULL;
- int errflg = 0;
- int dist = 100000;
- double phi_a, lam_a, phi_b, lam_b;
- double h_d_ratio = 0.1, mm_per_deg = 200.0, dist_c_m1 = 0.0;
- double dist_c_m2 = 0.0, a_center = 0.0;
- char *pos = NULL, *m1 = NULL, *m2 = NULL, *m_c = NULL;
-
- pi = asin(1.0) * 2.0;
- deg2rad = pi / 180.0;
-
- while ((c = getopt(argc, argv, "a:b:f:d:r:p:m:n:s:t:c:")) != EOF) {
- switch (c) {
- case 'a':
- tmp = strdup(optarg);
- if ((sep = strchr(tmp, ',')) == NULL) {
- errflg++;
- break;
- }
- *sep = '\0';
- phi_a = atof(tmp) * deg2rad;
- lam_a = atof(sep+1) * deg2rad;
- free(tmp);
- break;
- case 'b':
- tmp = strdup(optarg);
- if ((sep = strchr(tmp, ',')) == NULL) {
- usage();
- }
- *sep = '\0';
- phi_b = atof(tmp) * deg2rad;
- lam_b = atof(sep+1) * deg2rad;
- free(tmp);
- break;
- case 'f':
- data_file = optarg;
- break;
- case 'd':
- dist = atoi(optarg);
- break;
- case 'r':
- h_d_ratio = atof(optarg);
- break;
- case 's':
- dist_c_m1 = -atof(optarg);
- break;
- case 't':
- dist_c_m2 = -atof(optarg);
- break;
- case 'p':
- pos = optarg;
- break;
- case 'm':
- m1 = optarg;
- break;
- case 'n':
- m2 = optarg;
- break;
- case 'c':
- m_c = optarg;
- break;
- }
-}
-
-#if 0
- {
- double a1 = 0.0, a2 = 90.0;
- double d1 = -20.0, d2 = 10.0;
-
- fprintf(stderr, "==> %f\n", center_angle(a1*deg2rad, a2*deg2rad, d1, d2) / deg2rad);
- exit(1);
- }
-#endif
-
- if (errflg) {
- usage();
- exit(1);
- }
-
- if (!data_file) {
- usage();
- exit(1);
- }
-
- if (pos){
- int n = get_pos(data_file, pos, &phi_a, &lam_a);
- if (n == 0) {
- fprintf(stderr, "No matching entry for %s in datafile.\n",
- pos);
- exit(1);
- } else if (n > 1) {
- fprintf(stderr, "More than one matching entry for %s in datafile.\n",
- pos);
- exit(1);
- }
- }
-
- if (m1 && m2) {
- double phi, lam;
- double a1, a2, a;
- int n;
-
- n = get_pos(data_file, m1, &phi, &lam);
- if (n == 0) {
- fprintf(stderr, "No matching entry for %s in datafile.\n",
- m1);
- exit(1);
- } else if (n > 1) {
- fprintf(stderr, "More than one matching entry for %s in datafile.\n",
- m1);
- exit(1);
- }
- a1 = alpha(phi_a, lam_a, phi, lam);
-
- n = get_pos(data_file, m2, &phi, &lam);
- if (n == 0) {
- fprintf(stderr, "No matching entry for %s in datafile.\n",
- m2);
- exit(1);
- } else if (n > 1) {
- fprintf(stderr, "More than one matching entry for %s in datafile.\n",
- m2);
- exit(1);
- }
- a2 = alpha(phi_a, lam_a, phi, lam);
-
- a_center = center_angle(a1, a2, dist_c_m1, dist_c_m2);
- mm_per_deg = (dist_c_m1 - dist_c_m2) / (tan(a1 - a_center) - tan(a2 - a_center));
- fprintf(stderr, "center_angle = %f\n", a_center / deg2rad);
-
- }
-
-
-
- read_file(phi_a, lam_a, data_file, dist, h_d_ratio, mm_per_deg, a_center);
-}
-
-
-#define PS_HEADER "%!\n \
-/mountain { % expects name, height, dist, deg on stack\n \
- newpath % Start a new path\n \
- gsave % Keep rotations temporary\n \
- rotate % Rotate by degrees on stack\n \
- dup \n \
- 0 moveto \n \
- add % End line at 20 + dist + height\n \
- dup % Duplicate end of line pos\n \
- 0 lineto\n \
- 10 add % Start text 10 from end of line \n \
- 0 moveto\n \
- show\n \
- stroke\n \
- grestore % Get back the unrotated state\n \
-} def \n \
-/Times-Roman findfont \n \
-8 scalefont \n \
-setfont \n \
-300 344 translate\n \
-5 0 moveto\n \
-0 0 5 0 360 arc\n \
-stroke
-%11 0 moveto\n"
-
-
-#define PS_HEADER_PHOTO "%!\n \
- /mountain { % expects name, height, dist, deg on stack\n \
- newpath\n \
- 0.352778 div % convert from mm to PS points\n \
- dup\n \
- dup\n \
- 200 exch moveto\n \
- 500 exch lineto\n \
- 500 exch moveto\n \
- pop \n \
- pop \n \
- show\n \
- stroke\n \
-} def\n \
-\n \
- /Times-Roman findfont \n \
- 6 scalefont \n \
- setfont \n
- 0 420 translate \n"
-
-
-int get_pos(char *filename, char *name, double *phi, double *lam) {
- FILE *fp;
- char buf[1024];
- char *vals[10];
- char **ap, *bp;
- double height;
- int found = 0;
-
- fp = fopen(filename, "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;
-
- if (strstr(vals[1], name)) {
- *phi = atof(vals[3]) * deg2rad;
- *lam = atof(vals[4]) * deg2rad;
- height = atof(vals[5]);
- fprintf(stderr, "Found matching entry: %s (%fm)\n", vals[1], height);
- found++;
- }
- }
-
- fclose(fp);
- return found;
-}
-
-
-
-int read_file(double phi_a, double lam_a, char *name,
- int dist, double h_d_ratio, double mm_per_deg, double a_center) {
- FILE *fp;
- char buf[1024];
- char *vals[10];
- char **ap, *bp;
- double phi_b, lam_b, height, alph, dist_center;
-
- fp = fopen(name, "r");
- if (!fp) {
- perror("fopen");
- return 1;
- }
-
- printf("%s", PS_HEADER_PHOTO);
- printf("/mm_per_deg %f def\n", mm_per_deg);
- printf("/a_center %f def\n", a_center);
- while (fgets(buf, sizeof(buf), fp)) {
- bp = buf;
- for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;)
- if (++ap >= &vals[10])
- break;
-
- phi_b = atof(vals[3]) * deg2rad;
- lam_b = atof(vals[4]) * deg2rad;
-
- if (phi_a == phi_b && lam_a == lam_b) {
- continue;
- }
-
- height = atof(vals[5]);
-
- if (distance(phi_a, lam_a, phi_b, lam_b) * 6368000.0 > dist) {
- continue;
- }
-
-
- if (height / (distance(phi_a, lam_a, phi_b, lam_b)* 6368000) < h_d_ratio) {
- continue;
- }
-
- alph = alpha(phi_a, lam_a, phi_b, lam_b);
- alph = alph - a_center;
- if (alph > pi / 2.0 || alph < - pi /2.0) {
- continue;
- }
-
- dist_center = tan(alph) * mm_per_deg;
-
- printf("(%s) %f %f %f mountain\n", vals[1],
- height / 20.0,
- distance(phi_a, lam_a, phi_b, lam_b) * 25000.0,
- dist_center);
-
-
-#if 0
- printf("%f %f %s %fm\n",
- alpha(phi_a, lam_a, phi_b, lam_b),
- distance(phi_a, lam_a, phi_b, lam_b) * 6368000,
- vals[1],
- height);
-#endif
- }
-
- printf("showpage\n");
-
- fclose(fp);
- return 0;
-}
-
-
-double
-distance(double phi_a, double lam_a, double phi_b, double lam_b) {
- return acos(sin(phi_a)*sin(phi_b) + cos(phi_a)*cos(phi_b)*cos(lam_a - lam_b));
-}
-
-double
-sin_alpha(double lam_a, double lam_b, double phi_b, double c) {
- return sin(lam_b - lam_a) * cos(phi_b) / sin(c);
-}
-
-double
-cos_alpha(double phi_a, double phi_b, double c) {
- return (sin(phi_b) - sin(phi_a) * cos(c)) / (cos(phi_a) * sin(c));
-}
-
-double alpha(double phi_a, double lam_a, double phi_b, double lam_b) {
- double dist, sin_alph, cos_alph, alph;
-
- dist = distance(phi_a, lam_a, phi_b, lam_b);
- sin_alph = sin_alpha(lam_a, lam_b, phi_b, dist);
- cos_alph = cos_alpha(phi_a, phi_b, dist);
-
- if (sin_alph > 0) {
- alph = acos(cos_alph);
- } else {
- alph = 2.0 * pi - acos(cos_alph);
- }
-
- return alph;
-}
-
-double
-center_angle(double alph_a, double alph_b, double d1, double d2) {
- double tan_a, tan_b;
-
- fprintf(stderr, "a=%f, b=%f d1=%f d2=%f\n",
- alph_a / deg2rad, alph_b / deg2rad, d1, d2);
-
- 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);
-}
-
-void
-usage() {
- fprintf(stderr,
- "usage: panorama -a <phi>,<lambda>\n"
- " -b <phi>,<lambda>\n");
-}
diff --git a/src/util.c b/src/util.c
index f33c1b4..7a31712 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,26 +1,9 @@
-/*
- * "$Id: util.c,v 1.1 2005/02/28 17:56:51 hofmann Exp $"
+/*
+ * Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
*
- * flpsed program.
- *
- * Copyright 2005 by Johannes Hofmann
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program 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
- * General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
+ * This software may be used and distributed according to the terms
+ * of the GNU General Public License, incorporated herein by reference.
*/
-
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -29,48 +12,48 @@
FILE *
pexecvp(const char *file, char *const argv[], pid_t *pid, char *type) {
- FILE *iop;
- int pdes[2];
+ FILE *iop;
+ int pdes[2];
+
+ if (pipe(pdes) < 0) {
+ return NULL;
+ }
+
+ *pid = vfork();
- if (pipe(pdes) < 0) {
- return NULL;
- }
-
- *pid = vfork();
+ if (*pid == -1) {
+ perror("vfork");
+ close(pdes[0]);
+ close(pdes[1]);
+ return NULL;
+ } else if (*pid == 0) {
+ /* child */
- if (*pid == -1) {
- perror("vfork");
- close(pdes[0]);
- close(pdes[1]);
- return NULL;
- } else if (*pid == 0) {
- /* child */
-
- if (*type == 'r') {
- close(pdes[0]);
- if (pdes[1] != STDOUT_FILENO) {
- dup2(pdes[1], STDOUT_FILENO);
- close(pdes[1]);
- }
- } else {
- close(pdes[1]);
- if (pdes[0] != STDIN_FILENO) {
- dup2(pdes[0], STDIN_FILENO);
- close(pdes[0]);
- }
- }
+ if (*type == 'r') {
+ close(pdes[0]);
+ if (pdes[1] != STDOUT_FILENO) {
+ dup2(pdes[1], STDOUT_FILENO);
+ close(pdes[1]);
+ }
+ } else {
+ close(pdes[1]);
+ if (pdes[0] != STDIN_FILENO) {
+ dup2(pdes[0], STDIN_FILENO);
+ close(pdes[0]);
+ }
+ }
- execvp(file, argv);
- exit(127);
- } else {
- /* parent */
- if (*type == 'r') {
- iop = fdopen(pdes[0], "r");
- close(pdes[1]);
- } else {
- iop = fdopen(pdes[1], "w");
- close(pdes[0]);
- }
- return iop;
- }
+ execvp(file, argv);
+ exit(127);
+ } else {
+ /* parent */
+ if (*type == 'r') {
+ iop = fdopen(pdes[0], "r");
+ close(pdes[1]);
+ } else {
+ iop = fdopen(pdes[1], "w");
+ close(pdes[0]);
+ }
+ return iop;
+ }
}
diff --git a/src/util.h b/src/util.h
index d5a71e1..f30047e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,24 +1,8 @@
-/*
- * "$Id: util.h,v 1.2 2005/03/17 18:46:20 hofmann Exp $"
+/*
+ * Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
*
- * flpsed program.
- *
- * Copyright 2005 by Johannes Hofmann
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program 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
- * General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
+ * This software may be used and distributed according to the terms
+ * of the GNU General Public License, incorporated herein by reference.
*/
#ifndef _UTIL_H_
#define _UTIL_H_
@@ -29,8 +13,8 @@
extern "C" {
#endif
-FILE *
-pexecvp(const char *file, char *const argv[], pid_t *pid, char *type);
+ FILE *
+ pexecvp(const char *file, char *const argv[], pid_t *pid, char *type);
#ifdef __cplusplus
}