コード例 #1
0
    def testBoundingSphereFromPoints(self):
        sphere = BoundingSphere()
        self.failUnless(len(sphere.center) == 0)
        self.failUnless(sphere.radius == 0.0)

        self.failUnless(sphere.minPointX[0] == float('inf'))
        self.failUnless(sphere.minPointY[1] == float('inf'))
        self.failUnless(sphere.minPointZ[2] == float('inf'))

        self.failUnless(sphere.maxPointX[0] == float('-inf'))
        self.failUnless(sphere.maxPointY[1] == float('-inf'))
        self.failUnless(sphere.maxPointZ[2] == float('-inf'))

        points = [[1.1, 3.2, 4.9], [3.1, 1.0, 21.4], [9.1, 3.2, 2.0], [2.0, 4.0, 9.5]]
        sphere.fromPoints(points)

        self.failUnless(sphere.minPointX[0] != float('inf'))
        self.failUnless(sphere.minPointY[1] != float('inf'))
        self.failUnless(sphere.minPointZ[2] != float('inf'))

        self.failUnless(sphere.maxPointX[0] != float('-inf'))
        self.failUnless(sphere.maxPointY[1] != float('-inf'))
        self.failUnless(sphere.maxPointZ[2] != float('-inf'))

        for point in points:
            distance = c3d.distance(sphere.center, point)
            self.failUnless(distance <= sphere.radius)

        # Point outside the sphere
        pointOutside = [1000.0, 1000.0, 1000.0]
        distance = c3d.distance(sphere.center, pointOutside)
        self.failUnless(distance > sphere.radius)
コード例 #2
0
    def testBoundingSphereFromPoints(self):
        sphere = BoundingSphere()
        self.failUnless(len(sphere.center) == 0)
        self.failUnless(sphere.radius == 0.0)

        self.failUnless(sphere.minPointX[0] == float('inf'))
        self.failUnless(sphere.minPointY[1] == float('inf'))
        self.failUnless(sphere.minPointZ[2] == float('inf'))

        self.failUnless(sphere.maxPointX[0] == float('-inf'))
        self.failUnless(sphere.maxPointY[1] == float('-inf'))
        self.failUnless(sphere.maxPointZ[2] == float('-inf'))

        points = [[1.1, 3.2, 4.9], [3.1, 1.0, 21.4], [9.1, 3.2, 2.0],
                  [2.0, 4.0, 9.5]]
        sphere.fromPoints(points)

        self.failUnless(sphere.minPointX[0] != float('inf'))
        self.failUnless(sphere.minPointY[1] != float('inf'))
        self.failUnless(sphere.minPointZ[2] != float('inf'))

        self.failUnless(sphere.maxPointX[0] != float('-inf'))
        self.failUnless(sphere.maxPointY[1] != float('-inf'))
        self.failUnless(sphere.maxPointZ[2] != float('-inf'))

        for point in points:
            distance = c3d.distance(sphere.center, point)
            self.failUnless(distance <= sphere.radius)

        # Point outside the sphere
        pointOutside = [1000.0, 1000.0, 1000.0]
        distance = c3d.distance(sphere.center, pointOutside)
        self.failUnless(distance > sphere.radius)
コード例 #3
0
 def testBoundingSpherePrecision(self):
     tilePath = 'forge/data/quantized-mesh/raron.flat.1.terrain'
     ter = TerrainTile()
     ter.fromFile(tilePath, 7.80938, 7.81773, 46.30261, 46.30799)
     coords = ter.getVerticesCoordinates()
     llh2ecef = lambda x: LLH2ECEF(x[0], x[1], x[2])
     coords = map(llh2ecef, coords)
     sphere = BoundingSphere()
     sphere.fromPoints(coords)
     for coord in coords:
         distance = c3d.distance(sphere.center, coord)
         self.failUnless(distance <= sphere.radius)
コード例 #4
0
 def testBoundingSpherePrecision(self):
     tilePath = 'forge/data/quantized-mesh/raron.flat.1.terrain'
     ter = TerrainTile()
     ter.fromFile(tilePath, 7.80938, 7.81773, 46.30261, 46.30799)
     coords = ter.getVerticesCoordinates()
     llh2ecef = lambda x: LLH2ECEF(x[0], x[1], x[2])
     coords = map(llh2ecef, coords)
     sphere = BoundingSphere()
     sphere.fromPoints(coords)
     for coord in coords:
         distance = c3d.distance(sphere.center, coord)
         self.failUnless(distance <= sphere.radius)
