2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file SimpleMatrixSpecializations.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in SimpleMatrixSpecializations.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////////
34 // IMPLEMENTATION of inline methods.
35 ///////////////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////////
38 // ----------------------- Standard services ------------------------------
39 template <typename M, DGtal::Dimension TM, DGtal::Dimension TN>
41 typename DGtal::SimpleMatrixSpecializations<M,TM,TN>::Component
42 DGtal::SimpleMatrixSpecializations<M,TM,TN>::minorDeterminant(const Matrix &aM,
43 const DGtal::Dimension ai,
44 const DGtal::Dimension aj)
46 BOOST_STATIC_ASSERT(TM == TN);
49 DGtal::SimpleMatrix<Component,TM-1,TN-1> mat;
50 DGtal::Dimension indexR=0;
51 DGtal::Dimension indexC=0;
52 for (DGtal::Dimension i=0; i<TM; i++)
53 for (DGtal::Dimension j=0; j<TN; j++)
57 ASSERT(indexR < TM -1);
58 ASSERT(indexC < TN -1);
59 mat.setComponent(indexR,indexC, aM(i,j));
69 return mat.determinant();
72 return mat.determinant();
75 template <typename M, DGtal::Dimension TM, DGtal::Dimension TN>
77 typename DGtal::SimpleMatrixSpecializations<M,TM,TN>::Component
78 DGtal::SimpleMatrixSpecializations<M,TM,TN>::determinant(const Matrix &aM)
80 BOOST_STATIC_ASSERT(TM == TN);
82 Component d = DGtal::NumberTraits<Component>::ZERO;
83 for(DGtal::Dimension i= 0; i< TM; ++i)
84 d += aM(i,0) * aM.cofactor(i,0);
87 // ----------------------- Specialization 1x1 ------------------------------
91 typename DGtal::SimpleMatrixSpecializations<M,1,1>::Component
92 DGtal::SimpleMatrixSpecializations<M,1,1>::minorDeterminant(const Matrix &aM,
93 const DGtal::Dimension i,
94 const DGtal::Dimension j)
96 boost::ignore_unused_variable_warning( aM );
97 boost::ignore_unused_variable_warning( i );
98 boost::ignore_unused_variable_warning( j );
99 ASSERT(false && "Not defined for 1x1 matrices");
100 return NumberTraits<Component>::ZERO;
103 template <typename M>
105 typename DGtal::SimpleMatrixSpecializations<M,1,1>::Component
106 DGtal::SimpleMatrixSpecializations<M,1,1>::determinant(const Matrix &aM)
111 // ----------------------- Specialization 2x2 ------------------------------
113 template <typename M>
115 typename DGtal::SimpleMatrixSpecializations<M,2,2>::Component
116 DGtal::SimpleMatrixSpecializations<M,2,2>::minorDeterminant(const Matrix &aM,
117 const DGtal::Dimension i,
118 const DGtal::Dimension j)
122 return aM((i+1) % 2,(j+1) % 2);
125 template <typename M>
127 typename DGtal::SimpleMatrixSpecializations<M,2,2>::Component
128 DGtal::SimpleMatrixSpecializations<M,2,2>::determinant(const Matrix &aM)
131 return aM(0,0)*aM(1,1) - aM(0,1)*aM(1,0);
133 // ----------------------- Specialization 3x3 ------------------------------
135 template <typename M>
137 typename DGtal::SimpleMatrixSpecializations<M,3,3>::Component
138 DGtal::SimpleMatrixSpecializations<M,3,3>::minorDeterminant(const Matrix &aM,
139 const DGtal::Dimension ai,
140 const DGtal::Dimension aj)
144 DGtal::SimpleMatrix<Component,2,2> mat;
145 DGtal::Dimension indexR=0;
146 DGtal::Dimension indexC=0;
147 for (DGtal::Dimension i=0; i<3; i++)
148 for (DGtal::Dimension j=0; j<3; j++)
152 ASSERT(indexR < 3 -1);
153 ASSERT(indexC < 3 -1);
154 mat.setComponent(indexR,indexC, aM(i,j));
164 return mat.determinant(); //DGtal::SimpleMatrixSpecializations<M,2,2>::determinant(mat);
167 return mat.determinant(); //DGtal::SimpleMatrixSpecializations<M,2,2>::determinant(mat);
170 template <typename M>
172 typename DGtal::SimpleMatrixSpecializations<M,3,3>::Component
173 DGtal::SimpleMatrixSpecializations<M,3,3>::determinant(const Matrix &aM)
175 return aM(0,0) * ( (aM(1,1)*aM(2,2))-
177 aM(1,0) * ( (aM(0,1)*aM(2,2))-
179 + aM(2,0) * ( (aM(0,1)*aM(1,2))-
184 ///////////////////////////////////////////////////////////////////////////////