def render_kitti(self, render_2d: bool) -> None:
        """
        Renders the annotations in the KITTI dataset from a lidar and a camera view.
        :param render_2d: Whether to render 2d boxes (only works for camera data).
        """
        if render_2d:
            print('Rendering 2d boxes from KITTI format')
        else:
            print('Rendering 3d boxes projected from 3d KITTI format')

        # Load the KITTI dataset.
        kitti = KittiDB(root=self.nusc_kitti_dir, splits=(self.split, ))

        # Create output folder.
        render_dir = os.path.join(self.nusc_kitti_dir, 'render')
        if not os.path.isdir(render_dir):
            os.mkdir(render_dir)

        # Render each image.
        for token in kitti.tokens[:self.image_count]:
            for sensor in ['lidar', 'camera']:
                out_path = os.path.join(render_dir,
                                        '%s_%s.png' % (token, sensor))
                print('Rendering file to disk: %s' % out_path)
                kitti.render_sample_data(token,
                                         sensor_modality=sensor,
                                         out_path=out_path,
                                         render_2d=render_2d)
                plt.close(
                )  # Close the windows to avoid a warning of too many open windows.
    def render_kitti(self) -> None:
        """
        Renders the annotations in the KITTI dataset from a lidar and a camera view.
        """
        # Load the KITTI dataset.
        kitti = KittiDB(root=self.nusc_kitti_dir, splits=(self.split, ))

        # Create output folder.
        render_dir = os.path.join(self.nusc_kitti_dir, 'render')
        if not os.path.isdir(render_dir):
            os.mkdir(render_dir)

        # Render each image.
        for token in kitti.tokens[:self.image_count]:
            for sensor in ['lidar', 'camera']:
                out_path = os.path.join(render_dir,
                                        '%s_%s.png' % (token, sensor))
                print('Rendering file to disk: %s' % out_path)
                kitti.render_sample_data(token,
                                         sensor_modality=sensor,
                                         out_path=out_path)
                plt.close(
                )  # Close the windows to avoid a warning of too many open windows.
    def render_kitti(self, render_2d: bool = False) -> None:
        """
        Renders the annotations in the KITTI dataset from a lidar and a camera view.
        :param render_2d: Whether to render 2d boxes (only works for camera data).
        """
        if render_2d:
            print('Rendering 2d boxes from KITTI format')
        else:
            print('Rendering 3d boxes projected from 3d KITTI format')

        # Load the KITTI dataset.
        kitti = KittiDB(root=self.nusc_kitti_dir, splits=[''])

        def get_transforms(token: str, root: str) -> dict:
            calib_filename = KittiDB.get_filepath(token, 'calib', root=root)

            lines = [line.rstrip() for line in open(calib_filename)]
            velo_to_cam = np.array(lines[5].strip().split(' ')[1:],
                                   dtype=np.float64)
            velo_to_cam.resize((3, 4))

            r0_rect = np.array(lines[4].strip().split(' ')[1:],
                               dtype=np.float64)
            r0_rect.resize((3, 3))
            p_left = np.array(lines[2].strip().split(' ')[1:],
                              dtype=np.float64)
            p_left.resize((3, 4))

            # Merge rectification and projection into one matrix.
            p_combined = np.eye(4)
            p_combined[:3, :3] = r0_rect
            p_combined = np.dot(p_left, p_combined)
            return {
                'velo_to_cam': {
                    'R': velo_to_cam[:, :3],
                    'T': velo_to_cam[:, 3]
                },
                'r0_rect': r0_rect,
                'p_left': p_left,
                'p_combined': p_combined,
            }

        kitti.get_transforms = get_transforms  # monkeypatching np.float32 -> 64
        # Create output folder.
        render_dir = os.path.join(self.nusc_kitti_dir, 'render')
        if not os.path.isdir(render_dir):
            os.mkdir(render_dir)

        # Render each image.
        tokens = kitti.tokens
        if self.samples_count is not None:
            tokens = tokens[:self.samples_count]

        # currently supports only single thread processing
        for token in tqdm(tokens):

            for sensor in ['lidar', 'camera']:
                out_path = os.path.join(render_dir,
                                        '%s_%s.png' % (token, sensor))
                kitti.render_sample_data(token,
                                         sensor_modality=sensor,
                                         out_path=out_path,
                                         render_2d=render_2d)
                # Close the windows to avoid a warning of too many open windows.
                plt.close()