Ejemplo n.º 1
0
def travelRight(xr=0.1, N=100):
    import KCore.Vector as Vector
    posCam = getState('posCam')
    posEye = getState('posEye')
    dirCam = getState('dirCam')
    d1 = Vector.sub(posEye, posCam)
    R = Vector.norm(d1)
    L = 2. * 3.14 * R * xr * 0.5
    d2 = Vector.cross(d1, dirCam)
    d2 = Vector.normalize(d2)
    d2 = Vector.mul(L, d2)
    P2 = Vector.sub(posCam, d2)
    d3 = Vector.sub(posEye, P2)
    d4 = Vector.cross(d3, dirCam)
    d4 = Vector.normalize(d4)
    d4 = Vector.mul(L, d4)
    P3 = Vector.sub(P2, d4)
    checkPoints = [posCam, tuple(P2), tuple(P3)]
    moveCamera(checkPoints, N=N)
Ejemplo n.º 2
0
def writeCassiopeeLamps(file):
    type = VARS[2].get()

    eye = CPlot.getState('posEye')
    cam = CPlot.getState('posCam')
    dir = CPlot.getState('dirCam')
    d = Vector.sub(eye, cam)
    n = Vector.cross(d, dir)
    dir = Vector.normalize(dir)
    n = Vector.normalize(n)
    norm = Vector.norm(d)
    d = Vector.normalize(d)
    n = Vector.sub(n, dir)
    n = Vector.add(n, d)
    n = Vector.mul(0.4 * norm, n)
    pos = Vector.sub(eye, n)

    if type == 'Interior':
        pass
        ##         # distant light
        ##         file.write('AttributeBegin\n')
        ##         file.write('LightGroup "default"\n')
        ##         file.write('Exterior "world"\n')
        ##         file.write('LightSource "distant"\n')
        ##         file.write('      "point from" ['+
        ##                    str(pos[0])+' '+str(pos[1])+' '+str(pos[2])+
        ##                    '] "point to" ['+
        ##                    str(eye[0])+' '+str(eye[1])+' '+str(eye[2])+']\n')
        ##         file.write('      "color L" [5 5 5]\n')
        ##         file.write('AttributeEnd\n')

    else:  # Exterior
        # sun/sky
        sundir = Vector.sub(pos, eye)
        sundir = Vector.normalize(sundir)
        file.write('AttributeBegin\n')
        file.write('LightGroup "default"\n')
        file.write('Exterior "world"\n')
        file.write('LightSource "sunsky"\n')
        file.write('      "vector sundir" [' + str(sundir[0]) + ' ' +
                   str(sundir[1]) + ' ' + str(sundir[2]) + ']\n')
        file.write('      "float turbidity" [2.0]\n')
        file.write('      "float gain" [0.005]\n')
        file.write('AttributeEnd\n')
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def replaceText(event=None):
    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 nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    CTK.saveTree()
    # Recupere l'OBB de la selection
    Z = []
    dels = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        Z.append(CTK.t[2][nob][2][noz])
        dels.append(CTK.t[2][nob][0] + Internal.SEP1 +
                    CTK.t[2][nob][2][noz][0])
    nob0 = CTK.Nb[nzs[0]] + 1
    try:
        a = T.join(Z)
    except:
        a = Z[0]
    OBB = G.BB(a, method='OBB')

    P0 = C.getValue(OBB, 'GridCoordinates', 0)
    P1 = C.getValue(OBB, 'GridCoordinates', 1)
    P2 = C.getValue(OBB, 'GridCoordinates', 2)
    P3 = C.getValue(OBB, 'GridCoordinates', 4)
    v1 = Vector.sub(P1, P0)
    n1 = Vector.norm(v1)
    v2 = Vector.sub(P2, P0)
    n2 = Vector.norm(v2)
    v3 = Vector.sub(P3, P0)
    n3 = Vector.norm(v3)
    v1p = v1
    v2p = v2
    v3p = v3
    if abs(n1) < 1.e-12:
        v1 = Vector.cross(v2, v3)
        v1p = (0., 0., 0.)
    elif abs(n2) < 1.e-12:
        v2 = Vector.cross(v1, v3)
        v2p = (0., 0., 0.)
    elif abs(n3) < 1.e-12:
        v3 = Vector.cross(v2, v3)
        v3p = (0., 0., 0.)

    # Essaie de matcher les vecteur sur la vue p1,p2,p3
    # On suppose que dirCam doit etre e2, ...
    posCam = CPlot.getState('posCam')
    posEye = CPlot.getState('posEye')
    dirCam = CPlot.getState('dirCam')
    e2 = dirCam
    e3 = Vector.sub(posCam, posEye)
    e1 = Vector.cross(e2, e3)

    f1 = None
    f2 = None
    f3 = None
    Pt = P0
    s1 = Vector.dot(e1, v1)
    s2 = Vector.dot(e1, v2)
    s3 = Vector.dot(e1, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f1 = v1
        else:
            f1 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f1 = v2
        else:
            f1 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f1 = v3
        else:
            f1 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    s1 = Vector.dot(e2, v1)
    s2 = Vector.dot(e2, v2)
    s3 = Vector.dot(e2, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f2 = v1
        else:
            f2 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f2 = v2
        else:
            f2 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f2 = v3
        else:
            f2 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    s1 = Vector.dot(e3, v1)
    s2 = Vector.dot(e3, v2)
    s3 = Vector.dot(e3, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f3 = v1
        else:
            f3 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f3 = v2
        else:
            f3 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f3 = v3
        else:
            f3 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    (x0, y0, z0) = Pt
    n2 = Vector.norm(f2)

    # Cree le texte
    text = VARS[0].get()
    type = VARS[1].get()
    font = VARS[3].get()

    smoothness = VARS[2].get()
    smooth = 0
    if smoothness == 'Regular': smooth = 0
    elif smoothness == 'Smooth': smooth = 2
    elif smoothness == 'Very smooth': smooth = 4
    if type == '3D': a = D.text3D(text, smooth=smooth, font=font)
    elif type == '2D': a = D.text2D(text, smooth=smooth, font=font)
    elif type == '1D':
        a = D.text1D(text, smooth=smooth, font=font)
        a = C.convertArray2Tetra(a)
        a = T.join(a)
    BB = G.bbox(a)
    h2 = BB[4] - BB[1]

    # Scale, positionne le texte
    factor = n2 / h2
    a = T.homothety(a, (BB[0], BB[1], BB[2]), factor)
    a = T.translate(a, (x0 - BB[0], y0 - BB[1], z0 - BB[2]))
    a = T.rotate(a, (x0, y0, z0), ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((f1, f2, f3)))

    CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs)
    CPlot.delete(dels)
    CTK.add(CTK.t, nob0, -1, a)
    #C._fillMissingVariables(CTK.t)
    CTK.TXT.insert('START', 'Text replaced.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()