Пример #1
0
def calcLayoutPointType(scene):

    walls = scene.layoutWalls
    for i in range(len(walls)):
        w1 = walls[i]
        w2 = walls[(i+1)%len(walls)]
        pc, p1, p2 = w1.getintersection(w2)
        
        v1 = np.array(utils.pointsDirectionPow(pc.xyz, p1.xyz, 1))[[0,2]]
        v1[v1>0] = 1; v1[v1<0] = -1
        v2 = np.array(utils.pointsDirectionPow(pc.xyz, p2.xyz, 1))[[0,2]]
        v2[v2>0] = 1; v2[v2<0] = -1
        n1 = -np.array(w1.normal)[[0,2]]
        n1[n1>0] = 1; n1[n1<0] = -1
        n2 = -np.array(w2.normal)[[0,2]]
        n2[n2>0] = 1; n2[n2<0] = -1
        
        if (v1+n1)[0]==(v2+n2)[0] and (v1+n1)[1]==(v2+n2)[1]:
            pc.type = 0
        else:
            r = -0.0# -0.25
            if w1.planeEquation[3]>r or w2.planeEquation[3]>r:
                pc.type = 2
            else:
                pc.type = 1
Пример #2
0
    def updateGeoPoints(self):

        gps = self.gPoints
        acs = self.attach.corners

        #make sure the gpoints are left-up and right-down
        dis = [[], []]
        xyzs = [
            gps[0].xyz, (gps[1].xyz[0], gps[0].xyz[1], gps[1].xyz[2]),
            gps[1].xyz, (gps[0].xyz[0], gps[1].xyz[1], gps[0].xyz[2])
        ]
        for i in range(2):
            for xyz in xyzs:
                dis[i].append(utils.pointsDistance(xyz, acs[i * 2].xyz))
            xyz = xyzs[dis[i].index(min(dis[i]))]
            gps[i] = data.GeoPoint(self.__scene, None, xyz)

        # stick to wall boundary
        localBbox2d = []
        for i in range(2):
            xyz = list(gps[i].xyz)
            dis = utils.pointsDirectionPow(acs[i * 2].xyz, gps[i].xyz, 2)
            cxz = math.sqrt(dis[0] + dis[2]) / self.attach.width
            cy = math.sqrt(dis[1]) / self.__scene.label.getLayoutHeight()
            if cxz <= 0.03:
                xyz[0] = acs[i * 2].xyz[0]
                xyz[2] = acs[i * 2].xyz[2]
                cxz = 0
            if cy <= 0.03:
                xyz[1] = acs[i * 2].xyz[1]
                cy = 0
            gps[i] = data.GeoPoint(self.__scene, None, tuple(xyz))
            coord = (cxz, cy) if i == 0 else (1 - cxz, 1 - cy)
            localBbox2d.append(coord)
        self.localBbox2d = tuple(localBbox2d)
Пример #3
0
def alignManhattan(gps):

    class Edge:
        def __init__(self, axis, p1):
            self.axis = axis
            self.points = [p1]
            self.center = (0, 0, 0)

    n = len(gps)
    if n < 2:
        print('cant align manh world')
        return
    
    #create edges, calculate axis type and contain points
    edges = []
    for i in range(n):

        dist = utils.pointsDirectionPow(gps[i].xyz, gps[(i+1)%n].xyz, 2)
        axis = 0 if dist[0] >= dist[2] else 1

        if len(edges) == 0:
            edges.append(Edge(axis, gps[i]))
        elif not edges[-1].axis == axis:
            edges[-1].points.append(gps[i])
            edges.append(Edge(axis, gps[i]))
        elif edges[-1].axis == axis:
            edges[-1].points.append(gps[i])

    #merge last edge to first if they have same axis
    if edges[0].axis == edges[-1].axis:
        edges[0].points += edges[-1].points
        edges.pop()

    #calculate each edge's center position
    for edge in edges:
        pList = [p.xyz for p in edge.points]
        edge.center = utils.pointsMean(pList)

    #calculate manhattan corner points
    manhPoints = []
    for i in range(len(edges)):
        if edges[i].axis == 0:
            manhPoints.append((edges[i-1].center[0], 0, edges[i].center[2]))
        elif edges[i].axis == 1:
            manhPoints.append((edges[i].center[0], 0, edges[i-1].center[2]))

    return manhPoints