function generatePointSets(result, pbeDef, optionStruct)
% generate 5 data sets as matrices in data folder
%
% ./data/<caseName>_pointSet_original
% ./data/<caseName>_pointSet_scaled
% ./data/<caseName>_pointSet_reduced
% ./data/<caseName>_pointSet_reducedAndScaled
% ./data/<caseName>_pointSet_scaledAndReduced
zerotol = 1e-6;

% standard options
stdOptionStruct.nBin = 50;
stdOptionStruct.nBatch = 10;
stdOptionStruct.nReduced = 100;
stdOptionStruct.viewStatistics = false;
stdOptionStruct.caseName = 'dump';
% merge input and standard options
optionStruct = mergeStruct(optionStruct, stdOptionStruct);
% get my location
myPath = fileparts(which(mfilename));

%% generate original data (read out)
dataPointSet = readResultData(result, pbeDef);
% distribution data information
dataStatistic = computeDistributionStatistics(dataPointSet, optionStruct.nBin);
if optionStruct.viewStatistics == true
    printDistributionStatistic(dataStatistic, ...
        ['Original data, nSample = ' num2str(length(dataPointSet.timeVector))] );
end
% save it
originalDataFileName = [myPath filesep 'data' filesep ...
    optionStruct.caseName '_pointSet_original.matx'];
save(originalDataFileName, '-mat', 'dataPointSet', 'dataStatistic');

%% reduce dataset
dataPointSet = reduceSampleData(dataPointSet, dataStatistic, optionStruct.nSample, optionStruct.nBatch);
dataStatistic = computeDistributionStatistics(dataPointSet, optionStruct.nBin);
if optionStruct.viewStatistics == true
    printDistributionStatistic(dataStatistic, ...
        ['Reduced data, nSample = ' num2str(length(dataPointSet.timeVector))] );
end
% save it
save([myPath filesep 'data' filesep optionStruct.caseName ...
    '_pointSet_reduced.matx'], 'dataPointSet', 'dataStatistic');

%% scale reduced dataset
dataPointSet.hcMatrix = bsxfun(@times, dataPointSet.hcMatrix, 1./...
    computeMeasureDec(pbeDef.dec, 'hC', dataPointSet.hcMatrix, 'volume', zerotol, [], 1).^(1/3));
dataStatistic = computeDistributionStatistics(dataPointSet, optionStruct.nBin);
% print
if optionStruct.viewStatistics == true
    printDistributionStatistic(dataStatistic, ...
        ['Reduced and Scaled data, nSample = ' ...
         num2str(length(dataPointSet.timeVector))] );
end
% save
save([myPath filesep 'data' filesep optionStruct.caseName ...
    '_pointSet_reducedScaled.matx'], 'dataPointSet', 'dataStatistic');


%% scale original dataset
clear data dataStatistic
load(originalDataFileName, '-mat');
dataPointSet.hcMatrix = bsxfun(@times, dataPointSet.hcMatrix, 1./...
    computeMeasureDec(pbeDef.dec, 'hC', dataPointSet.hcMatrix, 'volume', zerotol, [], 1).^(1/3));
dataStatistic = computeDistributionStatistics(dataPointSet, optionStruct.nBin);
% print
if optionStruct.viewStatistics == true
    printDistributionStatistic(dataStatistic, ...
        ['Scaled data, nSample = ' ...
         num2str(length(dataPointSet.timeVector))] );
end
% save
save([myPath filesep 'data' filesep optionStruct.caseName ...
    '_pointSet_scaled.matx'], 'dataPointSet', 'dataStatistic');

%% reduce scaled dataset
dataPointSet = reduceSampleData(dataPointSet, dataStatistic, optionStruct.nSample, optionStruct.nBatch);
dataStatistic = computeDistributionStatistics(dataPointSet, optionStruct.nBin);
if optionStruct.viewStatistics == true
    printDistributionStatistic(dataStatistic, ...
        ['Scaled and Reduced data, nSample = ' num2str(length(dataPointSet.timeVector))] );
end
% save it
save([myPath filesep 'data' filesep optionStruct.caseName ...
    '_pointSet_scaledReduced.matx'], 'dataPointSet', 'dataStatistic');

