From dadd1edab19c6f87c3e8cca7e9fbcce554dd4cb0 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Thu, 9 Aug 2007 20:25:59 +0200 Subject: add export mode position, export to stdout --- src/GipfelWidget.H | 2 +- src/GipfelWidget.cxx | 11 +---------- src/gipfel.cxx | 40 ++++++++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index f51926f..3dc8503 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -61,7 +61,7 @@ class GipfelWidget : public Fl_Widget { int save_image(char *file); - int export_hills(const char *file); + int export_hills(FILE *fp); const char * get_image_filename(); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index b3e9697..20d4a42 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -675,18 +675,10 @@ GipfelWidget::handle(int event) { } int -GipfelWidget::export_hills(const char *file) { - FILE *fp; +GipfelWidget::export_hills(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(); @@ -703,7 +695,6 @@ GipfelWidget::export_hills(const char *file) { (int) rint(pan->get_real_distance(m))); } - fclose(fp); return 0; } diff --git a/src/gipfel.cxx b/src/gipfel.cxx index db579de..295adf6 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -59,7 +59,7 @@ 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, double visibility); +static int export_hills(const char *export_mode, double visibility); void set_values() { double k0 = 0.0, k1 = 0.0, x0 = 0.0; @@ -263,7 +263,7 @@ void usage() { fprintf(stderr, "usage: gipfel [-v ] [-d ]\n" " [-s] [-j ] [-t ] [-h ]\n" - " [-e ]\n" + " [-e hills] -e [position]\n" " []\n" " -v Set point from which the picture was taken.\n" " This must be a string that unambiguously \n" @@ -279,7 +279,8 @@ void usage() { " -h Height of result image.\n" " -j JPEG output file for Stitch mode.\n" " -t Output directory for TIFF images in Stitch mode.\n" - " -e Export positions on image to file .\n" + " -e position Export position of image to stdout.\n" + " -e hills Export hill positions on image to stdout.\n" " JPEG file(s) to use.\n"); } @@ -420,7 +421,7 @@ int main(int argc, char** argv) { double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; double visibility = 0.07; char *outpath = "/tmp"; - char *export_file = NULL; + char *export_mode = NULL; err = 0; while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4e:V:")) != EOF) { @@ -433,7 +434,12 @@ int main(int argc, char** argv) { data_file = optarg; break; case 'e': - export_file = optarg; + if (strcmp(optarg, "position") && strcmp(optarg, "hills")) { + fprintf(stderr, "Unknown export mode %s.\n", optarg); + err++; + } else { + export_mode = optarg; + } break; case 'v': view_point = optarg; @@ -520,8 +526,8 @@ int main(int argc, char** argv) { stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); - } else if (export_file) { - return export_hills(export_file, visibility); + } else if (export_mode) { + return export_hills(export_mode, visibility); } Fl::get_system_colors(); @@ -633,17 +639,31 @@ stitch(GipfelWidget::sample_mode_t m, int b_16, } static int -export_hills(const char *file, double visibility) { +export_hills(const char *export_mode, double visibility) { int ret = 1; - if (img_file) { + 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(file); + ret = gipf->export_hills(stdout); delete gipf; gipf = NULL; + } else { + ImageMetaData md; + if (md.load_image(img_file) == 0) { + printf(",,%s,,%f,%f,%d\n", img_file, + md.get_longitude(), + md.get_latitude(), + (int) rint(md.get_height())); + ret = 0; + } } return ret; -- cgit v1.2.3