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

📄 plothdf.m

📁 低矮房屋风压系数、风荷载计算分析matlab程序
💻 M
📖 第 1 页 / 共 2 页
字号:
function plotHDF( HDF_pathname, bldg_struct )

%   Three-dimensional plotting of pressure tap locations, with wire frame 
%   between building corners. If building dimensions are provided as an
%   optional input argument, then taps can also be plotted with the
%   coordinates scaled to match the building dimensions. The reads
%   Hierarchical Data Format (HDF) pressure database files.
%   The following fields are required in the data file:

%   Tap_Coordinates_3D -- A 5-column matrix with each row defining the 
%       position of one pressure tap:
%       (1) tap #, (2)face #, (3) x-coordinate, (4) y-coord, (5) z-coord
%
%   Building_Corners_3D -- A 3-column matrix with each row defining the 
%       position of one corner of the building: 
%       (1) x-coordinate, (2) y-coord, (3) z-coord
%
%   Wire_Frame_Lines_3D -- A 2-column matrix with each row defining the 
%       numbers of the two building corners to be connected by a line 
%       segment. The corner numbers correspond to the rows of the matrix
%       Building_Corners_3D.

if ~exist('HDF_pathname','var') || isempty(HDF_pathname)
    % Load pathname for HDF files used in last analysis, if available, otherwise create empty string:
    if exist('tmp_HDF_path.mat','file'), load('tmp_HDF_path'); end
    if ~exist('HDF_path','var') || ~isstr(HDF_path), HDF_path = ''; end
    % Prompt user to select pressure database folder:
    HDF_path = uigetdir(HDF_path,'Select the directory containing HDF pressure database files to be displayed');
    if any(HDF_path~=0)
        save('tmp_HDF_path','HDF_path');
        HDF_pathname = HDF_path;
    else
        err = errordlg('HDF pressure database file selection cancelled', 'Analysis cancelled');
        uiwait(err); return;
    end
end

% Obtain list of HDF files in the specified folder:
dir_listing = dir(HDF_pathname);
file_list = dir_listing(find(cat(1,dir_listing.isdir)==0)); % eliminate directories from list
dir_ind = 0; % initialize index for counting the number of wind directions
for i = 1:length(file_list)
    filename = file_list(i).name; 
    hdf_ext_ind = strfind( filename, '.HDF' );
    if ~isempty(hdf_ext_ind)
        dir_ind = dir_ind+1;
        hdf_filename_root{dir_ind} = filename(1:hdf_ext_ind-5);
        theta_a_str(dir_ind,:) = filename(hdf_ext_ind-4:hdf_ext_ind-1);
        theta_a(dir_ind,1) = str2num( theta_a_str(dir_ind,:) )/10;
        theta_a_cell{dir_ind} = [num2str( str2num( theta_a_str(dir_ind,:) )/10 ) ' degrees'];
    end
end
hdf_filename_root = unique(hdf_filename_root);
if size(hdf_filename_root,1)~=1
    err = errordlg(['All HDF file names in the selected directory must be identical '...
        'except for the wind direction, specified by the last 4 characters before the file extension.'], ...
        'Error in pressure database folder contents');
    uiwait(err); return;
end
hdf_filename_root = hdf_filename_root{1};
if isempty( theta_a )
    err = errordlg(['No HDF files found in selected folder'], ...
        'Error in pressure database folder contents');
    uiwait(err); return;
end    

q = 1; % wind direction number

HDF_filename = [hdf_filename_root theta_a_str(q,:) '.HDF'];
HDF_full_filename = fullfile(HDF_pathname, HDF_filename);

HDF_struct = load_hdf_coords( HDF_full_filename );

% Extract sampling frequency (model scale) from HDF data structure:
f_s = HDF_struct.Data_Sample_Rate;

% Extract model dimensions (full-scale) from HDF data structure:
L = HDF_struct.Building_Length_Ft;
W = HDF_struct.Building_Width_Ft;
H = HDF_struct.Building_Height_Ft; % eave height
R = HDF_struct.Roof_Slope_in_12*W/2; % slope is given as rise (in inches) per foot of horizontal distance

