File: povrays.cmd

package info (click to toggle)
evolver 2.70+ds-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 17,148 kB
  • sloc: ansic: 127,395; makefile: 209; sh: 98
file content (190 lines) | stat: -rw-r--r-- 7,823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// povrays.cmd

// Surface Evolver command for producing POV-Ray input file.
// Output is to stdout, so redirect to desired file.

// Programmer: Ken Brakke, brakke@susqu.edu, http://www.susqu.edu/brakke

// Like povray.cmd, but with vertex normals for a smooth surface.
// A normal at a vertex of a facet is the average of all adjacent
//   facet normals within a certain angle of the original facet normal

// Usage: 
//        Use the "show edge where ..." command to declare which
//        edges are to be depicted as thin cylinders.
//        Set "edge_radius" to desired radius of edge cylinders.
//        Set "critcos" to critical cosine of angle for facets
//           regarded as smoothly joined.
//        Run "povrays" with output redirected to a file, e.g.
//            Enter command: povrays >>> "something.pov"

edge_radius := 0.003; // adjust this for desired radius of edge cylinders
critcos := 0.8;  // criterion for vertex normal averaging.

procedure print_color(integer ev_color) {
      if ( ev_color == white ) then printf " t_white "
      else if ( ev_color == black ) then printf " t_black "
      else if ( ev_color == blue) then printf " t_blue "
      else if ( ev_color == green ) then printf " t_green "
      else if ( ev_color == cyan ) then printf " t_cyan "
      else if ( ev_color == red ) then printf " t_red "
      else if ( ev_color == magenta ) then printf " t_magenta "
      else if ( ev_color == brown ) then printf " t_brown "
      else if ( ev_color == lightgray ) then printf " t_lightgray "
      else if ( ev_color == darkgray ) then printf " t_darkgray "
      else if ( ev_color == lightblue ) then printf " t_lightblue "
      else if ( ev_color == lightgreen ) then printf " t_lightgreen "
      else if ( ev_color == lightcyan ) then printf " t_lightcyan "
      else if ( ev_color == lightred ) then printf " t_lightred "
      else if ( ev_color == lightmagenta ) then printf " t_lightmagenta "
      else if ( ev_color == yellow ) then printf " t_yellow ";
}

