⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polyedit.m

📁 computation of conformal maps to polygonally bounded regions
💻 M
📖 第 1 页 / 共 3 页
字号:
  delete(data.Edges(k))
  data.Edges(k) = [];
end
guidata(data.Figure,data)


function PEClear(obj,varargin)
data = guidata(obj);
delete(data.Vertices)
delete(data.Edges)
data.Vertices = [];
data.Edges = [];
data.polyvertex = [];
data.polybeta = [];
data.atinf = [];
data.isclosed = 0;
data.addmode = 'first';
guidata(obj,data)
set(data.AddButton,'value',1)
PEAddMode(obj)


function PEFinish(obj,varargin)
data = guidata(obj);
pts = PE_get_clicks(data);
x = pts(:,1);  y = pts(:,2);
%%x = get(data.Vertices,'xdata');
%%y = get(data.Vertices,'ydata');
m = length(x);
n = length(x) - sum(data.atinf)/2;
if n > 1
  data.Edges(n) = plot(x([m,1]),y([m,1]),'-','user',n);
  if n==2
    % Special degenerate case.
    data.polybeta = [1;1];
  else
    % Find betas at last and first vertex.
    neworient = sign( diff( x([m 1])+i*y([m 1]) ) );
    if ~data.atinf(m)
      % Last vertex was finite.
      data.polybeta(n) = angle(data.orient/neworient) / pi;
    else
      % Last vertex was infinite.
      b = scangle( x([m-2:m 1])+i*y([m-2:m 1]) );
      b = b(2:3);
      b(b>0) = b(b>0) - 2;
      data.polybeta(n) = sum(b);
    end
    data.orient = neworient;
    % First vertex is always finite.
    neworient = sign( diff( x(1:2)+i*y(1:2) ) );
    data.polybeta(1) = angle(data.orient/neworient) / pi; 
  end
end
drawnow
% Let the user know if this thing is not legal.
try 
  polygon(data.polyvertex,data.polybeta+1);
catch
  warndlg('This is currently not a proper polygon','PolyEdit Warning',...
      'modal')
end
data.isclosed = 1;
set(data.Vertices,'color','b','markerfacecolor','b')
guidata(obj,data)
set(data.AddButton,'enable','off')
set(data.MoveButton,'value',1)
PEMoveMode(obj)
set(data.FinishButton,'enable','off')
set(data.AcceptButton,'enable','on')

function PEXLimSet(obj,varargin)
data = guidata(obj);
xlim = str2num(get(data.XLimEdit,'string'));
set(gca,'xlim',xlim)
PESnapMode(obj)
 
function PEYLimSet(obj,varargin)
data = guidata(obj);
ylim = str2num(get(data.YLimEdit,'string'));
set(gca,'ylim',ylim)
PESnapMode(obj)
 
function PEAccept(obj,varargin)
data = guidata(obj);
try 
  p = polygon( data.polyvertex, 1+data.polybeta);
catch
  errordlg('Not a proper polygon.','Polyedit error')
  p = polygon([]);
end
data.polygon = p;
guidata(obj,data)
uiresume

function PEQuit(obj,varargin)
data = guidata(obj);
p = polygon([]);
data.polygon = p;
guidata(obj,data)
uiresume


% Utility functions.

function pts = PE_get_clicks(data)
pts = get(data.Vertices,'user');
if isempty(pts)
  pts = zeros(0,2);
elseif size(pts,1)>1
  pts = cat(1,pts{:});
end

function adj = PE_adjacent_edges(data,idx)
n = length(data.polyvertex);
m = length(data.Edges);
if idx==1
  if ~data.isclosed
    adj = [NaN 1];
  else
    adj = [m 1];
  end
elseif idx==n & ~data.isclosed
  adj = [m NaN];
else
  adj = [idx-1 idx];
end


% GUI functions.

function PE_make_widgets(fig,axlim)

set(fig,'units','char','defaultuicontrolunits','char')
set(gca,'xlim',axlim(1:2),'ylim',axlim(3:4))

% Create uicontrol frames
uicontrol('style','frame','tag','SettingsFrame');
uicontrol('style','frame','tag','ActionsFrame');

% Load in icon data for settings
bg = get(0,'defaultuicontrolbackground');
names = {'addseq','addexist','move','eraser',...
      'trash','polyclose','OK','quit'};
for j=1:length(names)
  icons{j} = imread(['private/' names{j} '.png'],'back',bg);
end

widget(1) = uicontrol('style','toggle',...
    'cdata',icons{1},...
    'tooltip','Add vertices in sequence',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEAddMode,...
    'tag','AddButton');
widget(end+1) = uicontrol('style','toggle',...
    'cdata',icons{2},...
    'tooltip','Insert vertices',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEInsertMode,...
    'tag','InsertButton');
widget(end+1) = uicontrol('style','toggle',...
    'cdata',icons{3},...
    'tooltip','Move vertices',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEMoveMode,...
    'tag','MoveButton');
widget(end+1) = uicontrol('style','toggle',...
    'cdata',icons{4},...
    'tooltip','Delete vertices',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEDeleteMode,...
    'tag','DeleteButton');
widget(end+1) = uicontrol('style','push',...
    'cdata',icons{5},...
    'tooltip','Start over',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEClear,...
    'tag','ClearButton');
widget(end+1) = uicontrol('style','push',...
    'cdata',icons{6},...
    'tooltip','Add final side',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEFinish,...
    'tag','FinishButton');
widget(end+1) = uicontrol('style','push',...
    'cdata',icons{7},...
    'tooltip','Accept and exit',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEAccept,...
    'enable','off',...
    'tag','AcceptButton');
widget(end+1) = uicontrol('style','push',...
    'cdata',icons{8},...
    'tooltip','Discard and quit',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEQuit,...
    'tag','CancelButton');

names = {'snapxy','quantlen','quantang'};
for j=1:length(names)
  icons{j} = imread(['private/' names{j} '.png'],'back',bg);
end

widget(end+1) = uicontrol('style','text',...
    'string','x limits:',...
    'hor','r',...
    'tag','XLimText');
widget(end+1) = uicontrol('style','text',...
    'string','y limits:',...
    'hor','r',...
    'tag','YLimText');
widget(end+1) = uicontrol('style','edit',...
    'string',sprintf('[%.3g %.3g]',axlim(1:2)),...
    'tag','XLimEdit',...
    'call',@PEXLimSet);
widget(end+1) = uicontrol('style','edit',...
    'string',sprintf('[%.3g %.3g]',axlim(3:4)),...
    'tag','YLimEdit',...
    'call',@PEYLimSet );

widget(end+1) = uicontrol('style','toggle',...
    'cdata',icons{1},...
    'tooltip','Snap to grid',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PESnapMode,...
    'tag','SnapToggle');

widget(end+1) = uicontrol('style','toggle',...
    'cdata',icons{2},...
    'tooltip','Discretize length',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEDiscLenMode,...
    'tag','DiscLenToggle');
widget(end+1) = uicontrol('style','toggle',...
    'cdata',icons{3},...
    'tooltip','Discretize angle',...
    'unit','pix',...
    'pos',[0 0 42 42],...
    'call',@PEDiscAngMode,...
    'tag','DiscAngToggle');

widget(end+1) = uicontrol('style','text',...
    'string','Spacing:',...
    'hor','r',...
    'tag','SpacingText');
widget(end+1) = uicontrol('style','text',...
    'string','Quantum:',...
    'hor','r',...
    'tag','AngQuantText');
widget(end+1) = uicontrol('style','text',...
    'string','Quantum:',...
    'hor','r',...
    'tag','LenQuantText');

gridspace = diff(axlim(1:2))/16;
widget(end+1) = uicontrol('style','edit',...
    'string',sprintf('%.3g',gridspace),...
    'call',@PESnapMode,...
    'tag','GridSpaceEdit');
