ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/xyz2pov/src/pov_writer.c
(Generate patch)

Comparing:
branches/mmeineke/xyz2pov/src/pov_writer.c (file contents), Revision 60 by mmeineke, Thu Aug 1 21:12:33 2002 UTC vs.
trunk/xyz2pov/src/pov_writer.c (file contents), Revision 1095 by mmeineke, Mon Apr 5 19:34:21 2004 UTC

# Line 1 | Line 1
1 + #define _FILE_OFFSET_BITS 64
2 +
3   #include <stdio.h>
4   #include <stdlib.h>
5   #include <string.h>
# Line 22 | Line 24 | void clean_bonds(void);
24    
25   void clean_bonds(void);
26  
27 + void initBondList(void){
28 +  bl_head = NULL;
29 + }
30  
31   void pov_write(FILE *out_file, struct coords *the_coords, int n_atoms,
32 <               int d_hydrogens, int d_bonds, int d_atoms){
32 >               int d_hydrogens, int d_bonds, int d_atoms, int d_vectors){
33  
34    int i,j; /*loop counters */
35    int skip_atom, skip_bond, test1, test2; /*booleans */
# Line 44 | Line 49 | void pov_write(FILE *out_file, struct coords *the_coor
49              "//************************************************************\n"
50              "\n"
51              "\n");
52 <
52 >    
53      for(i = 0; i < n_atoms; i++){
54        
55 <      skip_atom = 0;
55 >      skip_atom = 0;    
56        
57        if(!d_hydrogens){
58          skip_atom = !strcmp("H", the_coords[i].name);
59        }
60        
61 <      if(!skip_atom){
62 <        
61 >      if(!skip_atom){          
62 >        
63          fprintf(out_file,
64                  "make_%s_atom( %lf, %lf, %lf )\n",
65                  the_coords[i].name,
# Line 63 | Line 68 | void pov_write(FILE *out_file, struct coords *the_coor
68                  the_coords[i].y);
69        }
70      }
71 <    
71 >
72      fprintf(out_file,
73              "\n"
74              "\n");
75 +  }
76 +
77 +      
78 +  if (d_vectors) {
79 +
80 +    fprintf(out_file,
81 +            "//************************************************************\n"
82 +            "// The list of vectors\n"
83 +            "//************************************************************\n"
84 +            "\n"
85 +            "\n");
86      
87 +    for(i = 0; i < n_atoms; i++){
88 +      
89 +      if (the_coords[i].hasVector) {
90 +        fprintf(out_file,
91 +                "make_%s_vector(%lf, %lf, %lf, %lf, %lf, %lf)\n",
92 +                the_coords[i].name,
93 +                the_coords[i].x,
94 +                the_coords[i].z,
95 +                the_coords[i].y,
96 +                the_coords[i].ux,
97 +                the_coords[i].uz,
98 +                the_coords[i].uy);
99 +      }
100 +    }
101 +    
102 +    fprintf(out_file,
103 +            "\n"
104 +            "\n");
105    }
106 <  
106 >      
107    if(d_bonds){
108      
109      fprintf(out_file,
# Line 79 | Line 113 | void pov_write(FILE *out_file, struct coords *the_coor
113              "\n"
114              "\n");
115      
116 <    make_bonds(the_coords, n_atoms);
116 >    if( bl_head == NULL ) make_bonds(the_coords, n_atoms);
117      
118      current_bond = bl_head->next;
119      
# Line 130 | Line 164 | void pov_write(FILE *out_file, struct coords *the_coor
164        current_bond = current_bond->next;
165      }
166    
167 <    clean_bonds();
167 >    if( regenerateBonds )clean_bonds();
168    }
169   }
170  
# Line 209 | Line 243 | void clean_bonds(){
243      }
244      
245      bl_head->next = NULL;
246 +    free( bl_head );
247 +    bl_head = NULL;
248   }
249  
250  
# Line 250 | Line 286 | void make_header_macros(FILE *out_file){
286              "  #local z2 = end_2z;\n"
287              "\n"
288              "  #if(ROTATE)\n"
289 <            "    #local x1_new = A11 * x1 + A12 * y1 + A13 * z1;\n"
290 <            "    #local y1_new = A21 * x1 + A22 * y1 + A23 * z1;\n"
291 <            "    #local z1_new = A31 * x1 + A32 * y1 + A33 * z1;\n"
289 >            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
290 >            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
291 >            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
292              "\n"
293 <            "    #local x2_new = A11 * x2 + A12 * y2 + A13 * z2;\n"
294 <            "    #local y2_new = A21 * x2 + A22 * y2 + A23 * z2;\n"
295 <            "    #local z2_new = A31 * x2 + A32 * y2 + A33 * z2;\n"
293 >            "    #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
294 >            "    #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
295 >            "    #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
296              "\n"
297              "  #else\n"
298              "    #local x1_new = x1;"
# Line 294 | Line 330 | void make_header_macros(FILE *out_file){
330              "\n"
331              "  #if(ROTATE)\n"
332              "\n"
333 <            "    #local x1_new = A11 * x1 + A12 * y1 + A13 * z1;\n"
334 <            "    #local y1_new = A21 * x1 + A22 * y1 + A23 * z1;\n"
335 <            "    #local z1_new = A31 * x1 + A32 * y1 + A33 * z1;\n"
333 >            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
334 >            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
335 >            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
336              "\n"
337              "  #else\n"
338              "\n"
# Line 321 | Line 357 | void make_header_macros(FILE *out_file){
357              "    }\n"
358              "  }\n"
359              "#end\n"
360 +            "#macro make_%s_vector "
361 +            "(center_x, center_y, center_z, ux, uy, uz)\n"
362              "\n"
363 +            "  #local vx = VECTOR_SCALE * ux;\n"
364 +            "  #local vy = VECTOR_SCALE * uy;\n"
365 +            "  #local vz = VECTOR_SCALE * uz;\n"
366 +            "  #local x1 = center_x - 0.5 * vx;\n"
367 +            "  #local y1 = center_y - 0.5 * vy;\n"
368 +            "  #local z1 = center_z - 0.5 * vz;\n"
369 +            "  #local x2 = center_x + 0.5 * vx;\n"
370 +            "  #local y2 = center_y + 0.5 * vy;\n"
371 +            "  #local z2 = center_z + 0.5 * vz;\n"
372 +            "  #local v2 = vx*vx + vy*vy + vz*vz;\n"
373 +            "  #local vl  = sqrt(v2);\n"
374 +            "  #local x3 = x1 + vx * (1.0 - CONE_FRACTION);\n"
375 +            "  #local y3 = y1 + vy * (1.0 - CONE_FRACTION);\n"
376 +            "  #local z3 = z1 + vz * (1.0 - CONE_FRACTION);\n"
377 +            "\n"
378 +            "  #if(ROTATE)\n"
379 +            "    #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
380 +            "    #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
381 +            "    #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
382 +            "\n"
383 +            "    #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
384 +            "    #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
385 +            "    #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
386 +            "\n"
387 +            "    #local x3_new = rotatePointX + A11 * (x3-rotatePointX) + A12 * (y3-rotatePointY) + A13 * (z3-rotatePointZ);\n"
388 +            "    #local y3_new = rotatePointY + A21 * (x3-rotatePointX) + A22 * (y3-rotatePointY) + A23 * (z3-rotatePointZ);\n"
389 +            "    #local z3_new = rotatePointZ + A31 * (x3-rotatePointX) + A32 * (y3-rotatePointY) + A33 * (z3-rotatePointZ);\n"
390 +            "\n"
391 +            "  #else\n"
392 +            "    #local x1_new = x1;"
393 +            "    #local y1_new = y1;"
394 +            "    #local z1_new = z1;"
395 +            "\n"
396 +            "    #local x2_new = x2;"
397 +            "    #local y2_new = y2;"
398 +            "    #local z2_new = z2;"
399 +            "\n"
400 +            "    #local x3_new = x3;"
401 +            "    #local y3_new = y3;"
402 +            "    #local z3_new = z3;"
403 +            "\n"
404 +            "  #end\n"
405 +            "\n"
406 +            "  cylinder{\n"
407 +            "    < x1_new, y1_new, z1_new >,\n"
408 +            "    < x3_new, y3_new, z3_new >,\n"
409 +            "    STICK_RADIUS\n"
410 +            "    texture{\n"
411 +            "      pigment{ rgb < %lf, %lf, %lf > }\n"
412 +            "      finish{\n"
413 +            "        ambient .2\n"
414 +            "        diffuse .6\n"
415 +            "        specular 1\n"
416 +            "        roughness .001\n"
417 +            "        metallic\n"
418 +            "      }\n"
419 +            "    }\n"
420 +            "  }\n"
421 +            "  cone{\n"
422 +            "    < x2_new, y2_new, z2_new >, 0.0\n"
423 +            "    < x3_new, y3_new, z3_new >, CONE_RADIUS\n"
424 +            "    texture{\n"
425 +            "      pigment{ rgb < %lf, %lf, %lf > }\n"
426 +            "      finish{\n"
427 +            "        ambient .2\n"
428 +            "        diffuse .6\n"
429 +            "        specular 1\n"
430 +            "        roughness .001\n"
431 +            "        metallic\n"
432 +            "      }\n"
433 +            "    }\n"
434 +            "  }\n"
435 +            "#end\n"
436 +            "\n"
437              "\n",
438              name,
439              name,
440              red, green, blue,
441              name,
442              radius,
443 +            red, green, blue,
444 +            name,
445 +            red, green, blue,
446              red, green, blue);
447      
448      current_type = current_type->next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines