function [example, example_shape] = construct_model_example(params, model, ref_points_vec);
% CONSTRUCT_MODEL_EXAMPLE: Constructs a model example
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      [example, example_shape] = 
%      construct_model_example(params, model, ref_points_vec);
%
%
%    INPUT/S
%
%      -params:
%           Input parameters. meaning of each parameter is 
%           yet to be resolved.
%
%      -model:
%           X
%
%      -ref_points_vec:
%           X
%      
%    OUTPUT/S
%
%      -example
%           X
%
%      -example_shape
%           X
%
%    PENDING WORK
%
%      -Find out what each parameters does (see INPUT/S)
%
%    KNOWN BUG/S
%
%      -
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 24th, 2003
%      -Revision:    0.0.2
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

combined_shape_pcs = model.pcs(1:model.n_shape_modes,:);
combined_intensity_pcs = model.pcs(model.n_shape_modes+1:size(model.pcs),:);

% get shape-free grey-level image
example_sample = model.intensity_model.mean' + ...
  sum(model.intensity_model.pcs * (combined_intensity_pcs .* ...
  repmat(params,size(combined_intensity_pcs,1),1)),2);

% get reparameterisation
where = find(model.shape_weight==0);
model.shape_weight(where) = realmax;
example_shape = model.shape_model.mean' + ...
 sum((model.shape_model.pcs ./ repmat(model.shape_weight,size(model.shape_model.pcs,1),1)) * (combined_shape_pcs .* ...
 repmat(params,size(combined_shape_pcs,1),1)),2);

% warp the shape-free image from above!
example = interp1(ref_points_vec, example_sample, example_shape, 'linear',0);
    
