Fast line drawing

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

Fast line drawing

Denis Lepchev
Good morning,
I have the following question:

We have an application where we need to draw many vector lines (x1,y1 -> x2,y2) (possibly thousands) in one plot. Currently we use something like this:

# draws  a line from (x1,y1) to (x2,y2)
def drawline(self,str_x,str_y,x1,y1,x2,y2,color1):
        self._plot_data.set_data(str_x,[x1,x2])
        self._plot_data.set_data(str_y,[y1,y2])
        self._plot.plot((str_x,str_y),type="line",color=color1)
 

which I believe is not the best since it creates like thousands different plots, and at some moment it becomes very slow. Is there some faster way to draw the primitive lines? We don't need any manipulation on these lines after they are drawn so it can be some "draw and forget" solution, so the solution that we use now is kind of overkill. I believe we need to use Kiva, but couldn't find any examples on this.

Thanks in advance,
Denis


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

Re: Fast line drawing

Peter Wang
On Sat, Dec 25, 2010 at 4:25 AM, Denis Lepchev <[hidden email]> wrote:
> Good morning,
> I have the following question:
>
> We have an application where we need to draw many vector lines (x1,y1 ->
> x2,y2) (possibly thousands) in one plot. Currently we use something like
> this:

You should look at the QuiverPlot class:
https://svn.enthought.com/enthought/browser/Chaco/trunk/enthought/chaco/quiverplot.py

And its corresponding example:
https://svn.enthought.com/enthought/browser/Chaco/trunk/examples/quiver.py

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

Re: Fast line drawing

Denis Lepchev
Thanks

On Sat, Dec 25, 2010 at 12:22 PM, Peter Wang <[hidden email]> wrote:
On Sat, Dec 25, 2010 at 4:25 AM, Denis Lepchev <[hidden email]> wrote:
> Good morning,
> I have the following question:
>
> We have an application where we need to draw many vector lines (x1,y1 ->
> x2,y2) (possibly thousands) in one plot. Currently we use something like
> this:

You should look at the QuiverPlot class:
https://svn.enthought.com/enthought/browser/Chaco/trunk/enthought/chaco/quiverplot.py

And its corresponding example:
https://svn.enthought.com/enthought/browser/Chaco/trunk/examples/quiver.py

-Peter
_______________________________________________
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: Fast line drawing

Denis Lepchev
Hi Peter,

I tried to use  QuiverPlot as You suggested, and have a few questions:

1) as I understand each vector consists of 2 coordinate points x,y and lengths in respective directions dx, dy. But after plotting few sample vectors, it can be noticed that length on screen actually is not equal to dx, dy. It will be equal, only if I translate dx, dy from data space into the screen space. Is it intended or it is a bug?

2) after changing the zoom or resizing I am able to keep coordinate points x,y updated via respective index_mapper and value_mapper of the quiverplot, but lengths dx, dy are not updated. How can it be done?

Thanks, Denis

On Sat, Dec 25, 2010 at 2:36 PM, Denis Lepchev <[hidden email]> wrote:
Thanks


On Sat, Dec 25, 2010 at 12:22 PM, Peter Wang <[hidden email]> wrote:
On Sat, Dec 25, 2010 at 4:25 AM, Denis Lepchev <[hidden email]> wrote:
> Good morning,
> I have the following question:
>
> We have an application where we need to draw many vector lines (x1,y1 ->
> x2,y2) (possibly thousands) in one plot. Currently we use something like
> this:

You should look at the QuiverPlot class:
https://svn.enthought.com/enthought/browser/Chaco/trunk/enthought/chaco/quiverplot.py

And its corresponding example:
https://svn.enthought.com/enthought/browser/Chaco/trunk/examples/quiver.py

-Peter
_______________________________________________
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: Fast line drawing

Peter Wang
On Sun, Dec 26, 2010 at 11:45 AM, Denis Lepchev <[hidden email]> wrote:
> 1) as I understand each vector consists of 2 coordinate points x,y and
> lengths in respective directions dx, dy. But after plotting few sample
> vectors, it can be noticed that length on screen actually is not equal to
> dx, dy. It will be equal, only if I translate dx, dy from data space into
> the screen space. Is it intended or it is a bug?

Ah, the vectors are currently only implemented as a screen-space
length.  This also is why zooming and resizing don't resize the
vectors.  I will look into implementing this tomorrow.

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