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

Home » Public Forums » archive » Re: Strange behavior of POLYFILL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Strange behavior of POLYFILL [message #77709] Thu, 22 September 2011 05:28 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Xavi Llort writes:

> I have to calculate this for ~1.E6 different polygons in less than 4
> minutes and all analytical solutions do not fulfill the benchmark.
> POLYFILLV does, but giving a wrong answer!!

Yes, the price of speed! :-)

Ronn Kling had an analytical solution that could do
many points at once and I believe was fast. I can't
find it now, and I'm just leaving the office for a
few days. You might check on Ronn's web page:

http://www.kilvarock.com

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Strange behavior of POLYFILL [message #77711 is a reply to message #77709] Thu, 22 September 2011 03:41 Go to previous messageGo to next message
Xavi Llort is currently offline  Xavi Llort
Messages: 15
Registered: September 2006
Junior Member
Thanks for the answer,

But I also coded an analytical solution. The point is that I need a
really fast way to obtain all the points inside a polygon rather than
testing one by one.
I have to calculate this for ~1.E6 different polygons in less than 4
minutes and all analytical solutions do not fulfill the benchmark.
POLYFILLV does, but giving a wrong answer!!

I ended in this simple polygon (a triangle) that instead of retrieving
10 points is only retrieving 9 (clearly seen in the plot). I do not
know if it is really an IDL bug or I'm doing something wrong...
Re: Strange behavior of POLYFILL [message #77731 is a reply to message #77711] Wed, 21 September 2011 06:21 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Xavi Llort writes:

> After hours fighting against POLYFILLV, I found a strange
> behavior that I cannot understand...
>
> Here there is a small code searching the points inside a triangle. Why
> there is a point that clearly is inside the triangle and not retrieved
> by PolyfillV (see plot)? Does anyone have a solution?

I don't have time this morning to look at this very
carefully, but I will say that PolyFillV is a *graphic*
solution, not an *analytical* solution. It seems to
me you are looking for an analytical solution. If so,
there are better ways. IDLanROI is one and here is
an article that describes another:

http://www.idlcoyote.com/tips/point_in_polygon.html

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Strange behavior of POLYFILL [message #77735 is a reply to message #77731] Wed, 21 September 2011 02:11 Go to previous messageGo to next message
Xavi Llort is currently offline  Xavi Llort
Messages: 15
Registered: September 2006
Junior Member
I was meaning POLYFILLV instead of POLYFILL, sorry!

And by the way, I tested on 2 machines:

IDL> help, !version,/str
** Structure !VERSION, 8 tags, length=104, data length=100:
ARCH STRING 'x86_64'
OS STRING 'linux'
OS_FAMILY STRING 'unix'
OS_NAME STRING 'linux'
RELEASE STRING '8.0'
BUILD_DATE STRING 'Jun 18 2010'
MEMORY_BITS INT 64
FILE_OFFSET_BITS
INT 64

IDL> help, !version, /str
** Structure !VERSION, 8 tags, length=76, data length=76:
ARCH STRING 'i386'
OS STRING 'darwin'
OS_FAMILY STRING 'unix'
OS_NAME STRING 'Mac OS X'
RELEASE STRING '7.0'
BUILD_DATE STRING 'Oct 25 2007'
MEMORY_BITS INT 32
FILE_OFFSET_BITS
INT 64
Re: Strange behavior of POLYFILL [message #77793 is a reply to message #77709] Fri, 23 September 2011 02:48 Go to previous messageGo to next message
Xavi Llort is currently offline  Xavi Llort
Messages: 15
Registered: September 2006
Junior Member
Thank you very much for the alternative!

It works (below there is a piece of code comparing against POLYFILLV),
but the computational is quite high, specially searching in a large
number of points.
In my case (a 1024 by 1024) the overall time goes from ~1.E-5 secs of
POLYFILLV to ~2 secs of Ronn Kling's routine, and I cannot afford.

Is this a bug of POLYFILLV? Does anyone experienced similar problems?

Thanks again for your help,
Xavi Llort


PRO POLY_HELL_2
dim_x = 1024l & dim_y = 1024l
lon_res = 0.02 & lat_res = 0.02
lon_arr = FINDGEN(dim_x)*lon_res - 12.99
lat_arr = FINDGEN(dim_y)*lat_res + 29.53
triangle_xx = [-4.27, -4.3221145, -4.3234300, -4.27]
triangle_yy = [35.449997, 35.535344, 35.365467,35.449997]

;
************************************************************ **********
; POLYFILL calculus
t0 = SYSTIME(/SEC)
xx_n = (triangle_xx - lon_arr[0]) / lon_res +1.
yy_n = (triangle_yy - lat_arr[0]) / lat_res +1.
points_in = POLYFILLV(xx_n, yy_n, dim_x, dim_y )
lap1 = SYSTIME(/SEC) - t0

DEVICE, DEC=0
LOADCT, 5
WINDOW, 0, XSIZE=800, YSIZE=800, TITLE='RESULT WITH POLYFILL'

PLOT, triangle_xx, triangle_yy, PSYM=-4, XR=[-4.39, -4.15], XSTYLE=1,
$
YR=[35.33, 35.57], YSTYLE=1
lon_mat = REBIN(lon_arr, dim_x, dim_y)
lat_mat = REBIN(TRANSPOSE(lat_arr), dim_x, dim_y)
OPLOT, lon_mat, lat_mat, psym=1, SYMSIZE=0.7
OPLOT, lon_mat[points_in], lat_mat[points_in], psym=4, SYMSIZE=1.4,
COLOR=115, THICK=2.

;
************************************************************ **********
; Ron Kling calculus
t1 = SYSTIME(/SEC)
lon_vals = REFORM( REBIN(lon_arr, dim_x, dim_y), dim_x*dim_y)
lat_vals = REFORM( REBIN(TRANSPOSE(lat_arr), dim_x, dim_y),
dim_x*dim_y)
data = TRANSPOSE([[lon_vals],[lat_vals]])
connect = REFORM( INDGEN(3),3,1)
points_in_Kling = pointInsideApolygon (triangle_xx[0:2],
triangle_yy[0:2], connect, data)
lap2 = SYSTIME(/SEC) - t1

WINDOW, 1, XSIZE=800, YSIZE=800, TITLE='RESULT WITH RONN KLING
ROUTINE'
PLOT, triangle_xx, triangle_yy, PSYM=-4, XR=[-4.39, -4.15], XSTYLE=1,
$
YR=[35.33, 35.57], YSTYLE=1
OPLOT, lon_vals, lat_vals, psym=1, SYMSIZE=0.7
OPLOT, lon_vals[points_in_Kling], lat_vals[points_in_Kling], psym=4,
SYMSIZE=1.4, COLOR=115, THICK=2.

PRINT, ' '
PRINT, '*** POLYFILL used ' + STRING(lap1,FORMAT='(E9.3)') + '
seconds'
PRINT, '*** Ronn Kling used ' + STRING(lap2,FORMAT='(E9.3)') + '
seconds'

END
Re: Strange behavior of POLYFILL [message #77904 is a reply to message #77793] Tue, 27 September 2011 06:06 Go to previous message
Xavi Llort is currently offline  Xavi Llort
Messages: 15
Registered: September 2006
Junior Member
Dear all again,

I've tested massively the POLYFILLV against Ronn Kling's routine and
Polyfillv is preforming quite a lot of errors...
I wonder if there is a way to report it to ITT, does anyone know how
to do it?

Maybe it can be corrected for future versions and we will have the
wonderful the exactness of Ronn's routine with the speed of
Polyfillv...

Thanks,
Xavi
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 8.1 PostScript Output on a Sheet of Paper
Next Topic: Best way to share 'enum' between various functions

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

Current Time: Wed Oct 08 16:00:33 PDT 2025

Total time taken to generate the page: 0.00673 seconds