Subdiv2D

Objective-C

@interface Subdiv2D : NSObject

Swift

class Subdiv2D : NSObject

The Subdiv2D module

Member of Imgproc

Class Constants

  • Declaration

    Objective-C

    @property (class, readonly) int PTLOC_ERROR

    Swift

    class var PTLOC_ERROR: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PTLOC_OUTSIDE_RECT

    Swift

    class var PTLOC_OUTSIDE_RECT: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PTLOC_INSIDE

    Swift

    class var PTLOC_INSIDE: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PTLOC_VERTEX

    Swift

    class var PTLOC_VERTEX: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PTLOC_ON_EDGE

    Swift

    class var PTLOC_ON_EDGE: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int NEXT_AROUND_ORG

    Swift

    class var NEXT_AROUND_ORG: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int NEXT_AROUND_DST

    Swift

    class var NEXT_AROUND_DST: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PREV_AROUND_ORG

    Swift

    class var PREV_AROUND_ORG: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PREV_AROUND_DST

    Swift

    class var PREV_AROUND_DST: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int NEXT_AROUND_LEFT

    Swift

    class var NEXT_AROUND_LEFT: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int NEXT_AROUND_RIGHT

    Swift

    class var NEXT_AROUND_RIGHT: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PREV_AROUND_LEFT

    Swift

    class var PREV_AROUND_LEFT: Int32 { get }
  • Declaration

    Objective-C

    @property (class, readonly) int PREV_AROUND_RIGHT

    Swift

    class var PREV_AROUND_RIGHT: Int32 { get }

