예제 #1
0
def loadLabelByJson(path, scene):

    with open(path) as f:
        jdata = json.load(f)

    scene.label.setCameraHeight(jdata['cameraHeight'])
    scene.label.setLayoutHeight(jdata['layoutHeight'])

    pointsDict = jdata['layoutPoints']
    pointsList = pointsDict['points']

    gPoints = []
    for point in pointsList:
        xyz = tuple(point['xyz'])
        gPoint = data.GeoPoint(scene, None, xyz)
        gPoints.append(gPoint)

    scene.label.setLayoutPoints(gPoints)

    walls = scene.label.getLayoutWalls()

    if 'layoutObj2ds' in jdata:

        obj2dsDict = jdata['layoutObj2ds']
        obj2dsList = obj2dsDict['obj2ds']

        object2ds = []
        for obj2d in obj2dsList:
            gp1 = data.GeoPoint(scene, None, tuple(obj2d['points'][0]))
            gp2 = data.GeoPoint(scene, None, tuple(obj2d['points'][1]))
            wall = walls[int(obj2d['wallIdx'])]
            object2d = data.Object2D(scene, [gp1, gp2], wall)
            object2ds.append(object2d)

        scene.label.setLayoutObject2d(object2ds)
예제 #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 genTmpWall(self, wall):

        gp1 = data.GeoPoint(self.__scene, None, wall.gPoints[0].xyz)
        gp2 = data.GeoPoint(self.__scene, None, wall.gPoints[1].xyz)
        wall = data.WallPlane(self.__scene, [gp1, gp2])

        return wall
예제 #4
0
    def genObject2d(self, points, wall):

        p1 = data.GeoPoint(self.__scene, None, points[0])
        p2 = data.GeoPoint(self.__scene, None, points[1])

        obj = data.Object2D(self.__scene, [p1, p2], wall)
        self.__layoutObjects2d.append(obj)
예제 #5
0
    def updateCorners(self):

        gps = self.gPoints
        scene = self.__scene

        self.corners = [
            data.GeoPoint(scene, None, gps[0].xyz),
            data.GeoPoint(scene, None,
                          (gps[1].xyz[0], gps[0].xyz[1], gps[1].xyz[2])),
            data.GeoPoint(scene, None, gps[1].xyz),
            data.GeoPoint(scene, None,
                          (gps[0].xyz[0], gps[1].xyz[1], gps[0].xyz[2]))
        ]
예제 #6
0
    def genSplitPoints(self, wall, point):

        p1 = data.GeoPoint(self.__scene, None, point)
        p2 = data.GeoPoint(self.__scene, None, point)

        wP1idx = self.__layoutPoints.index(wall.gPoints[0])
        wP2idx = self.__layoutPoints.index(wall.gPoints[1])

        if abs(wP1idx - wP2idx) == len(self.__layoutPoints) - 1:
            self.__layoutPoints.extend((p1, p2))
        else:
            idx = max([wP1idx, wP2idx])
            self.__layoutPoints[idx:idx] = [p1, p2]

        self.genLayoutWallsByPoints(self.__layoutPoints)
예제 #7
0
    def updateCorners(self):

        gps = self.gPoints
        scene = self.__scene
        cameraH = scene.label.getCameraHeight()
        cam2ceilH = scene.label.getCam2CeilHeight()

        self.corners = [
            data.GeoPoint(scene, None,
                          (gps[0].xyz[0], cam2ceilH, gps[0].xyz[2])),
            data.GeoPoint(scene, None,
                          (gps[1].xyz[0], cam2ceilH, gps[1].xyz[2])),
            data.GeoPoint(scene, None,
                          (gps[1].xyz[0], -cameraH, gps[1].xyz[2])),
            data.GeoPoint(scene, None,
                          (gps[0].xyz[0], -cameraH, gps[0].xyz[2]))
        ]
예제 #8
0
    def calcManhLayoutPoints(self, points):

        self.__layoutPoints = []

        manhxyz = utils.alignManhattan(points)
        for xyz in manhxyz:
            gp = data.GeoPoint(self.__scene, None, xyz)
            self.__layoutPoints.append(gp)
예제 #9
0
    def updateCorners(self):

        self.corners = []
        for gp in self.gPoints:
            if self.__isCeiling:
                xyz = (gp.xyz[0], self.height, gp.xyz[2])
            else:
                xyz = (gp.xyz[0], -self.height, gp.xyz[2])
            corner = data.GeoPoint(self.__scene, None, xyz)
            self.corners.append(corner)
예제 #10
0
    def calcInitLayout(self):

        self.cleanLayout()

        samplePoints = []
        for x in np.arange(0.0, 1.0, 0.01):
            coords = (x, 0.5)
            geoPoint = data.GeoPoint(self.__scene, coords)
            samplePoints.append(geoPoint)

        self.calcManhLayoutPoints(samplePoints)
        self.genLayoutWallsByPoints(self.__layoutPoints)

        #self.mergeTrivialWalls(0.5)
        self.mergeTrivialWalls(1.0)
        #self.pushPred.optimizeLayoutBF()
        self.pushPred.optimizeLayoutGS()