/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* $Id: vctDeterminant.h,v 1.9 2007/04/26 19:33:57 anton Exp $ Author(s): Ofri Sadowsky Created on: 2004-04-16 (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ #ifndef _vctDeterminant_h #define _vctDeterminant_h #include /*! \file \brief Defines vctDeterminant */ /*! \brief Determinant function for fixed size matrices Compute the determinant of a fixed size square matrix. This templated class is currently specialized for matrices of size 1 by 1, 2 by 2 or 3 by 3. \param _size The size of the square matrix */ template class vctDeterminant { public: enum {SIZE = _size}; /*! Actually compute the determinant of the matrix. \param matrix A fixed size square matrix */ template static _elementType Compute(const vctFixedSizeConstMatrixBase<_size, _size, _rowStride, _colStride, _elementType, _dataPtrType> & matrix); }; #ifndef DOXYGEN template<> class vctDeterminant<1> { public: enum {SIZE = 1}; template static _elementType Compute(const vctFixedSizeConstMatrixBase & matrix) { return matrix.Element(0, 0); } }; template<> class vctDeterminant<2> { public: enum {SIZE = 2}; template static _elementType Compute(const vctFixedSizeConstMatrixBase & matrix) { return matrix.Element(0, 0) * matrix.Element(1, 1) - matrix.Element(0, 1) * matrix.Element(1, 0); } }; template<> class vctDeterminant<3> { public: enum {SIZE = 3}; template static _elementType Compute(const vctFixedSizeConstMatrixBase & matrix) { return matrix.Element(0, 0) * ( matrix.Element(1, 1) * matrix.Element(2, 2) - matrix.Element(1, 2) * matrix.Element(2, 1) ) - matrix.Element(0, 1) * ( matrix.Element(1, 0) * matrix.Element(2, 2) - matrix.Element(1, 2) * matrix.Element(2, 0) ) + matrix.Element(0, 2) * ( matrix.Element(1, 0) * matrix.Element(2, 1) - matrix.Element(1, 1) * matrix.Element(2, 0) ); } }; #endif // DOXYGEN #endif // _vctDeterminant_h // **************************************************************************** // Change History // **************************************************************************** // // $Log: vctDeterminant.h,v $ // Revision 1.9 2007/04/26 19:33:57 anton // All files in libraries: Applied new license text, separate copyright and // updated dates, added standard header where missing. // // Revision 1.8 2006/11/20 20:33:20 anton // Licensing: Applied new license to cisstCommon, cisstVector, cisstNumerical, // cisstInteractive, cisstImage and cisstOSAbstraction. // // Revision 1.7 2005/09/26 15:41:47 anton // cisst: Added modelines for emacs and vi. // // Revision 1.6 2005/05/19 19:29:00 anton // cisst libs: Added the license to cisstCommon and cisstVector // // Revision 1.5 2004/12/01 17:14:53 anton // cisstVector: Replace access to matrix elements by Element() instead of // double [][] for increased performance. See ticket #79. // // Revision 1.4 2004/10/25 13:52:05 anton // Doxygen documentation: Cleanup all the useless \ingroup. // // Revision 1.3 2004/09/03 19:53:52 anton // vctDeterminant: Documentation. // // Revision 1.2 2004/04/20 21:24:04 ofri // Attempting to fix compilation error on gcc // // Revision 1.1 2004/04/20 21:17:51 ofri // class vctDeterminant added to the repository after being tested on .NET // // // ****************************************************************************