Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!purdue!haven!decuac!shlump.nac.dec.com!hannah.enet.dec.com!batcheldern From: batcheldern@hannah.enet.dec.com Newsgroups: comp.lang.postscript Subject: Re: Drawing lots of triangles Message-ID: <7561@shlump.nac.dec.com> Date: 18 Jan 90 14:42:35 GMT References: <9561@batcomputer.tn.cornell.edu> Sender: newsdaemon@shlump.nac.dec.com Reply-To: BatchelderN@hannah.enet.dec.com Distribution: na Organization: Digital Equipment Corporation Lines: 144 > I was glad to see all of the helpful suggestions about how to draw boxes fast, > but I have a different problem that seems to me much harder to optimize under > PS. I have a picture that consists almost entirely of 180,000 filled triangles. > (This is the output from a 3D rendering program.) Here is a sample of one > of the files: > > %! > %%BoundingBox: 0 0 612 792 > %%EndComments > initgraphics > 8.5 72 mul 0 translate 90 rotate 72 1000 div dup scale > 2.0 setmiterlimit 60 45 {add .5 mul} setscreen > /NP {newpath} def /SD {setdash} def /SG {99 div setgray} def /MT {moveto} def > /LT {lineto} def /CP {closepath} def /GS {gsave} def /FL {fill} def > /GR {grestore} def /SK {stroke} def /LW {setlinewidth} def > erasepage > [... other graphics stuff deleted, triangles follow] > NP 8761 6576 MT > 8781 6584 LT > 8782 6574 LT > 8761 6576 LT > CP GS 99 SG FL GR > ... about 180,000 times > > Is there anything obviously inefficient about the way this is being printed? I > see from the 'boxes' discussion that I could redefine the NP, MT, LT, etc. to > be one letter, but that is a small savings. Any other suggestions? Yes, define your shortened commands as single letters, but more importantly, change the form of the definitions. Your definition involve executing a procedure, and looking up the name in the procedure, and then executing the operator. Better to use definitions of the form: /l /lineto load def so that l is defined to be the operator, rather than a procedure which contains a name which has the operator as a value. Also, you only need two lineto's to makea triangle, since the closepath will add the last line segment for you. Also, rather than do a gsave/grestore and then a newpath, simply fill the triangle. This would require getting the source to the package, but you're going to have to do that to get any real savings anyway. Better yet, do your own PostScript conversion, and have all the flexibility you want. I don't know what range of triangle shapes you have, but if there are less than 257 of them, then you can create a font with all of your different shapes, and use show to put them on the page. This will compact your file tremendously, and will put the power of the font cache to work for you. As an aside, for those of us out here who are curious, could you give us a short description of what this thing you're drawing is? (I'd like to know about the boxes one too!) > ++Eric Fielding > eric@geology.tn.cornell.edu > eric@crnlthry.bitnet > Ned Batchelder, Digital Equipment Corp., BatchelderN@Hannah.enet.DEC.com In article <9561@batcomputer.tn.cornell.edu>, eric@batcomputer.tn.cornell.edu (Eric Fielding) writes: > I was glad to see all of the helpful suggestions about how to draw boxes fast, > but I have a different problem that seems to me much harder to optimize under > PS. I have a picture that consists almost entirely of 180,000 filled triangles. > (This is the output from a 3D rendering program.) Here is a sample of one > of the files: > > %! > %%BoundingBox: 0 0 612 792 > %%EndComments > initgraphics > 8.5 72 mul 0 translate 90 rotate 72 1000 div dup scale > 2.0 setmiterlimit 60 45 {add .5 mul} setscreen > /NP {newpath} def /SD {setdash} def /SG {99 div setgray} def /MT {moveto} def > /LT {lineto} def /CP {closepath} def /GS {gsave} def /FL {fill} def > /GR {grestore} def /SK {stroke} def /LW {setlinewidth} def > /PLP {1024 1 true [1024 0 0 1 0 0] {<8080808080808080>} imagemask} def > /WLP {1024 1 true [1024 0 0 1 0 0] {<8888888888888888>} imagemask} def > erasepage > [... other graphics stuff deleted, triangles follow] > NP 8761 6576 MT > 8781 6584 LT > 8782 6574 LT > 8761 6576 LT > CP GS 99 SG FL GR > NP 8761 6576 MT > 8760 6587 LT > 8781 6584 LT > 8761 6576 LT > CP GS 99 SG FL GR > NP 8740 6581 MT > 8760 6587 LT > 8761 6576 LT > 8740 6581 LT > CP GS 99 SG FL GR > ... about 180,000 times > > Is there anything obviously inefficient about the way this is being printed? I > see from the 'boxes' discussion that I could redefine the NP, MT, LT, etc. to > be one letter, but that is a small savings. Any other suggestions? (I don't > have the source the graphics package, but I could get it, or use post-processing > under either Ultrix or VMS.) > Yes, define your shortened commands as single letters, but more importantly, change the form of the definitions. Your definition involve executing a procedure, and looking up the name in the procedure, and then executing the operator. Better to use definitions of the form: /l /lineto load def so that l is defined to be the operator, rather than a procedure which contains a name which has the operator as a value. Also, you only need two lineto's to makea triangle, since the closepath will add the last line segment for you. Also, rather than do a gsave/grestore and then a newpath, simply fill the triangle. This would require getting the source to the package, but you're going to have to do that to get any real savings anyway. Better yet, do your own PostScript conversion, and have all the flexibility you want. I don't know what range of triangle shapes you have, but if there are less than 257 of them, then you can create a font with all of your different shapes, and use show to put them on the page. This will compact your file tremendously, and will put the power of the font cache to work for you. As an aside, for those of us out here who are curious, could you give us a short description of what this thing you're drawing is? (I'd like to know about the boxes one too!) Ned Batchelder, Digital Equipment Corp., BatchelderN@Hannah.enet.DEC.com