?? polgui_ver1_r14.m
字號:
function varargout = polgui_ver1_r14(varargin)% -------------------------------------------------------------------------% Copyright (C) 2005-2008, Nitin B. Bangera (nitinb2@gmail.com)%% POLGUI is free software: you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation, either version 3 of the License, or% (at your option) any later version.% % This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.% % You should have received a copy of the GNU General Public License% along with this program. If not, see <http://www.gnu.org/licenses/>.% -------------------------------------------------------------------------% -- POLGUI Ver 1.0 for Matlab R14 -- % -------------------------------------------------------------------------% Matlab Interface for Polhemus Digitizer( Only with one stylus pen )% Author Nitin B Bangera % % NOTE : Set Screen Resolution to "1280 by 1024" or higher for GUI to be% displayed correctly% % Usage :% % % ------ polgui_ver1_r14, by itself, creates a new POLGUI_VER1_R14 with% default settings of 1 receivers (stylus pen)% % ------ modify line 235 to change EEG Montage % ------ modify line 271 and 273 to set Baud rate euivalent to that on% Polhemus (default set to 57600)% Baud Rate Settings on switch on back of Polhemus ( 1= UP, 0=Down)% Baud rate SW 1 SW 2 SW 3% 1200 0 0 0% 2400 1 0 0% 4800 0 1 0% 9600 1 1 0% 19200 0 0 1% 38400 1 0 1% 57600 0 1 1% 115200 1 1 1% Important Variables Saved: in file collected_data.mat% -------------------------------------------------------------------------% data_orig --> Original Data including the 3 consecutive points collected % for each location for averaging and pen movement error detection% data -> Averaged data% data_transf -> Data transformed to head co-ordinate frame% location -> Names of locations digitized% count -> Total number of digitized points% M -> Rotation matrix for transformation% T -> Translation matrix% -------------------------------------------------------------------------% Description of global variables and counters in the code % % needed_loc LOC DATA DATA_ORIG DATA_TRANSF COUNTER COUNTER1 special_case strmatch_index redigitize additional T M % % needed_loc -> chararcter array with the CARDINAL POINT locations% and EEG montage locations% LOC-> Set of digitized locations% DATA_ORIG -> Original Data before averaging% DATA -> Data after averaging 3 successive digitizations for each point% DATA_TRANSF -> Data after co-ordinate transformation% COUNTER -> Main Counter% COUNTER1-> Counter which includes count for 3 successive digitization for each point% Tag for 4 cases for remove button : % special_case% Case 0-> Initial Condition , Case 1-> counter <=4% Case 2-> Counter between 4 and length of needed montage % Case 3-> Additional Points% % strmatch_index -> matches current Vaue in the listbox with needed_loc matrix and returns index % redigitize -> Tag to check if redigitization is needed Values: 0 or 1% additional -> Tag to check if digitization of additional points is needed Values: 0 or 1% T -> Translation Matrix% M -> Rotation Matrtix% --------------------------------------------------------------------------% Steps for head digitization using POLGUI% 1.Before starting GUI, edit EEG_MONTAGE variable (on line 215 in this m-file) to set required% montage to be acquired. % % 2. Start GUI by typing name of this m-file in MATLAB command line (GUI% mode) e.g. polgui_ver4_r14 % % % Follow these steps in GUI by clicking on respective buttons in sequential% order% a. Initialise Device: % Serial Object created with specific Baud rate. Change this call back to% change serial port properties% % To digitize position the tip of the Isotrack Stylus at the desired point% and click on the dialog box within the GUI. The co-ordinates% displayed are the averages of three sequential readings taken from the% digitizer. If they differ from each other by more than 2 mm, you are asked% to digitize the point again.% % b. Get Test Point:% Secure one test point% % c. Get Cardinal Points in order LA(left Auricular), RA(Right Auricular)% and Nasion.% % d. Align Frame from device coordinates to head co-ordinate axes determined % by the cardinal points% Head Coordinate system:% The head coordinate system is defined as folloew: The x axis passes through the % preauricular points with positive values on the right, the y-axis will be% perpendicular to x axis, passing through the nasion and the positive axis % pointing towards the nose, and the z axis will be pointed up, perpendicular to xy plane.% The auricular points are known as anatomical landmarks or cardinal points.% % Principle: % When Align Frame is press, the coordinates of the cardinal locations will % change to head frame. Notice the z coordinates of all three points are% zero. The y coordinates of the auricular points are zero with a positive x% coordinate on the right and a negative on the left auricular point,% respectively. The nasion has a zero x coordinate and its y coordinate is% positive. The auricular points will be almost symmetrically located: their % x coordinates are opposite and about of equal magnitude % % -Procedure for alignment-------------------------------------------------% a1. Calculate the new origin coordinates o% Define three vectors a(nasion-la), b1(ra-la) and b2(la-ra)% Drop projection of a on b1 and b2 to calculatet1 and t2 respectively.% find ratio in which projection from b1 (point o) divides vector b1% o=la+t*b1 o=(Ox,Oy,Oz)% % b1. Define the three new coordinate axes ox(normalised ra-o),oy(normalised% nasion-o),oz(cross(ox,oy))% % c1. First translate orgin by -o% Define Translation matrix T as follows:% | 1 0 0 0|% | 0 1 0 0|% T = | 0 0 1 0|% |-Ox -Oy -Oz 0|% % d1. Then Rotate .Define Rotation Matrix M as folows:% R=[ox;oy;oz]% R1=inverse(R) or transpose(R)% |" " "|% |" R1 "|% M= |" " "|% |0 0 0|% % e1. Transform points to new co-ordinate axes with center at o and three% axes ox,oy and oz% [xnew ynew znew ]=[xold yold zold 1]*T*M;% -------------------------------------------------------------------------% e. Get EEG montage points.% % f. Get additional points% Fot additional points , click the stylus pen for digitization.% % g. Press stop to close the serial device and delete objects from memory.% -------------------------------------------------------------------------% % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @polgui_ver1_r14_OpeningFcn, ... 'gui_OutputFcn', @polgui_ver1_r14_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT%--------------------------------------------------------------------------% --- Executes just before polgui_ver1_r14 is made visible.function polgui_ver1_r14_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to polgui_ver1_r14 (see VARARGIN)set(hObject, 'Units', 'pixels');handles.banner = imread('head.png'); % Read the image file banner.jpginfo = imfinfo('head.png'); % Determine the size of the image fileaxes(handles.logo);image(handles.banner)set(handles.logo, ... 'Visible', 'off', ... 'Units', 'pixels');% Choose default command line output for polgui_ver1_r14handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes polgui_ver1_r14 wait for user response (see UIRESUME)% uiwait(handles.figure1);%--------------------------------------------------------------------------% --- Outputs from this function are returned to the command line.function varargout = polgui_ver1_r14_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;%--------------------------------------------------------------------------% --- Executes on button press in initialise.%Sets Baudrate and created serial object% To change port name and baudrate change int this callbackfunction initialise_Callback(hObject, eventdata, handles)% hObject handle to initialise (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% EEG Montage to be aquired . Pts 2,3 and 4 are cardinal points_pen% Edit EEG_MONTAGE to change EEG MontageEEG_MONTAGE=strvcat('Fp1','Fp2','F3','F4','C3','C4','P3',... 'P4','O1','02','F7','F8','T3','T4','T5','T6','FZ','CZ','PZ','OZ','A1','A2','Ref','PO1',... 'PO2','CP1','CP2','FTC1','FTC2','TCP1','TCP2','X31','X32','X33');handles.needed_loc=strvcat('test','LA','RA','NASION',EEG_MONTAGE);global special_case strmatch_index no_add additional redigitize T M k;handles.location=[]; % Handles structure for location nameshandles.data=[]; % Handles Structure for final DATA handles.count=1; % Handles structure for overall count of points digitizedspecial_case=0;% Tag for 4 cases for remove button : % Case 0-> Initial Condition , Case 1-> counter <=4% Case 2-> Counter between 4 and length of needed montage % Case 3-> Additional Pointsstrmatch_index=0;no_add=0; additional=0; % Tag to get additonal points, Values:0 or 1redigitize=0; % Tag to keep track of redigitization ,Values 0 or 1k=5;str1=sprintf('\n\n\nInitialising device \n');set(handles.points,'String',[]);set(handles.text1,'String',str1);set(handles.remove,'Enable','on');set(handles.get_test,'Enable','on');set(handles.align,'Enable','off');set(handles.get_la,'Enable','off');set(handles.get_ra,'Enable','off');set(handles.get_nasion,'Enable','off');set(handles.get_montage,'Enable','off');set(handles.get_additional,'Enable','off');set(handles.stop,'Enable','on');% Create serial object and set baud rate tmp_pc=ispc;if (tmp_pc) handles.s=serial('COM1','BaudRate',57600);else handles.s=serial('/dev/ttyS0','BaudRate',57600);end%handles.s=serial('COM1','BaudRate',57600);guidata(hObject,handles);str_text1=sprintf('\nDEVICE READY \n\n\nRemove : deletes last digitized point');str_text2=sprintf('\n\nGet Test Point');set(handles.text2,'String',str_text2);set(handles.text1,'String',str_text1);set(handles.initialise,'Enable','off');set(handles.text_nasion,'String','No Points Digitized');set(handles.text_la,'String','No Points Digitized');set(handles.text_ra,'String','No Points Digitized');%--------------------------------------------------------------------------% --- Executes on button press in stop.% Save data in mat file collected_datafunction stop_Callback(hObject, eventdata, handles)% hObject handle to stop (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.initialise,'Enable','on');global DATA DATA_ORIG DATA_TRANSF COUNTER1 COUNTER LOC count T M redigitize;data_orig=DATA_ORIG;data=DATA;data_transf=DATA_TRANSF;count=COUNTER-1;location=LOC;COUNTER1=[];COUNTER=[];DATA_ORIG=[];DATA=[];DATA_TRANSF=[];LOC=[];save collected_data data_orig data data_transf count location T M;hold(handles.coordinates,'off');fclose(handles.s);delete(handles.s);clear handles.s;clear handles.data;clear handles.location;clear handles.T; clear handles.M;guidata(hObject,handles);str3=sprintf('\n\n\nPOLGUI Ver 1.0');str4=sprintf('\n\n\nPoints Digitized\n\nPress "Initialise" to Start');set(handles.text1,'String',str3);set(handles.text2,'String',str4);set(handles.remove,'Enable','off');set(handles.stop,'Enable','off');set(handles.remove,'Enable','on');set(handles.get_test,'Enable','on');set(handles.align,'Enable','on');set(handles.get_la,'Enable','on');set(handles.get_ra,'Enable','on');set(handles.get_nasion,'Enable','on');set(handles.get_montage,'Enable','on');set(handles.get_additional,'Enable','on');clear data data_orig data_transf count location T M;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -