visualization stuff
[physik/posic.git] / visualize
1 #!/bin/sh
2
3 #
4 # visualization script
5 # author: frank.zirkelbach@physik.uni-augsburg.de
6 #
7
8 # help function
9 draw_cyl() {
10         cat >> temp.pov <<-EOF
11 cylinder {
12 <$1, $3, $2>, <$4, $6, $5>, 0.05
13 pigment { color White }
14 }
15 EOF
16 }
17
18         
19
20 directory="doesnt_exist____for_sure"
21 width="1024"
22 height="768"
23 radius="1.0"
24 x0=""; y0=""; z0="";
25 x1=""; y1=""; z1="";
26 cx=""; cy=""; cz="";
27 lx="0"; ly="-100"; lz="100";
28
29 while [ "$1" ]; do
30         case "$1" in
31                 -d)             directory=$2;           shift 2;;
32                 -w)             width=$2;               shift 2;;
33                 -h)             height=$2;              shift 2;;
34                 -r)             radius=$2;              shift 2;;
35                 -nll)           x0=$2; y0=$3; z0=$4;    shift 4;;
36                 -fur)           x1=$2; y1=$3; z1=$4;    shift 4;;
37                 -c)             cx=$2; cy=$3; cz=$4;    shift 4;;
38                 -l)             lx=$2; ly=$3; lz=$4;    shift 4;;
39                 -o)             ortographic=1;          shift 1;;
40                 *)
41                                 echo "options:"
42                                 echo "########"
43                                 echo "directory to progress:"
44                                 echo "  -d <directory> (mandatory)"
45                                 echo "png dim:"
46                                 echo "  -w <width>"
47                                 echo "  -h <height>"
48                                 echo "atom size:"
49                                 echo "  -r <radius>"
50                                 echo "visualization volume:"
51                                 echo "  -nll <x> <y> <z> (near lower left)"
52                                 echo "  -fur <x> <y> <z> (far upper right)"
53                                 echo "  -o (ortographic)"
54                                 echo "povray:"
55                                 echo "  -c <x> <y> <z> (camera position)"
56                                 echo "  -l <x> <y> <z> (light source)"
57                                 exit 1;;
58         esac
59 done
60
61 if [ ! -d $directory ] ; then
62         echo "no valid directory"
63         exit 1
64 fi
65
66 POVRAY="povray -W${width} -H${height} -d" 
67
68 for file in $directory/atomic_conf_*.xyz; do
69
70         cat > temp.pov <<-EOF
71 #include "colors.inc"
72 #include "textures.inc"
73 #include "shapes.inc"
74 #include "glass.inc"
75 #include "metals.inc"
76 #include "woods.inc"
77 #include "stones.inc"
78 EOF
79
80         # meta info
81         count=`grep '# \[P\]' $file | awk '{ print $3 }'`
82         time=`grep '# \[P\]' $file | awk '{ print $4 }'`
83         camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
84         [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
85
86         # atoms
87         if [ -n "$x0" ]; then
88                 export x0 y0 z0 x1 y1 z1 radius
89                 cat $file | grep -v '#' | awk '\
90                 BEGIN {
91                         x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
92                         x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
93                         radius=ENVIRON["radius"];
94                 }
95                 {
96                         if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
97                            ($2<=x1)&&($3<=y1)&&($4<=z1)) {
98                                 print "sphere { <"$2","$4","$3">, "radius" ";
99                                 print "texture { pigment { color "$5" } ";
100                                 print "finish { phong 1 metallic } } }";
101                         }
102                 }' >> temp.pov
103         else
104                 cat $file | grep -v '#' | while read name x y z color temp; do
105                         cat >> temp.pov <<-EOF
106 sphere {
107 <$x, $z, $y>, $radius
108 texture {
109 pigment { color $color }
110 finish {
111 phong 1
112 metallic
113 }
114 }
115 }
116 EOF
117                 done
118         fi
119
120         # boundaries
121         if [ -z "$x0" ]; then
122         cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
123                 cat >> temp.pov <<-EOF
124 cylinder {
125 <$x1, $z1, $y1>, <$x2, $z2, $y2>, 0.05
126 pigment { color White }
127 }
128 EOF
129         done
130         else
131                 # manually drawing the 3x4 boundaries ...
132                 draw_cyl $x0 $y0 $z0 $x1 $y0 $z0
133                 draw_cyl $x0 $y0 $z0 $x0 $y1 $z0
134                 draw_cyl $x1 $y1 $z0 $x1 $y0 $z0
135                 draw_cyl $x0 $y1 $z0 $x1 $y1 $z0
136
137                 draw_cyl $x0 $y0 $z1 $x1 $y0 $z1
138                 draw_cyl $x0 $y0 $z1 $x0 $y1 $z1
139                 draw_cyl $x1 $y1 $z1 $x1 $y0 $z1
140                 draw_cyl $x0 $y1 $z1 $x1 $y1 $z1
141
142                 draw_cyl $x0 $y0 $z1 $x0 $y0 $z0
143                 draw_cyl $x0 $y1 $z1 $x0 $y1 $z0
144                 draw_cyl $x1 $y0 $z1 $x1 $y0 $z0
145                 draw_cyl $x1 $y1 $z1 $x1 $y1 $z0
146         fi
147
148         # add camera and light source
149         cat >> temp.pov <<-EOF
150 camera {
151 EOF
152         if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
153 orthographic
154 EOF
155         fi
156         cat >> temp.pov <<-EOF
157 location $camloc
158 look_at <0,0,0>
159 }
160 light_source { <0,100,-100> color White shadowless }
161 EOF
162
163         # mv png
164         $POVRAY temp.pov > /dev/null 2>&1
165         mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
166
167 done
168
169 echo "done"