Methods

  • Declaration

    Objective-C

    - (nonnull instancetype)initWithRect:(nonnull Rect2i *)rect;

    Swift

    init(rect: Rect2i)

    Parameters

    rect

    Rectangle that includes all of the 2D points that are to be added to the subdivision.

    The function creates an empty Delaunay subdivision where 2D points can be added using the function insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime error is raised.

  • creates an empty Subdiv2D object. To create a new empty Delaunay subdivision you need to use the #initDelaunay function.

    Declaration

    Objective-C

    - (nonnull instancetype)init;

    Swift

    init()
  • Returns vertex location from vertex ID.

    Declaration

    Objective-C

    - (nonnull Point2f *)getVertex:(int)vertex firstEdge:(nonnull int *)firstEdge;

    Swift

    func getVertex(vertex: Int32, firstEdge: UnsafeMutablePointer<Int32>) -> Point2f

    Parameters

    vertex

    vertex ID.

    firstEdge

    Optional. The first edge ID which is connected to the vertex.

    Return Value

    vertex (x,y)

  • Returns vertex location from vertex ID.

    Declaration

    Objective-C

    - (nonnull Point2f *)getVertex:(int)vertex;

    Swift

    func getVertex(vertex: Int32) -> Point2f

    Parameters

    vertex

    vertex ID.

    Return Value

    vertex (x,y)

  • Returns the edge destination.

    Declaration

    Objective-C

    - (int)edgeDst:(int)edge dstpt:(nonnull Point2f *)dstpt;

    Swift

    func edgeDst(edge: Int32, dstpt: Point2f) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    dstpt

    Output vertex location.

    Return Value

    vertex ID.

  • Returns the edge destination.

    Declaration

    Objective-C

    - (int)edgeDst:(int)edge;

    Swift

    func edgeDst(edge: Int32) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    Return Value

    vertex ID.

  • Returns the edge origin.

    Declaration

    Objective-C

    - (int)edgeOrg:(int)edge orgpt:(nonnull Point2f *)orgpt;

    Swift

    func edgeOrg(edge: Int32, orgpt: Point2f) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    orgpt

    Output vertex location.

    Return Value

    vertex ID.

  • Returns the edge origin.

    Declaration

    Objective-C

    - (int)edgeOrg:(int)edge;

    Swift

    func edgeOrg(edge: Int32) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    Return Value

    vertex ID.

  • Finds the subdivision vertex closest to the given point.

    Declaration

    Objective-C

    - (int)findNearest:(nonnull Point2f *)pt nearestPt:(nonnull Point2f *)nearestPt;

    Swift

    func findNearest(pt: Point2f, nearestPt: Point2f) -> Int32

    Parameters

    pt

    Input point.

    nearestPt

    Output subdivision vertex point.

    The function is another function that locates the input point within the subdivision. It finds the subdivision vertex that is the closest to the input point. It is not necessarily one of vertices of the facet containing the input point, though the facet (located using locate() ) is used as a starting point.

    Return Value

    vertex ID.

  • Finds the subdivision vertex closest to the given point.

    Declaration

    Objective-C

    - (int)findNearest:(nonnull Point2f *)pt;

    Swift

    func findNearest(pt: Point2f) -> Int32

    Parameters

    pt

    Input point.

    The function is another function that locates the input point within the subdivision. It finds the subdivision vertex that is the closest to the input point. It is not necessarily one of vertices of the facet containing the input point, though the facet (located using locate() ) is used as a starting point.

    Return Value

    vertex ID.

  • Returns one of the edges related to the given edge.

    Declaration

    Objective-C

    - (int)getEdge:(int)edge nextEdgeType:(int)nextEdgeType;

    Swift

    func getEdge(edge: Int32, nextEdgeType: Int32) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    nextEdgeType

    Parameter specifying which of the related edges to return. The following values are possible:

    • NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge)
    • NEXT_AROUND_DST next around the edge vertex ( eDnext )
    • PREV_AROUND_ORG previous around the edge origin (reversed eRnext )
    • PREV_AROUND_DST previous around the edge destination (reversed eLnext )
    • NEXT_AROUND_LEFT next around the left facet ( eLnext )
    • NEXT_AROUND_RIGHT next around the right facet ( eRnext )
    • PREV_AROUND_LEFT previous around the left facet (reversed eOnext )
    • PREV_AROUND_RIGHT previous around the right facet (reversed eDnext )

    sample output

    Return Value

    edge ID related to the input edge.

  • Insert a single point into a Delaunay triangulation.

    Declaration

    Objective-C

    - (int)insert:(nonnull Point2f *)pt;

    Swift

    func insert(pt: Point2f) -> Int32

    Parameters

    pt

    Point to insert.

    The function inserts a single point into a subdivision and modifies the subdivision topology appropriately. If a point with the same coordinates exists already, no new point is added.

    Note

    If the point is outside of the triangulation specified rect a runtime error is raised.

    Return Value

    the ID of the point.

  • Returns the location of a point within a Delaunay triangulation.

    Declaration

    Objective-C

    - (int)locate:(nonnull Point2f *)pt
             edge:(nonnull int *)edge
           vertex:(nonnull int *)vertex;

    Swift

    func locate(pt: Point2f, edge: UnsafeMutablePointer<Int32>, vertex: UnsafeMutablePointer<Int32>) -> Int32

    Parameters

    pt

    Point to locate.

    edge

    Output edge that the point belongs to or is located to the right of it.

    vertex

    Optional output vertex the input point coincides with.

    The function locates the input point within the subdivision and gives one of the triangle edges or vertices.

    • The point falls into some facet. The function returns #PTLOC_INSIDE and edge will contain one of edges of the facet.
    • The point falls onto the edge. The function returns #PTLOC_ON_EDGE and edge will contain this edge.
    • The point coincides with one of the subdivision vertices. The function returns #PTLOC_VERTEX and vertex will contain a pointer to the vertex.
    • The point is outside the subdivision reference rectangle. The function returns #PTLOC_OUTSIDE_RECT and no pointers are filled.
    • One of input arguments is invalid. A runtime error is raised or, if silent or “parent” error processing mode is selected, #PTLOC_ERROR is returned.

    Return Value

    an integer which specify one of the following five cases for point location:

  • Returns next edge around the edge origin.

    Declaration

    Objective-C

    - (int)nextEdge:(int)edge;

    Swift

    func nextEdge(edge: Int32) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    Return Value

    an integer which is next edge ID around the edge origin: eOnext on the picture above if e is the input edge).

  • Returns another edge of the same quad-edge.

    Declaration

    Objective-C

    - (int)rotateEdge:(int)edge rotate:(int)rotate;

    Swift

    func rotateEdge(edge: Int32, rotate: Int32) -> Int32

    Parameters

    edge

    Subdivision edge ID.

    rotate

    Parameter specifying which of the edges of the same quad-edge as the input one to return. The following values are possible:

    • 0 - the input edge ( e on the picture below if e is the input edge)
    • 1 - the rotated edge ( eRot )
    • 2 - the reversed edge (reversed e (in green))
    • 3 - the reversed rotated edge (reversed eRot (in green))

    Return Value

    one of the edges ID of the same quad-edge as the input edge.

  • Declaration

    Objective-C

    - (int)symEdge:(int)edge NS_SWIFT_NAME(symEdge(edge:));

    Swift

    func symEdge(edge: Int32) -> Int32
  • Returns a list of all edges.

    Declaration

    Objective-C

    - (void)getEdgeList:(nonnull NSMutableArray<Float4 *> *)edgeList;

    Swift

    func getEdgeList(edgeList: NSMutableArray)

    Parameters

    edgeList

    Output vector.

    The function gives each edge as a 4 numbers vector, where each two are one of the edge vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3].

  • Returns a list of the leading edge ID connected to each triangle.

    Declaration

    Objective-C

    - (void)getLeadingEdgeList:(nonnull IntVector *)leadingEdgeList;

    Swift

    func getLeadingEdgeList(leadingEdgeList: IntVector)

    Parameters

    leadingEdgeList

    Output vector.

    The function gives one edge ID for each triangle.

  • Returns a list of all triangles.

    Declaration

    Objective-C

    - (void)getTriangleList:(nonnull NSMutableArray<Float6 *> *)triangleList;

    Swift

    func getTriangleList(triangleList: NSMutableArray)

    Parameters

    triangleList

    Output vector.

    The function gives each triangle as a 6 numbers vector, where each two are one of the triangle vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5].

  • Returns a list of all Voronoi facets.

    Declaration

    Objective-C

    - (void)getVoronoiFacetList:(nonnull IntVector *)idx
                      facetList:
                          (nonnull NSMutableArray<NSMutableArray<Point2f *> *> *)
                              facetList
                   facetCenters:(nonnull NSMutableArray<Point2f *> *)facetCenters;

    Swift

    func getVoronoiFacetList(idx: IntVector, facetList: NSMutableArray, facetCenters: NSMutableArray)

    Parameters

    idx

    Vector of vertices IDs to consider. For all vertices you can pass empty vector.

    facetList

    Output vector of the Voronoi facets.

    facetCenters

    Output vector of the Voronoi facets center points.

  • Creates a new empty Delaunay subdivision

    Declaration

    Objective-C

    - (void)initDelaunay:(nonnull Rect2i *)rect;

    Swift

    func initDelaunay(rect: Rect2i)

    Parameters

    rect

    Rectangle that includes all of the 2D points that are to be added to the subdivision.

  • Insert multiple points into a Delaunay triangulation.

    Declaration

    Objective-C

    - (void)insertVector:(nonnull NSArray<Point2f *> *)ptvec;

    Swift

    func insert(ptvec: [Point2f])

    Parameters

    ptvec

    Points to insert.

    The function inserts a vector of points into a subdivision and modifies the subdivision topology appropriately.