obtainMeasureInfo

PURPOSE ^

returns information of an available measures in a struct

SYNOPSIS ^

function measureStruct = obtainMeasureInfo(measureName, facetNormalMatrix)

DESCRIPTION ^

 returns information of an available measures in a struct

 Syntax: measureStruct = obtainMeasureInfo(measureName)
   or    measureStruct = obtainMeasureInfo(measureName, facetNormalMatrix)

 Translates a measure name to a known measure in form of a struct
   containing the following information:
     .name  - the name of the measure
     .dim   - the dimension of the measure refering a 3-dimensional object
     .isPar - whether the measure requires a parameter that usually is a
              direction
     .handleHrep - this is a function handle (anonymous function) to the
                   function that calculates the measure based on a
                   H-representaation.
     .handleVrep - same as above based on a V-representaation.
     .handleH - same as above based on a h- vector (only provided, if matrix of
                facet normals is provided)

 The input measureName might be empty so that all possible measures are
   returned in a struct vector. Or a cell array of measure names are
   provided which results in a struct vector of the given measures.

 Available measures and possible names:
   volume - volume
   surface - surface, surfaceArea, surface area
   facet - facet, facetArea, facet area
   projection - projection, projectionArea, projection area
   feret - feret, feret diameter
   support - support, support value
   meanWidth - meanWidth, mean width
   edgeLength - edgeLength, edge length

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function measureStruct = obtainMeasureInfo(measureName, facetNormalMatrix)
0002 % returns information of an available measures in a struct
0003 %
0004 % Syntax: measureStruct = obtainMeasureInfo(measureName)
0005 %   or    measureStruct = obtainMeasureInfo(measureName, facetNormalMatrix)
0006 %
0007 % Translates a measure name to a known measure in form of a struct
0008 %   containing the following information:
0009 %     .name  - the name of the measure
0010 %     .dim   - the dimension of the measure refering a 3-dimensional object
0011 %     .isPar - whether the measure requires a parameter that usually is a
0012 %              direction
0013 %     .handleHrep - this is a function handle (anonymous function) to the
0014 %                   function that calculates the measure based on a
0015 %                   H-representaation.
0016 %     .handleVrep - same as above based on a V-representaation.
0017 %     .handleH - same as above based on a h- vector (only provided, if matrix of
0018 %                facet normals is provided)
0019 %
0020 % The input measureName might be empty so that all possible measures are
0021 %   returned in a struct vector. Or a cell array of measure names are
0022 %   provided which results in a struct vector of the given measures.
0023 %
0024 % Available measures and possible names:
0025 %   volume - volume
0026 %   surface - surface, surfaceArea, surface area
0027 %   facet - facet, facetArea, facet area
0028 %   projection - projection, projectionArea, projection area
0029 %   feret - feret, feret diameter
0030 %   support - support, support value
0031 %   meanWidth - meanWidth, mean width
0032 %   edgeLength - edgeLength, edge length
0033 %
0034 
0035 % The elk-library: convex geometry applied to crystallization modeling.
0036 %   Copyright (C) 2012 Alexander Reinhold
0037 %
0038 % This program is free software: you can redistribute it and/or modify it
0039 %   under the terms of the GNU General Public License as published by the
0040 %   Free Software Foundation, either version 3 of the License, or (at your
0041 %   option) any later version.
0042 %
0043 % This program is distributed in the hope that it will be useful, but
0044 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0045 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0046 %   General Public License for more details.
0047 %
0048 % You should have received a copy of the GNU General Public License along
0049 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0050 
0051 %% Input
0052 if ~exist('facetNormalMatrix', 'var')
0053     facetNormalMatrix = [];
0054 end
0055 if ~exist('measureName', 'var') || isempty(measureName)
0056     measureName = {'volume', ...
0057                    'surface', 'facet', 'projection', ...
0058                    'feret', 'support'};
0059 end
0060 if ~iscell(measureName)
0061     measureName = {measureName};
0062 end
0063 
0064 %% Build struct
0065 measureStruct = struct();
0066 for iMeasure = 1:length(measureName)
0067     [thisMeasureStruct functionName] = internalMeasureInfo(measureName{iMeasure});
0068     measureStruct(iMeasure).name = thisMeasureStruct.name;
0069     measureStruct(iMeasure).dim = thisMeasureStruct.dim;
0070     measureStruct(iMeasure).isPar = thisMeasureStruct.isPar;
0071     
0072     if ~measureStruct(iMeasure).isPar
0073         % handle for V- and H-representation
0074         measureStruct(iMeasure).handleVrep = @(vrep)(eval(...
0075             [functionName 'Vrep(vrep)']));
0076         measureStruct(iMeasure).handleHrep = @(hrep)(eval(...
0077             [functionName 'Hrep(hrep)']));
0078         % handles for H and Hc vectors
0079         if ~isempty(facetNormalMatrix)
0080             measureStruct(iMeasure).handleH = @(h)(...
0081                 measureStruct(iMeasure).handleHrep(struct(...
0082                 'A', facetNormalMatrix, 'h', h)));
0083         end
0084     else
0085         % handle for V- and H-representation
0086         measureStruct(iMeasure).handleVrep = @(vrep, par)(eval(...
0087             [functionName 'Vrep(vrep, par)']));
0088         measureStruct(iMeasure).handleHrep = @(hrep, par)(eval(...
0089             [functionName 'Hrep(hrep, par)']));
0090         % handles for H and Hc vectors
0091         if ~isempty(facetNormalMatrix)
0092             measureStruct(iMeasure).handleH = @(h,par)(...
0093                 measureStruct(iMeasure).handleHrep(struct(...
0094                 'A', facetNormalMatrix, 'h', h), ...
0095                 par));
0096         end
0097     end
0098 
0099 end
0100 
0101 end
0102 
0103 function [measureStruct, functionName] = internalMeasureInfo(measureName)
0104 
0105 %% Volume
0106 if strcmp(measureName, 'volume')
0107         measureStruct.name = 'volume';
0108         measureStruct.dim = 3;
0109         measureStruct.isPar = 0;
0110         functionName = 'computeVolume';
0111         
0112 %% Surface
0113 elseif strcmpi(measureName, 'surface') || ...
0114        strcmpi(measureName, 'surfaceArea') || strcmp(measureName, 'surface area')
0115 
0116         measureStruct.name = 'surface';
0117         measureStruct.dim = 2;
0118         measureStruct.isPar = 0;
0119         functionName = 'computeFacetArea';
0120         
0121 %% Facet
0122 elseif strcmpi(measureName, 'facet') || ...
0123        strcmpi(measureName, 'facetarea') || strcmpi(measureName, 'facet area')
0124 
0125         measureStruct.name = 'facet';
0126         measureStruct.dim = 2;
0127         measureStruct.isPar = 1;
0128         functionName = 'computeFacetArea';
0129 
0130 %% Projection Area
0131 elseif strcmpi(measureName, 'projection') || ...
0132        strcmpi(measureName, 'projectionArea') || strcmpi(measureName, 'projection area')
0133 
0134         measureStruct.name = 'projection';
0135         measureStruct.dim = 2;
0136         measureStruct.isPar = 1;
0137         functionName = 'computeProjectionArea';
0138         
0139 %% Feret Diameter
0140 elseif strcmpi(measureName, 'feret') || strcmpi(measureName, 'feret diameter')
0141 
0142         measureStruct.name = 'feret';
0143         measureStruct.dim = 1;
0144         measureStruct.isPar = 1;
0145         functionName = 'computeFeret';
0146                                    
0147 %% Support value
0148 elseif strcmpi(measureName, 'support') || strcmpi(measureName, 'support value')
0149         measureStruct.name = 'support';
0150         measureStruct.dim = 1;
0151         measureStruct.isPar = 1;
0152         functionName = 'computeSupportValue';
0153         
0154 %% Mean width
0155 elseif strcmpi(measureName, 'meanWidth') || strcmpi(measureName, 'mean width')
0156         measureStruct.name = 'meanWidth';
0157         measureStruct.dim = 1;
0158         measureStruct.isPar = 0;
0159         functionName = 'computeMeanWidth';    
0160 %% Mean width
0161 elseif strcmpi(measureName, 'edgeLength') || strcmpi(measureName, 'edge length')
0162         measureStruct.name = 'edgeLength';
0163         measureStruct.dim = 1;
0164         measureStruct.isPar = 1;
0165         functionName = 'computeEdgeLength';   
0166 else
0167 %% Failure
0168         error('elk:polytope:wrongInput', ...
0169             ['Given measure ''' measureName ''' is unknown']);
0170 end
0171 
0172 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005