コード例 #1
0
def TRITFI():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nzs = CPlot.getSelectedZones()
    if len(nzs) == 0:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    surf = getSurfaces()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        z = C.convertBAR2Struct(z)
        zones.append(z)

    if len(zones) != 3:
        CTK.TXT.insert('START', 'TRI TFI takes 3 contours.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    coords1 = C.getFields(Internal.__GridCoordinates__, zones[0])[0]
    coords2 = C.getFields(Internal.__GridCoordinates__, zones[1])[0]
    coords3 = C.getFields(Internal.__GridCoordinates__, zones[2])[0]

    [m1, m2, m3] = trimesh(coords1, coords2, coords3)
    if (m1 == 0):
        CTK.TXT.insert('START', m2 + '\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    m1 = C.convertArrays2ZoneNode('TFI1', [m1])
    m2 = C.convertArrays2ZoneNode('TFI2', [m2])
    m3 = C.convertArrays2ZoneNode('TFI3', [m3])

    if surf != []:
        m1 = T.projectOrthoSmooth(m1, surf)
        m2 = T.projectOrthoSmooth(m2, surf)
        m3 = T.projectOrthoSmooth(m3, surf)

    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
    bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
    nob = C.getNobOfBase(bases[0], CTK.t)
    for i in [m1, m2, m3]:
        CTK.add(CTK.t, nob, -1, i)
    CTK.TXT.insert('START', 'TRI-TFI mesh created.\n')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #2
0
def drawCubic(npts):
    global CURRENTZONE; global CURRENTPOLYLINE
    if (CTK.t == []): return
    w = WIDGETS['draw']
    if (CTK.__BUSY__ == False):
        CPlot.unselectAllZones()
        CTK.saveTree()
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while (CTK.__BUSY__ == True):
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                CPlot.unselectAllZones()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                CURRENTPOLYLINE.append((l[0],l[1],l[2]))
                if (CURRENTZONE == None):
                    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
                    base = Internal.getNodeFromName1(CTK.t, 'CONTOURS')
                    nob = C.getNobOfBase(base, CTK.t)
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.add(CTK.t, nob, -1, a)
                    ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
                    noz = ret[1]
                else:
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.replace(CTK.t, nob, noz, a)
                (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                CTK.TKTREE.updateApp()
                CPlot.render()
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
       a = D.polyline(CURRENTPOLYLINE)
       d = G.cart( (0,0,0), (1./(npts-1),1,1), (npts,1,1) )
       a = G.map(a, d)
       surfaces = getSurfaces()
       if (surfaces != []): a = T.projectOrthoSmooth(a, surfaces)
       nob = C.getNobOfBase(ret[0], CTK.t)
       CTK.replace(CTK.t, nob, ret[1], a)
       #C._fillMissingVariables(CTK.t)
       (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
       CTK.TKTREE.updateApp()
       CPlot.render()
       CURRENTZONE = None
       CURRENTPOLYLINE = []
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
コード例 #3
0
def MONO2TFI():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nzs = CPlot.getSelectedZones()
    if len(nzs) == 0:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    surf = getSurfaces()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        z = C.convertBAR2Struct(z)
        zones.append(z)

    if len(zones) != 2:
        CTK.TXT.insert('START', 'MONO2 TFI takes 2 contours.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    coords1 = C.getFields(Internal.__GridCoordinates__, zones[0])[0]
    coords2 = C.getFields(Internal.__GridCoordinates__, zones[1])[0]

    [m] = mono2mesh(coords1, coords2)
    if isinstance(m, str):
        CTK.TXT.insert('START', m + '\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    m = C.convertArrays2ZoneNode('TFI', [m])
    if surf != []: m = T.projectOrthoSmooth(m, surf)

    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
    bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
    nob = C.getNobOfBase(bases[0], CTK.t)
    CTK.add(CTK.t, nob, -1, m)
    CTK.TXT.insert('START', 'HO-TFI mesh created.\n')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #4
0
def drawLine(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    prev = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(WIDGETS['draw'])
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while l == []:
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                WIDGETS['draw'].update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__:
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (prev != l):
                    line = D.line(prev, l, npts)
                    if surfaces != []: line = T.projectOrthoSmooth(line, surfaces)
                    CTK.add(CTK.t, nob, -1, line)
                    CTK.TXT.insert('START', 'Line created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(WIDGETS['draw'])
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['draw'])
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(WIDGETS['draw'])
       CPlot.setState(cursor=0)
    return
コード例 #5
0
def TFI():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nzs = CPlot.getSelectedZones()
    if len(nzs) == 0:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    surf = getSurfaces()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        dim = Internal.getZoneDim(z)
        if dim[3] == 'BAR':
            zp = C.convertBAR2Struct(z)
            zones.append(zp)
        else:
            zones.append(z)

    try:
        CTK.saveTree()
        mesh = G.TFI(zones)
        if surf != []: mesh = T.projectOrthoSmooth(mesh, surf)
        CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
        bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
        nob = C.getNobOfBase(bases[0], CTK.t)
        CTK.add(CTK.t, nob, -1, mesh)
        CTK.TXT.insert('START', 'TFI mesh created.\n')
        #C._fillMissingVariables(CTK.t)
        (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
        CTK.TKTREE.updateApp()
        CPlot.render()
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: TFI')
        CTK.TXT.insert('START', 'TFI mesh failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
コード例 #6
0
def drawFreeHand():
    global CURRENTZONE; global CURRENTPOLYLINE; global ALLZONES
    w = WIDGETS['draw']
    prev = []; first = []
    if CTK.__BUSY__ == False:
        CPlot.unselectAllZones()
        CTK.saveTree()
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        buttonState = 0
        while CTK.__BUSY__ == True:
            if prev == []: # first point
                l = []
                while l == []:
                    l = CPlot.getActivePoint()
                    if l != []: prev = l; first = l
                    time.sleep(CPlot.__timeStep__)
                    w.update()
                    if CTK.__BUSY__ == False: break
            else: # next points
                diff = -1.
                while (diff < 1.e-10):
                    (buttonState,x,y,z) = CPlot.getMouseState()
                    l = (x,y,z)
                    diff = Vector.norm2(Vector.sub(l,prev))
                    diff1 = Vector.norm2(Vector.sub(l,first))
                    if (diff1 < 1.e-10): l = first
                    if (buttonState == 5): break
                    time.sleep(CPlot.__timeStep__)
                    w.update()
                    if (CTK.__BUSY__ == False): break
                    
            prev = l
            CPlot.unselectAllZones()
            if (buttonState == 5): # button released
                ALLZONES.append(CURRENTZONE)
                CURRENTZONE = None; prev = []; first = []
                CURRENTPOLYLINE = []
                CTK.TKTREE.updateApp()
                
            if (CTK.__BUSY__ == True and buttonState != 5):
                CURRENTPOLYLINE.append((l[0],l[1],l[2]))
                if (CURRENTZONE == None):
                    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
                    base = Internal.getNodeFromName1(CTK.t, 'CONTOURS')
                    nob = C.getNobOfBase(base, CTK.t)
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.add(CTK.t, nob, -1, a)
                    ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
                    noz = ret[1]
                else:
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.replace(CTK.t, nob, noz, a)
                (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                CPlot.render()
            buttonState = 0
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       surfaces = getSurfaces()
       if (surfaces != []):
           if (CURRENTZONE != None): ALLZONES += [CURRENTZONE]
           for s in ALLZONES:
               ret = Internal.getParentOfNode(CTK.t, s)
               nob = C.getNobOfBase(ret[0], CTK.t)
               a = T.projectOrthoSmooth(s, surfaces)
               noz = ret[1]
               CTK.replace(CTK.t, nob, noz, a)
       #C._fillMissingVariables(CTK.t)
       (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
       CTK.TKTREE.updateApp()
       CPlot.render()
       CURRENTZONE = None; ALLZONES = []
       CURRENTPOLYLINE = []
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
コード例 #7
0
def drawRectangle(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click left/lower corner...\n')
    w = WIDGETS['draw']
    prev = []; second = []
    if (CTK.__BUSY__ == False):
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while (CTK.__BUSY__ == True):
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if (prev == []):
                    prev = l
                    CTK.TXT.insert('START', 'Click right/up corner...\n')
                elif (prev != l):
                    e1,e2 = getVectorsFromCanvas()
                    e1n = Vector.norm(e1)
                    e2n = Vector.norm(e2)
                    if (e2n > e1n): e1 = e2
                    P1 = l; P2 = prev
                    P1P2 = Vector.sub(P2, P1)
                    P1P2n = Vector.norm(P1P2)
                    Q = Vector.norm(Vector.cross(e1, P1P2))
                    L = math.sqrt( P1P2n*P1P2n - Q*Q )
                    sign = Vector.dot(e1, P1P2)
                    if (sign > 0): e1 = Vector.mul(L, e1)
                    else: e1 = Vector.mul(-L, e1)
                    P3 = Vector.add(P1, e1)
                    P4 = Vector.sub(P2, e1)
                    l1 = D.line(P1, P3, npts)
                    l2 = D.line(P3, P2, npts)
                    l3 = D.line(P2, P4, npts)
                    l4 = D.line(P4, P1, npts)
                    rect = T.join([l1,l2,l3,l4])
                    if (surfaces != []):
                        rect = T.projectOrthoSmooth(rect, surfaces)
                    CTK.add(CTK.t, nob, -1, rect)
                    CTK.TXT.insert('START', 'Rectangle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
コード例 #8
0
def drawArc(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    w = WIDGETS['draw']
    prev = []; second = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if (prev == []):
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (second == [] and prev != l):
                    second = l
                    CTK.TXT.insert('START', 'Click third point...\n')
                elif (prev != l and second != l):
                    x1 = l[0]; y1 = l[1]; z1 = l[2]
                    x2 = prev[0]; y2 = prev[1]; z2 = prev[2]
                    x3 = second[0]; y3 = second[1]; z3 = second[2]
                    xa = x2 - x1; ya = y2 - y1; za = z2 - z1
                    xb = x3 - x1; yb = y3 - y1; zb = z3 - z1
                    xc = x3 - x2; yc = y3 - y2; zc = z3 - z2
                    a2 = xa*xa + ya*ya + za*za
                    b2 = xb*xb + yb*yb + zb*zb
                    c2 = xc*xc + yc*yc + zc*zc
                    A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2
                    R = math.sqrt( a2*b2*c2 / A )
                    
                    nx = ya*zb - za*yb
                    ny = za*xb - xa*zb
                    nz = xa*yb - ya*xb
                    tx = ya*nz - za*ny
                    ty = za*nx - xa*nz
                    tz = xa*ny - ya*nx
                    norm = tx*tx + ty*ty + tz*tz
                    normi = 1./math.sqrt(norm)
                    tx = tx*normi; ty = ty*normi; tz = tz*normi;
                    alpha = R*R - (xa*xa+ya*ya+za*za)*0.25
                    alpha = math.sqrt(alpha)
                    center = [0,0,0]
                    center[0] = 0.5*(x1+x2) + alpha*tx
                    center[1] = 0.5*(y1+y2) + alpha*ty
                    center[2] = 0.5*(z1+z2) + alpha*tz
                    dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3
                    l = dx3*dx3 + dy3*dy3 + dz3*dz3
                    if (abs(l - R*R) > 1.e-10):
                        center[0] = 0.5*(x1+x2) - alpha*tx
                        center[1] = 0.5*(y1+y2) - alpha*ty
                        center[2] = 0.5*(z1+z2) - alpha*tz
                        dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3
                        l = dx3*dx3 + dy3*dy3 + dz3*dz3
                    
                    e1 = [x1-center[0], y1-center[1], z1-center[2]]
                    e2 = [x2-center[0], y2-center[1], z2-center[2]]
                    e3 = Vector.cross(e1, e2)
                    e4 = Vector.cross(e1, e3)

                    # Images des pts dans le plan xyz 
                    pt1 = D.point((x1,y1,z1))
                    pt2 = D.point((x2,y2,z2))
                    pt3 = D.point((x3,y3,z3))
                    pt1 = T.rotate(pt1,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)) )
                    pt2 = T.rotate(pt2,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)))
                    pt3 = T.rotate(pt3,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)))
                    xp1 = C.getValue(pt1, 'CoordinateX', 0)
                    yp1 = C.getValue(pt1, 'CoordinateY', 0)
                    zp1 = C.getValue(pt1, 'CoordinateZ', 0)
                    xp2 = C.getValue(pt2, 'CoordinateX', 0)
                    yp2 = C.getValue(pt2, 'CoordinateY', 0)
                    zp2 = C.getValue(pt2, 'CoordinateZ', 0)
                    xp3 = C.getValue(pt3, 'CoordinateX', 0)
                    yp3 = C.getValue(pt3, 'CoordinateY', 0)
                    zp3 = C.getValue(pt3, 'CoordinateZ', 0)
                    
                    dx1 = (xp1-center[0])/R; dy1 = (yp1-center[1])/R
                    if dx1 > 1.: dx1 = 1.
                    if dx1 < -1.: dx1 = -1.
                    if dy1 > 0: teta1 = math.acos(dx1)
                    else: teta1 = 2*math.pi - math.acos(dx1)
                    teta1 = teta1*180./math.pi; teta1 = 360.

                    dx2 = (xp2-center[0])/R; dy2 = (yp2-center[1])/R
                    if dx2 > 1.: dx2 = 1.
                    if dx2 < -1.: dx2 = -1.
                    if dy2 > 0: teta2 = math.acos(dx2)
                    else: teta2 = 2*math.pi - math.acos(dx2)
                    teta2 = teta2*180./math.pi

                    dx3 = (xp3-center[0])/R; dy3 = (yp3-center[1])/R
                    if dx3 > 1.: dx3 = 1.
                    if dx3 < -1.: dx3 = -1.
                    if dy3 > 0: teta3 = math.acos(dx3)
                    else: teta3 = 2*math.pi - math.acos(dx3)
                    teta3 = teta3*180./math.pi

                    if teta3 > teta2: teta1 = 360.
                    else: teta1 = 0.

                    circle = D.circle((center[0],center[1],center[2]), R, 
                                      tetas=teta2, tetae=teta1, N=npts)
                    circle = T.rotate(circle,
                                      (center[0], center[1], center[2]),
                                      ((1,0,0), (0,1,0), (0,0,1)),
                                      (e1, e4, e3))
                    if surfaces != []:
                        circle = T.projectOrthoSmooth(circle, surfaces)
                    CTK.add(CTK.t, nob, -1, circle)
                    CTK.TXT.insert('START', 'Circle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
コード例 #9
0
def drawCircle(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    w = WIDGETS['draw']
    prev = []; second = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (second == [] and prev != l):
                    second = l
                    CTK.TXT.insert('START', 'Click third point...\n')
                elif (prev != l and second != l):
                    x1 = l[0]; y1 = l[1]; z1 = l[2]
                    x2 = prev[0]; y2 = prev[1]; z2 = prev[2]
                    x3 = second[0]; y3 = second[1]; z3 = second[2]
                    xa = x2 - x1; ya = y2 - y1; za = z2 - z1
                    xb = x3 - x1; yb = y3 - y1; zb = z3 - z1
                    xc = x3 - x2; yc = y3 - y2; zc = z3 - z2
                    a2 = xa*xa + ya*ya + za*za
                    b2 = xb*xb + yb*yb + zb*zb
                    c2 = xc*xc + yc*yc + zc*zc
                    A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2
                    R = math.sqrt( a2*b2*c2 / A )
                    
                    nx = ya*zb - za*yb
                    ny = za*xb - xa*zb
                    nz = xa*yb - ya*xb
                    tx = ya*nz - za*ny
                    ty = za*nx - xa*nz
                    tz = xa*ny - ya*nx
                    norm = tx*tx + ty*ty + tz*tz
                    normi = 1./math.sqrt(norm)
                    tx = tx*normi; ty = ty*normi; tz = tz*normi;
                    alpha = R*R - (xa*xa+ya*ya+za*za)*0.25
                    alpha = math.sqrt(alpha)
                    center = [0,0,0]
                    center[0] = 0.5*(x1+x2) + alpha*tx
                    center[1] = 0.5*(y1+y2) + alpha*ty
                    center[2] = 0.5*(z1+z2) + alpha*tz
                    l = (center[0]-x3)*(center[0]-x3) + \
                        (center[1]-y3)*(center[1]-y3) + \
                        (center[2]-z3)*(center[2]-z3)
                    if (abs(l - R*R) > 1.e-10):
                        center[0] = 0.5*(x1+x2) - alpha*tx
                        center[1] = 0.5*(y1+y2) - alpha*ty
                        center[2] = 0.5*(z1+z2) - alpha*tz
                        l = (center[0]-x3)*(center[0]-x3) + \
                        (center[1]-y3)*(center[1]-y3) + \
                        (center[2]-z3)*(center[2]-z3)
                    circle = D.circle( (center[0],center[1],center[2]), R, N=npts)
                    e1 = [x1-center[0], y1-center[1], z1-center[2]]
                    e2 = [x2-center[0], y2-center[1], z2-center[2]]
                    e3 = Vector.cross(e1, e2)
                    e4 = Vector.cross(e1, e3)
                    circle = T.rotate(circle,
                                      (center[0], center[1], center[2]),
                                      ((1,0,0), (0,1,0), (0,0,1)),
                                      (e1, e4, e3))
                    if (surfaces != []):
                        circle = T.projectOrthoSmooth(circle, surfaces)
                    CTK.add(CTK.t, nob, -1, circle)
                    CTK.TXT.insert('START', 'Circle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
コード例 #10
0
def HOTFI():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nzs = CPlot.getSelectedZones()
    if len(nzs) == 0:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    surf = getSurfaces()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        z = C.convertBAR2Struct(z)
        zones.append(z)

    if len(zones) != 2:
        CTK.TXT.insert('START', 'HO TFI takes 2 contours.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    weight = CTK.varsFromWidget(VARS[1].get(), type=1)
    weight = weight[0]

    # Nombre de pts (tous les 2 pairs ou tous les 2 impairs)
    Nt1 = Internal.getZoneDim(zones[0])[1]
    Nt2 = Internal.getZoneDim(zones[1])[1]
    if Nt1 / 2 - Nt1 * 0.5 == 0 and Nt2 / 2 - Nt2 * 0.5 != 0:
        CTK.TXT.insert(
            'START',
            'Number of points of countours must be all odd or all even.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    if Nt1 / 2 - Nt1 * 0.5 != 0 and Nt2 / 2 - Nt2 * 0.5 == 0:
        CTK.TXT.insert(
            'START',
            'Number of points of countours must be all odd or all even.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    coords1 = C.getFields(Internal.__GridCoordinates__, zones[0])[0]
    coords2 = C.getFields(Internal.__GridCoordinates__, zones[1])[0]

    optWeight = 0
    optOffset = 0
    optScore = 1.e6
    Nt2 = coords2[2]
    for j in range(-Nt2 // 8, Nt2 // 8):
        for i in range(2, 10):
            try:
                [m, m1, m2, m3] = TFIs.TFIHalfO__(coords1, coords2, i, j)
                score = quality([m, m1, m2, m3])
                if (score < optScore):
                    optWeight = i
                    optScore = score
                    optOffset = j
            except:
                pass
    print('resulting score=%g' % optScore)
    [m, m1, m2, m3] = TFIs.TFIHalfO__(coords1, coords2, optWeight, optOffset)

    m = C.convertArrays2ZoneNode('TFI1', [m])
    m1 = C.convertArrays2ZoneNode('TFI2', [m1])
    m2 = C.convertArrays2ZoneNode('TFI3', [m2])
    m3 = C.convertArrays2ZoneNode('TFI4', [m3])

    if surf != []:
        m = T.projectOrthoSmooth(m, surf)
        m1 = T.projectOrthoSmooth(m1, surf)
        m2 = T.projectOrthoSmooth(m2, surf)
        m3 = T.projectOrthoSmooth(m3, surf)

    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
    bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
    nob = C.getNobOfBase(bases[0], CTK.t)
    for i in [m, m1, m2, m3]:
        CTK.add(CTK.t, nob, -1, i)
    CTK.TXT.insert('START', 'HO-TFI mesh created.\n')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #11
0
def OTFI():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nzs = CPlot.getSelectedZones()
    if len(nzs) == 0:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    surf = getSurfaces()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        z = C.convertArray2Hexa(z)
        zones.append(z)
    zones = T.join(zones)
    zones = G.close(zones)
    a = C.convertBAR2Struct(z)

    weight = CTK.varsFromWidget(VARS[1].get(), type=1)
    weight = weight[0]

    # Nombre de pts
    Nt = Internal.getZoneDim(a)[1]
    if Nt / 2 - Nt * 0.5 == 0:
        CTK.TXT.insert('START', 'Number of points of countour must be odd.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    coords = C.getFields(Internal.__GridCoordinates__, a)[0]

    optWeight = 0
    optOffset = 0
    optScore = 1.e6
    Nt = coords[2]
    for j in range(-Nt // 4, Nt // 4 + 1):
        for i in range(3, 10):
            try:
                [m, m1, m2, m3, m4] = TFIs.TFIO__(coords, i, j)
                score = quality([m, m1, m2, m3])
                if score < optScore:
                    optWeight = i
                    optOffset = j
                    optScore = score
            except:
                pass
    print('resulting weight=%g, offset=%g.' % (optWeight, optOffset))
    print('resulting score=%g.' % optScore)
    [m, m1, m2, m3, m4] = TFIs.TFIO__(coords, optWeight, optOffset)

    m = C.convertArrays2ZoneNode('TFI1', [m])
    m1 = C.convertArrays2ZoneNode('TFI2', [m1])
    m2 = C.convertArrays2ZoneNode('TFI3', [m2])
    m3 = C.convertArrays2ZoneNode('TFI4', [m3])
    m4 = C.convertArrays2ZoneNode('TFI5', [m4])

    if surf != []:
        m = T.projectOrtho(m, surf)
        m1 = T.projectOrthoSmooth(m1, surf)
        m2 = T.projectOrthoSmooth(m2, surf)
        m3 = T.projectOrthoSmooth(m3, surf)
        m4 = T.projectOrthoSmooth(m4, surf)

    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
    bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
    nob = C.getNobOfBase(bases[0], CTK.t)
    for i in [m, m1, m2, m3, m4]:
        CTK.add(CTK.t, nob, -1, i)
    CTK.TXT.insert('START', 'O-TFI mesh created.\n')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #12
0
# - projectOrthoSmooth (pyTree) -
import Geom.PyTree as D
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

a = D.sphere((0, 0, 0), 1., 30)
b = G.cart((-0.5, -0.5, -1.5), (0.05, 0.05, 0.1), (20, 20, 1))
c = T.projectOrthoSmooth(b, [a], niter=2)
test.testT(c, 1)