calibration.cpp

00001 /***************************************************************************
00002  *  calibration.cpp - Abstract class defining a camera calibration matrix K
00003  *                    for a finite camera
00004  *
00005  *  Generated: Thu May 8 13:24 2008
00006  *  Copyright  2008  Christof Rath <c.rath@student.tugraz.at>
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #include "calibration.h"
00025 #include <iostream>
00026 #include <core/exceptions/software.h>
00027
00028 using namespace fawkes;
00029 
00030 /** @class Calibration <models/camera/calibration.h>
00031  * A Calibration matrix for a finite camera.
00032  *
00033  * @author Christof Rath
00034  */
00035 
00036 /** Hidden default constructor.
00037  */
00038 Calibration::Calibration(): Matrix(3, 3)
00039 {
00040   id();
00041 }
00042 
00043 /** Constructor.
00044  * @param k 3x3 Calibration matrix of the camera
00045  */
00046 Calibration::Calibration(const fawkes::Matrix& k): Matrix(3, 3)
00047 {
00048   K(k);
00049 }
00050 
00051 /** Copy Constructor.
00052  * @param cal the Calibration to copy
00053  */
00054 Calibration::Calibration(const Calibration& cal): Matrix(3, 3)
00055 {
00056   K(cal.K());
00057 }
00058 
00059 /** Destructor.
00060  */
00061 Calibration::~Calibration()
00062 {
00063 }
00064 
00065 /** Calibration getter.
00066  * @return The calibration matrix
00067  */
00068 Matrix
00069 Calibration::K() const
00070 {
00071   return get_submatrix(0, 0, 3, 3);
00072 }
00073 
00074 /** Sets the calibration matrix.
00075  * The matrix k has a size 3x3. The elements (row by row):
00076  * scale factor in x-direction, skew, x-coordinate of the principal point
00077  * 0, scale factor in y-direction, y-coordinate of the principal point
00078  * 0, 0, 1
00079  * @param k the calibration matrix
00080  */
00081 Calibration&
00082 Calibration::K(const fawkes::Matrix& k)
00083 {
00084   unsigned int i,j;
00085   k.size(i, j);
00086
00087   if (i != j || i != 3)
00088     throw IllegalArgumentException("The calibration matrix has to be 3 by 3");
00089
00090   id();
00091   overlay (0, 0, k);
00092   return *this;
00093 }
00094