Exemplo n.º 1
0
def createGrid():
    _data_ = _name_ + 'createGrid_data'
    dia = Dialog(items=[
        _I('name', '__auto__'),
        _I('object type', choices=['Formex', 'Mesh', 'TriSurface']),
        _I('base', choices=base_patterns),
        _I('nx', 4),
        _I('ny', 2),
        _I('stepx', 1.),
        _I('stepy', 1.),
        _I('taper', 0),
        _I('bias', 0.),
    ])
    if _data_ in pf.PF:
        dia.updateData(pf.PF[_data_])
    res = dia.getResults()
    if res:
        pf.PF[_data_] = res
        name = res['name']
        if name == '__auto__':
            name = autoName(res['object type']).next()
        F = Formex(res['base']).replic2(n1=res['nx'],
                                        n2=res['ny'],
                                        t1=res['stepx'],
                                        t2=res['stepy'],
                                        bias=res['bias'],
                                        taper=res['taper'])
        F = convertFormex(F, res['object type'])
        export({name: F})
        selection.set([name])
        if res['object type'] == 'TriSurface':
            surface_menu.selection.set([name])
        selection.draw()
Exemplo n.º 2
0
def inside(self, pts):
    """Test which of the points pts are inside the surface.

    Parameters:

    - `pts`: a (usually 1-plex) Formex or a data structure that can be used
      to initialize a Formex.

    Returns an integer array with the indices of the points that are
    inside the surface. The indices refer to the onedimensional list
    of points as obtained from pts.points().
    """
    from formex import Formex
    if not isinstance(pts, Formex):
        pts = Formex(pts)
    pts = Formex(pts)  #.asPoints()
    print(type(pts))

    # determine bbox of common space of surface and points
    bb = bboxIntersection(self, pts)
    if (bb[0] > bb[1]).any():
        # No bbox intersection: no points inside
        return array([], dtype=Int)

    # Limit the points to the common part
    # Add point numbers as property, to allow return of original numbers
    pts.setProp(arange(pts.nelems()))
    pts = pts.clip(testBbox(pts, bb))

    # Apply the gtsinside shooting algorithm in three directions
    ins = zeros((pts.nelems(), 3), dtype=bool)
    for i in range(3):
        dirs = roll(arange(3), -i)[1:]
        # clip the surface perpendicular to the shooting direction
        S = self.clip(testBbox(self, bb, dirs))
        # find inside points shooting in direction i
        ok = gtsinside(S, pts, dir=i)
        ins[ok, i] = True

    ok = where(ins.sum(axis=-1) > 1)[0]
    return pts.prop[ok]
Exemplo n.º 3
0
    def readFormex(self, nelems, nplex, props, eltype, sep):
        """Read a Formex from a pyFormex geometry file.

        The coordinate array for nelems*nplex points is read from the file.
        If present, the property numbers for nelems elements are read.
        From the coords and props a Formex is created and returned.
        """
        ndim = 3
        f = readArray(self.fil, Float, (nelems, nplex, ndim), sep=sep)
        if props:
            p = readArray(self.fil, Int, (nelems, ), sep=sep)
        else:
            p = None
        return Formex(f, p, eltype)
Exemplo n.º 4
0
 def toFormex(self):
     from formex import Formex
     x = stack([self.coords, roll(self.coords, -1, axis=0)], axis=1)
     return Formex(x)
Exemplo n.º 5
0
    def area(self):
        """Compute area inside a polygon.

        """
        from plugins.section2d import PlaneSection
        return PlaneSection(Formex(self.coords)).sectionChar()['A']