viewCrystal

PURPOSE ^

plot a crystal definition

SYNOPSIS ^

function patchHandleVector = viewCrystal(cdef, h, varargin)

DESCRIPTION ^

 plot a crystal definition

 Syntax: viewCrystal(cdef)

 In the simplest form, the crystal is displayed with all facets being
   present. The facets are colored according to their face groups. The plot also contains
   a legend that annotates the facet colors. The required fields of the
   struct cdef are: A and groupMappingMatrix (see obtainCrystal).

 h = viewCrystal returns the patch handles of the plotted crystal.

 viewCrystal(cdef, h) or viewCrystal(cdef, hC) uses the given h- or
   hC-vector to plot the crystal.

 viewCrystal(.., 'optionName', optionValue) accepts a list of options to
   adjust the behavior of this function:
     colorbar - switches the colorbar legend on (1) and off (0). 
                Default: 1
     colormap - is either a string for the selected colormap or a matrix 
                with predefined colors (see 'doc colormap'). Default:
                'jet'
     option - an option struct that is handed to viewPolytope (see
              viewPolytop for details. Default: []
     zerotol - zerotol is used to identify values that are close to zero 
               by zero. Default: elkZerotol

 See also: obtainCrystal

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function patchHandleVector = viewCrystal(cdef, h, varargin)
0002 % plot a crystal definition
0003 %
0004 % Syntax: viewCrystal(cdef)
0005 %
0006 % In the simplest form, the crystal is displayed with all facets being
0007 %   present. The facets are colored according to their face groups. The plot also contains
0008 %   a legend that annotates the facet colors. The required fields of the
0009 %   struct cdef are: A and groupMappingMatrix (see obtainCrystal).
0010 %
0011 % h = viewCrystal returns the patch handles of the plotted crystal.
0012 %
0013 % viewCrystal(cdef, h) or viewCrystal(cdef, hC) uses the given h- or
0014 %   hC-vector to plot the crystal.
0015 %
0016 % viewCrystal(.., 'optionName', optionValue) accepts a list of options to
0017 %   adjust the behavior of this function:
0018 %     colorbar - switches the colorbar legend on (1) and off (0).
0019 %                Default: 1
0020 %     colormap - is either a string for the selected colormap or a matrix
0021 %                with predefined colors (see 'doc colormap'). Default:
0022 %                'jet'
0023 %     option - an option struct that is handed to viewPolytope (see
0024 %              viewPolytop for details. Default: []
0025 %     zerotol - zerotol is used to identify values that are close to zero
0026 %               by zero. Default: elkZerotol
0027 %
0028 % See also: obtainCrystal
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('h', 'var') || isempty(h)
0048     h = ones([size(cdef.A, 1), 1]);
0049 end
0050 if size(h,1) == 1, h = h';end
0051 if length(h) == size(cdef.A, 1)
0052     % everything OK
0053 elseif length(h) == size(cdef.groupMappingMatrix, 2)
0054     h = cdef.groupMappingMatrix * h;
0055 else
0056     error('elk:crystal:wrongInput', ...
0057           'The input vector must either be an h- or an hC-vector');
0058 end
0059 nGroup = size(cdef.groupMappingMatrix, 2);
0060 
0061 %% Options handling
0062 [colorMap, f_colorbar, plotOptionStruct, zerotol, millerStringOption] = ...
0063     mapOption(varargin, ...
0064     'colormap', 'jet', ...
0065     'colorbar', 1, ...
0066     'option', struct([]), ...
0067     'zerotol', elkZerotol, ...
0068     'millerStringOption', {'{', 1});
0069 
0070 %% plot crystal
0071 hrep.A = cdef.A;
0072 hrep.h = h;
0073 patchHandleVector = viewPolytope(hrep, 'option', plotOptionStruct);
0074 
0075 %% find facet numbers
0076 patchIsFacet = zeros(1, length(patchHandleVector));
0077 for iPatch = 1:length(patchHandleVector)
0078     % m vertices in an m times 3 matrix.
0079     vertices = [get(patchHandleVector(iPatch), 'XData'), ...
0080                 get(patchHandleVector(iPatch), 'YData'), ...
0081                 get(patchHandleVector(iPatch), 'ZData')]';
0082     filter = ones([size(cdef.A, 1), 1]);
0083     for i_vertex = 1:size(vertices, 2)
0084         filter = filter & isZero(cdef.A*vertices(:,i_vertex) - h, zerotol);
0085     end
0086     if sum(filter) == 1
0087         patchIsFacet(iPatch) = find(filter);
0088     else
0089         %error('facet of patch can not be identified: either not unique or not existing');
0090     end
0091 end
0092 
0093 %% annotation handling
0094 % switch annotation
0095 %     case 'single'
0096 %         for i_patch = 1:length(patch_facet)
0097 %             if patch_facet(i_patch)==0, ann_str{i_patch} = '';continue;end;
0098 %             ann_str{i_patch} = '(';
0099 %             for j = 1:3
0100 %                 ann_str{i_patch} = [ann_str{i_patch} num2str(cdef.mil_complete(patch_facet(i_patch), j))];
0101 %                 if j < 3,ann_str{i_patch} = [ann_str{i_patch} ','];end;
0102 %             end
0103 %             ann_str{i_patch} = [ann_str{i_patch} ')'];
0104 %         end
0105 %     case 'groups'
0106 %         for i_patch = 1:length(patch_facet)
0107 %             if patch_facet(i_patch)==0, ann_str{i_patch} = '';continue;end;
0108 %             group = find(cdef.groupMappingMatrix(patch_facet(i_patch), :));
0109 %             ann_str{i_patch} = '\{';
0110 %             for j = 1:3
0111 %                 ann_str{i_patch} = [ann_str{i_patch} num2str(cdef.mil_defined(group, j))];
0112 %                 if j < 3,ann_str{i_patch} = [ann_str{i_patch} ','];end;
0113 %             end
0114 %             ann_str{i_patch} = [ann_str{i_patch} '\}'];
0115 %         end
0116 %     case iscell(annotation)
0117 %         switch length(annotation)
0118 %             case size(G, 1)
0119 %             case size(G, 2)
0120 %             otherwise
0121 %                 error('with strings given in annotation, the number of labels should match the number of facets or the number of facet groups');
0122 %         end
0123 %     otherwise
0124 %         for i_patch = 1:length(patch_facet)
0125 %             ann_str{i_patch} = '';
0126 %         end
0127 % end
0128 %
0129 % % make annotation
0130 % for i_patch = 1:length(patch_facet)
0131 %     if patch_facet(i_patch)==0,continue;end;
0132 %     %X = cdef.A(patch_facet(i_patch), :) * h(patch_facet(i_patch)) * 1.1;
0133 %     vertices = [get(h_patches(i_patch), 'XData'), ...
0134 %                 get(h_patches(i_patch), 'YData'), ...
0135 %                 get(h_patches(i_patch), 'ZData')]';
0136 %     X = mean(vertices, 2)' + cdef.A(patch_facet(i_patch), :) * max(...
0137 %                 [get(gca, 'XLim'), get(gca, 'YLim'), get(gca, 'ZLim')]...
0138 %                 ) / 10000;
0139 %     h_tmp = text(X(1), X(2), X(3), ann_str{i_patch});
0140 % end
0141 
0142 %% apply colors
0143 set(gca, 'Color', 'none');
0144 
0145 % assign color-data to patches
0146 for iPatch = 1:length(patchIsFacet)
0147     if patchIsFacet(iPatch)==0
0148         group = size(cdef.groupMappingMatrix, 2) + 1;
0149         set(patchHandleVector(iPatch), 'linestyle', 'none');
0150     else
0151         group = find(cdef.groupMappingMatrix(patchIsFacet(iPatch), :));
0152     end
0153     set(patchHandleVector(iPatch), 'CData', nGroup - group + 1, 'FaceColor', 'flat', ...
0154         'CDataMapping', 'direct');
0155 end
0156 
0157 % set limits of c-axis
0158 set(gca, 'CLim', [0.5, size(cdef.groupMappingMatrix, 2) + 0.5]);
0159 
0160 % determine colormap
0161 if ischar(colorMap)
0162     eval(['colorMap = colormap(' colorMap '(size(cdef.groupMappingMatrix, 2)));']);
0163 end
0164 colorMap = colorMap(end:-1:1, :);
0165 
0166 % apply colormap
0167 colormap(colorMap);
0168 
0169 % draw colorbar
0170 if f_colorbar
0171     handleColorBar = colorbar;
0172     % label colorbar
0173     for j = 1:size(cdef.groupMappingMatrix, 2)
0174         if length(millerStringOption) == 2
0175         labelColorBar{nGroup - j + 1} = convertMillerToString(...
0176             cdef.millerDefined(j,:), millerStringOption{1}, millerStringOption{2});
0177         elseif length(millerStringOption) == 1 && ~iscell(millerStringOption{1})
0178         labelColorBar{nGroup - j + 1} = millerStringOption{1};
0179         elseif length(millerStringOption) == 1 && iscell(millerStringOption{1})
0180         labelColorBar{nGroup - j + 1} = millerStringOption{1}{j};
0181         end
0182     end
0183     set(handleColorBar, 'YTick', 1:size(cdef.groupMappingMatrix, 2), 'YTickLabel', labelColorBar);
0184 end
0185        
0186 if nargout == 0
0187     clear patchHandleVector
0188 end

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