Class to get neighbouring polygons from edges and points.
Note
This class assumes that the geometry is clean such that an edge is only shared by two polygons, if this is not the case then the information may not be correct.
Warning
The object passed to Neighbor.Init() must not be modified during the use of this class. For example, if you resize a polygon object or modify the polygons this class may crash if you then try and use the classes functions.
Initialise the internal polygon information, this function must be called before the class can be used to get the neighbouring polygons.
Parameters: 


Flushes the neighbor information.
Gets the polygon opposite to poly with respect to the edge from point a to b.
Parameters: 


Raises IndexError:  
If a, b or poly is out of range. 

Returns: 
The opposite polygon index, or NOTOK if none exists or if poly isn’t one of the edge polygons. 
Get the polygons that are attached to the given point index.
For example:
To get the polygons around say point 137 you would use:
polys = neigbor.GetPointPolys(137)
for poly in polys:
#do something with poly
pass
Parameters:  pnt (int) – The point index to use to find the associated polygons. 

Raises IndexError:  
If pnt is out of range.  
Return type:  list 
Returns:  A list of returned polygons. 
Get the polygons that neighbor the given edge:
first, second = neighbor.GetEdgePolys(1, 2)
Parameters: 


Raises IndexError:  
If a or b is out of range. 

Return type: 
tuple(int, int) 
Returns: 
The first and second polygon associated with the edge. 
Get the total number of edges found.
Return type:  int 

Returns:  The number of edges. 
Get a dict that contains neighbor information about the given polygon. One can use this to browse through all available edges using the following code:
nbr = utils.Neighbor()
nbr.Init(op)
vadr = op.GetAllPolygons()
for i in xrange(op.GetPolygonCount()):
pli = nbr.GetPolyInfo(i)
for side in xrange(4): # # test all 4 sides of a polygon
# Only proceed if edge has not already been processed
# and edge really exists (for triangles side 2 from c..d does not exist as c==d)
if pli["mark"][side] or side==2 and vadr[i].c==vadr[i].d: continue
# One can also skip the side==2 && vadr[i].c==vadr[i].d test as pli["mark"][2] is always True for triangles
if side==0:
a=vadr[i].a; b=vadr[i].b
elif side==1:
a=vadr[i].b; b=vadr[i].c
elif side==2:
a=vadr[i].c; b=vadr[i].d
elif side==3:
a=vadr[i].d; b=vadr[i].a
# Do something with the edge a..b
0123 are the indices for ab/bc/cd/da. For triangles the face/edge index 2 is set to NOTOK (as c == d). e.g. a value of 5821 for face means: ab neighbor face is 5, bc neighbor face is 8 etc.
Parameters:  poly (int) – The polygon index to get the neighbor information for. 

Return type:  dict{mark: bool*4, face: int*4, edge: int*4} 
Returns:  The neighbor information about the given polygon. 
Key mark:  False if that polygon “generated” an edge, for example think of two polygons that share an edge, one has set mark = False for this edge because it was the first and “built” this edge and the other(s) will set mark = True as no new edge had to be generated. 
Key face:  The neighbouring polygons. Note: If a value is NOTOK this means there is no neighbor. 
Key edge:  The edges of the polygon. 