Exemplo n.º 1
0
def polyCreateDefaultEdges_(poly, boundaryMarker=1,
                            isClosed=True, isHole=False, **kwargs):
    """INTERNAL."""
    nEdges = poly.nodeCount() - 1 + isClosed
    bm = None
    if hasattr(boundaryMarker, '__len__'):
        if len(boundaryMarker) == nEdges:
            bm = boundaryMarker
        else:
            raise Exception("marker length != nEdges", len(boundaryMarker),
                            nEdges)
    else:
        bm = [boundaryMarker] * nEdges

    for i in range(poly.nodeCount() - 1):
        poly.createEdge(poly.node(i), poly.node(i + 1), bm[i])

    if isClosed:
        poly.createEdge(poly.node(poly.nodeCount() - 1), poly.node(0), bm[-1])
    
    pg.warnNonEmptyArgs(kwargs)
Exemplo n.º 2
0
def testMethod(**kwargs):
    pg.warnNonEmptyArgs(kwargs)
Exemplo n.º 3
0
def testMethod(**kwargs):
    pg.warnNonEmptyArgs(kwargs)
Exemplo n.º 4
0
def createPolygon(verts, isClosed=False, isHole=False, **kwargs):
    """Create a polygon from a list of vertices.

    All vertices needs to be unique and duplicate vertices will be ignored.
    If you want the polygon be a closed region you can set the 'isCloses' flag.
    Closed region can be attributed by assigning a region marker.
    The automatic region marker is set in the center of all vertices.

    Parameters
    ----------
    verts : []
        * List of x y pairs [[x0, y0], ... ,[xN, yN]]

    **kwargs:

        * boundaryMarker : int [1]
            Marker for the resulting boundary edges
        * leftDirection : bool [True]
            Rotational direction
        * marker : int [None]
            Marker for the resulting triangle cells after mesh generation.
        * area : float [0]
            Maximum cell size for resulting triangles after mesh generation
        * isHole : bool [False]
            The Polygone will become a hole instead of a triangulation

    isClosed : bool [True]
        Add closing edge between last and first node.

    Returns
    -------
    poly : :gimliapi:`GIMLI::Mesh`
        The resulting polygon is a :gimliapi:`GIMLI::Mesh`.

    Examples
    --------
    >>>  # no need to import matplotlib. pygimli's show does
    >>> import pygimli as pg
    >>> import pygimli.meshtools as mt
    >>> p1 = mt.createPolygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]],
    ...                       isClosed=True, marker=3, area=0.1)
    >>> p2 = mt.createPolygon([[0.3, 0.15], [0.85, 0.15], [0.85, 0.7]],
    ...                       isClosed=True, marker=3, area=0.1, isHole=True)
    >>> ax, _ = pg.show(mt.mergePLC([p1,p2]))
    """
    poly = pg.Mesh(2)

    for v in verts:
        poly.createNodeWithCheck(v, warn=True)

    boundaryMarker = kwargs.pop('boundaryMarker', 1)
    marker = kwargs.pop('marker', None)
    area = kwargs.pop('area', 0)
    isHole = kwargs.pop('isHole', False)

    polyCreateDefaultEdges_(poly, isClosed=isClosed, isHole=False,
                            boundaryMarker=boundaryMarker)

    if isClosed and marker is not None or area > 0:
        if isHole:
            poly.addHoleMarker(pg.center(poly.positions()))
        else:
            if marker is None:  # in case marker is None but area is given
                marker = 0
            poly.addRegionMarker(pg.center(poly.positions()),
                                 marker=marker, area=area)

    # set a regionmarker here .. somewhere

    pg.warnNonEmptyArgs(kwargs)
    return poly