Ejemplo n.º 1
0
    def curvature(self, points=None):
        """"""
        if not points:
            points = self.heightfield()

        curvature = []

        if rs.IsPolysurface(self.guid):
            rs.EnableRedraw(False)
            faces = {}
            for point in points:
                bcp = rs.BrepClosestPoint(self.guid, point)
                uv = bcp[1]
                index = bcp[2][1]
                try:
                    face = faces[index]
                except (TypeError, IndexError):
                    face = rs.ExtractSurface(self.guid, index, True)
                    faces[index] = face
                props = rs.SurfaceCurvature(face, uv)
                curvature.append((point, (props[1], props[3], props[5])))
            rs.DeleteObjects(faces.values())
            rs.EnableRedraw(False)
        elif rs.IsSurface(self.guid):
            for point in points:
                bcp = rs.BrepClosestPoint(self.guid, point)
                uv = bcp[1]
                props = rs.SurfaceCurvature(self.guid, uv)
                curvature.append((point, (props[1], props[3], props[5])))
        else:
            raise RhinoSurfaceError('object is not a surface')

        return curvature
Ejemplo n.º 2
0
def getCurvatureOfClosestPoint(pt, srf, scale=None):
    if scale is None:
        global curvatureScale
        scale = curvatureScale

    u, v = rs.SurfaceClosestPoint(srf, pt)
    c = rs.SurfaceCurvature(srf, (u, v))

    if c is None:
        return 0
    else:
        return c[7] * scale
Ejemplo n.º 3
0
def SurfaceTensorField(srf_id, Nu, Nv):
    uDomain = rs.SurfaceDomain(srf_id, 0)
    vDomain = rs.SurfaceDomain(srf_id, 1)

    t = []
    k = []
    for i in range(Nu):
        u = uDomain[0] + (i/Nu)*(uDomain[1]-uDomain[0])
        for j in range(Nv):
            v = vDomain[0]+(j/Nv)*(vDomain[1]-vDomain[0])
            t.append( rs.SurfaceFrame(srf_id, (u,v)) )
            k.append( rs.SurfaceCurvature(srf_id, (u,v))[5] )
    return t,k
Ejemplo n.º 4
0
def MovePt2PtBasedOnSrf(fromPt, toPt, toSrf):

    u, v = rs.SurfaceClosestPoint(toSrf, toPt)

    vt = rs.VectorCreate(toPt, fromPt)
    vt = rs.VectorUnitize(vt)

    c = rs.SurfaceCurvature(toSrf, (u, v))
    c = c[7]

    vt = rs.VectorScale(vt, 10 * c)

    return rs.PointAdd(toPt, vt)
def SurfaceCurvature(srf_id, u0, u1, v0, v1):
    gsum = 0.0
    ustep = 0.1 * (u1 - u0)
    vstep = 0.1 * (v1 - v0)
    u = u0
    while u < u1 + (0.5 * ustep):
        v = v0
        while v < v1 + (0.5 * vstep):
            gdat = rs.SurfaceCurvature(srf_id, (u, v))
            if gdat: gsum += gdat[6]
            v += vstep
        u += ustep
    return gsum
Ejemplo n.º 6
0
def MapCurvatureStep(srf_id, uvPt, max, reverse, accuracy):
    data_curvature = rs.SurfaceCurvature(srf_id, uvPt)
    if not data_curvature: return
    vec = data_curvature[5]
    if max: vec = data_curvature[3]

    if reverse: vec = rs.VectorReverse(vec)
    vec = rs.VectorUnitize(vec)
    vec = rs.VectorScale(vec, accuracy)

    dPoint = rs.VectorAdd(data_curvature[0], vec)
    nPoint = rs.SurfaceClosestPoint(srf_id, dPoint)
    mPoint = rs.EvaluateSurface(srf_id, nPoint)

    if rs.Distance(mPoint, data_curvature[0])< (0.5*accuracy): return
    return nPoint