tap_c0_3d = HDF_struct.Tap_Coordinates_3D; % tap #, face #, x-coord, y-coord, z-coord

% shift origin to opposite corner of model:
tap_c_3d = tap_c0_3d;
tap_c_3d(:,3) = W-tap_c0_3d(:,3);
tap_c_3d(:,4) = L-tap_c0_3d(:,4);
% eliminate internal pressure taps:
ext_ind = find(tap_c_3d(:,2)~=0);
tap_c_3d = tap_c_3d(ext_ind,:);
% eliminate taps on end walls:
ind_no_ends = intersect(find(tap_c_3d(:,4)~=0), find(tap_c_3d(:,4)~=L));
tap_c_3d = tap_c_3d(ind_no_ends,:);
% assign new face numbers:
tap_c_3d(find(tap_c_3d(:,3)==0),2) = 1;
tap_c_3d(find(tap_c_3d(:,3)>0 & tap_c_3d(:,3)<W/2 ),2) = 2;
tap_c_3d(find(tap_c_3d(:,3)==W/2 ),2) = 0;
tap_c_3d(find(tap_c_3d(:,3)>W/2 & tap_c_3d(:,3)<W),2) = 3;
tap_c_3d(find(tap_c_3d(:,3)==W),2) = 4;

tap_num = tap_c_3d (:,1);
for i=1:length(tap_num)
    tap_num_cell{i} = ['Tap ' num2str(tap_num(i))];
    tap_label_cell{i} = [' ' num2str(tap_num(i))];
end
[tf, tap_ind] = ismember(tap_num, HDF_struct.Tap_Position_List);

tap_circle = [];
tap_label = [];

% error checking (can be removed eventually)
% min(tap_lc(:,1)==tap_trib_bnds(:,1));
if ismember(0, tf)
    error('Tap number not found in "Tap_Position_List" field in HDF file.');
elseif ~isempty(setxor( tap_num, HDF_struct.Tap_Position_List(tap_ind)))
    error('Error in matching tap number with "Tap_Position_List" in HDF file.');
end
tap_sel = 1; % tap number initially selected for plotting


corners = HDF_struct.Building_Corners_3D;
line_ends = HDF_struct.Wire_Frame_Lines_3D;

face_list = unique(tap_c_3d(:,2));
color_list = {'r','b','g','m','c','y','k'};

tap_scale = 0;
if (exist('bldg_struct') && ~isempty(bldg_struct)) && (isfield(bldg_struct,'d0') && ~isempty(bldg_struct.d0))
    tap_scale = 1;
    % Extract structural dimensions from bldg_struct:
    W0 = bldg_struct.d0(1);
    L0 = bldg_struct.d0(2);
    H0 = bldg_struct.d0(3);
    R0 = bldg_struct.d0(4);

    % Scale tap coordinates:
    scl_tap_c_3d = tap_c_3d;
    scl_tap_c_3d(:,3) = scl_tap_c_3d(:,3)*W0/W; % scale x-coordinates
    scl_tap_c_3d(:,4) = scl_tap_c_3d(:,4)*L0/L; % scale y-coordinates
    % scale z-coordinates:
    roof_ind = find(scl_tap_c_3d(:,5)>H);
    wall_ind = find(scl_tap_c_3d(:,5)<=H);
    scl_tap_c_3d(roof_ind,5) = H0+(scl_tap_c_3d(roof_ind,5)-H)*R0/R;
    scl_tap_c_3d(wall_ind,5) = scl_tap_c_3d(wall_ind,5)*H0/H;
    
    % scale building corners:
    scl_corners = corners;
    scl_corners(:,1) = scl_corners(:,1)*W0/W; % scale x-coordinates
    scl_corners(:,2) = scl_corners(:,2)*L0/L; % scale y-coordinates
    % scale z-coordinates:
    roof_crn_ind = find(scl_corners(:,3)>H);
    wall_crn_ind = find(scl_corners(:,3)<=H);
    scl_corners(roof_crn_ind,3) = H0+(scl_corners(roof_crn_ind,3)-H)*R0/R;
    scl_corners(wall_crn_ind,3) = scl_corners(wall_crn_ind,3)*H0/H;
    
end


plot_img = 0;
HDF_fields = fieldnames(HDF_struct);
HDF_img_fields = HDF_fields(find(strncmp(HDF_fields,'Image',5)));
if ~isempty(HDF_img_fields)
    plot_img = 1;
    img_num = 1;
    for i=1:length(HDF_img_fields)
        HDF_img(i).img = HDF_struct.(HDF_img_fields{i});
    end
end

scrsz = get(0,'ScreenSize');
oX = scrsz(3)*.05;
oY = scrsz(4)*.1;
dX = scrsz(3)*.9;
dY = scrsz(4)*.8;
clr = get(0,'DefaultUicontrolBackgroundColor');

top_h = 6; % height of panel at top of figure
btm_h = 5; % height of menu panel at bottom of figure

% ************************* Create figure for plotting tap coordinates:

fig = figure('Color',clr,'Position',[oX oY dX dY],'Name','Plotting of Pressure Tap Coordinates','NumberTitle','off'); 
set( fig, 'Units', 'character');
Size = get( fig, 'Position');
Xc = Size(1);
Yc = Size(2);
X0 = Size(3);
Y0 = Size(4);
plot_h = Y0 - top_h - btm_h;
toggle_w = X0/4-2; % width of toggle buttons on menu panel at bottom
toggle_h = btm_h-1; % height of exit button on menu panel at top

menu_w = 70; % width of menu panel for plot selections at right edge


