sualization mods + adabtions
[physik/posic.git] / visualize
index b85b839..f24e7b7 100755 (executable)
--- a/visualize
+++ b/visualize
@@ -1,15 +1,60 @@
 #!/bin/sh
 
-if [ ! -d $1 ] ; then
-       echo "no such directory -> $1"
-       exit
+#
+# visualization script
+# author: frank.zirkelbach@physik.uni-augsburg.de
+#
+
+directory="doesnt_exist____for_sure"
+width="1024"
+height="768"
+radius="1.0"
+x0=""; y0=""; z0="";
+x1=""; y1=""; z1="";
+cx=""; cy=""; cz="";
+lx="0"; ly="-100"; lz="100";
+
+while [ "$1" ]; do
+       case "$1" in
+               -d)             directory=$2;           shift 2;;
+               -w)             width=$2;               shift 2;;
+               -h)             height=$2;              shift 2;;
+               -r)             radius=$2;              shift 2;;
+               -nll)           x0=$2; y0=$3; z0=$4;    shift 4;;
+               -fur)           x1=$2; y1=$3; z1=$4;    shift 4;;
+               -c)             cx=$2; cy=$3; cz=$4;    shift 4;;
+               -l)             lx=$2; ly=$3; lz=$4;    shift 4;;
+               -o)             ortographic=1;          shift 1;;
+               *)
+                               echo "options:"
+                               echo "########"
+                               echo "directory to progress:"
+                               echo "  -d <directory> (mandatory)"
+                               echo "png dim:"
+                               echo "  -w <width>"
+                               echo "  -h <height>"
+                               echo "atom size:"
+                               echo "  -r <radius>"
+                               echo "visualization volume:"
+                               echo "  -nll <x> <y> <z> (near lower left)"
+                               echo "  -fur <x> <y> <z> (far upper right)"
+                               echo "  -o (ortographic)"
+                               echo "povray:"
+                               echo "  -c <x> <y> <z> (camera position)"
+                               echo "  -l <x> <y> <z> (light source)"
+                               exit 1;;
+       esac
+done
+               
+if [ ! -d $directory ] ; then
+       echo "no valid directory"
+       exit 1
 fi
 
-POVRAY="povray -W1024 -H768 -d" 
+POVRAY="povray -W${width} -H${height} -d" 
 
-echo "processing $1 ..."
+for file in $directory/atomic_conf_*.xyz; do
 
-for file in $1/povray_*.in ; do
        cat > temp.pov <<-EOF
 #include "colors.inc"
 #include "textures.inc"
@@ -21,49 +66,75 @@ for file in $1/povray_*.in ; do
 EOF
 
        # meta info
-       count=`grep '# \[C\]' $file | awk '{ print $3 }'`
-       time=`grep '# \[T\]' $file | awk '{ print $3 }'`
-       camloc=`grep '# \[L\]' $file | awk '{ print $3 }'`
+       count=`grep '# \[P\]' $file | awk '{ print $3 }'`
+       time=`grep '# \[P\]' $file | awk '{ print $4 }'`
+       camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
+       [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
 
        # atoms
-       cat $file | grep -v '#' | while read radius x y z ; do #temp dis; do
-               cat >> temp.pov <<-EOF
+       if [ -n "$x0" ]; then
+               export x0 y0 z0 x1 y1 z1 radius
+               cat $file | grep -v '#' | awk '\
+               BEGIN {
+                       x0=ENVIRON["x0"]; y0==ENVIRON["y0"]; z0==ENVIRON["z0"];
+                       x1=ENVIRON["x1"]; y0==ENVIRON["y1"]; z0==ENVIRON["z1"];
+                       radius=ENVIRON["radius"];
+               }
+               {
+                       if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
+                          ($2<=x1)&&($3<=y1)&&($4<=z1)) {
+                               print "sphere { <"$2","$4","$3">, "radius" ";
+                               print "texture { pigment { color "$5" } ";
+                               print "finish { phong 1, metallic } } }";
+                       }
+               }' >> temp.pov
+       else
+               cat $file | grep -v '#' | while read name x y z color temp; do
+                       cat >> temp.pov <<-EOF
 sphere {
-       <$x, $z, $y>, $radius
-       texture {
-               pigment { color Yellow }
-               finish {
-                       phong 1
-                       metallic
-                }
-       }
+<$x, $z, $y>, $radius
+texture {
+pigment { color $color }
+finish {
+phong 1
+metallic
+}
+}
 }
 EOF
-       done
+               done
+       fi
 
        # boundaries
+       if [ -z "$x0" ]; then
        cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
                cat >> temp.pov <<-EOF
 cylinder {
-       <$x1, $z1, $y1>, <$x2, $z2, $y2>, 0.05
-       pigment { color White }
+<$x1, $z1, $y1>, <$x2, $z2, $y2>, 0.05
+pigment { color White }
 }
 EOF
        done
+       fi
 
        # add camera and light source
        cat >> temp.pov <<-EOF
 camera {
-//     orthographic
-       location $camloc
-       look_at <0,0,0>
+EOF
+       if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
+orthographic
+EOF
+       fi
+       cat >> temp.pov <<-EOF
+location $camloc
+look_at <0,0,0>
 }
-light_source { <0,10000,0> color White shadowless }
+light_source { <0,100,-100> color White shadowless }
 EOF
 
        # mv png
        $POVRAY temp.pov > /dev/null 2>&1
-       mv temp.png `echo $file | sed 's/\.in/\.png/'`
+       mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
 
 done