summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-12-18 22:11:00 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-12-18 22:11:00 +0100
commit4b2dc2ab9526ccca3cc6a0a7d85e9236b7ed3582 (patch)
tree210946ecf21d42100bcf9ded155f63a11462a7e7
parent7872b3cd1f6d1ee55f9b5fc772fe5463bd3c647e (diff)
add distortion profile handling
-rw-r--r--src/GipfelWidget.H9
-rw-r--r--src/GipfelWidget.cxx58
-rw-r--r--src/ImageMetaData.H1
-rw-r--r--src/ImageMetaData.cxx23
-rw-r--r--src/gipfel.cxx40
5 files changed, 119 insertions, 12 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index a3f9ed7..fa82803 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -10,6 +10,7 @@
#include <FL/Fl_Widget.H>
#include <FL/Fl_Menu_Button.H>
#include "Panorama.H"
+#include "ImageMetaData.H"
class GipfelWidget : public Fl_Widget {
private:
@@ -22,6 +23,8 @@ class GipfelWidget : public Fl_Widget {
Fl_Menu_Button *mb;
char *img_file;
double track_width;
+ ImageMetaData *md;
+
int show_hidden;
int handle(int event);
@@ -124,6 +127,12 @@ class GipfelWidget : public Fl_Widget {
int get_pixel(GipfelWidget::sample_mode_t,
double a_alph, double a_nick, uchar *r, uchar *g, uchar *b);
+ int get_distortion_profile_name(char *buf, int buflen);
+
+ int save_distortion_params(const char *prof_name);
+
+ int load_distortion_params(const char *prof_name);
+
void draw();
};
#endif
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 1c1ad92..e80d94c 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -20,9 +20,9 @@
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_JPEG_Image.H>
+#include <FL/Fl_Preferences.H>
#include <FL/fl_draw.H>
-#include "ImageMetaData.H"
#include "Fl_Search_Chooser.H"
#include "choose_hill.H"
#include "GipfelWidget.H"
@@ -50,6 +50,7 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
img_file = NULL;
track_width = 200.0;
show_hidden = 0;
+ md = new ImageMetaData();
for (i=0; i<=3; i++) {
marker->add(new Hill(i * 10, 0));
@@ -61,7 +62,6 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
int
GipfelWidget::load_image(char *file) {
Fl_Image *new_img;
- ImageMetaData *md;
new_img = new Fl_JPEG_Image(file);
@@ -90,7 +90,6 @@ GipfelWidget::load_image(char *file) {
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());
@@ -100,9 +99,22 @@ GipfelWidget::load_image(char *file) {
set_tilt_angle(md->get_tilt());
set_projection((ProjectionLSQ::Projection_t) md->get_projection_type());
set_focal_length_35mm(md->get_focal_length_35mm());
+
+ // try to get distortion parameters in the following ordering:
+ // 1. gipfel data in JPEG comment
+ // 2. matching distortion profile
+ // 3. set the to 0.0, 0.0
md->get_distortion_params(&pan->parms.k0, &pan->parms.k1);
+ if (isnan(pan->parms.k0)) {
+ char buf[1024];
+ get_distortion_profile_name(buf, sizeof(buf));
+ load_distortion_params(buf);
+ if (isnan(pan->parms.k0)) {
+ pan->parms.k0 = 0.0;
+ pan->parms.k1 = 0.0;
+ }
+ }
fprintf(stderr, "%f %f\n", pan->parms.k0, pan->parms.k1);
- delete md;
return 0;
}
@@ -781,3 +793,41 @@ GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
return 0;
}
+
+int
+GipfelWidget::get_distortion_profile_name(char *buf, int buflen) {
+ int n;
+
+ if (md && md->get_manufacturer() && md->get_model()) {
+ n = snprintf(buf, buflen, "%s_%s_%.2f_mm",
+ md->get_manufacturer(), md->get_model(), md->get_focal_length());
+
+ return n > buflen;
+ } else {
+ return 1;
+ }
+}
+
+static Fl_Preferences dist_prefs(Fl_Preferences::USER,
+ "Johannes.HofmannATgmx.de", "gipfel/DistortionProfiles");
+
+int
+GipfelWidget::load_distortion_params(const char *prof_name) {
+ int ret = 0;
+
+ Fl_Preferences prof(dist_prefs, prof_name);
+ ret += prof.get("k0", pan->parms.k0, pan->parms.k0);
+ ret += prof.get("k1", pan->parms.k1, pan->parms.k1);
+
+ return !ret;
+}
+
+int
+GipfelWidget::save_distortion_params(const char *prof_name) {
+
+ Fl_Preferences prof(dist_prefs, prof_name);
+ prof.set("k0", pan->parms.k0);
+ prof.set("k1", pan->parms.k1);
+
+ return 0;
+}
diff --git a/src/ImageMetaData.H b/src/ImageMetaData.H
index f9baf75..27cbbd8 100644
--- a/src/ImageMetaData.H
+++ b/src/ImageMetaData.H
@@ -27,6 +27,7 @@ class ImageMetaData {
int load_image_jpgcom(char *name);
int save_image_jpgcom(char *in_img, char *out_img);
int load_image_exif(char *name);
+ void clear();
public:
ImageMetaData();
diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx
index 0e2c03b..95b6e86 100644
--- a/src/ImageMetaData.cxx
+++ b/src/ImageMetaData.cxx
@@ -18,8 +18,18 @@
#include "ImageMetaData.H"
ImageMetaData::ImageMetaData() {
+ clear();
+}
+
+ImageMetaData::~ImageMetaData() {
+ if (manufacturer) free(manufacturer);
+ if (model) free(model);
+}
+
+void
+ImageMetaData::clear() {
manufacturer = NULL;
- model = NULL;
+ model = NULL;
longitude = NAN;
latitude = NAN;
height = NAN;
@@ -34,15 +44,14 @@ ImageMetaData::ImageMetaData() {
projection_type = 0;
}
-ImageMetaData::~ImageMetaData() {
- if (manufacturer) free(manufacturer);
- if (model) free(model);
-}
-
int
ImageMetaData::load_image(char *name, int img_width) {
int ret;
+ if (manufacturer) free(manufacturer);
+ if (model) free(model);
+ clear();
+
ret = load_image_jpgcom(name);
if (ret == 2) { // old format
focal_length_35mm = scale * 35.0 / (double) img_width;
@@ -53,8 +62,6 @@ ImageMetaData::load_image(char *name, int img_width) {
if (isnan(direction)) direction = 0.0;
if (isnan(nick)) nick = 0.0;
if (isnan(tilt)) tilt = 0.0;
- if (isnan(k0)) k0 = 0.0;
- if (isnan(k1)) k1 = 0.0;
return ret;
}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index ba62ff6..a54cdd1 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -164,6 +164,43 @@ void comp_cb(Fl_Widget *, void *) {
set_values();
}
+void save_distortion_cb(Fl_Widget *, void *) {
+ char buf[1024];
+ const char * prof_name;
+ double k0, k1;
+
+ gipf->get_distortion_params(&k0, &k1);
+ gipf->get_distortion_profile_name(buf, sizeof(buf));
+ prof_name = fl_input("Save Distortion Profile (k0=%f, k1=%f)",
+ buf, k0, k1);
+
+ if (prof_name == NULL) {
+ return;
+ }
+
+ gipf->save_distortion_params(prof_name);
+ set_values();
+}
+
+void load_distortion_cb(Fl_Widget *, void *) {
+ char buf[1024];
+ const char * prof_name;
+
+ gipf->get_distortion_profile_name(buf, sizeof(buf));
+ prof_name = fl_input("Load Distortion Profile", buf);
+
+ if (prof_name == NULL) {
+ return;
+ }
+
+ if (gipf->load_distortion_params(prof_name) != 0) {
+ fl_alert("Could not load profile %s.", prof_name);
+ } else {
+ set_values();
+ }
+}
+
+
void about_cb() {
fl_message("gipfel -- and you know what you see.\n"
"Version %s\n\n"
@@ -185,6 +222,9 @@ void fill_menubar(Fl_Menu_Bar* mb) {
mb->add("&Projection/Panoramic Projection", 0, (Fl_Callback *)proj_cb,
(void *)1, FL_MENU_RADIO);
+ mb->add("&Distortion/Load Profile", 0, (Fl_Callback *)load_distortion_cb);
+ mb->add("&Distortion/Save Profile", 0, (Fl_Callback *)save_distortion_cb);
+
mb->add("&Option/Show Hidden", 0, (Fl_Callback *) hidden_cb,
(void *)0, FL_MENU_TOGGLE);