% create panel for selecting original or scaled tap coordinates:
top_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[0 Y0-top_h X0 top_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop','Title','Select tap coordinates to plot:');

orig_radio = uicontrol(top_panel, 'Style', 'radiobutton', 'String','Original tap coordinates','Value',1,...
    'Units','characters','Position',[4 top_h-3.5 60 1.5],...
    'Callback',@OrigCallback);
scaled_radio = uicontrol(top_panel, 'Style', 'radiobutton', 'String','Tap coordinates scaled to match building dimensions',...
    'Value',0,'Enable','off','Units','characters','Position',[4 top_h-5 60 1.5],...
    'Callback',@ScaledCallback);
if tap_scale
    set(scaled_radio,'Enable','on');
end

% create panel for selecting taps to label:
tap_label_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[X0-menu_w btm_h menu_w plot_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop','Title','Select pressure taps to label:');

uicontrol(tap_label_panel,'BackgroundColor',clr, 'Style', 'text', 'String','(ctrl-click or shift-click to select multiple)',...
    'HorizontalAlignment','left','Units','characters','Position',[2 plot_h-4 menu_w-4 1.5]);

tap_label_listbox = uicontrol(tap_label_panel, 'Style', 'listbox', 'String',tap_num_cell,'Value',tap_sel,...
    'Units','characters','Position',[2 plot_h-32 menu_w-4 28],'BackgroundColor','w','Enable','on',...
    'Min',1,'Max',length(tap_num),'Callback',@UpdateTapLabel);

plot_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[0 btm_h X0-menu_w plot_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop',...
    'Title',['Plot of pressure tap coordinates (filename: ' HDF_filename '):']);
plot_axes = axes('Parent',plot_panel);

menu_panel  = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[0 0 X0 btm_h]);

uicontrol(menu_panel, 'Style','pushbutton','String','Photos of Building Model',...
    'Units','characters','Position',[X0/8-toggle_w/2 0.5 toggle_w toggle_h],...
    'Callback',@ImgButtonCallback);

uicontrol(menu_panel, 'Style','togglebutton','String','Pressure Tap Locations','Value',1,'Enable','inactive',...
    'BackgroundColor',.87*[1 1 1],'Units','characters','Position',[X0*3/8-toggle_w/2 0.5 toggle_w toggle_h]);

uicontrol(menu_panel, 'Style','pushbutton','String','Pressure Time Series',...
    'Units','characters','Position',[X0*5/8-toggle_w/2 0.5 toggle_w toggle_h],...
    'Callback',@TSButtonCallback);

uicontrol(menu_panel, 'Style','pushbutton','String','Close',...
    'Units','characters','Position',[X0*7/8-toggle_w/2 0.5 toggle_w toggle_h],...
    'Callback',@ExitCallback);

% ************************* Create figure for displaying photos of model:

img_fig = figure('Color',clr,'Position',[oX oY dX dY],'Name','Plotting of Pressure Tap Coordinates','NumberTitle','off'); 
set( img_fig, 'Units', 'character');

% create panel for selecting frame to plot:
img_select_panel = uipanel('Parent',img_fig,'BackgroundColor',clr,'Units','character','Position',[0 Y0-top_h X0 top_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop','Title','Select image to plot:');
img_popup = uicontrol(img_select_panel, 'Style', 'popupmenu', 'String','','Value',img_num,...
    'Units','characters','Position',[2 top_h-4 70 1.5],'BackgroundColor','w','Enable','off',...
    'Callback',@ImgSelectCallback);
if plot_img
    set(img_popup,'String',HDF_img_fields,'Enable','on');
end
    

img_panel = uipanel('Parent',img_fig,'BackgroundColor',clr,'Units','character','Position',[0 btm_h X0 plot_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop',...
    'Title',['Photo of building model in the wind tunnel (filename: ' HDF_filename '):']);
img_axes = axes('Parent',img_panel);


img_menu_panel  = uipanel('Parent',img_fig,'BackgroundColor',clr,'Units','character','Position',[0 0 X0 btm_h]);


uicontrol(img_menu_panel, 'Style','togglebutton','String','Photos of Building Model','Value',1,'Enable','inactive',...
    'BackgroundColor',.87*[1 1 1],'Units','characters','Position',[X0/8-toggle_w/2 0.5 toggle_w toggle_h]);

uicontrol(img_menu_panel, 'Style','pushbutton','String','Pressure Tap Locations',...
    'Units','characters','Position',[X0*3/8-toggle_w/2 0.5 toggle_w toggle_h],...
    'Callback',@TapButtonCallback);

uicontrol(img_menu_panel, 'Style','pushbutton','String','Pressure Time Series',...
    'Units','characters','Position',[X0*5/8-toggle_w/2 0.5 toggle_w toggle_h],...
    'Callback',@TSButtonCallback);

uicontrol(img_menu_panel, 'Style','pushbutton','String','Close',...
    'Units','characters','Position',[X0*7/8-toggle_w/2 0.5 toggle_w toggle_h],...
    'Callback',@ExitCallback);

% ************************* Create figure for displaying pressure time series:

ts_fig = figure('Color',clr,'Position',[oX oY dX dY],'Name','Plotting of Pressure Time Series','NumberTitle','off'); 
set( ts_fig, 'Units', 'character');

% create panel for plotting time series:
ts_plot_panel = uipanel('Parent',ts_fig,'BackgroundColor',clr,'Units','character','Position',[0 btm_h X0-menu_w Y0-btm_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop',...
    'Title',['Time series of pressure coefficients (filename: ' HDF_filename '):']);
ts_plot_axes = axes('Parent',ts_plot_panel);

% create panel for selecting time series to plot:
ts_select_panel = uipanel('Parent',ts_fig,'BackgroundColor',clr,'Units','character','Position',[X0-menu_w btm_h menu_w Y0-btm_h],...
    'FontSize',12,'FontWeight','bold','TitlePosition','lefttop','Title','Select time series to plot (and save):');

uicontrol(ts_select_panel,'BackgroundColor',clr, 'Style', 'text', 'String','Select wind direction:',...
    'HorizontalAlignment','left','Units','characters','Position',[2 Y0-btm_h-4 menu_w-4 1.5]);

dir_popup = uicontrol(ts_select_panel, 'Style', 'popupmenu', 'String',theta_a_cell,'Value',q,...
    'Units','characters','Position',[2 Y0-btm_h-6 menu_w-4 1.5],'BackgroundColor','w','Enable','on',...

⌨️ 快捷键说明

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