def outCore(): 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 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] ooc = Internal.getNodesFromName1(z, 'OutOfCore') if (len(ooc) == 0): # Save zone base = CTK.t[2][nob] name = '.' + base[0] + '#' + z[0] + '.cgns' t = C.newPyTree(['Base']) t[2][1][2].append(z) C.convertPyTree2File(t, name) # Replace zone bb = G.BB(z) bb[2].append(['OutOfCore', numpy.array([1]), [], \ 'UserDefinedData_t']) bb = CPlot.addRender2Zone(bb, blending=0.2) CTK.replace(CTK.t, nob, noz, bb) CTK.saveTree() # il est apres pour forcer le flush CTK.TXT.insert('START', 'Selected zones out of core.\n') CTK.t = C.fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def setShaderParameter(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 shaderParameter2 = (WIDGETS['param2'].get()) / 50. shaderParameter1 = (WIDGETS['param1'].get()) / 50. VARS[4].set('Shader parameter 1 [%.2f].' % shaderParameter1) VARS[5].set('Shader parameter 2 [%.2f].' % shaderParameter2) nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = CPlot.addRender2Zone( CTK.t[2][nob][2][noz], shaderParameters=[shaderParameter1, shaderParameter2]) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() Panels.updateRenderPanel() CPlot.render()
def setAll(): 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 material = VARS[0].get() color = VARS[1].get() blending = WIDGETS['blending'].get() / 100. VARS[6].set('Blending [%.2f].' % blending) meshOverlay = VARS[3].get() shaderParameter2 = (WIDGETS['param2'].get()) / 50. shaderParameter1 = (WIDGETS['param1'].get()) / 50. nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = CPlot.addRender2Zone( CTK.t[2][nob][2][noz], material=material, color=color, blending=blending, shaderParameters=[shaderParameter1, shaderParameter2]) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() Panels.updateRenderPanel() CPlot.render()
def createZEllipse(): import Geom.PyTree as D import Transform.PyTree as T alpha = CTK.varsFromWidget(VARS[1].get(), type=2) if len(alpha) == 1: ax = alpha[0] ay = alpha[0] az = alpha[0] bx = alpha[0] by = alpha[0] bz = alpha[0] elif len(alpha) == 3: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[0] by = alpha[1] bz = alpha[2] elif len(alpha) == 6: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[3] by = alpha[4] bz = alpha[5] else: CTK.TXT.insert('START', 'Borders factor incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: box = G.bbox(CTK.t) except: box = [0, 0, 0, 1, 1, 1] hx = box[3] - box[0] hy = box[4] - box[1] if hx < 1.e-10: hx = 0.1 if hy < 1.e-10: hy = 0.1 hx = hx * 0.7 * ax hy = hy * 0.7 * ay cx = 0.5 * (box[0] + box[3]) cy = 0.5 * (box[1] + box[4]) if hx < hy: s = D.circle((cx, cy, box[2]), hx, N=50) s = T.contract(s, (cx, cy, box[2]), (1, 0, 0), (0, 0, 1), hy / hx) else: s = D.circle((cx, cy, box[2]), hy, N=50) s = T.contract(s, (cx, cy, box[2]), (0, 1, 0), (0, 0, 1), hx / hy) s = C.convertArray2Tetra(s) s = G.close(s, 1.e-6) p = G.fittingPlaster(s, bumpFactor=0.) s = G.gapfixer(s, p) s = CPlot.addRender2Zone(s, material='Solid', color='White', meshOverlay=0) return [s]
def createZPlane(): alpha = CTK.varsFromWidget(VARS[1].get(), type=2) if len(alpha) == 1: ax = alpha[0] ay = alpha[0] az = alpha[0] bx = alpha[0] by = alpha[0] bz = alpha[0] elif len(alpha) == 3: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[0] by = alpha[1] bz = alpha[2] elif len(alpha) == 6: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[3] by = alpha[4] bz = alpha[5] else: CTK.TXT.insert('START', 'Borders factor incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: box = G.bbox(CTK.t) except: box = [0, 0, 0, 1, 1, 1] hx = box[3] - box[0] hy = box[4] - box[1] if hx < 1.e-10: hx = 0.1 if hy < 1.e-10: hy = 0.1 hx = hx * 0.5 hy = hy * 0.5 b = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2]), (hx, hy, 1), (ax + bx + 3, ay + by + 3, 1)) b = CPlot.addRender2Zone(b, material='Solid', color='White', meshOverlay=1) return [b]
def setMaterial(): 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 material = VARS[0].get() nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = CPlot.addRender2Zone(CTK.t[2][nob][2][noz], material=material) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() Panels.updateRenderPanel() CPlot.render()
def setBlending(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 blending = WIDGETS['blending'].get() / 100. nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = CPlot.addRender2Zone(CTK.t[2][nob][2][noz], blending=blending) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() Panels.updateRenderPanel() CPlot.render()
def createGround(): import Post.PyTree as P alpha = CTK.varsFromWidget(VARS[1].get(), type=2) if len(alpha) == 1: ax = alpha[0] ay = alpha[0] az = alpha[0] bx = alpha[0] by = alpha[0] bz = alpha[0] elif len(alpha) == 3: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[0] by = alpha[1] bz = alpha[2] elif len(alpha) == 6: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[3] by = alpha[4] bz = alpha[5] else: CTK.TXT.insert('START', 'Borders factor incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: box = G.bbox(CTK.t) except: box = [0, 0, 0, 1, 1, 1] hx = box[3] - box[0] hy = box[4] - box[1] hz = box[5] - box[2] if hx < 1.e-10: hx = 0.1 if hy < 1.e-10: hy = 0.1 if hz < 1.e-10: hz = 0.001 h = max(hx, hy) ay = ax bx = ax by = ax # force square deltax = 0.5 * (h - hx) deltay = 0.5 * (h - hy) hx = h * 0.5 hy = h * 0.5 hz = 0.1 * hz b = G.cart( (box[0] - ax * hx - deltax, box[1] - ay * hy - deltay, box[2] - hz), (hx, hy, hz), (ax + bx + 3, ay + by + 3, 2)) b = P.exteriorFaces(b) b = CPlot.addRender2Zone(b, material='Solid', color='White', meshOverlay=1) # plafond (optionel) c = G.cart((box[0] - ax * hx - deltax, box[1] - ay * hy - deltay, box[2] + (ax + bx + 2) * hx - hz), (hx, hy, hz), (ax + bx + 3, ay + by + 3, 1)) return [b, c]
def createBox(half=0, zpos=0): alpha = CTK.varsFromWidget(VARS[1].get(), type=2) if len(alpha) == 1: ax = alpha[0] ay = alpha[0] az = alpha[0] bx = alpha[0] by = alpha[0] bz = alpha[0] elif len(alpha) == 3: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[0] by = alpha[1] bz = alpha[2] elif len(alpha) == 6: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[3] by = alpha[4] bz = alpha[5] else: CTK.TXT.insert('START', 'Borders factor incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if zpos == 1: az = 0 # force zmin posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') LX = posEye[0] - posCam[0] LY = posEye[1] - posCam[1] LZ = posEye[2] - posCam[2] try: box = G.bbox(CTK.t) except: box = [0, 0, 0, 1, 1, 1] hx = box[3] - box[0] hy = box[4] - box[1] hz = box[5] - box[2] if hx < 1.e-10: hx = 0.1 if hy < 1.e-10: hy = 0.1 if hz < 1.e-10: hz = 0.1 hx = hx * 0.5 hy = hy * 0.5 hz = hz * 0.5 ni = 3 + ax + bx nj = 3 + ay + by nk = 3 + az + bz if LX < 0: # plan xmin b1 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (1, nj, nk)) else: # plan xmax b1 = G.cart((box[3] + bx * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (1, nj, nk)) b1 = CPlot.addRender2Zone(b1, material='Solid', color='White', meshOverlay=1) if LY < 0: # plan ymin b2 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (ni, 1, nk)) else: # plan ymax b2 = G.cart((box[0] - ax * hx, box[4] + by * hy, box[2] - az * hz), (hx, hy, hz), (ni, 1, nk)) b2 = CPlot.addRender2Zone(b2, material='Solid', color='White', meshOverlay=1) if LZ < 0: # plan zmin b3 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (ni, nj, 1)) else: b3 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[5] + bz * hz), (hx, hy, hz), (ni, nj, 1)) b3 = CPlot.addRender2Zone(b3, material='Solid', color='White', meshOverlay=1) if half == 1: return [b1, b2, b3] if LX >= 0: # plan xmin b4 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (1, nj, nk)) else: # plan xmax b4 = G.cart((box[3] + bx * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (1, nj, nk)) b4 = CPlot.addRender2Zone(b4, material='Solid', color='White', meshOverlay=1) if LY >= 0: # plan ymin b5 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (ni, 1, nk)) else: # plan ymax b5 = G.cart((box[0] - ax * hx, box[4] + by * hy, box[2] - az * hz), (hx, hy, hz), (ni, 1, nk)) b5 = CPlot.addRender2Zone(b5, material='Solid', color='White', meshOverlay=1) if LZ >= 0: # plan zmin b6 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2] - az * hz), (hx, hy, hz), (ni, nj, 1)) else: b6 = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[5] + bz * hz), (hx, hy, hz), (ni, nj, 1)) b6 = CPlot.addRender2Zone(b6, material='Solid', color='White', meshOverlay=1) return [b1, b2, b3, b4, b5, b6]
tsph = GP.sphere6((0, 0, 0), 1., N=3, ntype='TRI') tsph = C.convertLO2HO(tsph, 0) for i in range(C.getNPts(tsph)): x = C.getValue(tsph, 'CoordinateX', i) y = C.getValue(tsph, 'CoordinateY', i) z = C.getValue(tsph, 'CoordinateZ', i) nrm = sqrt(x * x + y * y + z * z) x /= nrm y /= nrm z /= nrm C.setValue(tsph, 'CoordinateX', i, x) C.setValue(tsph, 'CoordinateY', i, y) C.setValue(tsph, 'CoordinateZ', i, z) tsph = T.translate(tsph, (3., 0, 0)) t = C.newPyTree(['Base1', 'Base2']) t[2][1][2] += Ci.getZones(qsph) t[2][2][2] += Ci.getZones(tsph) for shader in [ "Chrome", "Glass", "Wood", 'Marble', 'XRay', 'Metal', 'Granite', 'Brick', 'Cloud', 'Gooch' ]: s = CPlot.addRender2Zone(t, material=shader, color='White') CPlot.display(s, mode="Render") l = '' while (l != 'n'): l = CPlot.getKeyboard() CPlot.resetKeyboard()
# - addRender2Zone (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import CPlot.PyTree as CPlot a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1)) C._initVars(a, '{Density}={CoordinateX}') C._initVars(a, '{centers:VelocityX}={centers:CoordinateY}') # With a material a = CPlot.addRender2Zone(a, material='Glass', color='Blue', blending=1., meshOverlay=1, shaderParameters=[1., 1.]) # With field a = CPlot.addRender2Zone(a, material='Solid', color='Iso:Density', blending=1., meshOverlay=1, shaderParameters=[1., 1.]) # With field+material a = CPlot.addRender2Zone(a, material='Chrome', color='Iso:centers:VelocityX', blending=1., meshOverlay=1, shaderParameters=[1., 1.]) C.convertPyTree2File(a, 'out.cgns')
# - display (pyTree) - # Affichage du shader smoke (mode solid) import Geom.PyTree as D import CPlot.PyTree as CPlot import Converter.PyTree as C a = D.sphere((0, 0, 0), 1.) a = C.convertArray2Hexa(a) a = CPlot.addRender2Zone(a, material='Smoke', color='White') t = C.newPyTree(['Base', a]) CPlot.display(t, mode=2)
# - display (pyTree) - # Affichage des shaders (mode solid) import Geom.PyTree as D import CPlot.PyTree as CPlot import Transform.PyTree as T import Converter.PyTree as C import time a = D.sphere((0, 0, 0), 1.) a = CPlot.addRender2Zone(a, material='Chrome', color='White') b = T.translate(a, (0, 2.5, 0)) b = CPlot.addRender2Zone(b, material='Glass', color='Blue') c = T.translate(a, (0, 5., 0)) c = CPlot.addRender2Zone(c, material='Wood', color='Brown') d = T.translate(a, (0, 0, -2.5)) d = CPlot.addRender2Zone(d, material='Marble', color='Yellow') e = T.translate(a, (0, 2.5, -2.5)) e = CPlot.addRender2Zone(e, material='XRay', color='Blue') f = T.translate(a, (0, 5, -2.5)) f = CPlot.addRender2Zone(f, material='Metal', color='Blue') i = T.translate(a, (0, 0, -5)) i = CPlot.addRender2Zone(i, material='Granite', color='White') g = T.translate(a, (0, 2.5, -5.)) g = C.initVars(g,
# - addRender2Zone (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import CPlot.PyTree as CPlot import KCore.test as test a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1)) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') C._initVars(a, 'F', 1.) C._initVars(a, 'centers:G', 2.) a = CPlot.addRender2Zone(a, material='Glass', color='Blue') t = C.newPyTree(['Base', 2, a]) test.testT(t, 1)