function varargout = Anatomical_atlas(varargin)
% ANATOMICAL_ATLAS MATLAB code for Anatomical_atlas.fig
%      ANATOMICAL_ATLAS, by itself, creates a new ANATOMICAL_ATLAS or raises the existing
%      singleton*.
%
%      H = ANATOMICAL_ATLAS returns the handle to a new ANATOMICAL_ATLAS or the handle to
%      the existing singleton*.
%
%      ANATOMICAL_ATLAS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ANATOMICAL_ATLAS.M with the given input arguments.
%
%      ANATOMICAL_ATLAS('Property','Value',...) creates a new ANATOMICAL_ATLAS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Anatomical_atlas_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Anatomical_atlas_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Anatomical_atlas

% Last Modified by GUIDE v2.5 25-May-2016 11:01:38

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Anatomical_atlas_OpeningFcn, ...
                   'gui_OutputFcn',  @Anatomical_atlas_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if 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 Anatomical_atlas is made visible.
function Anatomical_atlas_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 Anatomical_atlas (see VARARGIN)

% Choose default command line output for Anatomical_atlas
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
set(handles.chyba,'Visible','off');
global barva
barva=1;

% UIWAIT makes Anatomical_atlas wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Anatomical_atlas_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 structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global data
global max
[file, path]=uigetfile({'*.mat'},'Načíst data');
path_file=fullfile(path,file);
load(path_file);
max=size(data);
max=max(3);
vykresli(1,handles)




function Pixel_Callback(hObject, eventdata, handles)
% hObject    handle to Pixel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Pixel as text
%        str2double(get(hObject,'String')) returns contents of Pixel as a double


% --- Executes during object creation, after setting all properties.
function Pixel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Pixel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function rez_Callback(hObject, eventdata, handles)
% hObject    handle to rez (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of rez as text
%        str2double(get(hObject,'String')) returns contents of rez as a double
a=get(handles.rez,'String');
a=str2num(a);
% if(a>max && a<0)
%     vypsat error

vykresli(a,handles)

% --- Executes during object creation, after setting all properties.
function rez_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rez (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in plus.
function plus_Callback(hObject, eventdata, handles)
% hObject    handle to plus (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.chyba,'Visible','off');
a=get(handles.rez,'String');
a=str2num(a);
a=a+1;
global max
if(a>max)
     moc=num2str(max);
     text=['Rozsah musí být od 1 do ', moc, '!' ];
    set(handles.chyba,'Visible','on','String',text);  
    a=a-1;
end
vykresli(a,handles)



% --- Executes on button press in minus.
function minus_Callback(hObject, eventdata, handles)
% hObject    handle to minus (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.chyba,'Visible','off');
a=get(handles.rez,'String');
a=str2num(a);
a=a-1;
global max
if(a<1) 
    moc=num2str(max);
    text=['Rozsah musí být od 1 do ', moc, '!' ];
    set(handles.chyba,'Visible','on','String',text);  
    a=a+1;
end
vykresli(a,handles)




% --- Executes during object creation, after setting all properties.
function Gray_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Gray (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



% --- Executes on button press in Gray.
function Gray_Callback(hObject, eventdata, handles)
% hObject    handle to Gray (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

 % Hint: get(hObject,'Value') returns toggle state of Gray
%this is for gray scale
global barva
barva=2;
a=get(handles.rez,'String');
a=str2num(a);
vykresli(a,handles)


% --- Executes on button press in Jetk.
function Jetk_Callback(hObject, eventdata, handles)
% hObject    handle to Jetk (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of Jetk
global barva
barva=3;
a=get(handles.rez,'String');
a=str2num(a);
vykresli(a,handles)

function vykresli(i,handles) 
global data
global barva

if barva==1
    colormap(hot);
    imagesc(data(:,:,i));
elseif barva==2
    colormap(gray);
    imagesc(data(:,:,i));
elseif barva==3
    colormap(jet);
    imagesc(data(:,:,i));
else
    disp('error!')
end


pop=get(handles.popis, 'Value');

if pop==1                               %Vykreslování popisku
    hold on
a=get(handles.rez,'String');
a=str2num(a);
drawArrow = @(x,y,varargin) quiver( x(1),y(1),x(2)-x(1),y(2)-y(1),0, varargin{:});
  if a>0 && a<6
   set(handles.pop1,'Visible','on');
   set(handles.pop2,'Visible','off');
   set(handles.pop3,'Visible','off');
   text(150,28,'2','Color',[1 1 1],'FontSize',16)
   text(51,33,'1','Color',[1 1 1],'FontSize',16)
   text(203,40,'3','Color',[1 1 1],'FontSize',16)

x1 = [57 71];
y1 = [44 101];
x2=[147 132];
y2=[35 93];
x3=[198 136];
y3=[44 134];

drawArrow(x1,y1,'linewidth',1,'color','w'); hold on
drawArrow(x2,y2,'linewidth',1,'color','w'); hold on
drawArrow(x3,y3,'linewidth',1,'color','w'); hold off

   
  elseif a>5 && a<14
   set(handles.pop3,'Visible','off');
   set(handles.pop1,'Visible','off');   
   set(handles.pop2,'Visible','on');
   
   
x5=[181 155];
y5=[28 76];
x6=[149 137];
y6=[31 93];
x7=[229 142];
y7=[93 123];
x8=[216 168];
y8=[49 78] ; 

drawArrow(x5,y5,'linewidth',1,'color','w'); hold on
drawArrow(x6,y6,'linewidth',1,'color','w'); hold on
drawArrow(x8,y8,'linewidth',1,'color','w'); hold on
drawArrow(x7,y7,'linewidth',1,'color','w'); hold off

   text(184,25,'5','Color',[1 1 1],'FontSize',16)
   text(152,28,'4','Color',[1 1 1],'FontSize',16)
   text(232,90,'7','Color',[1 1 1],'FontSize',16)
   text(221,48,'6','Color',[1 1 1],'FontSize',16)
  elseif a>13 && a<=15
   set(handles.pop1,'Visible','off');
   set(handles.pop2,'Visible','off');
   set(handles.pop3,'Visible','on');
   text(170,30,'8','Color',[1 1 1],'FontSize',16)

x4=[168 133];
y4=[35 80];

drawArrow(x4,y4,'linewidth',1,'color','w'); hold off

  end                
else 
    set(handles.pop1,'Visible','off');
    set(handles.pop2,'Visible','off');
    set(handles.pop3,'Visible','off');
end


a=num2str(i);
set(handles.rez,'String',a)
hp=impixelinfo;
set(hp,'Position',[30 155 150 20]);
colorbar;


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes during object creation, after setting all properties.
function pushbutton4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



% --- Executes on button press in color.
function color_Callback(hObject, eventdata, handles)
% hObject    handle to color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of color
global barva
barva=1;
a=get(handles.rez,'String');
a=str2num(a);
vykresli(a,handles)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global data
data=imrotate(data,90);
vykresli(1,handles)


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in popis.
function popis_Callback(hObject, eventdata, handles)
vykresli(1,handles)


% --------------------------------------------------------------------
function matload_Callback(hObject, eventdata, handles)
% hObject    handle to matload (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function imgload_Callback(hObject, eventdata, handles)
% hObject    handle to imgload (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
