def clip_stl(): """Clip the stl model.""" global F,oldF itemlist = [['axis',0],['begin',0.0],['end',1.0],['nodes','any']] res,accept = widgets.inputDialog(itemlist,'Clipping Parameters').process() if accept: updateGUI() clear() bb = F.bbox() message("Original bbox: %s" % bb) xmi = bb[0][0] xma = bb[1][0] dx = xma-xmi axis = int(res[0][1]) xc1 = xmi + float(res[1][1]) * dx xc2 = xmi + float(res[2][1]) * dx nodes = res[3][1] print nodes w = F.where(nodes='any',dir=axis,min=xc1,max=xc2) draw(F.cclip(w),color='yellow',wait=False) oldF = F F = F.clip(w) message("Clipped bbox = %s" % F.bbox()) #linewidth(2) draw(F,color='green')
def clip_surface(): """Clip the stl model.""" if not check_surface(): return itemlist = [['axis',0],['begin',0.0],['end',1.0],['nodes','any']] res,accept = widgets.inputDialog(itemlist,'Clipping Parameters').getResult() if accept: updateGUI() nodes,elems = PF['old_surface'] = PF['surface'] F = Formex(nodes[elems]) bb = F.bbox() GD.message("Original bbox: %s" % bb) xmi = bb[0][0] xma = bb[1][0] dx = xma-xmi axis = int(res[0][1]) xc1 = xmi + float(res[1][1]) * dx xc2 = xmi + float(res[2][1]) * dx nodid = res[3][1] print nodid clear() draw(F,color='yellow') w = F.test(nodes='any',dir=axis,min=xc1,max=xc2) F = F.clip(w) draw(F,clor='red')
def rotate_selection(): """Rotate the selection.""" global selection itemlist = [ [ 'axis',0], ['angle','0.0'] ] res,accept = widgets.inputDialog(itemlist,'Rotation Parameters').process() if accept: axis = int(res[0][1]) angle = float(res[1][1]) for F in byName(selection): oldF = F F = F.rotate(angle,axis) drawChanges(F,oldF)
def translate_selection(): """Translate the selected Formices.""" global selection itemlist = [ [ 'direction',0], ['distance','1.0'] ] res,accept = widgets.inputDialog(itemlist,'Translation Parameters').getResult() if accept: dir = int(res[0][1]) dist = float(res[1][1]) for F in byName(selection): oldF = F F = F.translate(dir,dist) drawChanges(F,oldF)
def scale_stl(): """Scale the stl model.""" global F,oldF itemlist = [ [ 'X-scale',1.0], [ 'Y-scale',1.0], [ 'Z-scale',1.0] ] res,accept = widgets.inputDialog(itemlist,'Scaling Parameters').process() if accept: print res updateGUI() clear() draw(F,color='yellow',wait=False) oldF = F F = F.scale(map(float,[r[1] for r in res])) draw(F,color='green')
def rotate_stl(): """Rotate the stl model.""" global F,oldF itemlist = [ [ 'axis',0], ['angle','0.0'] ] res,accept = widgets.inputDialog(itemlist,'Rotation Parameters').process() if accept: print res updateGUI() clear() draw(F,color='yellow',wait=False) oldF = F F = F.rotate(float(res[1][1]),int(res[0][1])) draw(F,color='green')
def toFormex(): """Transform the surface model to a named Formex.""" if not check_surface(): return itemlist = [ [ 'name', PF.get('project','')] ] res,accept = widgets.inputDialog(itemlist,'Name of the Formex').getResult() if accept: name = res[0][1] #print name nodes,elems = PF['surface'] #print nodes.shape #print elems.shape PF[name] = Formex(nodes[elems])
def rotate_surface(): """Rotate the stl model.""" if not check_surface(): return itemlist = [ [ 'axis',0], ['angle','0.0'] ] res,accept = widgets.inputDialog(itemlist,'Rotation Parameters').getResult() if accept: updateGUI() print res nodes,elems = PF['old_surface'] = PF['surface'] F = Formex(nodes.reshape((-1,1,3))) nodes = F.rotate(float(res[1][1]),int(res[0][1])).f PF['surface'] = nodes,elems clear() show_changes(PF['old_surface'],PF['surface'])
def scale_surface(): """Scale the stl model.""" if not check_surface(): return itemlist = [ [ 'X-scale',1.0], [ 'Y-scale',1.0], [ 'Z-scale',1.0] ] res,accept = widgets.inputDialog(itemlist,'Scaling Parameters').getResult() if accept: updateGUI() scale = map(float,[r[1] for r in res]) print scale nodes,elems = PF['old_surface'] = PF['surface'] F = Formex(nodes.reshape((-1,1,3))) nodes = F.scale(scale).f PF['surface'] = nodes,elems clear() show_changes(PF['old_surface'],PF['surface'])
def clip_selection(): """Clip the stl model.""" global F itemlist = [['axis',0],['begin',0.0],['end',1.0]] res,accept = widgets.inputDialog(itemlist,'Clipping Parameters').process() if accept: Flist = byName(selection) bb = bbox(Flist) axis = int(res[0][1]) xmi = bb[0][axis] xma = bb[1][axis] dx = xma-xmi xc1 = xmi + float(res[1][1]) * dx xc2 = xmi + float(res[2][1]) * dx for F in Flist: w = F.where(dir=axis,min=xc1,max=xc2) oldF = F.cclip(w) F = F.clip(w) drawChanges(F,oldF)
def section_stl(): """Sectionize the stl model.""" global F,sections,ctr,diam clear() linewidth(1) draw(F,color='yellow') bb = F.bbox() message("Bounding box = %s" % bb) itemlist = [['number of sections',20],['relative thickness',0.1]] res,accept = widgets.inputDialog(itemlist,'Sectioning Parameters').process() sections = [] ctr = [] diam = [] if accept: n = int(res[0][1]) th = float(res[1][1]) xmin = bb[0][0] xmax = bb[1][0] dx = (xmax-xmin) / n dxx = dx * th X = xmin + arange(n+1) * dx message("Sections are taken at X-values: %s" % X) c = zeros([n,3],float) d = zeros([n,1],float) linewidth(2) for i in range(n+1): G = F.clip(F.where(nodes='any',dir=0,min=X[i]-dxx,max=X[i]+dxx)) draw(G,color='blue',view=None) GD.canvas.update() C = G.center() H = Formex(G.f-C) x,y,z = H.x(),H.y(),H.z() D = 2 * sqrt((x*x+y*y+z*z).mean()) message("Section Center: %s; Diameter: %s" % (C,D)) sections.append(G) ctr.append(C) diam.append(D)