| 1 |
########################### Hey, Emacs, we're -*-maplev-*- mode! |
| 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 |
## Revised : 2003 |
| 14 |
## Claus-Justus Heine, Abteilung fuer Angewandte Mathematik, |
| 15 |
## Universitaet Freiburg. |
| 16 |
## |
| 17 |
## |
| 18 |
## Documentation : currently ?gvplot or ?writeoogl or ?geomview |
| 19 |
## |
| 20 |
## History |
| 21 |
## fjw 9/21/93 initial maple->geomview for Maple VR2 |
| 22 |
## slevy 11/27/93 interactive geomview pipe; |
| 23 |
## backwards compatable to Maple V |
| 24 |
## fjw 11/29/93 debugging; added color options |
| 25 |
## |
| 26 |
## lr ([email protected]) 03/28/97 |
| 27 |
## modifications for Maple VR4 (replaced gc() calls) |
| 28 |
## |
| 29 |
## |
| 30 |
## Usage: readlib(gvplot); |
| 31 |
## (optional) gvcommand := `geomview initial-options ...`; |
| 32 |
## (optional) gvdirectories := `/some/dir/ectory:/other/dir...`; |
| 33 |
## 3dplot_struct := plot3d( ... ): |
| 34 |
## writeoogl(`filename`, 3dplot_struct); |
| 35 |
## gvplot(3dplot_struct); |
| 36 |
|
| 37 |
geomview := module() |
| 38 |
option `Copyright (C) 2003 by Claus-Justus Heine, Department for Applied Mathematics, Freiburg University. Heavily based on gvplot, Copyright (C) 1993 by Frederick Wicklin and Stuart Levy, Geometry Center.`; |
| 39 |
description `Geomview interface for MapleV8`; |
| 40 |
export gvdirectories, gvcommand, fwriteoogl, writeoogl, gvplot, gvsendcmd; |
| 41 |
local default_gvdirectories, default_gvcommand, `oogl/lprn`, |
| 42 |
HSV2RGB, find_colorlist, find_appearance, |
| 43 |
make_tmpname, print_colorlist, find_view, make_localtmpname; |
| 44 |
global `gvplot/User_ID`; |
| 45 |
|
| 46 |
|
| 47 |
# To search for "geomview" and "togeomview" in directories which might not |
| 48 |
# be on the default UNIX search path, list those director(ies) here, as in |
| 49 |
# default_gvdirectories := `/u/geom/bin:/usr/local/bin:` |
| 50 |
# or, set the "gvdirectories" variable before invoking gvplot(). |
| 51 |
|
| 52 |
default_gvdirectories := ``: |
| 53 |
|
| 54 |
# To start geomview with non-default options, or to start another program |
| 55 |
# via gvplot, put its name and initial arguments here in place of `geomview`, |
| 56 |
# or set the variable "gvcommand" before invoking gvplot(). |
| 57 |
# Changing default_gvcommand, then resaving gvplot.m, alters the default for |
| 58 |
# all users; setting the gvcommand variable changes it for just your session. |
| 59 |
|
| 60 |
default_gvcommand := `geomview`: |
| 61 |
|
| 62 |
### Set up filename to use as temporary site for data. ### |
| 63 |
### Take file in /tmp and postfix number which is (hopefully) ### |
| 64 |
### independent of users. Eg, if user1 and user2 are both ### |
| 65 |
### using writeoogl, then they will be writing to different ### |
| 66 |
### files. This is UNIX specific (but so is Geomview). ### |
| 67 |
|
| 68 |
make_tmpname := proc() |
| 69 |
local tmp_fname; |
| 70 |
if `gvplot/User_ID` = '`gvplot/User_ID`' then |
| 71 |
`gvplot/User_ID` := (round( rand() * (time()+1) ) mod 9999) + 1; |
| 72 |
fi; |
| 73 |
tmp_fname := `Maple`||(`gvplot/User_ID`); |
| 74 |
return(tmp_fname); |
| 75 |
end; |
| 76 |
|
| 77 |
make_localtmpname := proc() |
| 78 |
local tmp_fname, id; |
| 79 |
id := (round( rand() * (time()+1) ) mod 9999) + 1; |
| 80 |
tmp_fname := `/tmp/`||`Maple`||`id`; |
| 81 |
return(tmp_fname); |
| 82 |
end; |
| 83 |
|
| 84 |
### Upon invoking the geomview package, maple creates a global |
| 85 |
### variable `gvplot/User_ID` which is assigned a "random" number. |
| 86 |
### This variable is used to create user-specific files in /tmp. |
| 87 |
################################################################## |
| 88 |
# There doesn't seem to be any explicit test for Maple V1 vs. V2, |
| 89 |
# but all V1 plot objects seem to begin with FUNCTION, so use that fact |
| 90 |
# to detect that we must be careful not to print invalid float constants. |
| 91 |
################################################################## |
| 92 |
|
| 93 |
writeoogl := proc() |
| 94 |
option `Copyright (C) 2003 by Claus-Justus Heine, Department for Applied Mathematics, Freiburg University. All rights reserved.`; |
| 95 |
description `convert a MapleV8 PLOT3d() structure to OOGL`; |
| 96 |
local outfd, ps; |
| 97 |
if nargs > 2 or nargs = 0 then |
| 98 |
ERROR(`Usage:writeoogl(``filename``,3dplot_struct); OR writeoogl(3dplot_struct);`) |
| 99 |
fi; |
| 100 |
if nargs = 2 and not type(args[1], string) then |
| 101 |
ERROR(`Invalid file name (not string)`, args[1]) |
| 102 |
fi; |
| 103 |
if nargs = 2 then |
| 104 |
print(`Saving Maple 3D structs to Geomview file`, args[1]); |
| 105 |
outfd:=fopen(args[1],`WRITE`,`BINARY`); |
| 106 |
else |
| 107 |
outfd:=`default`; |
| 108 |
fi; |
| 109 |
ps := args[nargs]; |
| 110 |
try |
| 111 |
fwriteoogl(outfd, ps); |
| 112 |
finally |
| 113 |
if outfd <> `default` then |
| 114 |
fclose(outfd); |
| 115 |
fi; |
| 116 |
end try; |
| 117 |
end; # writeoogl |
| 118 |
|
| 119 |
fwriteoogl := proc() |
| 120 |
local header, item, zlist, plist, llist, ppoint, pcolor, appear, |
| 121 |
i, j, totl, xrange, yrange, nx, ny, savedprintbytes, |
| 122 |
coloron, colorlist, totalverts, tlist, npoints, |
| 123 |
view, haveview, clipcmd, clipfd, clipfname, ccnt, outfd, ps; |
| 124 |
options `Copyright 1993 by Frederick Wicklin and Stuart Levy, Geometry Center`; |
| 125 |
if nargs <> 2 then |
| 126 |
ERROR(`Usage:fwriteoogl(file_descriptor,3dplot_struct);`) |
| 127 |
fi; |
| 128 |
|
| 129 |
outfd := args[1]; |
| 130 |
ps := args[2]; |
| 131 |
|
| 132 |
if not op(0, ps) = PLOT3D then ERROR(`Invalid plot structure`,ps, |
| 133 |
`; must be of type PLOT3D, as from plot3d(), tubeplot(), spacecurve(), etc.`) |
| 134 |
fi; |
| 135 |
if nops(ps) < 1 then ERROR(`Empty 3D plot structure!`) fi; |
| 136 |
|
| 137 |
xrange := 'xrange'; # nullify this local variable |
| 138 |
# |
| 139 |
# Some things we need to know beforehand. |
| 140 |
# |
| 141 |
appear := find_appearance(1, ps); |
| 142 |
colorlist := find_colorlist(1, ps); |
| 143 |
coloron := op(1,colorlist); |
| 144 |
view := find_view(1, ps); |
| 145 |
haveview := op(1,view); |
| 146 |
|
| 147 |
# |
| 148 |
# possibly pipe the stuff to clip(1) |
| 149 |
# |
| 150 |
if haveview <> FALSE then |
| 151 |
clipfname:=make_localtmpname(); |
| 152 |
clipfd :=outfd; |
| 153 |
outfd :=fopen(clipfname,WRITE,BINARY); |
| 154 |
fi; |
| 155 |
fprintf(outfd, "{ %s", appear); |
| 156 |
|
| 157 |
fprintf(outfd, "LIST"); |
| 158 |
|
| 159 |
################################################################## |
| 160 |
### BEGIN main loop over all 3D plots (may be a list of plots) ### |
| 161 |
################################################################## |
| 162 |
for item in ps do |
| 163 |
header := op(0,item); |
| 164 |
|
| 165 |
if header = GRID then |
| 166 |
if type(xrange, `..`) then |
| 167 |
zlist := item |
| 168 |
else # this is typical VR2 route |
| 169 |
xrange := op(1, item); |
| 170 |
yrange := op(2, item); |
| 171 |
zlist := op(3, item); |
| 172 |
|
| 173 |
####################################################### |
| 174 |
if( nops(item)>3 ) then |
| 175 |
colorlist := find_colorlist(4, item); |
| 176 |
coloron := op(1,colorlist); # either RGB, HUE, or FALSE |
| 177 |
fi; |
| 178 |
fi; |
| 179 |
nx := op(2,[ArrayDims(zlist)][1]); # num x elements |
| 180 |
ny := op(2,[ArrayDims(zlist)][1]);# num y elements |
| 181 |
fprintf(outfd, "{ INST transform { \n"); |
| 182 |
`oogl/lprn`(outfd, [0, (op(2,yrange)-op(1,yrange)) / (ny-1), 0, 0], "\n" ); |
| 183 |
`oogl/lprn`(outfd, [(op(2,xrange)-op(1,xrange)) / (nx-1), 0, 0, 0], "\n" ); |
| 184 |
fprintf(outfd, "0 0 1 0\n"); |
| 185 |
`oogl/lprn`(outfd, [op(1,xrange), op(1,yrange), 0, 1],"\n" ); |
| 186 |
if(coloron = FALSE) then |
| 187 |
fprintf(outfd, " } geom { ZMESH %d %d\n", ny, nx); # gv type |
| 188 |
else |
| 189 |
fprintf(outfd, " } geom { CZMESH %d %d\n", ny, nx); # color gv type |
| 190 |
fi; |
| 191 |
for j from 1 to ny do |
| 192 |
for i from 1 to nx do |
| 193 |
ppoint := zlist[j][i]; |
| 194 |
`oogl/lprn`(outfd, ppoint,"\n"); |
| 195 |
print_colorlist(outfd, coloron, colorlist); |
| 196 |
od; |
| 197 |
od; |
| 198 |
fprintf(outfd, "} }\n"); |
| 199 |
|
| 200 |
########################### MESH ########################### |
| 201 |
# EX: plot3d( [x(s,t), y(s,t), z(s,t)], s=smin..smax, t=tmin..tmax] |
| 202 |
# Saving Maple MESH struct to geomview MESH struct |
| 203 |
############################################################### |
| 204 |
elif header = MESH then |
| 205 |
llist := op(1, item): |
| 206 |
if( nops(item)>1 ) then |
| 207 |
colorlist := find_colorlist(2, item); |
| 208 |
coloron := op(1,colorlist); # either RGB, HUE, or FALSE |
| 209 |
fi; |
| 210 |
if(coloron=FALSE) then |
| 211 |
fprintf(outfd, "{ MESH \n" ); # gv type |
| 212 |
else |
| 213 |
fprintf(outfd, "{ CMESH \n" ); # color gv type |
| 214 |
fi; |
| 215 |
if op(0,llist) = Array then |
| 216 |
nx := op(2,[ArrayDims(llist)][1]); # num x elements |
| 217 |
ny := op(2,[ArrayDims(llist)][1]);# num y elements |
| 218 |
else |
| 219 |
nx := nops(llist); # maple rows |
| 220 |
ny := nops(op(1,llist)); # maple cols |
| 221 |
fi; |
| 222 |
fprintf(outfd, "%d\n", nx ); # num x elements |
| 223 |
fprintf(outfd, "%d\n", ny ); # num y elements |
| 224 |
# Maple store points in row-dominant manner |
| 225 |
# But geomview want column-dominant, so need to |
| 226 |
# print out the transpose of the matrix in the plot3d struct |
| 227 |
for j from 1 to ny do |
| 228 |
for i from 1 to nx do |
| 229 |
ppoint := llist[j][i]; |
| 230 |
`oogl/lprn`(outfd,ppoint,"\n"); |
| 231 |
print_colorlist(outfd, coloron, colorlist); |
| 232 |
od; |
| 233 |
od; |
| 234 |
fprintf(outfd, " }\n"); |
| 235 |
|
| 236 |
########################### CURVES ########################## |
| 237 |
# EX: spacecurve( [x(t), y(t), z(t)], t=tmin..tmax] |
| 238 |
# Saving Maple CURVES struct to geomview VECT struct |
| 239 |
############################################################### |
| 240 |
elif header = CURVES then |
| 241 |
llist := select(type, item, list); |
| 242 |
if( nops(item)>1 ) then |
| 243 |
colorlist := find_colorlist(2, item); |
| 244 |
coloron := op(1,colorlist); # either RGB, HUE, or FALSE |
| 245 |
fi; |
| 246 |
fprintf(outfd, "{ VECT \n"); # gv type |
| 247 |
# Number of polylines, total vertices. |
| 248 |
totalverts := sum('nops(op(i,llist))', 'i'=1..nops(llist)); |
| 249 |
fprintf(outfd, "%d %d ", nops(llist), totalverts); |
| 250 |
if coloron=FALSE then |
| 251 |
fprintf(outfd, "1\n"); # One color in all |
| 252 |
`oogl/lprn`(outfd,[seq(nops(op(i,llist)), i=1..nops(llist))],"\n"); # Vertex counts |
| 253 |
`oogl/lprn`(outfd,[1, seq(0, i=2..nops(llist))],"\n"); # Color counts. |
| 254 |
else |
| 255 |
fprintf(outfd, "%d\n", nops(llist));# Total number of colors, 1 per polyline |
| 256 |
`oogl/lprn`(outfd,[seq(nops(op(i,llist)), i=1..nops(llist))],"\n"); # Vertex counts |
| 257 |
`oogl/lprn`(outfd,[seq(1, i=1..nops(llist))],"\n"); # Color counts. |
| 258 |
fi; |
| 259 |
for plist in llist do |
| 260 |
for ppoint in plist do # print all vertices |
| 261 |
`oogl/lprn`(outfd,ppoint,"\n"); |
| 262 |
od |
| 263 |
od; |
| 264 |
if coloron=FALSE then |
| 265 |
fprintf(outfd, "1 1 1 1\n"); # color RGBA = white and opaque |
| 266 |
else |
| 267 |
for ccnt from 1 to nops(llist) do |
| 268 |
print_colorlist(outfd, coloron, colorlist); |
| 269 |
od; |
| 270 |
fi; |
| 271 |
fprintf(outfd, " }\n"); |
| 272 |
|
| 273 |
######################### POLYGONS ########################## |
| 274 |
#EX:polygonplot3d([seq([seq([x(s,t),y(s,t),z(s,t)],s=smin..smax],tmin..tmax])): |
| 275 |
# Polygons are handled differently than the other objects w/r/t |
| 276 |
# color. Leave color alone and let user change color using geomview. |
| 277 |
############################################################### |
| 278 |
elif header = POLYGONS then |
| 279 |
# coloron:=FALSE; |
| 280 |
pcolor := i $ i=1..0; # Empty sequence |
| 281 |
totl := 0: nx := 0: # use nx to count number of polygons |
| 282 |
if( nops(item)>1 ) then |
| 283 |
colorlist := find_colorlist(2, item); |
| 284 |
coloron := op(1,colorlist); # either RGB, HUE, or FALSE |
| 285 |
fi; |
| 286 |
for llist in item do # sequence of lists POLY(),COLOR(), |
| 287 |
if type(llist,list) then |
| 288 |
nx := nx + 1; # number of polygons |
| 289 |
totl := totl + nops(llist); # compute total number of vertices |
| 290 |
fi |
| 291 |
od; |
| 292 |
|
| 293 |
fprintf(outfd, "%s\n", find_appearance(1, item)); |
| 294 |
|
| 295 |
fprintf(outfd, "{ OFF \n"); # gv type |
| 296 |
fprintf(outfd, "%d %d %d\n", totl, nx, 0); # total verts,polygons,"edges"(not used!) |
| 297 |
for llist in item do |
| 298 |
if type(llist,list) then |
| 299 |
for ppoint in llist do |
| 300 |
`oogl/lprn`(outfd,ppoint,"\n"); # List of vertices |
| 301 |
od; |
| 302 |
fi; |
| 303 |
od; |
| 304 |
fprintf(outfd, "\n"); |
| 305 |
totl := 0; |
| 306 |
for llist in item do |
| 307 |
if type(llist,list) then |
| 308 |
## There are only two possibilities for POLYGONS ## |
| 309 |
## In both cases, it means entire polygon is same color ## |
| 310 |
tlist:=[nops(llist), i $ i=totl..totl+nops(llist)-1]; |
| 311 |
`oogl/lprn`(outfd,tlist,""); |
| 312 |
print_colorlist(outfd, coloron, colorlist); |
| 313 |
if coloron=FALSE then |
| 314 |
fprintf(outfd, "\n"); |
| 315 |
fi; |
| 316 |
totl := totl + nops(llist); |
| 317 |
fi; |
| 318 |
od; |
| 319 |
fprintf(outfd, "}\n"); |
| 320 |
|
| 321 |
######################### POINTS ########################## |
| 322 |
#EX:PLOT3D(POINTS([0,0,1],[1,0,0],[0,1,0])); |
| 323 |
############################################################### |
| 324 |
elif header = POINTS then |
| 325 |
colorlist := find_colorlist(2, item); |
| 326 |
coloron := op(1,colorlist); # either RGB, HUE, or FALSE |
| 327 |
fprintf(outfd, "%s\n", find_appearance(2,item)); |
| 328 |
if coloron=FALSE then |
| 329 |
npoints := nops(item); |
| 330 |
fprintf(outfd, "{ VECT %d %d %d\n", npoints, npoints, 0); |
| 331 |
else |
| 332 |
npoints := nops(item) - 1; |
| 333 |
fprintf(outfd, "{ VECT %d %d %d\n", npoints, npoints, npoints); |
| 334 |
fi; |
| 335 |
fprintf(outfd, cat(seq("1\n", i=1..npoints))); |
| 336 |
fprintf(outfd, "\n"); |
| 337 |
if coloron=FALSE then |
| 338 |
fprintf(outfd, cat(seq("0\n", i=1..npoints))); |
| 339 |
else |
| 340 |
fprintf(outfd, cat(seq("1\n", i=1..npoints))); |
| 341 |
fi; |
| 342 |
fprintf(outfd, "\n"); |
| 343 |
for i from 1 to npoints do |
| 344 |
ppoint := op(i, item); |
| 345 |
`oogl/lprn`(outfd,ppoint,"\n"); |
| 346 |
od; |
| 347 |
if coloron<>FALSE then |
| 348 |
for i from 1 to npoints do |
| 349 |
print_colorlist(outfd, coloon, colorlist); |
| 350 |
od; |
| 351 |
fi; |
| 352 |
fprintf(outfd, "}\n"); |
| 353 |
|
| 354 |
########################### TEXT ############################ |
| 355 |
# 3D plots using the "plots" package may include TEXT |
| 356 |
# This is not supported |
| 357 |
############################################################### |
| 358 |
elif header = TEXT then |
| 359 |
fprintf(outfd, " "); |
| 360 |
fi; |
| 361 |
od; # END main for loop |
| 362 |
|
| 363 |
fprintf(outfd, "}\n"); |
| 364 |
if haveview <> FALSE then |
| 365 |
if nops(view) = 1 then |
| 366 |
clipcmd:=sprintf("clip -v 0,0,1 -g %e -l %e %s", |
| 367 |
view[1][1], view[1][2], clipfname); |
| 368 |
else |
| 369 |
clipcmd:=sprintf(cat("clip -v 1,0,0 -g %e -l %e %s |", |
| 370 |
"clip -v 0,1,0 -g %e -l %e |", |
| 371 |
"clip -v 0,0,1 -g %e -l %e"), |
| 372 |
view[1][1], view[1][2], clipfname, |
| 373 |
view[2][1], view[2][2], |
| 374 |
view[3][1], view[3][2]); |
| 375 |
fi; |
| 376 |
fclose(outfd); |
| 377 |
outfd:=clipfd; |
| 378 |
fprintf(outfd, op(2,ssystem(clipcmd))); |
| 379 |
fremove(clipfname); |
| 380 |
fi; |
| 381 |
NULL; |
| 382 |
end; |
| 383 |
|
| 384 |
|
| 385 |
gvplot := proc() |
| 386 |
local gvname, gvcmd, gvdirs, ps, tmp_fname, outfd; |
| 387 |
options `Copyright 1993 by Frederick Wicklin and Stuart Levy, Geometry Center`; |
| 388 |
tmp_fname := make_tmpname(); |
| 389 |
|
| 390 |
### Let user specify, via "gvcommand" and "gvdirectories" global vars, |
| 391 |
### which program/args to run when invoking geomview, |
| 392 |
### and how to set the search path to find it and togeomview. |
| 393 |
|
| 394 |
if gvcommand <> 'gvcommand' |
| 395 |
then gvcmd := gvcommand |
| 396 |
else gvcmd := default_gvcommand |
| 397 |
fi; |
| 398 |
if gvdirectories <> 'gvdirectories' |
| 399 |
then gvdirs := gvdirectories |
| 400 |
else gvdirs := default_gvdirectories |
| 401 |
fi; |
| 402 |
|
| 403 |
ps := args[nargs]; |
| 404 |
gvname := `Maple`; |
| 405 |
|
| 406 |
if nargs < 1 or nargs > 2 then |
| 407 |
ERROR(`Usage: gvplot(3dplot_structure) -or- gvplot(``name``, 3dplot_structure)`); |
| 408 |
fi; |
| 409 |
if nargs > 1 then gvname := args[1] fi; |
| 410 |
if not op(0, ps) = PLOT3D then |
| 411 |
ERROR(`Invalid plot structure`,ps, |
| 412 |
`; must be of type PLOT3D, as from plot3d(), tubeplot(), spacecurve(), etc.`) |
| 413 |
fi; |
| 414 |
# start geomview reading from stdin |
| 415 |
if system( `PATH=` || gvdirs || `:$PATH togeomview -cp `||tmp_fname||` `||gvcmd||`</dev/null ` ) <> 0 then |
| 416 |
ERROR(`gvplot: togeomview: Can't start a copy of geomview. `|| |
| 417 |
`If "togeomview" or "geomview" were not found `|| |
| 418 |
`try setting the variable "gvdirectories" to the name of the directory where `|| |
| 419 |
`they're installed (or to a colon-separated list of directories).`); |
| 420 |
fi; |
| 421 |
outfd:=fopen(`/tmp/geomview/`||tmp_fname,WRITE,BINARY); |
| 422 |
try |
| 423 |
fprintf(outfd, "(geometry %s\n", gvname); |
| 424 |
fwriteoogl( outfd, ps ); |
| 425 |
fprintf(outfd, ")\n"); |
| 426 |
finally |
| 427 |
fclose(outfd); |
| 428 |
end try; |
| 429 |
NULL; |
| 430 |
end; |
| 431 |
|
| 432 |
gvsendcmd := proc() |
| 433 |
local gvname, gvcmd, gvdirs, ps, savedprintbytes, tmp_fname; |
| 434 |
options `Copyright 1993 by Frederick Wicklin and Stuart Levy, Geometry Center`; |
| 435 |
|
| 436 |
tmp_fname := make_tmpname(); |
| 437 |
|
| 438 |
### Let user specify, via "gvcommand" and "gvdirectories" global vars, |
| 439 |
### which program/args to run when invoking geomview, |
| 440 |
### and how to set the search path to find it and togeomview. |
| 441 |
|
| 442 |
if gvcommand <> 'gvcommand' |
| 443 |
then gvcmd := gvcommand |
| 444 |
else gvcmd := default_gvcommand |
| 445 |
fi; |
| 446 |
if gvdirectories <> 'gvdirectories' |
| 447 |
then gvdirs := gvdirectories |
| 448 |
else gvdirs := default_gvdirectories |
| 449 |
fi; |
| 450 |
|
| 451 |
# start geomview reading from stdin |
| 452 |
if system( `PATH=` || gvdirs || `:$PATH togeomview -Mcp `||tmp_fname||` `||gvcmd||`</dev/null ` ) <> 0 then |
| 453 |
ERROR(`gvplot: togeomview: Can't start a copy of geomview. `|| |
| 454 |
`If "togeomview" or "geomview" were not found `|| |
| 455 |
`try setting the variable "gvdirectories" to the name of the directory where `|| |
| 456 |
`they're installed (or to a colon-separated list of directories).`); |
| 457 |
fi; |
| 458 |
savedprintbytes:=kernelopts( printbytes): |
| 459 |
kernelopts( printbytes=false): |
| 460 |
writeto(`/tmp/geomview/`||tmp_fname); |
| 461 |
lprint(args); |
| 462 |
writeto(terminal); |
| 463 |
kernelopts( printbytes=savedprintbytes): |
| 464 |
NULL; |
| 465 |
end; |
| 466 |
|
| 467 |
# possible gvplot enhancements: |
| 468 |
# allow remote display? |
| 469 |
# Maybe use a two-step Rube Goldberg hookup with an external converter |
| 470 |
# that directly reads lprint() format. Likely to be faster for large objects. |
| 471 |
# Then gvplot would read |
| 472 |
# gvplot := proc() |
| 473 |
# ... |
| 474 |
# if system(`togeomview -Mcp Maple.raw maple2oogl -togeomview -Mcp Maple`)<>0 |
| 475 |
# then ERROR(...) fi; |
| 476 |
# writeto(`/tmp/geomview/Maple.raw`); |
| 477 |
# lprint(`(geometry`, gvname, `<<`); |
| 478 |
# lprint(3dplot_struct); |
| 479 |
# lprint(`>>)`); |
| 480 |
# writeto(terminal); |
| 481 |
# end; |
| 482 |
# and writeoogl would read |
| 483 |
# writeoogl := proc() |
| 484 |
# ... |
| 485 |
# if system(cat(`togeomview -Mcp Maple.rawdata maple2oogl -o `, fname)) <> 0 |
| 486 |
# then ERROR(...) fi; |
| 487 |
# writeto(`/tmp/geomview/Maple.rawdata`); |
| 488 |
# lprint(`<<', 3dplot_string, `>>'); |
| 489 |
# writeto(terminal); |
| 490 |
# end; |
| 491 |
# |
| 492 |
# Here 'togeomview' is actually being used to start 'maple2oogl' rather |
| 493 |
# than geomview itself. In the first case, maple2oogl -togeomview would |
| 494 |
# invoke code to start a copy of geomview. |
| 495 |
|
| 496 |
`oogl/lprn` := proc(outfd, v, terminator) |
| 497 |
local i, fmt, n; |
| 498 |
options `Copyright 2003 by Claus-Justus Heine`; |
| 499 |
if type(v, list) then |
| 500 |
fmt:=""; |
| 501 |
for i from 1 to nops(v) do |
| 502 |
if type(v[i],integer) then |
| 503 |
fmt:=cat(fmt, "%d "); |
| 504 |
elif type(v[i],realcons) then |
| 505 |
fmt:=cat(fmt, "%e "); |
| 506 |
fi; |
| 507 |
od; |
| 508 |
fprintf(outfd, cat(fmt, terminator), seq(v[i], i = 1..nops(v)) ); |
| 509 |
elif type(v, hfarray) then |
| 510 |
n := op(2, ArrayDims(v)); |
| 511 |
fmt:=cat(seq("%e ", i = 1 .. n)); |
| 512 |
fprintf(outfd, cat(fmt, terminator), seq(v[i], i = 1..n) ); |
| 513 |
elif type(v, realcons) then |
| 514 |
fprintf(outfd, cat("%e", terminator), v); |
| 515 |
else |
| 516 |
fprintf(outfd, "0 #\n"); |
| 517 |
fi |
| 518 |
end; |
| 519 |
|
| 520 |
############################################################### |
| 521 |
## HSV2RGB converts Maple Hues to RGB colors. |
| 522 |
## The HUEs used are in [0,1] so assume that S=V=1 (this is close) |
| 523 |
## The following algorithm is from Computer Graphics |
| 524 |
## By Foley, vanDam, Feiner, Hughes, 2nd Ed. Addison-Wesley |
| 525 |
## p 593 |
| 526 |
## |
| 527 |
## Adapted by fjw 11/29/93 |
| 528 |
## Input: (h,s,v) in [0,1]^3 |
| 529 |
## Output: sequence r,b,g each in [0,1] |
| 530 |
############################################################### |
| 531 |
HSV2RGB := proc( h,s,v ) |
| 532 |
local hh,ip,fp,p,q,t; |
| 533 |
options `Copyright 1990 by Foley, vanDam, Feiner, Hughes`; |
| 534 |
if (s = 0) then # color on B/W center line |
| 535 |
if (h<0) then # There is no hue,ie, hue undefined |
| 536 |
return( v,v,v ); |
| 537 |
else |
| 538 |
ERROR(`Undefined color`); |
| 539 |
fi; |
| 540 |
else |
| 541 |
if (h>1) then hh:=1 fi; |
| 542 |
hh := 6*h; # hh now in [0,6] |
| 543 |
ip := floor(hh); # ip is integer part of h |
| 544 |
fp := hh - ip; # fp is fractional part of h |
| 545 |
p := v*(1-s); |
| 546 |
q := v*(1-(s*fp)); |
| 547 |
t := v*(1-(s*(1-fp))); |
| 548 |
if (ip=0) then |
| 549 |
return( v,t,p ); |
| 550 |
elif (ip=1) then |
| 551 |
return( q,v,p ); |
| 552 |
elif (ip=2) then |
| 553 |
return( p,v,t ); |
| 554 |
elif (ip=3) then |
| 555 |
return( p,q,v ); |
| 556 |
elif (ip=4) then |
| 557 |
return( t,p,v ); |
| 558 |
else |
| 559 |
return( v,p,q ); |
| 560 |
fi; |
| 561 |
fi; |
| 562 |
end; |
| 563 |
|
| 564 |
|
| 565 |
######################################################## |
| 566 |
# find_colorlist |
| 567 |
# input: n where to start looking for color data |
| 568 |
# item what list to search |
| 569 |
# output: list of color information or NULL list |
| 570 |
######################################################## |
| 571 |
find_colorlist := proc(n,item) |
| 572 |
local i; |
| 573 |
options `Copyright 1993 by Frederick Wicklin, Geometry Center`; |
| 574 |
for i from n to nops(item) do |
| 575 |
if type(op(i,item),function) and (op(0,op(i,item))=COLOR or op(0,op(i,item))=COLOUR) then |
| 576 |
return(op(i,item)) |
| 577 |
fi; |
| 578 |
od; |
| 579 |
return([FALSE]); # no color info found |
| 580 |
end; |
| 581 |
|
| 582 |
######################################################## |
| 583 |
# find_view |
| 584 |
# input: n where to start looking for clipping data |
| 585 |
# item what list to search |
| 586 |
# output: clipping information in the form [[xmin,xmax],[...]] |
| 587 |
######################################################## |
| 588 |
find_view := proc(n, item) |
| 589 |
option `Copyright (C) 2003 by Claus-Justus Heine, Department for Applied Mathematics, Freiburg University. All rights reserved.`; |
| 590 |
description `Find the viewport definition`; |
| 591 |
local i, j, clipping, view; |
| 592 |
|
| 593 |
for i from n to nops(item) do |
| 594 |
if type(op(i,item),function) and (op(0,op(i,item))=VIEW) then |
| 595 |
view:=op(i,item); |
| 596 |
clipping:=[seq([op(1,op(j,view)),op(2,op(j,view))],j = 1..nops(view))]; |
| 597 |
return clipping; |
| 598 |
fi; |
| 599 |
od; |
| 600 |
return([FALSE]); # no view info found |
| 601 |
end; # find_view find_view := proc(n,item) |
| 602 |
|
| 603 |
######################################################## |
| 604 |
# find_appearance |
| 605 |
# input: n index to start seeking color data |
| 606 |
# list list to search |
| 607 |
# output: argument of STYLE option (e.g. `PATCH`) or [] list. |
| 608 |
######################################################## |
| 609 |
find_appearance := proc(n, list) |
| 610 |
local i, part, ap, color, colortype; |
| 611 |
ap := ``; color := ``; |
| 612 |
for i from n to nops(list) do |
| 613 |
part := op(i,list); |
| 614 |
if type(part,function) and (op(0,part)=COLOR or op(0,part)=COLOUR) then |
| 615 |
colortype := op(1,part); |
| 616 |
if colortype = HUE then |
| 617 |
color := [HSV2RGB(op(2,part), 0.9, 1)] |
| 618 |
elif colortype = RGB then |
| 619 |
color := [op(2..4,part)] |
| 620 |
elif colortype = HSV then |
| 621 |
color := [HSV2RGB(op(2,colorlist), op(3,colorlist), op(4,colorlist))]; |
| 622 |
fi |
| 623 |
# Otherwise, this "color" tag isn't for us |
| 624 |
elif type(part,function) and op(0,part) = STYLE then |
| 625 |
if op(1,part) = PATCH then |
| 626 |
ap := cat(ap, ` +face -edge`) |
| 627 |
elif op(1,part) = LINE or op(1,part) = WIREFRAME then |
| 628 |
ap := cat(ap, ` -face +edge`) |
| 629 |
fi |
| 630 |
elif type(part,function) and op(0,part) = THICKNESS and type(op(1,part),integer) then |
| 631 |
ap := cat(ap, ` linewidth `, op(1,part)); |
| 632 |
elif type(part,function) and op(0,part) = SYMBOL then |
| 633 |
ap := cat(ap, ` linewidth `, op(2,part)); |
| 634 |
fi |
| 635 |
od; |
| 636 |
if color <> `` then |
| 637 |
color := cat( op(1..3, map(v -> cat(convert(v,string),` `), color) ) ); |
| 638 |
# ap := cat(ap, `\n material { edgecolor `, color, `\n diffuse `, color, `}\n`); |
| 639 |
|
| 640 |
# leave everything except the edge color to the handlers |
| 641 |
# for the specific plot-types. Otherwise there are |
| 642 |
# problems with Geomview and transparency |
| 643 |
# |
| 644 |
ap := cat(ap, `\n material { edgecolor `, color, `}\n`); |
| 645 |
fi; |
| 646 |
if ap <> `` then |
| 647 |
# |
| 648 |
# "transparent" is here because it cannot be changed |
| 649 |
# inside Geomview otherwise |
| 650 |
# |
| 651 |
ap := cat(` appearance { `, ap, `}`) |
| 652 |
fi; |
| 653 |
return(ap); |
| 654 |
end; |
| 655 |
|
| 656 |
|
| 657 |
######################################################## |
| 658 |
# |
| 659 |
# COLOR |
| 660 |
# Color may be specified in three different ways. RGB color |
| 661 |
# specification requires three floating-point values for each |
| 662 |
# color. The three values must each be between 0 and 1 and specify the |
| 663 |
# amount of red, green, and blue light in the final color. For |
| 664 |
# example, COLOR(RGB, 1.0, 0.0, 0.0) is red while COLOR(RGB, 1.0, 1.0, |
| 665 |
# 0.0) is yellow. The HSV color specification also requires three |
| 666 |
# numbers for each color. The fractional portion of the first value |
| 667 |
# indicates the color and the remaining two values give the purity |
| 668 |
# (saturation) and the brightness of the color. The latter two values |
| 669 |
# must be between zero and one. The HUE color specification only |
| 670 |
# requires a single floating-point value and cycles through the colors |
| 671 |
# of the spectrum based on the fractional part of the value. For |
| 672 |
# example COLOR(HUE, 0.9) is violet while COLOR(HUE, 0.1) is |
| 673 |
# red. COLOR(HUE, x) is equivalent to COLOR(HSV, x, 0.9, 1.0). |
| 674 |
# |
| 675 |
# Color can take several extra keyword options for 3-D |
| 676 |
# plotting. XYZSHADING, XYSHADING and ZSHADING specify that an objects |
| 677 |
# color is to be based on its coordinates. ZHUE and ZGREYSCALE are |
| 678 |
# modified forms of ZSHADING. |
| 679 |
# |
| 680 |
######################################################## |
| 681 |
print_colorlist := proc(outfd, coloron, colorlist) |
| 682 |
option `Copyright (C) 2003 by Claus-Justus Heine, Department for Applied Mathematics, Freiburg University. All rights reserved.`; |
| 683 |
description `Print colorlist in OOGL RGB format.`; |
| 684 |
if coloron = RGB then |
| 685 |
fprintf(outfd, "%e %e %e %e\n", |
| 686 |
op(2,colorlist),op(3,colorlist),op(4,colorlist), 1); |
| 687 |
elif coloron = HUE then |
| 688 |
fprintf(outfd, "%s %d\n", HSV2RGB(op(2,colorlist), 0.9, 1.0), 1); |
| 689 |
elif coloron = HSV then |
| 690 |
fprintf(outfd, "%s %d\n", |
| 691 |
HSV2RGB(op(2,colorlist), op(3,colorlist), op(4,colorlist)), |
| 692 |
1); |
| 693 |
elif coloron != FALSE then |
| 694 |
fprintf(outfd, "0.666 0.666 0.666 1\n"); |
| 695 |
fi; |
| 696 |
end; # print_colorlist print_colorlist := proc(outfd, coloron, colorlist) |
| 697 |
|
| 698 |
end module: # geomviewgeomview:=module() |