widget(end+1) = uicontrol('style','text',...
    'string','p / ',...
    'fontname','symbol',...
    'fontsize',11,...
    'hor','r',...
    'tag','PiText');
widget(end+1) = uicontrol('style','edit',...
    'string','6',...
    'tag','AngQuantEdit');
widget(end+1) = uicontrol('style','edit',...
    'string',sprintf('%.3g',2*gridspace),...
    'tag','LenQuantEdit');

set(gca,'unit','char','box','on','xgrid','off','ygrid','off',...
     'plotboxaspectratio',[1,1,1],'tag','Axes')

% Preview line
line(NaN,NaN,'linestyle','--','color','r','erasemode','norm',...
    'clipping','off','tag','PreviewLine');

data = guihandles(fig);

% Determine how large the icons are in character units on this computer. 
set(widget,'unit','char')
icon_size = get(widget(1),'pos');
data.iconsize = icon_size(3:4);

data.Figure = fig;
data.Edges = [];
data.Vertices = [];
data.currentpoint = [NaN NaN];
data.addmode = 'first';
data.atinf = [];
data.isclosed = 0;

guidata(fig,data)


function PE_resize_widgets(fig,varargin)

figpos = get(fig,'pos');
data = guidata(fig);

% Minimum sizes
figpos(3) = max(figpos(3),95);
figpos(4) = max(figpos(4),36);

set(fig,'pos',figpos)

h = figpos(4) - data.iconsize(2) - 0.5;
set(data.SettingsFrame,'pos',[figpos(3)-23 0 23 h])
set(data.ActionsFrame,'pos',[0 h figpos(3) data.iconsize(2)+0.5]);

% Leave a cushion around the axes
h = 10 + data.iconsize(2);
set(data.Axes,'pos',[ 8 5 figpos(3)-39 figpos(4)-h]);

% Settings
is = data.iconsize;
w = figpos(3) - 22;
wb = (21-is(1))/2;
h = figpos(4) - 2 - 2*is(2);
set(data.SnapToggle, 'pos',[w+wb h is(1) is(2)])
h = h - 1.75;
set(data.SpacingText, 'pos',[w+1 h 10 1.25])
set(data.GridSpaceEdit, 'pos',[w+11.5 h 9.5 1.5])
h = h - 2.5 - is(2);
set(data.DiscLenToggle, 'pos',[w+wb h is] )
h = h - 1.75;
set(data.LenQuantText, 'pos',[w+1 h 11 1.25])
set(data.LenQuantEdit, 'pos',[w+13 h 6 1.5])
h = h - 2.5 - is(2);
set(data.DiscAngToggle, 'pos',[w+wb h is] )
h = h - 1.75;
set(data.AngQuantText, 'pos',[w+1 h 10 1.25])
set(data.PiText, 'pos',[w+11.5 h 4 1.25])
set(data.AngQuantEdit, 'pos',[w+16 h 5 1.5])
h = h - 4;
set(data.XLimText, 'pos',[w+1 h 9 1.25])
set(data.XLimEdit, 'pos',[w+11 h 10 1.5])
h = h - 2.5;
set(data.YLimText, 'pos',[w+1 h 9 1.25])
set(data.YLimEdit, 'pos',[w+11 h 10 1.5])

% Actions
h = figpos(4) - data.iconsize(2) - 0.25;
dx = data.iconsize(1);
dy = data.iconsize(2);
set(data.AddButton, 'pos',[1 h dx dy])
set(data.MoveButton, 'pos',[1+dx h dx dy])
set(data.InsertButton, 'pos',[1+2*dx h dx dy])
set(data.DeleteButton, 'pos',[1+3*dx h dx dy])
set(data.ClearButton, 'pos',[4+4*dx h dx dy])
set(data.FinishButton, 'pos',[4+5*dx h dx dy])
set(data.AcceptButton, 'pos',[7+6*dx h dx dy])
set(data.CancelButton, 'pos',[7+7*dx h dx dy])

drawnow

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -