Exemplo n.º 1
0
def add_sharp_edges(polys, points, sharp_edges):
    fixed_nodes = []
    if sharp_edges:
        for edge in sharp_edges:
            pt1, pt2 = rs.CurveStartPoint(edge), rs.CurveEndPoint(edge)
            index1 = str(rs.PointArrayClosestPoint(points, pt1))
            index2 = str(rs.PointArrayClosestPoint(points, pt2))
            flag1 = False
            flag2 = False
            for key in polys:
                indices = polys[key]['indices']
                for i, index in enumerate(indices):

                    if index == index1:
                        if flag1:
                            #rs.AddTextDot(index,points[int(index)])
                            points.append(points[int(index)])
                            indices[i] = str(len(points) - 1)
                        flag1 = True
                    if index == index2:
                        if flag2:
                            #rs.AddTextDot(index,points[int(index)])
                            points.append(points[int(index)])
                            indices[i] = str(len(points) - 1)
                        flag2 = True
                polys[key]['indices'] = indices
    return polys, points
Exemplo n.º 2
0
def get_faces_from_polylines(polys, points):
    for key in polys:
        poly_points = polys[key]['points']
        indices = []
        for point in poly_points:
            indices.append(str(rs.PointArrayClosestPoint(points, point)))
        polys[key]['indices'] = indices
    return polys
Exemplo n.º 3
0
def testAlign(crv1,crv2):
    start=rs.CurveStartPoint(crv2)
    crv1Start=rs.CurveStartPoint(crv1)
    pts=rs.PolylineVertices(crv1)
    index=rs.PointArrayClosestPoint(pts,start)
    crv1Pt=pts[index]
    if index!=0:
        return False
    else:
        return True
Exemplo n.º 4
0
def mesh_to_mesh(rhino_mesh,trg_len,vis):
    
    print rhino_mesh
    crvs = rs.DuplicateMeshBorder(rhino_mesh)
    
    
    
    vertices = [map(float, vertex) for vertex in rs.MeshVertices(rhino_mesh)]
    faces = map(list, rs.MeshFaceVertices(rhino_mesh))
    
    mesh  = Mesh.from_vertices_and_faces(vertices, faces)
    
    
    pts_objs = rs.GetObjects("Fixed Points",1)
    rs.EnableRedraw(False)
    if pts_objs:
        pts_fixed = [rs.PointCoordinates(obj) for obj in pts_objs]
        
        pts = []
        index_key = {}
        count = 0
        for k, a in mesh.vertices_iter(True):
            pts.append((a['x'], a['y'], a['z'])) 
            index_key[count] = k
            count += 1
        
        fixed = [] 
        for pt_fix in pts_fixed:
            index = rs.PointArrayClosestPoint(pts,pt_fix)
            fixed.append(index_key[index])
    
    

      
    edge_lengths = []
    for u, v in mesh.edges():
        edge_lengths.append(mesh.edge_length(u, v))
    target_start = max(edge_lengths)/2  
     
    id = rs.coerceguid(rhino_mesh, True)
    mesh_rhino_obj = rs.coercemesh(id, False)
    
    boundary = set(mesh.vertices_on_boundary())
    user_func = wrapper_2(crvs,mesh_rhino_obj,fixed,boundary,vis)
        
    rs.HideObject(rhino_mesh)
        
    remesh(mesh,trg_len,
       tol=0.1, divergence=0.01, kmax=400,
       target_start=target_start, kmax_approach=200,
       verbose=False, allow_boundary=True,
       ufunc=user_func)  
        
    rs.DeleteObject(rhino_mesh)
    return draw_light(mesh,temp = False) 
Exemplo n.º 5
0
def close_curve():
    curve_a = curves[0]
    curve_b = curves[1]
    points_a = [rs.CurveStartPoint(curve_a), rs.CurveEndPoint(curve_a)]
    points_b = [rs.CurveStartPoint(curve_b), rs.CurveEndPoint(curve_b)]
    for test_point in points_a:
        closest_point = rs.PointArrayClosestPoint(points_b, test_point)
        curves.append(rs.AddLine(test_point, points_b[closest_point]))
        points_b.pop(closest_point)
    rs.JoinCurves(curves, True)
    print "Curves closed"
