def tweenCurveOnsurface(m, n, icurves, points0, points1):
    print {'def'}
    print {m}
    for icurve in icurves:
        ipoints = rs.DivideCurve(icurve, m + 1)
        ipointssnm.append(ipoints)
    for i in range(m):
        icurvesNew = []
        ps = []
        puvs = []
        p = points1[(i + 1)]
        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
        puvs.append(puv)
        for j in range(n):
            #转换数据类型
            p = ipointssnm[j][i + 1]
            puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
            ps.append(p)
            puvs.append(puv)
        p = points0[i + 1]
        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
        puvs.append(puv)
        crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
        icurvesNew.append(crv)
        print(crv)
    return icurvesNew
Example #2
0
def initEndPt(q):
    """ Take a QuadTree and do the first steps. """
    q.root.subdivide()

    # get midpoints
    initMidPts = q.root.get_midpoints()

    # discard node with other fixPt in it
    children = q.get_children()
    for i, node in enumerate(children):
        if node.contains(q.excludePt):
            del initMidPts[i]
            del children[i]
            break  # since there is only one other end point here we can safely break if contains=True

    lenNoD = {
    }  # a dict where we store the result from ghc.CrvOnSrf; Length is key
    # test the three midpoints
    for i in range(len(initMidPts)):
        inputPts = [fixPt1, initMidPts[i], fixPt2]
        # returns curve, length, domain
        srfcrvLen = ghc.CurveOnSurface(surface, inputPts, False)[1]
        # save to dict, length as key, node as value
        lenNoD[srfcrvLen] = children[i]

    # sort for shortest path and get the node
    shortest = sorted(lenNoD)[0]
    nodeToSubD = lenNoD[shortest]
    # return the node
    return nodeToSubD
     puvs = []
     p = points30[-(i + 1) - 1]
     puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
     puvs.append(puv)
     for j in range(n):
         #转换数据类型
         p = ipointssnm[j][i + 1]
         puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
         ps.append(p)
         puvs.append(puv)
     p = points12[i + 1]
     puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
     puvs.append(puv)
     print(count)
     print(puvs[2])
     crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
     icurvesm.append(crv)
     #print (crv)
 #print surfObj
 count = count + 1
 if (count >= loop):
     print('aaaaaaaaaaaaaaaaaaaaaaaaaaa')
     break
 icurvesn = []
 ipointssmn = []
 for icurve in icurvesm:
     ipoints = rs.DivideCurve(icurve, n + 1)
     ipointssmn.append(ipoints)
 global surfObj
 surfObj = rs.coercerhinoobject(surface).Geometry
 print surfObj
Example #4
0
for it in range(nIterations):
    # 1) subD, node gets children
    winnerNode1.subdivide()
    winnerNode2.subdivide()

    # 2) get midpoints
    midPts1 = winnerNode1.get_midpoints()
    midPts2 = winnerNode2.get_midpoints()

    # 3) test
    children1 = winnerNode1.get_children()
    lenNoD = {}
    for m in range(len(midPts1)):
        inputPts = [fixPt1, midPts1[m], winnerNode2.midpoint, fixPt2]
        srfcrvLen = ghc.CurveOnSurface(surface, inputPts, False)[1]
        lenNoD[srfcrvLen] = children1[m]
    shortest = sorted(lenNoD)[0]
    winnerNode1 = lenNoD[shortest]

    children2 = winnerNode2.get_children()
    lenNoD = {}
    for m in range(len(midPts2)):
        inputPts = [fixPt1, winnerNode1.midpoint, midPts2[m], fixPt2]
        srfcrvLen = ghc.CurveOnSurface(surface, inputPts, False)[1]
        lenNoD[srfcrvLen] = children2[m]
    shortest = sorted(lenNoD)[0]
    winnerNode2 = lenNoD[shortest]

