c4d.utils.Neighbor

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.

Members

Neighbor.__init__()
Return type:c4d.utils.Neighbor
Returns:The new neighbor object.
Neighbor.Init(op, bs=None)

Initialise the internal polygon information, this function must be called before the class can be used to get the neighbouring polygons.

Parameters:
  • op (c4d.PolygonObject) – The class object.
  • bs (c4d.BaseSelect) – The polygon selection that will be used to build the neighbor information. By default None to use all polygons.
Neighbor.Flush()

Flushes the neighbor information.

Neighbor.GetNeighbor(a, b, poly)
../../../_images/neighbor.png

Gets the polygon opposite to poly with respect to the edge from point a to b.

Parameters:
  • a (int) – The point index that defines the first edge point.
  • b (int) – The point index that defines the second edge point.
  • poly (int) – The index of the polygon to get the polygon opposite to.
  • poly – The index of the polygon to get the polygon opposite to.
Raises:

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

Returns:

The opposite polygon index, or NOTOK if none exists or if poly is not one of the edge polygons.

Neighbor.GetPointPolys(pnt)
../../../_images/pointpolys.png

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.
Neighbor.GetEdgePolys(a, b)
../../../_images/edgepolys.png

Get the polygons that neighbor the given edge:

first, second = neighbor.GetEdgePolys(1, 2)
Parameters:
  • a (int) – The point index that defines the first edge point.
  • b (int) – The point index that defines the second edge point.
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.

Neighbor.GetEdgeCount()

Get the total number of edges found.

Return type:int
Returns:The number of edges.
Neighbor.GetPolyInfo(poly)

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

0-1-2-3 are the indices for a-b/b-c/c-d/d-a. For triangles the face/edge index 2 is set to NOTOK (as c == d). e.g. a value of 5-8-2-1 for face means: a-b neighbor face is 5, b-c 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.
Neighbor.GetPointOneRingPoints(pnt)

New in version R19.

Gets the points that are attached through one edge to the given point.

Parameters:pnt (int) – The point index to use to find the associated one ring points.
Return type:List[int]
Returns:A list of points indices.