convertVrepToHrep

PURPOSE ^

convert a V-representation into a H-representation

SYNOPSIS ^

function hrep = convertVrepToHrep(vrep, zerotol, flatness, useCddlib)

DESCRIPTION ^

 convert a V-representation into a H-representation

 Syntax: hrep = convertVrepToHrep(vrep)
   or    hrep = convertVrepToHrep(vrep, zerotol, flatness)

 The parameter zerotol applies for scaleVrep only (default is elkZerotol).

 Consider that cddlib applies an additional zerotol that is stored in the 
   function zerotolCddlib during initialization of this library 
   (buildCddlib).

 The parameter flatness is only applied if the dimension of the object is 
   smaller than the dimension it is embedded in (e.g. a 2D object in 3D 
   space). The flatness is applied by adding [flatness/2] to all facet 
   distances for which the corresponding hyperplane fully contains the
   polytope.

 There are two underlying methods to perform this conversion. The direct
   approach uses triangulation (convhulln). An alternative approach is to 
   utilize duality and use convertHrepToVrep with the underlying 
   double-description method (cddlib). The default is choosen by 
   speed and reliability. The alternative is used if this approach fails.

 convert(.., prefereCddlib) gives the possibility to change the default
   standard algorithm to be used. Default: 0

 See also: convertPolytope, convertHrepToVrep, scaleVrep

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hrep = convertVrepToHrep(vrep, zerotol, flatness, useCddlib)
0002 % convert a V-representation into a H-representation
0003 %
0004 % Syntax: hrep = convertVrepToHrep(vrep)
0005 %   or    hrep = convertVrepToHrep(vrep, zerotol, flatness)
0006 %
0007 % The parameter zerotol applies for scaleVrep only (default is elkZerotol).
0008 %
0009 % Consider that cddlib applies an additional zerotol that is stored in the
0010 %   function zerotolCddlib during initialization of this library
0011 %   (buildCddlib).
0012 %
0013 % The parameter flatness is only applied if the dimension of the object is
0014 %   smaller than the dimension it is embedded in (e.g. a 2D object in 3D
0015 %   space). The flatness is applied by adding [flatness/2] to all facet
0016 %   distances for which the corresponding hyperplane fully contains the
0017 %   polytope.
0018 %
0019 % There are two underlying methods to perform this conversion. The direct
0020 %   approach uses triangulation (convhulln). An alternative approach is to
0021 %   utilize duality and use convertHrepToVrep with the underlying
0022 %   double-description method (cddlib). The default is choosen by
0023 %   speed and reliability. The alternative is used if this approach fails.
0024 %
0025 % convert(.., prefereCddlib) gives the possibility to change the default
0026 %   standard algorithm to be used. Default: 0
0027 %
0028 % See also: convertPolytope, convertHrepToVrep, scaleVrep
0029 
0030 % The elk-library: convex geometry applied to crystallization modeling.
0031 %   Copyright (C) 2012 Alexander Reinhold
0032 %
0033 % This program is free software: you can redistribute it and/or modify it
0034 %   under the terms of the GNU General Public License as published by the
0035 %   Free Software Foundation, either version 3 of the License, or (at your
0036 %   option) any later version.
0037 %
0038 % This program is distributed in the hope that it will be useful, but
0039 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0040 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0041 %   General Public License for more details.
0042 %
0043 % You should have received a copy of the GNU General Public License along
0044 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0045 
0046 %% Input handling
0047 if ~exist('zerotol', 'var') || isempty(zerotol)
0048     zerotol = elkZerotol;
0049 end
0050 if ~exist('flatness', 'var') || isempty(flatness)
0051     flatness = 0;
0052 end
0053 if ~exist('useCddlib', 'var') || isempty(useCddlib)
0054     useCddlib = 0;
0055 end
0056 if isempty(vrep.V)
0057     hrep.A = vrep.V;
0058     hrep.h = [];
0059     return
0060 end
0061 vrepDim = size(vrep.V, 2);
0062 
0063 %% Reduce dimension if flat
0064 [vrepReduced, reduceTrafo, reduceOffset] = reduceVrepDimension(vrep, zerotol);
0065 reducedDim = size(vrepReduced.V, 2);
0066 
0067 %% Scale polytope
0068 [vrepScaled, scale, scaleOffset] = scaleVrep(vrepReduced, zerotol);
0069 
0070 % outer conversion structure
0071 useAlternative = 0;
0072 while useCddlib > -1
0073 try
0074     if ~useCddlib
0075         %% direct approach (convhulln)
0076         hrep = convertVrepToHrepByConvhulln(vrepScaled, zerotol);
0077     else
0078         %% dual approach (cddlib)
0079         % map to dual polytope in H-representation
0080         dualHrep = computeDualPolytope(vrepScaled);
0081         
0082         % convert to dual Vrep
0083         dualVrep = convertHrepToVrep(dualHrep, zerotol, inf, 1);
0084         
0085         % convert back to normal Hrep
0086         hrep = computeDualPolytope(dualVrep);
0087     end
0088     % assign to exit loop:
0089     useCddlib = -1;
0090 catch thisError
0091     if ~useAlternative
0092         warning('elk:conversion:method', thisError.message);
0093         warning('elk:conversion:method', ...
0094             'Using alternative approach to convert polytope.');
0095         useAlternative = 1;
0096         useCddlib = ~useCddlib;
0097     else
0098         % safe input polytope
0099         if exist('log_convertVrepToHrep.mat', 'file')
0100             load log_convertVrepToHrep.mat
0101             logVrep{end+1} = vrep;
0102         else
0103             logVrep{1} = vrep;
0104         end
0105         save log_convertVrepToHrep.mat logVrep
0106         warning('elk:polytope:method', ...
0107             ['Given vrep cannot be converted to hrep (usually cddlib). ' ...
0108             'Polytope stored in: ' cd filesep 'log_convertVrepToHrep.mat']);
0109         rethrow(thisError);
0110     end
0111 end
0112 end
0113 
0114 %% Revert scaling
0115 hrep = stretchHrep(hrep, scale, zeros(length(scale), 1));
0116 hrep = moveHrep(hrep, scaleOffset);
0117 
0118 %% Project back to original dimension
0119 if reducedDim < vrepDim
0120     hrep = liftHrepDimension(hrep, reduceTrafo, reduceOffset, flatness);
0121 end
0122 
0123 %% apply flatness
0124 % flatFacetIndexList = (1:(2*(vrepDim-reducedDim))) + size(hrep.A, 1);
0125 % hrep.h(flatFacetIndexList) = hrep.h(flatFacetIndexList) + flatness/2;
0126 
0127 %% Normalize
0128 hrep = normalizeHrep(hrep);
0129

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