[GRASS-SVN] r60112 - in grass-addons/grass6/vector: . v.out.blend

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 5 08:27:22 PDT 2014


Author: vincent
Date: 2014-05-05 08:27:22 -0700 (Mon, 05 May 2014)
New Revision: 60112

Added:
   grass-addons/grass6/vector/v.out.blend/
   grass-addons/grass6/vector/v.out.blend/Makefile
   grass-addons/grass6/vector/v.out.blend/description.html
   grass-addons/grass6/vector/v.out.blend/v.out.blend
Log:
new v.out.blend addon submission


Added: grass-addons/grass6/vector/v.out.blend/Makefile
===================================================================
--- grass-addons/grass6/vector/v.out.blend/Makefile	                        (rev 0)
+++ grass-addons/grass6/vector/v.out.blend/Makefile	2014-05-05 15:27:22 UTC (rev 60112)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.out.blend
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass6/vector/v.out.blend/description.html
===================================================================
--- grass-addons/grass6/vector/v.out.blend/description.html	                        (rev 0)
+++ grass-addons/grass6/vector/v.out.blend/description.html	2014-05-05 15:27:22 UTC (rev 60112)
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS manual: v.out.blend</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+</head>
+<body bgcolor="white">
+
+<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
+
+<h2>NAME</h2>
+<em><b>v.out.blend</b></em>  - this module is a Blender user oriented add-on.  It outputs a 3d delaunay triangulation (.ply file) from a 3d vector pointcloud and optionally an image to drape on (.tif file), e.g. within Blender
+<h2>KEYWORDS</h2>
+mesh, export, Blender, render
+<h2>SYNOPSIS</h2>
+<b>v.out.blend</b><br>
+<b>v.out.blend help</b><br>
+<b>v.out.blend</b> <b>vinput</b>=<em>string</em> <b>dsn</b>=<em>string</em> [<b>rinput</b>=<em>string</em>]
+
+<h3>Parameters:</h3>
+<DL>
+<DT><b>vinput</b>=<em>string</em></DT>
+<DD>Name of 3d vector point to export</DD>
+
+<DT><b>dsn</b>=<em>string</em></DT>
+<DD>output directory name</DD>
+
+<DT><b>rinput</b>=<em>string</em></DT>
+<DD>Name of raster to export</DD>
+
+</DL>
+<h2>NOTES</h2>
+<p><em>v.out.blend</em> was written towards <a href="http://blender.org">Blender</A> 3d computer graphics software users. Regarding geographic data, accessing the capabilities of such software might be very helpful to produce high quality outputs, and rewarding for the data producer... but transferring digital data from GRASS to Blender is a bit tricky.</p><p>This addon aims at exporting to Blender a 3d pointcloud (figuring eg topographic data), previously turned into a triangular mesh. Optionally one can export a raster as an image which can further be draped on this surface. As usual it is quite rough but the annotated code should be easily adaptable to one's personnal needs.</p><p>To run properly <em>v.out.blend</em> needs ParaView and its ParaView python client (pvpython) to be installed on your system.
+</p>
+
+
+<h2>EXAMPLE</h2>
+
+This command generates a Stanford 3d mesh named <tt>MyMesh.ply</tt>, and a tiff image named <tt>ortho.tif</tt>, on the <tt>~/Desktop</tt> directory :
+<p><tt> 
+v.out.blend vinput=MyMesh rinput=ortho dsn="~/Desktop"
+</tt></p>
+
+<h2>SEE ALSO</h2>
+
+<em><a
+href="https://trac.osgeo.org/grass/browser/grass-addons/grass6/vector/v.out.ply/description.html">v.out.ply</a></em>, 
+<em><a href="http://grass.osgeo.org/grass64/manuals/html64_user/v.out.vtk.html">v.out.vtk</a></em>
+
+<h2>AUTHOR</h2>
+
+Vincent Bain, Toraval, France
+
+<p><i>Last changed: $Date: 2015-05-05$</i>
+
+</body>
+</html>

