def difference2(): 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 len(nzs) != 2: CTK.TXT.insert('START', 'Please, select two surfaces.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = CTK.varsFromWidget(VARS[0].get(), type=1) if len(tol) != 1: CTK.TXT.insert('START', 'Tolerance is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = tol[0] CTK.saveTree() deletedZoneNames = [] nz = nzs[0] nob1 = CTK.Nb[nz] + 1 noz1 = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob1][0] + Internal.SEP1 + CTK.t[2][nob1][2][noz1][0]) z1 = CTK.t[2][nob1][2][noz1] nz = nzs[1] nob2 = CTK.Nb[nz] + 1 noz2 = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob2][0] + Internal.SEP1 + CTK.t[2][nob2][2][noz2][0]) z2 = CTK.t[2][nob2][2][noz2] try: j = XOR.booleanMinus(z2, z1, tol=tol) CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(deletedZoneNames) CTK.add(CTK.t, nob1, -1, j) CTK.TXT.insert('START', 'Difference performed.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: difference') CTK.TXT.insert('START', 'Difference failed.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - convexify any concave polygon in the mesh (array) - import Intersector.PyTree as XOR import Converter.PyTree as C M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=1) m = XOR.simplifyCells(m, 1) m = XOR.prepareCellsSplit(m, PH_set=0, split_policy=0, PH_conc_threshold=1. / 3., PH_cvx_threshold=0.05, PG_cvx_threshold=1.e-8) m = XOR.splitNonStarCells(m, PH_conc_threshold=1. / 3., PH_cvx_threshold=0.05, PG_cvx_threshold=1.e-8) C.convertPyTree2File(m, 'out.cgns')
# - boolean difference (pyTree) - # BAR import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test c1 = D.circle( (0,0,0), 1, N=100 ) c2 = D.circle( (0.2,0,0), 1, N=50 ) c1 = C.convertArray2Tetra(c1); c1 = G.close(c1) c2 = C.convertArray2Tetra(c2); c2 = G.close(c2) x = XOR.booleanMinus(c1, c2, tol=0.) test.testT(x)
# - boolean difference (pyTree) - import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test s1 = D.sphere((0, 0, 0), 1, N=20) s2 = D.sphere((0., 1., 0.), 1, N=30) s1 = C.convertArray2Tetra(s1) s1 = G.close(s1) s2 = C.convertArray2Tetra(s2) s2 = G.close(s2) x = XOR.booleanMinus(s1, s2, tol=0.) test.testT(x)
# - boolean minus (PyTree) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 x = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1) test.testT(x, 1) x = XOR.booleanMinus(M1, M2, tol, preserve_right=0, solid_right=1) test.testT(x, 2) #~ x = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=0) #~ test.testT(x,3) #~ #~ x = XOR.booleanMinus(M1, M2, tol, preserve_right=0, solid_right=0) #~ test.testT(x,4)
# - convexify any concave polygon in the mesh (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=2) #full agg to convexify afterward #C.convertArrays2File([m], 'i.plt') PG_threshold = 1.e-2 m = XOR.prepareCellsSplit(m, PH_set = 0, split_policy = 0, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 1) m = XOR.prepareCellsSplit(m, PH_set = 0, split_policy = 1, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 2) m = XOR.prepareCellsSplit(m, PH_set = 0, split_policy = 2, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 3) m = XOR.prepareCellsSplit(m, PH_set = 1, split_policy = 0, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 4)
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)