summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/Makefile4
-rw-r--r--src/GipfelWidget.H2
-rw-r--r--src/GipfelWidget.cxx25
-rw-r--r--src/Hill.H3
-rw-r--r--src/Panorama.H2
-rw-r--r--src/Panorama.cxx4
-rw-r--r--src/gipfel.cxx85
7 files changed, 80 insertions, 45 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 4b3ee86..7c26813 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -26,10 +26,10 @@ gipfelweb/thumbs/%.jpg: %.jpg
convert -resize '1000x150>' -quality 80 $< $@
gipfelweb/gipfel/%.pos: %.jpg
- gipfel -e position $< > $@
+ gipfel -p $< > $@
gipfelweb/gipfel/%.gipf: gipfelweb/slides/%.jpg gipfelweb/gipfel/index.gipfel
- gipfel -v 0.02 -d gipfelweb/gipfel/index.gipfel -e hills $< > $@
+ gipfel -v 0.02 -e gipfelweb/gipfel/index.gipfel $< > $@
gipfelweb/gipfel/index.gipfel: $(positions)
cat $(positions) > gipfelweb/gipfel/index.gipfel
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 274ce33..435c9be 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -62,7 +62,7 @@ class GipfelWidget : public Fl_Widget {
int save_image(char *file);
- int export_hills(FILE *fp);
+ int export_hills(const char *file, FILE *fp);
const char * get_image_filename();
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 4ccbfa2..e6bed3a 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -197,7 +197,7 @@ GipfelWidget::load_data(const char *file) {
int
GipfelWidget::load_track(const char *file) {
if (track_points) {
- pan->remove_trackpoints();
+ pan->remove_hills(Hill::TRACK_POINT);
track_points->clobber();
delete track_points;
}
@@ -706,13 +706,26 @@ GipfelWidget::handle(int event) {
}
int
-GipfelWidget::export_hills(FILE *fp) {
- Hills *mnts;
+GipfelWidget::export_hills(const char *file, FILE *fp) {
+ Hills export_hills, *mnts;
if (!have_gipfel_info) {
+ fprintf(stderr, "No gipfel info available for %s.\n", img_file);
return 0;
}
+ if (file) {
+ if (export_hills.load(file) != 0) {
+ return 1;
+ }
+
+ for (int i=0; i<export_hills.get_num(); i++) {
+ export_hills.get(i)->flags |= Hill::EXPORT;
+ }
+
+ pan->add_hills(&export_hills);
+ }
+
fprintf(fp, "#\n# name\theight\tx\ty\tdistance\tflags\n#\n");
mnts = pan->get_visible_mountains();
@@ -722,6 +735,10 @@ GipfelWidget::export_hills(FILE *fp) {
int _x = (int) rint(m->x) + w() / 2;
int _y = (int) rint(m->y) + h() / 2;
+ if (file && !(m->flags & Hill::EXPORT)) {
+ continue;
+ }
+
if (_x < 0 || _x > w() || _y < 0 || _y > h()) {
continue;
}
@@ -736,6 +753,8 @@ GipfelWidget::export_hills(FILE *fp) {
(int) rint(pan->get_real_distance(m)), flags);
}
+ pan->remove_hills(Hill::EXPORT);
+
return 0;
}
diff --git a/src/Hill.H b/src/Hill.H
index 16d6eff..ea7e25e 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -18,7 +18,8 @@ class Hill {
DUPLICATE = 0x01,
TRACK_POINT = 0x02,
VISIBLE = 0x04,
- HIDDEN = 0x08
+ HIDDEN = 0x08,
+ EXPORT = 0x10,
} flags_t;
double phi, lam;
diff --git a/src/Panorama.H b/src/Panorama.H
index d5ebb37..86bf447 100644
--- a/src/Panorama.H
+++ b/src/Panorama.H
@@ -66,7 +66,7 @@ class Panorama {
void add_hills(Hills *h);
- void remove_trackpoints();
+ void remove_hills(int flags);
int set_viewpoint(const char *pos);
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index 516b688..1f13c21 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -67,13 +67,13 @@ Panorama::add_hills(Hills *h) {
}
void
-Panorama::remove_trackpoints() {
+Panorama::remove_hills(int flags) {
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)) {
+ if (! (m->flags & flags)) {
h_new->add(m);
}
}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index ba757e2..50f2404 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -59,7 +59,8 @@ static int stitch(GipfelWidget::sample_mode_t m , int b_16,
int stitch_w, int stitch_h,
double from, double to, int type, const char *path, int argc, char **argv);
-static int export_hills(const char *export_mode, double visibility);
+static int export_hills(const char *export_file, double visibility);
+static int export_position();
void set_values() {
double k0 = 0.0, k1 = 0.0, x0 = 0.0;
@@ -263,7 +264,7 @@ void usage() {
fprintf(stderr,
"usage: gipfel [-v <viewpoint>] [-d <file>]\n"
" [-s] [-j <file>] [-t <dir] [-w <width>] [-h <height>]\n"
- " [-e hills] -e [position]\n"
+ " [-e <file>] -p]\n"
" [<image(s)>]\n"
" -v <viewpoint> Set point from which the picture was taken.\n"
" This must be a string that unambiguously \n"
@@ -279,8 +280,10 @@ void usage() {
" -h <height> Height of result image.\n"
" -j <file> JPEG output file for Stitch mode.\n"
" -t <dir> Output directory for TIFF images in Stitch mode.\n"
- " -e position Export position of image to stdout.\n"
- " -e hills Export hill positions on image to stdout.\n"
+ " -p Export position of image to stdout.\n"
+ " -e <file> Export positions of hills from <file> on image\n"
+ " to stdout. Uses hills from default data file if\n"
+ " <file> is omitted.\n"
" <image(s)> JPEG file(s) to use.\n");
}
@@ -415,16 +418,17 @@ int main(int argc, char** argv) {
char *view_point = NULL;
int err, my_argc;
int stitch_flag = 0, stitch_w = 2000, stitch_h = 500;
- int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0;
+ int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0, position_flag = 0;
+ int export_flag = 0;
int bicubic_flag = 0, b_16_flag = 0;
double stitch_from = 0.0, stitch_to = 380.0;
double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0;
double visibility = 0.07;
char *outpath = "/tmp";
- char *export_mode = NULL;
+ char *export_file = NULL;
err = 0;
- while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4e:V:")) != EOF) {
+ while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4e:V:p")) != EOF) {
switch (c) {
case '?':
usage();
@@ -434,12 +438,8 @@ int main(int argc, char** argv) {
data_file = optarg;
break;
case 'e':
- if (strcmp(optarg, "position") && strcmp(optarg, "hills")) {
- fprintf(stderr, "Unknown export mode %s.\n", optarg);
- err++;
- } else {
- export_mode = optarg;
- }
+ export_flag++;
+ export_file = optarg;
break;
case 'v':
view_point = optarg;
@@ -450,6 +450,9 @@ int main(int argc, char** argv) {
case 's':
stitch_flag++;
break;
+ case 'p':
+ position_flag++;
+ break;
case '4':
b_16_flag++;
break;
@@ -526,8 +529,10 @@ int main(int argc, char** argv) {
stitch_w, stitch_h, stitch_from, stitch_to,
type, outpath, my_argc, my_argv);
- } else if (export_mode) {
- return export_hills(export_mode, visibility);
+ } else if (export_flag) {
+ return export_hills(export_file, visibility);
+ } else if (position_flag) {
+ return export_position();
}
Fl::get_system_colors();
@@ -639,32 +644,42 @@ stitch(GipfelWidget::sample_mode_t m, int b_16,
}
static int
-export_hills(const char *export_mode, double visibility) {
- int ret = 1;
+export_hills(const char *export_file, double visibility) {
+ int ret;
+
+ if (!img_file) {
+ fprintf(stderr, "export: No image file given.\n");
+ return 1;
+ }
+
+ gipf = new GipfelWidget(0,0,800,600);
+ gipf->load_image(img_file);
+ gipf->load_data(data_file);
+ gipf->set_height_dist_ratio(visibility);
+ ret = gipf->export_hills(export_file, stdout);
+ delete gipf;
+ gipf = NULL;
+
+ return ret;
+}
+
+static int
+export_position() {
+ ImageMetaData md;
if (!img_file) {
fprintf(stderr, "export: No image file given.\n");
return 1;
}
- if (strcmp(export_mode, "hills") == 0) {
- gipf = new GipfelWidget(0,0,800,600);
- gipf->load_image(img_file);
- gipf->load_data(data_file);
- gipf->set_height_dist_ratio(visibility);
- ret = gipf->export_hills(stdout);
- delete gipf;
- gipf = NULL;
+ if (md.load_image(img_file) == 0) {
+ printf(",%s,,%f,%f,%d\n", img_file,
+ md.get_latitude(),
+ md.get_longitude(),
+ (int) rint(md.get_height()));
+
+ return 0;
} else {
- ImageMetaData md;
- if (md.load_image(img_file) == 0) {
- printf(",%s,,%f,%f,%d\n", img_file,
- md.get_latitude(),
- md.get_longitude(),
- (int) rint(md.get_height()));
- ret = 0;
- }
+ return 1;
}
-
- return ret;
}