Debian Codegraph @

src/bin/geomutil/maple2oogl/gvplot.mapleV4

raw
1 ##########################
2 ##
3 ## Title : writeoogl, a package for converting maple PLOT3D
4 ## objects to Geomview data objects.
5 ## gvplot, interactive pipe to Geomview from Maple
6 ##
7 ## Created : Dec 5 1993
8 ##
9 ## Authors : Frederick Wicklin and
10 ## Stuart Levy
11 ## The Geometry Center
12 ##
13 ## Documentation : currently ?gvplot or ?writeoogl or ?geomview
14 ##
15 ## History
16 ## fjw 9/21/93 initial maple->geomview for Maple VR2
17 ## slevy 11/27/93 interactive geomview pipe;
18 ## backwards compatable to Maple V
19 ## fjw 11/29/93 debugging; added color options
20 ##
21 ## lr ([email protected]) 03/28/97
22 ## modifications for Maple VR4 (replaced gc() calls)
23 ##
24 ##
25 ## Usage: readlib(gvplot);
26 ## (optional) gvcommand := `geomview initial-options ...`;
27 ## (optional) gvdirectories := `/some/dir/ectory:/other/dir...`;
28 ## 3dplot_struct := plot3d( ... ):
29 ## writeoogl(`filename`, 3dplot_struct);
30 ## gvplot(3dplot_struct);
31
32 # To search for "geomview" and "togeomview" in directories which might not
33 # be on the default UNIX search path, list those director(ies) here, as in
34 # default_gvdirectories := `/u/geom/bin:/usr/local/bin:`
35 # or, set the "gvdirectories" variable before invoking gvplot().
36
37 default_gvdirectories := ``:
38
39 # To start geomview with non-default options, or to start another program
40 # via gvplot, put its name and initial arguments here in place of `geomview`,
41 # or set the variable "gvcommand" before invoking gvplot().
42 # Changing default_gvcommand, then resaving gvplot.m, alters the default for
43 # all users; setting the gvcommand variable changes it for just your session.
44
45 default_gvcommand := `geomview`:
46
47
48 ### Upon invoking the geomview package, maple creates a global
49 ### variable UsEr_ID__ which is assigned a "random" number.
50 ### This variable is used to create user-specific files in /tmp.
51 ##################################################################
52 # There doesn't seem to be any explicit test for Maple V1 vs. V2,
53 # but all V1 plot objects seem to begin with FUNCTION, so use that fact
54 # to detect that we must be careful not to print invalid float constants.
55 ##################################################################
56 `oogl/lprn` := `oogl/lprnV2`:
57
58 writeoogl := proc()
59 global `oogl/lprn`;
60 local header, item, ps, zlist, plist, llist, ppoint, pcolor, appear,
61 i, j, totl, xrange, yrange, nx, ny, savedprintbytes,
62 coloron,colorlist,ccnt, totalverts;
63 options `Copyright 1993 by Frederick Wicklin and Stuart Levy, Geometry Center`;
64
65 if nargs > 2 or nargs = 0 then
66 ERROR(`Usage:writeoogl(``filename``,3dplot_struct); OR writeoogl(3dplot_struct);`)
67 fi;
68 ps := args[nargs];
69 if not type(ps, PLOT3D) then ERROR(`Invalid plot structure`,ps,
70 `; must be of type PLOT3D, as from plot3d(), tubeplot(), spacecurve(), etc.`)
71 fi;
72 if nargs = 2 and not type(args[1], string) then
73 ERROR(`Invalid file name (not string)`, args[1])
74 fi;
75 if nops(ps) < 1 then ERROR(`Empty 3D plot structure!`) fi;
76
77 ##################################################################
78 # When run in command-line mode, Garbage Collection (GC) #
79 # messages printed to terminal can interfere with the data flow. #
80 # Therefore suppress GC during writing of GeomView data #
81 ##################################################################
82 if nargs = 2 then
83 savedprintbytes:=kernelopts( printbytes):
84 kernelopts( printbytes=false):
85 print(`Saving Maple 3D structs to Geomview file`, args[1]);
86 writeto(args[1]);
87 fi;
88 xrange := 'xrange'; # nullify this local variable
89 appear := find_appearance(1, ps);
90 lprint( appear, `{LIST` );
91
92 ##################################################################
93 ### BEGIN main loop over all 3D plots (may be a list of plots) ###
94 ##################################################################
95 for item in ps do
96 coloron := FALSE; # default is no color info
97 header := op(0,item);
98
99 if header = FUNCTION then
100 # Maple V1 only: FUNCTION( f(x,y), xrange, yrange )
101 # or FUNCTION( x(u,v), y(u,v), z(u,v), u = u0..u1, v = v0..v1 )
102 xrange := op(nops(item)-1, item);
103 if type(xrange, `=`) then xrange := op(2, xrange) fi;
104 yrange := op(nops(item), item);
105 if type(yrange, `=`) then yrange := op(2, yrange) fi;
106 # Maple V1 -- don't trust lprint()
107 `oogl/lprn` := `oogl/lprnV1`;
108
109 ########################### GRID ############################
110 # EX: plot3d( f(x,y), x=xmin..xmax, y=ymin..ymax]
111 # Saving Maple GRID struct to geomview ZMESH struct
112 # Maple V1: FUNCTION( f(x,y), xrange,yrange ) followed by GRID( zlist )
113 # In Maple V1, we might see either ZMESH-style data (only Z per vertex)
114 # or a full 3-D mesh (x,y,z per vertex). Just check the first
115 # vertex to see.
116 # Maple V2: GRID( xrange, yrange, zlist )
117 # Maple V2 uses GRID only for ZMESH-style data,
118 # and uses a MESH header for meshes with general 3-D verts.
119 ###############################################################
120 elif header = GRID then
121 if type(xrange, `..`) then
122 zlist := item
123 else # this is typical VR2 route
124 xrange := op(1, item);
125 yrange := op(2, item);
126 zlist := op(3, item);
127 #######################################################
128 # if color, then there are 4 possibilities:
129 # colorlist = COLOR(HUE, h[1],...,h[nops[colorlist])
130 # colorlist = COLOR(HUE, h)
131 # colorlist = COLOR(RGB, r[1],g[1],b[1],...)
132 # colorlist = COLOR(RGB, r,g,b)
133 # Convert HUES to an RGB value using HSV2RGB and
134 # (assume that Maple uses s=v=1). Add a 1 at the end of
135 # the list for geomview's "alpha": 0<=>transparent, 1<=>opaque
136 #######################################################
137 if( nops(item)>3 ) then
138 colorlist := find_colorlist(4, item);
139 coloron := op(1,colorlist); # either RGB, HUE, or FALSE
140 fi;
141 fi;
142 nx := nops(zlist);
143 ny := nops(op(1,zlist));
144 if type(op(1, op(1,zlist)), list) then
145 lprint(`{ { MESH`, ny, nx)
146 else # scale this data by wrapping it in transformation matrix
147 lprint(`{ INST transform { `);
148 `oogl/lprn`( [0, (op(2,yrange)-op(1,yrange)) / (ny-1), 0, 0] );
149 `oogl/lprn`( [(op(2,xrange)-op(1,xrange)) / (nx-1), 0, 0, 0] );
150 lprint(0, 0, 1, 0);
151 `oogl/lprn`( [op(1,xrange), op(1,yrange), 0, 1] );
152 if(coloron = FALSE) then
153 lprint(` } geom { ZMESH`, ny, nx); # gv type
154 else
155 lprint(` } geom { CZMESH`, ny, nx); # color gv type
156 fi;
157 fi;
158 ccnt := 2; # set color counter to 2
159 for plist in zlist do
160 for ppoint in plist do
161 `oogl/lprn`(ppoint);
162 if (coloron = HUE) and nops(colorlist)>2 then
163 lprint(HSV2RGB(op(ccnt,colorlist), 1,1), 1);
164 ccnt := ccnt + 1;
165 elif (coloron = HUE) and nops(colorlist)=2 then
166 lprint(HSV2RGB(op(2,colorlist), 1,1), 1);
167 elif (coloron = RGB) and nops(colorlist)>4 then
168 lprint(op(ccnt,colorlist),op(ccnt+1,colorlist),op(ccnt+2,colorlist),1);
169 ccnt := ccnt + 3;
170 elif (coloron = RGB) and nops(colorlist)=4 then
171 lprint(op(2,colorlist),op(3,colorlist),op(4,colorlist), 1);
172 fi;
173 od;
174 od;
175 lprint( `} }`);
176
177 ########################### MESH ###########################
178 # EX: plot3d( [x(s,t), y(s,t), z(s,t)], s=smin..smax, t=tmin..tmax]
179 # Saving Maple MESH struct to geomview MESH struct
180 ###############################################################
181 elif header = MESH then
182 llist := op(1, item):
183 if( nops(item)>1 ) then
184 colorlist := find_colorlist(2, item);
185 coloron := op(1,colorlist); # either RGB, HUE, or FALSE
186 fi;
187 if(coloron=FALSE) then
188 lprint(`{ MESH ` ); # gv type
189 else
190 lprint(`{ CMESH ` ); # color gv type
191 fi;
192 lprint( nops(llist)); # num x elements
193 lprint( nops(op(1,llist)) ); # num y elements
194 # Maple store points in row-dominant manner
195 # But geomview want column-dominant, so need to
196 # print out the transpose of the matrix in the plot3d struct
197 nx := nops(llist); # maple rows
198 ny := nops(op(1,llist)); # maple cols
199 for j from 1 to ny do
200 for i from 1 to nx do
201 ppoint := op(j, op(i,llist));
202 `oogl/lprn`(ppoint);
203 if (coloron = HUE) and nops(colorlist)>2 then
204 lprint(HSV2RGB(op((i-1)*ny+j +1,colorlist), 1,1), 1);
205 elif (coloron = HUE) and nops(colorlist)=2 then
206 lprint(HSV2RGB(op(2,colorlist), 1,1), 1);
207 elif (coloron = RGB) and nops(colorlist)>4 then
208 lprint(op(3*((i-1)*ny+j-1)+2,colorlist),op(3*((i-1)*ny+j-1)+3,colorlist),op(3*((i-1)*ny+j-1)+4,colorlist),1);
209 elif (coloron = RGB) and nops(colorlist)=4 then
210 lprint(op(2,colorlist),op(3,colorlist),op(4,colorlist), 1);
211 fi;
212 od;
213 od;
214 lprint( `}`);
215
216 ########################### CURVES ##########################
217 # EX: spacecurve( [x(t), y(t), z(t)], t=tmin..tmax]
218 # Saving Maple CURVES struct to geomview VECT struct
219 ###############################################################
220 elif header = CURVES then
221 llist := select(type, item, list);
222 if( nops(item)>1 ) then
223 colorlist := find_colorlist(2, item);
224 coloron := op(1,colorlist); # either RGB, HUE, or FALSE
225 fi;
226 lprint(`{ VECT `); # gv type
227 # Number of polylines, total vertices.
228 totalverts := sum('nops(op(i,llist))', 'i'=1..nops(llist));
229 lprint(nops(llist), totalverts);
230 if coloron=FALSE then
231 lprint(1); # One color in all
232 lprint(seq(nops(op(i,llist)), i=1..nops(llist))); # Vertex counts
233 lprint(1, 0 $ 'i'=2..nops(llist)); # Color counts.
234 else
235 lprint(totalverts); # Total number of colors, 1 per vert
236 lprint(seq(nops(op(i,llist)), i=1..nops(llist))); # Vertex counts
237 lprint(seq(nops(op(i,llist)), i=1..nops(llist))); # color per vert
238 fi;
239 for plist in llist do
240 for ppoint in plist do # print all vertices
241 `oogl/lprn`(ppoint);
242 od
243 od;
244 if coloron=FALSE then
245 lprint(1,1,1,1); # color RGBA = white and opaque
246 elif (coloron = HUE) and nops(colorlist)>2 then
247 for ccnt from 2 to nops(colorlist) do
248 lprint(HSV2RGB(op(ccnt,colorlist), 1,1), 1);
249 od;
250 elif (coloron = HUE) and nops(colorlist)=2 then
251 for ccnt from 1 to nops(llist) do
252 lprint(HSV2RGB(op(2,colorlist), 1,1), 1);
253 od;
254 elif (coloron = RGB) and nops(colorlist)>4 then
255 for ccnt from 2 by 3 to nops(colorlist) do
256 lprint(op(ccnt,colorlist),op(ccnt+1,colorlist),op(ccnt+2,color\list),1);
257 od;
258 elif (coloron = RGB) and nops(colorlist)=4 then
259 for ccnt from 1 to nops(llist) do
260 lprint(op(2,colorlist),op(3,colorlist),op(4,colorlist),1);
261 od;
262 fi;
263 lprint( `}`);
264
265 ######################### POLYGONS ##########################
266 #EX:polygonplot3d([seq([seq([x(s,t),y(s,t),z(s,t)],s=smin..smax],tmin..tmax])):
267 # Polygons are handled differently than the other objects w/r/t
268 # color. Leave color alone and let user change color using geomview.
269 ###############################################################
270 elif header = POLYGONS then
271 pcolor := i $ i=1..0; # Empty sequence
272 totl := 0: nx := 0: # use nx to count number of polygons
273 for llist in item do # sequence of lists POLY(),COLOR(),
274 if type(llist,list) then
275 nx := nx + 1; # number of polygons
276 totl := totl + nops(llist); # compute total number of vertices
277 fi
278 od;
279
280 lprint(find_appearance(1, item));
281
282 # if coloron=FALSE then
283 lprint(`{ OFF `); # gv type
284 # else
285 # lprint(`{ COFF `); # color
286 # fi;
287 lprint(totl, nx, 0); # total verts,polygons,"edges"(not used!)
288 for llist in item do
289 if type(llist,list) then
290 for ppoint in llist do
291 `oogl/lprn`(ppoint); # List of vertices
292 od;
293 fi;
294 od;
295 lprint(``);
296 totl := 0;
297 for llist in item do
298 if type(llist,function)
299 and (op(0,llist)=COLOR or op(0,llist)=COLOUR) then
300 colorlist := llist;
301 if op(1,llist)=HUE and nops(colorlist)=2 then
302 pcolor := HSV2RGB(op(2,colorlist),1,1); # use ppoint for RGB
303 elif op(1,llist)=RGB and nops(colorlist)=4 then
304 pcolor := op(2..4,colorlist);
305 fi;
306 elif type(llist,list) then
307 ## There are only two possibilities for POLYGONS ##
308 ## In both cases, it means entire polygon is same color ##
309 lprint( nops(llist), i $ i=totl..totl+nops(llist)-1, ` `, pcolor);
310 totl := totl + nops(llist);
311 fi;
312 od;
313 lprint( `}`);
314
315 ######################### POINTS ##########################
316 #EX:PLOT3D(POINTS([0,0,1],[1,0,0],[0,1,0]));
317 ###############################################################
318 elif header = POINTS then
319 lprint(`{ VECT`, nops(item), nops(item), 0);
320 for plist in item do lprint(`1`) od;
321 lprint(``);
322 for plist in item do lprint(`0`) od;
323 lprint(``);
324 for ppoint in item do
325 `oogl/lprn`(ppoint)
326 od;
327 lprint(`}`);
328
329 ########################### TEXT ############################
330 # 3D plots using the "plots" package may include TEXT
331 # This is not supported
332 ###############################################################
333 elif header = TEXT then
334 print(` `);
335 fi;
336 od; # END main for loop
337
338 lprint( `}`);
339 if nargs = 2 then
340 writeto(terminal);
341 kernelopts( printbytes=savedprintbytes):
342 fi;
343 NULL;
344 end:
345
346
347 gvplot := proc()
348 global UsEr_ID__, gvcommand, default_gvcommand, gvdirectories, default_gvdirectories;
349 local gvname, gvcmd, gvdirs, ps, savedprintbytes, tmp_fname;
350 options `Copyright 1993 by Frederick Wicklin and Stuart Levy, Geometry Center`;
351 ### Set up filename to use as temporary site for data. ###
352 ### Take file in /tmp and postfix number which is (hopefully) ###
353 ### independent of users. Eg, if user1 and user2 are both ###
354 ### using writeoogl, then they will be writing to different ###
355 ### files. This is UNIX specific (but so is Geomview). ###
356 if UsEr_ID__ = 'UsEr_ID__' then
357 UsEr_ID__ := (round( rand() * (time()+1) ) mod 9999) + 1;
358 fi;
359 tmp_fname := `Maple`.(UsEr_ID__);
360
361 ### Let user specify, via "gvcommand" and "gvdirectories" global vars,
362 ### which program/args to run when invoking geomview,
363 ### and how to set the search path to find it and togeomview.
364
365 if gvcommand <> 'gvcommand'
366 then gvcmd := gvcommand
367 else gvcmd := default_gvcommand
368 fi;
369 if gvdirectories <> 'gvdirectories'
370 then gvdirs := gvdirectories
371 else gvdirs := default_gvdirectories
372 fi;
373
374 ps := args[nargs];
375 gvname := `Maple`;
376
377 if nargs < 1 or nargs > 2 then
378 ERROR(`Usage: gvplot(3dplot_structure) -or- gvplot(``name``, 3dplot_structure)`);
379 fi;
380 if nargs > 1 then gvname := args[1] fi;
381 if not type( ps, PLOT3D) then
382 ERROR(`Invalid plot structure`,ps,
383 `; must be of type PLOT3D, as from plot3d(), tubeplot(), spacecurve(), etc.`)
384 fi;
385 # start geomview reading from stdin
386 if system( `PATH=` . gvdirs . `:$PATH togeomview -Mcp `.tmp_fname.` `.gvcmd.`</dev/null` ) <> 0 then
387 ERROR(`gvplot: togeomview: Can't start a copy of geomview. `.
388 `If "togeomview" or "geomview" were not found `.
389 `try setting the variable "gvdirectories" to the name of the directory where `.
390 `they're installed (or to a colon-separated list of directories).`);
391 fi;
392 savedprintbytes:=kernelopts( printbytes):
393 kernelopts( printbytes=false):
394 writeto(`/tmp/geomview/`.tmp_fname);
395 lprint(`(geometry`, gvname);
396 writeoogl( ps );
397 lprint(`)`);
398 writeto(terminal);
399 kernelopts( printbytes=savedprintbytes):
400 NULL;
401 end:
402
403 gvcommand := proc()
404 global UsEr_ID__, gvcommand, default_gvcommand, gvdirectories, default_gvdirectories;
405 local gvname, gvcmd, gvdirs, ps, savedprintbytes, tmp_fname;
406 options `Copyright 1993 by Frederick Wicklin and Stuart Levy, Geometry Center`;
407 ### Set up filename to use as temporary site for data. ###
408 ### Take file in /tmp and postfix number which is (hopefully) ###
409 ### independent of users. Eg, if user1 and user2 are both ###
410 ### using writeoogl, then they will be writing to different ###
411 ### files. This is UNIX specific (but so is Geomview). ###
412 if UsEr_ID__ = 'UsEr_ID__' then
413 UsEr_ID__ := (round( rand() * (time()+1) ) mod 9999) + 1;
414 fi;
415 tmp_fname := `Maple`.(UsEr_ID__);
416
417 ### Let user specify, via "gvcommand" and "gvdirectories" global vars,
418 ### which program/args to run when invoking geomview,
419 ### and how to set the search path to find it and togeomview.
420
421 if gvcommand <> 'gvcommand'
422 then gvcmd := gvcommand
423 else gvcmd := default_gvcommand
424 fi;
425 if gvdirectories <> 'gvdirectories'
426 then gvdirs := gvdirectories
427 else gvdirs := default_gvdirectories
428 fi;
429
430 # start geomview reading from stdin
431 if system( `PATH=` . gvdirs . `:$PATH togeomview -Mcp `.tmp_fname.` `.gvcmd.`</dev/null` ) <> 0 then
432 ERROR(`gvplot: togeomview: Can't start a copy of geomview. `.
433 `If "togeomview" or "geomview" were not found `.
434 `try setting the variable "gvdirectories" to the name of the directory where `.
435 `they're installed (or to a colon-separated list of directories).`);
436 fi;
437 savedprintbytes:=kernelopts( printbytes):
438 kernelopts( printbytes=false):
439 writeto(`/tmp/geomview/`.tmp_fname);
440 lprint(args);
441 writeto(terminal);
442 kernelopts( printbytes=savedprintbytes):
443 NULL;
444 end:
445
446 # possible gvplot enhancements:
447 # allow remote display?
448 # Maybe use a two-step Rube Goldberg hookup with an external converter
449 # that directly reads lprint() format. Likely to be faster for large objects.
450 # Then gvplot would read
451 # gvplot := proc()
452 # ...
453 # if system(`togeomview -Mcp Maple.raw maple2oogl -togeomview -Mcp Maple`)<>0
454 # then ERROR(...) fi;
455 # writeto(`/tmp/geomview/Maple.raw`);
456 # lprint(`(geometry`, gvname, `<<`);
457 # lprint(3dplot_struct);
458 # lprint(`>>)`);
459 # writeto(terminal);
460 # end:
461 # and writeoogl would read
462 # writeoogl := proc()
463 # ...
464 # if system(cat(`togeomview -Mcp Maple.rawdata maple2oogl -o `, fname)) <> 0
465 # then ERROR(...) fi;
466 # writeto(`/tmp/geomview/Maple.rawdata`);
467 # lprint(`<<', 3dplot_string, `>>');
468 # writeto(terminal);
469 # end:
470 #
471 # Here 'togeomview' is actually being used to start 'maple2oogl' rather
472 # than geomview itself. In the first case, maple2oogl -togeomview would
473 # invoke code to start a copy of geomview.
474
475 # Help information for writeoogl
476 `help/text/writeoogl` := TEXT(
477 ` `,
478 `HELP FOR: writeoogl, gvplot `,
479 ` `,
480 `CALLING SEQUENCE: `,
481 ` readlib(gvplot): `,
482 ` writeoogl( ``filename``, 3dplot_struct ); `,
483 ` writeoogl( 3dplot_struct ); `,
484 ` gvplot( 3dplot_struct ); `,
485 ` gvplot( ``geomview_name``, 3dplot_struct ) `,
486 ` `,
487 `PARAMETERS: `,
488 ` filename the file which will contain the Geomview data `,
489 ` 3dplot_struct a Maple PLOT3D data structure `,
490 ` geomview_name name of the object in the Geomview browser `,
491 ` `,
492 `SYNOPSIS: `,
493 ` writeoogl() accepts Maple PLOT3D structures and writes files `,
494 ` readable by Geomview. gvplot() converts Maple PLOT3D structures`,
495 ` and displays them immediately using Geomview, starting a copy of`,
496 ` Geomview if necessary.`,
497 ``,
498 ` Supported data types include the Maple structures MESH, GRID, `,
499 ` CURVES, POINTS, and POLYGONS. `,
500 ` See ?plot3d[structure] for more information on Maple PLOT3D types.`,
501 ` `,
502 ` The Maple MESH and GRID structures are translated into Geomview's`,
503 ` MESH and ZMESH objects, respectively, Maple CURVES and POINTS`,
504 ` become VECT objects, and Maple POLYGONS becomes an OFF object.`,
505 ` `,
506 ` The Maple TEXT structure is not supported. Color information is`,
507 ` supported for all objects.`,
508 ``,
509 ` The form writeoogl(filename, plot_struct) writes data in OOGL`,
510 ` (Geomview) form to the given file; writeoogl(plot) writes to the`,
511 ` current output stream as selected by writeto().`,
512 ``,
513 ` gvplot() normally starts the program "geomview", with no options;`,
514 ` to specify something else, set the variable "gvcommand", as in:`,
515 ` gvcommand := ``/usr/local/bin/gv -wpos 200x200 -c startup.gv``;`,
516 ` before invoking gvplot(). Also, if the programs "geomview" or`,
517 ` "togeomview" are not on your UNIX search path, set the variable`,
518 ` gvdirectories := ``/some/dir/ectory:/some/other/directory``;`,
519 ` to the appropriate directory (or directories separated by colons).`,
520 ` `,
521 `EXAMPLES: `,
522 ` readlib(gvplot): `,
523 ` my_plot := plot3d(sin(x+y), x=-Pi..Pi, y=-Pi..Pi): `,
524 ` writeoogl( ``sinxy.mesh``, my_plot ); `,
525 ` Saving Maple 3D structs to Geomview file, sinxy.mesh `,
526 ` steiner := plot3d([ sin(2*x)*(cos(y))^2, sin(x)*sin(2*y), `,
527 ` cos(x)*sin(2*y)], x=-Pi..Pi, y=-Pi..Pi): `,
528 ` writeoogl( ``steiner.mesh``, steiner); `,
529 ` Saving Maple 3D structs to Geomview file, steiner.mesh`,
530 ` # Display it in geomview directly `,
531 ` gvplot( steiner ); `,
532 ` # load in the plots package `,
533 ` with(plots): `,
534 ` trefoil := spacecurve([ -2*cos(t)- 1/2*cos(5*t)+ 3*sin(2*t), `,
535 ` -3*cos(2*t)+ 2*sin(t)- 1/2*sin(5*t), 2*cos(3*t), t=0..2*Pi]):`,
536 ` writeoogl( ``trefoil.vect``, trefoil); `,
537 ` Saving Maple 3D structs to Geomview file, trefoil.vect`,
538 ` tetrahedra := [[1,0,0],[-1,0,0],[0,0,1]], [[1,0,0],[0,0,1],[0,1,0]], `,
539 ` [[0,1,0],[-1,0,0],[0,0,1]], [[1,0,0],[0,1,0],[-1,0,0]]:`,
540 ` Tplot :=polygonplot3d([tetrahedra]): `,
541 ` writeoogl( ``tetrahedra.off``, Tplot); `,
542 ` Saving Maple 3D structs to Geomview file, tetrahedra.off`,
543 ` # you can even create a single file with multiple objects `,
544 ` all_objs := display3d( {my_plot, steiner, trefoil, Tplot} ): `,
545 ` writeoogl( ``all.list``, all_objs ); `,
546 ` Saving Maple 3D structs to Geomview file, all.list `,
547 ` `,
548 `SEE ALSO: plot3d[structure] `
549
550 ):
551
552 `help/text/gvplot` := `help/text/writeoogl`:
553 `help/text/geomview` := `help/text/writeoogl`:
554
555
556 # Convert number to string, avoiding excess digits and avoiding Maple V1's
557 # propensity to emit Float(mantissa,exponent) rather than ordinary exponential
558 # notation!
559
560 `oogl/cvs` := proc(v)
561 local sign, absmant;
562 options `Copyright 1993 by Stuart Levy, Geometry Center`;
563 if type(v, float) then
564 absmant := cat(abs(op(1,v)));
565 sign := substring(`-`, 1..1-signum(v));
566 if abs(v) >= 1 then
567 if(op(2,v) >= 0) then
568 cat(op(1,v), '0' $ op(2,v))
569 else
570 cat(
571 sign,
572 substring(absmant, 1..length(absmant)+op(2,v)),
573 `.`,
574 substring(absmant, length(absmant)+op(2,v)+1..8)
575 )
576 fi
577 elif abs(v) > .000001 then
578 cat( sign,
579 substring( `.0000000`, 1 .. 1-length(absmant)-op(2,v) ),
580 substring(absmant, 1..7)
581 )
582 else
583 cat( sign,
584 `.`, substring( absmant, 1..7),
585 `e`, op(2,v) + length(absmant)
586 )
587 fi
588 elif type(v, realcons) then
589 cat(v)
590 fi;
591 end:
592
593 #
594 # lprint a number, or a list of numbers.
595 #
596 `oogl/lprnV1` := proc (v)
597 local i;
598 options `Copyright 1993 by Stuart Levy, Geometry Center`;
599 if type(v, list) then
600 lprint( ' `oogl/cvs`(v[i]) ' $ i=1..nops(v) );
601 elif type(v,float) and abs(v) <= .1 then
602 lprint(`oogl/cvs`(v));
603 elif type(v, realcons) then
604 lprint(v);
605 else
606 lprint(`0 #`);
607 fi;
608 end:
609
610
611 # Ditto, but assume we're Maple V2, which prints floating constants
612 # in acceptable form. Don't bother to reformat them.
613
614 `oogl/lprnV2` := proc(v)
615 local i;
616 options `Copyright 1993 by Stuart Levy, Geometry Center`;
617 if type(v, list) then
618 lprint( 'v[i]' $ i = 1..nops(v) ); # Print on one line
619 elif type(v, realcons) then
620 lprint(v);
621 else
622 lprint(`0 #`);
623 fi
624 end:
625
626 ###############################################################
627 ## HSV2RGB converts Maple Hues to RGB colors.
628 ## The HUEs used are in [0,1] so assume that S=V=1 (this is close)
629 ## The following algorithm is from Computer Graphics
630 ## By Foley, vanDam, Feiner, Hughes, 2nd Ed. Addison-Wesley
631 ## p 593
632 ##
633 ## Adapted by fjw 11/29/93
634 ## Input: (h,s,v) in [0,1]^3
635 ## Output: sequence r,b,g each in [0,1]
636 ###############################################################
637 HSV2RGB := proc( h,s,v )
638 local hh,ip,fp,p,q,t;
639 options `Copyright 1990 by Foley, vanDam, Feiner, Hughes`;
640 if (s = 0) then # color on B/W center line
641 if (h<0) then # There is no hue,ie, hue undefined
642 RETURN( v,v,v );
643 else
644 ERROR(`Undefined color`);
645 fi;
646 else
647 if (h>1) then hh:=1 fi;
648 hh := 6*h; # hh now in [0,6]
649 ip := floor(hh); # ip is integer part of h
650 fp := hh - ip; # fp is fractional part of h
651 p := v*(1-s);
652 q := v*(1-(s*fp));
653 t := v*(1-(s*(1-fp)));
654 if (ip=0) then
655 RETURN( v,t,p );
656 elif (ip=1) then
657 RETURN( q,v,p );
658 elif (ip=2) then
659 RETURN( p,v,t );
660 elif (ip=3) then
661 RETURN( p,q,v );
662 elif (ip=4) then
663 RETURN( t,p,v );
664 else
665 RETURN( v,p,q );
666 fi;
667 fi;
668 end:
669
670
671 ########################################################
672 # find_colorlist
673 # input: n where to start looking for color data
674 # item what list to search
675 # output: list of color information or NULL list
676 ########################################################
677 find_colorlist := proc(n,item)
678 local i;
679 options `Copyright 1993 by Frederick Wicklin, Geometry Center`;
680 for i from n to nops(item) do
681 if type(op(i,item),function) and (op(0,op(i,item))=COLOR or op(0,op(i,item))=COLOUR) then
682 RETURN(op(i,item))
683 fi;
684 od;
685 RETURN([FALSE]); # no color info found
686 end:
687
688 ########################################################
689 # find_appearance
690 # input: n index to start seeking color data
691 # list list to search
692 # output: argument of STYLE option (e.g. `PATCH`) or [] list.
693 ########################################################
694 find_appearance := proc(n, list)
695 local i, part, ap, color, colortype;
696 ap := ``; color := ``;
697 for i from n to nops(list) do
698 part := op(i,list);
699 if type(part,function) and (op(0,part)=COLOR or op(0,part)=COLOUR) then
700 colortype := op(1,part);
701 if colortype = HUE and nops(part) = 2 then
702 color := [HSV2RGB(op(2,part), 1, 1)]
703 elif colortype = RGB and nops(part) = 4 then
704 color := [op(2..4,part)]
705 fi
706 # Otherwise, this "color" tag isn't for us
707 elif type(part,function) and op(0,part) = STYLE then
708 if op(1,part) = PATCH then
709 ap := cat(ap, ` +face -edge`)
710 elif op(1,part) = LINE or op(1,part) = WIREFRAME then
711 ap := cat(ap, ` -face +edge`)
712 fi
713 elif type(part,function) and op(0,part) = THICKNESS and type(op(1,part),integer) then
714 ap := cat(ap, ` linewidth `, op(1,part));
715 fi
716 od;
717 if color <> `` then
718 color := cat( op(1..3, map(v -> cat(convert(v,string),` `), color) ) );
719 ap := cat(ap, `\n material { edgecolor `, color, `\n diffuse `, color, `}\n`);
720 fi;
721 if ap <> `` then
722 ap := cat(` appearance { `, ap, `}`)
723 fi;
724 RETURN(ap);
725 end:
726
727 [`writeoogl`, `gvplot`];