Code covered by the BSD License  

Highlights from
Fast Inpolygon in MEX

4.0

4.0 | 1 rating Rate this file 8 Downloads (last 30 days) File Size: 5.86 KB File ID: #30819
image thumbnail

Fast Inpolygon in MEX

by Tolga Birdal

 

22 Mar 2011 (Updated 22 Mar 2011)

Fast inpolygon function implemented in MEX. So far one of the fastest.

| Watch this File

File Information
Description

This is a C implementation of the great Matlab code provided by Darren Engwirda. You can find his code in:
http://www.mathworks.com/matlabcentral/fileexchange/10391-fast-points-in-polygon-test
 
According to my estimates, it works more than 2x as fast. So far, this is one of the fastest implementation that I know of. Sorting is big step of this algorithm. To make it an exact replica, I use stable_sort of std library.
 
Here is a sample call:
 
tic(); [In2 On2]=inpolygon_fast(x, y, xv, yv); toc();
 
The call interface is similiar to inpolygon and not to inpoly. Here x and y are the points to check, where xv and yv define the polygon.
 
The attachment includes the cpp file, a sample function for comparison and Darren's code.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
22 Mar 2011 Bruno Luong

According to my test, fastest in_polygon is not this submission but this one:

http://www.mathworks.com/matlabcentral/fileexchange/27840-2d-polygon-interior-detection

The CPP mex file (not C) lacks help, document on calling convention, and error checking. I get few crashes when playing around with it.

22 Mar 2011 Tolga Birdal

You are right. Good to know.
Actually there is help and calling convention in the above documentation and I provided a sample file as well.
Error checking is not done for speed reasons (your code also lacks that in some sense).

25 May 2011 Alex Franquet  
10 Oct 2011 Yaver Kamer

So now that you know that this code is not the fastest would you kindly consider editing your bold claims just for the sake of not being misleading?

Please login to add a comment or rating.
Updates
22 Mar 2011

Small updates in description.

Tag Activity for this File
Tag Applied By Date/Time
inpolygon Tolga Birdal 22 Mar 2011 11:27:48
inpoly Tolga Birdal 22 Mar 2011 11:27:48
points in polygon Tolga Birdal 22 Mar 2011 11:27:48
fastest inpolygon Tolga Birdal 22 Mar 2011 11:27:48
mex Tolga Birdal 22 Mar 2011 11:27:48
image processing Tolga Birdal 22 Mar 2011 11:27:48
computer vision Tolga Birdal 22 Mar 2011 11:27:48

Contact us at files@mathworks.com