DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SimpleMatrixSpecializations.ih
1 
30 
31 #include <cstdlib>
34 // IMPLEMENTATION of inline methods.
36 
38 // ----------------------- Standard services ------------------------------
39 template <typename M, DGtal::Dimension TM, DGtal::Dimension TN>
40 inline
43  const DGtal::Dimension ai,
44  const DGtal::Dimension aj)
45 {
46  BOOST_STATIC_ASSERT(TM == TN);
47  ASSERT(ai<TM);
48  ASSERT(aj<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++)
54  {
55  if (i!=ai && j!=aj)
56  {
57  ASSERT(indexR < TM -1);
58  ASSERT(indexC < TN -1);
59  mat.setComponent(indexR,indexC, aM(i,j));
60  indexC++;
61  }
62  if (indexC==TM-1)
63  {
64  indexC=0;
65  indexR++;
66  }
67 
68  if (indexR==TM-1)
69  return mat.determinant();
70  }
71 
72  return mat.determinant();
73 }
74 
75 template <typename M, DGtal::Dimension TM, DGtal::Dimension TN>
76 inline
79 {
80  BOOST_STATIC_ASSERT(TM == TN);
81 
83  for(DGtal::Dimension i= 0; i< TM; ++i)
84  d += aM(i,0) * aM.cofactor(i,0);
85  return d;
86 }
87 // ----------------------- Specialization 1x1 ------------------------------
88 
89 template <typename M>
90 inline
93  const DGtal::Dimension i,
94  const DGtal::Dimension j)
95 {
96  ASSERT(false && "Not defined for 1x1 matrices");
98 }
99 
100 template <typename M>
101 inline
104 {
105 
106  return aM(0,0);
107 }
108 // ----------------------- Specialization 2x2 ------------------------------
109 
110 template <typename M>
111 inline
114  const DGtal::Dimension i,
115  const DGtal::Dimension j)
116 {
117  ASSERT(i<2);
118  ASSERT(j<2);
119  return aM((i+1) % 2,(j+1) % 2);
120 }
121 
122 template <typename M>
123 inline
126 {
127 
128  return aM(0,0)*aM(1,1) - aM(0,1)*aM(1,0);
129 }
130 // ----------------------- Specialization 3x3 ------------------------------
131 
132 template <typename M>
133 inline
136  const DGtal::Dimension ai,
137  const DGtal::Dimension aj)
138 {
139  ASSERT(ai<3);
140  ASSERT(aj<3);
142  DGtal::Dimension indexR=0;
143  DGtal::Dimension indexC=0;
144  for (DGtal::Dimension i=0; i<3; i++)
145  for (DGtal::Dimension j=0; j<3; j++)
146  {
147  if (i!=ai && j!=aj)
148  {
149  ASSERT(indexR < 3 -1);
150  ASSERT(indexC < 3 -1);
151  mat.setComponent(indexR,indexC, aM(i,j));
152  indexC++;
153  }
154  if (indexC==3-1)
155  {
156  indexC=0;
157  indexR++;
158  }
159 
160  if (indexR==3-1)
161  return determinant(mat);
162  }
163 
164  return determinant(mat);
165 }
166 
167 template <typename M>
168 inline
171 {
172  return aM(0,0) * ( (aM(1,1)*aM(2,2))-
173  (aM(1,2)*aM(2,1)) )-
174  aM(1,0) * ( (aM(0,1)*aM(2,2))-
175  (aM(0,2)*aM(2,1)) )
176  + aM(2,0) * ( (aM(0,1)*aM(1,2))-
177  (aM(0,2)*aM(1,1)) );
178 }
179 
180 // //
182 
183