Chaco plot hittest()

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Chaco plot hittest()

Jonathan Hogg
Hi there,

Can anyone explain why BaseXYPlot and LinePlot have differing, incompatible implementations of the hittest() method? The former takes a 'return_distance' optional argument and returns screen co-ordinates, the latter doesn't have that argument and returns data co-ordinates.

This means that other plots based on BaseXYPlot that don't override hittest - such as ScatterPlot - operate in a different way to LinePlot. It would seem to defeat the utility of object-orientation if I have to put a bunch of 'if isinstance' calls into my code.

(As an aside, the LinePlot implementation seems to be substantially more hacky than the BaseXYPlot one, although returning data co-ordinates does seem more useful to me.)

Cheers,

Jonathan

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

bryce hendrix-2
On Mon, Jan 31, 2011 at 6:11 AM, Jonathan Hogg <[hidden email]> wrote:
Hi there,

Can anyone explain why BaseXYPlot and LinePlot have differing, incompatible implementations of the hittest() method? The former takes a 'return_distance' optional argument and returns screen co-ordinates, the latter doesn't have that argument and returns data co-ordinates.

This means that other plots based on BaseXYPlot that don't override hittest - such as ScatterPlot - operate in a different way to LinePlot. It would seem to defeat the utility of object-orientation if I have to put a bunch of 'if isinstance' calls into my code.

(As an aside, the LinePlot implementation seems to be substantially more hacky than the BaseXYPlot one, although returning data co-ordinates does seem more useful to me.)


Jonathan,

I don't know the exact history of the two variations (maybe Peter will chime in?), but looking at LinePlot's method, i don't particularly like that it doesn't hittest the actual line either. If there isn't too much dependent code, we might be able to change the LinePlot's implementation.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Peter Wang
On Mon, Jan 31, 2011 at 10:37 AM, bryce hendrix <[hidden email]> wrote:
> Jonathan,
> I don't know the exact history of the two variations (maybe Peter will chime
> in?), but looking at LinePlot's method, i don't particularly like that it
> doesn't hittest the actual line either.

This would be a nice feature, but be warned that this may actually be
difficult to do quickly and accurately.

> If there isn't too much dependent
> code, we might be able to change the LinePlot's implementation.

I'm all for making these two more consistent.

-Peter
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

bryce hendrix-2
On Mon, Jan 31, 2011 at 10:17 AM, Peter Wang <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:37 AM, bryce hendrix <[hidden email]> wrote:
> Jonathan,
> I don't know the exact history of the two variations (maybe Peter will chime
> in?), but looking at LinePlot's method, i don't particularly like that it
> doesn't hittest the actual line either.

This would be a nice feature, but be warned that this may actually be
difficult to do quickly and accurately.


I'm thinking about going segment-by-segment, creating 2 parallel lines above and below the segment, then solving the set of linear equations determined by the bounding box. Does that make sense? Can anyone suggest a better solution?

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Chris Colbert
you can solve the distance between the point and line with a dot product (i'd have to look up again how to represent the line) then just check if the distance below a threshold. 

Assuming I understand the problem correctly...

On Mon, Jan 31, 2011 at 2:32 PM, bryce hendrix <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:17 AM, Peter Wang <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:37 AM, bryce hendrix <[hidden email]> wrote:
> Jonathan,
> I don't know the exact history of the two variations (maybe Peter will chime
> in?), but looking at LinePlot's method, i don't particularly like that it
> doesn't hittest the actual line either.

This would be a nice feature, but be warned that this may actually be
difficult to do quickly and accurately.


I'm thinking about going segment-by-segment, creating 2 parallel lines above and below the segment, then solving the set of linear equations determined by the bounding box. Does that make sense? Can anyone suggest a better solution?

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Chris Colbert
and assuming that I do understand the problem right. You could chuck each line segment as row in an nx3 array, do one dot product, then find the min. 

On Mon, Jan 31, 2011 at 3:22 PM, Chris Colbert <[hidden email]> wrote:
you can solve the distance between the point and line with a dot product (i'd have to look up again how to represent the line) then just check if the distance below a threshold. 

Assuming I understand the problem correctly...

On Mon, Jan 31, 2011 at 2:32 PM, bryce hendrix <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:17 AM, Peter Wang <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:37 AM, bryce hendrix <[hidden email]> wrote:
> Jonathan,
> I don't know the exact history of the two variations (maybe Peter will chime
> in?), but looking at LinePlot's method, i don't particularly like that it
> doesn't hittest the actual line either.

