def curveNode(cur): bspline = False rational = False try: poles = cur.getPoles() weights = cur.getWeights() except: return False try: rational = cur.isRational() except: pass try: knots = cur.getKnots() mults = cur.getMultiplicities() bspline = True except: bspline = False # *** Set poles *** polesnode = coinNodes.coordinate3Node(poles) # *** Set weights *** weightStr = getString(weights) polySep = coinNodes.polygonNode((0.5, 0.5, 0.5), 1) polySep.vertices = poles # *** Set markers *** markerSep = coinNodes.markerSetNode((1, 0, 0), coin.SoMarkerSet.DIAMOND_FILLED_9_9) markerSep.color = [(1, 0, 0)] + [(0.5, 0.0, 0.5)] * (len(poles) - 1) if rational: # *** Set weight text *** weightSep = coinNodes.multiTextNode((1, 0, 0), "osiFont,FreeSans,sans", 16, 0) weightSep.data = (poles, weightStr) if bspline: # *** Set knots *** knotPoints = [] for k in knots: p = cur.value(k) knotPoints.append((p.x, p.y, p.z)) knotsnode = coinNodes.coordinate3Node(knotPoints) # *** Set texts *** multStr = [] for m in mults: multStr.append("\n%d" % m) knotMarkerSep = coinNodes.markerSetNode( (0, 0, 1), coin.SoMarkerSet.CIRCLE_FILLED_5_5) knotMarkerSep.color = [(0, 0, 1)] * len(knotPoints) # *** Set mult text *** multSep = coinNodes.multiTextNode((0, 0, 1), "osiFont,FreeSans,sans", 16, 1) multSep.data = (knotPoints, multStr) vizSep = coin.SoSeparator() vizSep.addChild(polesnode) vizSep.addChild(polySep) vizSep.addChild(markerSep) if rational: vizSep.addChild(weightSep) if bspline: vizSep.addChild(knotsnode) vizSep.addChild(knotMarkerSep) vizSep.addChild(multSep) return vizSep
def surfNode(surf): bspline = False rational = False try: poles = surf.getPoles() weights = surf.getWeights() nbU = int(surf.NbUPoles) nbV = int(surf.NbVPoles) except: return False try: rational = surf.isURational() or surf.isVRational() except: pass try: uknots = surf.getUKnots() vknots = surf.getVKnots() bspline = True except: bspline = False # *** Set poles *** flatPoles = to1D(poles) polesnode = coinNodes.coordinate3Node(flatPoles) # *** Set weights *** flatW = to1D(weights) weightStr = getString(flatW) polyRowSep = coinNodes.rowNode((0.5, 0, 0), 1) polyRowSep.vertices = (nbU, nbV) polyRowSep.color = [(0.5, 0.0, 0.0)] * len(flatPoles) polyColSep = coinNodes.colNode((0, 0, 0.5), 1) polyColSep.vertices = (nbU, nbV) polyColSep.color = [(0.0, 0.0, 0.5)] * len(flatPoles) # *** Set markers *** markerSep = coinNodes.markerSetNode((1, 0, 0), coin.SoMarkerSet.DIAMOND_FILLED_9_9) markerSep.color = [(1, 0, 0)] + [(0.5, 0.0, 0.5)] * (len(flatPoles) - 1) u0, u1, v0, v1 = surf.bounds() halfU = u0 + 1. * (u1 - u0) / 2 halfV = v0 + 1. * (v1 - v0) / 2 UPos = surf.value(halfU, v0) Uletter = coinNodes.text2dNode((0, 0, 0), "osiFont,FreeSans,sans", 20, (UPos.x, UPos.y, UPos.z), 'U') VPos = surf.value(u0, halfV) Vletter = coinNodes.text2dNode((0, 0, 0), "osiFont,FreeSans,sans", 20, (VPos.x, VPos.y, VPos.z), 'V') vizSep = coin.SoSeparator() vizSep.addChild(polesnode) vizSep.addChild(polyRowSep) vizSep.addChild(polyColSep) vizSep.addChild(markerSep) vizSep.addChild(Uletter) vizSep.addChild(Vletter) if rational: # *** Set weight text *** weightSep = coinNodes.multiTextNode((1, 0, 0), "osiFont,FreeSans,sans", 16, 0) weightSep.data = (flatPoles, weightStr) vizSep.addChild(weightSep) if bspline: # *** Set knots *** uknotPoints = [] nb_curves = 0 for k in uknots: try: uIso = surf.uIso(k) epts = uIso.toShape().discretize(100) if len(epts) == 100: for p in epts: uknotPoints.append((p.x, p.y, p.z)) nb_curves += 1 except: FreeCAD.Console.PrintError("Error computing surface U Iso\n") if nb_curves > 0: uknotsnode = coinNodes.coordinate3Node(uknotPoints) uCurves = coinNodes.rowNode((1.0, 0.5, 0.3), 3) uCurves.color = [(1.0, 0.5, 0.3)] * 99 uCurves.color += [(0.7, 0.0, 0.3)] * (nb_curves - 1) * 99 uCurves.vertices = (nb_curves, 100) vizSep.addChild(uknotsnode) vizSep.addChild(uCurves) vknotPoints = [] nb_curves = 0 for k in vknots: try: vIso = surf.vIso(k) epts = vIso.toShape().discretize(100) if len(epts) == 100: for p in epts: vknotPoints.append((p.x, p.y, p.z)) nb_curves += 1 except: FreeCAD.Console.PrintError("Error computing surface V Iso\n") if nb_curves > 0: vknotsnode = coinNodes.coordinate3Node(vknotPoints) vCurves = coinNodes.rowNode((0.3, 0.5, 1.0), 3) vCurves.color = [(0.8, 0.8, 0.0)] * 99 vCurves.color += [(0.3, 0.0, 0.7)] * (nb_curves - 1) * 99 vCurves.vertices = (nb_curves, 100) vizSep.addChild(vknotsnode) vizSep.addChild(vCurves) # removed because of several FC crashes ## ***** isoCurves ****** #uparam = paramList(16,u0,u1) #uisoPoints = [] #nb_curves = 0 #for k in uparam: #try: #uIso = surf.uIso(k) #epts = uIso.toShape().discretize(100) #if len(epts) == 100: #for p in epts: #uisoPoints.append((p.x,p.y,p.z)) #nb_curves += 1 #except: #FreeCAD.Console.PrintError("Error computing surface U Iso\n") #if nb_curves > 0: #uisonode = coinNodes.coordinate3Node(uisoPoints) #uisoCurves = coinNodes.rowNode((0.0,0.0,0.0),1) #uisoCurves.transparency = 0.8 #uisoCurves.vertices=(nb_curves,100) #vizSep.addChild(uisonode) #vizSep.addChild(uisoCurves) ##debug(str(uCurves.vertices)) #vparam = paramList(16,v0,v1) #visoPoints = [] #nb_curves = 0 #for k in vparam: #try: #vIso = surf.vIso(k) #epts = vIso.toShape().discretize(100) #if len(epts) == 100: #for p in epts: #vknotPoints.append((p.x,p.y,p.z)) #nb_curves += 1 #except: #FreeCAD.Console.PrintError("Error computing surface V Iso\n") #if nb_curves > 0: #visonode = coinNodes.coordinate3Node(visoPoints) #visoCurves = coinNodes.rowNode((0.0,0.0,0.0),1) #visoCurves.transparency = 0.8 #visoCurves.vertices=(nb_curves,100) #vizSep.addChild(visonode) #vizSep.addChild(visoCurves) ## *** Set texts *** #multStr = [] #for m in mults: #multStr.append("%d"%m) #knotMarkerSep = coinNodes.markerSetNode((0,0,1),coin.SoMarkerSet.CIRCLE_FILLED_9_9) ## *** Set mult text *** #multSep = coinNodes.multiTextNode((0,0,1),"osiFont,FreeSans,sans",16,1) #multSep.data = (knotPoints,multStr) return vizSep