def getValueFromMouse(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return var = VARS[0].get() if var == 'CoordinateX': point = CPlot.getActivePoint() val = point[0] elif var == 'CoordinateY': point = CPlot.getActivePoint() val = point[1] elif var == 'CoordinateZ': point = CPlot.getActivePoint() val = point[2] else: val = None; c = 0 for i in WIDGETS['field']['values']: if var == i: break c += 1 c = c-3 # a cause des coord values = CPlot.getActivePointF() if values != []: val = values[c] if val != None: VARS[1].set(str(val))
def streamRibbon(): if CTK.t == []: return npts = CTK.varsFromWidget(VARS[0].get(), type=2) if len(npts) != 1: CTK.TXT.insert('START', 'Number of points in stream incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return npts = npts[0] v1 = VARS[1].get() v2 = VARS[2].get() v3 = VARS[3].get() CTK.TXT.insert('START', 'Click to select starting point...\n') l = [] while (l == []): l = CPlot.getActivePoint() time.sleep(0.1) print('Ribbon: starting point %d' % l) CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'STREAMS', 2) b = Internal.getNodesFromName1(CTK.t, 'STREAMS') nob = C.getNobOfBase(b[0], CTK.t) try: stream = P.streamRibbon(CTK.t, (l[0], l[1], l[2]), (0, 0, 0.01), [v1, v2, v3], N=npts) CTK.add(CTK.t, nob, -1, stream) CTK.TXT.insert('START', 'Stream ribbon created.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: streamRibbon') CTK.TXT.insert('START', 'Stream ribbon fails.\n') CTK.TXT.insert('START', 'Error: ', 'Error') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
def measure(): if CTK.t == []: return prev = [] w = WIDGETS['button'] if CTK.__BUSY__ == False: CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while CTK.__BUSY__: CPlot.unselectAllZones() 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 prev != l: dist = (l[0]-prev[0])*(l[0]-prev[0])+\ (l[1]-prev[1])*(l[1]-prev[1])+\ (l[2]-prev[2])*(l[2]-prev[2]) dist = math.sqrt(dist) CTK.TXT.insert('START', 'dist= ' + str(dist) + '\n') time.sleep(CPlot.__timeStep__) prev = [] CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=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)
def getPointCoordinates(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return point = CPlot.getActivePoint() if point != []: VARS[0].set(str(point[0]) + ';' + str(point[1]) + ';' + str(point[2]))
def translateClick(): 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 prev = [] w = WIDGETS['translate'] if CTK.__BUSY__ == False: CTK.__BUSY__ = True nzs = CPlot.getSelectedZones() CTK.TXT.insert('START', 'Click start point...\n') TTK.sunkButton(w) while CTK.__BUSY__: CPlot.unselectAllZones() l = [] while l == []: l = CPlot.getActivePoint() time.sleep(CPlot.__timeStep__) w.update() if CTK.__BUSY__ == False: break if CTK.__BUSY__: if prev == []: prev = l if nzs == []: nzs = CPlot.getSelectedZones() CTK.TXT.insert('START', 'Click end point...\n') elif prev != l: CTK.saveTree() vx = l[0] - prev[0] vy = l[1] - prev[1] vz = l[2] - prev[2] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] a = T.translate(z, (vx, vy, vz)) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Zones translated.\n') CPlot.render() prev = [] break CTK.__BUSY__ = False TTK.raiseButton(w) else: CTK.__BUSY__ = False TTK.raiseButton(w)
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
def setCenterRotation(): point = CPlot.getActivePoint() if point != []: VARS[4].set(str(point[0])) VARS[5].set(str(point[1])) VARS[6].set(str(point[2]))
def setTransOrigin(): point = CPlot.getActivePoint() if point != []: VARS[1].set(str(point[0])) VARS[2].set(str(point[1])) VARS[3].set(str(point[2]))
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)
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)
def sculpt(): 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 TOOLS = createTools() #CTK.display(TOOLS) bbox = G.bbox(CTK.t) size = max(bbox[3] - bbox[0], bbox[4] - bbox[1], bbox[5] - bbox[2]) CPlot.unselectAllZones() w = WIDGETS['sculpt'] if CTK.__BUSY__ == False: CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while CTK.__BUSY__: l = [] while l == []: nz = CPlot.getSelectedZone() l = CPlot.getActivePointIndex() time.sleep(CPlot.__timeStep__) w.update() if (CTK.__BUSY__ == False): break if CTK.__BUSY__: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.saveTree() depth = 0.5 * WIDGETS['depth'].get() / 100. depth = size * depth width = 0.5 * WIDGETS['width'].get() / 100. width = size * width brushType = VARS[2].get() z = CTK.t[2][nob][2][noz] posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') vect = (posEye[0] - posCam[0], posEye[1] - posCam[1], posEye[2] - posCam[2]) if brushType == 'Deform': click = CPlot.getActivePoint() point = (click[0], click[1], click[2]) z = T.deformPoint(z, point, vect, depth, width) CTK.replace(CTK.t, nob, noz, z) elif brushType == 'Sphere': click = CPlot.getActivePoint() center = (click[0], click[1], click[2]) s = D.sphere(center, depth, N=10) s = C.convertArray2Tetra(s) s = G.close(s) z = C.convertArray2Tetra(z) z = G.close(z) z = XOR.booleanMinus(z, s) CTK.replace(CTK.t, nob, noz, z) elif brushType == 'Cube': click = CPlot.getActivePoint() center = (click[0], click[1], click[2]) s = D.sphere(center, depth, N=20) s = C.convertArray2Tetra(s) s = G.close(s) z = C.convertArray2Tetra(z) z = G.close(z) z = XOR.booleanMinus(z, s) CTK.replace(CTK.t, nob, noz, z) CTK.TKTREE.updateApp() CPlot.unselectAllZones() CPlot.render() CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0)
def initCanvas(event=None): dir = VARS[0].get() if dir == 'None' and CTK.t == []: return global CANVASSIZE, XC, YC, ZC, UX, UY, UZ, LX, LY, LZ, DIRX, DIRY, DIRZ if CANVASSIZE == -1: try: bb = G.bbox(CTK.t) CANVASSIZE = max(bb[3] - bb[0], bb[4] - bb[1], bb[5] - bb[2]) except: CANVASSIZE = 1 nzs = CPlot.getSelectedZones() if (nzs != [] and dir != 'None'): point = CPlot.getActivePoint() if point != []: XC = point[0] YC = point[1] ZC = point[2] if dir == 'None': deleteCanvasBase() (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render() return elif dir == 'View': posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') if nzs == []: XC = posEye[0] YC = posEye[1] ZC = posEye[2] LX = posEye[0] - posCam[0] LY = posEye[1] - posCam[1] LZ = posEye[2] - posCam[2] if LX * LX + LY * LY + LZ * LZ < 1.e-10: LX = -1 if dirCam[0] * dirCam[0] + dirCam[1] * dirCam[1] + dirCam[2] * dirCam[ 2] == 0.: dirCam = (0, 0, 1) DIRX = dirCam[0] DIRY = dirCam[1] DIRZ = dirCam[2] UX = dirCam[1] * LZ - dirCam[2] * LY UY = dirCam[2] * LX - dirCam[0] * LZ UZ = dirCam[0] * LY - dirCam[1] * LX elif dir == 'YZ': DIRX = 1 DIRY = 0 DIRZ = 0 UX = 0 UY = 1 UZ = 0 LX = 0 LY = 0 LZ = 1 elif dir == 'XZ': DIRX = 0 DIRY = 1 DIRZ = 0 UX = 1 UY = 0 UZ = 0 LX = 0 LY = 0 LZ = 1 else: DIRX = 0 DIRY = 0 DIRZ = 1 UX = 1 UY = 0 UZ = 0 LX = 0 LY = 0 LZ = 1 CTK.TXT.insert('START', 'Set a canvas.\n') setCanvas()
def view(event=None): if CTK.t == []: return pos = float(VARS[1].get()) global VALUE VALUE = pos delta = float(VARS[4].get()) global DELTA DELTA = delta plane = VARS[0].get() order = int(VARS[3].get()) eps = float(VARS[2].get()) algo = VARS[5].get() nzs = CPlot.getSelectedZones() if nzs != []: point = CPlot.getActivePoint() if len(point) == 3: if plane == 'X': pos = point[0] elif plane == 'Y': pos = point[1] elif plane == 'Z': pos = point[2] VARS[1].set(str(pos)) VALUE = pos if plane == 'Mesh': CTK.display(CTK.t) return try: if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() active = [] tp = Internal.appendBaseName2ZoneName(CTK.t, updateRef=False, separator=Internal.SEP1) for z in CTK.__MAINACTIVEZONES__: active.append(tp[2][CTK.Nb[z] + 1][2][CTK.Nz[z]]) temp = C.newPyTree(['Base']) temp[2][1][2] += active if plane == 'X' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateX', pos) elif plane == 'Y' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateY', pos) elif plane == 'Z' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateZ', pos) elif plane == 'X' and algo == 'Slice2': p = P.extractPlane(active, (1, 0, 0, -pos), order=order, tol=eps) elif plane == 'Y' and algo == 'Slice2': p = P.extractPlane(active, (0, 1, 0, -pos), order=order, tol=eps) elif plane == 'Z' and algo == 'Slice2': p = P.extractPlane(active, (0, 0, 1, -pos), order=order, tol=eps) elif plane == 'X' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateX}>=' + str(VALUE)) elif plane == 'Y' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateY}>=' + str(VALUE)) elif plane == 'Z' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateZ}>=' + str(VALUE)) elif plane == 'X' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateX}<=' + str(VALUE)) elif plane == 'Y' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateY}<=' + str(VALUE)) elif plane == 'Z' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateZ}<=' + str(VALUE)) elif plane == 'X' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateX}>=' + str(VALUE - DELTA) + ') & ({CoordinateX}<=' + str(VALUE + DELTA) + ')') elif plane == 'Y' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateY}>=' + str(VALUE - DELTA) + ') & ({CoordinateY}<=' + str(VALUE + DELTA) + ')') elif plane == 'Z' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateZ}>=' + str(VALUE - DELTA) + ') & ({CoordinateZ}<=' + str(VALUE + DELTA) + ')') CTK.dt = C.newPyTree(['Base']) if algo == 'Slice1': CTK.dt[2][1][2] += p elif algo == 'Slice2': CTK.dt[2][1][2] += [p] else: CTK.dt[2][1][2] += p[2][1][2] CTK.display(CTK.dt, mainTree=CTK.SLICE) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp() except ValueError: CTK.TXT.insert('START', 'Intersection is empty.\n') return except Exception as e: Panels.displayErrors([0, str(e)], header='Error: slice') CTK.TXT.insert('START', 'Slice failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return
def set2Axis(): point = CPlot.getActivePoint() if point != []: VARS[7].set(str(point[0])) VARS[8].set(str(point[1])) VARS[9].set(str(point[2]))
def paint(): 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 # get patined var field = CPlot.getState('scalarField') if field == -1: CTK.TXT.insert('START', 'Scalar field is not set.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CPlot.unselectAllZones() CTK.saveTree() w = WIDGETS['paint'] if not CTK.__BUSY__: CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while CTK.__BUSY__ == True: l = [] while l == []: nz = CPlot.getSelectedZone() l = CPlot.getActivePointIndex() #time.sleep(CPlot.__timeStep__) w.update() if not CTK.__BUSY__: break if CTK.__BUSY__: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.saveTree() value = float(WIDGETS['value'].get()) #width = float(WIDGETS['width'].get()) #brushType = VARS[2].get() z = CTK.t[2][nob][2][noz] posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') vect = (posEye[0] - posCam[0], posEye[1] - posCam[1], posEye[2] - posCam[2]) click = CPlot.getActivePoint() point = (click[0], click[1], click[2]) ind = CPlot.getActivePointIndex() #hook = C.createHook varNames = C.getVarNames(z)[0] if len(varNames) > field + 3: var = varNames[field + 3] C.setValue(z, var, ind[0], value) else: CTK.TXT.insert( 'START', 'Field %d not found. Use scalar mode.\n' % field) CTK.TXT.insert('START', 'Error: ', 'Error') CTK.replace(CTK.t, nob, noz, z) CTK.TKTREE.updateApp() CPlot.unselectAllZones() CPlot.render() CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0)
def apply2D(density, npts, factor, ntype=0): nzs = CPlot.getSelectedZones() nz = nzs[0] nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] zone = CTK.t[2][nob][2][noz] ret = getEdges2D(zone, 0.) if ret is None: return True (m, r, u, ind) = ret out = [] # Applique la fonction sur m[0] (edge a modifier) i = m[0] dims = Internal.getZoneDim(i) np = dims[1]*dims[2]*dims[3] if ntype == 0: # uniformize if density > 0: npts = D.getLength(i)*density if factor > 0: npts = np*factor[0] npts = int(max(npts, 2)) distrib = G.cart((0,0,0), (1./(npts-1.),1,1), (npts,1,1)) b = G.map(i, distrib) elif ntype == 1: # refine if factor < 0: factor = (npts-1.)/(np-1) else: npts = factor*(np-1)+1 b = G.refine(i, factor, 1) elif ntype == 2: # stretch (factor=h) h = factor l = D.getLength(i) a = D.getCurvilinearAbscissa(i) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') N = dims[1] val = C.getValue(a, 's', ind) Xc = CPlot.getActivePoint() valf = val Pind = C.getValue(i, 'GridCoordinates', ind) if ind < N-1: # cherche avec indp1 Pindp1 = C.getValue(i, 'GridCoordinates', ind+1) v1 = Vector.sub(Pindp1, Pind) v2 = Vector.sub(Xc, Pind) if Vector.dot(v1,v2) >= 0: val2 = C.getValue(a, 's', ind+1) alpha = Vector.norm(v2)/Vector.norm(v1) valf = val+alpha*(val2-val) if ind > 0 and val == valf: # cherche avec indm1 Pindm1 = C.getValue(i, 'GridCoordinates', ind-1) v1 = Vector.sub(Pindm1, Pind) v2 = Vector.sub(Xc, Pind) if Vector.dot(v1,v2) >= 0: val2 = C.getValue(a, 's', ind-1) alpha = Vector.norm(v2)/Vector.norm(v1) valf = val+alpha*(val2-val) if h < 0: distrib = G.enforcePoint(distrib, valf) else: if val == 0: distrib = G.enforcePlusX(distrib, h/l, N/10, 1) elif val == 1: distrib = G.enforceMoinsX(distrib, h/l, N/10, 1) else: distrib = G.enforceX(distrib, valf, h/l, N/10, 1) b = G.map(i, distrib) elif ntype == 3: # copyDistrib (factor=source=edge pour l'instant) source = factor b = G.map(i, source, 1) elif ntype == 4: # smooth (factor=eps, npts=niter) niter = npts eps = factor a = D.getCurvilinearAbscissa(i) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') bornes = P.exteriorFaces(distrib) distrib = T.smooth(distrib, eps=eps, niter=niter, fixedConstraints=[bornes]) b = G.map(i, distrib, 1) dimb = Internal.getZoneDim(b) npts = dimb[1] out.append(b) # Raffine les edges si necessaires if npts != np: ret = getEdges2D(zone, 2.) if ret is None: return True (m, r, u, ind) = ret for i in r: dims = Internal.getZoneDim(i) np = dims[1]*dims[2]*dims[3] factor = (npts-1.)/(np-1) # npts de m b = G.refine(i, factor, 1) out.append(b) # Garde les autres out += u #tp = C.newPyTree(['Base']) #tp[2][1][2] += out #C.convertPyTree2File(tp, 'edges.cgns') # Rebuild try: b = G.TFI(out) # Projection du patch interieur #dimsb = Internal.getZoneDim(b) #bs = T.subzone(b, (2,2,1), (dimsb[1]-1,dimsb[2]-1,1)) #bs = T.projectOrtho(bs, [zone]) #b = T.patch(b, bs, position=(2,2,1)) #tp = C.newPyTree(['Base']) #tp[2][1][2] += [b, zone] #C.convertPyTree2File(tp, 'face.cgns') b = T.projectOrtho(b, [zone]) CTK.replace(CTK.t, nob, noz, b) return False except Exception as e: Panels.displayErrors([0,str(e)], header='Error: apply2D') return True
def stretch1D(h): fail = False nzs = CPlot.getSelectedZones() nz = nzs[0] nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] dims = Internal.getZoneDim(z) try: if dims[0] == 'Unstructured': a = C.convertBAR2Struct(z) else: a = z except Exception as e: #print 'Error: stretch1D: %s.'%str(e) Panels.displayErrors([0,str(e)], header='Error: stretch1D') return True # Fail ind = CPlot.getActivePointIndex() if ind == []: return True # Fail ind = ind[0] l = D.getLength(a) a = D.getCurvilinearAbscissa(a) zp = D.getCurvilinearAbscissa(z) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') N = dims[1] val = C.getValue(zp, 's', ind) Xc = CPlot.getActivePoint() valf = val Pind = C.getValue(z, 'GridCoordinates', ind) if ind < N-1: # cherche avec indp1 Pindp1 = C.getValue(z, 'GridCoordinates', ind+1) v1 = Vector.sub(Pindp1, Pind) v2 = Vector.sub(Xc, Pind) if Vector.dot(v1,v2) >= 0: val2 = C.getValue(zp, 's', ind+1) alpha = Vector.norm(v2)/Vector.norm(v1) valf = val+alpha*(val2-val) if ind > 0 and val == valf: # cherche avec indm1 Pindm1 = C.getValue(z, 'GridCoordinates', ind-1) v1 = Vector.sub(Pindm1, Pind) v2 = Vector.sub(Xc, Pind) if Vector.dot(v1,v2) >= 0: val2 = C.getValue(zp, 's', ind-1) alpha = Vector.norm(v2)/Vector.norm(v1) valf = val+alpha*(val2-val) if h < 0: # enforce point distrib = G.enforcePoint(distrib, valf) else: # enforce h if val == 0: distrib = G.enforcePlusX(distrib, h/l, N/10, 1) elif val == 1: distrib = G.enforceMoinsX(distrib, h/l, N/10, 1) else: distrib = G.enforceX(distrib, valf, h/l, N/10, 1) try: a1 = G.map(a, distrib) CTK.replace(CTK.t, nob, noz, a1) except Exception as e: fail = True Panels.displayErrors([0,str(e)], header='Error: stretch1D') return fail
def apply3D(density, npts, factor, ntype): nzs = CPlot.getSelectedZones() nz = nzs[0] nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] zone = CTK.t[2][nob][2][noz] ret = getEdges3D(zone, 0.) if ret is None: return True (m, r, f, ue, uf, ind) = ret out = [] # Applique la fonction sur m i = m[0] dims = Internal.getZoneDim(i) np = dims[1]*dims[2]*dims[3] if ntype == 0: # uniformize if density > 0: npts = D.getLength(i)*density if factor > 0: npts = np*factor[0] npts = int(max(npts, 2)) distrib = G.cart((0,0,0), (1./(npts-1.),1,1), (npts,1,1)) b = G.map(i, distrib) elif ntype == 1: # refine if factor < 0: factor = (npts-1.)/(np-1) else: npts = factor*(np-1)+1 b = G.refine(i, factor, 1) elif ntype == 2: # stretch (factor=h) h = factor l = D.getLength(i) a = D.getCurvilinearAbscissa(i) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') N = dims[1] val = C.getValue(a, 's', ind) Xc = CPlot.getActivePoint() valf = val Pind = C.getValue(i, 'GridCoordinates', ind) if ind < N-1: # cherche avec indp1 Pindp1 = C.getValue(i, 'GridCoordinates', ind+1) v1 = Vector.sub(Pindp1, Pind) v2 = Vector.sub(Xc, Pind) if Vector.dot(v1,v2) >= 0: val2 = C.getValue(a, 's', ind+1) alpha = Vector.norm(v2)/Vector.norm(v1) valf = val+alpha*(val2-val) if ind > 0 and val == valf: # cherche avec indm1 Pindm1 = C.getValue(i, 'GridCoordinates', ind-1) v1 = Vector.sub(Pindm1, Pind) v2 = Vector.sub(Xc, Pind) if Vector.dot(v1,v2) >= 0: val2 = C.getValue(a, 's', ind-1) alpha = Vector.norm(v2)/Vector.norm(v1) valf = val+alpha*(val2-val) if h < 0: distrib = G.enforcePoint(distrib, valf) else: if val == 0: distrib = G.enforcePlusX(distrib, h/l, N/10, 1) elif val == 1: distrib = G.enforceMoinsX(distrib, h/l, N/10, 1) else: distrib = G.enforceX(distrib, valf, h/l, N/10, 1) b = G.map(i, distrib) elif ntype == 3: source = factor b = G.map(i, source, 1) elif ntype == 4: # smooth (factor=eps, npts=niter) niter = npts eps = factor a = D.getCurvilinearAbscissa(i) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') bornes = P.exteriorFaces(distrib) distrib = T.smooth(distrib, eps=eps, niter=niter, fixedConstraints=[bornes]) b = G.map(i, distrib, 1) dimb = Internal.getZoneDim(b) npts = dimb[1] out.append(b) # Raffine les edges si necessaires if npts != np: ret = getEdges3D(zone, 2.) if ret is None: return True (m, r, f, ue, uf, ind) = ret for i in r: dims = Internal.getZoneDim(i) np = dims[1]*dims[2]*dims[3] factor = (npts-1.)/(np-1) # npts de m b = G.refine(i, factor, 1) out.append(b) # Garde les autres out += ue outf = [] # Rebuild les faces for i in f: # trouve les edges de la face edges = P.exteriorFacesStructured(i) match = [] for e in edges: dime = Internal.getZoneDim(e) np = dime[1]-1 P0 = C.getValue(e, Internal.__GridCoordinates__, 0) P1 = C.getValue(e, Internal.__GridCoordinates__, np) for ei in out: # retrouve les edges par leurs extremites dimei = Internal.getZoneDim(ei) npi = dimei[1]-1 Q0 = C.getValue(ei, Internal.__GridCoordinates__, 0) Q1 = C.getValue(ei, Internal.__GridCoordinates__, npi) t1 = Vector.norm2(Vector.sub(P0,Q0)) t2 = Vector.norm2(Vector.sub(P1,Q1)) if (t1 < 1.e-12 and t2 < 1.e-12): match.append(ei) if len(match) == 4: # OK fn = G.TFI(match) # Projection du patch interieur #dimsf = Internal.getZoneDim(fn) #fns = T.subzone(fn, (2,2,1), (dimsf[1]-1,dimsf[2]-1,1)) #fns = T.projectOrtho(fns, [i]) #fn = T.patch(fn, fns, position=(2,2,1)) #fn = T.projectOrtho(fn, [i]) outf.append(fn) else: return True outf += uf try: b = G.TFI(outf) CTK.replace(CTK.t, nob, noz, b) return False except Exception as e: Panels.displayErrors([0,str(e)], header='Error: apply3D') return True
def display1D(event=None): if CTK.t == []: return # Get slot try: slot = int(VARS[5].get()) except: slot = 0 # Get grid size try: gridSize = VARS[1].get() grids = gridSize.split(';') if (len(grids) == 1): gridSize = (int(grids[0]), 1) else: gridSize = (int(grids[0]), int(grids[1])) except: gridSize = (1, 1) CPlot.setState(gridSize=gridSize) # Get grid pos try: gridPos = VARS[2].get() grids = gridPos.split(';') if (len(grids) == 1): gridPos = (int(grids[0]), 1) else: gridPos = (int(grids[0]), int(grids[1])) except: gridPos = (0, 0) # Recupere la direction pour la coupe ou 'Elements' dir = VARS[0].get() if dir == 'None': CPlot.display1D([], slot=slot) return # clear # Recupere le pt pour la coupe ou les elements 1D if dir == 'Elements': # elements -> recupere les elements 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 points = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selected = CTK.t[2][nob][0] + '/' + z[0] points.append(selected) elif (dir == 'I' or dir == 'J' or dir == 'K'): # indice -> recupere les indices + la zone if (CTK.__MAINTREE__ <= 0): CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nz = CPlot.getSelectedZone() if (nz == -1): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return points = [] nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selected = CTK.t[2][nob][0] + '/' + z[0] index = CPlot.getActivePointIndex() points = (selected, index) else: # les coupes -> recupere les coord du pt point = CPlot.getActivePoint() if point == []: point = (0., 0., 0.) # Recupere les variables a afficher var1 = VARS[3].get() var1 = var1.replace('centers:', '') var2 = VARS[4].get() var2 = var2.replace('centers:', '') # Recupere les zones actives actives = [] zones = Internal.getZones(CTK.t) if CTK.__MAINTREE__ == 1: nzs = CPlot.getActiveZones() for nz in nzs: actives.append(zones[nz]) else: actives = zones if actives == []: return if (dir == 'X (Y)'): elts = P.isoSurfMC(actives, 'CoordinateY', point[1]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2]) if (elts2 != []): elts = elts2 elif (dir == 'Y (X)'): elts = P.isoSurfMC(actives, 'CoordinateX', point[0]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2]) if (elts2 != []): elts = elts2 elif (dir == 'Z (X)'): elts = P.isoSurfMC(actives, 'CoordinateX', point[0]) if (elts != []): elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1]) if (elts2 != []): elts = elts2 elif (dir == 'X (Z)'): elts = P.isoSurfMC(actives, 'CoordinateZ', point[2]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1]) if (elts2 != []): elts = elts2 elif (dir == 'Y (Z)'): elts = P.isoSurfMC(actives, 'CoordinateZ', point[2]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0]) if (elts2 != []): elts = elts2 elif (dir == 'Z (Y)'): elts = P.isoSurfMC(actives, 'CoordinateY', point[1]) if (elts != []): elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0]) if (elts2 != []): elts = elts2 elif (dir == 'I'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (1, ind[3], ind[4]), (-1, ind[3], ind[4])) elts.append(zp) except: pass elif (dir == 'J'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (ind[2], 1, ind[4]), (ind[2], -1, ind[4])) elts.append(zp) except: pass elif (dir == 'K'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (ind[2], ind[3], 1), (ind[2], ind[3], -1)) elts.append(zp) except: pass elif (dir == 'Elements'): elts = [] for v in points: v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) if (bases != []): zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): elts.append(z) if elts == []: CTK.TXT.insert('START', 'Nothing to display.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: elts = D.getCurvilinearAbscissa(elts) except: pass # Fit first axis pos = WIDGETS['rangePos'].get() / 50. - 1. zoom = WIDGETS['rangeZoom'].get() / 120. minv1 = C.getMinValue(elts, var1) maxv1 = C.getMaxValue(elts, var1) if (maxv1 - minv1 < 1.e-6): maxv1 += 5.e-7 minv1 -= 5.e-7 # active point localisation nz = CPlot.getSelectedZone() if (nz != -1): ind = CPlot.getActivePointIndex() nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] f1 = C.getValue(z, var1, ind[0]) try: r1min = (f1 - minv1) * zoom + minv1 + pos * (1. - zoom) * (maxv1 - minv1) r1max = (f1 - maxv1) * zoom + maxv1 + pos * (1. - zoom) * (maxv1 - minv1) except: # var1 not found in z, le cherche dans elts xf1 = C.getValue(z, 'CoordinateX', ind[0]) yf1 = C.getValue(z, 'CoordinateY', ind[0]) zf1 = C.getValue(z, 'CoordinateZ', ind[0]) f1 = minv1 + 0.5 * (maxv1 - minv1) r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * ( 1. - zoom) * (maxv1 - minv1) r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * ( 1. - zoom) * (maxv1 - minv1) else: f1 = minv1 + 0.5 * (maxv1 - minv1) r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * (1. - zoom) * ( maxv1 - minv1) r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * (1. - zoom) * ( maxv1 - minv1) # Fit second axis p = P.selectCells( elts, '({%s} < %20.16g) & ({%s} > %20.16g)' % (var1, r1max, var1, r1min)) minv2 = C.getMinValue(p, var2) maxv2 = C.getMaxValue(p, var2) # display CPlot.display1D(p, slot=slot, bgBlend=0., gridPos=gridPos, var1=var1, var2=var2, r1=(r1min, r1max), r2=(minv2, maxv2)) CTK.TXT.insert('START', 'Plot displayed.\n')
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)
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)
def extract(event=None): if CTK.t == []: return pos = float(VARS[1].get()) global VALUE VALUE = pos delta = float(VARS[4].get()) global DELTA DELTA = delta plane = VARS[0].get() order = int(VARS[3].get()) eps = float(VARS[2].get()) algo = VARS[5].get() nzs = CPlot.getSelectedZones() if nzs != []: point = CPlot.getActivePoint() if plane == 'X': pos = point[0] elif plane == 'Y': pos = point[1] elif plane == 'Z': pos = point[2] VARS[1].set(str(pos)) VALUE = pos if plane == 'Mesh': return try: CTK.saveTree() if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() active = [] zones = Internal.getZones(CTK.t) for z in CTK.__MAINACTIVEZONES__: active.append(zones[z]) temp = C.newPyTree(['Base']) temp[2][1][2] += active if plane == 'X' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateX', pos) elif plane == 'Y' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateY', pos) elif plane == 'Z' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateZ', pos) elif plane == 'X' and algo == 'Slice2': p = P.extractPlane(active, (1, 0, 0, -pos), order=order, tol=eps) elif plane == 'Y' and algo == 'Slice2': p = P.extractPlane(active, (0, 1, 0, -pos), order=order, tol=eps) elif plane == 'Z' and algo == 'Slice2': p = P.extractPlane(active, (0, 0, 1, -pos), order=order, tol=eps) elif plane == 'X' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateX}>=' + str(VALUE)) elif plane == 'Y' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateY}>=' + str(VALUE)) elif plane == 'Z' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateZ}>=' + str(VALUE)) elif plane == 'X' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateX}<=' + str(VALUE)) elif plane == 'Y' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateY}<=' + str(VALUE)) elif plane == 'Z' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateZ}<=' + str(VALUE)) elif plane == 'X' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateX}>=' + str(VALUE - DELTA) + ') & ({CoordinateX}<=' + str(VALUE + DELTA) + ')') elif plane == 'Y' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateY}>=' + str(VALUE - DELTA) + ') & ({CoordinateY}<=' + str(VALUE + DELTA) + ')') elif plane == 'Z' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateZ}>=' + str(VALUE - DELTA) + ') & ({CoordinateZ}<=' + str(VALUE + DELTA) + ')') CTK.t = C.addBase2PyTree(CTK.t, 'EXTRACT', 2) base = Internal.getNodeFromName1(CTK.t, 'EXTRACT') if algo == 'Slice1': for i in p: i[0] = C.getZoneName(i[0]) base[2] += p elif algo == 'Slice2': p[0] = C.getZoneName(p[0]) base[2] += [p] else: p = C.deleteEmptyZones(p) for i in p[2][1][2]: i[0] = C.getZoneName(i[0]) base[2] += p[2][1][2] #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Slice extracted.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp() except ValueError: CTK.TXT.insert('START', 'Intersection is empty.\n') return except Exception as e: Panels.displayErrors([0, str(e)], header='Error: slice') CTK.TXT.insert('START', 'Slice failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return