#--------------------------------------------------------------------------------------
# Output
Example #5
0
def ConnectPointss(surface, pointss, diagonalDirection, bRing, step):
    # print "bRing",bRing
    # 01
    if (rs.IsSurface(surface)):
        curves = []
        polylines = []
        step = int(step)
        # 11
        if not bRing:
            if diagonalDirection == 1:
                for i in range(len(pointss) - 1):
                    i = len(pointss) - i - 2
                    puvs = []
                    pls = []
                    surfObj = rs.coercerhinoobject(surface).Geometry
                    for j in range(len(pointss[0])):
                        if i + j >= len(pointss):
                            break
                        p = pointss[(i + j)][j]
                        pls.append(p)
                        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                        puvs.append(puv)
                    crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
                    curves.append(crv)
                    polyline = rs.AddPolyline(pls)
                    polylines.append(polyline)
                for i in range(len(pointss[0]) - 1):
                    i = i + 1
                    puvs = []
                    pls = []
                    surfObj = rs.coercerhinoobject(surface).Geometry
                    for j in range(len(pointss)):
                        if i + j >= len(pointss[0]):
                            break
                        p = pointss[j][(i + j)]
                        pls.append(p)
                        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                        puvs.append(puv)
                    crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
                    curves.append(crv)
                    polyline = rs.AddPolyline(pls)
                    polylines.append(polyline)
            if diagonalDirection == -1:
                for i in range(len(pointss) - 1):
                    i = len(pointss) - i - 2
                    puvs = []
                    pls = []
                    surfObj = rs.coercerhinoobject(surface).Geometry
                    for j in range(len(pointss[0])):
                        if i + j >= len(pointss):
                            break
                        p = pointss[(i + j)][len(pointss[0]) - j - 1]
                        pls.append(p)
                        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                        puvs.append(puv)
                    crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
                    curves.append(crv)
                    polyline = rs.AddPolyline(pls)
                    polylines.append(polyline)
                for i in range(len(pointss[0]) - 1):
                    i = i + 1
                    puvs = []
                    pls = []
                    surfObj = rs.coercerhinoobject(surface).Geometry
                    for j in range(len(pointss)):
                        if i + j >= len(pointss[0]):
                            break
                        p = pointss[j][len(pointss[0]) - (i + j) - 1]
                        pls.append(p)
                        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                        puvs.append(puv)
                    crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
                    curves.append(crv)
                    polyline = rs.AddPolyline(pls)
                    polylines.append(polyline)
            if diagonalDirection == 0:
                polylines = [rs.AddPolyline(pls) for pls in pointss]
        # 11 成环
        else:
            # print len(pointss)
            for i in range(int(len(pointss) / step)):
                puvs = []
                surfObj = rs.coercerhinoobject(surface).Geometry
                pls = []
                for j in range(len(pointss[0])):
                    # print  (i*step+j*diagonalDirection)%len(pointss)
                    p = pointss[(i * step + j * diagonalDirection) %
                                len(pointss)][j]
                    puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                    puvs.append(puv)
                    pls.append(p)
                crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
                curves.append(crv)
                polyline = rs.AddPolyline(pls)
                polylines.append(polyline)
    return curves
Example #6
0
def InterporateCurves(surface,
                      curves,
                      m,
                      n,
                      loop,
                      bAdaptive,
                      bRatio,
                      bRing=False):
    """在两个方向上分别生成m,n条生成插值曲线"""
    bEdgeBePoint = False
    m = int(m)
    n = int(n)
    icurvesn = []
    icurvesm = []
    ipointssnm = []
    ipointssmn = []
    if len(curves) == 4:
        curve01 = curves[0]
        curve12 = curves[1]
        curve23 = curves[2]
        curve30 = curves[3]
    if len(curves) == 3:
        curve01 = curves[0]
        curve12 = curves[1]
        curve23 = rs.CurveEndPoint(curves[1])
        curve30 = curves[2]
    rm = 1
    rn = 1
    # print len(curves)
    if bRatio:
        rm = (rs.CurveLength(curve23) / rs.CurveLength(curve01))**(1 / (m))
        # rn=1
        rn = (rs.CurveLength(curve30) / rs.CurveLength(curve12))**(1 / (n))
    points01 = DivideCurveByNumberAndRatio(curve01, n + 1, 1 / rn)
    points12 = DivideCurveByNumberAndRatio(curve12, m + 1, rm)
    if len(curves) == 4:
        points23 = DivideCurveByNumberAndRatio(curve23, n + 1, rn)
        global points000
        points000 = points23[:]
    if len(curves) == 3:
        points23 = [curve23] * (n + 2)
    points30 = DivideCurveByNumberAndRatio(curve30, m + 1, 1 / rm)

    # print "points01",points01
    # print "points23",points23

    # if bRing:
    #   points23=ghc.ShiftList(points23,1,True)

    #   if rs.IsCurveClosed(curve23)and rs.IsCurveClosed(curve30):
    #       points30=ghc.ShiftList(points30,1,True)
    bpoints = points01 + points12 + points23 + points30

    if bRing:
        points23 = ghc.ShiftList(points23, 1, True)
    for i in range(n):
        if (rs.IsSurface(surface)):
            icurve = rs.ShortPath(surface, points01[i + 1],
                                  points23[::-1][i + 1])
        else:
            icurve = rs.AddLine(points01[i + 1], points23[::-1][i + 1])
        icurvesn.append(icurve)
    count = 0
    ipointss = []
    while (count < loop):  # 完整的一次循环,count=+2
        ipointssnm = []
        ipointssnm = []
        relativeLengths = []
        if (bAdaptive and count != 0):
            curvesm = icurvesm[:]
            curvesm.insert(0, curve01)
            curvesm.append(curve23)
            sumMidLength = 0
            midLengths = []
            for ii in range(m + 1):
                midLength = (rs.CurveLength(curvesm[ii]) +
                             rs.CurveLength(curvesm[ii + 1])) * 0.5
                midLengths.append(midLength)
                sumMidLength += midLength
            relativeLengths = [
                midLength / sumMidLength for midLength in midLengths
            ]
            points12 = DivideCurveByRelativeLengths(curve12, relativeLengths)
            points30 = DivideCurveByRelativeLengths(
                curve30, list(reversed(relativeLengths)))
        for icurve in icurvesn:
            if (bAdaptive and count != 0):
                # print "relativeLengths1",relativeLengths
                ipoints = DivideCurveByRelativeLengths(icurve, relativeLengths)

            else:
                ipoints = DivideCurveByNumberAndRatio(icurve, m + 1, rm)
            ipointssnm.append(ipoints)
            #    global surfObj
        surfObj = rs.coercerhinoobject(surface).Geometry
        # print surfObj
        icurvesm = []
        for i in range(m):
            if (rs.IsSurface(surface)):
                puvs = []
                p = points30[-(i + 1) - 1]
                puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                puvs.append(puv)
                for j in range(n):
                    # 转换数据类型
                    p = ipointssnm[j][i + 1]
                    puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                    puvs.append(puv)
                if not bRing:
                    p = points12[i + 1]
                    puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                    puvs.append(puv)
                # print (count)
                # print (puvs[2])
                crv = ghc.CurveOnSurface(surfObj, puvs, bRing)[0]
                icurvesm.append(crv)
            else:
                ps = []
                p = points30[-(i + 1) - 1]
                ps.append(p)
                for j in range(n):
                    # 转换数据类型
                    p = ipointssnm[j][i + 1]
                    pm = rs.MeshClosestPoint(surface, p)[0]
                    ps.append(pm)
                # points12和points03的节点位置可能不完全重合,曲线的朝向影响了分段结果
                if not bRing:
                    p = points12[i + 1]
                else:
                    p = points30[-(i + 1) - 1]
                ps.append(p)
                crv = rs.AddPolyline(ps)
                # print rs.IsCurveClosed(crv)
                icurvesm.append(crv)
        count = count + 1
        points03 = list(reversed(points30))
        ipointss = ipointssnm
        ipointss.insert(0, points03)
        if not bRing:
            ipointss.append(points12)
        if (count >= loop):
            print('循环正常结束')
            break
        ipointssmn = []
        relativeLengths = []
        if (bAdaptive and count != 0):
            curvesn = icurvesn[:]
            curvesn.insert(0, curve30)
            curvesn.append(curve12)
            sumMidLength = 0
            midLengths = []
            for ii in range(n + 1):
                midLength = (rs.CurveLength(curvesn[ii]) +
                             rs.CurveLength(curvesn[ii + 1])) * 0.5
                midLengths.append(midLength)
                sumMidLength += midLength
            # print "midLengths",midLengths
            relativeLengths = [
                midLength / sumMidLength for midLength in midLengths
            ]
            points01 = DivideCurveByRelativeLengths(curve01, relativeLengths)
            points23 = DivideCurveByRelativeLengths(
                curve23, list(reversed(relativeLengths)))
            if rs.IsCurveClosed(curve23):
                points23 = ghc.ShiftList(points23, 1, True)
        for icurve in icurvesm:
            if (bAdaptive and count != 0):
                # print "relativeLengths2",relativeLengths
                ipoints = DivideCurveByRelativeLengths(icurve, relativeLengths)
            else:
                ipoints = DivideCurveByNumberAndRatio(icurve, n + 1, 1 / rn)
                # print n+1,1/rn,rs.IsCurveClosed(icurve)
                # print "ipoints",len(ipoints)
            ipointssmn.append(ipoints)
        icurvesn = []
        # global surfObj
        surfObj = rs.coercerhinoobject(surface).Geometry
        # print surfObj
        for i in range(n):
            if (rs.IsSurface(surface)):
                ps = []
                puvs = []
                p = points01[(i + 1)]
                ps.append(p)
                puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                puvs.append(puv)
                for j in range(m):
                    # 转换数据类型
                    p = ipointssmn[j][i + 1]
                    puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                    puvs.append(puv)
                p = points23[-(i + 1) - 1]
                ps.append(p)
                puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
                puvs.append(puv)
                crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
                crvm = rs.AddPolyline(ps)
                icurvesn.append(crv)
            else:
                ps = []
                p = points01[(i + 1)]
                ps.append(p)
                for j in range(m):
                    # 转换数据类型
                    p = ipointssmn[j][i + 1]
                    pm = rs.MeshClosestPoint(surface, p)[0]
                    ps.append(pm)
                p = points23[-(i + 1) - 1]
                ps.append(p)
                crv = rs.AddPolyline(ps)
                icurvesn.append(crv)
        count = count + 1
        ipointss = ipointssmn
        points32 = list(reversed(points23))
        ipointss.insert(0, points01)
        ipointss.append(points32)
        # print count,len(ipointss[0]),len(ipointss[1]),len(ipointss[2]),len(ipointss[3])
        if (count >= 100):
            break
    # print "ipointss",ipointss
    return icurvesm, icurvesn, ipointss