Changeset 395


Ignore:
Timestamp:
07/01/08 16:13:37 (5 years ago)
Author:
fma
Message:

Moved mosaic params to Mosaic object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/model/shooting.py

    r391 r395  
    7575        @type simulatedHardware: {HeadSimulation} 
    7676        """ 
    77         self.__running = False 
     77        self.__shooting = False 
    7878        self.__suspend = False 
    7979        self.__stop = False 
     
    8787        self.newPictSignal = Signal() 
    8888        self.camera = Camera() 
    89  
    90         self.yawStart = 0. 
    91         self.pitchStart = 0. 
    92         self.yawEnd = 0. 
    93         self.pitchEnd = 0. 
     89        self.mosaic = Mosaic(self.camera) 
     90        #self.fullSpherical = FullSpherical() 
     91 
    9492        self.position = self.hardware.readPosition() 
    9593        self.progress = 0. 
    9694        self.sequence = "Idle" 
    9795 
    98         #self.__computeParams('startEnd') 
    99  
     96    # Properties 
    10097    def __getStabilizationDelay(self): 
    10198        """ 
     
    109106     
    110107    stabilizationDelay = property(__getStabilizationDelay, __setStabilizationDelay) 
    111      
    112     def __getOverlap(self): 
    113         """ 
    114         """ 
    115         return ConfigManager().getFloat('Preferences', 'SHOOTING_OVERLAP') 
    116      
    117     def __setOverlap(self, overlap): 
    118         """ 
    119         """ 
    120         ConfigManager().setFloat('Preferences', 'SHOOTING_OVERLAP', overlap, 2) 
    121          
    122     overlap = property(__getOverlap, __setOverlap) 
    123      
    124     def __getCameraOrientation(self): 
    125         """ 
    126         """ 
    127         return ConfigManager().get('Preferences', 'SHOOTING_CAMERA_ORIENTATION') 
    128      
    129     def __setCameraOrientation(self, cameraOrientation): 
    130         """ 
    131         """ 
    132         ConfigManager().set('Preferences', 'SHOOTING_CAMERA_ORIENTATION', cameraOrientation) 
    133  
    134     cameraOrientation = property(__getCameraOrientation, __setCameraOrientation) 
    135  
    136     def __getYawFov(self): 
    137         """ 
    138         """ 
    139         yawCameraFov = self.camera.getYawFov(self.cameraOrientation) 
    140         return abs(self.yawEnd - self.yawStart) + yawCameraFov 
    141  
    142     yawFov = property(__getYawFov, "Total yaw FoV") 
    143  
    144     def __getPitchFov(self): 
    145         """ 
    146         """ 
    147         pitchCameraFov = self.camera.getPitchFov(self.cameraOrientation) 
    148         return abs(self.pitchEnd - self.pitchStart) + pitchCameraFov 
    149  
    150     pitchFov = property(__getPitchFov, "Total pitch FoV") 
    151  
    152     def __getYawNbPicts(self): 
    153         """ 
    154         """ 
    155         yawCameraFov = self.camera.getYawFov(self.cameraOrientation) 
    156         if round(self.yawFov - yawCameraFov, 1) >= 0.1: 
    157             nbPicts = int(((self.yawFov - self.overlap * yawCameraFov) / (yawCameraFov * (1 - self.overlap))) + 1) 
    158         else: 
    159             nbPicts = 1 
    160         return nbPicts 
    161  
    162     yawNbPicts = property(__getYawNbPicts, "Yaw nb picts") 
    163  
    164     def __getPitchNbPicts(self): 
    165         """ 
    166         """ 
    167         pitchCameraFov = self.camera.getPitchFov(self.cameraOrientation) 
    168         if round(self.pitchFov - pitchCameraFov, 1) >= 0.1: 
    169            nbPicts = int(((self.pitchFov - self.overlap * pitchCameraFov) / (pitchCameraFov * (1 - self.overlap))) + 1) 
    170         else: 
    171             nbPicts = 1 
    172         return nbPicts 
    173  
    174     pitchNbPicts = property(__getPitchNbPicts, "Pitch nb picts") 
    175  
    176     def __getRealYawOverlap(self): 
    177         """ Recompute real yaw overlap. 
    178         """ 
    179         yawCameraFov = self.camera.getYawFov(self.cameraOrientation) 
    180         if self.yawNbPicts > 1: 
    181             overlap = (self.yawNbPicts * yawCameraFov - self.yawFov) / (yawCameraFov * (self.yawNbPicts - 1)) 
    182         else: 
    183             overlap = 1. 
    184         return overlap 
    185  
    186     yawRealOverlap = property(__getRealYawOverlap, "Real yaw overlap") 
    187  
    188     def __getRealPitchOverlap(self): 
    189         """ Recompute real pitch overlap. 
    190         """ 
    191         pitchCameraFov = self.camera.getPitchFov(self.cameraOrientation) 
    192         if self.pitchNbPicts > 1: 
    193             overlap = (self.pitchNbPicts * pitchCameraFov - self.pitchFov) / (pitchCameraFov * (self.pitchNbPicts - 1)) 
    194         else: 
    195             overlap = 1. 
    196         return overlap 
    197  
    198     pitchRealOverlap = property(__getRealPitchOverlap, "Real pitch overlap") 
    199  
    200     #def __computeParams(self, setParam): 
    201         #""" Compute missing params from given params. 
    202  
    203         #@param setParam: given params type ('startEnd', 'fov', 'nbPict') 
    204         #@type setParam: str 
    205  
    206         #@todo: add fov and nbPicts 
    207         #""" 
    208         #if setParam == 'startEnd': 
    209             #self.yawFov = self.__getYawFov() 
    210             #self.pitchFov = self.__getPitchFov() 
    211             #self.yawNbPicts = self.__getYawNbPicts() 
    212             #self.pitchNbPicts = self.__getPitchNbPicts() 
    213             #self.yawRealOverlap = self.__getRealYawOverlap() 
    214             #self.pitchRealOverlap = self.__getRealPitchOverlap() 
    215         #elif setParam == 'fov': 
    216             #Logger().warning("Shooting.__computeParam(): 'fov' setting not yet implemented") 
    217         #elif setParam == 'nbPicts': 
    218             #Logger().warning("Shooting.__computeParam(): 'nbPicts' setting not yet implemented") 
    219         #else: 
    220             #raise ValueError("param must be in ('startEnd', 'fov', 'nbPict')") 
    221108 
    222109    def switchToRealHardware(self): 
     
    242129        self.position = self.hardware.readPosition() 
    243130 
    244     def storeStartPosition(self): 
    245         """ Store current position as start position. 
    246         """ 
    247         self.yawStart, self.pitchStart = self.hardware.readPosition() 
    248         Logger().debug("Shooting.storeStartPosition(): yaw=%.1f, pitch=%.1f" % (self.yawStart, self.pitchStart)) 
    249         #self.__computeParams('startEnd') 
    250  
    251     def storeEndPosition(self): 
    252         """ Store current position as end position. 
    253         """ 
    254         self.yawEnd, self.pitchEnd = self.hardware.readPosition() 
    255         Logger().debug("Shooting.storeEndPosition(): yaw=%.1f, pitch=%.1f" % (self.yawEnd, self.pitchEnd)) 
    256         #self.__computeParams('startEnd') 
    257  
    258     def setYaw360(self): 
    259         """ Compute start/end yaw position for 360°. 
    260          
    261         Récupérer position courante et calculer début et fin pour avoir 
    262         +-180°, overlap inclus 
    263         """ 
    264         yaw, pitch = self.hardware.readPosition() 
    265         yawCameraFov = self.camera.getPitchFov(self.cameraOrientation) 
    266         self.yawStart = yaw - 180.  + yawCameraFov * (1 - self.overlap) / 2. 
    267         self.yawEnd = yaw + 180. - yawCameraFov * (1 - self.overlap) / 2. 
    268         Logger().debug("Shooting.setYaw360(): startYaw=%.1f, endYaw=%.1f" % (self.yawStart, self.yawEnd)) 
    269  
    270     def setPitch180(self): 
    271         """ Compute start/end pitch position for 180°. 
    272          
    273         Récupérer position courante et calculer début et fin pour avoir 
    274         +-90°, overlap inclus 
    275         Tenir compte des butées softs ! 
    276         """ 
    277         yaw, pitch = self.hardware.readPosition() 
    278         pitchCameraFov = self.camera.getPitchFov(self.cameraOrientation) 
    279         self.pitchStart = pitch - 90. + pitchCameraFov * (1 - self.overlap) / 2. 
    280         self.pitchEnd = pitch + 90. - pitchCameraFov * (1 - self.overlap) / 2. 
    281         Logger().debug("Shooting.setPitch180(): startPitch=%.1f, endPitch=%.1f" % (self.pitchStart, self.pitchEnd)) 
    282  
    283131    def setManualShoot(self, flag): 
    284132        """ Turn on/off manual shoot. 
     
    290138        """ 
    291139        self.__manualShoot = flag 
    292  
    293     def generate(self): 
    294         """ Generate all shooting positions. 
    295          
    296         @return: shooting positions 
    297         @rtype: list of dict 
    298         """ 
    299         pass 
    300140 
    301141    def initProgress(self): 
     
    322162 
    323163        Logger().trace("Shooting.start()") 
     164 
     165        data = Data() 
     166        values = {'stabilizationDelay': "%.1f" % self.stabilizationDelay, 
     167                  'overlap': "%.2f" % self.mosaic.overlap, 
     168                  'yawRealOverlap': "%.2f" % self.mosaic.yawRealOverlap, 
     169                  'pitchRealOverlap': "%.2f" % self.mosaic.pitchRealOverlap, 
     170                  'cameraOrientation': "%s" % self.mosaic.cameraOrientation, 
     171                  'timeValue': "%.1f" % self.camera.timeValue, 
     172                  'nbPicts': "%d" % self.camera.nbPicts, 
     173                  'sensorCoef': "%.1f" % self.camera.sensorCoef, 
     174                  'sensorRatio': "%s" % self.camera.sensorRatio, 
     175                  'focal': "%.1f" % self.camera.lens.focal, 
     176                  'fisheye': "%s" % self.camera.lens.fisheye, 
     177                  'template': "mosaic", 
     178                  'yawNbPicts': "%d" % self.mosaic.yawNbPicts, 
     179                  'pitchNbPicts': "%d" % self.mosaic.pitchNbPicts 
     180              } 
     181        data.createHeader(values) 
     182        self.progress = 0. 
    324183        self.__stop = False 
    325         self.__running = True 
    326  
    327         cameraFov = self.camera.getYawFov(self.cameraOrientation) 
     184        self.__shooting = True 
     185 
     186        # Loop over all positions 
    328187        try: 
    329             yawInc = (self.yawFov - cameraFov) / (self.yawNbPicts - 1) 
    330         except ZeroDivisionError: 
    331             yawInc = self.yawFov - cameraFov 
    332         yawInc *= cmp(self.yawEnd, self.yawStart) 
    333         cameraFov = self.camera.getPitchFov(self.cameraOrientation) 
    334         try: 
    335             pitchInc = (self.pitchFov - cameraFov) / (self.pitchNbPicts - 1) 
    336         except ZeroDivisionError: 
    337             pitchInc = self.pitchFov - cameraFov 
    338         pitchInc *= cmp(self.pitchEnd, self.pitchStart) 
    339         mosaic = Mosaic(self.yawNbPicts, self.pitchNbPicts) 
    340  
    341         try: 
    342             data = Data() 
    343             values = {'stabilizationDelay': "%.1f" % self.stabilizationDelay, 
    344                       'overlap': "%.2f" % self.overlap, 
    345                       'yawRealOverlap': "%.2f" % self.yawRealOverlap, 
    346                       'pitchRealOverlap': "%.2f" % self.pitchRealOverlap, 
    347                       'cameraOrientation': "%s" % self.cameraOrientation, 
    348                       'timeValue': "%.1f" % self.camera.timeValue, 
    349                       'nbPicts': "%d" % self.camera.nbPicts, 
    350                       'sensorCoef': "%.1f" % self.camera.sensorCoef, 
    351                       'sensorRatio': "%s" % self.camera.sensorRatio, 
    352                       'focal': "%.1f" % self.camera.lens.focal, 
    353                       'fisheye': "%s" % self.camera.lens.fisheye, 
    354                       'template': "mosaic", 
    355                       'yawNbPicts': "%d" % self.yawNbPicts, 
    356                       'pitchNbPicts': "%d" % self.pitchNbPicts 
    357                   } 
    358             data.createHeader(values) 
    359  
    360             # Loop over all positions 
    361             totalNbPicts = self.yawNbPicts * self.pitchNbPicts 
    362             self.progress = 0. 
    363             for i, (yawIndex, pitchIndex) in enumerate(mosaic): 
    364                 yaw = self.yawStart + yawIndex * yawInc 
    365                 pitch = self.pitchStart + pitchIndex * pitchInc 
     188            for i, (yaw, pitch) in enumerate(self.mosaic): 
    366189                Logger().debug("Shooting.start(): Goto yaw=%.1f pitch=%.1f" % (yaw, pitch)) 
    367190                Logger().info("Moving") 
     
    386209                    self.sequence = "Shooting %d/%d" % (pict + 1, self.camera.nbPicts) 
    387210                    self.hardware.shoot(self.camera.timeValue) 
    388                     data.addImage(pict + 1, yaw, pitch) 
     211                    data.addPicture(pict + 1, yaw, pitch) 
    389212 
    390213                    checkSuspendStop() 
    391214 
    392                 progressFraction = float((i + 1)) / float(totalNbPicts) 
     215                progressFraction = float((i + 1)) / float(self.mosaic.totalNbPicts) 
    393216                self.progress = progressFraction 
    394217                self.newPictSignal.emit(yaw, pitch) # Include progress? 
     
    402225            self.sequence = "Over" 
    403226             
    404         self.__running = False 
     227        self.__shooting = False 
    405228 
    406229    def isShooting(self): 
     
    410233        @rtype: bool 
    411234        """ 
    412         return self.__running 
     235        return self.__shooting 
    413236 
    414237    def suspend(self): 
Note: See TracChangeset for help on using the changeset viewer.