Exemplo n.º 1
0
def clip_surface():
    """Clip the stl model."""
    if not check_surface():
        return
    itemlist = [['axis',0],['begin',0.0],['end',1.0],['nodes','any']]
    res,accept = widgets.inputDialog(itemlist,'Clipping Parameters').getResult()
    if accept:
        updateGUI()
        nodes,elems = PF['old_surface'] = PF['surface']
        F = Formex(nodes[elems])
        bb = F.bbox()
        GD.message("Original bbox: %s" % bb) 
        xmi = bb[0][0]
        xma = bb[1][0]
        dx = xma-xmi
        axis = int(res[0][1])
        xc1 = xmi + float(res[1][1]) * dx
        xc2 = xmi + float(res[2][1]) * dx
        nodid = res[3][1]
        print nodid
        clear()
        draw(F,color='yellow')
        w = F.test(nodes='any',dir=axis,min=xc1,max=xc2)
        F = F.clip(w)
        draw(F,clor='red')
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 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]