comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: CURSOR skips a few beats :-(
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: CURSOR skips a few beats :-( [message #69621 is a reply to message #69620] Fri, 29 January 2010 09:58 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Gianguido Cianci wrote:
> On Jan 27, 4:29 pm, David Fanning <n...@dfanning.com> wrote:
>> Well, you can do shapes easily enough just by connecting
>> the dots. For example, in AnnotateWindow you can choose
>> a pencil cursor and draw whatever shape you like (if you
>> have any drawing talent, of course). You just can't get
>> ALL the points the cursor crosses over. I don't think
>> object graphics will help in this case, either. You will
>> have learned them for nothing. :-)
>>
>
> Right, you can join the dots... so when IDL plots the line between the
> dots, it calculates which pixels need to turn white. How do I get the
> coords of all those pixels?

Maybe you can reverse engineer Brensenham's algorithm?

See: http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

cheers,

paulv

p.s. BTW, David Fanning is correct - you should make this a widget program.

>
> I have come up with a three-step linear interpolation that I do
> between each pair of points and it seems to be working (with 2 probs).
> here is a snippet:
>
> pro dlines
>
> f_xsize = 300
> f_ysize = 300
>
> map = bytarr(f_xsize, f_ysize,2)*0b
>
> FOR line = 0, 1 DO BEGIN
> cursor, d1, d2, /down, /device
> device, cursor_standard = 32
> !mouse.button=0
> x1 = 0 > d1 < f_xsize-1
> y1 = 0 > d2 < f_ysize-1
> WHILE (!MOUSE.button NE 4) DO BEGIN
> plots, x1, y1, /device, ps = 3, color = fsc_color((['green',
> 'red'])[line])
> map[x1,y1, line] = 1b
> oldx = x1
> oldy = y1
> CURSOR, X1, Y1, /device,1
> x1 = 0 > x1 < f_xsize-1
> y1 = 0 > y1 < f_ysize-1
>
> dx = abs(x1-oldx)
> dy = abs(y1-oldy)
> l = sqrt((dx)^2+(dy)^2)
> IF ~keyword_set(nointerpolation) AND l GT sqrt(2) THEN BEGIN
> IF dx EQ 0 THEN BEGIN ; if I need to interpolate
> a vertical segment
> xx = indgen(dy)+min([y1, oldy]) ;new x's
> yy = round(interpol([x1, oldx], [y1, oldy], xx))
> map[yy,xx, replicate(line, n_elements(xx)) ] = 1b
> ENDIF ELSE BEGIN ; all other orientations
> xx = indgen(dx)+min([x1, oldx]) ;new x's
> yy = round(interpol([y1, oldy], [x1, oldx], xx))
> map[xx,yy, replicate(line, n_elements(xx)) ] = 1b
>
> ;;need to do this for certain diagonals
> IF dy NE 0 THEN BEGIN xx = indgen(dy)+min([y1,
> oldy]) ;new x's
> yy = round(interpol([x1, oldx], [y1, oldy], xx))
> map[yy,xx, replicate(line, n_elements(xx)) ] = 1b
> ENDIF
> ENDELSE
> ENDIF
> ENDWHILE
> w = where(map[*,*,line] EQ 1b)
> a = array_indices(map[*,*,line], w)
> device, /cursor_crosshair
> ENDFOR
>
> END
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> Problem #1: it is not very pretty, but I could live with that I
> suppose. Though I feel there must be a better way.
>
> Problem #2: when you (slowly!) move the mouse out of the left edge of
> the window the program crashes because x1= 0>x1<f_xsize-1 sets x1 to
> -1!!! And I can't figure that one out :-(
>
>
>> P.S. Even using the pencil tool in something like Photoshop
>> you see that if you move your pencil fast you get a straight
>> line, while if you move it slowly you can get a nice even
>> bend in the line. I think this is a function of your
>> medium (a computer) and not a function of your art skills.
>>
>
> Hmm... I am not sure where you're going with the above. I hope the
> first part of this reply and the code clarify my issues...
>
>
> Thanks,
> Gianguido
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Mode and variation of cells in multiple grids (3-D problem)
Next Topic: read an mp3?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 17:58:29 PDT 2025

Total time taken to generate the page: 1.03861 seconds