//  [python]
def spin(self, share_data, kf_buffer):
        print("mapping process started!!!!!!!!!")
        while True:
            torch.cuda.empty_cache()
            if not kf_buffer.empty():
                tracked_frame = kf_buffer.get()
                # self.create_voxels(tracked_frame)
                if not self.initialized:
                    self.first_frame_id = tracked_frame.index
                    if self.mesher is not None:
                        self.mesher.rays_d = tracked_frame.get_rays()
                    self.create_voxels(tracked_frame)
                    self.insert_keyframe(tracked_frame)
                    while kf_buffer.empty():
                        self.do_mapping(share_data, tracked_frame, selection_method='current')
                    self.initialized = True
                else:
                    if self.remove_back:
                        tracked_frame = self.remove_back_points(tracked_frame)
                    self.do_mapping(share_data, tracked_frame)
                    self.create_voxels(tracked_frame)
                    if (torch.linalg.norm(tracked_frame.pose.translation().cpu()
                        - self.current_keyframe.pose.translation().cpu())) > self.keyframe_gap:
                        self.insert_keyframe(tracked_frame)
                        print(
                            f"********** current num kfs: { len(self.keyframe_graph) } **********")

                # self.create_voxels(tracked_frame)
                tracked_pose = tracked_frame.get_pose().detach()
                ref_pose = self.current_keyframe.get_pose().detach()
                rel_pose = torch.linalg.inv(ref_pose) @ tracked_pose
                self.frame_poses += [(len(self.keyframe_graph) -
                                      1, rel_pose.cpu())]

                if self.mesh_freq > 0 and (tracked_frame.index) % self.mesh_freq == 0:
                    if self.final_iter and len(self.keyframe_graph) > 20:
                        print(f"********** post-processing steps **********")
                        #self.num_iterations = 1
                        final_num_iter = len(self.keyframe_graph) + 1
                        progress_bar = tqdm(
                            range(0, final_num_iter), position=0)
                        progress_bar.set_description(" post-processing steps")
                        for iter in progress_bar:
                            #tracked_frame=self.keyframe_graph[iter//self.window_size]
                            self.do_mapping(share_data, tracked_frame=None,
                                            update_pose=False, update_decoder=False, selection_method='random')


                    self.logger.log_mesh(self.extract_mesh(res=self.mesh_res, clean_mesh=False),name=f"mesh_{tracked_frame.index:05d}.ply")
                    pose = self.get_updated_poses()
                    self.logger.log_numpy_data(np.asarray(pose), f"frame_poses_{tracked_frame.index:05d}")

                    if self.final_iter and len(self.keyframe_graph) > 20:
                        self.keyframe_graph = []
                        self.keyframe_graph += [self.current_keyframe]
                if self.save_data_freq > 0 and (tracked_frame.stamp + 1) % self.save_data_freq == 0:
                    self.save_debug_data(tracked_frame)
            elif share_data.stop_mapping:
                break
        print("******* extracting mesh without replay *******")
        self.logger.log_mesh(self.extract_mesh(res=self.mesh_res, clean_mesh=False), name="final_mesh_noreplay.ply")
        if self.final_iter:
            print(f"********** post-processing steps **********")
            #self.num_iterations = 1
            final_num_iter = len(self.keyframe_graph) + 1
            progress_bar = tqdm(
                range(0, final_num_iter), position=0)
            progress_bar.set_description(" post-processing steps")
            for iter in progress_bar:
                tracked_frame=self.keyframe_graph[iter//self.window_size]
                self.do_mapping(share_data, tracked_frame=None,
                                update_pose=False, update_decoder=False, selection_method='random')

        print("******* extracting final mesh *******")
        pose = self.get_updated_poses()
        self.logger.log_numpy_data(np.asarray(pose), "frame_poses")
        self.logger.log_mesh(self.extract_mesh(res=self.mesh_res, clean_mesh=False))
        print("******* mapping process died *******")