summaryrefslogtreecommitdiff
path: root/src/GipfelWidget.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/GipfelWidget.cxx')
-rw-r--r--src/GipfelWidget.cxx122
1 files changed, 65 insertions, 57 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 00c5aad..e1dad77 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -46,8 +46,7 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
cur_mountain = NULL;
mb = NULL;
marker = new Hills();
- m1 = NULL;
- m2 = NULL;
+ known_hills = new Hills();
img_file = NULL;
track_width = 200.0;
show_hidden = 0;
@@ -102,7 +101,8 @@ GipfelWidget::load_image(char *file) {
set_tilt_angle(md->get_tilt());
set_projection((Projection::Projection_t) md->get_projection_type());
set_focal_length_35mm(md->get_focal_length_35mm());
-
+ md->get_distortion_params(&pan->parms.k0, &pan->parms.k1);
+ fprintf(stderr, "%f %f\n", pan->parms.k0, pan->parms.k1);
delete md;
return 0;
@@ -133,6 +133,7 @@ GipfelWidget::save_image(char *file) {
md->set_tilt(get_tilt_angle());
md->set_focal_length_35mm(get_focal_length_35mm());
md->set_projection_type((int) get_projection());
+ md->set_distortion_params(pan->parms.k0, pan->parms.k1);
ret = md->save_image(img_file, file);
delete md;
@@ -211,8 +212,6 @@ void
GipfelWidget::draw() {
Hills *mnts;
Hill *m;
- int center_x = w() / 2;
- int center_y = h() / 2;
int i;
if (img == NULL) {
@@ -227,6 +226,8 @@ GipfelWidget::draw() {
mnts = pan->get_visible_mountains();
for (i=0; i<mnts->get_num(); i++) {
m = mnts->get(i);
+ int m_x = w() / 2 + x() + (int) rint(m->x);
+ int m_y = h() / 2 + y() + (int) rint(m->y);
if (m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) {
continue;
@@ -236,34 +237,19 @@ GipfelWidget::draw() {
continue;
}
- if (m == m1) {
+ if (known_hills->contains(m)) {
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");
+ draw_flag(m_x, m_y, "1");
} 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_xyline(m_x- CROSS_SIZE, m_y, m_x + CROSS_SIZE);
+ fl_yxline(m_x, m_y + m->label_y - CROSS_SIZE, m_y + CROSS_SIZE);
- 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);
+ fl_draw(m->name, m_x , m_y + m->label_y);
}
/* track */
@@ -271,6 +257,9 @@ GipfelWidget::draw() {
int last_x, last_y, last_initialized = 0;
for (i=1; i<track_points->get_num(); i++) {
+ m = mnts->get(i);
+ int m_x = w() / 2 + x() + (int) rint(m->x);
+ int m_y = h() / 2 + y() + (int) rint(m->y);
if (!(track_points->get(i)->flags & Hill::VISIBLE)) {
continue;
}
@@ -285,14 +274,13 @@ GipfelWidget::draw() {
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_vertex(last_x, last_y);
+ fl_vertex(m_x, m_y);
fl_end_line();
}
- last_x = track_points->get(i)->x;
- last_y = track_points->get(i)->y;
+ last_x = m_x;
+ last_y = m_y;
last_initialized++;
}
fl_line_style(0);
@@ -303,7 +291,7 @@ GipfelWidget::draw() {
static int
-overlap(int m1, int n1, int m2, int n2) {
+overlap(double m1, double n1, double m2, double n2) {
return m1 <= n2 && n1 >= m2;
}
@@ -354,6 +342,28 @@ GipfelWidget::set_labels(Hills *v) {
int
GipfelWidget::set_cur_mountain(int m_x, int m_y) {
+ Hill *m;
+ int center_x = w() / 2;
+ int center_y = h() / 2;
+ int i;
+
+ for (i=0; i<known_hills->get_num(); i++) {
+ m = known_hills->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;
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+
+int
+GipfelWidget::toggle_known_mountain(int m_x, int m_y) {
Hills *mnts = pan->get_visible_mountains();
Hill *m;
int center_x = w() / 2;
@@ -368,19 +378,12 @@ GipfelWidget::set_cur_mountain(int m_x, int m_y) {
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);
+
+ if (known_hills->contains(m)) {
+ known_hills->remove(m);
+ } else {
+ known_hills->add(m);
}
redraw();
@@ -524,11 +527,11 @@ 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;
+
+ if (!known_hills->contains(m)) {
+ known_hills->add(m);
}
+
}
}
@@ -589,12 +592,12 @@ GipfelWidget::get_mountains() {
int
GipfelWidget::comp_params() {
- if (m1 == NULL || m2 == NULL) {
+ if (known_hills->get_num() < 2) {
fprintf(stderr, "Position m1 and m2 first.\n");
return 1;
}
fl_cursor(FL_CURSOR_WAIT);
- pan->comp_params(m1, m2);
+ pan->comp_params(known_hills);
set_labels(pan->get_visible_mountains());
redraw();
fl_cursor(FL_CURSOR_DEFAULT);
@@ -602,12 +605,12 @@ GipfelWidget::comp_params() {
int
GipfelWidget::guess() {
- if (m1 == NULL) {
+ if (known_hills->get_num() < 1) {
fprintf(stderr, "Position m1 first.\n");
return 1;
}
fl_cursor(FL_CURSOR_WAIT);
- pan->guess(marker, m1);
+ pan->guess(marker, known_hills->get(0));
set_labels(pan->get_visible_mountains());
redraw();
fl_cursor(FL_CURSOR_DEFAULT);
@@ -639,20 +642,25 @@ GipfelWidget::handle(int event) {
switch(event) {
case FL_PUSH:
+ mark_x = Fl::event_x()-x();
+ mark_y = Fl::event_y()-y();
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;
+ } else if (Fl::event_button() == 2) {
+ toggle_known_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_RELEASE:
+ cur_mountain = NULL;
+ return 1;
+ break;
case FL_FOCUS:
return 1;
break;