conf.py 2.47 KB
Newer Older
BobYeah's avatar
BobYeah committed
1
import torch
BobYeah's avatar
BobYeah committed
2
3
import util
import numpy as np
BobYeah's avatar
BobYeah committed
4
5
6
7
8
9
class Conf(object):
    def __init__(self):
        self.pupil_size = 0.02
        self.retinal_res = torch.tensor([ 320, 320 ])
        self.layer_res = torch.tensor([ 320, 320 ])
        self.layer_hfov = 90                  # layers' horizontal FOV
BobYeah's avatar
BobYeah committed
10
11
        self.eye_hfov = 80                    # eye's horizontal FOV (ignored in foveated rendering)
        self.eye_enable_fovea = False          # enable foveated rendering
BobYeah's avatar
BobYeah committed
12
13
14
        self.eye_fovea_angles = [ 40, 80 ]    # eye's foveation layers' angles
        self.eye_fovea_downsamples = [ 1, 2 ] # eye's foveation layers' downsamples
        self.d_layer = [ 1, 3 ]               # layers' distance
BobYeah's avatar
BobYeah committed
15
16
17
        self.eye_fovea_blend = [ self._GenFoveaLayerBlend(0) ]
                                                # blend maps of fovea layers
        self.light_field_dim = 5
BobYeah's avatar
BobYeah committed
18
19
20
21
    def GetNLayers(self):
        return len(self.d_layer)
    
    def GetLayerSize(self, i):
BobYeah's avatar
BobYeah committed
22
        w = util.Fov2Length(self.layer_hfov)
BobYeah's avatar
BobYeah committed
23
24
25
        h = w * self.layer_res[0] / self.layer_res[1]
        return torch.tensor([ h, w ]) * self.d_layer[i]

BobYeah's avatar
BobYeah committed
26
27
28
29
30
31
    def GetPixelSizeOfLayer(self, i):
        '''
        Get pixel size of layer i
        '''
        return util.Fov2Length(self.layer_hfov) * self.d_layer[i] / self.layer_res[0]

BobYeah's avatar
BobYeah committed
32
33
    def GetEyeViewportSize(self):
        fov = self.eye_fovea_angles[-1] if self.eye_enable_fovea else self.eye_hfov
BobYeah's avatar
BobYeah committed
34
        w = util.Fov2Length(fov)
BobYeah's avatar
BobYeah committed
35
        h = w * self.retinal_res[0] / self.retinal_res[1]
BobYeah's avatar
BobYeah committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        return torch.tensor([ h, w ])

    def GetRegionOfFoveaLayer(self, i):
        '''
        Get region of fovea layer i in retinal image
        
        Returns
        --------
        slice object stores the start and end of region
        '''
        roi_size = int(np.ceil(self.retinal_res[0] * self.eye_fovea_angles[i] / self.eye_fovea_angles[-1]))
        roi_offset = int((self.retinal_res[0] - roi_size) / 2)
        return slice(roi_offset, roi_offset + roi_size)
    
    def _GenFoveaLayerBlend(self, i):
        '''
        Generate blend map for fovea layer i
        
        Parameters
        --------
        i - index of fovea layer
        
        Returns
        --------
        H[i] x W[i], blend map
        
        '''
        region = self.GetRegionOfFoveaLayer(i)
        width = region.stop - region.start
        R = width / 2
        p = util.MeshGrid([ width, width ])
        r = torch.linalg.norm(p - R, 2, dim=2, keepdim=False)
        return util.SmoothStep(R, R * 0.6, r)