This would be a nice feature, but be warned that this may actually be
difficult to do quickly and accurately.


I'm thinking about going segment-by-segment, creating 2 parallel lines above and below the segment, then solving the set of linear equations determined by the bounding box. Does that make sense? Can anyone suggest a better solution?

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Chris Colbert
actually i'm wrong, because that assumes the lines are infinite. I will need to think about this one more. 

On Mon, Jan 31, 2011 at 3:23 PM, Chris Colbert <[hidden email]> wrote:
and assuming that I do understand the problem right. You could chuck each line segment as row in an nx3 array, do one dot product, then find the min. 


On Mon, Jan 31, 2011 at 3:22 PM, Chris Colbert <[hidden email]> wrote:
you can solve the distance between the point and line with a dot product (i'd have to look up again how to represent the line) then just check if the distance below a threshold. 

Assuming I understand the problem correctly...

On Mon, Jan 31, 2011 at 2:32 PM, bryce hendrix <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:17 AM, Peter Wang <[hidden email]> wrote:
On Mon, Jan 31, 2011 at 10:37 AM, bryce hendrix <[hidden email]> wrote:
> Jonathan,
> I don't know the exact history of the two variations (maybe Peter will chime
> in?), but looking at LinePlot's method, i don't particularly like that it
> doesn't hittest the actual line either.

This would be a nice feature, but be warned that this may actually be
difficult to do quickly and accurately.


I'm thinking about going segment-by-segment, creating 2 parallel lines above and below the segment, then solving the set of linear equations determined by the bounding box. Does that make sense? Can anyone suggest a better solution?

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev





_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

bryce hendrix-2
On Mon, Jan 31, 2011 at 12:24 PM, Chris Colbert <[hidden email]> wrote:
actually i'm wrong, because that assumes the lines are infinite. I will need to think about this one more. 



Yup, which is why I thought solving it as a set of 4 constraints might be the best solution (that I could come up).


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Corran Webster
In reply to this post by Chris Colbert
On Mon, Jan 31, 2011 at 2:24 PM, Chris Colbert <[hidden email]> wrote:
actually i'm wrong, because that assumes the lines are infinite. I will need to think about this one more. 

Should be able to do searchsorted on the x-values, then use your suggestion just on that one segment.  Not perfect, but close enough, and has a reasonable chance of being fast enough, particularly if you cache the array of normal vectors to the line segments.

-- Corran

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Robert Kern
On Mon, Jan 31, 2011 at 2:36 PM, Corran Webster <[hidden email]> wrote:
> On Mon, Jan 31, 2011 at 2:24 PM, Chris Colbert <[hidden email]> wrote:
>>
>> actually i'm wrong, because that assumes the lines are infinite. I will
>> need to think about this one more.
>
> Should be able to do searchsorted on the x-values, then use your suggestion
> just on that one segment.  Not perfect, but close enough, and has a
> reasonable chance of being fast enough, particularly if you cache the array
> of normal vectors to the line segments.

The index values are not always sorted. The paths can be arbitrarily
loopy and/or vertical. I would test the vertices first (it's
relatively cheap, and it's common for a user to fixate on a vertex
rather than a line). Then I would narrow down the possible segments by
checking containment within their bounding boxes (expanded on each
side by the hit test resolution). Then you can do the appropriate
cross product on that subset of segments to test if it is within the
given resolution. If the test point is within a segment's bounding box
and is close enough to the infinite line described by the endpoints of
the line segment, then it is also close enough to just the line
segment.

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco plot hittest()

Jonathan Hogg
In reply to this post by bryce hendrix-2
On 31 Jan 2011, at 16:37, bryce hendrix wrote:

> I don't know the exact history of the two variations (maybe Peter will chime in?), but looking at LinePlot's method, i don't particularly like that it doesn't hittest the actual line either. If there isn't too much dependent code, we might be able to change the LinePlot's implementation.

Great. I've switched to using 'map_index()' for the moment instead, since it is common and can be massaged into doing what I need. The loss of a simple distance value is a pain though.

Jonathan

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev