Beispiel #1
0
def FitSurface(srf_id, samples):
    surf_points = rs.SurfacePoints(srf_id)
    G = rs.SurfaceEditPoints(srf_id, True, True)
    N = GrevilleNormals(srf_id)
    S = ConvertToUVW(srf_id, samples)

    Forces = [(0, 0, 0) for pt in surf_points]
    Factors = [0.0 for pt in surf_points]
    proximity = 0.0
    translation = 0.0

    for i in range(len(S)):
        proximity += abs(S[i][2])
        for j in range(len(surf_points)):
            local_dist = (S[i][0] - G[j][0])**2 + (S[i][1] - G[j][1])**2
            if local_dist < 0.01: local_dist = 0.01
            local_factor = 1 / local_dist
            local_force = rs.VectorScale(N[j], local_factor * S[i][2])
            Forces[j] = rs.VectorAdd(Forces(j), local_force)
            Factors[j] += local_factor

    Forces = DivideVectorArray(Forces, Factors)

    for i in range(len(surf_points)):
        surf_points[i] = rs.PointAdd(surf_points[i], Forces[i])
        translation += rs.VectorLength(Forces[i])

    srf_N = rs.SurfacePointCount(srf_id)
    srf_K = rs.SurfaceKnots(srf_id)
    srf_W = rs.SurfaceWeights(srf_id)
    srf_D = (rs.SurfaceDegree(srf_id, 0), rs.SurfaceDegree(srf_id, 1))
    return rs.AddNurbsSurface(srf_N, P, srf_K[0], srf_K[1], srf_D, srf_W)
Beispiel #2
0
def FitSurface(srf_id, samples):
    ptSurface = rs.SurfacePoints(srf_id)
    grSurface = rs.SurfaceEditPoints(srf_id, True, True)
    nrSurface = GrevilleNormals(srf_id)

    uvSamples = XYZ_To_UVW(srf_id, samples)
    vecForce = [(0, 0, 0) for p in ptSurface]
    vecFactor = [0 for p in ptSurface]

    #Create null vectors for all control-point forces
    for sample in uvSamples:
        for j in range(len(grSurface)):
            local_distance = (sample[0] - grSurface[j][0])**2 + (
                sample[1] - grSurface[j][1])**2
            local_factor = 100 / (local_distance**2)
            local_force = nrSurface[j]
            local_force = rs.VectorScale(local_force, local_factor * sample[2])
            vecForce[j] = rs.VectorAdd(vecForce[j], local_force)
            vecFactor[j] = vecFactor[j] + local_factor

    for i in range(len(ptSurface)):
        ptSurface[i] = rs.PointAdd(ptSurface[i],
                                   rs.VectorDivide(vecForce[i], vecFactor[i]))

    srf_CP_Count = rs.SurfacePointCount(srf_id)
    srf_Knots = rs.SurfaceKnots(srf_id)
    srf_Weights = rs.SurfaceWeights(srf_id)
    srf_Degree = (rs.SurfaceDegree(srf, 0), rs.SurfaceDegree(srf_id, 1))
    return rs.AddNurbsSurface(srf_CP_Count, ptSurface, srf_Knots[0],
                              srf_Knots[1], srf_Degree, srf_Weights)
Beispiel #3
0
def transformSrf(obj, dicTr):
    if obj:
        point_count = rs.SurfacePointCount(obj)
        points = rs.SurfacePoints(obj)
        knots = rs.SurfaceKnots(obj)
        degree = rs.SurfaceDegree(obj)
    else:
        return None
    for k in dicTr:
        points[k] = dicTr[k]
    if rs.IsSurfaceRational(obj):
        weights = rs.SurfaceWeights(obj)
        objout = rs.AddNurbsSurface(point_count, points, knots[0], knots[1],
                                    degree, weights)
    else:
        objout = rs.AddNurbsSurface(point_count, points, knots[0], knots[1],
                                    degree)
    if objout:
        rs.SelectObject(objout)
        rs.ObjectName(objout, "mod")
        return objout
    else:
        return objout
Beispiel #4
0
    def __init__(self):

        the_filename = 'longsinglesurf.txt'
        keys = [0]
        self.maker = {}
        for key in keys:
            self.maker[key] = SurfacetoRhino()
            self.maker[key].GetRhinoSurface(the_filename=the_filename)
            s1 = self.maker[key]
            rs.AddNurbsSurface(point_count=s1.point_count,
                               points=s1.control_vertices,
                               knots_u=s1.uknots,
                               knots_v=s1.vknots,
                               degree=[s1.up, s1.vp],
                               weights=None)
        pass
Beispiel #5
0
    def __init__(self):

        the_filename = 'surface_data.txt'
        keys = [0, 1, 2, 3, 4]
        self.maker = {}
        for key in keys:
            self.maker[key] = SurfacetoRhino()
            self.maker[key].GetRhinoSurface(the_filename='surface' + str(key) +
                                            'data.txt')
            s1 = self.maker[key]
            rs.AddNurbsSurface(point_count=s1.point_count,
                               points=s1.control_vertices,
                               knots_u=s1.uknots,
                               knots_v=s1.vknots,
                               degree=[s1.up, s1.vp],
                               weights=None)
        pass
def FitSurface(srf_id, samples):
    ptSurface = rs.SurfacePoints(srf_id)
    grSurface = rs.SurfaceEditPoints(idSrf, True, True)
    nrSurface = GrevilleNormals(srf_id)

    uvSamples = XYZ_To_UVW(srf_id, samples)
    #Create null vectors for all control-point forces
    vecForce = [(0,0,0) for pt in ptSurface]

    for i in range(len(uvSamples)):
        LocalCP = NearestUV(uvSamples[i], grSurface)
        LocalForce = nrSurface[LocalCP]
        LocalForce = rs.VectorScale(LocalForce, uvSamples[i][2])
        vecForce[LocalCP] = rs.VectorAdd(vecForce[LocalCP], LocalForce)
	
    ptSurface = [rs.PointAdd(ptSurface[i], vecForce[i]) for i in range(len(ptSurface))]

    srf_CP_Count = rs.SurfacePointCount(srf_id)
    srf_Knots = rs.SurfaceKnots(srf_id)
    srf_Weights = rs.SurfaceWeights(srf_id)
    srf_Degree = (rs.SurfaceDegree(srf_id, 0), rs.SurfaceDegree(srf_id, 1))
    return rs.AddNurbsSurface(srf_CP_Count, ptSurface, srf_Knots[0], srf_Knots[1], srf_Degree, srf_Weights)