classdef Xb3HandCalibrationPoints < handle
    
    properties
        points;
    end
    
    methods
        function o = Xb3HandCalibrationPoints()
            o.points = containers.Map('KeyType', 'int64','ValueType','any');
        end
        
        function add(o,pos,label,frame)
            
            point.label = label;
            point.position = pos;
            
%             keyboard
            try
                list = o.points(frame);
                
                %Check if not in list already
                pos = find(strcmp([list.label],label),1);
                
                if isempty(pos)
%                     disp('adding new')
                    list(end+1) = point;
                else
%                     disp('replacing')
                    list(pos) = point;
                end
            catch
                list = point;
            end
            
%             keyboard
            
            o.points(frame) = list;
        end
        
        function save(o,out_file)
            pts = o.points;
            save(out_file,'pts')
            warndlg(out_file,'Data saved')
        end
        
        function load(o,in_file)
            try
                load(in_file)
            catch err
                warning('Xb3HandCalibrationPoints:load:fileNotFound',err.message)
                return
            end
            
            o.points = pts;
            warndlg(in_file,'Data loaded')
        end
        
    end
end