コード例 #5
0
 def testBoundingSphereAssign(self):
     center = [1, 3, 12]
     radius = 8
     sphere = BoundingSphere(center=center, radius=radius)
     self.failUnless(sphere.center[0] == 1.0)
     self.failUnless(sphere.center[1] == 3.0)
     self.failUnless(sphere.center[2] == 12.0)
     self.failUnless(sphere.radius == 8.0)
コード例 #6
0
    def fromTerrainTopology(self, topology, bounds=None):
        if not isinstance(topology, TerrainTopology):
            raise Exception('topology object must be an instance of TerrainTopology')

        # If the bounds are not provided use
        # topology extent instead
        if bounds is not None:
            self._west = bounds[0]
            self._east = bounds[2]
            self._south = bounds[1]
            self._north = bounds[3]
        else:
            # Set tile bounds
            self._west = topology.minLon
            self._east = topology.maxLon
            self._south = topology.minLat
            self._north = topology.maxLat

        bSphere = BoundingSphere()
        bSphere.fromPoints(topology.cartesianVertices)

        ecefMinX = topology.ecefMinX
        ecefMinY = topology.ecefMinY
        ecefMinZ = topology.ecefMinZ
        ecefMaxX = topology.ecefMaxX
        ecefMaxY = topology.ecefMaxY
        ecefMaxZ = topology.ecefMaxZ

        # Center of the bounding box 3d (TODO verify)
        centerCoords = [
            ecefMinX + (ecefMaxX - ecefMinX) * 0.5,
            ecefMinY + (ecefMaxY - ecefMinY) * 0.5,
            ecefMinZ + (ecefMaxZ - ecefMinZ) * 0.5
        ]

        occlusionPCoords = occ.fromPoints(topology.cartesianVertices, bSphere)

        for k, v in TerrainTile.quantizedMeshHeader.iteritems():
            if k == 'centerX':
                self.header[k] = centerCoords[0]
            elif k == 'centerY':
                self.header[k] = centerCoords[1]
            elif k == 'centerZ':
                self.header[k] = centerCoords[2]
            elif k == 'minimumHeight':
                self.header[k] = topology.minHeight
            elif k == 'maximumHeight':
                self.header[k] = topology.maxHeight
            elif k == 'boundingSphereCenterX':
                self.header[k] = bSphere.center[0]
            elif k == 'boundingSphereCenterY':
                self.header[k] = bSphere.center[1]
            elif k == 'boundingSphereCenterZ':
                self.header[k] = bSphere.center[2]
            elif k == 'boundingSphereRadius':
                self.header[k] = bSphere.radius
            elif k == 'horizonOcclusionPointX':
                self.header[k] = occlusionPCoords[0]
            elif k == 'horizonOcclusionPointY':
                self.header[k] = occlusionPCoords[1]
            elif k == 'horizonOcclusionPointZ':
                self.header[k] = occlusionPCoords[2]

        bLon = MAX / (self._east - self._west)
        bLat = MAX / (self._north - self._south)

        quantizeLonIndices = lambda x: int(round((x - self._west) * bLon))
        quantizeLatIndices = lambda x: int(round((x - self._south) * bLat))

        deniv = self.header['maximumHeight'] - self.header['minimumHeight']
        # In case a tile is completely flat
        if deniv == 0:
            quantizeHeightIndices = lambda x: 0
        else:
            bHeight = MAX / deniv
            quantizeHeightIndices = lambda x: int(
                round((x - self.header['minimumHeight']) * bHeight)
            )

        # High watermark encoding performed during toFile
        self.u = map(quantizeLonIndices, topology.uVertex)
        self.v = map(quantizeLatIndices, topology.vVertex)
        self.h = map(quantizeHeightIndices, topology.hVertex)
        self.indices = topology.indexData

        # List all the vertices on the edge of the tile
        # High water mark encoded?
        for i in xrange(0, len(self.indices)):
            # Use original coordinates
            indice = self.indices[i]
            lon = topology.uVertex[indice]
            lat = topology.vVertex[indice]

            if lon == self._west and indice not in self.westI:
                self.westI.append(indice)
            elif lon == self._east and indice not in self.eastI:
                self.eastI.append(indice)

            if lat == self._south and indice not in self.southI:
                self.southI.append(indice)
            elif lat == self._north and indice not in self.northI:
                self.northI.append(indice)

        self.hasLighting = topology.hasLighting
        if self.hasLighting:
            self.vLight = topology.verticesUnitVectors