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

Home » Public Forums » archive » Delaunay triangulation search
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
Delaunay triangulation search [message #56147] Fri, 05 October 2007 15:17 Go to next message
Charudatta Phatak is currently offline  Charudatta Phatak
Messages: 6
Registered: November 2006
Junior Member
Hello All,

I want to know, is there a function in IDL which will give me the
corresponding indices of a traingle from a delaunay triangulation for
the given point. So suppose i use TRIANGULATE to generate a
triangulation. Then i want to go through the image pixel by pixel and
want to determine which pixels are enclosed in a particular triangle.

In MATLAB, the function tsearch does this. This is the help of tsearch
from matlab website:

tsearch
Search for enclosing Delaunay triangle
Syntax
T = tsearch(x,y,TRI,xi,yi)
Description
T = tsearch(x,y,TRI,xi,yi) returns an index into the rows of TRI for
each point in xi, yi. The tsearch command returns NaN for all points
outside the convex hull. Requires a triangulation TRI of the points x,y
obtained from delaunay.

I think a function like QHULL in IDL might be able to do the same thing
but i'm unable to figure how to use it.
Thank you...

cheers,
-cd
Re: Delaunay triangulation search [message #56270 is a reply to message #56147] Mon, 08 October 2007 18:48 Go to previous messageGo to next message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On Oct 5, 6:17 pm, Charudatta Phatak <cpha...@andrew.cmu.edu> wrote:
> Hello All,
>
> I want to know, is there a function in IDL which will give me the
> corresponding indices of a traingle from a delaunay triangulation for
> the given point. So suppose i use TRIANGULATE to generate a
> triangulation. Then i want to go through the image pixel by pixel and
> want to determine which pixels are enclosed in a particular triangle.
>
> In MATLAB, the function tsearch does this. This is the help of tsearch
> from matlab website:
>
> tsearch
> Search for enclosing Delaunay triangle
> Syntax
> T = tsearch(x,y,TRI,xi,yi)
> Description
> T = tsearch(x,y,TRI,xi,yi) returns an index into the rows of TRI for
> each point in xi, yi. The tsearch command returns NaN for all points
> outside the convex hull. Requires a triangulation TRI of the points x,y
> obtained from delaunay.
>
> I think a function like QHULL in IDL might be able to do the same thing
> but i'm unable to figure how to use it.
> Thank you...
>
> cheers,
> -cd

Hi,

I am sure there are much more efficient ways, but I suggest the brute
force approach by using IDL's IDLanROI and IDLanROIgroup objects.
They each have a ContainsPoints method which comes in handy even if
not very fast (or maybe it is fast and I am just impatient!) In any
event, I have modified the TRIANGULATE example from the online docs to
show what I mean. Hope it helps get you started.

Cheers,
Ben

***BEGIN
PRO TriSearch

; Make 50 normal x, y points:
x = RANDOMN(seed, 50)
y = RANDOMN(seed, 50)

mmX = [MIN(x), MAX(x)]
mmY = [MIN(y), MAX(y)]

x = (x-mmx[0])/(mmx[1]-mmx[0]) * 99
y = (y-mmy[0])/(mmy[1]-mmy[0]) * 99


WINDOW, 0
; Show points:
PLOT, x, y, psym=1,/ISO

; Obtain triangulation:
TRIANGULATE, x, y, tr, b

roiGroup = OBJ_NEW('IDLanROIgroup')
; Show the triangles:
FOR i=0, N_ELEMENTS(tr)/3-1 DO BEGIN
; Subscripts of vertices [0,1,2,0]:
t = [tr[*,i], tr[0,i]]
; Connect triangles:
PLOTS, x[t], y[t], psym = -3
roiGroup->Add, OBJ_NEW('IDLanROI', x[t], y[t])
ENDFOR

;mock up an image and the indices for each pixel
img = REPLICATE(255B, 100,100)
xx = FINDGEN(100) # REPLICATE(1.0,100)
yy = REPLICATE(1.0,100) # FINDGEN(100)

;find out if the pixels are in/out
;you could devise a way of testing each polygon (triangle) -
;it shouldn't be too hard - just arr = roiGroup->Get(/all)
;to retrieve the individual rois, then loop through testing each
;using the array[i]->ContainsPoints(xx,yy). It is your call.
ok = roiGroup->ContainsPoints(xx,yy)
A = WHERE(ok, nA, COMP = B, NCOMP = nB)
if nA then PLOTS, xx[A],yy[A], psym = 3

if nB GT 0 then begin
WINDOW, 1, XSIZE = 100, YSIZE = 100
img[B] = 0
TVSCL, img
endif

END
***END
Re: Delaunay triangulation search [message #56309 is a reply to message #56270] Thu, 11 October 2007 09:22 Go to previous message
Charudatta Phatak is currently offline  Charudatta Phatak
Messages: 6
Registered: November 2006
Junior Member
Hi Ben,

Thanks for the help. But i was able to do it simply using the built in
idl function POLYFILLV which in fact does exactly what i wanted. it
finds the indices of all the points enclosed in a given polygon and it
works pretty fast too.

cheers,
-cd



ben.bighair wrote:
> On Oct 5, 6:17 pm, Charudatta Phatak <cpha...@andrew.cmu.edu> wrote:
>> Hello All,
>>
>> I want to know, is there a function in IDL which will give me the
>> corresponding indices of a traingle from a delaunay triangulation for
>> the given point. So suppose i use TRIANGULATE to generate a
>> triangulation. Then i want to go through the image pixel by pixel and
>> want to determine which pixels are enclosed in a particular triangle.
>>
>> In MATLAB, the function tsearch does this. This is the help of tsearch
>> from matlab website:
>>
>> tsearch
>> Search for enclosing Delaunay triangle
>> Syntax
>> T = tsearch(x,y,TRI,xi,yi)
>> Description
>> T = tsearch(x,y,TRI,xi,yi) returns an index into the rows of TRI for
>> each point in xi, yi. The tsearch command returns NaN for all points
>> outside the convex hull. Requires a triangulation TRI of the points x,y
>> obtained from delaunay.
>>
>> I think a function like QHULL in IDL might be able to do the same thing
>> but i'm unable to figure how to use it.
>> Thank you...
>>
>> cheers,
>> -cd
>
> Hi,
>
> I am sure there are much more efficient ways, but I suggest the brute
> force approach by using IDL's IDLanROI and IDLanROIgroup objects.
> They each have a ContainsPoints method which comes in handy even if
> not very fast (or maybe it is fast and I am just impatient!) In any
> event, I have modified the TRIANGULATE example from the online docs to
> show what I mean. Hope it helps get you started.
>
> Cheers,
> Ben
>
> ***BEGIN
> PRO TriSearch
>
> ; Make 50 normal x, y points:
> x = RANDOMN(seed, 50)
> y = RANDOMN(seed, 50)
>
> mmX = [MIN(x), MAX(x)]
> mmY = [MIN(y), MAX(y)]
>
> x = (x-mmx[0])/(mmx[1]-mmx[0]) * 99
> y = (y-mmy[0])/(mmy[1]-mmy[0]) * 99
>
>
> WINDOW, 0
> ; Show points:
> PLOT, x, y, psym=1,/ISO
>
> ; Obtain triangulation:
> TRIANGULATE, x, y, tr, b
>
> roiGroup = OBJ_NEW('IDLanROIgroup')
> ; Show the triangles:
> FOR i=0, N_ELEMENTS(tr)/3-1 DO BEGIN
> ; Subscripts of vertices [0,1,2,0]:
> t = [tr[*,i], tr[0,i]]
> ; Connect triangles:
> PLOTS, x[t], y[t], psym = -3
> roiGroup->Add, OBJ_NEW('IDLanROI', x[t], y[t])
> ENDFOR
>
> ;mock up an image and the indices for each pixel
> img = REPLICATE(255B, 100,100)
> xx = FINDGEN(100) # REPLICATE(1.0,100)
> yy = REPLICATE(1.0,100) # FINDGEN(100)
>
> ;find out if the pixels are in/out
> ;you could devise a way of testing each polygon (triangle) -
> ;it shouldn't be too hard - just arr = roiGroup->Get(/all)
> ;to retrieve the individual rois, then loop through testing each
> ;using the array[i]->ContainsPoints(xx,yy). It is your call.
> ok = roiGroup->ContainsPoints(xx,yy)
> A = WHERE(ok, nA, COMP = B, NCOMP = nB)
> if nA then PLOTS, xx[A],yy[A], psym = 3
>
> if nB GT 0 then begin
> WINDOW, 1, XSIZE = 100, YSIZE = 100
> img[B] = 0
> TVSCL, img
> endif
>
> END
> ***END
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Error in coyote's colorbar
Next Topic: Re: Minor IDL code changes cause large slowdowns elsewhere in code

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

Current Time: Wed Oct 08 20:04:35 PDT 2025

Total time taken to generate the page: 0.00699 seconds