Exemplo n.º 6
0
def partitionPts (centroids, allPts):
    partitionedPts = []
    indexList = []
    for i in range(0,len(allPts)):
        indexList.append(rs.PointArrayClosestPoint(centroids,allPts[i]))
    for i in range(0,len(centroids)):
        tempList = []
        for j in range(0,len(allPts)):
            if(indexList[j]==i):
                tempList.append(allPts[j])
        partitionedPts.append(tempList)
    return partitionedPts #returns a list of lists of pt GUIDS
Exemplo n.º 7
0
def proximityPts(pts, initialIndex):
    ptsRemaining = pts
    ptsActivated = []
    initialIndex = initialIndex
    ptsActivated.append(pts[initialIndex])
    del ptsRemaining[initialIndex]
    
    for i in range(0, len(pts)):
        closestIndex = rs.PointArrayClosestPoint(ptsRemaining, ptsActivated[-1])
        ptsActivated.append(pts[closestIndex])
        del ptsRemaining[closestIndex]
    
    return ptsActivated
Exemplo n.º 8
0
def grow(num):
	#this method grows the global ptArray list
	#this method grows teh pointClooud represented by this list
	if num == 0:
		return 0
	randPt = randomPt(-25,25,-25,25,0,50)
	
	joinNode = nodeList[rs.PointArrayClosestPoint(ptArray, randPt)]
	joinPt = joinNode.pos
	joinVec = rs.VectorSubtract(randPt, joinPt)
	
	growthVec = rs.VectorUnitize(joinVec)
	newPt = rs.VectorAdd(joinPt, growthVec)
	
	newNode = node(newPt, joinNode)
	g = grow(num-1)
Exemplo n.º 9
0
def Main():
    mesh=rs.GetObjects("select mesh",rs.filter.mesh)
    start=rs.GetObject("select start points",rs.filter.point)
    refVec = rs.GetObject("select crv direction",rs.filter.curve)
    ang=rs.GetReal("enter branching angle",30)
    length=rs.GetReal("enter branch length",15)
    gen=rs.GetInteger("enter number of generations",3)
    lines=rs.AddLayer("branch",[255,0,0])
    rs.EnableRedraw(False)
    rs.CurrentLayer(lines)
    vec=tanVec(refVec,start)
    centers=rs.MeshFaceCenters(mesh)
    index=rs.PointArrayClosestPoint(centers,start)
    norm=rs.MeshFaceNormals(mesh)[index]
    vec=rs.VectorRotate(vec,0,norm)
    branches=baseBranch(mesh,start,vec,ang,length,gen)
    return branches
Exemplo n.º 10
0
    def grow(self):
        x1 = self.node[0][0] - (self.size[1] / 2)
        x2 = self.node[0][0] + (self.size[1] / 2)
        y1 = self.node[0][1] - (self.size[1] / 2)
        y2 = self.node[0][1] + (self.size[1] / 2)
        z1 = self.node[0][2]
        z2 = self.node[0][2] + self.size[0]

        i = 0
        while i < self.twigCount:
            randPt = placePt(x1, x2, y1, y2, z1, z2)
            joinPt = self.node[rs.PointArrayClosestPoint(self.node, randPt)]
            vec = rs.VectorScale(
                rs.VectorUnitize(rs.VectorSubtract(randPt, joinPt)),
                self.segLength)
            newPt = rs.PointAdd(joinPt, vec)
            self.addTwig(joinPt, newPt)
            i += 1
Exemplo n.º 11
0
 def closest_points(self,rh_objects):
     closest_list = []
     
     test_object = rh_objects[0]
     closest_list.append(test_object)
     while True:
         if len(rh_objects) == 0:
             break
         rh_objects.pop(rh_objects.index(test_object))
         if len(rh_objects) == 0:
             break
         
         closest_point_index = rs.PointArrayClosestPoint([rs.PointCoordinates(i.start_point) for i in rh_objects],test_object.point)
         closest_object = rh_objects[closest_point_index]
         closest_list.append(closest_object)
         test_object = closest_object
     #rs.DeleteObjects([point for point in point_cloud])
     return closest_list
