%% pivot measures
kernelVolume = @(H, up)(computeMeasureDec(pbeDefinition.dec, 'hC', ...
    {up, H(1:nC, :)}, 'volume', [], 0) ...
    );
kernelSurface = @(H, up)(computeMeasureDec(pbeDefinition.dec, 'hC', ...
    {up, H(1:nC, :)}, 'surface', [], 0) ...
    );
kernelMeanWidth = @(H, up)(computeMeasureDec(pbeDefinition.dec, 'hC', ...
    {up, H(1:nC, :)}, 'meanWidth', [], 0) ...
    );
kernelMeanWidthWhileEnforceValid = @(H, up)(computeMeasureDec(pbeDefinition.dec, 'hC', ...
    {up, H(1:nC, :)}, 'meanWidth', [], 1) ...
    );
oneMeanWidth = @(H, up)(computeMeasureDec(pbeDefinition.dec, 'hC', ...
    {up, ones(nC, size(H, 2))}, 'meanWidth', [], 0) ...
    );

%% particle measures
particleVolume = @(H, up, kVol, kSur, kMw)(...
    kVol + kSur .* H(nC+1, :) + ...
    2*pi*kMw.*H(nC+1, :).^2 + ...
    4/3*pi*H(nC+1, :).^3 ...
    );
particleSurface = @(H, up, kSur, kMw)(...
    kSur + 4.*pi.*kMw.*H(nC+1,:) + ...
    4.*pi.*H(nC+1,:).^2 ...
    );              
particleMeanWidth = @(H, up, kMw)(...
    kMw + 2.*H(nC+1, :) ...
    );

%% roundness values
% .. the min eliminates any nan that 0/0 produces
muB = @(kMeas, partMeas, n)(min(1, 1 - kMeas ./ partMeas).^n)
% muB1 = @(H, up)(...
%     min(1, 1 - kernelMeanWidth(H, up) ./ particleMeanWidth(H, up)) ...
%     );
% muB2 = @(H, up)(...
%     min(1, 1 - kernelSurface(H, up) ./ particleSurface(H, up)) ...
%     );
% muB3 = @(H, up)(...
%     min(1, 1 - kernelVolume(H, up) ./ particleVolume(H, up)));

%% level wise buildup
pivotLevelOne = @(H, up)([...
    kernelVolume(H, up); ...
    kernelSurface(H, up); ...
    kernelMeanWidth(H, up)]);
pivotLevelTwo = @(H, up, levelOne)([...
    levelOne; ...
    particleVolume(H, up, levelOne(1,:), levelOne(2,:), levelOne(3,:)); ...
    particleSurface(H, up, levelOne(2,:), levelOne(3,:)); ...
    particleMeanWidth(H, up, levelOne(3,:))]);
pivotLevelThree = @(H, up, levelTwo)([...
    levelTwo; ...
    muB(levelTwo(3,:), levelTwo(6,:), 1); ...
    muB(levelTwo(2,:), levelTwo(5,:), 2); ...
    muB(levelTwo(1,:), levelTwo(4,:), 3)])
pivotMeasures = @(H, up)(...
    pivotLevelThree(H, up, ...
      pivotLevelTwo(H, up, ...
        pivotLevelOne(H, up)...
        ) ...
      ) ...
    );
    
    
    


%% some testing
% muB1([0 0 0 0]', 1)
% muB2([0 0 0 0]', 1)
% muB3([0 0 0 0]', 1)
% 
% volTotal([0 0 0 0]', 1)
% surfTotal([0 0 0 0]', 1)
% mwTotal([0 0 0 0]', 1)
% 
% volKernel([0 0 0 0]', 1)
% surfKernel([0 0 0 0]', 1)
% mwKernel([0 0 0 0]', 1)