function [tcp , selIdx_torso_combo] = scale_torso_z(scp, tcp, factors, scp_kpis, scaling_options, selIdx_torso, selIdx_arms, file_pointers, format_options)
% scales the torso in the z direction.
%
% :param scp:                      Source control points
% :param tcp:                      Current target control points
% :param factors:                  Scaling factors
% :param scp_kpis:                 Key measurements based on scp
% :param scaling_options:          Settings for the scaling
% :param baby_measured_mass:       Measured baby mass
% :param selIdx_torso:             CP indices associated with the torso
% :param selIdx_arms:              CP indices associated with the arms
% :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

if scaling_options.scale_arms_method == 1
  selIdx_torso_combo = sort([selIdx_torso selIdx_arms]);
elseif scaling_options.scale_arms_method == 2
  selIdx_torso_combo = selIdx_torso;
else
  selIdx_torso_combo = selIdx_torso;
end

vectors_to_groin = tcp(selIdx_torso_combo,:) - scp_kpis.C3;
tcp(selIdx_torso_combo,3) = scp_kpis.C3(3) + factors(2) .* vectors_to_groin(:,3);


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')
  xlabel('X'); ylabel('Y');
  print([file_pointers.plot_dir 'XY_scale1'],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')
  print([file_pointers.plot_dir 'XZ_scale1'],format_options.pngprintOptions{:})

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