def generate():
    initpts()
    del listgoal[:]
    del agentlist[:]
    for j in range(len(start)):
        index = rs.PointArrayClosestPoint(
            goalcy, start[j])  #calculate the closest pt from goal to agent[j]
        vec = rs.VectorCreate(goalcy[index], start[j])
        vec = rs.VectorScale(vec, 3)
        listgoal.append(goalcy[index])  #store the calculated pts into list
        goalcy.pop(index)  #remove the calculating goal pt from goal list

        #velrnd = [(rnd.random()*2) - 1,(rnd.random()*2) - 1,(rnd.random()*2) - 1]
        """
       uniform
       """
        velrnd = [(rnd.uniform(-1, 1) * 2), (rnd.uniform(-1, 1) * 2),
                  (rnd.random() * 2)]

        vel = rs.VectorAdd(velrnd, vec)
        agentlist.append(agent(start[j], vel, 0.3, 1))
cube_pts = rs.AddPoints(pt)

cube_range = range(int(cube_dim) , int(cube_num * cube_dim) , int(cube_dim))

xdir = [rs.CopyObject(i, (r , 0 , 0)) for r in cube_range for i in cube_pts]

xdir = cube_pts + xdir

ydir=[rs.CopyObject(x , (0 , r , 0)) for r in cube_range for x in xdir]

zdir=[rs.CopyObject(x , (0 , 0 , r)) for r in cube_range for x in xdir] + \
     [rs.CopyObject(y , (0 , 0 , r)) for r in cube_range for y in ydir]

all_cube_pts = rs.coerce3dpointlist(xdir + ydir + zdir)

index = [rs.PointArrayClosestPoint(point_cloud, pt) for pt in all_cube_pts]

mesh_pts = [point_cloud[i] for i in index]

dist = [rs.Distance(c,p) for c,p in zip(all_cube_pts,mesh_pts)]

cubes = create_set(all_cube_pts)
dist = create_set(dist)

triangles = [polygonise(d,c,isolevel) for d,c in zip(dist,cubes)]

point1=[i[0] for tri in triangles for t in tri for i in t]
point2=[i[1] for tri in triangles for t in tri for i in t]
point3=[i[2] for tri in triangles for t in tri for i in t]

tri_pts = [rs.AddPoint(p1,p2,p3) for p1,p2,p3 in zip(point1 , point2 , point3)]
Exemplo n.º 14
0
znum = randZ(10)

#initializing first box, based on random numbers created with xnum, etc
#initializing box zero array
boxes = []
array = rs.AddBox([(0,0,0),(xnum,0,0),(xnum,ynum,0),\
(0,ynum,0),(0,0,znum),(xnum,0,znum),(xnum,ynum,znum),(0,ynum,znum)])
boxes.append(array)

#make random point, move that point closer to closest point in pts array
for i in range(1, 10):
    xnum = randX(10)
    ynum = randY(10)
    znum = randZ(10)
    pt = rs.AddPoint(placePt(100, 100, 100))
    index = rs.PointArrayClosestPoint(pts, pt)
    cp = pts[index]
    vect = rs.VectorCreate(cp, pt)
    unitVect = rs.VectorUnitize(vect)
    subVect = vect - unitVect
    newPt = rs.MoveObject(pt, subVect)
    #find newPt coordinates to feed into the 8 needed box corners
    newPtCoord = rs.PointCoordinates(newPt)
    #take newPt coordinates index 0,1, or 2 for x,y, or z respectively,
    #add random xnum,ynum, or znum to respective index
    newboxArray = rs.AddBox([(newPtCoord),(newPtCoord[0]+xnum,newPtCoord[1],newPtCoord[2]),\
    (newPtCoord[0]+xnum,newPtCoord[1]+ynum,newPtCoord[2]),(newPtCoord[0],newPtCoord[1]+ynum,newPtCoord[2]),\
    (newPtCoord[0],newPtCoord[1],newPtCoord[2]+znum),(newPtCoord[0]+xnum,newPtCoord[1],\
    newPtCoord[2]+znum),(newPtCoord[0]+xnum,newPtCoord[1]+ynum,newPtCoord[2]+znum),\
    (newPtCoord[0],newPtCoord[1]+ynum,newPtCoord[2]+znum)])
    pts.append(newPt)
