[GRASS-SVN] r56568 - grass-addons/grass6/display/d.anaglyph
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 2 22:36:42 PDT 2013
Author: hamish
Date: 2013-06-02 22:36:42 -0700 (Sun, 02 Jun 2013)
New Revision: 56568
Added:
grass-addons/grass6/display/d.anaglyph/spearfish_anaglyph.png
grass-addons/grass6/display/d.anaglyph/spearfish_stereogram.jpg
Modified:
grass-addons/grass6/display/d.anaglyph/d.anaglyph
grass-addons/grass6/display/d.anaglyph/description.html
Log:
add support for creating stereograms, example images
Modified: grass-addons/grass6/display/d.anaglyph/d.anaglyph
===================================================================
--- grass-addons/grass6/display/d.anaglyph/d.anaglyph 2013-06-02 21:37:47 UTC (rev 56567)
+++ grass-addons/grass6/display/d.anaglyph/d.anaglyph 2013-06-03 05:36:42 UTC (rev 56568)
@@ -5,7 +5,7 @@
# AUTHOR(S): M. Hamish Bowman, Dunedin, New Zealand
# Based on the method by Peter Loewe
# PURPOSE: Creates a sterographic 3D image suitable for viewing with
-# red/cyan glasses.
+# red/cyan glasses or by crossing your eyes.
#
# COPYRIGHT: (c) 2013 Hamish Bowman, and the GRASS Development Team
#
@@ -29,7 +29,7 @@
# does not preserve the map rotation.
#%Module
-#% description: Creates a sterographic 3D image suitable for viewing with red/cyan glasses.
+#% description: Creates a sterographic 3D image suitable for viewing with red/cyan glasses or by simply crossing your eyes.
#% keywords: raster
#%End
#%Option
@@ -76,6 +76,15 @@
#% answer: 2.0
#%End
#%Option
+#% key: color_overlay
+#% type: string
+#% required: no
+#% key_desc: name
+#% description: Name of raster map to drape across surface
+#% gisprompt: old,cell,raster
+#% guisection: Raster overlay
+#%End
+#%Option
#% key: vpoints
#% type: string
#% required: no
@@ -126,7 +135,21 @@
#% key: e
#% description: Equalize contrast
#%End
+#%Flag
+#% key: s
+#% label: Create a bifurcated sterogram pair instead of a blue/cyan anaglyph
+#% description: In this case the size option sets the size of each pane.
+#%End
+#%Flag
+#% key: c
+#% description: Cross-eyed mode for bifurcated sterogram pair
+#%End
+#%Flag
+#% key: g
+#% description: Create viewing guide for cross-eyed sterograms
+#%End
+
if [ -z "$GISBASE" ] ; then
echo "You must be in GRASS GIS to run this program." 1>&2
exit 1
@@ -158,7 +181,9 @@
cleanup()
{
- g.remove "$TEMP_IMG" --quiet
+ if [ "$GIS_FLAG_S" -ne 1 ] ; then
+ g.remove "$TEMP_IMG" --quiet
+ fi
rm -f "$TEMPFILE" "${TEMPFILE}."*
if [ -n "$WIND_OVERRIDE" ] ; then
unset WIND_OVERRIDE
@@ -242,7 +267,13 @@
VLINES=""
fi
+if [ -n "$GIS_OPT_COLOR_OVERLAY" ] ; then
+ DRAPE="color_map=$GIS_OPT_COLOR_OVERLAY"
+else
+ DRAPE=""
+fi
+
OLDDIR="`pwd`"
cd `dirname "$TEMPFILE"`
@@ -263,11 +294,14 @@
extent_frac=`echo "$avg_extentN" | awk '{print 0.005 * $1}'`
-g.message "Preparing map ..."
-r.mapcalc "$TEMP_IMG = $INMAP"
-r.colors $EFLAG "$TEMP_IMG" color=grey --quiet
+if [ "$GIS_FLAG_S" -ne 1 ] ; then
+ g.message "Preparing map ..."
+ r.mapcalc "$TEMP_IMG = $INMAP"
+ r.colors $EFLAG "$TEMP_IMG" color=grey --quiet
+else
+ TEMP_IMG="$INMAP"
+fi
-
if [ $GIS_FLAG_F -eq 1 ] ; then
#### flat image ####
if [ -n "$GIS_OPT_VIEWING_HEIGHT" ] ; then
@@ -286,7 +320,7 @@
fi
RENDER_OPTS="resolution_fine=1 perspective=15 twist=$TWIST \
- position=0.5,0.5 bgcolor=black $VLINES $VPOINTS"
+ position=0.5,0.5 bgcolor=black $VLINES $VPOINTS $DRAPE"
g.message "Rendering 3D scenes ..."
m.nviz.image elevation_map="$TEMP_IMG" output="$TEMPFILE.right" \
@@ -313,7 +347,9 @@
g.region save="tmp_anaglyph.$$"
WIND_OVERRIDE="tmp_anaglyph.$$"
export WIND_OVERRIDE
- g.region rast="$TEMP_IMG"
+ if [ "$GIS_FLAG_S" -ne 1 ] ; then
+ g.region rast="$TEMP_IMG"
+ fi
# really annoying: Nviz rotates along the shorter of the two axes, so
# we have to grow so that the region is taller than it is wide, so that
@@ -342,7 +378,8 @@
SPREAD_L=`echo "$SPREAD" | awk '{print 0.5 - $1}'`
SPREAD_R=`echo "$SPREAD" | awk '{print 0.5 + $1}'`
- RENDER_OPTS="resolution_fine=1 perspective=15 bgcolor=black $VLINES $VPOINTS"
+ RENDER_OPTS="resolution_fine=1 perspective=15 bgcolor=black \
+ $VLINES $VPOINTS $DRAPE"
g.message "Rendering 3D scenes ..."
@@ -361,17 +398,128 @@
BASENM=`basename "$TEMPFILE"`
-# split into R,G,B components
-g.message "Creating anaglyph ..."
-ppmtorgb3 "$BASENM.left.ppm" &
-ppmtorgb3 "$BASENM.right.ppm"
-check_ret
-wait
+# try to find a nice TTF font in the fontcap (d.font -l)
+find_a_font()
+{
+ FONTS="FreeSans Vera DroidSans LiberationSans-Regular DejaVuSans \
+ Arial Courier_New Trebuchet_MS"
+ VALID_FONT=""
+ for FONT in $FONTS ; do
+ d.font "$FONT" 2> /dev/null
+ if [ $? -eq 0 ] ; then
+ VALID_FONT="$FONT"
+ break
+ fi
+ done
+}
-rgb3toppm "$BASENM.left.red" "$BASENM.right.grn" "$BASENM.right.blu" \
- > "$BASENM.anaglyph.ppm"
-check_ret
+# make a spacer image. usage create_pbm <Width> <Height> <filename.pbm>
+create_pbm()
+{
+ cat << EOF > "$3"
+P1
+# block of black
+$1 $2
+EOF
+ i=0
+ while [ $i -lt $2 ] ; do
+ seq 1 "$1" | sed 's/.*/1 /' | tr -d '\n' >> "$3"
+ i=`expr "$i" + 1`
+ done
+}
+
+
+if [ "$GIS_FLAG_S" -ne 1 ] ; then
+ # split into R,G,B components
+ g.message "Creating anaglyph ..."
+ ppmtorgb3 "$BASENM.left.ppm" &
+ ppmtorgb3 "$BASENM.right.ppm"
+ check_ret
+ wait
+
+ rgb3toppm "$BASENM.left.red" "$BASENM.right.grn" "$BASENM.right.blu" \
+ > "$BASENM.anaglyph.ppm"
+ check_ret
+else
+ # stereogram
+ HEIGHT=`echo "$SIZE" | cut -f2 -d,`
+ create_pbm 5 "$HEIGHT" "$TEMPFILE.gutter.pbm"
+
+ if [ "$GIS_FLAG_C" -ne 1 ] ; then
+ pnmcat -leftright "$BASENM.right.ppm" "$TEMPFILE.gutter.pbm" \
+ "$BASENM.left.ppm" > "$BASENM.anaglyph.ppm"
+ check_ret
+ else
+ if [ "$GIS_FLAG_G" -ne 1 ] ; then
+ pnmcat -leftright "$BASENM.left.ppm" "$TEMPFILE.gutter.pbm" \
+ "$BASENM.right.ppm" > "$BASENM.anaglyph.ppm"
+ check_ret
+ else
+
+ # thanks (public domain)
+ # http://upload.wikimedia.org/wikipedia/commons/1/10/Stereo_Pair%2C_Lake_Palanskoye_Landslide%2C_Kamchatka_Peninsula%2C_Russia.jpg
+ SIDE_WIDTH=40
+ GUTTER_WIDTH=5
+ WIDTH=`echo "$SIZE" | cut -f1 -d,`
+ WIDTH2=`expr "$WIDTH" "*" 2 + $SIDE_WIDTH + $SIDE_WIDTH + $GUTTER_WIDTH`
+ HEIGHT=`echo "$SIZE" | cut -f2 -d,`
+
+ # dot guide at the top
+ GRASS_CAIROFILE="$TEMPFILE.dot.ppm"
+ GRASS_WIDTH="$WIDTH"
+ GRASS_HEIGHT=75
+ export GRASS_CAIROFILE GRASS_WIDTH GRASS_HEIGHT
+ d.mon start=cairo --quiet
+ d.erase black
+ echo "symbol basic/circle 25 50 50 white white" | d.graph
+ d.mon stop=cairo --quiet
+
+ # instructions at the bottom (use ppmlabel?)
+ GRASS_CAIROFILE="$TEMPFILE.text.ppm"
+ GRASS_WIDTH="$WIDTH2"
+ GRASS_HEIGHT=100
+ export GRASS_CAIROFILE GRASS_WIDTH GRASS_HEIGHT
+ d.mon start=cairo --quiet
+ d.erase black
+
+ VALID_FONT=""
+ find_a_font
+ if [ -n "$VALID_FONT" ] ; then
+ d.font "$VALID_FONT"
+ fi
+ cat << EOF | d.text at=50,67 align=cc size=25 color=white linespacing=2
+To view stereo pair, cross eyes slightly until a third
+white dot appears between the two. New center image is 3D!
+EOF
+ d.mon stop=cairo --quiet
+
+ # left,right side border and middle sep
+ TOPHEIGHT=`expr "$HEIGHT" + 75`
+ create_pbm "$SIDE_WIDTH" "$TOPHEIGHT" "$TEMPFILE.side.pbm"
+ create_pbm "$GUTTER_WIDTH" "$TOPHEIGHT" "$TEMPFILE.gutter.pbm"
+
+ # construct it
+ pnmcat -topbottom "$TEMPFILE.dot.ppm" "$BASENM.right.ppm" \
+ > "$BASENM.dotright.ppm"
+ check_ret
+
+ pnmcat -topbottom "$TEMPFILE.dot.ppm" "$BASENM.left.ppm" \
+ > "$BASENM.dotleft.ppm"
+ check_ret
+
+ pnmcat -leftright "$TEMPFILE.side.pbm" "$BASENM.dotleft.ppm" \
+ "$TEMPFILE.gutter.pbm" "$BASENM.dotright.ppm" "$TEMPFILE.side.pbm" \
+ > "$BASENM.upper.ppm"
+ check_ret
+
+ pnmcat -topbottom "$BASENM.upper.ppm" "$TEMPFILE.text.ppm" \
+ > "$BASENM.anaglyph.ppm"
+ check_ret
+ fi
+ fi
+fi
+
pnmtopng "$BASENM.anaglyph.ppm" > "$OLDDIR/$OUTFILE"
check_ret
Modified: grass-addons/grass6/display/d.anaglyph/description.html
===================================================================
--- grass-addons/grass6/display/d.anaglyph/description.html 2013-06-02 21:37:47 UTC (rev 56567)
+++ grass-addons/grass6/display/d.anaglyph/description.html 2013-06-03 05:36:42 UTC (rev 56568)
@@ -1,19 +1,47 @@
<h2>DESCRIPTION</h2>
<em>d.anaglyph</em> creates a sterographic 3D image suitable for viewing
-with red/cyan glasses. Vector line and point maps may be draped over the
-raster surface.
+either with red/cyan glasses, a stereograph viewer, or by simply crossing your
+eyes. Vector line and point maps may be draped over the raster surface.
+<p>
+Stereograms (two images side by side) will be in full color. Anaglyphs
+(needing red/cyan glasses) will be in greyscale, but some colors like
+yellow can be used. This module allows creation of stereograms either
+in straight mode (requiring a stereoscopic viewer), or cross-eyed, which
+you can do "free-view" without any special tools.
+
<h2>NOTES</h2>
The NetPBM image manipulation tools are required.
The output file will be a PNG image.
+<p>
+For "free-view" cross-eyed stereograms the <b>-g</b> flag is provided to
+help guide your eyes, by adding instructions and two white dots to focus on.
+It will be hard to focus the dots if they are more than the width of your
+eyes appart, in this case it is recommended to not set the image <b>size</b>
+of each pane any greater than about 200 pixels, so the two panes look like
+bookmarks. The narrower the image the easier it will be to focus on, but
+the less you will be able to see.
+<p>
+If draping a <b>color_overlay</b> raster map over the top of a DEM in
+anaglyph mode, it works best to first change the color map of the overlay
+raster to greyscale or sepia with the <em>r.color</em> module (perhaps with
+the <b>-e</b> flag), to avoid any red/cyan in the overlay's color table from
+confusing the 3D effect.
+<p>
+The flatten terrain and equalize contrast flags only operate in anaglyph mode.
+
+<center>
+<img src="spearfish_anaglyph.png">
+</center>
+
<h2>EXAMPLES</h2>
-North Carolina dataset:
+North Carolina dataset anaglyph:
<div class="code"><pre>
g.region rast=elevation
d.anaglyph input=elevation output=wake_anaglyph.png size=1280,960 \
@@ -21,7 +49,7 @@
</pre></div>
-Spearfish dataset:
+Spearfish dataset anaglyph:
<div class="code"><pre>
g.region rast=elevation.10m
d.anaglyph -e input=elevation.10m output=spearfish_anaglyph.png \
@@ -29,13 +57,23 @@
</pre></div>
+Spearfish dataset cross-eyed stereogram:
+<div class="code"><pre>
+g.region rast=elevation.10m
+r.colors -e elevation.10m color=haxby
+d.anaglyph -scg input=elevation.10m output=spearfish_stereogram.png \
+ size=185,500 viewing_height=27000
+</pre></div>
+
+<center>
+<img src="spearfish_stereogram.jpg" align="center">
+</center>
+
<h2>TODO</h2>
Fine tuning; needs more viewpoint separation when the z-exaggeration is high.
View is currently limited to top-down.
-<em>m.nviz.image</em> currently Segfaults if more vector maps are passed than
-attributes to go with them. We should fix that so if there are more maps than
-attributes the later maps reuse the attributes of the earlier ones.
+Sometimes one of the images flips (adjust the region width).
<h2>SEE ALSO</h2>
Added: grass-addons/grass6/display/d.anaglyph/spearfish_anaglyph.png
===================================================================
(Binary files differ)
Property changes on: grass-addons/grass6/display/d.anaglyph/spearfish_anaglyph.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: grass-addons/grass6/display/d.anaglyph/spearfish_stereogram.jpg
===================================================================
(Binary files differ)
Property changes on: grass-addons/grass6/display/d.anaglyph/spearfish_stereogram.jpg
___________________________________________________________________
Added: svn:mime-type
+ image/jpeg
More information about the grass-commit
mailing list