def rotate(): if CTK.t == []: return if not CTK.__BUSY__: bb = G.bbox(CTK.t) xc = 0.5 * (bb[3] + bb[0]) yc = 0.5 * (bb[4] + bb[1]) zc = 0.5 * (bb[5] + bb[2]) pos = CPlot.getState('posCam') posCam = [pos[0], pos[1], pos[2]] posEye = [xc, yc, zc] dirCam = [0, 0, 1] CTK.__BUSY__ = True TTK.sunkButton(WIDGETS['rotate']) CPlot.setState(cursor=2) i = 0 while CTK.__BUSY__: speed = WIDGETS['speed'].get() * 0.0006 / 100. cs = math.cos(speed * i * math.pi / 180) ss = math.sin(speed * i * math.pi / 180) px = cs * (posCam[0] - xc) + ss * (posCam[1] - yc) + xc py = -ss * (posCam[0] - xc) + cs * (posCam[1] - yc) + yc posCam[0] = px posCam[1] = py CPlot.setState(posCam=posCam) time.sleep(CPlot.__timeStep__) WIDGETS['rotate'].update() i += 1 CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['rotate']) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['rotate']) CPlot.setState(cursor=0)
def fit(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if CTK.__MAINTREE__ <= 0 or nzs == []: bb = G.bbox(CTK.t) else: sel = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] sel.append(z) bb = G.bbox(sel) xmin = bb[0] ymin = bb[1] zmin = bb[2] xmax = bb[3] ymax = bb[4] zmax = bb[5] plane = VARS[0].get() if plane == 'Mesh': delta = max(xmax - xmin, ymax - ymin) delta = max(delta, zmax - zmin) delta = delta / 50. VARS[4].set(str(delta)) x = 0.5 * (xmax + xmin) VARS[1].set(str(x)) elif plane == 'X': delta = (xmax - xmin) / 50. VARS[4].set(str(delta)) x = 0.5 * (xmax + xmin) VARS[1].set(str(x)) elif plane == 'Y': delta = (ymax - ymin) / 50. VARS[4].set(str(delta)) x = 0.5 * (ymax + ymin) VARS[1].set(str(x)) elif plane == 'Z': delta = (zmax - zmin) / 50. VARS[4].set(str(delta)) x = 0.5 * (zmax + zmin) VARS[1].set(str(x))
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 createText(event=None): CTK.saveTree() 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 CTK.t = C.addBase2PyTree(CTK.t, 'TEXT', 3) nodes = Internal.getNodesFromName1(CTK.t, 'TEXT') base = nodes[0] 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) # Modification de l'angle, de la position et de la taille du texte # en fonction du point de vue posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') BB = G.bbox(a) xc = 0.5 * (BB[3] + BB[0]) yc = 0.5 * (BB[4] + BB[1]) zc = 0.5 * (BB[5] + BB[2]) a = T.translate(a, (posEye[0] - xc, posEye[1] - yc, posEye[2] - zc)) lx = posEye[0] - posCam[0] ly = posEye[1] - posCam[1] lz = posEye[2] - posCam[2] if (lx * lx + ly * ly + lz * lz == 0.): lx = -1 if (dirCam[0] * dirCam[0] + dirCam[1] * dirCam[1] + dirCam[2] * dirCam[2] == 0.): dirCam = (0, 0, 1) ll = math.sqrt(lx * lx + ly * ly + lz * lz) a = T.homothety(a, (posEye[0], posEye[1], posEye[2]), 0.01 * ll) ux = dirCam[1] * lz - dirCam[2] * ly uy = dirCam[2] * lx - dirCam[0] * lz uz = dirCam[0] * ly - dirCam[1] * lx a = T.rotate(a, (posEye[0], posEye[1], posEye[2]), ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ((-ux, -uy, -uz), dirCam, (lx, ly, lz))) nob = C.getNobOfBase(base, CTK.t) CTK.add(CTK.t, nob, -1, a) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Text created.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def withOctree(a, offset, density): # step tol = 1./density # octree snears = []; sec = 0 for z in a: bb = G.bbox(z) rx = bb[3]-bb[0]; ry = bb[4]-bb[1]; rz = bb[5]-bb[2] snear = min(rx, ry); snear = min(snear, rz) snear = 0.1*snear sec = max(sec, snear) snears.append(snear) o = G.octree(a, snears, dfar=offset+sec) o = compDistance(o, a, loc='nodes') # iteration d'adaptation nit = 0 while nit < 10: print('iterating: %d...'%nit) o = C.node2Center(o, 'TurbulentDistance') o = G.getVolumeMap(o) # adapt C._initVars(o, '{centers:vol}={centers:vol}**0.33333') # was 2.1 factor C._initVars(o, '{centers:indicator}=logical_and({centers:vol} > %20.16g , abs({centers:TurbulentDistance}-%20.16g) < 1.*{centers:vol})'%(tol,offset)) o1 = G.adaptOctree(o, 'centers:indicator') #C.convertPyTree2File([o1]+a, 'out%d.cgns'%nit) # check convergence dim1 = Internal.getZoneDim(o1); dim = Internal.getZoneDim(o) if dim1 == dim: break #if (nit%2 == 0): o1 = P.extractMesh([o], o1) o1 = compDistance(o1, a, loc='nodes') o = o1 nit += 1 o = C.rmVars(o, 'centers:TurbulentDistance') o = C.rmVars(o, 'centers:vol') o = C.rmVars(o, 'centers:indicator') #C.convertPyTree2File(o, 'out.cgns') # Iso surface iso = P.isoSurfMC([o], 'TurbulentDistance', value=offset) return iso
def fly(): if CTK.t == []: return if not CTK.__BUSY__: bb = G.bbox(CTK.t) xc = 0.5 * (bb[3] + bb[0]) yc = 0.5 * (bb[4] + bb[1]) zc = 0.5 * (bb[5] + bb[2]) pos = CPlot.getState('posCam') posCam = [pos[0], pos[1], pos[2]] step = 0.0001 sigma = 10 beta = 8 / 3 ro = 28 CTK.__BUSY__ = True TTK.sunkButton(WIDGETS['fly']) CPlot.setState(cursor=2) i = 0 while CTK.__BUSY__: speed = WIDGETS['speed'].get() / 50. CPlot.setState(posCam=posCam) time.sleep(CPlot.__timeStep__) x = posCam[0] - xc y = posCam[2] - yc z = posCam[1] - zc x = 10 * x / max((bb[3] - bb[0]), 1.e-10) y = 10 * y / max((bb[4] - bb[1]), 1.e-10) z = 30 * z / max((bb[5] - bb[2]), 1.e-10) xp = x + step * speed * sigma * (y - x) yp = y + step * speed * (ro * x - y - x * z) zp = z + step * speed * (x * y - beta * z) xp = xp * (bb[3] - bb[0]) * 0.1 + xc yp = yp * (bb[4] - bb[1]) * 0.1 + yc zp = zp * (bb[5] - bb[2]) / 30. + zc posCam[0] = xp posCam[1] = zp posCam[2] = yp WIDGETS['fly'].update() i += 1 CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['fly']) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['fly']) CPlot.setState(cursor=0)
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 withCart(a, offset, density): # Calcul la grille cartesienne BB = G.bbox(a) xmin = BB[0]; ymin = BB[1]; zmin = BB[2] xmax = BB[3]; ymax = BB[4]; zmax = BB[5] ni = density*(xmax-xmin); nj = density*(ymax-ymin); nk = density*(zmax-zmin) if ni < 2: ni = 2 if nj < 2: nj = 2 if nk < 2: nk = 2 hi = (xmax-xmin)/(ni-1); hj = (ymax-ymin)/(nj-1); hk = (zmax-zmin)/(nk-1) h = min(hi, hj); h = min(h, hk); h = max(h, 1.e-6) ni = int((xmax-xmin)/h)+7; nj = int((ymax-ymin)/h)+7 nk = int((zmax-zmin)/h)+7 ni += int(2*offset/h); nj += int(2*offset/h); nk += int(2*offset/h) b = G.cart( (xmin-3*h-offset, ymin-3*h-offset, zmin-3*h-offset), (h, h, h), (ni,nj,nk) ) # Calcul la distance a la paroi b = compDistance(b, a, loc='nodes') #C.convertPyTree2File(b, 'out.cgns') # Extraction isoSurf iso = P.isoSurfMC([b], 'TurbulentDistance', value=offset) return iso
def symetrize(): 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 axis = VARS[4].get() nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return sel = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] sel.append(z) bb = G.bbox(sel) xmin = bb[0] ymin = bb[1] zmin = bb[2] xmax = bb[3] ymax = bb[4] zmax = bb[5] if axis == 'around XY-': X = ((xmin + xmax) * 0.5, (ymin + ymax) * 0.5, zmin) axe1 = (1., 0., 0.) axe2 = (0., 1., 0.) elif axis == 'XY+': X = ((xmin + xmax) * 0.5, (ymin + ymax) * 0.5, zmax) axe1 = (1., 0., 0.) axe2 = (0., 1., 0.) elif axis == 'around XZ-': X = ((xmin + xmax) * 0.5, ymin, (zmin + zmax) * 0.5) axe1 = (1., 0., 0.) axe2 = (0., 0., 1.) elif axis == 'around XZ+': X = ((xmin + xmax) * 0.5, ymax, (zmin + zmax) * 0.5) axe1 = (1., 0., 0.) axe2 = (0., 0., 1.) elif axis == 'around YZ-': X = (xmin, (ymin + ymax) * 0.5, (zmin + zmax) * 0.5) axe1 = (0., 1., 0.) axe2 = (0., 0., 1.) elif axis == 'around YZ+': X = (xmax, (ymin + ymax) * 0.5, (zmin + zmax) * 0.5) axe1 = (0., 1., 0.) axe2 = (0., 0., 1.) elif axis == 'around view': X = CPlot.getState('posEye') Y = CPlot.getState('posCam') axe1 = (X[0] - Y[0], X[1] - Y[1], X[2] - Y[2]) axe2 = CPlot.getState('dirCam') else: X = (0., 0., 0.) axe1 = (1., 0., 0.) axe2 = (0., 1., 0.) CTK.saveTree() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = T.symetrize(CTK.t[2][nob][2][noz], (X[0], X[1], X[2]), axe1, axe2) CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones have been symmetrized.\n') CTK.TKTREE.updateApp() CPlot.render()
def generateCompositeIBMMesh(tb, vmin, snears, dfar, dfarloc=0., DEPTH=2, NP=0, check=True, merged=1, sizeMax=4000000, symmetry=0, externalBCType='BCFarfield'): tbox = None snearsf = None dimPb = Internal.getNodeFromName(tb, 'EquationDimension') if dimPb is None: raise ValueError('EquationDimension is missing in input body tree.') dimPb = Internal.getValue(dimPb) model = Internal.getNodeFromName(tb, 'GoverningEquations') refstate = C.getState(tb) # list of near body meshes t = Internal.copyRef(tb) Internal._rmNodesFromType(t, "Zone_t") snearsExt = [] tblank = Internal.copyRef(tb) DEPTHEXT = 3 * DEPTH + 1 tov = Internal.rmNodesFromType(tb, 'Zone_t') for nob in range(len(tb[2])): base = tb[2][nob] if base[3] == 'CGNSBase_t': basename = base[0] res = generateIBMMesh(base, vmin, snears, dfarloc, DEPTH=DEPTH, NP=NP, tbox=None, snearsf=None, check=check, merged=merged, symmetry=symmetry, sizeMax=sizeMax, externalBCType='BCDummy', to=None, composite=1, mergeByParents=False) res = Internal.getZones(res) t[2][nob][2] = res # blanking box for off-body mesh extFacesL = C.extractBCOfType(res, "BCDummy") bbl = G.bbox(extFacesL) lMax = 0. for extf in extFacesL: if dimPb == 2: extf = T.subzone(extf, (1, 1, 1), (-1, 1, 1)) extf = G.getVolumeMap(extf) dxloc = C.getValue(extf, 'centers:vol', 0) if dimPb == 3: dxloc = dxloc**0.5 lMax = max(lMax, dxloc) snearsExt.append(dxloc) tov[2][nob][2].append(extf) # ATTENTION : engendre une boite parallelepipedique - peut ne pas etre valide dans # les cas ou le maillage cartesien proche corps n est pas parallelepipedique # A ameliorer # IDEM pour les conditions aux limites dans octree2StructLoc et generateIBMMesh xminb = bbl[0] + DEPTHEXT * lMax xmaxb = bbl[3] - DEPTHEXT * lMax yminb = bbl[1] + DEPTHEXT * lMax ymaxb = bbl[4] - DEPTHEXT * lMax if dimPb == 3: zminb = bbl[2] + DEPTHEXT * lMax zmaxb = bbl[5] - DEPTHEXT * lMax blankingBoxL = G.cart( (xminb, yminb, zminb), (xmaxb - xminb, ymaxb - yminb, zmaxb - zminb), (2, 2, 2)) else: blankingBoxL = G.cart((xminb, yminb, 0.), (xmaxb - xminb, ymaxb - yminb, 1.), (2, 2, 1)) blankingBoxL = P.exteriorFaces(blankingBoxL) tblank[2][nob][2] = [blankingBoxL] tcart = generateIBMMesh(tov, vmin, snearsExt, dfar, DEPTH=DEPTH, NP=NP, tbox=tbox, snearsf=snearsf, check=check, merged=1, sizeMax=sizeMax, symmetry=symmetry, externalBCType='BCFarfield', to=None, mergeByParents=True) tcart[2][1][0] = 'OffBody' C._rmBCOfType( t, 'BCDummy') # near body grids external borders must be BCOverlap t = C.fillEmptyBCWith(t, 'ov_ext', 'BCOverlap', dim=dimPb) t = C.mergeTrees(t, tcart) model = Internal.getValue(model) C._addState(t, 'GoverningEquations', model) C._addState(t, 'EquationDimension', dimPb) C._addState(t, state=refstate) return t, tblank
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]
# - snapFront (pyTree) - import numpy import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import Connector.PyTree as X import Transform.PyTree as T import Converter.Internal as Internal s = D.circle((0, 0, 0), 1., N=100) s2 = T.addkplane(s) # Grille cartesienne (reguliere) BB = G.bbox([s]) ni = 100 nj = 100 nk = 3 xmin = BB[0] ymin = BB[1] zmin = BB[2]-0.5 xmax = BB[3] ymax = BB[4] zmax = BB[5]+0.5 hi = (xmax-xmin)/(ni-1) hj = (ymax-ymin)/(nj-1)
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()
# - bbox (pyTree) - import Generator.PyTree as G a = G.cart((0., 0., 0.), (0.1, 0.1, 1.), (20, 20, 20)) print G.bbox(a)
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()
# - bbox (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import KCore.test as test # bbox d une zone a = G.cart((0., 0., 0.), (0.1, 0.1, 1.), (20, 20, 20)) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imin', a, 'imax', [1, 2, 3]) a = C.addBC2Zone(a, 'match2', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) sol = G.bbox(a) test.testO(sol, 1) # bbox d un arbre t = C.newPyTree(['Base']) b = G.cart((0.5, 0., 0.), (0.1, 0.1, 1.), (20, 20, 20)) b[0] = 'cart2' t[2][1][2] += [a, b] t[2][1] = C.addState(t[2][1], 'Mach', 0.6) sol = G.bbox(t) test.testO(sol, 2)
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 createMat(rep): # already created materials dict = {} file = open(rep + '/Materials.lxm', 'w') file.write('# Lux Render materials - written by Cassiopee -\n') # world (clear medium) file.write('MakeNamedVolume "world" "clear"\n') file.write(' "float fresnel" [1.00]\n') file.write(' "color absorption" [0.0 0.0 0.0]\n') file.write('\n') # air (avec des particules dedans) file.write('MakeNamedVolume "air" "homogeneous"\n') file.write(' "float fresnel" [1.0]\n') file.write(' "color g" [0.0 0.0 0.0]\n') file.write(' "color sigma_a" [0.0 0.0 0.0]\n') file.write(' "color sigma_s" [0.036 0.036 0.036]\n') file.write('\n') # lamp file.write('Texture "lamp blackbody" "color" "blackbody"\n') file.write(' "float temperature" [6500.000000000000000]\n') file.write('\n') file.write('MakeNamedMaterial "lamp"\n') file.write(' "string type" ["null"]\n') file.write('\n') # cree un materiau par zone zones = Internal.getZones(CTK.t) c = 0 for z in zones: material = 'Solid' color = 'White' mode = 0 blending = 1 # default ri = Internal.getNodesFromName1(z, '.RenderInfo') if ri != []: # Material mt = Internal.getNodesFromName1(ri[0], 'Material') if mt != []: material = Internal.getValue(mt[0]) # Color co = Internal.getNodesFromName1(ri[0], 'Color') if co != []: color = Internal.getValue(co[0]) # Blending co = Internal.getNodesFromName1(ri[0], 'Blending') if co != []: blending = Internal.getValue(co[0]) s = color.split(':') if len(s) == 2 and s[0] == 'Iso': vref = C.getVarNames(z)[0] for pos in xrange(len(vref)): if (vref[pos] == s[1]): break if pos == len(vref): color = 'White' mode = 0 else: color = 'Iso' mode = pos + 1 material = 'Iso' # traduction color if color[0] == '#': colorR = color[1:3] colorG = color[3:5] colorB = color[5:] colorR = int(colorR, 16) colorR = colorR / 255. colorG = int(colorG, 16) colorG = colorG / 255. colorB = int(colorB, 16) colorB = colorB / 255. elif color == 'White': colorR = 1 colorG = 1 colorB = 1 elif color == 'Black': colorR = 0 colorG = 0 colorB = 0 elif color == 'Grey': colorR = 0.69 colorG = 0.69 colorB = 0.69 elif color == 'Blue': colorR = 0 colorG = 0 colorB = 1 elif color == 'Red': colorR = 1 colorG = 0 colorB = 0 elif color == 'Green': colorR = 0 colorG = 1 colorB = 0 elif color == 'Yellow': colorR = 1 colorG = 1 colorB = 0 elif color == 'Orange': colorR = 0.94 colorG = 0.737 colorB = 0.06 elif color == 'Magenta': colorR = 1 colorG = 0 colorB = 1 elif color == 'Brown': colorR = 0.588 colorG = 0.294 colorB = 0 else: coloR = 1 colorG = 1 colorB = 1 # Scale (utlise pour scaler les textures) bb = G.bbox(z) rx = bb[3] - bb[0] ry = bb[4] - bb[1] rz = bb[5] - bb[2] scale = 0.5 * min(rx, ry, rz) if material == 'Solid': writeMatte0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Glass': writeGlass0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Chrome': writeChrome0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Metal': writeMetal0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'XRay': writeMatte0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Wood': writeWood0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Marble': writeMarble0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Granite': writeMatte0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Smoke': writeMatte0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Brick': writeMatte0(file, dict, c, colorR, colorG, colorB, scale) elif material == 'Light': writeGlass0(file, dict, c, colorR, colorG, colorB, scale) else: writeMatte0(file, dict, c, colorR, colorG, colorB, scale) c += 1 file.close() return
def savePovFile(): if CTK.t == []: return # Sauvegarde toutes les zones au format pov rep = VARS[2].get() dir = os.path.dirname(CTK.FILE) rep = os.path.join(dir, rep) os.chdir(rep) zones = Internal.getZones(CTK.t) c = 0; files = [] colors = []; materials = []; blendings = []; shader1s = [] scales = []; centers = [] for z in zones: z = C.convertArray2Tetra(z) # Scale (utlise pour scaler les textures) bb = G.bbox(z) rx = bb[3]-bb[0]; ry = bb[4]-bb[1]; rz = bb[5]-bb[2] scale = min(rx, ry, rz) scales.append(scale) centers.append([bb[0]+0.5*rx, bb[1]+0.5*ry, bb[2]+0.5*rz]) # Material/Color/Blending material = 'Solid'; color = 'White'; mode = 0; blending = 1; shader1 = 1. ri = Internal.getNodesFromName1(z, '.RenderInfo') if (ri != []): # Material mt = Internal.getNodesFromName1(ri[0], 'Material') if (mt != []): material = Internal.getValue(mt[0]) # Color co = Internal.getNodesFromName1(ri[0], 'Color') if (co != []): color = Internal.getValue(co[0]) # Blending co = Internal.getNodesFromName1(ri[0], 'Blending') if (co != []): blending = Internal.getValue(co[0]) # Shader parameter 1 co = Internal.getNodesFromName1(ri[0], 'ShaderParameters') if (co != []): shader1 = co[0][1][0] else: shader1 = 1. s = color.split(':') if (len(s) == 2 and s[0] == 'Iso'): # couleur = iso field vref = C.getVarNames(z)[0] for pos in xrange(len(vref)): if (vref[pos] == s[1]): break if (pos == len(vref)): color = 'White'; mode = 0 else: color = 'Iso'; mode = pos+1 # traduction color si #FFFFFF if (color[0] == '#'): colorR = color[1:3]; colorG = color[3:5]; colorB = color[5:] colorR = int(colorR, 16); colorR = colorR / 255. colorG = int(colorG, 16); colorG = colorG / 255. colorB = int(colorB, 16); colorB = colorB / 255. color = 'rgbf<'+str(colorR)+','+str(colorG)+','+str(colorB)+'>' colors.append(color); materials.append(material) blendings.append(blending); shader1s.append(shader1) nt = C.newPyTree(['Base']) nt[2][1][2].append(z) try: if (mode == 0): C.convertPyTree2File(nt, 'mesh_'+str(c)+'.pov') else: C.convertPyTree2File(nt, 'mesh_'+str(c)+'.pov', colormap=mode) # avec iso files.append('mesh_'+str(c)+'.pov') c += 1 except: pass # Cam position eye = CPlot.getState('posEye') cam = CPlot.getState('posCam') dir = CPlot.getState('dirCam') # Ecriture du fichier PovRay file = open('scene.pov', 'w') file.write('// POV-Ray version 3.6 scenery file written by *Cassiopee*\n') file.write('// Please render this file with :\n') file.write('// povray -W800 -H600 +a0.3 +SP16 scene.pov +P\n') file.write('#version 3.6;\n') file.write('#include "colors.inc"\n') file.write('#include "textures.inc"\n') file.write('#include "woods.inc"\n') file.write('#include "stones.inc"\n') # Brushed metal texture file.write('#declare Brushed_Depth = 10; // Bump size\n') file.write('#declare Brushed_Pigment = pigment {colour rgb 0.73} \n') file.write('#declare Brushed_Finish = finish {ambient 0 diffuse 0.95 specular 0.96 roughness 0.0005 phong 0.43 phong_size 25 brilliance 3.15 reflection 0.33 metallic metallic on }\n') file.write('// The brushed metal texture.\n') file.write('#declare Brushed_Texture = texture { average texture_map { [ pigment {Brushed_Pigment} normal {wood +Brushed_Depth ramp_wave rotate 90*x scale 50} finish {Brushed_Finish} ] [pigment {Brushed_Pigment} normal {wood -Brushed_Depth ramp_wave rotate 90*x scale 50} finish {Brushed_Finish} ] } }\n') # XRay texture file.write('#declare XRayTexture2 = texture { pigment { slope{'+'<' +str(cam[0])+' , '+str(cam[1])+' , '+str(cam[2])+'> - <' +str(eye[0])+' , '+str(eye[1])+' , '+str(eye[2])+'>}\n') file.write('pigment_map {[0 color rgbt 2*<1,1,1,0.1>] [0.75 color rgbt <0.1,0.6,2,1>*1] [1 color rgbt <1,1,1,1>] } } finish {ambient 3} }\n') # - Radiosity - #file.write('global_settings { assumed_gamma 1 radiosity { \n') #file.write('pretrace_start 0.08 \n') #file.write('pretrace_end 0.02 \n') #file.write('count 50 \n') #file.write('error_bound 0.5 \n') #file.write('recursion_limit 1 } } \n') # - Camera - file.write('#declare Cam0 = camera {angle 50 \n') file.write('#location <'+str(cam[0])+' , '+str(cam[1])+' , '+ str(cam[2])+'> \n') file.write('#look_at <'+str(eye[0])+' , '+str(eye[1])+' , '+ str(eye[2])+'>\n') file.write('#direction <-1,0,0>\n') file.write('#sky <'+str(dir[0])+','+str(dir[1])+','+str(dir[2])+'> }\n') # focal blur (experimental) #file.write('#focal_point <'+str(eye[0])+' , '+str(eye[1])+' , '+ # str(eye[2])+'>\n') #file.write('#aperture 0.4\n') #file.write('#blur_samples 20 }\n') file.write('camera{Cam0}\n') # - Lumieres: point - #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) dir = Vector.mul(0.1, dir) pos = Vector.add(cam, dir) c = 0; light = 0 for f in files: material = materials[c] if (material == 'Light'): xc = centers[c]; color = colors[c] light = 1 intensity = shader1s[c]*5. file.write('light_source{<'+str(xc[0])+' , '+str(xc[1])+' , '+ str(xc[2])+'> color '+color+'*'+str(intensity)+'}\n') c += 1 if (light == 0): # pas de lumiere dans l'arbre, on met celle par defaut file.write('light_source{<'+str(pos[0])+' , '+str(pos[1])+' , '+ str(pos[2])+'> color White*4}\n') # - Background - bckgrd = VARS[0].get() if (bckgrd == 'Blue sky'): # Ciel bleu file.write('sky_sphere { pigment { gradient <0,0,1> turbulence 0\n') file.write(' color_map { [0.00 rgb <0.6,0.7,1.0>]\n') file.write(' [0.35 rgb <0.1,0.2,0.8>]\n') file.write(' [0.65 rgb <0.1,0.2,0.8>]\n') file.write(' [1.00 rgb <0.6,0.7,1.0>]\n') file.write(' }\n') file.write(' scale 2\n') file.write(' } // end of pigment\n') file.write(' } //end of skysphere\n') elif (bckgrd == 'Cloudy sky'): # on pourrait faire beaucoup mieux file.write('sky_sphere { \n') file.write('pigment{ bozo turbulence 0.76\n') file.write(' color_map { [0.5 rgb <0.20, 0.20, 1.0>]\n') file.write(' [0.6 rgb <1,1,1>]\n') file.write(' [1.0 rgb <0.5,0.5,0.5>]\n') file.write(' }\n') file.write(' } // end of pigment\n') file.write(' } //end of skysphere\n') # Avec les macros de pov, pas satisfaisant #file.write('#include "skies.inc" \n') #file.write("object{ O_Cloud1 rotate 90*x}\n") #file.write("sphere { <0,0,0>, 100 \n") #file.write("texture {T_Cloud3} scale 100 }\n") elif (bckgrd == 'Starfield'): file.write('#include "stars.inc"\n') file.write('sphere { <0,0,0>, 1\n') file.write('texture { Starfield1 }\n') file.write('scale 10000\n') file.write(' } //end of sphere\n') elif (bckgrd == 'White'): file.write('sky_sphere { pigment { White } }\n') # Objets c = 0 for f in files: color = colors[c]; material = materials[c] blend = str(1.-blendings[c]) if (material == 'Solid' or material == 'None'): # OK file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color != 'Iso'): file.write('texture{pigment{color '+color+' filter '+ blend+'}\n') else: file.write('texture{pigment{filter '+ blend+'}\n') file.write('finish {ambient 0.1 diffuse 0.1 reflection 0.05 phong 0.5 }}\n') file.write('}\n') elif (material == 'Flat'): file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color != 'Iso'): file.write('texture{pigment{color '+color+' filter '+ blend+'}\n') else: file.write('texture{pigment{filter '+ blend+'}\n') file.write('finish {ambient 0.1 diffuse 0.1 reflection 0.0 phong 0.0 }}\n') file.write('}\n') elif (material == 'Glass'): # OK file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color != 'Iso'): file.write('texture{pigment{color '+color+' filter '+ str(-0.1*blendings[c] +1.)+' }\n') else: file.write('texture{pigment{filter '+ str(-0.1*blendings[c] +1.)+' }\n') file.write('finish {reflection 0.2 phong 0.7 }}\n') file.write('interior { ior 1.3 }\n') file.write('}\n') elif (material == 'Chrome'): # OK file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color != 'Iso'): file.write('texture{pigment{color '+color+' filter '+ blend+'}\n') else: file.write('texture{pigment{filter '+ blend+'}\n') file.write('finish {ambient 0.25 brilliance 4 diffuse 0.5 reflection 0.4 specular 0.2 metallic roughness 1/80 }}\n') file.write('}\n') elif (material == 'Metal'): file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color == 'White'): file.write('texture {pigment{color rgb 0.73}\n') elif (color != 'Iso'): file.write('texture {pigment{color '+color+' filter '+ blend+'}\n') else: file.write('texture {pigment{filter '+ blend+'}\n') file.write('finish {ambient 0 diffuse 0.95 specular 0.26 roughness 0.0005 phong 0.33 phong_size 2 brilliance 3.15 reflection 0.33 metallic metallic on } }\n') file.write('}\n') elif (material == 'XRay'): file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') file.write('texture { XRayTexture2 } }\n') elif (material == 'Wood'): # OK file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color == 'White'): file.write('texture{T_Wood3 \n') elif (color == 'Black'): file.write('texture{T_Wood2 \n') elif (color == 'Blue'): file.write('texture{T_Wood31 \n') elif (color == 'Red'): file.write('texture{T_Wood6 \n') elif (color == 'Green'): file.write('texture{T_Wood32 \n') elif (color == 'Yellow'): file.write('texture{T_Wood35 \n') elif (color == 'Orange'): file.write('texture{T_Wood7 \n') elif (color == 'Magenta'): file.write('texture{T_Wood4 \n') else: file.write('texture{T_Wood32 \n') file.write("scale "+str(scales[c])+"\n"); file.write('finish {ambient 0.7 brilliance 0.2 diffuse 0.1 reflection 0.01 specular 0.1 roughness 1/20 }}\n') file.write('}\n') elif (material == 'Marble' or material == 'Granite'): file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') if (color == 'White'): #file.write('texture{T_Grnt20 \n') file.write('texture{White_Marble \n') elif (color == 'Black'): file.write('texture{T_Grnt15 \n') elif (color == 'Blue'): file.write('texture{T_Wood6 \n') elif (color == 'Red'): file.write('texture{T_Wood28 \n') elif (color == 'Green'): file.write('texture{T_Grnt21 \n') elif (color == 'Yellow'): file.write('texture{T_Wood1 \n') elif (color == 'Orange'): file.write('texture{T_Wood13 \n') elif (color == 'Magenta'): file.write('texture{T_Grnt14 \n') else: file.write('texture{T_Grnt20 \n') file.write('scale '+str(scales[c])+'\n'); file.write('finish {ambient 0.3 brilliance 0.3 diffuse 0.1 reflection 0.1 specular 0.1 }}\n') file.write('}\n') elif (material == 'Smoke'): file.write('#include "'+f+'"\n') file.write('object {mesh_'+str(c)+'\n') file.write('texture{pigment{color '+color+' filter 1.}\n') #file.write('texture{pigment { rgbt 1 }\n') file.write('finish {ambient 0.1 diffuse 0.1 }}\n') file.write('hollow\n') file.write('interior{ //---------------------\n') file.write('media{ method 2 \n') file.write('emission 0. \n') file.write('scattering{ 1, // Type \n') file.write('<1,1,1>*0.2 // color of scattering haze \n') file.write('extinction 1. \n') file.write('// how fast the scattering media absorbs light \n') file.write('// useful if the media absorbs too much light \n') file.write('} // end scattering \n') file.write('density{ bozo \n') file.write('turbulence 8.0 \n') file.write(' color_map { \n') file.write(' [0.00 rgb 0] \n') file.write(' [0.05 rgb 0] \n') file.write(' [0.20 rgb 0.2] \n') file.write(' [0.30 rgb 0.6] \n') file.write(' [0.40 rgb 1] \n') file.write(' [1.00 rgb 1] \n') file.write(' } // end color_map \n') file.write('scale '+str(scales[c])+'\n'); file.write('} // end of density \n') file.write('samples 1,1 // 3,3 for adaptive sampling \n') file.write('intervals 10 // increase up to 15 \n') file.write('} // end of media --------------------------- \n') file.write('} // end of interior \n') file.write('}\n') c += 1 file.close() os.chdir('..')
# Extraction de bandes x=cte sur un maillage surfacique import Converter.PyTree as C import Post.PyTree as P import Geom.PyTree as D import Generator.PyTree as G import Transform.PyTree as T # IN: surface+solution # Attention: les normales doivent etre dirigees vers l'exterieur a = D.sphere((0, 0, 0), 1, N=100) a = C.initVars(a, 'p={CoordinateX}+{CoordinateY}') a = C.convertArray2Tetra(a) a = G.close(a) # Extraction de lignes x = cste bb = G.bbox(a) xmin = bb[0] ymin = bb[1] zmin = bb[2] xmax = bb[3] ymax = bb[4] zmax = bb[5] bands = [] dx = 1. / 10 for i in range(10): x = i / 10. b = G.cart((x, ymin - 1, zmin - 1), (dx, ymax - ymin + 2, zmax - zmin + 2), (2, 2, 2)) b = P.exteriorFaces(b) b = C.convertArray2Tetra(b)
def scale(): 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 v = CTK.varsFromWidget(VARS[1].get(), type=1) if len(v) != 1 and len(v) != 3 and len(v) != 6: CTK.TXT.insert('START', 'Scale factor is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return axis = VARS[5].get() if axis == 'along XYZ': axe1 = (1, 0, 0) axe2 = (0, 1, 0) axe3 = (0, 0, 1) else: # view posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') axe1 = (posEye[0] - posCam[0], posEye[1] - posCam[1], posEye[2] - posCam[2]) axe2 = dirCam axe3 = (axe1[1] * axe2[2] - axe1[2] * axe2[1], axe1[2] * axe2[0] - axe1[0] * axe2[2], axe1[0] * axe2[1] - axe1[1] * axe2[0]) nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() selection = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selection.append(z) if len(v) == 6: # center is given X = [v[3], v[4], v[5]] else: X = G.barycenter(selection) if len(v) == 1 and v[0] == 0.: # scale unitaire bbox = G.bbox(selection) dx = bbox[3] - bbox[0] dy = bbox[4] - bbox[1] dz = bbox[5] - bbox[2] if dx >= dy and dx >= dz: v[0] = 1. / dx if dy >= dx and dy >= dz: v[0] = 1. / dy if dz >= dy and dz >= dx: v[0] = 1. / dz list = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] list.append((nob, noz, nz)) z = CTK.t[2][nob][2][noz] if len(v) == 1: a = T.homothety(z, (X[0], X[1], X[2]), v[0]) else: z = T.contract(z, (X[0], X[1], X[2]), axe2, axe3, v[0]) z = T.contract(z, (X[0], X[1], X[2]), axe1, axe3, v[1]) a = T.contract(z, (X[0], X[1], X[2]), axe1, axe2, v[2]) CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones have been scaled.\n') CTK.TKTREE.updateApp() CPlot.render()