ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/xyz2pov/src/pov2anim.c
Revision: 104
Committed: Wed Sep 4 18:55:09 2002 UTC (21 years, 10 months ago) by mmeineke
Content type: text/plain
File size: 7256 byte(s)
Log Message:
fixed a little seen output bug. (Tarega is not always default)

File Contents

# Content
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <dirent.h>
8
9 #define ANIM_DIR "./anim"
10 #define POV_DIR "./pov"
11
12
13 char *program_name;
14 void usage(void);
15 int isNumber( char c );
16
17 int main(argc, argv)
18 int argc;
19 char *argv[];
20 {
21
22 int i, j, k; /*loop counters */
23 mode_t dir_mode = S_IRWXU;
24
25 char pov_flags[120] = ""; /*flags to be placed on the povray command line */
26 char *prefix = NULL; /*the prefix for the input and output files */
27 int start_frame = 0; /*the start frame */
28 int in_frame; /*the current in frame we're working with. */
29 int out_frame; /*the current out frame were working with */
30 int end_frame; /*the end frame */
31 short is_end_frame = 0; /*tells us to stop before we run out of pov files */
32 int in_file_exists = 0; /*lets us know if the in_file exists */
33 int compression = 0; /* boolean for toggling the compression flag */
34 int duplicate = 0; /* boolean to turn on duplicate frames */
35 int n_duplicates = 0; /* the number of duplicate frames */
36 int done;
37
38 char current_flag;
39
40 char command[1000];
41 char pov_dir[500];
42 char anim_dir[500];
43 char out_format[500];
44 char in_format[500];
45 char in_name[5000];
46 char out_name[500];
47 char out_name2[5000];
48
49 DIR *theDir;
50 struct dirent *dirEntry;
51 int nFrames;
52 size_t prefixLength;
53 double count;
54 int out_count;
55 int in_count;
56 char test_c;
57
58
59 program_name = argv[0]; /*save the program name in case we need it*/
60
61
62
63 for( i = 1; i < argc; i++){
64
65 if(argv[i][0] =='-'){
66
67 // parse the option
68
69 if(argv[i][1] == '-' ){
70
71 // parse long word options
72
73 fprintf( stderr,
74 "Invalid option \"%s\"\n", argv[i] );
75 usage();
76
77 }
78
79 else{
80
81 // parse single character options
82
83 done = 0;
84 j = 1;
85 current_flag = argv[i][j];
86 while( (current_flag != '\0') && (!done) ){
87
88 switch(current_flag){
89
90 case 'c':
91 // -c => turn on the compression flag for x-povray
92
93 compression = 1;
94 strcat(pov_flags, " +FP ");
95 break;
96
97 case 'd':
98 // -d <#> => duplicate the frames
99
100 duplicate = 1;
101 i++;
102 n_duplicates = atoi(argv[i]);
103 done =1;
104 break;
105
106
107
108 case 'f':
109 // -f <#> => tells us the final frame
110
111 is_end_frame = 1;
112 i++;
113 end_frame = atoi(argv[i]);
114 done=1;
115 break;
116
117 case 's':
118 // -s <#> => tells the start frame
119
120 i++;
121 start_frame = atoi(argv[i]);
122 done=1;
123 break;
124
125 case 'F':
126 // -F <flags> => The flag arguments to be passed to x-povray
127
128 i++;
129 strcat(pov_flags, argv[i]);
130 done=1;
131 break;
132
133 default:
134
135 (void)fprintf(stderr, "Bad option \"-%c\"\n", current_flag);
136 usage();
137 }
138 j++;
139 current_flag = argv[i][j];
140 }
141 }
142 }
143
144 else{
145
146 if( prefix != NULL ){
147 fprintf( stderr,
148 "Error at \"%s\", program does not currently support\n"
149 "more than one prefix.\n"
150 "\n",
151 argv[i]);
152 usage();
153 }
154
155 prefix = argv[i];
156 }
157 }
158
159
160 if(prefix == NULL){
161 usage();
162 }
163
164
165 if(access(ANIM_DIR, F_OK)){
166 /*create the anim directory*/
167 mkdir(ANIM_DIR, dir_mode);
168 }
169
170 if(!compression) strcat(pov_flags, " +FT ");
171
172 strcpy(anim_dir, ANIM_DIR); strcat(anim_dir, "/");
173 strcpy(pov_dir, POV_DIR); strcat(pov_dir, "/");
174
175 // find the number of digits to output
176
177 nFrames = 0;
178 if( is_end_frame ){
179 nFrames = end_frame - start_frame;
180 }
181 else{
182
183 theDir = opendir( POV_DIR );
184 dirEntry = readdir( theDir );
185 prefixLength = strlen( prefix );
186 while( dirEntry != NULL ){
187
188 if( !strncmp( dirEntry->d_name, prefix, prefixLength ) ) nFrames++;
189
190 dirEntry = readdir( theDir );
191 }
192 closedir( theDir );
193 }
194
195 out_count = 1;
196 count = (double)( nFrames * (n_duplicates+1) );
197 while( count >= 10.0 ){
198 count /= 10.0;
199 out_count++;
200 }
201
202 // how many padded digits are there for the input
203
204 theDir = opendir( POV_DIR );
205 dirEntry = readdir( theDir );
206 prefixLength = strlen( prefix );
207 while( dirEntry != NULL ){
208
209 in_count = 0;
210 if( !strncmp( dirEntry->d_name, prefix, prefixLength ) ){
211
212 i = prefixLength;
213 test_c = dirEntry->d_name[i];
214 while( isNumber( test_c ) ){
215
216 in_count++;
217 i++;
218 test_c = dirEntry->d_name[i];
219 }
220 break;
221 }
222
223 dirEntry = readdir( theDir );
224 }
225 closedir( theDir );
226
227
228 strcpy(in_name, pov_dir);
229 strcpy(out_name, anim_dir);
230
231 sprintf( in_format, "%s%s%%0%dd.pov", pov_dir, prefix, in_count );
232
233 sprintf( out_format, "%s%s%%0%dd", anim_dir, prefix, out_count );
234 if(compression) strcat(out_format, ".ppm");
235 else strcat(out_format, ".tga");
236
237 in_frame = start_frame;
238 out_frame = 0;
239
240 if(access(ANIM_DIR, F_OK)){
241 /*create the anim directory*/
242 mkdir(ANIM_DIR, dir_mode);
243 }
244
245
246 sprintf( in_name, in_format, in_frame );
247 sprintf( out_name, out_format, out_frame );
248
249 in_file_exists = !access(in_name, F_OK);
250
251 if( is_end_frame ){
252
253 while( (in_frame <= end_frame) && in_file_exists ){
254
255
256 sprintf(command, "x-povray +I %s +O %s %s",
257 in_name, out_name, pov_flags);
258 system(command);
259
260 if(duplicate){
261 for(k = 0; k < n_duplicates; k++){
262 out_frame++;
263
264 sprintf( out_name2, out_format, out_frame );
265 sprintf(command, "cp %s %s", out_name, out_name2);
266 system(command);
267 }
268 }
269
270 in_frame++;
271 out_frame++;
272
273 sprintf( in_name, in_format, in_frame );
274 sprintf( out_name, out_format, out_frame );
275
276 in_file_exists = !access(in_name, F_OK);
277 }
278 }
279 else{
280
281 while( in_file_exists ){
282
283
284 sprintf(command, "x-povray +I %s +O %s %s",
285 in_name, out_name, pov_flags);
286 system(command);
287
288 if(duplicate){
289 for(k = 0; k < n_duplicates; k++){
290 out_frame++;
291
292 sprintf( out_name2, out_format, out_frame );
293 sprintf(command, "cp %s %s", out_name, out_name2);
294 system(command);
295 }
296 }
297
298 in_frame++;
299 out_frame++;
300
301 sprintf( in_name, in_format, in_frame );
302 sprintf( out_name, out_format, out_frame );
303
304 in_file_exists = !access(in_name, F_OK);
305 }
306 }
307
308 return 0;
309 }
310
311
312
313
314
315 /***************************************************************************
316 * prints out the usage for the command line arguments, then exits.
317 ***************************************************************************/
318
319 void usage(){
320 (void)fprintf(stderr,
321 "The proper usage is: %s [options] <pov_prefix>\n\n"
322 "Options:\n"
323 " -c turns on compression for x-povray\n"
324 " -d <#> turns on and duplicates the number of frames\n"
325 " -s <#> the starting frame number\n"
326 " -f <#> the final frame number\n"
327 " -F \"<povray flags>\"\n"
328 " flags to pass to x-povray\n"
329
330 "\n",
331 program_name);
332 exit(8);
333 }
334
335
336 int isNumber( char c ){
337
338 if( c == '0') return 1;
339 else if( c == '1') return 1;
340 else if( c == '2') return 1;
341 else if( c == '3') return 1;
342 else if( c == '4') return 1;
343 else if( c == '5') return 1;
344 else if( c == '6') return 1;
345 else if( c == '7') return 1;
346 else if( c == '8') return 1;
347 else if( c == '9') return 1;
348
349 return 0;
350 }