Beispiel #1
0
def run():
    global F, G
    clear()
    smooth()
    view('iso')
    F = cylinder(L=8., D=2., nt=36, nl=20, diag='u').centered()
    F = TriSurface(F).setProp(3).close(method='planar').fixNormals()
    G = F.rotate(90., 0).trl(0, 1.).setProp(1)
    export({'F': F, 'G': G})
    draw([F, G])

    res = askItems([
        _I('op',
           text='Operation',
           choices=[
               '+ (Union)',
               '- (Difference)',
               '* Intersection',
               'Intersection Curve',
           ],
           itemtype='vradio'),
        _I('verbose', False, text='Show stats'),
    ])

    if not res:
        return
    op = res['op'][0]
    verbose = res['verbose']
    if op in '+-*':
        I = F.boolean(G, op, verbose=verbose)
    else:
        I = F.intersection(G, verbose=verbose)
    clear()
    draw(I)

    if op in '+-*':
        return

    else:
        if ack('Create a surface inside the curve ?'):
            I = I.toMesh()
            e = connectedLineElems(I.elems)
            I = Mesh(I.coords, connectedLineElems(I.elems)[0])
            clear()
            draw(I, color=red, linewidth=3)
            S = fillBorder(I, method='planar')
            draw(S)
Beispiel #2
0
def run():
    global F,G
    clear()
    smooth()
    view('iso')
    F = cylinder(L=8.,D=2.,nt=36,nl=20,diag='u').centered()
    F = TriSurface(F).setProp(3).close(method='planar').fixNormals()
    G = F.rotate(90.,0).trl(0,1.).setProp(1)
    export({'F':F,'G':G})
    draw([F,G])

    res = askItems(
        [ _I('op',text='Operation',choices=[
            '+ (Union)',
            '- (Difference)',
            '* Intersection',
            'Intersection Curve',
            ],itemtype='vradio'),
          _I('verbose',False,text='Show stats'),
        ])
    
    if not res:
        return
    op = res['op'][0]
    verbose = res['verbose']
    if op in '+-*':
        I = F.boolean(G,op,verbose=verbose)
    else:
        I = F.intersection(G,verbose=verbose)
    clear()
    draw(I)

    if op in '+-*':
        return

    else:
        if ack('Create a surface inside the curve ?'):
            I = I.toMesh()
            e = connectedLineElems(I.elems)
            I = Mesh(I.coords,connectedLineElems(I.elems)[0])
            clear()
            draw(I,color=red,linewidth=3)
            S = fillBorder(I,method='planar')
            draw(S)
    def getWireAxes(self):
        """Return the wire axes as curves.

        The return value is two lists of curves (PolyLines), representing the
        individual wire axes for each wire direction.
        """
        import connectivity
        M = self.F.toMesh()
        ML = [ M.withProp(i) for i in [1,3] ]
        wires = [ connectivity.connectedLineElems(Mi.elems) for Mi in ML ]
        wireaxes = [ [ Formex(M.coords[wi]).toCurve() for wi in wiresi ] for wiresi in wires ]
        return wireaxes
Beispiel #4
0
    def getWireAxes(self):
        """Return the wire axes as curves.

        The return value is two lists of curves (PolyLines), representing the
        individual wire axes for each wire direction.
        """
        import connectivity
        M = self.F.toMesh()
        ML = [M.withProp(i) for i in [1, 3]]
        wires = [connectivity.connectedLineElems(Mi.elems) for Mi in ML]
        wireaxes = [[Formex(M.coords[wi]).toCurve() for wi in wiresi]
                    for wiresi in wires]
        return wireaxes
Beispiel #5
0
def meshToPolyLine2(m2):
    "Convert a 2-plex mesh with ordered segments to a PolyLine."""
    'order line elements from boundary points'
    # Remove degenerate and doubles
    m2=m2.fuse().compact()
    ##m2 = Mesh(m2.coords,m2.elems.removeDegenerate().removeDoubles())
    m2 = Mesh(m2.coords,m2.elems.removeDegenerate().removeDuplicate())
    # Split in connected loops
    parts = connectedLineElems(m2.elems)
    prop = concatenate([ [i]*p.nelems() for i,p in enumerate(parts)])
    elems = concatenate(parts,axis=0)
    m2= Mesh(m2.coords,elems,prop=prop)
    pts = m2.elems[:,0]
    if m2.elems[-1,-1] != m2.elems[0,0]:
        pts = concatenate([pts,m2.elems[-1:,-1]])
        return PolyLine(m2.coords[pts], closed=False)
    else: return PolyLine(m2.coords[pts], closed=True)
