function ocam_model = rok_fisheye_camera_read_model (filename)
    % ocam_model = ROK_FISHEYE_CAMERA_READ_MODEL (filename)
    %
    % Reads the camera calibration model produced by Omnidirectional Camera
    % Calibration Toolbox for Matlab (OCamCalib). This function parses the
    % text file that is exported by the toolbox.lab.
    %
    % Input:
    %  - filename = name of camera calibration file, produced by
    %    OCamCalib's export function
    %
    % Output:
    %  - ocam_model = camera calibration model
    %
    % NOTE: this function requires OCamCalib's functions in path!
    %
    % Copyright (C) 2012, Rok Mandeljc <rok.mandeljc@fe.uni-lj.si>
    
    % Open file
    file = fopen(filename, 'r');
    
    % Skip comments and empty lines
    fgetl(file);
    fgetl(file);
   
    % Read coefficients
    line = fgetl(file);
    data = eval([ '[', line, ']' ]);
    ocam_model.ss = data(2:end);
   
    % Skip comments and empty lines
    fgetl(file);
    fgetl(file);
    fgetl(file);
   
    % Read coefficients of inverse polynomial model
    line = fgetl(file);
    data = eval([ '[', line, ']' ]);
    ocam_model.invpol = data(end:-1:2);
   
    % Skip comments and empty lines
    fgetl(file);
    fgetl(file);
    fgetl(file);
   
    % Read principal point
    line = fgetl(file);
    data = eval([ '[', line, ']' ]);
    ocam_model.xc = data(1) + 1;
    ocam_model.yc = data(2) + 1;
   
    % Skip comments and empty lines
    fgetl(file);
    fgetl(file);
    fgetl(file);
   
    % Read distortion coefficients
    line = fgetl(file);
    data = eval([ '[', line, ']' ]);
    ocam_model.c = data(1);
    ocam_model.d = data(2);
    ocam_model.e = data(3);
   
    % Skip comments and empty lines
    fgetl(file);
    fgetl(file);
    fgetl(file);
    
    % Original image width and height
    line = fgetl(file);
    data = eval([ '[', line, ']' ]);
    ocam_model.height = data(1);
    ocam_model.width = data(2);
    
    % Close file
    fclose(file);
    
    % Compute inverse polynomial (needed for world2cam_fast)
    width = ocam_model.width;
    height = ocam_model.height;
    ocam_model.pol = findinvpoly(ocam_model.ss,sqrt((width/2)^2+(height/2)^2));
end