function tcp = scale_head_circumference(scp, tcp, scaling_factor_head_hc, selIdx_head, scp_kpis, file_pointers, format_options)
% scales the head circumference.
%
% :param scp:                      Source control points
% :param tcp:                      Current target control points
% :param scaling_factor_head_hc:   Scaling factor
% :param selIdx_head:              Indicies for the cps associated with the head
% :param scp_kpis:                 Key measurements based on scp
% :param file_pointers:            File pointers for I/O operations
% :param format_options:           Misc formating options
%
% :return tcp:                     Updated tcp positions
%
% Created by : ABR august@lightness.eu
% Date : 2024-06-13
centre_of_head = [mean(scp(selIdx_head,1)) mean(scp(selIdx_head,2)) scp_kpis.C5(3)];

% 2a. Shrink the head in the X-Y direction
vectors_to_centre_of_head = tcp(selIdx_head , :) - centre_of_head;
tcp(selIdx_head , 1:2) = centre_of_head(1:2) + scaling_factor_head_hc .* vectors_to_centre_of_head(:,1:2);


if format_options.plot_flag
  figure()
  scatter(scp(:,1), scp(:,2))
  hold on
  axis equal
  scatter(tcp(:,1), tcp(:,2))
  scatter( 0 , 0 , 'sr', 'filled')
  scatter( centre_of_head(1) , centre_of_head(2) , 'vr', 'filled')
  xlabel('X'); ylabel('Y');
  print([file_pointers.plot_dir 'XY_scale3'],format_options.pngprintOptions{:})

  figure()
  scatter(scp(:,1), scp(:,3))
  hold on
  axis equal
  scatter(tcp(:,1), tcp(:,3))
  xlabel('X'); ylabel('Z');
  scatter( 0 , 0 , 'sr', 'filled')
  scatter( centre_of_head(1) , centre_of_head(3) , 'vr', 'filled')
  print([file_pointers.plot_dir 'XZ_scale3'],format_options.pngprintOptions{:})

  figure()
  scatter(scp(:,2), scp(:,3))
  hold on
  axis equal
  scatter(tcp(:,2), tcp(:,3))
  scatter( 0 , 0 , 'sr', 'filled')
  scatter( centre_of_head(2) , centre_of_head(3) , 'vr', 'filled')
  xlabel('Y'); ylabel('Z');
  print([file_pointers.plot_dir 'YZ_scale3'],format_options.pngprintOptions{:})
end