Ejemplo n.º 7
0
def nurbs_to_mesh_ani(srf,trg_len_min,trg_len_max,vis):
    trg_len = trg_len_max
    
    
    u_div = 30
    v_div = 30
    u_domain = rs.SurfaceDomain(srf, 0)
    v_domain = rs.SurfaceDomain(srf, 1)
    u = (u_domain[1] - u_domain[0]) / (u_div - 1)
    v = (v_domain[1] - v_domain[0]) / (v_div - 1)
    

    gauss = []
    for i in xrange(u_div):
        for j in xrange(v_div):
            data = rs.SurfaceCurvature (srf, (u_domain[0] + u * i, v_domain[0] + v * j))
            gauss.append(abs(data[7]))
            pt = rs.EvaluateSurface(srf,u_domain[0] + u * i, v_domain[0] + v * j)
            #rs.AddTextDot(round(abs(data[7]),3),pt)
    gauss_max = max(gauss)
    gauss_min = min(gauss)
    
    print gauss_max
    print gauss_min
    

            
    crvs = rs.DuplicateEdgeCurves(srf) 
    
    if len(crvs)>1:
        joint = rs.JoinCurves(crvs,True)
        if joint:
            if len(joint) > 2:
                print "hole" 
    else:
        if rs.IsCurveClosed(crvs[0]):
            joint = [crvs[0]]
            print "closed"#e.g. if it is a disk
        else:
            print "Surface need to be split"#e.g. if it is a sphere
            return None
         

    
    #sort curves (this is cheating: the longer curve is not necessarily the outer boundary!) 
    #todo: an inside outside comparison in uv space
    crvs_len = [rs.CurveLength(crv) for crv in joint] 
    crvs  = [x for (_,x) in sorted(zip(crvs_len,joint))]
    
    outer_crv =  crvs[-1]
    inner_crvs = crvs[:-1]
    
    outer_bound_pts = get_boundary_points(outer_crv,trg_len)
    if inner_crvs: inner_bounds_pts = [get_boundary_points(crvs,trg_len) for crvs in inner_crvs]
    
    all_pts = copy.copy(outer_bound_pts)
    if inner_crvs: 
        for pts in inner_bounds_pts:
            all_pts += pts
    
    outbound_keys = get_boundary_indecies(outer_bound_pts,all_pts)

    inbounds_keys = []
    if inner_crvs:
        for inner_bound_pts in inner_bounds_pts:
            inbounds_keys.append(get_boundary_indecies(inner_bound_pts,all_pts))   
     

    rs.DeleteObjects(crvs)        

    all_pts_uv = convert_to_uv_space(srf,all_pts) 
    tris = delaunay(all_pts_uv,outbound_keys,inbounds_keys)
    
    mesh = Mesh()
    
    for i,pt in enumerate(all_pts):
        mesh.add_vertex(str(i),{'x' : pt[0], 'y' : pt[1], 'z' : pt[2]})
    for tri in tris:
        mesh.add_face(tri)  
    
    edge_lengths = []
    for u, v in mesh.edges():
        edge_lengths.append(mesh.edge_length(u, v))
    
    target_start = max(edge_lengths)/22

    rs.EnableRedraw(False)
    
    srf_id = rs.coerceguid(srf, True)
    brep = rs.coercebrep(srf_id, False)   
    tolerance = rs.UnitAbsoluteTolerance()
    
    fixed = outbound_keys+[item for sublist in inbounds_keys for item in sublist]
    user_func = wrapper(brep,tolerance,fixed,vis)
    

    remesh_ani(srf,mesh,trg_len_min,trg_len_max,gauss_min,gauss_max,
       tol=0.1, divergence=0.008, kmax=400,
       target_start=target_start, kmax_approach=200,
       verbose=False, allow_boundary=False,
       ufunc=user_func)
 
    for k in xrange(1):
        mesh_smooth_on_local_plane(mesh,k=1,d=0.2,fixed=fixed)  
        user_func(mesh,k)
    
    return draw_light(mesh,temp = False)    
    
    


    
import rhinoscriptsyntax as rs

surface_id, _, _, _, _, _ = rs.GetSurfaceObject(
    "Select surface for curvature measurement")
point = rs.GetPointOnSurface(
    surface_id, "Select point on surface for curvature measurement")
u, v = rs.SurfaceClosestPoint(surface_id, point)

#point, normal, kappa_u, direction_u, kappa_v, direction_v, gaussian, mean =
surface_curvature = rs.SurfaceCurvature(surface_id, (u, v))

point, normal, kappa_u, direction_u, kappa_v, direction_v, gaussian, mean = surface_curvature

print "Surface curvature evaluation at parameter: ({0}, {1})".format(u, v)

print "  3-D Point: ({0}, {1}, {2})".format(point.X, point.Y, point.Z)

print "  3-D Normal: ({0}, {1}, {2})".format(normal.X, normal.Y, normal.Z)

print "  Maximum principal curvature: {0} ({1}, {2}, {3})".format(
    kappa_u, direction_u.X, direction_u.Y, direction_u.Z)

print "  Minimum principal curvature: {0} ({1}, {2}, {3})".format(
    kappa_v, direction_v.X, direction_v.Y, direction_v.Z)

print "  Gaussian curvature: {0}".format(gaussian)
print "  Mean curvature: {0}".format(mean)