def render(self, scene, bucket_order_info: BucketOrderInfo, multiThread: bool=True):

        self.scene = scene

        sample_list = [Sample(self.main_sampler, scene)]

        my_bucket_orders = BucketOrder.create(bucket_order_info.width, bucket_order_info.height,
                                              bucket_order_info.bucket_order_type)

        # 1) Init a Thread pool with the desired number of threads
        pool = ThreadPool(1)

        # 2) Add the task to the queue
        task_index = 0
        for i in range(bucket_order_info.width * bucket_order_info.height):
            pool.add_task(self.render_task,
                          task_index,
                          my_bucket_orders.buckets_orders[task_index],
                          bucket_order_info,
                          sample_list,
                          random.random() * 255)
            task_index += 1

        # 3) Wait for completion
        pool.wait_completion()
Beispiel #2
0
    def render(self, scene, bucket_order_info: BucketOrderInfo, multiThread: bool=True):

        self.scene = scene

        if self.surface_integrator is not None:
            self.surface_integrator.Preprocess(scene, self.camera, self)

        if self.volume_integrator is not None:
            self.volume_integrator.Preprocess(scene, self.camera, self)

        sample = Sample(self.main_sampler, self.surface_integrator, self.volume_integrator, scene)

        if multiThread:
            my_bucket_orders = BucketOrder.create(bucket_order_info.width, bucket_order_info.height,
                                                  bucket_order_info.bucket_order_type)

            pool = Pool(processes=multiprocessing.cpu_count())
            # pool = Pool(processes=1)
            pool._wrap_exception = False

            results = []

            for i in range(bucket_order_info.width * bucket_order_info.height):
                # for i in range(55, 56):
                a = pool.apply_async(self.render_task, args=(
                    i, my_bucket_orders.buckets_orders[i], bucket_order_info, sample, self),
                                     callback=self.draw)

                results.append(a)

            for r in results:
                r.wait()

        else:
            bucketOrderInfo = BucketOrderInfo(BucketOrderSortType.Random, 1, 1)
            self.render_task(0, 0, bucketOrderInfo, sample, self)

        print("Render end")

        data = write_png(self.camera.film.data, self.camera.film.width, self.camera.film.height)
        with open("my_image.png", 'wb') as fd:
            fd.write(data)