#!/usr/bin/env bash
# LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
#
# Produce an OSG scene graph file of terrain from a DEM file
# and produce color using false-color tools.
#
# Required software:
# - ImageMagick: composite
# - gis_*: Matt Perry's (Perry Geo) programs.
# - libgeotif: listgeo
# - OSG VirtualPlanetBuilder: osgdem


echo "THIS IS BROKEN!"
echo "ImageMagick composite doesn't work, use GIMP to merge TIF files."
exit 1


if [ "$1" = "" ] || [ "$1" = '-h' ]; then
    echo "tile-color.sh: <basenameOfDEM>"
    exit 0
fi

NAME=$1
LEVELS=2

if [ ! -f ${NAME}.dem ]; then
    echo "ERROR: ${NAME}.dem doesn't exist."
    exit 1
fi

# Input for gis_relief.
echo "3500   255 255 255"  > scale.txt
echo "2500   235 220 175" >> scale.txt
echo "1500   190 185 135" >> scale.txt
echo "700    240 250 150" >> scale.txt
echo "0      50  180  50" >> scale.txt
echo "-32768 200 230 255" >> scale.txt

# Start from scratch.
rm -f ${NAME}.osga

gis_shade ${NAME}.dem shade.tif
gis_relief ${NAME}.dem scale.txt color.tif
### !!! composite doesn't work, use GIMP ###
composite -compose multiply shade.tif color.tif composite.tif
gdal_translate ${NAME}.dem ${NAME}.tif
listgeo ${NAME}.tif > info
geotifcp -g info -c lzw composite.tif composite2.tif
osgdem -d ${NAME}.dem -t composite2.tif -l $LEVELS -o ${NAME}.ive -a ${NAME}.osga

# Clean.
#rm -f scale.txt composite* shade.tif color.tif
