Esempio n. 1
0
 def GetResourceLayerValueForHead(self, headID, surfacePoint=None):
     if self.currResourceTypeID:
         head = self.pin.FindHead(headID)
         if head:
             headID, phi, theta = head
             if surfacePoint:
                 theta = 2.0 * math.pi - surfacePoint.theta
                 phi = surfacePoint.phi
             else:
                 theta = 2.0 * math.pi - theta
                 phi = phi
             return max(0.0, builder.GetValueAt(self.sh, theta, phi))
     else:
         if self.pin.FindHead(headID) is not None:
             return 0.0
         return
Esempio n. 2
0
    def ChartResourceLayer(self, resSH):
        resourceTypeID = self.selectedResourceTypeID
        if not hasattr(self, 'thetaSamples'):
            self.thetaSamples, self.phiSamples = self.GenerateSamplePoints(
                SQRT_NUM_SAMPLES)
        data = []
        for i in xrange(len(self.thetaSamples)):
            value = builder.GetValueAt(resSH, self.phiSamples[i],
                                       self.thetaSamples[i])
            data.append(value)
            blue.pyos.BeNice()
            if resourceTypeID != self.selectedResourceTypeID:
                raise ResourceRenderAbortedError

        chart = self.CreateChartFromSamples(PLANET_RESOURCE_TEX_WIDTH,
                                            PLANET_RESOURCE_TEX_HEIGHT,
                                            self.phiSamples, self.thetaSamples,
                                            data)
        return chart
Esempio n. 3
0
    def CreateProgram(self,
                      harmonic,
                      ecuPinID,
                      resourceTypeID,
                      points=None,
                      headRadius=None):
        ecuPin = self.GetPin(ecuPinID)
        if points is None:
            points = ecuPin.heads
        if headRadius is None:
            headRadius = ecuPin.GetExtractorHeadRadius()
        overlapFactor = self.GetTypeAttribute(ecuPin.typeID,
                                              const.attributeEcuOverlapFactor)
        maxVolume = self.GetTypeAttribute(ecuPin.typeID,
                                          const.attributeEcuMaxVolume)
        overlapModifiers = {}
        heads = []
        for index, longitude, latitude in points:
            heads.append((index, SurfacePoint(theta=latitude, phi=longitude)))
            overlapModifiers[index] = 1.0

        distance = {}
        valueByIndex = {}
        for index, surfacePoint in heads:
            theta = 2.0 * math.pi - surfacePoint.theta
            phi = surfacePoint.phi
            valueByIndex[index] = max(builder.GetValueAt(harmonic, theta, phi),
                                      0)
            for index2, surfacePoint2 in heads:
                if index == index2:
                    continue
                key = tuple(sorted([index, index2]))
                if key not in distance:
                    distance[key] = surfacePoint.GetDistanceToOther(
                        surfacePoint2)

        with bluepy.TimerPush('OverlapOwnHeads'):
            for (head1, head2), dist in distance.iteritems():
                if dist < headRadius * 2:
                    radiusSquared = headRadius**2
                    overlap = (
                        2 * radiusSquared * math.acos(0.5 *
                                                      (dist / headRadius)) -
                        0.5 * dist * math.sqrt(4 * radiusSquared - dist**2)
                    ) / (math.pi * radiusSquared)
                    modifier = min(1, max(0, 1 - overlap * overlapFactor))
                    valueByIndex[head1] *= modifier
                    valueByIndex[head2] *= modifier
                    overlapModifiers[head1] *= modifier
                    overlapModifiers[head2] *= modifier

        with bluepy.TimerPush('OverlapOthersHeads'):
            otherHeadsInfo = []
            for pin in self.colonyData.GetECUs(ecuPinID):
                if pin.programType != resourceTypeID:
                    continue
                otherHeadsInfo.append(
                    (pin.GetExtractorHeadRadius(), pin.heads))

            headArea = math.pi * headRadius**2
            for index, surfacePoint1 in heads:
                modifier = 1
                for otherHeadRadius, otherHeads in otherHeadsInfo:
                    if modifier == 0:
                        break
                    for index2, longitude2, latitude2 in otherHeads:
                        surfacePoint2 = SurfacePoint(theta=latitude2,
                                                     phi=longitude2)
                        d, R, r = surfacePoint1.GetDistanceToOther(
                            surfacePoint2), headRadius, otherHeadRadius
                        if d > R + r:
                            continue
                        r2, R2, d2 = r**2, R**2, d**2
                        alpha = (d2 + r2 - R2) / (2 * d * r)
                        if alpha < -1:
                            overlap = math.pi * r2 / headArea
                        elif alpha > 1:
                            overlap = 1
                        else:
                            f1 = r**2 * math.acos(alpha)
                            f2 = R**2 * math.acos(
                                (d**2 + R**2 - r**2) / (2 * d * R))
                            f3 = 0.5 * math.sqrt((-d + r + R) * (d + r - R) *
                                                 (d - r + R) * (d + r + R))
                            A = f1 + f2 - f3
                            overlap = A / headArea
                        modifier *= min(
                            1, max(0, 1 - overlap * 2 * overlapFactor))

                valueByIndex[index] *= modifier
                overlapModifiers[index] *= modifier

        for index, modifier in overlapModifiers.iteritems():
            overlapModifiers[index] = 1.0 - modifier

        maxValue = maxVolume * sum(valueByIndex.values())
        programLength = GetProgramLengthFromHeadRadius(headRadius)
        cycleTime = GetCycleTimeFromProgramLength(programLength)
        numCycles = int(programLength / cycleTime)
        cycleTime = int(cycleTime * const.HOUR)
        return (int(maxValue), cycleTime, numCycles, overlapModifiers)
Esempio n. 4
0
 def GetCurrentResourceValueAt(self, phi, theta):
     if not self.currSphericalHarmonic:
         return None
     return builder.GetValueAt(self.currSphericalHarmonic, phi, theta)