parameters: (data, gcps, reconstruction, ix_rec)
docstring: Triangulates all the control points in common with 3D models (those that have at least one 3D annotation)
      and saves them in the coordinate space of the 3D models so that they can be visualized in the annotation tool.
  
      gcps only contains the 2D observations
      We re-load the gcps file here manually to also get the 3D observations (hacky but will do for now)
docstring_summary: Triangulates all the control points in common with 3D models (those that have at least one 3D annotation)
      and saves them in the coordinate space of the 3D models so that they can be visualized in the annotation tool.
docstring_tokens: Triangulates all the control points in common with 3D models ( those that have at least one 3D annotation ) and saves them in the coordinate space of the 3D models so that they can be visualized in the annotation tool .
function: def align_external_3d_models_to_reconstruction(data, gcps, reconstruction, ix_rec):
      """
      Triangulates all the control points in common with 3D models (those that have at least one 3D annotation)
      and saves them in the coordinate space of the 3D models so that they can be visualized in the annotation tool.
  
      gcps only contains the 2D observations
      We re-load the gcps file here manually to also get the 3D observations (hacky but will do for now)
      """
  
      # Manually load GCP file to get the 3D annotations
      # Dict[model_filename, List[Tuple[3d_point, gcp_id]]
  
      # Create a mapping from filename to gcp ids (for those gcps that have 3D annotations)
      map_filename_to_gcp_ids = defaultdict(set)
      gcps_3d = load_3d_annotations_from_gcp_file(data)
      for shot_id, observations in gcps_3d.items():
          for _coords, gcp_id in observations:
              map_filename_to_gcp_ids[shot_id].add(gcp_id)
  
      gcps_per_source_file = defaultdict(list)
      # Group the 2D annotations by the 3D model that they're also annotated in
      for gcp in gcps:
          for (
              shot_id,
              gcp_ids_annotated_in_3d_for_this_file,
          ) in map_filename_to_gcp_ids.items():
              if gcp.id in gcp_ids_annotated_in_3d_for_this_file:
                  gcps_per_source_file[shot_id].append(gcp)
  
      # We now operate independently on each 3D model
      for model_id, gcps_this_model in gcps_per_source_file.items():
          gcp_reprojections, alignment = align_3d_annotations_to_reconstruction(
              gcps_this_model, gcps_3d, model_id, reconstruction
          )
          p_out = f"{data.data_path}/gcp_reprojections_3D_{ix_rec}x{model_id}.json"
          logger.info(f"Saving reprojected 3D points to {p_out}")
          with open(p_out, "w") as f:
              json.dump(gcp_reprojections, f, indent=4, sort_keys=True)
          p_out = f"{data.data_path}/affine_alignment_{ix_rec}x{model_id}.json"
          logger.info(f"Saving affine parameters to {p_out}")
          with open(p_out, "w") as f:
              json.dump(alignment, f, indent=4, sort_keys=True)
function_tokens: def align_external_3d_models_to_reconstruction ( data , gcps , reconstruction , ix_rec ) : # Manually load GCP file to get the 3D annotations # Dict[model_filename, List[Tuple[3d_point, gcp_id]] # Create a mapping from filename to gcp ids (for those gcps that have 3D annotations) map_filename_to_gcp_ids = defaultdict ( set ) gcps_3d = load_3d_annotations_from_gcp_file ( data ) for shot_id , observations in gcps_3d . items ( ) : for _coords , gcp_id in observations : map_filename_to_gcp_ids [ shot_id ] . add ( gcp_id ) gcps_per_source_file = defaultdict ( list ) # Group the 2D annotations by the 3D model that they're also annotated in for gcp in gcps : for ( shot_id , gcp_ids_annotated_in_3d_for_this_file , ) in map_filename_to_gcp_ids . items ( ) : if gcp . id in gcp_ids_annotated_in_3d_for_this_file : gcps_per_source_file [ shot_id ] . append ( gcp ) # We now operate independently on each 3D model for model_id , gcps_this_model in gcps_per_source_file . items ( ) : gcp_reprojections , alignment = align_3d_annotations_to_reconstruction ( gcps_this_model , gcps_3d , model_id , reconstruction ) p_out = f"{data.data_path}/gcp_reprojections_3D_{ix_rec}x{model_id}.json" logger . info ( f"Saving reprojected 3D points to {p_out}" ) with open ( p_out , "w" ) as f : json . dump ( gcp_reprojections , f , indent = 4 , sort_keys = True ) p_out = f"{data.data_path}/affine_alignment_{ix_rec}x{model_id}.json" logger . info ( f"Saving affine parameters to {p_out}" ) with open ( p_out , "w" ) as f : json . dump ( alignment , f , indent = 4 , sort_keys = True )