function varargout = Mark4Cam(varargin)
% MARK4CAM M-file for Mark4Cam.fig
%      MARK4CAM, by itself, creates a new MARK4CAM or raises the existing
%      singleton*.
%
%      H = MARK4CAM returns the handle to a new MARK4CAM or the handle to
%      the existing singleton*.
%
%      MARK4CAM('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MARK4CAM.M with the given input arguments.
%
%      MARK4CAM('Property','Value',...) creates a new MARK4CAM or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Mark4Cam_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Mark4Cam_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 Mark4Cam

% Last Modified by GUIDE v2.5 11-Feb-2010 19:00:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Mark4Cam_OpeningFcn, ...
                   'gui_OutputFcn',  @Mark4Cam_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 Mark4Cam is made visible.
function Mark4Cam_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 Mark4Cam (see VARARGIN)

% Choose default command line output for Mark4Cam
handles.output = hObject;
set(handles.check_cam,'Value',1);

handles.cams   = getappdata(0,'cams');
handles.voxels = getappdata(0,'voxels');
handles.space  = getappdata(0,'space');
handles.latovoxel = getappdata(0,'latovoxel');
handles.markers = getappdata(0,'markers');

set(handles.plot_cam,'view',[75,20]);
grid(handles.plot_cam,'on');
grid(handles.plot_overlap,'on');
rotate3d on;
set(hObject,'toolbar','figure');

% [handles.cams handles.voxels]=mark2vox(handles.markers, handles.cams,...
%                                        handles.voxels,...
%                                        handles.space,handles.latovoxel);
guidata(hObject, handles);
                                   
% for i=1:size(handles.cams,2)
%     handles.pos =  [handles.pos; handles.cams(i).position'];
%     handles.cam_angles = [handles.cam_angles; handles.cams(i).angles'];
%     handles.cam_voxels{i}= num2str(handles.cams(i).voxels);
%     %handles.cam_setmark{i}= num2str(handles.cam(i).setmarkers);    
%     %setmark =  [setmark; handles.cams(i).setmark];
%     handles.rowname{i} = ['camera' num2str(i)];
% end
size(handles.cams,2)
% data=zeros(size(handles.cams,2),4)
% handles.data=data
for i=1:size(handles.cams,2)
    if ~isempty(handles.cams(i).setmarkers)
    handles.data(i,:)={['   [  ' num2str(handles.cams(i).position') ' ]'],...
                       [ '  [  ' num2str(handles.cams(i).angles') ' ]'],...
                       [ '  [ ' num2str(handles.cams(i).voxels) ' ]']...
                       [ '  [ ' num2str(handles.cams(i).setmarkers(1,:)) ']']};
    elseif isempty(handles.cams(i).setmarkers) && ~isempty(handles.cams(i).voxels)
        num2str(handles.cams(i).position')
        num2str(handles.cams(i).angles')
        num2str(handles.cams(i).voxels)
    handles.data(i,1)= {cat(2,'   [ ', num2str(handles.cams(i).position'), ' ]')}
    handles.data(i,2)= {cat(2,'  [ ', num2str(handles.cams(i).angles'), ' ]')}
    handles.data(i,3)= {cat(2,'  [ ', num2str(handles.cams(i).voxels),' ]')}
    handles.data(i,4)= {cat(2,'  [ ', 0, ' ]')}

    else
    handles.data(i,:)={['   [  ' num2str(handles.cams(i).position') ' ]'],...
                       [ '  [  ' num2str(handles.cams(i).angles') ' ]'],...
                       [ '  0 '],...
                       [ '  0 ']};     
    end
    
    handles.rowname{i} = ['camera' num2str(i)];
end
set(handles.popup_cam,'Value',1);

columnname =   {'position','angles','set voxels','set markers'};
%columnformat = {'numeric', 'bank', [], {'Fixed' 'Adjustable'}}; 
%columneditable =  [false false true true]; 
% t = uitable('Units','normalized','Position',...
%             [0.1 0.1 0.9 0.9], 'Data', dat,... 
%             'ColumnName', columnname,...
%             'ColumnFormat', columnformat,...
%             'ColumnEditable', columneditable);

set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'Units','char',...
                      'columnwidth',{'auto',57*3,...
                      max(80,length( num2str(handles.cams(1).voxels))*5),...
                      max(80,length( num2str(handles.cams(1).setmarkers))*5)},...
                      'Data',handles.data);
       
% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Mark4Cam_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)


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

cla(handles.plot_cam);
for i=1:size(handles.markers,2)
    axes(handles.plot_cam);
    voxel(handles.markers(:,i),[0.2 0.2 0.2],'y',1);
end
set(handles.plot_cam,'XLim',[-2 handles.space(1)+2],...
                      'YLim',[-2 handles.space(2)+2],...
                      'ZLim',[-2 handles.space(3)+2]); 
                  
plotcam3(handles.cams,handles.space,handles.voxels,...
             handles.latovoxel,[1 1 1 1 0 0]);

voxel([handles.space(1)/2,handles.space(2)/2,handles.space(3)/2],...
      [handles.space(1),handles.space(2),handles.space(3)],'g',0);

guidata(hObject,handles);

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

set(handles.plot_cam,'XLim',[-2 handles.space(1)+2],...
                      'YLim',[-2 handles.space(2)+2],...
                      'ZLim',[-2 handles.space(3)+2]);
axes(handles.plot_cam);
handles.show=[get(handles.check_cam,'Value'),...
              get(handles.check_versori,'Value'),...
              get(handles.check_FOV,'Value'),...
              0,...
              0,...
              0,0];
if get(handles.check_allmark,'Value')==1
    for i=1:size(handles.markers,2)
        voxel(handles.markers(:,i),[0.1 0.1 0.1],'y',0.5);
    end
end

if strcmp(get(handles.edit_cam,'String'),'All')
    plotcam3(handles.cams,handles.space,handles.voxels,...
         handles.latovoxel,handles.show);
    for i=1:size(handles.cams,2)
        text(handles.cams(i).position(1),...
             handles.cams(i).position(2),...
             handles.cams(i).position(3)+0.45,...
             num2str(i),'fontsize',11,'color','m');
    end
if get(handles.check_mark_inside,'value')==1
    axes(handles.plot_cam)
        for i=1:size(handles.cams,2)
            hold on
            setmark = handles.cams(i).setmarkers(1,:)
            %axes(handles.plot_cam)
            plot3(handles.markers(1,setmark),...
                  handles.markers(2,setmark),...
                  handles.markers(3,setmark),'r.')                  
        end
end
else
    label   = str2num(get(handles.edit_cam,'String'));
    plotcam3(handles.cams(label),handles.space,handles.voxels,...
         handles.latovoxel,handles.show);
     
    for i=1:size(label,2)
        text(handles.cams(label(i)).position(1),...
             handles.cams(label(i)).position(2),...
             handles.cams(label(i)).position(3)+0.45,...
             num2str(label(i)),'fontsize',11,'color','m');
        if get(handles.check_occlused,'value')==1
             for j=1:size(handles.cams(label(i)).setmarkers,2)
                temp=handles.cams(label(i)).setmarkers(:,j);
                if temp(2)==0
                    voxel(handles.markers(:,temp(1)),[0.1 0.1 0.1],'r',0.5);
                end
            end
   
        end
        if get(handles.check_mark_inside,'value')==1
            for j=1:size(handles.cams(label(i)).setmarkers,2)
                temp=handles.cams(label(i)).setmarkers(:,j);
                if temp(2)==0
                    voxel(handles.markers(:,temp(1)),[0.1 0.1 0.1],'r',0.5);
                elseif temp(2)==1
                    voxel(handles.markers(:,temp(1)),[0.1 0.1 0.1],'g',0.5);    
                else
                    voxel(handles.markers(:,temp(1)),[0.1 0.1 0.1],'y',0.5);
                end
            end
        end
        
        
    end
    
end

voxel(handles.space/2,handles.space,'c',0.02)


guidata(hObject,handles)



% --- Executes on button press in push_plot_selmark.
function push_plot_selmark_Callback(hObject, eventdata, handles)
% hObject    handle to push_plot_selmark (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.plot_cam,'XLim',[-2 handles.space(1)+2],...
                      'YLim',[-2 handles.space(2)+2],...
                      'ZLim',[-2 handles.space(3)+2]);
axes(handles.plot_cam);          
if get(handles.check_mark,'Value')==1        
    if strcmp(get(handles.edit_marker,'String'),'All')
        for i=1:size(handles.markers,2)
            voxel(handles.markers(:,i),[0.1 0.1 0.1],'y',0.5);
        end
    else
        label=str2num(get(handles.edit_marker,'String'));
        for i=1:size(label,2)
            if label(i)>size(handles.markers,2)
                errordlg(['Attento: non esiste il Marker ', num2str(label(i))],...
                    'Incorrect Selection','modal');
            else
                for i=1:size(label,2)
                    voxel(handles.markers(:,label(i)),[0.1 0.1 0.1],'y',0.5);
                    hold on;
                end
            end
        end
    end
end

if get(handles.check_markcam,'Value')==1
    vox_x= handles.space(1)/handles.latovoxel;
    vox_y= handles.space(2)/handles.latovoxel;
    vox_z= handles.space(3)/handles.latovoxel;
    labelmark= str2num(get(handles.edit_marker,'String'));
    %se inserisco + markers funziona ?
    for i=1:size(labelmark,2)
        if labelmark(i)>size(handles.markers,2)
            errordlg(['Attento: non esiste il Marker ', num2str(labelmark(i))],...
                'Incorrect Selection','modal');
        else
        pos     =  floor(handles.markers(:,labelmark(i))/handles.latovoxel)+1;
        %allora l'etichetta del voxel a cui corrispondono tali coordinate è
        etichetta= pos(1)+(pos(2)-1)*vox_x+(pos(3)-1)*vox_x*vox_y;
        labelcams=handles.voxels(etichetta).setcameras;
        plotcam3(handles.cams(labelcams),handles.space,handles.voxels,....
                 handles.latovoxel,[1 1 1 0 0 0 0]);

        end
        
    end
end

if get(handles.check_mark_all,'Value')==1
        for i=1:size(handles.markers,2)
            voxel(handles.markers(:,i),[0.1 0.1 0.1],'y',0.5);
        end   
end

if get(handles.check_mark_occlused,'Value')
    
end

% if get(handles.check_mark_all,'Value')==1                  
%     if strcmp(get(handles.edit_marker,'String'),'All')
%         for i=1:size(handles.markers,2)
%             voxel(handles.markers(:,i),[0.1 0.1 0.1],'y',0.5);
%         end
%     else
%         label=str2num(get(handles.edit_marker,'String'))
%         voxel(handles.markers(:,label),[0.1 0.1 0.1],'y',0.5);
%     end
% end
%     

% --- Executes on button press in push_realimg.
function push_realimg_Callback(hObject, eventdata, handles)
% hObject    handle to push_realimg (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.text_np1 ,'String','...');
    set(handles.text_nvisti ,'String','...');
    set(handles.text_nocclusi ,'String','...');
    
if get(handles.radio_cam,'Value')==0
    errordlg('Attento: devi selezionare una telecamera e non un marker',...
                'Incorrect Selection','modal');            
else
    if strcmp(get(handles.edit_cam,'String'),'All')
        errordlg('Attento: devi selezionare solo UNA telecamera',...
                 'Incorrect Selection','modal');
    end
    label=str2num(get(handles.edit_cam,'String'))
    if size(label,2)>1
         errordlg('Attento: devi selezionare solo UNA telecamera',...
                'Incorrect Selection','modal');
    else
        %lato=400;
        lato=handles.cams(1).intrinsic(3,1)
%         set(handles.plot_overlap,'XLim',[0 lato],...
%                       'YLim',[0 lato]);
        axes(handles.plot_overlap)
        imshow(handles.cams(label).realimg);
        axis normal
    end
end
guidata(hObject,handles);

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (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 push_overlap.
function push_overlap_Callback(hObject, eventdata, handles)
% hObject    handle to push_overlap (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    if strcmp(get(handles.edit_cam,'String'),'All')
        errordlg('Attento: devi selezionare solo UNA telecamera',...
                 'Incorrect Selection','modal');
    end
    
    label=str2num(get(handles.edit_cam,'String'));
    
    if size(label,2)>1
         errordlg('Attento: devi selezionare solo UNA telecamera',...
                'Incorrect Selection','modal');
    end
    
    axes(handles.plot_overlap);
    axis normal
    fictiousimg=handles.cams(label).fictiousimg; 
    for j=1:size(fictiousimg,2)
        if handles.cams(label).setmarkers(2,j)==1
                PlotCircle(fictiousimg(1,j),...
                           fictiousimg(2,j),...
                           fictiousimg(3,j),10000,'g');
            elseif handles.cams(label).setmarkers(2,j)==0
                PlotCircle(fictiousimg(1,j),...
                           fictiousimg(2,j),...
                           fictiousimg(3,j),10000,'r');
            else
                PlotCircle(fictiousimg(1,j),...
                           fictiousimg(2,j),...
                           fictiousimg(3,j),10000,'y');
            end
        hold on
    end
    hold off;
    
    p1=0;
    visti=0;
    occlusi=0;
    
    for i=1:size(handles.cams(label).setmarkers,2)
        if handles.cams(label).setmarkers(2,i)==0
            occlusi=occlusi+1;
        elseif handles.cams(label).setmarkers(2,i)==1
            p1=p1+1;
            visti = visti+1;
        else
            visti=visti+1;
        end
    end
    
    set(handles.text_np1 ,'String',num2str(p1));
    set(handles.text_nvisti ,'String',num2str(visti));
    set(handles.text_nocclusi ,'String',num2str(occlusi));
     
guidata(hObject,handles);

% --- Executes on button press in push_clear2.
function push_clear2_Callback(hObject, eventdata, handles)
% hObject    handle to push_clear2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.plot_overlap);
cla;
set(handles.text_np1 ,'String','...');
set(handles.text_nvisti ,'String','...');
set(handles.text_nocclusi ,'String','...');
guidata(hObject,handles);

% --- Executes on button press in push_next.
function push_next_Callback(hObject, eventdata, handles)
% hObject    handle to push_next (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  setappdata(0,'cams',handles.cams);
  setappdata(0,'voxels',handles.voxels);
  setappdata(0,'space',handles.space);
  setappdata(0,'latovoxel',handles.latovoxel);
%  setappdata(0,'dist',handles.dist);
%  setappdata(0,'fov_angle',handles.fov_angle);

Show_Tree
close(Mark4Cam)

% --- Executes on button press in checkbox12.
function checkbox12_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox12 (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 checkbox12


% --- Executes on selection change in popup_select_var.
function popup_select_var_Callback(hObject, eventdata, handles)
% hObject    handle to popup_select_var (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popup_select_var contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popup_select_var
switch get(handles.popup_select_var,'Value')   
    case 1
        set(handles.popup_cam,'visible','on');
        columnname =   {'position','angles','set voxels','set markers'};
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'Units','char',...
                      'columnwidth',{'auto',57*3,...
                      max(80,length( num2str(handles.cams(1).voxels))*5),...
                      max(80,length( num2str(handles.cams(1).setmarkers))*5)},...
                      'Data',handles.data);
      
    case 2
        set(handles.popup_cam,'visible','off');
        
        columnname =   {'position','set cameras','set markers'};
        
        for i=1:size(handles.voxels,2)
            handles.rowname{i} = ['voxels' num2str(i)];
            handles.datavox(i,:)= {['   [  ' num2str(handles.voxels(i).position') ' ]'],...
                       [ '  [  ' num2str(handles.voxels(i).setcameras) ' ]'],...
                       [ '  [ ' num2str(handles.voxels(i).setmarkers) ' ]']...
                                  };
        end
     
        
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'columnwidth',{55*3,max(100,size(handles.voxels(1).setcameras,2)*15),...
                      max(100,size(handles.voxels(1).setmarkers,2)*20)},...
                      'Data',handles.datavox);
    case 3
        set(handles.popup_cam,'visible','off');        
        columnname =   {'position','voxel','set cameras','Occlused for cam:'};
        
        vox_x= handles.space(1)/handles.latovoxel;
        vox_y= handles.space(2)/handles.latovoxel;
        vox_z= handles.space(3)/handles.latovoxel;
        
        Mx=100;
        for i=1:size(handles.markers,2)
            
            pos     =  floor(handles.markers(:,i)/handles.latovoxel)+1;
            %allora l'etichetta del voxel a cui corrispondono tali coordinate è
            etichetta= pos(1)+(pos(2)-1)*vox_x+(pos(3)-1)*vox_x*vox_y;
            
            Mx = max(Mx , size(handles.voxels(etichetta).setcameras,2)*20);
            handles.rowname{i} = ['marker' num2str(i)];
            handles.datamark(i,:)= { [' [  ' num2str(handles.markers(:,i)') ' ]'],...
                       ['         [  ' num2str(etichetta) ' ]'],...
                       [ '  [ ' num2str(handles.voxels(etichetta).setcameras) ' ]']...
                       [ '  [ ' num2str(handles.voxels(etichetta).setcameras) ' ]']};
        end
     
        
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'columnwidth',{55*3,'auto',...
                      Mx,...
                      'auto'},...
                      'Data',handles.datamark);
end


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

% Hint: popupmenu 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 selection change in popup_cam.
function popup_cam_Callback(hObject, eventdata, handles)
% hObject    handle to popup_cam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popup_cam contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popup_cam
switch get(handles.popup_cam,'Value')   
    case 1
%         columnname =   {'position','angles','set voxels','set markers',...
%                         'markers visit', 'markers occluded'};
        columnname =   {'position','angles','set voxels','set markers'};
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'Units','char',...
                      'columnwidth',{'auto',57*3,...
                      max(80,length( num2str(handles.cams(1).voxels))*5),...
                      max(80,length( num2str(handles.cams(1).setmarkers))*5)},...
                      'Data',handles.data);
       
    case 2
        columnname =   {'x  y z'};
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'columnwidth',{280},...
                      'Data',handles.data(:,1));
    case 3
        columnname =   {'angle [x y z]'};
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'columnwidth',{280},...
                      'Data',handles.data(:,2));
    case 4
        columnname =   {'set voxels'};
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'Units','char',...
                      'columnwidth',{280},...
                      'Data',handles.data(:,3));
    case 5
        columnname =   {'set markers'};
        set(handles.table_cam,'ColumnName', columnname,...
                      'Rowname', handles.rowname,...
                      'Units','char',...
                      'columnwidth',{280},...
                      'Data',handles.data(:,4));
    otherwise
end
guidata(hObject,handles)



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

% Hint: popupmenu 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 checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox6 (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 checkbox6


% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox7 (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 checkbox7


% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox8 (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 checkbox8


% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox9 (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 checkbox9


% --- Executes on button press in checkbox10.
function checkbox10_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox10 (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 checkbox10


% --- Executes on button press in checkbox11.
function checkbox11_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox11 (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 checkbox11


% --- Executes on button press in check_cam.
function check_cam_Callback(hObject, eventdata, handles)
% hObject    handle to check_cam (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 check_cam


% --- Executes on button press in check_mark_inside.
function check_mark_inside_Callback(hObject, eventdata, handles)
% hObject    handle to check_mark_inside (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 check_mark_inside


% --- Executes on button press in check_versori.
function check_versori_Callback(hObject, eventdata, handles)
% hObject    handle to check_versori (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 check_versori


% --- Executes on button press in check_allmark.
function check_allmark_Callback(hObject, eventdata, handles)
% hObject    handle to check_allmark (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 check_allmark


% --- Executes on button press in check_occlused.
function check_occlused_Callback(hObject, eventdata, handles)
% hObject    handle to check_occlused (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 check_occlused


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (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 push_back.
function push_back_Callback(hObject, eventdata, handles)
% hObject    handle to push_back (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Chose;
close(Mark4Cam);



function edit_cam_Callback(hObject, eventdata, handles)
% hObject    handle to edit_cam (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 edit_cam as text
%        str2double(get(hObject,'String')) returns contents of edit_cam as a double


% --- Executes during object creation, after setting all properties.
function edit_cam_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_cam (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 edit_marker_Callback(hObject, eventdata, handles)
% hObject    handle to edit_marker (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 edit_marker as text
%        str2double(get(hObject,'String')) returns contents of edit_marker as a double


% --- Executes during object creation, after setting all properties.
function edit_marker_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_marker (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 push_clear.
function push_clear_Callback(hObject, eventdata, handles)
% hObject    handle to push_clear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.plot_cam);
guidata(hObject,handles)

% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (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 pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton17 (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 text_sel_mark_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text_sel_mark (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes when selected object is changed in uipanel_select1.
function uipanel_select1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel_select1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
if hObject == handles.radio_cam
    set(handles.text_sel_mark,'visible','off');
    set(handles.edit_marker,'visible','off');
    set(handles.uipanel_mark,'visible','off');
    set(handles.push_plot_selmark,'visible','off');
    set(handles.uipanel_cam,'visible','on');
else
    set(handles.text_sel_mark,'visible','on');
    set(handles.edit_marker,'visible','on');
    set(handles.uipanel_mark,'visible','on');
    set(handles.push_plot_selmark,'visible','on');
    set(handles.uipanel_cam,'visible','off');
    
end
guidata(hObject,handles);


% --- Executes on button press in check_markcam.
function check_markcam_Callback(hObject, eventdata, handles)
% hObject    handle to check_markcam (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 check_markcam


% --- Executes on button press in check_FOV.
function check_FOV_Callback(hObject, eventdata, handles)
% hObject    handle to check_FOV (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 check_FOV


% --- Executes on button press in check_mark_occlused.
function check_mark_occlused_Callback(hObject, eventdata, handles)
% hObject    handle to check_mark_occlused (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 check_mark_occlused


% --- Executes on button press in check_mark_all.
function check_mark_all_Callback(hObject, eventdata, handles)
% hObject    handle to check_mark_all (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 check_mark_all


% --- Executes on button press in check_mark.
function check_mark_Callback(hObject, eventdata, handles)
% hObject    handle to check_mark (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 check_mark
