def createPoint(event=None): point = CTK.varsFromWidget(VARS[0].get(), type=1) if len(point) != 3: CTK.TXT.insert('START', 'Point coords are incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'POINTS', 1) base = Internal.getNodesFromName1(CTK.t, 'POINTS') base = base[0] nob = C.getNobOfBase(base, CTK.t) a = D.point((point[0], point[1], point[2])) CTK.add(CTK.t, nob, -1, a) CTK.TXT.insert('START', 'Point ' + VARS[0].get() + ' created.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - gapfixer (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test a = D.circle((0, 0, 0), 1, N=100) a = C.convertArray2Tetra(a) a = G.close(a) b = G.cart((-2., -2., 0.), (0.1, 0.1, 1.), (50, 50, 1)) a = C.initVars(a, 'F', 1.) a = C.initVars(a, 'centers:G', 2.) a1 = G.gapfixer(a, b) test.testT(a1, 1) hp = D.point((0.5, 0.5, 0.)) a2 = G.gapfixer(a, b, hp, refine=0) test.testT(a2, 2)
# - point (pyTree) - import Geom.PyTree as D import Converter.PyTree as C a = D.point((0, 0, 0)) b = D.point((1, 1, 1)) C.convertPyTree2File([a, b], "out.cgns")
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)
# - point (pyTree) - import Geom.PyTree as D import Converter.PyTree as C a = D.point((0, 0, 0)) C.convertPyTree2File(a, "out.cgns")
# - identifyNodes (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Geom.PyTree as D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 10)) b = G.cart((12, 0, 0), (1, 1, 1), (10, 10, 10)) hook, indir = C.createGlobalHook([a, b], function='nodes', indir=1) offset = [0, C.getNPts(a), C.getNPts(b)] f = D.point((13, 3, 3)) nodes = C.identifyNodes(hook, f) ind = nodes[0] print('Le premier point de f a pour indice', ind - offset[indir[ind]], 'sur la zone', indir[ind]) #>> Le premier point de f a pour indice 332 sur la zone 1