]> hackdaworld.org Git - physik/posic.git/blob - visualize
changed default resolution
[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 directory="doesnt_exist____for_sure"
19 width="640"
20 height="480"
21 radius="1.0"
22 x0=""; y0=""; z0="";
23 x1=""; y1=""; z1="";
24 cx=""; cy=""; cz="";
25 lx="0"; ly="-100"; lz="100";
26 bx0=""; by0=""; bz0="";
27 bx1=""; by1=""; bz1="";
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                 -b)             bx0=$2; by0=$3; bz0=$4;
41                                 bx1=$5; by1=$6; bz1=$7; shift 7;;
42                 *)
43                                 echo "options:"
44                                 echo "########"
45                                 echo "directory to progress:"
46                                 echo "  -d <directory> (mandatory)"
47                                 echo "png dim:"
48                                 echo "  -w <width>"
49                                 echo "  -h <height>"
50                                 echo "atom size:"
51                                 echo "  -r <radius>"
52                                 echo "visualization volume:"
53                                 echo "  -nll <x> <y> <z> (near lower left)"
54                                 echo "  -fur <x> <y> <z> (far upper right)"
55                                 echo "  -o (ortographic)"
56                                 echo "bounding box:"
57                                 echo "  -b <x0> <y0> <z0> <x1> <y1> <z1>"
58                                 echo "povray:"
59                                 echo "  -c <x> <y> <z> (camera position)"
60                                 echo "  -l <x> <y> <z> (light source)"
61                                 exit 1;;
62         esac
63 done
64
65 if [ ! -d $directory ] ; then
66         echo "no valid directory"
67         exit 1
68 fi
69
70 POVRAY="povray -W${width} -H${height} -d" 
71
72 for file in $directory/atomic_conf_*.xyz; do
73
74         cat > temp.pov <<-EOF
75 #include "colors.inc"
76 #include "textures.inc"
77 #include "shapes.inc"
78 #include "glass.inc"
79 #include "metals.inc"
80 #include "woods.inc"
81 #include "stones.inc"
82 EOF
83
84         # meta info
85         count=`grep '# \[P\]' $file | awk '{ print $3 }'`
86         time=`grep '# \[P\]' $file | awk '{ print $4 }'`
87         camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
88         [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
89
90         # atoms
91         if [ -n "$x0" ]; then
92                 export x0 y0 z0 x1 y1 z1 radius
93                 cat $file | grep -v '#' | awk '\
94                 BEGIN {
95                         x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
96                         x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
97                         radius=ENVIRON["radius"];
98                 }
99                 {
100                         if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
101                            ($2<=x1)&&($3<=y1)&&($4<=z1)) {
102                                 print "sphere { <"$2","$4","$3">, "radius" ";
103                                 print "texture { pigment { color "$5" } ";
104                                 print "finish { phong 1 metallic } } }";
105                         }
106                 }' >> temp.pov
107         else
108                 cat $file | grep -v '#' | while read name x y z color temp; do
109                         cat >> temp.pov <<-EOF
110 sphere {
111 <$x, $z, $y>, $radius
112 texture {
113 pigment { color $color }
114 finish {
115 phong 1
116 metallic
117 }
118 }
119 }
120 EOF
121                 done
122         fi
123
124         # boundaries
125         if [ -z "$bx0" ]; then
126
127         if [ -z "$x0" ]; then
128         cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
129                 cat >> temp.pov <<-EOF
130 cylinder {
131 <$x1, $z1, $y1>, <$x2, $z2, $y2>, 0.05
132 pigment { color White }
133 }
134 EOF
135         done
136         else
137                 # manually drawing the 3x4 boundaries ...
138                 draw_cyl $x0 $y0 $z0 $x1 $y0 $z0
139                 draw_cyl $x0 $y0 $z0 $x0 $y1 $z0
140                 draw_cyl $x1 $y1 $z0 $x1 $y0 $z0
141                 draw_cyl $x0 $y1 $z0 $x1 $y1 $z0
142
143                 draw_cyl $x0 $y0 $z1 $x1 $y0 $z1
144                 draw_cyl $x0 $y0 $z1 $x0 $y1 $z1
145                 draw_cyl $x1 $y1 $z1 $x1 $y0 $z1
146                 draw_cyl $x0 $y1 $z1 $x1 $y1 $z1
147
148                 draw_cyl $x0 $y0 $z1 $x0 $y0 $z0
149                 draw_cyl $x0 $y1 $z1 $x0 $y1 $z0
150                 draw_cyl $x1 $y0 $z1 $x1 $y0 $z0
151                 draw_cyl $x1 $y1 $z1 $x1 $y1 $z0
152         fi
153
154         else
155
156                 # manually drawing the 3x4 boundaries specified by argv ...
157                 draw_cyl $bx0 $by0 $bz0 $bx1 $by0 $bz0
158                 draw_cyl $bx0 $by0 $bz0 $bx0 $by1 $bz0
159                 draw_cyl $bx1 $by1 $bz0 $bx1 $by0 $bz0
160                 draw_cyl $bx0 $by1 $bz0 $bx1 $by1 $bz0
161
162                 draw_cyl $bx0 $by0 $bz1 $bx1 $by0 $bz1
163                 draw_cyl $bx0 $by0 $bz1 $bx0 $by1 $bz1
164                 draw_cyl $bx1 $by1 $bz1 $bx1 $by0 $bz1
165                 draw_cyl $bx0 $by1 $bz1 $bx1 $by1 $bz1
166
167                 draw_cyl $bx0 $by0 $bz1 $bx0 $by0 $bz0
168                 draw_cyl $bx0 $by1 $bz1 $bx0 $by1 $bz0
169                 draw_cyl $bx1 $by0 $bz1 $bx1 $by0 $bz0
170                 draw_cyl $bx1 $by1 $bz1 $bx1 $by1 $bz0
171
172         fi      
173
174         # add camera and light source
175         cat >> temp.pov <<-EOF
176 camera {
177 EOF
178         if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
179 orthographic
180 EOF
181         fi
182         cat >> temp.pov <<-EOF
183 location $camloc
184 look_at <0,0,0>
185 }
186 light_source { <0,100,-100> color White shadowless }
187 EOF
188
189         # mv png
190         $POVRAY temp.pov > /dev/null 2>&1
191         mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
192
193 done
194
195 echo "done"