Added: grass-addons/grass6/vector/v.out.blend/v.out.blend
===================================================================
--- grass-addons/grass6/vector/v.out.blend/v.out.blend	                        (rev 0)
+++ grass-addons/grass6/vector/v.out.blend/v.out.blend	2014-05-05 15:27:22 UTC (rev 60112)
@@ -0,0 +1,209 @@
+#!/bin/bash
+#
+################################################################################
+#
+# MODULE:		v.out.blend
+# AUTHOR(S):		Vincent Bain
+# PURPOSE:		outputs a 3d delaunay triangulation (.ply file) from a 3d vector pointcloud and optionally an image to drape on (.tif file), e.g. within blender
+
+# COPYRIGHT:		(C)Toraval-Vincent Bain 2014-05-05
+#
+#			This program is free software under the GNU General Public
+#			License (>=v2). Read the file COPYING that comes with GRASS
+#			for details.
+#
+# VERSION:		1.0
+#			test version
+#			
+################################################################################
+
+
+#%Module
+#% description: blender user-oriented add-on. Outputs a 3d delaunay triangulation (.ply file) from a 3d vector pointcloud and optionally an image to drape on (.tif file), e.g. within blender
+#%End
+
+#%Option
+#% key: vinput
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: Name of 3d vector point to export
+#% gisprompt: old,vector,vector
+#% guisection: Required
+#%End
+
+#%Option
+#% key: rinput
+#% type: string
+#% required: no
+#% multiple: no
+#% key_desc: name
+#% description: Name of raster to export
+#% gisprompt: old,cell,raster
+#% guisection: Optional
+#%End
+
+#%Option
+#% key: dsn
+#% type: string
+#% required: no
+#% multiple: no
+#% label: output directory name
+#% description: directory for storage. Default : current mapset
+#%End
+
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+
+#---------------------------------------------
+# Get environnment
+GIS_DBASE=`g.gisenv get=GISDBASE`
+GIS_LOCATION_NAME=`g.gisenv get=LOCATION_NAME`
+GIS_MAPSET=`g.gisenv get=MAPSET`
+GIS_MAP_PATH="${GIS_DBASE}/${GIS_LOCATION_NAME}/${GIS_MAPSET}"
+#---------------------------------------------
+
+#---------------------------------------------
+# Check for awk
+if ! echo test | awk '{print $0}' > /dev/null 2>&1; then
+	g.message -e "`basename $0`: awk required, please install awk/gawk first" 1>&2
+	exit 1
+fi
+#---------------------------------------------
+
+#---------------------------------------------
+# Check for pvpython
+if [ ! -x "`which pvpython`" ] ; then
+	g.message -e "pvpython (from paraview) required, install it first"
+	exit 1
+fi
+#---------------------------------------------
+
+#---------------------------------------------
+# save command line
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    CMDLINE=`basename "$0"`
+    for arg in "$@" ; do
+        CMDLINE="$CMDLINE \"$arg\""
+    done
+    export CMDLINE
+	exec g.parser "$0" "$@"
+fi
+#---------------------------------------------
+
+#---------------------------------------------
+# Functions handling user break
+
+Cleanup()
+{
+	if [ $vinput ]; then g.remove vect=$vinput 2>/dev/null; fi
+	if [ $rinput ]; then g.remove rast=$rinput 2>/dev/null; fi
+}
+Cleanexit()
+{
+	g.message -w "User break !"
+	Cleanup
+	exit 1
+}
+trap "Cleanexit" 2 3 15
+#---------------------------------------------
+
+#---------------------------------------------
+# switching working directory
+if [ ! $GIS_OPT_DSN ] ; then
+	dsn=`dirname "$HISTFILE"`
+else
+	dsn=$GIS_OPT_DSN
+fi
+cd $dsn
+#---------------------------------------------
+
+#---------------------------------------------
+# retrieving region bounds
+eval `g.region -g`
+#---------------------------------------------
+
+vinput="voutblend_$$"
+rinput="voutblend_$$"
+g.copy vect=$GIS_OPT_VINPUT,$vinput
+#---------------------------------------------
+# fitting the input vector to the current region (possible subset of points), then fitting region on this set of points
+v.edit -r map=$vinput type=point tool=delete bbox=$w,$s,$e,$n
+g.region -p vect=$vinput
+#---------------------------------------------
+
+#---------------------------------------------
+# running v.out.vtk
+v.out.vtk input=$vinput output=${GIS_OPT_VINPUT}.vtk
+g.message "File ${GIS_OPT_VINPUT}.vtk written to $dsn"
+#---------------------------------------------
+
+#---------------------------------------------
+# retrieving variables $west $south $east $north $bottom
+eval `v.info -g map=$vinput`
+#---------------------------------------------
+
+#---------------------------------------------
+# shifting and scaling dataset to fit with blender coordinate space
+# first let's get the number of selected points
+n=`sed -n '5'p ${GIS_OPT_VINPUT}.vtk | awk '{print$2}'`
+n=$((n+5))
+
+# we save the file header (6 lines)
+sed -n '1,5'p ${GIS_OPT_VINPUT}.vtk > ${GIS_OPT_VINPUT}rec.vtk
+
+# we adjust 3d coords
+# west=`echo "scale=3;$west - 5" | bc`
+# south=`echo "scale=3;$south - 5" | bc`
+# bottom=`echo "scale=3;$bottom - 5" | bc`
+sed -n '6,'$n''p ${GIS_OPT_VINPUT}.vtk | awk -v west="$west" -v south="$south" -v bottom="$bottom" '{print ($1-west)/10,($2-south)/10,($3-bottom)/10,""}' >> ${GIS_OPT_VINPUT}rec.vtk
+g.message "File ${GIS_OPT_VINPUT}rec.vtk written to $dsn, at scale 0.1 and the following shifts:
+x: -$west
+y: -$south
+z : -$bottom"
+
+# we give up with file tail : perhaps someone will need to keep scalar values, here we don't
+# count=`wc -l ${vinput} | awk '{print $1}' `
+# n=$(( n + 1 ))
+# count=$(( count - 1 ))
+# sed -n $n,${count}p ${GIS_OPT_VINPUT}.vtk >>${GIS_OPT_VINPUT}rec.vtk
+# sed -n '$'p ${GIS_OPT_VINPUT}.vtk | awk -v bottom
+#---------------------------------------------
+
+#---------------------------------------------
+# triangluating the pointcloud with pvpython (paraview python console)
+
+echo "
+from paraview.simple import *
+pointsrec = LegacyVTKReader( FileNames=['"${GIS_OPT_VINPUT}rec.vtk"'] )
+Delau = Delaunay2D()
+DataRepresentation3 = Show()
+writer = CreateWriter('"${GIS_OPT_VINPUT}rec.ply"',Delau)
+writer.FileType='Ascii'
+writer.UpdatePipeline()
+del writer" | pvpython 
+
+g.message "File ${GIS_OPT_VINPUT}rec.ply written to $dsn"
+#---------------------------------------------
+
+#---------------------------------------------
+# exporting the optional raster to tiff image
+if [ $GIS_OPT_RINPUT ] ; then
+	#---------------------------------------------
+	# r.mapcalc pour détourer le raster à la taille de la région
+	echo "$rinput = $GIS_OPT_RINPUT" | r.mapcalc
+	r.out.tiff input=$rinput output=${GIS_OPT_RINPUT}.tif compression=lzw
+	g.message "File ${GIS_OPT_RINPUT}.tif written to $dsn"
+fi
+
+Cleanup
+exit 0


Property changes on: grass-addons/grass6/vector/v.out.blend/v.out.blend
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list