summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Fl_Search_Chooser.H30
-rw-r--r--src/Fl_Search_Chooser.cxx117
-rw-r--r--src/Fl_Value_Dial.H26
-rw-r--r--src/Fl_Value_Dial.cxx90
-rw-r--r--src/GipfelWidget.H122
-rw-r--r--src/GipfelWidget.cxx916
-rw-r--r--src/Hill.H96
-rw-r--r--src/Hill.cxx396
-rw-r--r--src/Panorama.H140
-rw-r--r--src/Panorama.cxx698
-rw-r--r--src/Projection.H24
-rw-r--r--src/Projection.cxx10
-rw-r--r--src/ProjectionSphaeric.H18
-rw-r--r--src/ProjectionSphaeric.cxx198
-rw-r--r--src/ProjectionTangential.H20
-rw-r--r--src/ProjectionTangential.cxx410
-rw-r--r--src/Stitch.H6
-rw-r--r--src/Stitch.cxx4
-rw-r--r--src/ViewParams.H10
-rw-r--r--src/choose_hill.cxx52
-rw-r--r--src/util.c82
-rw-r--r--src/util.h4
22 files changed, 1734 insertions, 1735 deletions
diff --git a/src/Fl_Search_Chooser.H b/src/Fl_Search_Chooser.H
index 821ffdd..e968452 100644
--- a/src/Fl_Search_Chooser.H
+++ b/src/Fl_Search_Chooser.H
@@ -12,27 +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;
+ private:
+ public:
+ Fl_Window *w;
+ Fl_Search_Browser *sb;
- Fl_Search_Chooser(const char *title);
+ Fl_Search_Chooser(const char *title);
- void add(const char *t, void *d);
- void *data();
- void show();
- int shown();
+ 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 d9bc92c..d4f93b2 100644
--- a/src/Fl_Search_Chooser.cxx
+++ b/src/Fl_Search_Chooser.cxx
@@ -13,98 +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();
+ 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 35a3adf..94fda5a 100644
--- a/src/Fl_Value_Dial.H
+++ b/src/Fl_Value_Dial.H
@@ -10,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 773cb58..f210ca3 100644
--- a/src/Fl_Value_Dial.cxx
+++ b/src/Fl_Value_Dial.cxx
@@ -10,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 4b3166e..adbb623 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -12,108 +12,108 @@
#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,
- char *r, char *g, char *b);
+ static int get_pixel_nearest(Fl_Image *img, double x, double y,
+ char *r, char *g, char *b);
- static int get_pixel(Fl_Image *img, int x, int y,
- char *r, char *g, char *b);
+ static int get_pixel(Fl_Image *img, int x, int y,
+ char *r, char *g, char *b);
- public:
- GipfelWidget(int X,int Y,int W, int H);
+ public:
+ GipfelWidget(int X,int Y,int W, int H);
- void center();
+ void center();
- int load_image(char *file);
+ int load_image(char *file);
- int save_image(char *file);
-
- const char * get_image_filename();
+ int save_image(char *file);
- int load_data(const char *file);
+ const char * get_image_filename();
- int load_track(const char *file);
+ int load_data(const char *file);
- int set_viewpoint(const char *pos);
+ int load_track(const char *file);
- void set_viewpoint(const Hill *m);
+ int set_viewpoint(const char *pos);
- void set_center_angle(double a);
+ void set_viewpoint(const Hill *m);
- void set_nick_angle(double a);
+ void set_center_angle(double a);
- void set_tilt_angle(double a);
+ void set_nick_angle(double a);
- void set_focal_length_35mm(double s);
+ void set_tilt_angle(double a);
- void set_height_dist_ratio(double r);
+ void set_focal_length_35mm(double s);
- void set_hide_value(double h);
+ void set_height_dist_ratio(double r);
- void set_show_hidden(int h);
+ void set_hide_value(double h);
- void set_view_lat(double v);
+ void set_show_hidden(int h);
- void set_view_long(double v);
+ void set_view_lat(double v);
- void set_view_height(double v);
-
- const char * get_viewpoint();
+ void set_view_long(double v);
- double get_center_angle();
+ void set_view_height(double v);
- double get_nick_angle();
+ const char * get_viewpoint();
- double get_tilt_angle();
+ double get_center_angle();
- double get_focal_length_35mm();
+ double get_nick_angle();
- double get_height_dist_ratio();
+ double get_tilt_angle();
- double get_view_lat();
+ double get_focal_length_35mm();
- double get_view_long();
+ double get_height_dist_ratio();
- double get_view_height();
+ double get_view_lat();
- void set_track_width(double w);
+ double get_view_long();
- Projection::Projection_t get_projection();
+ double get_view_height();
- void set_projection(Projection::Projection_t p);
+ void set_track_width(double w);
- Hills *get_mountains();
+ Projection::Projection_t get_projection();
- int comp_params();
+ void set_projection(Projection::Projection_t p);
- int guess();
+ Hills *get_mountains();
- int update();
+ int comp_params();
- int get_pixel(double a_view, double a_nick,
- char *r, char *g, char *b);
+ int guess();
- void draw();
+ int update();
+
+ int get_pixel(double a_view, double a_nick,
+ char *r, char *g, char *b);
+
+ void draw();
};
#endif
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 2927cde..23cb075 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -37,75 +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();
+ 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) {
- Fl_Image *new_img;
- ImageMetaData *md;
- int ret;
+ Fl_Image *new_img;
+ ImageMetaData *md;
+ int ret;
+
+ new_img = new Fl_JPEG_Image(file);
+
+ if (new_img == NULL) {
+ return 1;
+ }
- new_img = new Fl_JPEG_Image(file);
-
- if (new_img == NULL) {
- return 1;
- }
+ if (img) {
+ delete img;
+ }
- if (img) {
- delete img;
- }
+ img = new_img;
- img = new_img;
-
- if (img_file) {
- free(img_file);
- }
+ if (img_file) {
+ free(img_file);
+ }
- img_file = strdup(file);
+ img_file = strdup(file);
- h(img->h());
- w(img->w());
+ 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);
+ 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());
+ // 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;
+ delete md;
- return 0;
+ return 0;
}
const char *
@@ -115,557 +115,557 @@ GipfelWidget::get_image_filename() {
int
GipfelWidget::save_image(char *file) {
- ImageMetaData *md;
- int ret;
+ ImageMetaData *md;
+ int ret;
- if (img_file == NULL) {
- fprintf(stderr, "Nothing to save\n");
- return 1;
- }
+ if (img_file == NULL) {
+ fprintf(stderr, "Nothing to save\n");
+ return 1;
+ }
- md = new ImageMetaData();
+ 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());
+ 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;
+ ret = md->save_image(img_file, file);
+ delete md;
- return ret;
+ 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();
- pan->add_hills(track_points);
- redraw();
-
- return 0;
+ 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);
- }
-
- redraw();
- return 0;
- }
- }
+ 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);
+ }
+
+ 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_focal_length_35mm(double s) {
- pan->set_scale(s * (double) img->w() / 35.0);
- set_labels(pan->get_visible_mountains());
- redraw();
+ 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_focal_length_35mm() {
- return pan->get_scale() * 35.0 / (double) img->w();
+ 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,
- char *r, char *g, char *b) {
+ char *r, char *g, char *b) {
double px, py;
@@ -678,7 +678,7 @@ GipfelWidget::get_pixel(double a_view, double a_nick,
}
return get_pixel_nearest(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
@@ -694,40 +694,40 @@ GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
int
GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
- char *r, char *g, char *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;
+ char *r, char *g, char *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:
+ *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 37ab44a..2e95def 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -11,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();
+ public:
+ Hills();
- Hills(const Hills *h);
+ Hills(const Hills *h);
- ~Hills();
+ ~Hills();
- int load(const char *file);
+ int load(const char *file);
- void mark_duplicates(double dist);
+ void mark_duplicates(double dist);
- void add(Hill *m);
+ void add(Hill *m);
- void add(Hills *h);
+ void add(Hills *h);
- void sort_phi();
+ void sort_phi();
- void sort_name();
+ void sort_name();
- void sort();
-
- void clear();
+ void sort();
- void clobber();
+ void clear();
- int get_num();
-
- Hill *get(int n);
+ void clobber();
+
+ int get_num();
+
+ Hill *get(int n);
};
#endif
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 14b8f81..d5ce1f6 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -14,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/Panorama.H b/src/Panorama.H
index 80a8f69..81cdf8e 100644
--- a/src/Panorama.H
+++ b/src/Panorama.H
@@ -14,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;
- void update_angles();
+ Hill * get_pos(const char *name);
- void update_coordinates();
+ void update_angles();
- void update_close_mountains();
+ void update_coordinates();
- void update_visible_mountains();
-
- void mark_hidden(Hills *hills);
+ void update_close_mountains();
- double distance(double phi, double lam);
+ void update_visible_mountains();
- double sin_alpha(double lam, double phi, double c);
+ 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 comp_center_angle(double alph_a, double alph_b, double d1, double d2);
+ double cos_alpha(double phi, double c);
- double comp_scale(double alph_a, double alph_b, double d1, double d2);
+ double alpha(double phi, double lam);
- int get_matrix(double m[]);
+ double nick(double dist, double height);
- int optimize(Hill *m1, Hill *m2);
+ double comp_center_angle(double alph_a, double alph_b, double d1, double d2);
- double get_value(Hills *p);
+ double comp_scale(double alph_a, double alph_b, double d1, double d2);
- double pi_d, deg2rad;
+ int get_matrix(double m[]);
- public:
- Panorama();
+ int optimize(Hill *m1, Hill *m2);
- ~Panorama();
-
- int load_data(const char *name);
+ double get_value(Hills *p);
- void add_hills(Hills *h);
+ double pi_d, deg2rad;
- void remove_trackpoints();
+ public:
+ Panorama();
- int set_viewpoint(const char *pos);
+ ~Panorama();
- void set_viewpoint(const Hill *m);
+ int load_data(const char *name);
- void set_height_dist_ratio(double r);
+ void add_hills(Hills *h);
- void set_hide_value(double h);
+ void remove_trackpoints();
- Hills * get_mountains();
+ int set_viewpoint(const char *pos);
- Hills * get_close_mountains();
+ void set_viewpoint(const Hill *m);
- Hills * get_visible_mountains();
+ void set_height_dist_ratio(double r);
- void set_center_angle(double a);
+ void set_hide_value(double h);
- void set_nick_angle(double a);
+ Hills * get_mountains();
- void set_tilt_angle(double a);
+ Hills * get_close_mountains();
- void set_scale(double s);
+ Hills * get_visible_mountains();
- void set_view_lat(double v);
+ void set_center_angle(double a);
- void set_view_long(double v);
+ void set_nick_angle(double a);
- void set_view_height(double v);
+ void set_tilt_angle(double a);
- const char * get_viewpoint();
+ void set_scale(double s);
- double get_center_angle();
+ void set_view_lat(double v);
- double get_nick_angle();
+ void set_view_long(double v);
- double get_tilt_angle();
+ void set_view_height(double v);
- double get_scale();
+ const char * get_viewpoint();
- double get_height_dist_ratio();
-
- double get_view_lat();
+ double get_center_angle();
- double get_view_long();
+ double get_nick_angle();
- double get_view_height();
+ double get_tilt_angle();
- double get_earth_radius(Hill *m);
+ double get_scale();
- double get_real_distance(Hill *m);
+ double get_height_dist_ratio();
- int comp_params(Hill *m1, Hill *m2);
+ double get_view_lat();
- int guess(Hills *p1, Hill *m1);
+ double get_view_long();
- Projection::Projection_t get_projection();
+ double get_view_height();
- void set_projection(Projection::Projection_t p);
+ double get_earth_radius(Hill *m);
- int get_coordinates(double a_view, double a_nick, double *x, double *y);
+ double get_real_distance(Hill *m);
+
+ int comp_params(Hill *m1, Hill *m2);
+
+ int guess(Hills *p1, Hill *m1);
+
+ Projection::Projection_t get_projection();
+
+ void set_projection(Projection::Projection_t p);
+
+ 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 4674c47..4ecf2f4 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -16,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;
+
+ if (view_name) {
+ free(view_name);
+ }
- view_name = strdup(m->name);
+ view_name = strdup(m->name);
- update_angles();
+ 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) {
- mountains->sort();
+ m->alph = alpha(m->phi, m->lam);
+ m->a_nick = nick(m->dist, m->height);
+ }
+ }
- update_close_mountains();
+
+ mountains->sort();
+
+ 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);
- 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))) {
+ 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);
- }
- }
+ 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;
- if (sin_alph > 0) {
- alph = acos(cos_alph);
- } else {
- alph = 2.0 * pi_d - acos(cos_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 (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/Projection.H b/src/Projection.H
index 6db0e97..3bc816e 100644
--- a/src/Projection.H
+++ b/src/Projection.H
@@ -11,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 int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms);
+ virtual void get_coordinates(double a_view, double a_nick,
+ const ViewParams *parms, double *x, double *y);
+
+ virtual int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms);
};
#endif
diff --git a/src/Projection.cxx b/src/Projection.cxx
index 88ec5bf..02674a7 100644
--- a/src/Projection.cxx
+++ b/src/Projection.cxx
@@ -10,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 f80940a..c6ce5f4 100644
--- a/src/ProjectionSphaeric.H
+++ b/src/ProjectionSphaeric.H
@@ -11,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 d4e7e43..96af4e0 100644
--- a/src/ProjectionSphaeric.cxx
+++ b/src/ProjectionSphaeric.cxx
@@ -14,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 07ddaf9..13e354a 100644
--- a/src/ProjectionTangential.H
+++ b/src/ProjectionTangential.H
@@ -11,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);
-
- int comp_params(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);
+
+ int comp_params(const Hill *m1, const Hill *m2, ViewParams *parms);
};
#endif
diff --git a/src/ProjectionTangential.cxx b/src/ProjectionTangential.cxx
index 230767c..8eed552 100644
--- a/src/ProjectionTangential.cxx
+++ b/src/ProjectionTangential.cxx
@@ -15,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);
-
- 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)));
+ tan_a1 = tan(a1);
+ tan_a2 = tan(a2);
- return sc;
+ 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;
}
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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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;
+ 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 d29c2e9..49dd6b8 100644
--- a/src/Stitch.H
+++ b/src/Stitch.H
@@ -12,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 f378747..7e8f909 100644
--- a/src/Stitch.cxx
+++ b/src/Stitch.cxx
@@ -78,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;
char 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/ViewParams.H b/src/ViewParams.H
index b6f34a2..d321253 100644
--- a/src/ViewParams.H
+++ b/src/ViewParams.H
@@ -8,11 +8,11 @@
#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.cxx b/src/choose_hill.cxx
index d3477f3..879e18a 100644
--- a/src/choose_hill.cxx
+++ b/src/choose_hill.cxx
@@ -11,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/util.c b/src/util.c
index df3126d..7a31712 100644
--- a/src/util.c
+++ b/src/util.c
@@ -12,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;
+ }
- 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]);
- }
- }
+ *pid = vfork();
- 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;
- }
+ 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]);
+ }
+ }
+
+ 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 ad0e423..f30047e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -13,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
}