from math import pi

from starflow.utils import ListUnion

from bson import SON
from model_categories import MODEL_CATEGORIES

MODELS = ListUnion(MODEL_CATEGORIES.values())

NUM_IMAGES = 20
USE_CANONICAL = True

NSEG = 20

base_images = [SON([('model_ids',[m]),
                    ('num_images',NUM_IMAGES),
                    ('use_canonical',USE_CANONICAL),
                    ('generator','renderman'),
                    ('selection','random'),
                    ('ty',SON([('$gt',-.6),('$lt',.6)])),
                    ('tz',SON([('$gt',-.6),('$lt',.6)])),
                    ('ryz',SON([('$gt',2*pi*(ind % NSEG)/NSEG),('$lt',2*pi*((ind % NSEG) + 1)/NSEG)]))
                    ])
               for (ind,m) in enumerate(MODELS)]

import copy

imagesets = []

#gray background
for m in base_images:
from starflow.utils import ListUnion

import copy 

from bson import SON

from model_categories import MODEL_CATEGORIES as CAT

all_models = ListUnion(CAT.values())
            

extraction =  SON([ ('transform_average',SON([('transform_name','translation'),('percentile',[73,90,99])])),
                    ('query',SON([('image.model_id',SON([('$in',all_models)])),
                                  ('image.bg_id','gray.tdl'), 
                                  ('image.tx',SON([('$exists',False)])),
                                  ('image.s',SON([('$exists',False)])),
                                  ('image.rxy',SON([('$exists',False)])),
                                  ('image.rxz',SON([('$exists',False)])),
                                  ('$or',[SON([('image.ty',SON([('$exists',True)])),('image.tz',SON([('$exists',True)]))]),
                                          SON([('image.ryz',SON([('$exists',True)]))])])
                                 ]))
                  ]) 
                
    
config = {
'extractions' : [extraction]
}