diff options
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | examples/Makefile | 50 | ||||
-rwxr-xr-x | examples/gipfel2html | 122 | ||||
-rw-r--r-- | src/GipfelWidget.H | 3 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 94 | ||||
-rw-r--r-- | src/Hill.H | 3 | ||||
-rw-r--r-- | src/ImageMetaData.H | 1 | ||||
-rw-r--r-- | src/ImageMetaData.cxx | 12 | ||||
-rw-r--r-- | src/Panorama.H | 2 | ||||
-rw-r--r-- | src/Panorama.cxx | 4 | ||||
-rw-r--r-- | src/gipfel.cxx | 90 |
11 files changed, 351 insertions, 31 deletions
@@ -23,4 +23,3 @@ stamp-h1 missing tags gipfel - diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..a863f23 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,50 @@ +images := $(wildcard *.jpg) +slides := $(addprefix gipfelweb/slides/, $(images)) +thumbs := $(addprefix gipfelweb/thumbs/, $(images)) +positions := $(addprefix gipfelweb/gipfel/, $(addsuffix .pos, $(basename $(images)))) +imgpos := $(addprefix gipfelweb/gipfel/, $(addsuffix .imgs, $(basename $(images)))) +hillpos := $(addprefix gipfelweb/gipfel/, $(addsuffix .hills, $(basename $(images)))) +html := $(addprefix gipfelweb/, $(addsuffix .html, $(basename $(images)))) +htmlhills := $(addprefix gipfelweb/hills/, $(addsuffix .html, $(basename $(images)))) + +all: + echo "make gipfelweb - create a HTML based we of gipfel oriented" + echo "images in the current directory." + +gipfelweb: dirs $(slides) $(thumbs) $(imgpos) $(hillpos) $(html) $(htmlhills) + +clean: + rm -rf gipfelweb/gipfel + +clobber: + rm -rf gipfelweb + +dirs: + mkdir -p gipfelweb/slides + mkdir -p gipfelweb/thumbs + mkdir -p gipfelweb/hills + mkdir -p gipfelweb/gipfel + +gipfelweb/slides/%.jpg: %.jpg + convert -resize '10000x600>' -quality 90 $< $@ + +gipfelweb/thumbs/%.jpg: %.jpg + convert -resize '1000x150>' -quality 80 $< $@ + +gipfelweb/gipfel/%.pos: %.jpg + gipfel -p $< > $@ + +gipfelweb/gipfel/%.imgs: gipfelweb/slides/%.jpg gipfelweb/gipfel/index.gipfel + gipfel -V 0.05 -e gipfelweb/gipfel/index.gipfel $< > $@ + +gipfelweb/gipfel/%.hills: gipfelweb/slides/%.jpg + gipfel -V 0.05 -E $< > $@ + +gipfelweb/gipfel/index.gipfel: $(positions) + cat $(positions) > gipfelweb/gipfel/index.gipfel + +gipfelweb/%.html: gipfelweb/slides/%.jpg gipfelweb/gipfel/%.imgs $(thumbs) + gipfel2html images $* > $@ + +gipfelweb/hills/%.html: gipfelweb/slides/%.jpg gipfelweb/gipfel/%.hills + gipfel2html hills $* > $@ diff --git a/examples/gipfel2html b/examples/gipfel2html new file mode 100755 index 0000000..35328c3 --- /dev/null +++ b/examples/gipfel2html @@ -0,0 +1,122 @@ +#!/bin/sh + +MODE="$1" +FILE="$2" + +if [ "$MODE" = "images" ]; then + DATAFILE="gipfelweb/gipfel/${FILE}.imgs" +else + DATAFILE="gipfelweb/gipfel/${FILE}.hills" +fi + +TITLE="" +if [ -e "${FILE}.title" ]; then + TITLE=`cat ${FILE}.title` +fi + +cat << EOF +<html> +<head> +<style type="text/css"> +#gipfel { display: block; position: relative; margin: 0; padding: 0; } +#gipfel li { visibility: hidden; list-style-type: none; position: absolute; background: url(25w.png); border: 1px solid black; font-family: sans-serif; font-size: x-small; color: #000; padding: 0; line-height: 1.3em; overflow: hidden; } +#gipfel span { visibility: hidden; position: absolute; left: 0; right: 0; display: block; padding: 5px; } +#gipfel:hover li { visibility: visible; } +#gipfel li:hover span {visibility: visible;} +EOF + +IFS=" " +i=0 +grep -v "^#" ${DATAFILE} | \ +while read name height x y dist flags dummy; do + if [ "${flags}" = "HIDDEN" ]; then + continue + fi + + if [ "$MODE" = "images" ]; then + thumb_w=`identify -format %w gipfelweb/thumbs/${name}` + thumb_h=`identify -format %h gipfelweb/thumbs/${name}` + + echo "#id_${i} {left:$((${x} - 10 / 2))px; top: $((${y} - 6 / 2))px; width: 10px; height: 6px;}" + echo "#id_${i}:hover {width: ${thumb_w}px; height: ${thumb_h}px; background: url(thumbs/${name});}" + else + echo "#id_${i} {left:$((${x} - 4 / 2))px; top: $((${y} - 4 / 2))px; width: 4px; height: 4px;}" + echo "#id_${i}:hover {width: 200px; height: 20px;}" + fi + + i=$((${i} + 1)) +done + +cat << EOF +</style></head> +<body bgcolor="#919faa"> +<script type="text/javascript"><!-- +google_ad_client = "pub-4715934322518147"; +google_ad_width = 728; +google_ad_height = 90; +google_ad_format = "728x90_as"; +google_ad_type = "text_image"; +google_ad_channel = ""; +google_color_border = "ffffff"; +google_color_bg = "f3f3f3"; +google_color_link = "000000"; +google_color_text = "333333"; +google_color_url = "666666"; +--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> +<br/> +<br/> +EOF + +echo "<h3>$TITLE</h3>" + +if [ "$MODE" = "images" ]; then + echo "<a href=\"hills/${FILE}.html\">show hill names</a>" +else + echo "<a href=\"javascript:history.back()\">back to gipfelweb</a>" +fi + +cat << EOF +<table border="0" cellpadding="0" cellspacing="1" bgcolor="black"> +<tr><td> +<table border="0" cellpadding="10" cellspacing="0" bgcolor="white"> +<tr><td> +<div id="gipfel"> +EOF + +if [ "$MODE" = "images" ]; then + echo "<img src=\"slides/${FILE}.jpg\"/>" +else + echo "<img src=\"../slides/${FILE}.jpg\"/>" +fi + +i=0 +grep -v "^#" ${DATAFILE} | \ +while read name height x y dist flags dummy; do + if [ "${flags}" = "HIDDEN" ]; then + continue + fi + + if [ "$MODE" = "images" ]; then + THUMB_TITLE="${name%.jpg}" + if [ -e "${name%.jpg}.title" ]; then + THUMB_TITLE=`cat ${name%.jpg}.title` + fi + echo "<li id=\"id_${i}\"><a href=\"${name%.jpg}.html\"><span>${THUMB_TITLE} (${height}m)</span></a></li>" + else + echo "<li id=\"id_${i}\"><span>${name} (${height}m)</span></li>" + fi + + i=$((${i} + 1)) +done + +cat << EOF +</ul> +</div> +</td></tr> +</table> +</td></tr> +</table> +<small>copyright © 2007 <ahref="http://www.ecademix.com/JohannesHofmann/impressum.html">Johannes Hofmann</a></small> +</body> +</html> +EOF diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 45bfaee..435c9be 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -22,6 +22,7 @@ class GipfelWidget : public Fl_Widget { Fl_Menu_Button *mb; char *img_file; double track_width; + int have_gipfel_info; ImageMetaData *md; int show_hidden; @@ -61,6 +62,8 @@ class GipfelWidget : public Fl_Widget { int save_image(char *file); + int export_hills(const char *file, FILE *fp); + const char * get_image_filename(); int load_data(const char *file); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index f9b5d21..8590b5c 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -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; + have_gipfel_info = 0; md = new ImageMetaData(); track_points = NULL; fl_register_images(); @@ -58,6 +59,7 @@ 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; + double direction, nick, tilt, fl; new_img = new Fl_JPEG_Image(file); @@ -90,11 +92,40 @@ GipfelWidget::load_image(char *file) { set_view_long(md->get_longitude()); set_view_lat(md->get_latitude()); set_view_height(md->get_height()); - set_center_angle(md->get_direction()); - set_nick_angle(md->get_nick()); - set_tilt_angle(md->get_tilt()); set_projection((ProjectionLSQ::Projection_t) md->get_projection_type()); - set_focal_length_35mm(md->get_focal_length_35mm()); + + have_gipfel_info = 1; + direction = md->get_direction(); + if (isnan(direction)) { + set_center_angle(0.0); + have_gipfel_info = 0; + } else { + set_center_angle(direction); + } + + nick = md->get_nick(); + if (isnan(nick)) { + set_nick_angle(0.0); + have_gipfel_info = 0; + } else { + set_nick_angle(nick); + } + + tilt = md->get_tilt(); + if (isnan(tilt)) { + set_tilt_angle(0.0); + have_gipfel_info = 0; + } else { + set_tilt_angle(tilt); + } + + fl = md->get_focal_length_35mm(); + if (isnan(fl)) { + set_focal_length_35mm(35.0); + have_gipfel_info = 0; + } else { + set_focal_length_35mm(fl); + } // try to get distortion parameters in the following ordering: // 1. gipfel data in JPEG comment @@ -166,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; } @@ -675,6 +706,59 @@ GipfelWidget::handle(int event) { } int +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(); + for (int i=0; i<mnts->get_num(); i++) { + Hill *m = mnts->get(i); + char *flags; + int _x = (int) rint(m->x) + w() / 2; + int _y = (int) rint(m->y) + h() / 2; + + if (m->flags & Hill::DUPLICATE || file && !(m->flags & Hill::EXPORT)) { + continue; + } + + if (_x < 0 || _x > w() || _y < 0 || _y > h()) { + continue; + } + + if (m->flags & Hill::HIDDEN) { + flags = "HIDDEN"; + } else { + flags = ""; + } + fprintf(fp, "%s\t%d\t%d\t%d\t%d\t%s\n", + m->name, (int) rint(m->height), _x, _y, + (int) rint(pan->get_real_distance(m)), flags); + } + + pan->remove_hills(Hill::EXPORT); + + 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; @@ -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/ImageMetaData.H b/src/ImageMetaData.H index 90b13c9..a305415 100644 --- a/src/ImageMetaData.H +++ b/src/ImageMetaData.H @@ -24,6 +24,7 @@ class ImageMetaData { double focal_length_35mm; double scale; int projection_type; + int have_gipfel_info; int load_image_jpgcom(char *name); int save_image_jpgcom(char *in_img, char *out_img); diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx index 2693851..0fa95d4 100644 --- a/src/ImageMetaData.cxx +++ b/src/ImageMetaData.cxx @@ -51,20 +51,12 @@ ImageMetaData::clear() { int ImageMetaData::load_image(char *name) { - int ret; - clear(); - ret = load_image_jpgcom(name); - + load_image_jpgcom(name); load_image_exif(name); // fill missing values from exif data - if (isnan(direction)) direction = 0.0; - if (isnan(nick)) nick = 0.0; - if (isnan(tilt)) tilt = 0.0; - if (isnan(focal_length_35mm)) focal_length_35mm = 35.0; - - return ret; + return 0; } int 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 16329c5..43f2ed5 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -59,6 +59,9 @@ 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_file, double visibility); +static int export_position(); + void set_values() { double k0 = 0.0, k1 = 0.0, x0 = 0.0; @@ -259,13 +262,15 @@ 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>] [-E] [-p]\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" + " -V <visibility> Set initial visibility.\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 +278,11 @@ 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" + " -p Export position of image to stdout.\n" + " -e <file> Export positions of hills from <file> on image.\n" + " -E Export hills from default data file.\n" " <image(s)> JPEG file(s) to use.\n"); } @@ -409,14 +417,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_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:V:pE")) != EOF) { switch (c) { case '?': usage(); @@ -425,12 +436,25 @@ int main(int argc, char** argv) { case 'd': data_file = optarg; break; + case 'e': + export_flag++; + export_file = optarg; + break; + case 'E': + export_flag++; + break; case 'v': view_point = optarg; break; + case 'V': + visibility = atof(optarg); + break; case 's': stitch_flag++; break; + case 'p': + position_flag++; + break; case '4': b_16_flag++; break; @@ -480,7 +504,6 @@ int main(int argc, char** argv) { } } - my_argc = argc - optind; my_argv = argv + optind; @@ -503,12 +526,15 @@ 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_flag) { + return export_hills(export_file, visibility); + } else if (position_flag) { + return export_position(); } Fl::get_system_colors(); @@ -542,6 +568,8 @@ int main(int argc, char** argv) { scroll->size(gipf->w(), gipf->h()); gipf->load_data(data_file); + gipf->set_height_dist_ratio(visibility); + scroll->end(); set_values(); @@ -575,7 +603,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 +644,44 @@ stitch(GipfelWidget::sample_mode_t m, int b_16, return 0; } + +static int +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 (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 { + return 1; + } +} |