viewBoundaryShape

PURPOSE ^

plot a shape struct

SYNOPSIS ^

function varargout = viewBoundaryShape(shapeStruct)

DESCRIPTION ^

 plot a shape struct

 Syntax: objectHandleVector = viewBoundaryShape(shapeStruct)
   or    [hEdge, hVertex] = viewBoundaryShape(shapeStruct)

 Plot edges and vertices of shape struct, if the corresponding fields are
  present.

 See also: fitShapeBnd, viewBoundary, obtainBnd

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = viewBoundaryShape(shapeStruct)
0002 % plot a shape struct
0003 %
0004 % Syntax: objectHandleVector = viewBoundaryShape(shapeStruct)
0005 %   or    [hEdge, hVertex] = viewBoundaryShape(shapeStruct)
0006 %
0007 % Plot edges and vertices of shape struct, if the corresponding fields are
0008 %  present.
0009 %
0010 % See also: fitShapeBnd, viewBoundary, obtainBnd
0011 
0012 % The elk-library: convex geometry applied to crystallization modeling.
0013 %   Copyright (C) 2012 Alexander Reinhold
0014 %
0015 % This program is free software: you can redistribute it and/or modify it
0016 %   under the terms of the GNU General Public License as published by the
0017 %   Free Software Foundation, either version 3 of the License, or (at your
0018 %   option) any later version.
0019 %
0020 % This program is distributed in the hope that it will be useful, but
0021 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0022 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023 %   General Public License for more details.
0024 %
0025 % You should have received a copy of the GNU General Public License along
0026 %   with this program.  If not, see <http://www.gnu.org/licenses/>
0027 
0028 %% initialize plotting
0029 nextPlotState = get(gca, 'nextPlot');
0030 set(gca, 'nextPlot', 'add');
0031 
0032 %% plot edges
0033 if ~isempty(shapeStruct.hrep) && ~isempty(shapeStruct.hrep.A)
0034     % the incidence matrix tells in every column (=vertex) to which edges it
0035     %   belongs to (=row):
0036     incidenceMatrix = abs(bsxfun(@minus, ...
0037         shapeStruct.hrep.A * shapeStruct.vrep.V', ...
0038         shapeStruct.hrep.h)) < elkZerotol;
0039     hEdge = nan(1, size(incidenceMatrix, 1));
0040      
0041     for iEdge = 1:size(incidenceMatrix, 1)
0042         vertexIndex = find(incidenceMatrix(iEdge, :));
0043         vertexMatrix(1, :) = shapeStruct.vrep.V(vertexIndex(1), :) + ...
0044                              shapeStruct.lambda * shapeStruct.hrep.A(iEdge, :);
0045         vertexMatrix(2, :) = shapeStruct.vrep.V(vertexIndex(2), :) + ...
0046                              shapeStruct.lambda * shapeStruct.hrep.A(iEdge, :);
0047 
0048         hEdge(iEdge) = plot(vertexMatrix(:,1), ...
0049                             vertexMatrix(:,2), 'r-');         
0050     end
0051     set(hEdge, 'linewidth', 3, 'color', 'r');
0052 else
0053     hEdge = [];
0054     incidenceMatrix = [];
0055 end
0056 
0057 if isfield(shapeStruct, 'lambda') && shapeStruct.lambda > 0
0058     % we can use the incidence matrix from above from which we extrakt
0059     %   starting angle and end angle for each vertex
0060     nVertex = max(size(incidenceMatrix, 2), 1);
0061     hVertex = nan(1, nVertex);
0062     for iVertex = 1:nVertex
0063         if ~isempty(incidenceMatrix)
0064             edgeIndexVector = find(incidenceMatrix(:, iVertex));
0065             [edgeAngleVector tmp] = convertCartToPolar(...
0066                 shapeStruct.hrep.A(edgeIndexVector, 1)', ...
0067                 shapeStruct.hrep.A(edgeIndexVector, 2)');
0068             edgeAngleVector = sort(edgeAngleVector);
0069             if (edgeAngleVector(2) - edgeAngleVector(1)) > pi
0070                 edgeAngleVector = [edgeAngleVector(2) edgeAngleVector(1)+2*pi];
0071             end
0072             phi = edgeAngleVector(1):0.01:edgeAngleVector(2);
0073         else
0074             phi = 0:0.01:2*pi;
0075         end
0076         
0077         hVertex(iVertex) = plot(...
0078             shapeStruct.vrep.V(iVertex, 1) + shapeStruct.lambda*cos(phi), ...
0079             shapeStruct.vrep.V(iVertex, 2) + shapeStruct.lambda*sin(phi),  'k-');
0080     end
0081 
0082     set(hVertex, 'linewidth', 3, 'color', 'k')
0083 else
0084     hVertex = [];
0085 end
0086 
0087 %% cleanup
0088 set(gca, 'dataAspectRatio', [1 1 1]);
0089 set(gca, 'nextPlot', nextPlotState);
0090 
0091 if nargout == 2
0092     varargout{1} = hEdge;
0093     varargout{2} = hVertex;
0094 elseif nargout == 1
0095     varargout{1} = [hEdge, hVertex];
0096 end

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