Exemplo n.º 15
0
def Main():
    #SETUP
    #-------------------------------------------------------------------------------------------------------
    #select the mesh to work on ////////////////////////////////////////////////////////////////////
    strMesh         = rs.GetObject ("select mesh to work on", 32)   
    # store the mesh face vertices - we'll need it later to rebuild the mesh
    arrFaceVertices = rs.MeshFaceVertices(strMesh)
    #select the attractors points       ////////////////////////////////////////////////////////////////////
    attrs           = rs.GetObjects ("select the attractors for direction - either points or curves", 5)
    # here we need to translate the attractors (IDS of points and curves that the user gave us) to coordinates
    #--------------------------------------------------------------------------
    arrAttractors = []
    for attr in attrs:
        if rs.IsCurve(attr) :
            #if it is a curve - i need to find the closest point to the current agent
            #right now i'll set it up to array(0,0,0) and i'll replace those values in the do loop later
            arrAttractors.append([0,0,0])
        else : 
            arrAttractors.append( rs.PointCoordinates(attr) )
    #select the agents          ////////////////////////////////////////////////////////////////////
    arrStrPtAgents = rs.GetObjects ("select Agents to move on the mesh", 1) 
    dblStep        = rs.GetReal("please type the step size of the agents' deformation factor",1)
    # here we need to translate the agents (points that the user gave us
    # to vertices on the mesh....
    #--------------------------------------------------------------------------
    # start a new array same size as the agents-points - call it agentsOnmesh
    agentsOnMesh = []       
    # get the mesh vertices
    arrVTXS         = rs.MeshVertices (strMesh)
    # loop throught the points-agents that the user gave us,
    for strPtAgent in arrStrPtAgents:
        arrPtAgent = rs.PointCoordinates(strPtAgent)
        # use point array closest point to determine which mesh vertex is closest to the current agent-point
        # store that index from pointarrayclosestpoint in the agentsOnMesh(i)       
        agentsOnMesh.append( rs.PointArrayClosestPoint(arrVTXS,arrPtAgent) )
        # end loop  
    #-------------------------------------------------------------------------------------------------------
    #RUN
    #-------------------------------------------------------------------------------------------------------    
    #loop for number of steps
    for e in range(100):
        #   get the mesh vertices of the current mesh arrVTXS
        arrVTXS = rs.MeshVertices (strMesh)
        #   start a arrNEWVTXS and make it equal to arrVTXS (for now)
        arrNEWVTXS = arrVTXS[:]
        #   i loop through each index in agentsOnMesh
        i = 0
        for agentOnMesh in  agentsOnMesh:
            # MOVE THE MESH POINT --------------------------------------------------------------------------
            j = 0
            for attr in attrs :
                if rs.IsCurve(attr) :
                    #here we find the closestpoint on the curve attractors from the current agent
                    dblParam = rs.CurveClosestPoint(attr,arrVTXS[agentOnMesh])
                    arrAttractors[j] = rs.EvaluateCurve(attr,dblParam)
                    j += 1
            ClosestAttIndex = rs.PointArrayClosestPoint(arrAttractors,arrVTXS[agentOnMesh])
            # make a vector from arrVTXS(agentsOnMesh(i)) towards the closest attractor arrAttractors(ClosestAttIndex)
            arrVector = rs.VectorCreate(arrAttractors[ClosestAttIndex], arrVTXS[agentOnMesh])
            arrVector = rs.VectorUnitize(arrVector)
            arrVector = rs.VectorScale(arrVector, dblStep)
            # add the vector to the arrVTXS(agentsOnMesh(i)) and store it in arrNEWVTXS(agentsOnMesh(i))
            arrNEWVTXS[agentOnMesh] = rs.PointAdd(arrVTXS[agentOnMesh], arrVector)
            # MOVE THE AGENT      --------------------------------------------------------------------------
            # get the adjacent mesh vtx indexes from MeshVtxAdjacentVtxs
            arrNeighborIndexes = MeshVtxAdjacentVtxs (strMesh, agentOnMesh, False, False)
            # choose which vtx to "move" to, and store it in agentsOnMesh(i)
            rnd = random.random()
            agentsOnMesh[i] = arrNeighborIndexes[int((rnd)*(len(arrNeighborIndexes)-1))]
            i += 1
        #   add a new mesh in the document using arrNEWVTXS
        strNewMesh = rs.AddMesh(arrNEWVTXS,arrFaceVertices)
        RenderAgentsOnMesh(strNewMesh, agentsOnMesh)
        #   delete the old one 
        rs.DeleteObject(strMesh)
        #   replace the ID of old mesh with the NEW ID
        strMesh = strNewMesh
