Thread View: adobe.postscript.programming
4 messages
4 total messages
Started by Nico_Schl�mer
Sat, 31 Jan 2009 16:03
postscript & sparse matrices: howto?
Author: Nico_Schl�mer
Date: Sat, 31 Jan 2009 16:03
Date: Sat, 31 Jan 2009 16:03
17 lines
1570 bytes
1570 bytes
hi! i'm dealing with matrices here and want to plot its value into postscript. in fact, i just need a black spot where a matrix entry is not zero, white everywhere else. easy, isn't it? particulary, my matrices have very few non-zero entries, so the ps file would only have a few black spots here and there. now, what's the best way to write this in postscript? the first thing i tried was the image environment: works well as soon as you got used to the syntax, but the big disadvantage for me was that i have to explicitly code all the white pixels, so the eps file gets a lot bigger than needed (it feels). the second thing i tried was defining a small "draw tiny box" command, then "move to" the non-zero spots, and evoke the function. that's better then the image way (the files are a lot smaller), but it still feels like a hack somehow. do you have any hints or suggestions for the issue? are there any commands or environment that would be better suited? all hints appreciated! cheers, nico
Re: postscript & sparse matrices: howto?
Author: Jeffrey H. Coffield
Date: Sat, 31 Jan 2009 19:24
Date: Sat, 31 Jan 2009 19:24
52 lines
2973 bytes
2973 bytes
Nico_Schl�mer@adobeforums.com wrote:
> hi!
>
> i'm dealing with matrices here and want to plot its value into postscript. in fact, i just need a black spot where a matrix entry is not zero, white everywhere else. easy, isn't it?
>
> particulary, my matrices have very few non-zero entries, so the ps file would only have a few black spots here and there.
>
> now, what's the best way to write this in postscript? the first thing i tried was the image environment: works well as soon as you got used to the syntax, but the big disadvantage for me was that i have to explicitly code all the white pixels, so the eps file gets a lot bigger than needed (it feels).
>
> the second thing i tried was defining a small "draw tiny box" command, then "move to" the non-zero spots, and evoke the function.
> that's better then the image way (the files are a lot smaller), but it still feels like a hack somehow.
>
> do you have any hints or suggestions for the issue? are there any commands or environment that would be better suited?
>
> all hints appreciated!
>
> cheers,
> nico
Would something like this work for you?
%! Adobe-PS
/inch {72 mul} def
<</PageSize [8.5 inch 11 inch]>> setpagedevice
/MaxValue 10 def % The max x or y value plotted
/GraphSize 8 inch def % The width of the graph
/Scale GraphSize MaxValue div def
.25 inch .5 inch translate
gsave .5 setgray 0 0 GraphSize GraphSize rectstroke grestore
Scale Scale scale
/Box {gsave translate 0 0 1 1 rectfill grestore} def
0 0 Box
1 1 Box
2 2 Box
3 3 Box
4 4 Box
5 5 Box
6 6 Box
7 7 Box
9 9 Box
showpage
Jeff Coffield
www.digitalsynergyinc.com
Re: postscript & sparse matrices: howto?
Author: Peter Davis
Date: Tue, 03 Feb 2009 11:38
Date: Tue, 03 Feb 2009 11:38
52 lines
3139 bytes
3139 bytes
On Jan 31, 11:03 am, Nico_Schlöm...@adobeforums.com wrote:
> hi!
>
> i'm dealing with matrices here and want to plot its value into postscript. in fact, i just need a black spot where a matrix entry is not zero, white everywhere else. easy, isn't it?
>
> particulary, my matrices have very few non-zero entries, so the ps file would only have a few black spots here and there.
>
> now, what's the best way to write this in postscript? the first thing i tried was the image environment: works well as soon as you got used to the syntax, but the big disadvantage for me was that i have to explicitly code all the white pixels, so the eps file gets a lot bigger than needed (it feels).
>
> the second thing i tried was defining a small "draw tiny box" command, then "move to" the non-zero spots, and evoke the function.
> that's better then the image way (the files are a lot smaller), but it still feels like a hack somehow.
>
> do you have any hints or suggestions for the issue? are there any commands or environment that would be better suited?
>
> all hints appreciated!
>
> cheers,
> nico
PostScript is, in some ways, a perfect language for sparse matrices.
You can simply use a dictionary. A dictionary key could be anything,
including a number. So you could store your matrix elements with
something like:
/mysparsemtx 100 dict def
/key x 1024 mul y add def
mysparsemtx key 1 put
Now wherever you have a "1" stored, you can treat that as a black
spot. You can traverse the whole matrix with
mysparsemtx {
pop % You can throw away the "1" since every entry has a "1" stored
dup 1024 mod /y exch def 1024 div /x exch def % unpack the original
x and y
% do whatever you want with x and y
} forall
NOTE: I haven't tested this code, but this is the gist of the
approach.
-pd
Re: postscript & sparse matrices: howto?
Author: Niho_Goran
Date: Mon, 09 Feb 2009 07:47
Date: Mon, 09 Feb 2009 07:47
1 lines
682 bytes
682 bytes
I am having exactly the same problem, the raster EPS gets extremely large! Any ideas anyone?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads