diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2007-08-09 19:22:23 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2007-08-09 19:22:23 +0200 |
commit | e235adf3601bd36605ed3510b55e63d8606cbbe0 (patch) | |
tree | 35c62163b2a0c8751d3741586f2c0bd096e94df8 /src | |
parent | 22968b805a4b7abbbf24f5e6e6e6ec68eef5d5a0 (diff) |
implement export
Diffstat (limited to 'src')
-rw-r--r-- | src/GipfelWidget.H | 2 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 33 | ||||
-rw-r--r-- | src/gipfel.cxx | 43 |
3 files changed, 68 insertions, 10 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 45bfaee..f51926f 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -61,6 +61,8 @@ class GipfelWidget : public Fl_Widget { int save_image(char *file); + int export_hills(const char *file); + const char * get_image_filename(); int load_data(const char *file); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index f9b5d21..b3e9697 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -675,6 +675,39 @@ GipfelWidget::handle(int event) { } int +GipfelWidget::export_hills(const char *file) { + FILE *fp; + Hills *mnts; + Hill *m; + + fp = fopen(file, "wb"); + + if (fp == NULL) { + perror("fopen"); + return 1; + } + + fprintf(fp, "#\n# name\theight\tx\ty\tdistance\n#\n"); + + mnts = pan->get_visible_mountains(); + for (int i=0; i<mnts->get_num(); i++) { + m = mnts->get(i); + + if (m->x < 0 || m->x > w() || m->y < 0 || m->y > h()) { + continue; + } + + fprintf(fp, "%s\t%d\t%d\t%d\t%d\n", + m->name, (int) rint(m->height), + (int) rint( m->x), (int) rint(m->y), + (int) rint(pan->get_real_distance(m))); + } + + fclose(fp); + return 0; +} + +int GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, double a_alph, double a_nick, int *r, int *g, int *b) { double px, py; diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 16329c5..cbc0923 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -59,6 +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 *file); + void set_values() { double k0 = 0.0, k1 = 0.0, x0 = 0.0; @@ -259,13 +261,14 @@ void fill_menubar(Fl_Menu_Bar* mb) { void usage() { fprintf(stderr, - "usage: gipfel [-v <viewpoint>] [-d <datafile>]\n" - " [-s] [-j <outfile>] [-t <outdir] [-w <width>] [-h <height>]\n" + "usage: gipfel [-v <viewpoint>] [-d <file>]\n" + " [-s] [-j <file>] [-t <dir] [-w <width>] [-h <height>]\n" + " [-e <file>]\n" " [<image(s)>]\n" " -v <viewpoint> Set point from which the picture was taken.\n" " This must be a string that unambiguously \n" " matches the name of an entry in the data file.\n" - " -d <datafile> Use <datafile> for GPS data.\n" + " -d <file> Use <file> for GPS data.\n" " -u <k0>,<k1> Use distortion correction values k0,k1.\n" " -s Stitch mode.\n" " -4 Create 16bit output (only with TIFF stitching).\n" @@ -273,8 +276,9 @@ void usage() { " -b Use bilinear interpolation for stitching.\n" " -w <width> Width of result image.\n" " -h <height> Height of result image.\n" - " -j <outfile> JPEG output file for Stitch mode.\n" - " -t <outdir> Output directory for TIFF images in Stitch mode.\n" + " -j <file> JPEG output file for Stitch mode.\n" + " -t <dir> Output directory for TIFF images in Stitch mode.\n" + " -e <file> Export positions on image to file <file>.\n" " <image(s)> JPEG file(s) to use.\n"); } @@ -414,9 +418,10 @@ int main(int argc, char** argv) { double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; + char *export_file = NULL; err = 0; - while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4")) != EOF) { + while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4e:")) != EOF) { switch (c) { case '?': usage(); @@ -425,6 +430,9 @@ int main(int argc, char** argv) { case 'd': data_file = optarg; break; + case 'e': + export_file = optarg; + break; case 'v': view_point = optarg; break; @@ -480,7 +488,6 @@ int main(int argc, char** argv) { } } - my_argc = argc - optind; my_argv = argv + optind; @@ -503,12 +510,13 @@ int main(int argc, char** argv) { type = STITCH_PREVIEW; } - stitch(bicubic_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, + return stitch(bicubic_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, b_16_flag, stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); - exit(0); + } else if (export_file) { + return export_hills(export_file); } Fl::get_system_colors(); @@ -575,7 +583,6 @@ stitch(GipfelWidget::sample_mode_t m, int b_16, st->load_image(argv[i]); } - if (type & STITCH_JPEG) { st->set_output(new JPEGOutputImage(path, 90)); @@ -617,3 +624,19 @@ stitch(GipfelWidget::sample_mode_t m, int b_16, return 0; } + +static int +export_hills(const char *file) { + int ret = 1; + + if (img_file) { + gipf = new GipfelWidget(0,0,800,600); + gipf->load_image(img_file); + gipf->load_data(data_file); + ret = gipf->export_hills(file); + delete gipf; + gipf = NULL; + } + + return ret; +} |