class Dataset: def __init__(self): self.name = 'Building_dataset_{}_{}_{}'.format(datetime.now().year, datetime.now().month, datetime.now().day) self.size = SIZE self.json = Annotation() self.factory = BuildingFactory() self.material_factory = MaterialFactory() def populate(self): for i in range(self.size): building = self.factory.produce() building.make() if use_materials: _monomaterial = np.random.random() < MATERIAL_PROB mat = self.material_factory.produce() print(mat.name) for v in building.volumes: if not _monomaterial: mat = self.material_factory.produce() v.apply(mat) for module_name in MODULES: for side in range(2): mod = GridApplier( ModuleFactory().mapping[module_name]) module = ModuleFactory().produce(module_name) module.connect(v, side) step = (np.random.randint(ceil(module.scale[0]), 6), np.random.randint(ceil(module.scale[0]), 6)) mod.apply(module, step=step, offset=(2.0, 2.0, 2.0, 1.0)) self.json.add(building, '{}.png'.format(i), '{}.obj'.format(i)) # building.save(filename=str(i)) renderer = Renderer(mode=0) renderer.render(filename='building_{}'.format(i)) building.save(i) building.save(i, ext='ply') building.demolish() cloud = PointCloud() cloud.make(i) def write(self): self.json.write(self.name + '.json')
''')) parser.add_argument('file', type=str, help='path to .gltf file') parser.add_argument('--save', type=str, help='path to save the .obj files to', default='samples') args = parser.parse_known_args(argv)[0] try: args = parser.parse_args() except SystemExit as e: print(repr(e)) filename = args.file save_path = args.save a = Annotation() reader = BlenderReader(filename) building_collection = Collection(Building) if save not in os.listdir(): os.mkdir(save) for b in reader.obj: building_collection.add(Building(b)) for i, b in enumerate(building_collection): a.add(name='{}/{}.png'.format(save, i), model='{}/{}.obj'.format(save, i), bb=b.get_bb()) b.save('{}/{}.obj'.format(save, i)) a.write('test.json')
class Dataset: """ Class that manages and creates the dataset. """ def __init__(self): """ Class initialization. """ self.name = 'Building_dataset_{}_{}_{}'.format(datetime.now().year, datetime.now().month, datetime.now().day) self.size = SIZE self.json = Annotation() self.factory = BuildingFactory() self.material_factory = MaterialFactory() def populate(self): """ Function that creates the dataset samples. :return: """ s = time() renderer = Renderer(mode=0) lightmanager = LightManager() cameramanager = CameraManager() for i in range(self.size): lightmanager.make() building = self.factory.produce() building.make() if use_materials: _monomaterial = np.random.random() < MATERIAL_PROB mat = self.material_factory.produce() for v in building.volumes: if not _monomaterial: mat = self.material_factory.produce() v.apply(mat) v.add_modules() self.json.add(building, '{}.png'.format(i), '{}.obj'.format(i)) cameramanager.make_main() renderer.render(filename='building_{}'.format(i)) if RENDER_VIEWS > 1: for view in range(1, RENDER_VIEWS): cameramanager.make() lightmanager.make() if RANDOMIZE_TEXTURES: if use_materials: _monomaterial = np.random.random() < MATERIAL_PROB mat = self.material_factory.produce() for v in building.volumes: if not _monomaterial: mat = self.material_factory.produce() v.apply(mat) renderer.render(filename='building_{}_{}'.format(i, view)) building.save(i) building.save(i, ext='ply') building.demolish() cloud = PointCloud() cloud.make(i) print('Whole process took: {}'.format(time() - s)) def write(self): """ Function that writes a json annotation to the dataset. :return: """ self.json.write(self.name + '.json')