Exemplo n.º 16
0
 def findAxis(self, point):
     norms = rs.MeshVertexNormals(self.mesh)
     verts = rs.MeshVertices(self.mesh)
     param = rs.PointArrayClosestPoint(verts, point)
     axis = norms[param]
     return axis
point_coord = rs.PointCoordinates(point1)
length = rs.CurveLength(line)
integerize = int(length)

#put points on the line
for i in range(integerize):
    points_on_line = rs.AddPoint(point_coord[0] + i, 0, 0)
    pipe_points.append(points_on_line)

#initializing cloud of line points
line_cloud = pipe_points

#move random cloud of points to closest points on line cloud
for i in range(0, 100):
    pt = rs.AddPoint(place_pts(100, 100, 100))
    index = rs.PointArrayClosestPoint(line_cloud, pt)
    cp = line_cloud[index]
    vect = rs.VectorCreate(cp, pt)

    project = rs.ProjectPointToSurface(pt, pipe, vect)
    rs.AddPoints(project)

    all_points.append(pt)

#making a function to delete objects, but I guess it'd be easier to just do the built in rs.DeleteObject
"""def delete_object(a,b,c,d,e):
    rs.DeleteObjects(object)
    return object
delete_object(pipe_points, all_points, pipe, point1, point2)
#delete_object(all_points)
#delete_object(pipe)
Exemplo n.º 18
0
            multiY = -1

        vecTest = rs.VectorUnitize([vecX, vecY, 0])
        vecTest[0] = vecTest[0] * multiX
        vecTest[1] = vecTest[1] * multiY
        vecTest = vecTest * Radius

        # transform candidate point

        testCoord = [sum(x) for x in zip(testPt, vecTest)]
        testCoord[2] = 0
        #print 'testing the following: ' + str(testCoord)

        # test distance to nearest point in pointcloud

        pointIndex = rs.PointArrayClosestPoint(cloudPointList, testCoord)
        testDistance = rs.Distance(testCoord, cloudPointList[pointIndex])
        #print 'distance equals: ' + str(testDistance)

        # if point is good add to master and active list

        if ((testDistance >= (Radius - 1)) & (0 <= testCoord[0] <= Width) &
            (0 <= testCoord[1] <= Height)):
            print 'success!'
            rs.AddPoint(testCoord)
            niceCoordTuple = round(testCoord[0], 2), round(testCoord[1], 2), 0
            activePointList.append(niceCoordTuple)
            cloudPointList.append(niceCoordTuple)
            countDownLength -= 1

        testCounter += 1
def obj_layer(layer_name):
    '''trying to be able to call obj_layer on clos_pt with a particular
    layer name to give the corresponding cloud points a different parameter
    to move by
    '''
    layer = rs.ObjectsByLayer(layer_name)
    return layer


#initializing cloud of points, vectorize between cloud and original points, move pt by sub_vect amount\
#draw line between pt and original points
for i in range(0, 5):
    pt = rs.AddPoint(place_pts(25, .25, .25))

    #find closest points from cloud to source points
    index = rs.PointArrayClosestPoint(source_pts, pt)
    clos_pt = source_pts[index]
    """
    #find layer of each point, put in
    for pt in og_source_pts:
        pt_name = rs.ObjectLayer(pt)
        change_layer = rs.ObjectLayer(clos_pt, pt_name)
    """
    #rs.ObjectsByLayer()
    #clos_pt_layer = rs.ObjectLayer(og_source_pts)
    #print clos_pt_layer
    #change_layer = rs.ObjectLayer(pt, clos_pt_layer)

    #vector initializing
    vect = rs.VectorCreate(clos_pt, pt)
    unit_vect = rs.VectorUnitize(vect)
Exemplo n.º 20
0
limitToResultsContaining = 'NC'

import rhinoscriptsyntax as rs
fhand = open('brickstacking/data analysis/yelp_academic_dataset_business.json')
xCoords = []
yCoords = []
points = []

for line in fhand:
    if limitToResultsContaining in line:
        line.strip()
        pos = line.find('latitude')
        pos2 = line.find(',',pos)
        pos3 = line.find('longitude')
        pos4 = line.find(',',pos3)
        xCoords.append(float(line[pos+10:pos2]))
        yCoords.append(float(line[pos3+11:pos4]))

for i in range(len(xCoords)):
    points.append(rs.AddPoint(xCoords[i],yCoords[i],0))

for i in range(len(points)):
	closest = rs.PointArrayClosestPoint(points,points[i])
	distance = rs.VectorLength(rs.VectorCreate(closest,points[i]))
	'''if distance > 1 :
		points.pop(i)'''
Exemplo n.º 21
0

point1 = rs.AddPoint(-100, 0, 0)
point2 = rs.AddPoint(100, 0, 0)

#cloud = rs.PointAdd(point1, point2)
#cloud = rs.AddPoints(point1)
cloud = (point1, point2)

line = rs.AddLine(point1, point2)
pipe = rs.AddPipe(line, 0, 4)

all_points = []
for i in range(0, 100):
    pt = rs.AddPoint(place_pts(100, 100, 100))
    index = rs.PointArrayClosestPoint(cloud, pt)
    cp = cloud[index]
    vect = rs.VectorCreate(cp, pt)
    #move = rs.MoveObject(pt,vect)
    #vector = rs.VectorCreate(index, pt)
    #index_points = rs.PointArrayClosestPoint(pipe_points, pt)
    #vector = rs.VectorCreate(index_points, pt)
    #rs.VectorCreate()
    #unit_vector = rs.VectorUnitize(vector)
    #new_pt = rs.MoveObject(pt, unit_vector)

    project = rs.ProjectPointToSurface(pt, pipe, vect)
    rs.AddPoints(project)

    all_points.append(pt)
Exemplo n.º 22
0
polys = get_polyline_points(polylines)
points = get_points_from_polylines(polys)
polys = get_faces_from_polylines(polys, points)
mesh_faces = [polys[key]['indices'] for key in polys]
mesh_vertices = points

mesh_obj = RhinoMesh.from_vertices_and_faces(mesh_vertices, mesh_faces)
mesh_unify_cycle_directions(mesh_obj)

#get fixed nodes
fixed = []
fixed_objs = rs.ObjectsByLayer("SD_fixed")
fixed_coords = [rs.PointCoordinates(obj) for obj in fixed_objs]
if fixed_objs:
    for i, vertex in enumerate(mesh_vertices):
        index = rs.PointArrayClosestPoint(fixed_coords, vertex)
        if rs.Distance(fixed_coords[index], vertex) < 0.1:
            fixed.append(str(i))

rs.DeleteObjects(polylines)

steps = 2

if 1 == 1:
    break_flag = False
    selection = ""
    dis = 0.1

    while True:
        mesh_obj.draw(
            name="control",