Beispiel #6
0
def meshToPolyLine2(m2):
    "Convert a 2-plex mesh with ordered segments to a PolyLine." ""
    'order line elements from boundary points'
    # Remove degenerate and doubles
    m2 = m2.fuse().compact()
    ##m2 = Mesh(m2.coords,m2.elems.removeDegenerate().removeDoubles())
    m2 = Mesh(m2.coords, m2.elems.removeDegenerate().removeDuplicate())
    # Split in connected loops
    parts = connectedLineElems(m2.elems)
    prop = concatenate([[i] * p.nelems() for i, p in enumerate(parts)])
    elems = concatenate(parts, axis=0)
    m2 = Mesh(m2.coords, elems, prop=prop)
    pts = m2.elems[:, 0]
    if m2.elems[-1, -1] != m2.elems[0, 0]:
        pts = concatenate([pts, m2.elems[-1:, -1]])
        return PolyLine(m2.coords[pts], closed=False)
    else:
        return PolyLine(m2.coords[pts], closed=True)
Beispiel #7
0
def close_loop_example():
    # one more example, originally not a closed loop curve
    F = Formex('l:11').replic(2,1,1) + Formex('l:2').replic(2,2,0)
    M = F.toMesh()
    draw(M,color='green')
    drawNumbers(M,color=red)
    drawNumbers(M.coords,color=blue)

    print("Original elements:",M.elems)
    conn = connectivity.connectedLineElems(M.elems)
    if len(conn) > 1:
        message("This curve is not a closed circumference")
        return None
    
    sorted = conn[0]
    print("Sorted elements:",sorted)

    showInfo('Click to continue')
    clear()
    M = Mesh(M.coords,sorted)
    drawNumbers(M)
    return M.toFormex()
def fillHoles():
    """Fill the holes in the selected surface."""
    from connectivity import connectedLineElems

    S = selection.check(single=True)
    if S:
        border_elems = S.getEdges()[S.borderEdges()]
        if border_elems.size != 0:
            # partition borders
            print (border_elems)
            border_elems = connectedLineElems(border_elems)
            print (border_elems)

            # draw borders in new viewport
            R = pf.canvas.camera.getRot()
            P = pf.canvas.camera.perspective
            layout(2)
            viewport(1)
            pf.canvas.camera.rot = R
            toolbar.setPerspective(P)
            for i, elems in enumerate(border_elems):
                draw(Formex(S.coords[elems], i))
            zoomAll()
            # pick borders for which the hole must be filled
            info("PICK HOLES WHICH HAVE TO BE FILLED.")
            picked = pick(mode="actor")
            layout(1)
            # fill the holes
            triangles = empty((0, 3), dtype=int)
            if picked.has_key(-1):
                for i in picked[-1]:
                    triangles = row_stack([triangles, fillHole(S.coords, border_elems[int(i)])])
                T = TriSurface(S.coords, triangles)
                S.append(T)
                draw(T, color="red", bbox=None)
            else:
                warning("No borders were picked.")
        else:
            warning("The surface %s does not have a border." % selection[0])
Beispiel #9
0
def close_loop_example():
    # one more example, originally not a closed loop curve
    F = Formex('l:11').replic(2, 1, 1) + Formex('l:2').replic(2, 2, 0)
    M = F.toMesh()
    draw(M, color='green')
    drawNumbers(M, color=red)
    drawNumbers(M.coords, color=blue)

    print("Original elements:", M.elems)
    conn = connectivity.connectedLineElems(M.elems)
    if len(conn) > 1:
        message("This curve is not a closed circumference")
        return None

    sorted = conn[0]
    print("Sorted elements:", sorted)

    showInfo('Click to continue')
    clear()
    M = Mesh(M.coords, sorted)
    drawNumbers(M)
    return M.toFormex()