povrays := {
   local ffx,ffy,ffz,ffnorm,vernum,nx,ny,nz,fffx,fffy,fffz,fffnorm;
   local costheta,nnorm;

  // Check assumptions
  if torus then
  { errprintf "Cannot run 'povrays' command in torus mode. Do 'detorus' first.\n";
    abort;
  };

  if symmetry_group then
  { errprintf "Cannot run 'povrays' command in symmetry group mode. Do 'detorus' first.\n";
    abort;
  };

  if space_dimension != 3 then
  { errprintf "The 'povrays' command must be run in three-dimensional space.\n";
    abort;
  };

  if surface_dimension == 1 then
  { errprintf "The 'povrays' command is not meant for the string model.\n";
    abort;
  };

  if simplex_representation then
  { errprintf "The 'povrays' command is not meant for the simplex model.\n";
    abort;
  };

  if lagrange_order >= 2 then
  { errprintf "The 'povrays' command is meant for the linear model, not quadratic or Lagrange.\n";
    abort;
  };

  if rgb_colors then
  { errprintf "The 'povrays' command does not do RGB colors; do rgb_colors off.\n";
    abort;
  };

   printf "// %s in POV-Ray format.\n\n",datafilename;

   printf "light_source { <0,0,300> color rgb <1,1,1> }\n";
   printf "light_source { <100,0,0> color rgb <1,1,1> }\n";
   printf "camera { location <12,0,0> sky <0,0,1>  // right handed \n";
   printf "         up <0,0,1> right <1.3,0,0> look_at <0,0,0> angle 15 }\n";
   printf "background { color <0.3,0.8,1.0> } // light blue\n\n";
   printf "// Textures corresponding to Evolver colors\n\n";
  
   printf "#declare t_black = texture { pigment { rgb <0.0,0.0,0.0> }}\n";
   printf "#declare t_blue = texture { pigment { rgb <0.0,0.0,1.,> }}\n";
   printf "#declare t_green = texture { pigment { rgb <0.0,1.,0.0,> }}\n";
   printf "#declare t_cyan = texture { pigment { rgb <0.0,1.,1.,> }}\n"; 
   printf "#declare t_red = texture { pigment { rgb <1.,0.0,0.0,> }}\n";
   printf "#declare t_magenta = texture { pigment { rgb <1.,0.0,1.,> }}\n";
   printf "#declare t_brown = texture { pigment { rgb <1.,0.5,0.,> }}\n";
   printf "#declare t_lightgray = texture { pigment { rgb <.6,.6,.6,> }}\n";
   printf "#declare t_darkgray = texture { pigment { rgb <.3,.3,.3,> }}\n";
   printf "#declare t_lightblue = texture { pigment { rgb <.3,.8,1.,> }}\n"; 
   printf "#declare t_lightgreen = texture { pigment { rgb <.5,1.,.5,> }}\n";
   printf "#declare t_lightcyan = texture { pigment { rgb <.5,1.,1.,> }}\n";
   printf "#declare t_lightred = texture { pigment { rgb <1.,.5,.5,> }}\n";
   printf "#declare t_lightmagenta = texture { pigment { rgb <1.,.5,1.,> }}\n";
   printf "#declare t_yellow = texture { pigment { rgb <1.,1.,.0,> }}\n";
   printf "#declare t_white = texture { pigment { rgb <1.,1.,1.,> }}\n"; 

   printf "\n//One overall object.\n";
   printf "union {\n";
   printf "// All facets in one big mesh object for efficiency.\n";
   printf "   mesh { \n";
   foreach facet ff where show and color >= 0 do {

     printf "   smooth_triangle { ";
     ffx := ff.x; ffy := ff.y; ffz := ff.z;
     ffnorm := sqrt(ffx^2 + ffy^2 + ffz^2);
     vernum := 1; 
     while ( vernum <= 3 ) do
     { nx := 0; ny := 0; nz := 0;
       foreach ff.vertex[vernum].facet fff do
       { fffx := fff.x; fffy := fff.y; fffz := fff.z;
         fffnorm := sqrt(fffx^2 + fffy^2 + fffz^2);
         costheta := (fffx*ffx+fffy*ffy+fffz*ffz)/ffnorm/fffnorm;
         if ( costheta > critcos ) then
         { nx := nx + fffx/fffnorm;
           ny := ny + fffy/fffnorm;
           nz := nz + fffz/fffnorm;
         } 
         else if ( costheta < -critcos ) then  // in case nonorientable
         { nx := nx - fffx/fffnorm;
           ny := ny - fffy/fffnorm;
           nz := nz - fffz/fffnorm;
         } 
       };
       nnorm := sqrt(nx^2+ny^2+nz^2);
       if vernum > 1 then printf ",";
       printf "<%f,%f,%f>,<%f,%f,%f>",
        ff.vertex[vernum].x,ff.vertex[vernum].y,ff.vertex[vernum].z, 
        nx/nnorm,ny/nnorm,nz/nnorm;
       vernum := vernum + 1;
     };
     printf " texture {";
     if view_matrix[1][1]*ffx + view_matrix[1][2]*ffy + view_matrix[1][3]*ffz > 0
     then
       print_color(ff.frontcolor)
     else
       print_color(ff.backcolor);
      printf " } }\n";
   };
   printf "  }  // end of mesh object\n";

   // Do desired edges
   printf "#declare edge_radius = %f;\n",edge_radius; 
   foreach edge ee where ee.show do
   { printf "cylinder { <%f,%f,%f>,<%f,%f,%f> edge_radius texture {", 
       ee.vertex[1].x,ee.vertex[1].y,ee.vertex[1].z,
       ee.vertex[2].x,ee.vertex[2].y,ee.vertex[2].z;
     print_color(ee.color);
     printf "} }\n";
   };

   // Windup
   printf "// overall viewing transformation\n";
   printf "  matrix < %f,%f,%f,\n",
        view_matrix[1][1],view_matrix[2][1],view_matrix[3][1];
   printf "           %f,%f,%f,\n",
        view_matrix[1][2],view_matrix[2][2],view_matrix[3][2];
   printf "           %f,%f,%f,\n",
        view_matrix[1][3],view_matrix[2][3],view_matrix[3][3];
   printf "           %f,%f,%f>\n",
        view_matrix[1][4],view_matrix[2][4],view_matrix[3][4];
   printf " }  // end of all objects\n";
}



// End povrays.cmd

// Usage: 
//        Use the "show edge where ..." command to declare which
//        edges are to be depicted as thin cylinders.
//        Set "edge_radius" to desired radius of edge cylinders.
//        Set "critcos" to critical cosine of angle for facets
//           regarded as smoothly joined.
//        Run "povray" and redirect to desired file, e.g.
//            Enter command: povray >>> "something.pov"
// Run "povrays" with output redirected to a file, e.g.
//    Enter command: povrays >>> "something.pov"